2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/gnunet-service-ats.c
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "gnunet_ats_service.h"
29 #include "gnunet-service-ats_performance.h"
30 #include "gnunet-service-ats_scheduling.h"
31 // #include "gnunet-service-ats_performance.h"
36 struct GNUNET_PeerIdentity peer;
48 struct GNUNET_TRANSPORT_ATS_Information * ats;
51 static struct GNUNET_CONTAINER_MultiHashMap * addresses;
56 handle_ats_start (void *cls, struct GNUNET_SERVER_Client *client,
57 const struct GNUNET_MessageHeader *message)
59 const struct ClientStartMessage * msg = (const struct ClientStartMessage *) message;
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
62 "Received `%s' message\n",
64 switch (ntohl (msg->start_flag))
66 case START_FLAG_SCHEDULING:
67 GAS_add_scheduling_client (client);
69 case START_FLAG_PERFORMANCE_WITH_PIC:
70 GAS_add_performance_client (client);
72 case START_FLAG_PERFORMANCE_NO_PIC:
76 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
79 GNUNET_SERVER_receive_done (client, GNUNET_OK);
83 struct CompareAddressContext
85 struct ATS_Address * search;
86 struct ATS_Address * result;
89 int compare_address_it (void *cls,
90 const GNUNET_HashCode * key,
93 struct CompareAddressContext * cac = cls;
94 struct ATS_Address * aa = (struct ATS_Address *) value;
95 if (0 == strcmp(aa->plugin, cac->search->plugin))
97 if ((aa->addr_len == cac->search->addr_len) &&
98 (0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)))
107 free_address_it (void *cls,
108 const GNUNET_HashCode * key,
111 struct ATS_Address * aa = cls;
121 * Task run during shutdown.
127 cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
129 GNUNET_CONTAINER_multihashmap_iterate (addresses, &free_address_it, NULL);
130 GNUNET_CONTAINER_multihashmap_destroy (addresses);
135 * Process template requests.
138 * @param server the initialized server
139 * @param cfg configuration to use
142 run (void *cls, struct GNUNET_SERVER_Handle *server,
143 const struct GNUNET_CONFIGURATION_Handle *cfg)
145 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
146 { &handle_ats_start, NULL,
147 GNUNET_MESSAGE_TYPE_ATS_START, sizeof (struct ClientStartMessage)},
148 { &GAS_handle_request_address, NULL,
149 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)},
150 { &GAS_handle_address_update, NULL,
151 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
152 { &GAS_handle_address_destroyed, NULL,
153 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
154 { &GAS_handle_reservation_request, NULL,
155 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)},
156 { &GAS_handle_preference_change, NULL,
157 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
160 addresses = GNUNET_CONTAINER_multihashmap_create(128);
161 GNUNET_SERVER_add_handlers (server, handlers);
162 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
168 * The main function for the ats service.
170 * @param argc number of arguments from the command line
171 * @param argv command line arguments
172 * @return 0 ok, 1 on error
175 main (int argc, char *const *argv)
178 GNUNET_SERVICE_run (argc, argv, "ats",
179 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
182 /* end of gnunet-service-ats.c */