diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-09-21 10:56:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-09-21 10:56:28 +0000 |
commit | d4afc6e37a14fe3257263c377a243c1a22ed9ee5 (patch) | |
tree | ccfce6d4f92808372d3e7ebfe9f5372e9f21f50c /src | |
parent | 60d02b5b0899f454cb65408bd2ed4c453fa75a3d (diff) | |
download | gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.tar.gz gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.zip |
migrating more services to new service API
Diffstat (limited to 'src')
23 files changed, 844 insertions, 998 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index ffe2c9616..aa3612c2d 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -83,7 +83,6 @@ gnunet_service_ats_SOURCES = \ | |||
83 | gnunet-service-ats.c gnunet-service-ats.h \ | 83 | gnunet-service-ats.c gnunet-service-ats.h \ |
84 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ | 84 | gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \ |
85 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ | 85 | gnunet-service-ats_connectivity.c gnunet-service-ats_connectivity.h \ |
86 | gnunet-service-ats_feedback.c gnunet-service-ats_feedback.h \ | ||
87 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ | 86 | gnunet-service-ats_normalization.c gnunet-service-ats_normalization.h \ |
88 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ | 87 | gnunet-service-ats_performance.c gnunet-service-ats_performance.h \ |
89 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ | 88 | gnunet-service-ats_plugins.c gnunet-service-ats_plugins.h \ |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 045a5bb67..9762faa51 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet-service-ats.h" | 28 | #include "gnunet-service-ats.h" |
29 | #include "gnunet-service-ats_addresses.h" | 29 | #include "gnunet-service-ats_addresses.h" |
30 | #include "gnunet-service-ats_connectivity.h" | 30 | #include "gnunet-service-ats_connectivity.h" |
31 | #include "gnunet-service-ats_feedback.h" | ||
32 | #include "gnunet-service-ats_normalization.h" | 31 | #include "gnunet-service-ats_normalization.h" |
33 | #include "gnunet-service-ats_performance.h" | 32 | #include "gnunet-service-ats_performance.h" |
34 | #include "gnunet-service-ats_preferences.h" | 33 | #include "gnunet-service-ats_preferences.h" |
@@ -42,27 +41,19 @@ | |||
42 | */ | 41 | */ |
43 | struct GNUNET_STATISTICS_Handle *GSA_stats; | 42 | struct GNUNET_STATISTICS_Handle *GSA_stats; |
44 | 43 | ||
45 | /** | ||
46 | * Handle to the ATS server. | ||
47 | */ | ||
48 | static struct GNUNET_SERVER_Handle *GSA_server; | ||
49 | |||
50 | 44 | ||
51 | /** | 45 | /** |
52 | * We have received a `struct ClientStartMessage` from a client. Find | 46 | * We have received a `struct ClientStartMessage` from a client. Find |
53 | * out which type of client it is and notify the respective subsystem. | 47 | * out which type of client it is and notify the respective subsystem. |
54 | * | 48 | * |
55 | * @param cls closure, unused | 49 | * @param cls handle to the client |
56 | * @param client handle to the client | 50 | * @param msg the start message |
57 | * @param message the start message | ||
58 | */ | 51 | */ |
59 | static void | 52 | static void |
60 | handle_ats_start (void *cls, | 53 | handle_ats_start (void *cls, |
61 | struct GNUNET_SERVER_Client *client, | 54 | const struct ClientStartMessage *msg) |
62 | const struct GNUNET_MessageHeader *message) | ||
63 | { | 55 | { |
64 | const struct ClientStartMessage *msg = | 56 | struct GNUNET_SERVICE_Client *client = cls; |
65 | (const struct ClientStartMessage *) message; | ||
66 | enum StartFlag flag; | 57 | enum StartFlag flag; |
67 | 58 | ||
68 | flag = ntohl (msg->start_flag); | 59 | flag = ntohl (msg->start_flag); |
@@ -72,10 +63,10 @@ handle_ats_start (void *cls, | |||
72 | switch (flag) | 63 | switch (flag) |
73 | { | 64 | { |
74 | case START_FLAG_SCHEDULING: | 65 | case START_FLAG_SCHEDULING: |
75 | if (GNUNET_OK != GAS_scheduling_add_client (client)) | 66 | if (GNUNET_OK != |
67 | GAS_scheduling_add_client (client)) | ||
76 | { | 68 | { |
77 | GNUNET_SERVER_receive_done (client, | 69 | GNUNET_SERVICE_client_drop (client); |
78 | GNUNET_SYSERR); | ||
79 | return; | 70 | return; |
80 | } | 71 | } |
81 | break; | 72 | break; |
@@ -92,12 +83,310 @@ handle_ats_start (void *cls, | |||
92 | break; | 83 | break; |
93 | default: | 84 | default: |
94 | GNUNET_break (0); | 85 | GNUNET_break (0); |
95 | GNUNET_SERVER_receive_done (client, | 86 | GNUNET_SERVICE_client_drop (client); |
96 | GNUNET_SYSERR); | ||
97 | return; | 87 | return; |
98 | } | 88 | } |
99 | GNUNET_SERVER_receive_done (client, | 89 | GNUNET_SERVICE_client_continue (client); |
100 | GNUNET_OK); | 90 | } |
91 | |||
92 | |||
93 | |||
94 | /** | ||
95 | * Handle 'reservation request' messages from clients. | ||
96 | * | ||
97 | * @param cls client that sent the request | ||
98 | * @param message the request message | ||
99 | */ | ||
100 | static void | ||
101 | handle_reservation_request (void *cls, | ||
102 | const struct ReservationRequestMessage *message) | ||
103 | { | ||
104 | struct GNUNET_SERVICE_Client *client = cls; | ||
105 | |||
106 | GAS_handle_reservation_request (client, | ||
107 | message); | ||
108 | GNUNET_SERVICE_client_continue (client); | ||
109 | } | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Check 'preference feedback' message is well-formed | ||
114 | * | ||
115 | * @param cls client that sent the request | ||
116 | * @param message the request message | ||
117 | * @return #GNUNET_OK if @a message is well-formed | ||
118 | */ | ||
119 | static int | ||
120 | check_feedback (void *cls, | ||
121 | const struct FeedbackPreferenceMessage *message) | ||
122 | { | ||
123 | uint16_t msize; | ||
124 | uint32_t nump; | ||
125 | |||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
127 | "Received PREFERENCE_FEEDBACK message\n"); | ||
128 | msize = ntohs (message->header.size); | ||
129 | nump = ntohl (message->num_feedback); | ||
130 | if (msize != | ||
131 | sizeof (struct FeedbackPreferenceMessage) + | ||
132 | nump * sizeof (struct PreferenceInformation)) | ||
133 | { | ||
134 | GNUNET_break (0); | ||
135 | return GNUNET_SYSERR; | ||
136 | } | ||
137 | return GNUNET_OK; | ||
138 | } | ||
139 | |||
140 | |||
141 | /** | ||
142 | * Handle 'preference feedback' messages from clients. | ||
143 | * | ||
144 | * @param cls client that sent the request | ||
145 | * @param msg the request message | ||
146 | */ | ||
147 | static void | ||
148 | handle_feedback (void *cls, | ||
149 | const struct FeedbackPreferenceMessage *msg) | ||
150 | { | ||
151 | struct GNUNET_SERVICE_Client *client = cls; | ||
152 | const struct PreferenceInformation *pi; | ||
153 | uint32_t nump; | ||
154 | |||
155 | nump = ntohl (msg->num_feedback); | ||
156 | if (GNUNET_NO == | ||
157 | GNUNET_CONTAINER_multipeermap_contains (GSA_addresses, | ||
158 | &msg->peer)) | ||
159 | { | ||
160 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
161 | "Received PREFERENCE FEEDBACK for unknown peer `%s'\n", | ||
162 | GNUNET_i2s (&msg->peer)); | ||
163 | GNUNET_SERVICE_client_continue (client); | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | GNUNET_STATISTICS_update (GSA_stats, | ||
168 | "# preference feedbacks requests processed", | ||
169 | 1, | ||
170 | GNUNET_NO); | ||
171 | pi = (const struct PreferenceInformation *) &msg[1]; | ||
172 | for (uint32_t i = 0; i < nump; i++) | ||
173 | { | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
175 | "Received PREFERENCE FEEDBACK for peer `%s'\n", | ||
176 | GNUNET_i2s (&msg->peer)); | ||
177 | GAS_plugin_notify_feedback (client, | ||
178 | &msg->peer, | ||
179 | GNUNET_TIME_relative_ntoh (msg->scope), | ||
180 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), | ||
181 | pi[i].preference_value); | ||
182 | } | ||
183 | GNUNET_SERVICE_client_continue (client); | ||
184 | } | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Handle 'request address list' messages from clients. | ||
189 | * | ||
190 | * @param cls client that sent the request | ||
191 | * @param message the request message | ||
192 | */ | ||
193 | static void | ||
194 | handle_request_address_list (void *cls, | ||
195 | const struct AddressListRequestMessage *message) | ||
196 | { | ||
197 | struct GNUNET_SERVICE_Client *client = cls; | ||
198 | |||
199 | GAS_handle_request_address_list (client, | ||
200 | message); | ||
201 | GNUNET_SERVICE_client_continue (client); | ||
202 | } | ||
203 | |||
204 | |||
205 | /** | ||
206 | * Handle 'request address' messages from clients. | ||
207 | * | ||
208 | * @param cls client that sent the request | ||
209 | * @param message the request message | ||
210 | */ | ||
211 | static void | ||
212 | handle_request_address (void *cls, | ||
213 | const struct RequestAddressMessage * message) | ||
214 | { | ||
215 | struct GNUNET_SERVICE_Client *client = cls; | ||
216 | |||
217 | GAS_handle_request_address (client, | ||
218 | message); | ||
219 | GNUNET_SERVICE_client_continue (client); | ||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
224 | * Cancel 'request address' messages from clients. | ||
225 | * | ||
226 | * @param cls client that sent the request | ||
227 | * @param message the request message | ||
228 | */ | ||
229 | static void | ||
230 | handle_request_address_cancel (void *cls, | ||
231 | const struct RequestAddressMessage *message) | ||
232 | { | ||
233 | struct GNUNET_SERVICE_Client *client = cls; | ||
234 | |||
235 | GAS_handle_request_address_cancel (client, | ||
236 | message); | ||
237 | GNUNET_SERVICE_client_continue (client); | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Handle 'address add' messages from clients. | ||
243 | * | ||
244 | * @param cls client that sent the request | ||
245 | * @param m the request message | ||
246 | */ | ||
247 | static int | ||
248 | check_address_add (void *cls, | ||
249 | const struct AddressAddMessage *m) | ||
250 | { | ||
251 | const char *address; | ||
252 | const char *plugin_name; | ||
253 | uint16_t address_length; | ||
254 | uint16_t plugin_name_length; | ||
255 | uint16_t size; | ||
256 | |||
257 | size = ntohs (m->header.size); | ||
258 | address_length = ntohs (m->address_length); | ||
259 | plugin_name_length = ntohs (m->plugin_name_length); | ||
260 | address = (const char *) &m[1]; | ||
261 | if (plugin_name_length != 0) | ||
262 | plugin_name = &address[address_length]; | ||
263 | else | ||
264 | plugin_name = ""; | ||
265 | |||
266 | if ( (address_length + plugin_name_length + | ||
267 | sizeof (struct AddressAddMessage) != size) || | ||
268 | ( (plugin_name_length > 0) && | ||
269 | (plugin_name[plugin_name_length - 1] != '\0') ) ) | ||
270 | { | ||
271 | GNUNET_break (0); | ||
272 | return GNUNET_SYSERR; | ||
273 | } | ||
274 | return GNUNET_OK; | ||
275 | } | ||
276 | |||
277 | |||
278 | /** | ||
279 | * Handle 'address add' messages from clients. | ||
280 | * | ||
281 | * @param cls client that sent the request | ||
282 | * @param message the request message | ||
283 | */ | ||
284 | static void | ||
285 | handle_address_add (void *cls, | ||
286 | const struct AddressAddMessage *message) | ||
287 | { | ||
288 | struct GNUNET_SERVICE_Client *client = cls; | ||
289 | |||
290 | GAS_handle_address_add (message); | ||
291 | GNUNET_SERVICE_client_continue (client); | ||
292 | } | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Handle 'address update' messages from clients. | ||
297 | * | ||
298 | * @param cls client that sent the request | ||
299 | * @param message the request message | ||
300 | */ | ||
301 | static void | ||
302 | handle_address_update (void *cls, | ||
303 | const struct AddressUpdateMessage *message) | ||
304 | { | ||
305 | struct GNUNET_SERVICE_Client *client = cls; | ||
306 | |||
307 | GAS_handle_address_update (message); | ||
308 | GNUNET_SERVICE_client_continue (client); | ||
309 | } | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Handle 'address destroyed' messages from clients. | ||
314 | * | ||
315 | * @param cls client that sent the request | ||
316 | * @param message the request message | ||
317 | */ | ||
318 | static void | ||
319 | handle_address_destroyed (void *cls, | ||
320 | const struct AddressDestroyedMessage *message) | ||
321 | { | ||
322 | struct GNUNET_SERVICE_Client *client = cls; | ||
323 | |||
324 | GAS_handle_address_destroyed (message); | ||
325 | GNUNET_SERVICE_client_continue (client); | ||
326 | } | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Check that 'change preference' message is well-formed. | ||
331 | * | ||
332 | * @param cls client that sent the request | ||
333 | * @param message the request message | ||
334 | * @return #GNUNET_OK if @a message is well-formed | ||
335 | */ | ||
336 | static int | ||
337 | check_preference_change (void *cls, | ||
338 | const struct ChangePreferenceMessage *message) | ||
339 | { | ||
340 | uint16_t msize; | ||
341 | uint32_t nump; | ||
342 | |||
343 | msize = ntohs (message->header.size); | ||
344 | nump = ntohl (message->num_preferences); | ||
345 | if ( (msize != | ||
346 | sizeof (struct ChangePreferenceMessage) + | ||
347 | nump * sizeof (struct PreferenceInformation)) || | ||
348 | (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) ) | ||
349 | { | ||
350 | GNUNET_break (0); | ||
351 | return GNUNET_SYSERR; | ||
352 | } | ||
353 | return GNUNET_OK; | ||
354 | } | ||
355 | |||
356 | |||
357 | /** | ||
358 | * Handle 'change preference' messages from clients. | ||
359 | * | ||
360 | * @param cls client that sent the request | ||
361 | * @param message the request message | ||
362 | */ | ||
363 | static void | ||
364 | handle_preference_change (void *cls, | ||
365 | const struct ChangePreferenceMessage *message) | ||
366 | { | ||
367 | struct GNUNET_SERVICE_Client *client = cls; | ||
368 | |||
369 | GAS_handle_preference_change (client, | ||
370 | message); | ||
371 | GNUNET_SERVICE_client_continue (client); | ||
372 | } | ||
373 | |||
374 | |||
375 | /** | ||
376 | * A client connected to us. Setup the local client | ||
377 | * record. | ||
378 | * | ||
379 | * @param cls unused | ||
380 | * @param client handle of the client | ||
381 | * @param mq message queue to talk to @a client | ||
382 | * @return @a client | ||
383 | */ | ||
384 | static void * | ||
385 | client_connect_cb (void *cls, | ||
386 | struct GNUNET_SERVICE_Client *client, | ||
387 | struct GNUNET_MQ_Handle *mq) | ||
388 | { | ||
389 | return client; | ||
101 | } | 390 | } |
102 | 391 | ||
103 | 392 | ||
@@ -107,10 +396,12 @@ handle_ats_start (void *cls, | |||
107 | * | 396 | * |
108 | * @param cls unused | 397 | * @param cls unused |
109 | * @param client handle of the client | 398 | * @param client handle of the client |
399 | * @param app_ctx | ||
110 | */ | 400 | */ |
111 | static void | 401 | static void |
112 | client_disconnect_handler (void *cls, | 402 | client_disconnect_cb (void *cls, |
113 | struct GNUNET_SERVER_Client *client) | 403 | struct GNUNET_SERVICE_Client *client, |
404 | void *app_ctx) | ||
114 | { | 405 | { |
115 | if (NULL == client) | 406 | if (NULL == client) |
116 | return; | 407 | return; |
@@ -134,7 +425,6 @@ cleanup_task (void *cls) | |||
134 | GAS_addresses_done (); | 425 | GAS_addresses_done (); |
135 | GAS_plugin_done (); | 426 | GAS_plugin_done (); |
136 | GAS_normalization_stop (); | 427 | GAS_normalization_stop (); |
137 | GAS_scheduling_done (); | ||
138 | GAS_performance_done (); | 428 | GAS_performance_done (); |
139 | GAS_preference_done (); | 429 | GAS_preference_done (); |
140 | GAS_reservations_done (); | 430 | GAS_reservations_done (); |
@@ -150,51 +440,21 @@ cleanup_task (void *cls) | |||
150 | * Process template requests. | 440 | * Process template requests. |
151 | * | 441 | * |
152 | * @param cls closure | 442 | * @param cls closure |
153 | * @param server the initialized server | ||
154 | * @param cfg configuration to use | 443 | * @param cfg configuration to use |
444 | * @param service the initialized service | ||
155 | */ | 445 | */ |
156 | static void | 446 | static void |
157 | run (void *cls, | 447 | run (void *cls, |
158 | struct GNUNET_SERVER_Handle *server, | 448 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
159 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 449 | struct GNUNET_SERVICE_Handle *service) |
160 | { | 450 | { |
161 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 451 | GSA_stats = GNUNET_STATISTICS_create ("ats", |
162 | {&handle_ats_start, NULL, | 452 | cfg); |
163 | GNUNET_MESSAGE_TYPE_ATS_START, | 453 | GAS_reservations_init (); |
164 | sizeof (struct ClientStartMessage)}, | ||
165 | {&GAS_handle_request_address, NULL, | ||
166 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, | ||
167 | sizeof (struct RequestAddressMessage)}, | ||
168 | {&GAS_handle_request_address_cancel, NULL, | ||
169 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL, | ||
170 | sizeof (struct RequestAddressMessage)}, | ||
171 | {&GAS_handle_request_address_list, NULL, | ||
172 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST, | ||
173 | sizeof (struct AddressListRequestMessage)}, | ||
174 | {&GAS_handle_address_add, NULL, | ||
175 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 0}, | ||
176 | {&GAS_handle_address_update, NULL, | ||
177 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, | ||
178 | sizeof (struct AddressUpdateMessage) }, | ||
179 | {&GAS_handle_address_destroyed, NULL, | ||
180 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, | ||
181 | sizeof (struct AddressDestroyedMessage) }, | ||
182 | {&GAS_handle_reservation_request, NULL, | ||
183 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, | ||
184 | sizeof (struct ReservationRequestMessage)}, | ||
185 | {&GAS_handle_preference_change, NULL, | ||
186 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, | ||
187 | {&GAS_handle_feedback, NULL, | ||
188 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, 0}, | ||
189 | {NULL, NULL, 0, 0} | ||
190 | }; | ||
191 | GSA_server = server; | ||
192 | GSA_stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
193 | GAS_reservations_init (server); | ||
194 | GAS_connectivity_init (); | 454 | GAS_connectivity_init (); |
195 | GAS_preference_init (); | 455 | GAS_preference_init (); |
196 | GAS_normalization_start (); | 456 | GAS_normalization_start (); |
197 | GAS_addresses_init (server); | 457 | GAS_addresses_init (); |
198 | if (GNUNET_OK != | 458 | if (GNUNET_OK != |
199 | GAS_plugin_init (cfg)) | 459 | GAS_plugin_init (cfg)) |
200 | { | 460 | { |
@@ -206,37 +466,69 @@ run (void *cls, | |||
206 | GAS_preference_done (); | 466 | GAS_preference_done (); |
207 | if (NULL != GSA_stats) | 467 | if (NULL != GSA_stats) |
208 | { | 468 | { |
209 | GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO); | 469 | GNUNET_STATISTICS_destroy (GSA_stats, |
470 | GNUNET_NO); | ||
210 | GSA_stats = NULL; | 471 | GSA_stats = NULL; |
211 | } | 472 | } |
212 | return; | 473 | return; |
213 | } | 474 | } |
214 | GAS_performance_init (server); | 475 | GAS_performance_init (); |
215 | GAS_scheduling_init (server); | ||
216 | |||
217 | GNUNET_SERVER_disconnect_notify (server, | ||
218 | &client_disconnect_handler, | ||
219 | NULL); | ||
220 | GNUNET_SERVER_add_handlers (server, handlers); | ||
221 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 476 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, |
222 | NULL); | 477 | NULL); |
223 | } | 478 | } |
224 | 479 | ||
225 | 480 | ||
226 | /** | 481 | /** |
227 | * The main function for the ats service. | 482 | * Define "main" method using service macro. |
228 | * | ||
229 | * @param argc number of arguments from the command line | ||
230 | * @param argv command line arguments | ||
231 | * @return 0 ok, 1 on error | ||
232 | */ | 483 | */ |
233 | int | 484 | GNUNET_SERVICE_MAIN |
234 | main (int argc, char *const *argv) | 485 | ("ats", |
235 | { | 486 | GNUNET_SERVICE_OPTION_NONE, |
236 | return (GNUNET_OK == | 487 | &run, |
237 | GNUNET_SERVICE_run (argc, argv, "ats", | 488 | &client_connect_cb, |
238 | GNUNET_SERVICE_OPTION_NONE, | 489 | &client_disconnect_cb, |
239 | &run, NULL)) ? 0 : 1; | 490 | NULL, |
240 | } | 491 | GNUNET_MQ_hd_fixed_size (ats_start, |
492 | GNUNET_MESSAGE_TYPE_ATS_START, | ||
493 | struct ClientStartMessage, | ||
494 | NULL), | ||
495 | GNUNET_MQ_hd_fixed_size (request_address, | ||
496 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, | ||
497 | struct RequestAddressMessage, | ||
498 | NULL), | ||
499 | GNUNET_MQ_hd_fixed_size (request_address_cancel, | ||
500 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL, | ||
501 | struct RequestAddressMessage, | ||
502 | NULL), | ||
503 | GNUNET_MQ_hd_fixed_size (request_address_list, | ||
504 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST, | ||
505 | struct AddressListRequestMessage, | ||
506 | NULL), | ||
507 | GNUNET_MQ_hd_var_size (address_add, | ||
508 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, | ||
509 | struct AddressAddMessage, | ||
510 | NULL), | ||
511 | GNUNET_MQ_hd_fixed_size (address_update, | ||
512 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, | ||
513 | struct AddressUpdateMessage, | ||
514 | NULL), | ||
515 | GNUNET_MQ_hd_fixed_size (address_destroyed, | ||
516 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, | ||
517 | struct AddressDestroyedMessage, | ||
518 | NULL), | ||
519 | GNUNET_MQ_hd_fixed_size (reservation_request, | ||
520 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, | ||
521 | struct ReservationRequestMessage, | ||
522 | NULL), | ||
523 | GNUNET_MQ_hd_var_size (preference_change, | ||
524 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, | ||
525 | struct ChangePreferenceMessage, | ||
526 | NULL), | ||
527 | GNUNET_MQ_hd_var_size (feedback, | ||
528 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, | ||
529 | struct FeedbackPreferenceMessage, | ||
530 | NULL), | ||
531 | GNUNET_MQ_handler_end ()); | ||
532 | |||
241 | 533 | ||
242 | /* end of gnunet-service-ats.c */ | 534 | /* end of gnunet-service-ats.c */ |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 44a4782d5..1a4a33206 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -347,13 +347,13 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
347 | * known and current performance information. It has a solver component | 347 | * known and current performance information. It has a solver component |
348 | * responsible for the resource allocation. It tells the solver about changes | 348 | * responsible for the resource allocation. It tells the solver about changes |
349 | * and receives updates when the solver changes the resource allocation. | 349 | * and receives updates when the solver changes the resource allocation. |
350 | * | ||
351 | * @param server handle to our server | ||
352 | */ | 350 | */ |
353 | void | 351 | void |
354 | GAS_addresses_init (struct GNUNET_SERVER_Handle *server) | 352 | GAS_addresses_init () |
355 | { | 353 | { |
356 | GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 354 | GSA_addresses |
355 | = GNUNET_CONTAINER_multipeermap_create (128, | ||
356 | GNUNET_NO); | ||
357 | update_addresses_stat (); | 357 | update_addresses_stat (); |
358 | } | 358 | } |
359 | 359 | ||
@@ -515,7 +515,7 @@ struct AddressIteration | |||
515 | /** | 515 | /** |
516 | * Actual handle to the client. | 516 | * Actual handle to the client. |
517 | */ | 517 | */ |
518 | struct GNUNET_SERVER_Client *client; | 518 | struct GNUNET_SERVICE_Client *client; |
519 | 519 | ||
520 | /** | 520 | /** |
521 | * Are we sending all addresses, or only those that are active? | 521 | * Are we sending all addresses, or only those that are active? |
@@ -558,30 +558,26 @@ transmit_req_addr (struct AddressIteration *ai, | |||
558 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 558 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
559 | 559 | ||
560 | { | 560 | { |
561 | struct GNUNET_MQ_Envelope *env; | ||
561 | struct PeerInformationMessage *msg; | 562 | struct PeerInformationMessage *msg; |
562 | char *addrp; | 563 | char *addrp; |
563 | size_t plugin_name_length; | 564 | size_t plugin_name_length; |
564 | size_t msize; | 565 | size_t msize; |
565 | struct GNUNET_SERVER_NotificationContext **uc; | ||
566 | struct GNUNET_SERVER_NotificationContext *nc; | ||
567 | 566 | ||
568 | if (NULL != plugin_name) | 567 | if (NULL != plugin_name) |
569 | plugin_name_length = strlen (plugin_name) + 1; | 568 | plugin_name_length = strlen (plugin_name) + 1; |
570 | else | 569 | else |
571 | plugin_name_length = 0; | 570 | plugin_name_length = 0; |
572 | msize = sizeof (struct PeerInformationMessage) + | 571 | msize = plugin_addr_len + plugin_name_length; |
573 | plugin_addr_len + plugin_name_length; | 572 | |
574 | char buf[msize] GNUNET_ALIGN; | 573 | GNUNET_assert (sizeof (struct PeerInformationMessage) + msize |
575 | 574 | < GNUNET_SERVER_MAX_MESSAGE_SIZE); | |
576 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 575 | env = GNUNET_MQ_msg_extra (msg, |
577 | msg = (struct PeerInformationMessage *) buf; | 576 | msize, |
578 | msg->header.size = htons (msize); | 577 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); |
579 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | ||
580 | msg->id = htonl (ai->id); | 578 | msg->id = htonl (ai->id); |
581 | if (NULL != id) | 579 | if (NULL != id) |
582 | msg->peer = *id; | 580 | msg->peer = *id; |
583 | else | ||
584 | memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity)); | ||
585 | msg->address_length = htons (plugin_addr_len); | 581 | msg->address_length = htons (plugin_addr_len); |
586 | msg->address_active = ntohl (active); | 582 | msg->address_active = ntohl (active); |
587 | msg->plugin_name_length = htons (plugin_name_length); | 583 | msg->plugin_name_length = htons (plugin_name_length); |
@@ -590,28 +586,16 @@ transmit_req_addr (struct AddressIteration *ai, | |||
590 | if (NULL != prop) | 586 | if (NULL != prop) |
591 | GNUNET_ATS_properties_hton (&msg->properties, | 587 | GNUNET_ATS_properties_hton (&msg->properties, |
592 | prop); | 588 | prop); |
593 | else | ||
594 | memset (&msg->properties, | ||
595 | 0, | ||
596 | sizeof (struct GNUNET_ATS_Properties)); | ||
597 | msg->address_local_info = htonl ((uint32_t) local_address_info); | 589 | msg->address_local_info = htonl ((uint32_t) local_address_info); |
598 | addrp = (char *) &msg[1]; | 590 | addrp = (char *) &msg[1]; |
599 | if (NULL != plugin_addr) | 591 | GNUNET_memcpy (addrp, |
600 | GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len); | 592 | plugin_addr, |
593 | plugin_addr_len); | ||
601 | if (NULL != plugin_name) | 594 | if (NULL != plugin_name) |
602 | strcpy (&addrp[plugin_addr_len], plugin_name); | 595 | strcpy (&addrp[plugin_addr_len], |
603 | uc = GNUNET_SERVER_client_get_user_context (ai->client, | 596 | plugin_name); |
604 | struct GNUNET_SERVER_NotificationContext *); | 597 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client), |
605 | if (NULL == uc) | 598 | env); |
606 | { | ||
607 | GNUNET_break (0); | ||
608 | return; | ||
609 | } | ||
610 | nc = *uc; | ||
611 | GNUNET_SERVER_notification_context_unicast (nc, | ||
612 | ai->client, | ||
613 | &msg->header, | ||
614 | GNUNET_NO); | ||
615 | } | 599 | } |
616 | 600 | ||
617 | 601 | ||
@@ -679,22 +663,18 @@ req_addr_peerinfo_it (void *cls, | |||
679 | /** | 663 | /** |
680 | * Handle 'address list request' messages from clients. | 664 | * Handle 'address list request' messages from clients. |
681 | * | 665 | * |
682 | * @param cls unused, NULL | 666 | * @param cls client that sent the request |
683 | * @param client client that sent the request | 667 | * @param alrm the request message |
684 | * @param message the request message | ||
685 | */ | 668 | */ |
686 | void | 669 | void |
687 | GAS_handle_request_address_list (void *cls, | 670 | GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, |
688 | struct GNUNET_SERVER_Client *client, | 671 | const struct AddressListRequestMessage *alrm) |
689 | const struct GNUNET_MessageHeader *message) | ||
690 | { | 672 | { |
691 | struct AddressIteration ai; | 673 | struct AddressIteration ai; |
692 | const struct AddressListRequestMessage *alrm; | ||
693 | struct GNUNET_PeerIdentity allzeros; | 674 | struct GNUNET_PeerIdentity allzeros; |
694 | 675 | ||
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
696 | "Received ADDRESSLIST_REQUEST message\n"); | 677 | "Received ADDRESSLIST_REQUEST message\n"); |
697 | alrm = (const struct AddressListRequestMessage *) message; | ||
698 | ai.all = ntohl (alrm->all); | 678 | ai.all = ntohl (alrm->all); |
699 | ai.id = ntohl (alrm->id); | 679 | ai.id = ntohl (alrm->id); |
700 | ai.client = client; | 680 | ai.client = client; |
@@ -728,8 +708,6 @@ GAS_handle_request_address_list (void *cls, | |||
728 | GNUNET_HELLO_ADDRESS_INFO_NONE, | 708 | GNUNET_HELLO_ADDRESS_INFO_NONE, |
729 | GNUNET_BANDWIDTH_ZERO, | 709 | GNUNET_BANDWIDTH_ZERO, |
730 | GNUNET_BANDWIDTH_ZERO); | 710 | GNUNET_BANDWIDTH_ZERO); |
731 | GNUNET_SERVER_receive_done (client, | ||
732 | GNUNET_OK); | ||
733 | } | 711 | } |
734 | 712 | ||
735 | 713 | ||
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 274985e66..61de1cd31 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -30,6 +30,7 @@ | |||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_ats_service.h" | 31 | #include "gnunet_ats_service.h" |
32 | #include "gnunet-service-ats.h" | 32 | #include "gnunet-service-ats.h" |
33 | #include "ats.h" | ||
33 | 34 | ||
34 | /** | 35 | /** |
35 | * NOTE: Do not change this documentation. This documentation is based on | 36 | * NOTE: Do not change this documentation. This documentation is based on |
@@ -366,11 +367,9 @@ extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses; | |||
366 | /** | 367 | /** |
367 | * Initialize address subsystem. The addresses subsystem manages the addresses | 368 | * Initialize address subsystem. The addresses subsystem manages the addresses |
368 | * known and current performance information. | 369 | * known and current performance information. |
369 | * | ||
370 | * @param server handle to our server | ||
371 | */ | 370 | */ |
372 | void | 371 | void |
373 | GAS_addresses_init (struct GNUNET_SERVER_Handle *server); | 372 | GAS_addresses_init (void); |
374 | 373 | ||
375 | 374 | ||
376 | /** | 375 | /** |
@@ -475,14 +474,12 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | |||
475 | /** | 474 | /** |
476 | * Handle 'address list request' messages from clients. | 475 | * Handle 'address list request' messages from clients. |
477 | * | 476 | * |
478 | * @param cls unused, NULL | ||
479 | * @param client client that sent the request | 477 | * @param client client that sent the request |
480 | * @param message the request message | 478 | * @param alrm the request message |
481 | */ | 479 | */ |
482 | void | 480 | void |
483 | GAS_handle_request_address_list (void *cls, | 481 | GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, |
484 | struct GNUNET_SERVER_Client *client, | 482 | const struct AddressListRequestMessage *alrm); |
485 | const struct GNUNET_MessageHeader *message); | ||
486 | 483 | ||
487 | 484 | ||
488 | #endif | 485 | #endif |
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c index 2cf434c70..c47ee03e6 100644 --- a/src/ats/gnunet-service-ats_connectivity.c +++ b/src/ats/gnunet-service-ats_connectivity.c | |||
@@ -40,7 +40,7 @@ struct ConnectionRequest | |||
40 | /** | 40 | /** |
41 | * Client that made the request. | 41 | * Client that made the request. |
42 | */ | 42 | */ |
43 | struct GNUNET_SERVER_Client *client; | 43 | struct GNUNET_SERVICE_Client *client; |
44 | 44 | ||
45 | /* TODO: allow client to express a 'strength' for this request */ | 45 | /* TODO: allow client to express a 'strength' for this request */ |
46 | }; | 46 | }; |
@@ -75,17 +75,13 @@ GAS_connectivity_has_peer (void *cls, | |||
75 | /** | 75 | /** |
76 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients. | 76 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients. |
77 | * | 77 | * |
78 | * @param cls unused, NULL | ||
79 | * @param client client that sent the request | 78 | * @param client client that sent the request |
80 | * @param message the request message | 79 | * @param message the request message |
81 | */ | 80 | */ |
82 | void | 81 | void |
83 | GAS_handle_request_address (void *cls, | 82 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, |
84 | struct GNUNET_SERVER_Client *client, | 83 | const struct RequestAddressMessage *msg) |
85 | const struct GNUNET_MessageHeader *message) | ||
86 | { | 84 | { |
87 | const struct RequestAddressMessage *msg = | ||
88 | (const struct RequestAddressMessage *) message; | ||
89 | struct ConnectionRequest *cr; | 85 | struct ConnectionRequest *cr; |
90 | 86 | ||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -99,7 +95,6 @@ GAS_handle_request_address (void *cls, | |||
99 | cr, | 95 | cr, |
100 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 96 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
101 | GAS_plugin_request_connect_start (&msg->peer); | 97 | GAS_plugin_request_connect_start (&msg->peer); |
102 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
103 | } | 98 | } |
104 | 99 | ||
105 | 100 | ||
@@ -117,7 +112,7 @@ free_matching_requests (void *cls, | |||
117 | const struct GNUNET_PeerIdentity *pid, | 112 | const struct GNUNET_PeerIdentity *pid, |
118 | void *value) | 113 | void *value) |
119 | { | 114 | { |
120 | struct GNUNET_SERVER_Client *client = cls; | 115 | struct GNUNET_SERVICE_Client *client = cls; |
121 | struct ConnectionRequest *cr = value; | 116 | struct ConnectionRequest *cr = value; |
122 | 117 | ||
123 | if (cr->client == client) | 118 | if (cr->client == client) |
@@ -140,18 +135,13 @@ free_matching_requests (void *cls, | |||
140 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL messages | 135 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL messages |
141 | * from clients. | 136 | * from clients. |
142 | * | 137 | * |
143 | * @param cls unused, NULL | 138 | * @param client the client that sent the request |
144 | * @param client client that sent the request | 139 | * @param msg the request message |
145 | * @param message the request message | ||
146 | */ | 140 | */ |
147 | void | 141 | void |
148 | GAS_handle_request_address_cancel (void *cls, | 142 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, |
149 | struct GNUNET_SERVER_Client *client, | 143 | const struct RequestAddressMessage *msg) |
150 | const struct GNUNET_MessageHeader *message) | ||
151 | { | 144 | { |
152 | const struct RequestAddressMessage *msg = | ||
153 | (const struct RequestAddressMessage *) message; | ||
154 | |||
155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
156 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", | 146 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", |
157 | GNUNET_i2s (&msg->peer)); | 147 | GNUNET_i2s (&msg->peer)); |
@@ -160,7 +150,6 @@ GAS_handle_request_address_cancel (void *cls, | |||
160 | &msg->peer, | 150 | &msg->peer, |
161 | &free_matching_requests, | 151 | &free_matching_requests, |
162 | client); | 152 | client); |
163 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
164 | } | 153 | } |
165 | 154 | ||
166 | 155 | ||
@@ -171,7 +160,7 @@ GAS_handle_request_address_cancel (void *cls, | |||
171 | * @param client handle of the (now dead) client | 160 | * @param client handle of the (now dead) client |
172 | */ | 161 | */ |
173 | void | 162 | void |
174 | GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client) | 163 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) |
175 | { | 164 | { |
176 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | 165 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, |
177 | &free_matching_requests, | 166 | &free_matching_requests, |
@@ -185,7 +174,9 @@ GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client) | |||
185 | void | 174 | void |
186 | GAS_connectivity_init () | 175 | GAS_connectivity_init () |
187 | { | 176 | { |
188 | connection_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO); | 177 | connection_requests |
178 | = GNUNET_CONTAINER_multipeermap_create (32, | ||
179 | GNUNET_NO); | ||
189 | } | 180 | } |
190 | 181 | ||
191 | 182 | ||
diff --git a/src/ats/gnunet-service-ats_connectivity.h b/src/ats/gnunet-service-ats_connectivity.h index f10f9de0e..b8f194b36 100644 --- a/src/ats/gnunet-service-ats_connectivity.h +++ b/src/ats/gnunet-service-ats_connectivity.h | |||
@@ -26,6 +26,8 @@ | |||
26 | #ifndef GNUNET_SERVICE_ATS_CONNECTIVITY_H | 26 | #ifndef GNUNET_SERVICE_ATS_CONNECTIVITY_H |
27 | #define GNUNET_SERVICE_ATS_CONNECTIVITY_H | 27 | #define GNUNET_SERVICE_ATS_CONNECTIVITY_H |
28 | 28 | ||
29 | #include "ats.h" | ||
30 | |||
29 | 31 | ||
30 | /** | 32 | /** |
31 | * Is the given peer in the list of peers for which we | 33 | * Is the given peer in the list of peers for which we |
@@ -43,27 +45,23 @@ GAS_connectivity_has_peer (void *cls, | |||
43 | /** | 45 | /** |
44 | * Handle 'request address' messages from clients. | 46 | * Handle 'request address' messages from clients. |
45 | * | 47 | * |
46 | * @param cls unused, NULL | ||
47 | * @param client client that sent the request | 48 | * @param client client that sent the request |
48 | * @param message the request message | 49 | * @param msg the request message |
49 | */ | 50 | */ |
50 | void | 51 | void |
51 | GAS_handle_request_address (void *cls, | 52 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, |
52 | struct GNUNET_SERVER_Client *client, | 53 | const struct RequestAddressMessage *msg); |
53 | const struct GNUNET_MessageHeader *message); | ||
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Cancel 'request address' messages from clients. | 57 | * Cancel 'request address' messages from clients. |
58 | * | 58 | * |
59 | * @param cls unused, NULL | ||
60 | * @param client client that sent the request | 59 | * @param client client that sent the request |
61 | * @param message the request message | 60 | * @param msg the request message |
62 | */ | 61 | */ |
63 | void | 62 | void |
64 | GAS_handle_request_address_cancel (void *cls, | 63 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, |
65 | struct GNUNET_SERVER_Client *client, | 64 | const struct RequestAddressMessage *msg); |
66 | const struct GNUNET_MessageHeader *message); | ||
67 | 65 | ||
68 | 66 | ||
69 | /** | 67 | /** |
@@ -73,7 +71,7 @@ GAS_handle_request_address_cancel (void *cls, | |||
73 | * @param client handle of the (now dead) client | 71 | * @param client handle of the (now dead) client |
74 | */ | 72 | */ |
75 | void | 73 | void |
76 | GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client); | 74 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client); |
77 | 75 | ||
78 | 76 | ||
79 | /** | 77 | /** |
diff --git a/src/ats/gnunet-service-ats_feedback.c b/src/ats/gnunet-service-ats_feedback.c deleted file mode 100644 index deb8e3d5d..000000000 --- a/src/ats/gnunet-service-ats_feedback.c +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2011-2015 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/gnunet-service-ats_feedback.c | ||
22 | * @brief ats service, handling of feedback | ||
23 | * @author Matthias Wachs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet-service-ats_plugins.h" | ||
28 | #include "gnunet-service-ats_feedback.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Change the preference for a peer | ||
34 | * | ||
35 | * @param application the client sending this request | ||
36 | * @param peer the peer id | ||
37 | * @param scope the time interval for this feedback: [now - scope .. now] | ||
38 | * @param kind the preference kind to change | ||
39 | * @param score_abs the new preference score | ||
40 | */ | ||
41 | static void | ||
42 | preference_feedback (struct GNUNET_SERVER_Client *application, | ||
43 | const struct GNUNET_PeerIdentity *peer, | ||
44 | const struct GNUNET_TIME_Relative scope, | ||
45 | enum GNUNET_ATS_PreferenceKind kind, | ||
46 | float score_abs) | ||
47 | { | ||
48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
49 | "Received PREFERENCE FEEDBACK for peer `%s'\n", | ||
50 | GNUNET_i2s (peer)); | ||
51 | GAS_plugin_notify_feedback (application, | ||
52 | peer, | ||
53 | scope, | ||
54 | kind, | ||
55 | score_abs); | ||
56 | } | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Handle 'preference feedback' messages from clients. | ||
61 | * | ||
62 | * @param cls unused, NULL | ||
63 | * @param client client that sent the request | ||
64 | * @param message the request message | ||
65 | */ | ||
66 | void | ||
67 | GAS_handle_feedback (void *cls, | ||
68 | struct GNUNET_SERVER_Client *client, | ||
69 | const struct GNUNET_MessageHeader *message) | ||
70 | { | ||
71 | const struct FeedbackPreferenceMessage *msg; | ||
72 | const struct PreferenceInformation *pi; | ||
73 | uint16_t msize; | ||
74 | uint32_t nump; | ||
75 | uint32_t i; | ||
76 | |||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
78 | "Received PREFERENCE_FEEDBACK message\n"); | ||
79 | msize = ntohs (message->size); | ||
80 | if (msize < sizeof (struct FeedbackPreferenceMessage)) | ||
81 | { | ||
82 | GNUNET_break (0); | ||
83 | GNUNET_SERVER_receive_done (client, | ||
84 | GNUNET_SYSERR); | ||
85 | return; | ||
86 | } | ||
87 | msg = (const struct FeedbackPreferenceMessage *) message; | ||
88 | nump = ntohl (msg->num_feedback); | ||
89 | if (msize != | ||
90 | sizeof (struct FeedbackPreferenceMessage) + | ||
91 | nump * sizeof (struct PreferenceInformation)) | ||
92 | { | ||
93 | GNUNET_break (0); | ||
94 | GNUNET_SERVER_receive_done (client, | ||
95 | GNUNET_SYSERR); | ||
96 | return; | ||
97 | } | ||
98 | if (GNUNET_NO == | ||
99 | GNUNET_CONTAINER_multipeermap_contains (GSA_addresses, | ||
100 | &msg->peer)) | ||
101 | { | ||
102 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
103 | "Received PREFERENCE FEEDBACK for unknown peer `%s'\n", | ||
104 | GNUNET_i2s (&msg->peer)); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | GNUNET_STATISTICS_update (GSA_stats, | ||
109 | "# preference feedbacks requests processed", | ||
110 | 1, | ||
111 | GNUNET_NO); | ||
112 | pi = (const struct PreferenceInformation *) &msg[1]; | ||
113 | for (i = 0; i < nump; i++) | ||
114 | preference_feedback (client, | ||
115 | &msg->peer, | ||
116 | GNUNET_TIME_relative_ntoh(msg->scope), | ||
117 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), | ||
118 | pi[i].preference_value); | ||
119 | GNUNET_SERVER_receive_done (client, | ||
120 | GNUNET_OK); | ||
121 | } | ||
122 | |||
123 | /* end of gnunet-service-ats_feedback.c */ | ||
diff --git a/src/ats/gnunet-service-ats_feedback.h b/src/ats/gnunet-service-ats_feedback.h deleted file mode 100644 index 0ecb5d9b4..000000000 --- a/src/ats/gnunet-service-ats_feedback.h +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2011-2014 GNUnet e.V. | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/gnunet-service-ats_feedback.h | ||
22 | * @brief handle client feedback | ||
23 | * @author Matthias Wachs | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #ifndef GNUNET_SERVICE_ATS_FEEDBACK_H | ||
27 | #define GNUNET_SERVICE_ATS_FEEDBACK_H | ||
28 | |||
29 | #include "gnunet_util_lib.h" | ||
30 | |||
31 | /** | ||
32 | * Handle 'preference feedback' messages from clients. | ||
33 | * | ||
34 | * @param cls unused, NULL | ||
35 | * @param client client that sent the request | ||
36 | * @param message the request message | ||
37 | */ | ||
38 | void | ||
39 | GAS_handle_feedback (void *cls, | ||
40 | struct GNUNET_SERVER_Client *client, | ||
41 | const struct GNUNET_MessageHeader *message); | ||
42 | |||
43 | #endif | ||
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 8702716f9..5252a71bc 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -36,12 +36,12 @@ | |||
36 | /** | 36 | /** |
37 | * Context for sending messages to performance clients without PIC. | 37 | * Context for sending messages to performance clients without PIC. |
38 | */ | 38 | */ |
39 | static struct GNUNET_SERVER_NotificationContext *nc_no_pic; | 39 | static struct GNUNET_NotificationContext *nc_no_pic; |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Context for sending messages to performance clients with PIC. | 42 | * Context for sending messages to performance clients with PIC. |
43 | */ | 43 | */ |
44 | static struct GNUNET_SERVER_NotificationContext *nc_pic; | 44 | static struct GNUNET_NotificationContext *nc_pic; |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -63,7 +63,7 @@ static struct GNUNET_SERVER_NotificationContext *nc_pic; | |||
63 | * @param bandwidth_in assigned inbound bandwidth | 63 | * @param bandwidth_in assigned inbound bandwidth |
64 | */ | 64 | */ |
65 | static void | 65 | static void |
66 | notify_client (struct GNUNET_SERVER_Client *client, | 66 | notify_client (struct GNUNET_SERVICE_Client *client, |
67 | const struct GNUNET_PeerIdentity *peer, | 67 | const struct GNUNET_PeerIdentity *peer, |
68 | const char *plugin_name, | 68 | const char *plugin_name, |
69 | const void *plugin_addr, | 69 | const void *plugin_addr, |
@@ -81,8 +81,6 @@ notify_client (struct GNUNET_SERVER_Client *client, | |||
81 | plugin_addr_len + | 81 | plugin_addr_len + |
82 | plugin_name_length; | 82 | plugin_name_length; |
83 | char buf[msize] GNUNET_ALIGN; | 83 | char buf[msize] GNUNET_ALIGN; |
84 | struct GNUNET_SERVER_NotificationContext **uc; | ||
85 | struct GNUNET_SERVER_NotificationContext *nc; | ||
86 | char *addrp; | 84 | char *addrp; |
87 | 85 | ||
88 | if (NULL != prop) | 86 | if (NULL != prop) |
@@ -111,24 +109,17 @@ notify_client (struct GNUNET_SERVER_Client *client, | |||
111 | strcpy (&addrp[plugin_addr_len], plugin_name); | 109 | strcpy (&addrp[plugin_addr_len], plugin_name); |
112 | if (NULL == client) | 110 | if (NULL == client) |
113 | { | 111 | { |
114 | GNUNET_SERVER_notification_context_broadcast (nc_pic, | 112 | GNUNET_notification_context_broadcast (nc_pic, |
115 | &msg->header, | 113 | &msg->header, |
116 | GNUNET_YES); | 114 | GNUNET_YES); |
117 | } | 115 | } |
118 | else | 116 | else |
119 | { | 117 | { |
120 | uc = GNUNET_SERVER_client_get_user_context (client, | 118 | struct GNUNET_MQ_Envelope *env; |
121 | struct GNUNET_SERVER_NotificationContext *); | 119 | |
122 | if (NULL == uc) | 120 | env = GNUNET_MQ_msg_copy (&msg->header); |
123 | { | 121 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
124 | GNUNET_break (0); | 122 | env); |
125 | return; | ||
126 | } | ||
127 | nc = *uc; | ||
128 | GNUNET_SERVER_notification_context_unicast (nc, | ||
129 | client, | ||
130 | &msg->header, | ||
131 | GNUNET_YES); | ||
132 | } | 123 | } |
133 | } | 124 | } |
134 | 125 | ||
@@ -183,7 +174,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
183 | /** | 174 | /** |
184 | * Iterator for called from #GAS_addresses_get_peer_info() | 175 | * Iterator for called from #GAS_addresses_get_peer_info() |
185 | * | 176 | * |
186 | * @param cls closure with the `struct GNUNET_SERVER_Client *` to inform. | 177 | * @param cls closure with the `struct GNUNET_SERVICE_Client *` to inform. |
187 | * @param id the peer id | 178 | * @param id the peer id |
188 | * @param plugin_name plugin name | 179 | * @param plugin_name plugin name |
189 | * @param plugin_addr address | 180 | * @param plugin_addr address |
@@ -206,7 +197,7 @@ peerinfo_it (void *cls, | |||
206 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 197 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
207 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 198 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
208 | { | 199 | { |
209 | struct GNUNET_SERVER_Client *client = cls; | 200 | struct GNUNET_SERVICE_Client *client = cls; |
210 | 201 | ||
211 | if (NULL == id) | 202 | if (NULL == id) |
212 | return; | 203 | return; |
@@ -237,25 +228,24 @@ peerinfo_it (void *cls, | |||
237 | * @param flag flag specifying the type of the client | 228 | * @param flag flag specifying the type of the client |
238 | */ | 229 | */ |
239 | void | 230 | void |
240 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | 231 | GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, |
241 | enum StartFlag flag) | 232 | enum StartFlag flag) |
242 | { | 233 | { |
234 | struct GNUNET_MQ_Handle *mq; | ||
235 | |||
236 | mq = GNUNET_SERVICE_client_get_mq (client); | ||
243 | if (START_FLAG_PERFORMANCE_WITH_PIC == flag) | 237 | if (START_FLAG_PERFORMANCE_WITH_PIC == flag) |
244 | { | 238 | { |
245 | GNUNET_SERVER_notification_context_add (nc_pic, | 239 | GNUNET_notification_context_add (nc_pic, |
246 | client); | 240 | mq); |
247 | GNUNET_SERVER_client_set_user_context (client, | ||
248 | &nc_pic); | ||
249 | GAS_addresses_get_peer_info (NULL, | 241 | GAS_addresses_get_peer_info (NULL, |
250 | &peerinfo_it, | 242 | &peerinfo_it, |
251 | client); | 243 | client); |
252 | } | 244 | } |
253 | else | 245 | else |
254 | { | 246 | { |
255 | GNUNET_SERVER_notification_context_add (nc_no_pic, | 247 | GNUNET_notification_context_add (nc_no_pic, |
256 | client); | 248 | mq); |
257 | GNUNET_SERVER_client_set_user_context (client, | ||
258 | &nc_no_pic); | ||
259 | } | 249 | } |
260 | } | 250 | } |
261 | 251 | ||
@@ -266,10 +256,10 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | |||
266 | * @param server handle to our server | 256 | * @param server handle to our server |
267 | */ | 257 | */ |
268 | void | 258 | void |
269 | GAS_performance_init (struct GNUNET_SERVER_Handle *server) | 259 | GAS_performance_init () |
270 | { | 260 | { |
271 | nc_no_pic = GNUNET_SERVER_notification_context_create (server, 32); | 261 | nc_no_pic = GNUNET_notification_context_create (32); |
272 | nc_pic = GNUNET_SERVER_notification_context_create (server, 32); | 262 | nc_pic = GNUNET_notification_context_create (32); |
273 | } | 263 | } |
274 | 264 | ||
275 | 265 | ||
@@ -279,9 +269,9 @@ GAS_performance_init (struct GNUNET_SERVER_Handle *server) | |||
279 | void | 269 | void |
280 | GAS_performance_done () | 270 | GAS_performance_done () |
281 | { | 271 | { |
282 | GNUNET_SERVER_notification_context_destroy (nc_no_pic); | 272 | GNUNET_notification_context_destroy (nc_no_pic); |
283 | nc_no_pic = NULL; | 273 | nc_no_pic = NULL; |
284 | GNUNET_SERVER_notification_context_destroy (nc_pic); | 274 | GNUNET_notification_context_destroy (nc_pic); |
285 | nc_pic = NULL; | 275 | nc_pic = NULL; |
286 | } | 276 | } |
287 | 277 | ||
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index bbaa8bc2b..7958a84e5 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -68,7 +68,7 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
68 | * @param flag flag specifying the type of the client | 68 | * @param flag flag specifying the type of the client |
69 | */ | 69 | */ |
70 | void | 70 | void |
71 | GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | 71 | GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, |
72 | enum StartFlag flag); | 72 | enum StartFlag flag); |
73 | 73 | ||
74 | 74 | ||
@@ -79,7 +79,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | |||
79 | * @param addresses the address handle to use | 79 | * @param addresses the address handle to use |
80 | */ | 80 | */ |
81 | void | 81 | void |
82 | GAS_performance_init (struct GNUNET_SERVER_Handle *server); | 82 | GAS_performance_init (void); |
83 | 83 | ||
84 | 84 | ||
85 | /** | 85 | /** |
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index c2388e28b..f70c4cd9b 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c | |||
@@ -510,7 +510,7 @@ GAS_plugin_delete_address (struct ATS_Address *address) | |||
510 | * @param score_abs degree of the appreciation | 510 | * @param score_abs degree of the appreciation |
511 | */ | 511 | */ |
512 | void | 512 | void |
513 | GAS_plugin_notify_feedback (struct GNUNET_SERVER_Client *application, | 513 | GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, |
514 | const struct GNUNET_PeerIdentity *peer, | 514 | const struct GNUNET_PeerIdentity *peer, |
515 | const struct GNUNET_TIME_Relative scope, | 515 | const struct GNUNET_TIME_Relative scope, |
516 | enum GNUNET_ATS_PreferenceKind kind, | 516 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h index 3f3261767..8b12416c6 100644 --- a/src/ats/gnunet-service-ats_plugins.h +++ b/src/ats/gnunet-service-ats_plugins.h | |||
@@ -105,7 +105,7 @@ GAS_plugin_delete_address (struct ATS_Address *address); | |||
105 | * @param score_abs degree of the appreciation | 105 | * @param score_abs degree of the appreciation |
106 | */ | 106 | */ |
107 | void | 107 | void |
108 | GAS_plugin_notify_feedback (struct GNUNET_SERVER_Client *application, | 108 | GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, |
109 | const struct GNUNET_PeerIdentity *peer, | 109 | const struct GNUNET_PeerIdentity *peer, |
110 | const struct GNUNET_TIME_Relative scope, | 110 | const struct GNUNET_TIME_Relative scope, |
111 | enum GNUNET_ATS_PreferenceKind kind, | 111 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index 64779bbca..9f11dc6a8 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c | |||
@@ -132,7 +132,7 @@ struct PreferenceClient | |||
132 | /** | 132 | /** |
133 | * Client handle | 133 | * Client handle |
134 | */ | 134 | */ |
135 | struct GNUNET_SERVER_Client *client; | 135 | struct GNUNET_SERVICE_Client *client; |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * Mapping peer identities to `struct PreferencePeer` entry | 138 | * Mapping peer identities to `struct PreferencePeer` entry |
@@ -553,7 +553,7 @@ update_iterator (void *cls, | |||
553 | * @param score_abs the normalized score | 553 | * @param score_abs the normalized score |
554 | */ | 554 | */ |
555 | static void | 555 | static void |
556 | update_preference (struct GNUNET_SERVER_Client *client, | 556 | update_preference (struct GNUNET_SERVICE_Client *client, |
557 | const struct GNUNET_PeerIdentity *peer, | 557 | const struct GNUNET_PeerIdentity *peer, |
558 | enum GNUNET_ATS_PreferenceKind kind, | 558 | enum GNUNET_ATS_PreferenceKind kind, |
559 | float score_abs) | 559 | float score_abs) |
@@ -646,41 +646,17 @@ update_preference (struct GNUNET_SERVER_Client *client, | |||
646 | /** | 646 | /** |
647 | * Handle 'preference change' messages from clients. | 647 | * Handle 'preference change' messages from clients. |
648 | * | 648 | * |
649 | * @param cls unused, NULL | 649 | * @param client the client that sent the request |
650 | * @param client client that sent the request | 650 | * @param msg the request message |
651 | * @param message the request message | ||
652 | */ | 651 | */ |
653 | void | 652 | void |
654 | GAS_handle_preference_change (void *cls, | 653 | GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, |
655 | struct GNUNET_SERVER_Client *client, | 654 | const struct ChangePreferenceMessage *msg) |
656 | const struct GNUNET_MessageHeader *message) | ||
657 | { | 655 | { |
658 | const struct ChangePreferenceMessage *msg; | ||
659 | const struct PreferenceInformation *pi; | 656 | const struct PreferenceInformation *pi; |
660 | uint16_t msize; | ||
661 | uint32_t nump; | 657 | uint32_t nump; |
662 | uint32_t i; | ||
663 | 658 | ||
664 | msize = ntohs (message->size); | ||
665 | if (msize < sizeof (struct ChangePreferenceMessage)) | ||
666 | { | ||
667 | GNUNET_break (0); | ||
668 | GNUNET_SERVER_receive_done (client, | ||
669 | GNUNET_SYSERR); | ||
670 | return; | ||
671 | } | ||
672 | msg = (const struct ChangePreferenceMessage *) message; | ||
673 | nump = ntohl (msg->num_preferences); | 659 | nump = ntohl (msg->num_preferences); |
674 | if ( (msize != | ||
675 | sizeof (struct ChangePreferenceMessage) + | ||
676 | nump * sizeof (struct PreferenceInformation)) || | ||
677 | (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) ) | ||
678 | { | ||
679 | GNUNET_break (0); | ||
680 | GNUNET_SERVER_receive_done (client, | ||
681 | GNUNET_SYSERR); | ||
682 | return; | ||
683 | } | ||
684 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
685 | "Received PREFERENCE_CHANGE message for peer `%s'\n", | 661 | "Received PREFERENCE_CHANGE message for peer `%s'\n", |
686 | GNUNET_i2s (&msg->peer)); | 662 | GNUNET_i2s (&msg->peer)); |
@@ -690,14 +666,12 @@ GAS_handle_preference_change (void *cls, | |||
690 | GNUNET_NO); | 666 | GNUNET_NO); |
691 | pi = (const struct PreferenceInformation *) &msg[1]; | 667 | pi = (const struct PreferenceInformation *) &msg[1]; |
692 | GAS_plugin_solver_lock (); | 668 | GAS_plugin_solver_lock (); |
693 | for (i = 0; i < nump; i++) | 669 | for (uint32_t i = 0; i < nump; i++) |
694 | update_preference (client, | 670 | update_preference (client, |
695 | &msg->peer, | 671 | &msg->peer, |
696 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), | 672 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), |
697 | pi[i].preference_value); | 673 | pi[i].preference_value); |
698 | GAS_plugin_solver_unlock (); | 674 | GAS_plugin_solver_unlock (); |
699 | GNUNET_SERVER_receive_done (client, | ||
700 | GNUNET_OK); | ||
701 | } | 675 | } |
702 | 676 | ||
703 | 677 | ||
@@ -782,7 +756,7 @@ GAS_preference_get_by_peer (void *cls, | |||
782 | * @param client the client | 756 | * @param client the client |
783 | */ | 757 | */ |
784 | void | 758 | void |
785 | GAS_preference_client_disconnect (struct GNUNET_SERVER_Client *client) | 759 | GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client) |
786 | { | 760 | { |
787 | struct PreferenceClient *c_cur; | 761 | struct PreferenceClient *c_cur; |
788 | 762 | ||
diff --git a/src/ats/gnunet-service-ats_preferences.h b/src/ats/gnunet-service-ats_preferences.h index 3a483d816..fe01aa573 100644 --- a/src/ats/gnunet-service-ats_preferences.h +++ b/src/ats/gnunet-service-ats_preferences.h | |||
@@ -46,14 +46,12 @@ | |||
46 | /** | 46 | /** |
47 | * Handle 'preference change' messages from clients. | 47 | * Handle 'preference change' messages from clients. |
48 | * | 48 | * |
49 | * @param cls unused, NULL | 49 | * @param client the client that sent the request |
50 | * @param client client that sent the request | 50 | * @param msg the request message |
51 | * @param message the request message | ||
52 | */ | 51 | */ |
53 | void | 52 | void |
54 | GAS_handle_preference_change (void *cls, | 53 | GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, |
55 | struct GNUNET_SERVER_Client *client, | 54 | const struct ChangePreferenceMessage *msg); |
56 | const struct GNUNET_MessageHeader *message); | ||
57 | 55 | ||
58 | 56 | ||
59 | /** | 57 | /** |
@@ -89,7 +87,7 @@ GAS_preference_get_by_peer (void *cls, | |||
89 | * @param client the disconnecting client | 87 | * @param client the disconnecting client |
90 | */ | 88 | */ |
91 | void | 89 | void |
92 | GAS_preference_client_disconnect (struct GNUNET_SERVER_Client *client); | 90 | GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client); |
93 | 91 | ||
94 | 92 | ||
95 | #endif | 93 | #endif |
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index 97098c819..95952e96f 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c | |||
@@ -138,63 +138,43 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
138 | /** | 138 | /** |
139 | * Handle 'reservation request' messages from clients. | 139 | * Handle 'reservation request' messages from clients. |
140 | * | 140 | * |
141 | * @param cls unused, NULL | ||
142 | * @param client client that sent the request | 141 | * @param client client that sent the request |
143 | * @param message the request message | 142 | * @param msg the request message |
144 | */ | 143 | */ |
145 | void | 144 | void |
146 | GAS_handle_reservation_request (void *cls, | 145 | GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, |
147 | struct GNUNET_SERVER_Client *client, | 146 | const struct ReservationRequestMessage *msg) |
148 | const struct GNUNET_MessageHeader *message) | ||
149 | { | 147 | { |
150 | const struct ReservationRequestMessage *msg = | 148 | struct GNUNET_MQ_Envelope *env; |
151 | (const struct ReservationRequestMessage *) message; | 149 | struct ReservationResultMessage *result; |
152 | struct ReservationResultMessage result; | ||
153 | int32_t amount; | 150 | int32_t amount; |
154 | struct GNUNET_TIME_Relative res_delay; | 151 | struct GNUNET_TIME_Relative res_delay; |
155 | struct GNUNET_SERVER_NotificationContext **uc; | ||
156 | struct GNUNET_SERVER_NotificationContext *nc; | ||
157 | 152 | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
159 | "Received RESERVATION_REQUEST message\n"); | 154 | "Received RESERVATION_REQUEST message\n"); |
160 | uc = GNUNET_SERVER_client_get_user_context (client, | ||
161 | struct GNUNET_SERVER_NotificationContext *); | ||
162 | if (NULL == uc) | ||
163 | { | ||
164 | GNUNET_break (0); | ||
165 | return; | ||
166 | } | ||
167 | nc = *uc; | ||
168 | amount = (int32_t) ntohl (msg->amount); | 155 | amount = (int32_t) ntohl (msg->amount); |
169 | res_delay = reservations_reserve (&msg->peer, amount); | 156 | res_delay = reservations_reserve (&msg->peer, amount); |
170 | if (res_delay.rel_value_us > 0) | 157 | if (res_delay.rel_value_us > 0) |
171 | amount = 0; | 158 | amount = 0; |
172 | result.header.size = htons (sizeof (struct ReservationResultMessage)); | 159 | env = GNUNET_MQ_msg (result, |
173 | result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); | 160 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); |
174 | result.amount = htonl (amount); | 161 | result->amount = htonl (amount); |
175 | result.peer = msg->peer; | 162 | result->peer = msg->peer; |
176 | result.res_delay = GNUNET_TIME_relative_hton (res_delay); | 163 | result->res_delay = GNUNET_TIME_relative_hton (res_delay); |
177 | GNUNET_STATISTICS_update (GSA_stats, | 164 | GNUNET_STATISTICS_update (GSA_stats, |
178 | "# reservation requests processed", | 165 | "# reservation requests processed", |
179 | 1, | 166 | 1, |
180 | GNUNET_NO); | 167 | GNUNET_NO); |
181 | 168 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | |
182 | GNUNET_SERVER_notification_context_unicast (nc, | 169 | env); |
183 | client, | ||
184 | &result.header, | ||
185 | GNUNET_NO); | ||
186 | GNUNET_SERVER_receive_done (client, | ||
187 | GNUNET_OK); | ||
188 | } | 170 | } |
189 | 171 | ||
190 | 172 | ||
191 | /** | 173 | /** |
192 | * Initialize reservations subsystem. | 174 | * Initialize reservations subsystem. |
193 | * | ||
194 | * @param server handle to our server | ||
195 | */ | 175 | */ |
196 | void | 176 | void |
197 | GAS_reservations_init (struct GNUNET_SERVER_Handle *server) | 177 | GAS_reservations_init () |
198 | { | 178 | { |
199 | trackers = GNUNET_CONTAINER_multipeermap_create (128, | 179 | trackers = GNUNET_CONTAINER_multipeermap_create (128, |
200 | GNUNET_NO); | 180 | GNUNET_NO); |
@@ -211,7 +191,8 @@ GAS_reservations_init (struct GNUNET_SERVER_Handle *server) | |||
211 | */ | 191 | */ |
212 | static int | 192 | static int |
213 | free_tracker (void *cls, | 193 | free_tracker (void *cls, |
214 | const struct GNUNET_PeerIdentity *key, void *value) | 194 | const struct GNUNET_PeerIdentity *key, |
195 | void *value) | ||
215 | { | 196 | { |
216 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; | 197 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; |
217 | 198 | ||
diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h index cc51e82a5..ec28053b5 100644 --- a/src/ats/gnunet-service-ats_reservations.h +++ b/src/ats/gnunet-service-ats_reservations.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #define GNUNET_SERVICE_ATS_RESERVATIONS_H | 27 | #define GNUNET_SERVICE_ATS_RESERVATIONS_H |
28 | 28 | ||
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "ats.h" | ||
30 | 31 | ||
31 | 32 | ||
32 | /** | 33 | /** |
@@ -46,14 +47,12 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
46 | /** | 47 | /** |
47 | * Handle 'reservation request' messages from clients. | 48 | * Handle 'reservation request' messages from clients. |
48 | * | 49 | * |
49 | * @param cls unused, NULL | ||
50 | * @param client client that sent the request | 50 | * @param client client that sent the request |
51 | * @param message the request message | 51 | * @param message the request message |
52 | */ | 52 | */ |
53 | void | 53 | void |
54 | GAS_handle_reservation_request (void *cls, | 54 | GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, |
55 | struct GNUNET_SERVER_Client *client, | 55 | const struct ReservationRequestMessage *message); |
56 | const struct GNUNET_MessageHeader *message); | ||
57 | 56 | ||
58 | 57 | ||
59 | /** | 58 | /** |
@@ -62,7 +61,7 @@ GAS_handle_reservation_request (void *cls, | |||
62 | * @param server handle to our server | 61 | * @param server handle to our server |
63 | */ | 62 | */ |
64 | void | 63 | void |
65 | GAS_reservations_init (struct GNUNET_SERVER_Handle *server); | 64 | GAS_reservations_init (void); |
66 | 65 | ||
67 | 66 | ||
68 | /** | 67 | /** |
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index f19370f7a..fd7eff8fb 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -29,16 +29,10 @@ | |||
29 | #include "gnunet-service-ats_scheduling.h" | 29 | #include "gnunet-service-ats_scheduling.h" |
30 | #include "ats.h" | 30 | #include "ats.h" |
31 | 31 | ||
32 | |||
33 | /** | ||
34 | * Context for sending messages to clients. | ||
35 | */ | ||
36 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
37 | |||
38 | /** | 32 | /** |
39 | * Actual handle to the client. | 33 | * Actual handle to the client. |
40 | */ | 34 | */ |
41 | static struct GNUNET_SERVER_Client *my_client; | 35 | static struct GNUNET_SERVICE_Client *my_client; |
42 | 36 | ||
43 | 37 | ||
44 | /** | 38 | /** |
@@ -48,7 +42,7 @@ static struct GNUNET_SERVER_Client *my_client; | |||
48 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 42 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
49 | */ | 43 | */ |
50 | int | 44 | int |
51 | GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) | 45 | GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client) |
52 | { | 46 | { |
53 | if (NULL != my_client) | 47 | if (NULL != my_client) |
54 | { | 48 | { |
@@ -57,10 +51,6 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) | |||
57 | return GNUNET_SYSERR; | 51 | return GNUNET_SYSERR; |
58 | } | 52 | } |
59 | my_client = client; | 53 | my_client = client; |
60 | GNUNET_SERVER_notification_context_add (nc, | ||
61 | client); | ||
62 | GNUNET_SERVER_client_set_user_context (client, | ||
63 | &nc); | ||
64 | return GNUNET_OK; | 54 | return GNUNET_OK; |
65 | } | 55 | } |
66 | 56 | ||
@@ -72,7 +62,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) | |||
72 | * @param client handle of the (now dead) client | 62 | * @param client handle of the (now dead) client |
73 | */ | 63 | */ |
74 | void | 64 | void |
75 | GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client) | 65 | GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client) |
76 | { | 66 | { |
77 | if (my_client != client) | 67 | if (my_client != client) |
78 | return; | 68 | return; |
@@ -96,7 +86,8 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
96 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 86 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
97 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 87 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
98 | { | 88 | { |
99 | struct AddressSuggestionMessage msg; | 89 | struct GNUNET_MQ_Envelope *env; |
90 | struct AddressSuggestionMessage *msg; | ||
100 | 91 | ||
101 | if (NULL == my_client) | 92 | if (NULL == my_client) |
102 | return; | 93 | return; |
@@ -104,55 +95,39 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
104 | "# address suggestions made", | 95 | "# address suggestions made", |
105 | 1, | 96 | 1, |
106 | GNUNET_NO); | 97 | GNUNET_NO); |
107 | msg.header.size = htons (sizeof (struct AddressSuggestionMessage)); | 98 | env = GNUNET_MQ_msg (msg, |
108 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | 99 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); |
109 | msg.peer = *peer; | 100 | msg->peer = *peer; |
110 | msg.session_id = htonl (session_id); | 101 | msg->session_id = htonl (session_id); |
111 | msg.bandwidth_out = bandwidth_out; | 102 | msg->bandwidth_out = bandwidth_out; |
112 | msg.bandwidth_in = bandwidth_in; | 103 | msg->bandwidth_in = bandwidth_in; |
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
114 | "ATS sends quota for peer `%s': (in/out) %u/%u\n", | 105 | "ATS sends quota for peer `%s': (in/out) %u/%u\n", |
115 | GNUNET_i2s (peer), | 106 | GNUNET_i2s (peer), |
116 | (unsigned int) ntohl (bandwidth_in.value__), | 107 | (unsigned int) ntohl (bandwidth_in.value__), |
117 | (unsigned int) ntohl (bandwidth_out.value__)); | 108 | (unsigned int) ntohl (bandwidth_out.value__)); |
118 | GNUNET_SERVER_notification_context_unicast (nc, | 109 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client), |
119 | my_client, | 110 | env); |
120 | &msg.header, | ||
121 | GNUNET_YES); | ||
122 | } | 111 | } |
123 | 112 | ||
124 | 113 | ||
125 | /** | 114 | /** |
126 | * Handle 'address add' messages from clients. | 115 | * Handle 'address add' messages from clients. |
127 | * | 116 | * |
128 | * @param cls unused, NULL | 117 | * @param m the request message |
129 | * @param client client that sent the request | ||
130 | * @param message the request message | ||
131 | */ | 118 | */ |
132 | void | 119 | void |
133 | GAS_handle_address_add (void *cls, | 120 | GAS_handle_address_add (const struct AddressAddMessage *m) |
134 | struct GNUNET_SERVER_Client *client, | ||
135 | const struct GNUNET_MessageHeader *message) | ||
136 | { | 121 | { |
137 | const struct AddressAddMessage *m; | ||
138 | const char *address; | 122 | const char *address; |
139 | const char *plugin_name; | 123 | const char *plugin_name; |
140 | uint16_t address_length; | 124 | uint16_t address_length; |
141 | uint16_t plugin_name_length; | 125 | uint16_t plugin_name_length; |
142 | uint16_t size; | ||
143 | struct GNUNET_ATS_Properties prop; | 126 | struct GNUNET_ATS_Properties prop; |
144 | 127 | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
146 | "Received `%s' message\n", | 129 | "Received `%s' message\n", |
147 | "ADDRESS_ADD"); | 130 | "ADDRESS_ADD"); |
148 | size = ntohs (message->size); | ||
149 | if (size < sizeof (struct AddressAddMessage)) | ||
150 | { | ||
151 | GNUNET_break (0); | ||
152 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
153 | return; | ||
154 | } | ||
155 | m = (const struct AddressAddMessage *) message; | ||
156 | address_length = ntohs (m->address_length); | 131 | address_length = ntohs (m->address_length); |
157 | plugin_name_length = ntohs (m->plugin_name_length); | 132 | plugin_name_length = ntohs (m->plugin_name_length); |
158 | address = (const char *) &m[1]; | 133 | address = (const char *) &m[1]; |
@@ -160,16 +135,6 @@ GAS_handle_address_add (void *cls, | |||
160 | plugin_name = &address[address_length]; | 135 | plugin_name = &address[address_length]; |
161 | else | 136 | else |
162 | plugin_name = ""; | 137 | plugin_name = ""; |
163 | |||
164 | if ((address_length + plugin_name_length + | ||
165 | sizeof (struct AddressAddMessage) != ntohs (message->size)) || | ||
166 | ( (plugin_name_length > 0) && | ||
167 | (plugin_name[plugin_name_length - 1] != '\0') ) ) | ||
168 | { | ||
169 | GNUNET_break (0); | ||
170 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
171 | return; | ||
172 | } | ||
173 | GNUNET_STATISTICS_update (GSA_stats, | 138 | GNUNET_STATISTICS_update (GSA_stats, |
174 | "# addresses created", | 139 | "# addresses created", |
175 | 1, | 140 | 1, |
@@ -184,27 +149,19 @@ GAS_handle_address_add (void *cls, | |||
184 | ntohl (m->address_local_info), | 149 | ntohl (m->address_local_info), |
185 | ntohl (m->session_id), | 150 | ntohl (m->session_id), |
186 | &prop); | 151 | &prop); |
187 | GNUNET_SERVER_receive_done (client, | ||
188 | GNUNET_OK); | ||
189 | } | 152 | } |
190 | 153 | ||
191 | 154 | ||
192 | /** | 155 | /** |
193 | * Handle 'address update' messages from clients. | 156 | * Handle 'address update' messages from clients. |
194 | * | 157 | * |
195 | * @param cls unused, NULL | 158 | * @param m the request message |
196 | * @param client client that sent the request | ||
197 | * @param message the request message | ||
198 | */ | 159 | */ |
199 | void | 160 | void |
200 | GAS_handle_address_update (void *cls, | 161 | GAS_handle_address_update (const struct AddressUpdateMessage *m) |
201 | struct GNUNET_SERVER_Client *client, | ||
202 | const struct GNUNET_MessageHeader *message) | ||
203 | { | 162 | { |
204 | const struct AddressUpdateMessage *m; | ||
205 | struct GNUNET_ATS_Properties prop; | 163 | struct GNUNET_ATS_Properties prop; |
206 | 164 | ||
207 | m = (const struct AddressUpdateMessage *) message; | ||
208 | GNUNET_STATISTICS_update (GSA_stats, | 165 | GNUNET_STATISTICS_update (GSA_stats, |
209 | "# address updates received", | 166 | "# address updates received", |
210 | 1, | 167 | 1, |
@@ -214,27 +171,20 @@ GAS_handle_address_update (void *cls, | |||
214 | GAS_addresses_update (&m->peer, | 171 | GAS_addresses_update (&m->peer, |
215 | ntohl (m->session_id), | 172 | ntohl (m->session_id), |
216 | &prop); | 173 | &prop); |
217 | GNUNET_SERVER_receive_done (client, | ||
218 | GNUNET_OK); | ||
219 | } | 174 | } |
220 | 175 | ||
221 | 176 | ||
222 | /** | 177 | /** |
223 | * Handle 'address destroyed' messages from clients. | 178 | * Handle 'address destroyed' messages from clients. |
224 | * | 179 | * |
225 | * @param cls unused, NULL | 180 | * @param m the request message |
226 | * @param client client that sent the request | ||
227 | * @param message the request message | ||
228 | */ | 181 | */ |
229 | void | 182 | void |
230 | GAS_handle_address_destroyed (void *cls, | 183 | GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m) |
231 | struct GNUNET_SERVER_Client *client, | ||
232 | const struct GNUNET_MessageHeader *message) | ||
233 | { | 184 | { |
234 | const struct AddressDestroyedMessage *m; | 185 | struct GNUNET_MQ_Envelope *env; |
235 | struct GNUNET_ATS_SessionReleaseMessage srm; | 186 | struct GNUNET_ATS_SessionReleaseMessage *srm; |
236 | 187 | ||
237 | m = (const struct AddressDestroyedMessage *) message; | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
239 | "Received `%s' message\n", | 189 | "Received `%s' message\n", |
240 | "ADDRESS_DESTROYED"); | 190 | "ADDRESS_DESTROYED"); |
@@ -244,42 +194,12 @@ GAS_handle_address_destroyed (void *cls, | |||
244 | GNUNET_NO); | 194 | GNUNET_NO); |
245 | GAS_addresses_destroy (&m->peer, | 195 | GAS_addresses_destroy (&m->peer, |
246 | ntohl (m->session_id)); | 196 | ntohl (m->session_id)); |
247 | srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); | 197 | env = GNUNET_MQ_msg (srm, |
248 | srm.header.size = ntohs (sizeof (struct GNUNET_ATS_SessionReleaseMessage)); | 198 | GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); |
249 | srm.session_id = m->session_id; | 199 | srm->session_id = m->session_id; |
250 | srm.peer = m->peer; | 200 | srm->peer = m->peer; |
251 | GNUNET_SERVER_notification_context_unicast (nc, | 201 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client), |
252 | client, | 202 | env); |
253 | &srm.header, | ||
254 | GNUNET_NO); | ||
255 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
256 | } | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Initialize scheduling subsystem. | ||
261 | * | ||
262 | * @param server handle to our server | ||
263 | */ | ||
264 | void | ||
265 | GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) | ||
266 | { | ||
267 | nc = GNUNET_SERVER_notification_context_create (server, 128); | ||
268 | } | ||
269 | |||
270 | |||
271 | /** | ||
272 | * Shutdown scheduling subsystem. | ||
273 | */ | ||
274 | void | ||
275 | GAS_scheduling_done () | ||
276 | { | ||
277 | if (NULL != my_client) | ||
278 | { | ||
279 | my_client = NULL; | ||
280 | } | ||
281 | GNUNET_SERVER_notification_context_destroy (nc); | ||
282 | nc = NULL; | ||
283 | } | 203 | } |
284 | 204 | ||
285 | 205 | ||
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 99dc6084b..26cb2c73a 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h | |||
@@ -37,7 +37,7 @@ | |||
37 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 37 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
38 | */ | 38 | */ |
39 | int | 39 | int |
40 | GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); | 40 | GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -47,7 +47,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client); | |||
47 | * @param client handle of the (now dead) client | 47 | * @param client handle of the (now dead) client |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client); | 50 | GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
@@ -69,57 +69,29 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
69 | /** | 69 | /** |
70 | * Handle 'address add' messages from clients. | 70 | * Handle 'address add' messages from clients. |
71 | * | 71 | * |
72 | * @param cls unused, NULL | ||
73 | * @param client client that sent the request | 72 | * @param client client that sent the request |
74 | * @param message the request message | 73 | * @param m the request message |
75 | */ | 74 | */ |
76 | void | 75 | void |
77 | GAS_handle_address_add (void *cls, | 76 | GAS_handle_address_add (const struct AddressAddMessage *m); |
78 | struct GNUNET_SERVER_Client *client, | ||
79 | const struct GNUNET_MessageHeader *message); | ||
80 | 77 | ||
81 | 78 | ||
82 | /** | 79 | /** |
83 | * Handle 'address update' messages from clients. | 80 | * Handle 'address update' messages from clients. |
84 | * | 81 | * |
85 | * @param cls unused, NULL | 82 | * @param m the request message |
86 | * @param client client that sent the request | ||
87 | * @param message the request message | ||
88 | */ | 83 | */ |
89 | void | 84 | void |
90 | GAS_handle_address_update (void *cls, | 85 | GAS_handle_address_update (const struct AddressUpdateMessage *m); |
91 | struct GNUNET_SERVER_Client *client, | ||
92 | const struct GNUNET_MessageHeader *message); | ||
93 | 86 | ||
94 | 87 | ||
95 | /** | 88 | /** |
96 | * Handle 'address destroyed' messages from clients. | 89 | * Handle 'address destroyed' messages from clients. |
97 | * | 90 | * |
98 | * @param cls unused, NULL | 91 | * @param m the request message |
99 | * @param client client that sent the request | ||
100 | * @param message the request message | ||
101 | */ | ||
102 | void | ||
103 | GAS_handle_address_destroyed (void *cls, | ||
104 | struct GNUNET_SERVER_Client *client, | ||
105 | const struct GNUNET_MessageHeader *message); | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Initialize scheduling subsystem. | ||
110 | * | ||
111 | * @param server handle to our server | ||
112 | * @param ah the address handle to use | ||
113 | */ | ||
114 | void | ||
115 | GAS_scheduling_init (struct GNUNET_SERVER_Handle *server); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Shutdown scheduling subsystem. | ||
120 | */ | 92 | */ |
121 | void | 93 | void |
122 | GAS_scheduling_done (void); | 94 | GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m); |
123 | 95 | ||
124 | 96 | ||
125 | #endif | 97 | #endif |
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index e6a790377..90f99cb5d 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c | |||
@@ -2281,7 +2281,7 @@ GAS_mlp_address_change_preference (void *solver, | |||
2281 | */ | 2281 | */ |
2282 | static void | 2282 | static void |
2283 | GAS_mlp_address_preference_feedback (void *solver, | 2283 | GAS_mlp_address_preference_feedback (void *solver, |
2284 | struct GNUNET_SERVER_Client *application, | 2284 | struct GNUNET_SERVICE_Client *application, |
2285 | const struct GNUNET_PeerIdentity *peer, | 2285 | const struct GNUNET_PeerIdentity *peer, |
2286 | const struct GNUNET_TIME_Relative scope, | 2286 | const struct GNUNET_TIME_Relative scope, |
2287 | enum GNUNET_ATS_PreferenceKind kind, | 2287 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 7d55fcad3..9309bc2ea 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -879,7 +879,7 @@ GAS_proportional_change_preference (void *solver, | |||
879 | */ | 879 | */ |
880 | static void | 880 | static void |
881 | GAS_proportional_feedback (void *solver, | 881 | GAS_proportional_feedback (void *solver, |
882 | struct GNUNET_SERVER_Client *application, | 882 | struct GNUNET_SERVICE_Client *application, |
883 | const struct GNUNET_PeerIdentity *peer, | 883 | const struct GNUNET_PeerIdentity *peer, |
884 | const struct GNUNET_TIME_Relative scope, | 884 | const struct GNUNET_TIME_Relative scope, |
885 | enum GNUNET_ATS_PreferenceKind kind, | 885 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index eac62c440..a3bdf200c 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -2373,7 +2373,7 @@ GAS_ril_address_property_changed (void *solver, | |||
2373 | */ | 2373 | */ |
2374 | static void | 2374 | static void |
2375 | GAS_ril_address_preference_feedback (void *solver, | 2375 | GAS_ril_address_preference_feedback (void *solver, |
2376 | struct GNUNET_SERVER_Client *application, | 2376 | struct GNUNET_SERVICE_Client *application, |
2377 | const struct GNUNET_PeerIdentity *peer, | 2377 | const struct GNUNET_PeerIdentity *peer, |
2378 | const struct GNUNET_TIME_Relative scope, | 2378 | const struct GNUNET_TIME_Relative scope, |
2379 | enum GNUNET_ATS_PreferenceKind kind, | 2379 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h index 731e39d86..27f4a6f0f 100644 --- a/src/include/gnunet_ats_plugin.h +++ b/src/include/gnunet_ats_plugin.h | |||
@@ -74,7 +74,7 @@ typedef void | |||
74 | */ | 74 | */ |
75 | typedef void | 75 | typedef void |
76 | (*GAS_solver_address_feedback_preference) (void *solver, | 76 | (*GAS_solver_address_feedback_preference) (void *solver, |
77 | struct GNUNET_SERVER_Client *application, | 77 | struct GNUNET_SERVICE_Client *application, |
78 | const struct GNUNET_PeerIdentity *peer, | 78 | const struct GNUNET_PeerIdentity *peer, |
79 | const struct GNUNET_TIME_Relative scope, | 79 | const struct GNUNET_TIME_Relative scope, |
80 | enum GNUNET_ATS_PreferenceKind kind, | 80 | enum GNUNET_ATS_PreferenceKind kind, |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index effb33e51..ae65802b0 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -61,7 +61,7 @@ struct ZoneIteration | |||
61 | /** | 61 | /** |
62 | * Namestore client which intiated this zone iteration | 62 | * Namestore client which intiated this zone iteration |
63 | */ | 63 | */ |
64 | struct NamestoreClient *client; | 64 | struct NamestoreClient *nc; |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * The nick to add to the records | 67 | * The nick to add to the records |
@@ -95,21 +95,17 @@ struct ZoneIteration | |||
95 | */ | 95 | */ |
96 | struct NamestoreClient | 96 | struct NamestoreClient |
97 | { | 97 | { |
98 | /** | ||
99 | * Next element in the DLL | ||
100 | */ | ||
101 | struct NamestoreClient *next; | ||
102 | 98 | ||
103 | /** | 99 | /** |
104 | * Previous element in the DLL | 100 | * The client |
105 | */ | 101 | */ |
106 | struct NamestoreClient *prev; | 102 | struct GNUNET_SERVICE_Client *client; |
107 | 103 | ||
108 | /** | 104 | /** |
109 | * The client | 105 | * Message queue for transmission to @e client |
110 | */ | 106 | */ |
111 | struct GNUNET_SERVER_Client *client; | 107 | struct GNUNET_MQ_Handle *mq; |
112 | 108 | ||
113 | /** | 109 | /** |
114 | * Head of the DLL of | 110 | * Head of the DLL of |
115 | * Zone iteration operations in progress initiated by this client | 111 | * Zone iteration operations in progress initiated by this client |
@@ -152,7 +148,7 @@ struct ZoneMonitor | |||
152 | /** | 148 | /** |
153 | * Task active during initial iteration. | 149 | * Task active during initial iteration. |
154 | */ | 150 | */ |
155 | struct GNUNET_SCHEDULER_Task * task; | 151 | struct GNUNET_SCHEDULER_Task *task; |
156 | 152 | ||
157 | /** | 153 | /** |
158 | * Offset of the zone iteration used to address next result of the zone | 154 | * Offset of the zone iteration used to address next result of the zone |
@@ -190,7 +186,7 @@ struct CacheOperation | |||
190 | /** | 186 | /** |
191 | * Client to notify about the result. | 187 | * Client to notify about the result. |
192 | */ | 188 | */ |
193 | struct GNUNET_SERVER_Client *client; | 189 | struct NamestoreClient *nc; |
194 | 190 | ||
195 | /** | 191 | /** |
196 | * Client's request ID. | 192 | * Client's request ID. |
@@ -225,21 +221,6 @@ static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | |||
225 | static char *db_lib_name; | 221 | static char *db_lib_name; |
226 | 222 | ||
227 | /** | 223 | /** |
228 | * Our notification context. | ||
229 | */ | ||
230 | static struct GNUNET_SERVER_NotificationContext *snc; | ||
231 | |||
232 | /** | ||
233 | * Head of the Client DLL | ||
234 | */ | ||
235 | static struct NamestoreClient *client_head; | ||
236 | |||
237 | /** | ||
238 | * Tail of the Client DLL | ||
239 | */ | ||
240 | static struct NamestoreClient *client_tail; | ||
241 | |||
242 | /** | ||
243 | * Head of cop DLL. | 224 | * Head of cop DLL. |
244 | */ | 225 | */ |
245 | static struct CacheOperation *cop_head; | 226 | static struct CacheOperation *cop_head; |
@@ -262,8 +243,7 @@ static struct ZoneMonitor *monitor_tail; | |||
262 | /** | 243 | /** |
263 | * Notification context shared by all monitors. | 244 | * Notification context shared by all monitors. |
264 | */ | 245 | */ |
265 | static struct GNUNET_SERVER_NotificationContext *monitor_nc; | 246 | static struct GNUNET_NotificationContext *monitor_nc; |
266 | |||
267 | 247 | ||
268 | 248 | ||
269 | /** | 249 | /** |
@@ -274,17 +254,10 @@ static struct GNUNET_SERVER_NotificationContext *monitor_nc; | |||
274 | static void | 254 | static void |
275 | cleanup_task (void *cls) | 255 | cleanup_task (void *cls) |
276 | { | 256 | { |
277 | struct ZoneIteration *no; | ||
278 | struct NamestoreClient *nc; | ||
279 | struct CacheOperation *cop; | 257 | struct CacheOperation *cop; |
280 | 258 | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
282 | "Stopping namestore service\n"); | 260 | "Stopping namestore service\n"); |
283 | if (NULL != snc) | ||
284 | { | ||
285 | GNUNET_SERVER_notification_context_destroy (snc); | ||
286 | snc = NULL; | ||
287 | } | ||
288 | while (NULL != (cop = cop_head)) | 261 | while (NULL != (cop = cop_head)) |
289 | { | 262 | { |
290 | GNUNET_NAMECACHE_cancel (cop->qe); | 263 | GNUNET_NAMECACHE_cancel (cop->qe); |
@@ -295,23 +268,13 @@ cleanup_task (void *cls) | |||
295 | } | 268 | } |
296 | GNUNET_NAMECACHE_disconnect (namecache); | 269 | GNUNET_NAMECACHE_disconnect (namecache); |
297 | namecache = NULL; | 270 | namecache = NULL; |
298 | while (NULL != (nc = client_head)) | 271 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, |
299 | { | 272 | GSN_database)); |
300 | while (NULL != (no = nc->op_head)) | ||
301 | { | ||
302 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | ||
303 | GNUNET_free (no); | ||
304 | } | ||
305 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | ||
306 | GNUNET_SERVER_client_set_user_context (nc->client, NULL); | ||
307 | GNUNET_free (nc); | ||
308 | } | ||
309 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database)); | ||
310 | GNUNET_free (db_lib_name); | 273 | GNUNET_free (db_lib_name); |
311 | db_lib_name = NULL; | 274 | db_lib_name = NULL; |
312 | if (NULL != monitor_nc) | 275 | if (NULL != monitor_nc) |
313 | { | 276 | { |
314 | GNUNET_SERVER_notification_context_destroy (monitor_nc); | 277 | GNUNET_notification_context_destroy (monitor_nc); |
315 | monitor_nc = NULL; | 278 | monitor_nc = NULL; |
316 | } | 279 | } |
317 | } | 280 | } |
@@ -323,26 +286,24 @@ cleanup_task (void *cls) | |||
323 | * | 286 | * |
324 | * @param cls closure | 287 | * @param cls closure |
325 | * @param client identification of the client | 288 | * @param client identification of the client |
289 | * @param app_ctx the `struct NamestoreClient` of @a client | ||
326 | */ | 290 | */ |
327 | static void | 291 | static void |
328 | client_disconnect_notification (void *cls, | 292 | client_disconnect_cb (void *cls, |
329 | struct GNUNET_SERVER_Client *client) | 293 | struct GNUNET_SERVICE_Client *client, |
294 | void *app_ctx) | ||
330 | { | 295 | { |
296 | struct NamestoreClient *nc = app_ctx; | ||
331 | struct ZoneIteration *no; | 297 | struct ZoneIteration *no; |
332 | struct NamestoreClient *nc; | ||
333 | struct ZoneMonitor *zm; | 298 | struct ZoneMonitor *zm; |
334 | struct CacheOperation *cop; | 299 | struct CacheOperation *cop; |
335 | 300 | ||
336 | if (NULL == client) | ||
337 | return; | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
339 | "Client %p disconnected\n", | 302 | "Client %p disconnected\n", |
340 | client); | 303 | client); |
341 | if (NULL == (nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient))) | ||
342 | return; | ||
343 | for (zm = monitor_head; NULL != zm; zm = zm->next) | 304 | for (zm = monitor_head; NULL != zm; zm = zm->next) |
344 | { | 305 | { |
345 | if (client == zm->nc->client) | 306 | if (nc == zm->nc) |
346 | { | 307 | { |
347 | GNUNET_CONTAINER_DLL_remove (monitor_head, | 308 | GNUNET_CONTAINER_DLL_remove (monitor_head, |
348 | monitor_tail, | 309 | monitor_tail, |
@@ -358,40 +319,39 @@ client_disconnect_notification (void *cls, | |||
358 | } | 319 | } |
359 | while (NULL != (no = nc->op_head)) | 320 | while (NULL != (no = nc->op_head)) |
360 | { | 321 | { |
361 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | 322 | GNUNET_CONTAINER_DLL_remove (nc->op_head, |
323 | nc->op_tail, | ||
324 | no); | ||
362 | GNUNET_free (no); | 325 | GNUNET_free (no); |
363 | } | 326 | } |
364 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | ||
365 | GNUNET_free (nc); | ||
366 | for (cop = cop_head; NULL != cop; cop = cop->next) | 327 | for (cop = cop_head; NULL != cop; cop = cop->next) |
367 | if (client == cop->client) | 328 | if (nc == cop->nc) |
368 | cop->client = NULL; | 329 | cop->nc = NULL; |
330 | GNUNET_free (nc); | ||
369 | } | 331 | } |
370 | 332 | ||
371 | 333 | ||
372 | /** | 334 | /** |
373 | * Add a client to our list of active clients, if it is not yet | 335 | * Add a client to our list of active clients. |
374 | * in there. | ||
375 | * | 336 | * |
337 | * @param cls NULL | ||
376 | * @param client client to add | 338 | * @param client client to add |
339 | * @param mq message queue for @a client | ||
377 | * @return internal namestore client structure for this client | 340 | * @return internal namestore client structure for this client |
378 | */ | 341 | */ |
379 | static struct NamestoreClient * | 342 | static void * |
380 | client_lookup (struct GNUNET_SERVER_Client *client) | 343 | client_connect_cb (void *cls, |
344 | struct GNUNET_SERVICE_Client *client, | ||
345 | struct GNUNET_MQ_Handle *mq) | ||
381 | { | 346 | { |
382 | struct NamestoreClient *nc; | 347 | struct NamestoreClient *nc; |
383 | 348 | ||
384 | nc = GNUNET_SERVER_client_get_user_context (client, struct NamestoreClient); | ||
385 | if (NULL != nc) | ||
386 | return nc; | ||
387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
388 | "Client %p connected\n", | 350 | "Client %p connected\n", |
389 | client); | 351 | client); |
390 | nc = GNUNET_new (struct NamestoreClient); | 352 | nc = GNUNET_new (struct NamestoreClient); |
391 | nc->client = client; | 353 | nc->client = client; |
392 | GNUNET_SERVER_notification_context_add (snc, client); | 354 | nc->mq = mq; |
393 | GNUNET_CONTAINER_DLL_insert (client_head, client_tail, nc); | ||
394 | GNUNET_SERVER_client_set_user_context (client, nc); | ||
395 | return nc; | 355 | return nc; |
396 | } | 356 | } |
397 | 357 | ||
@@ -415,14 +375,13 @@ lookup_nick_it (void *cls, | |||
415 | const struct GNUNET_GNSRECORD_Data *rd) | 375 | const struct GNUNET_GNSRECORD_Data *rd) |
416 | { | 376 | { |
417 | struct GNUNET_GNSRECORD_Data **res = cls; | 377 | struct GNUNET_GNSRECORD_Data **res = cls; |
418 | int c; | ||
419 | 378 | ||
420 | if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR)) | 379 | if (0 != strcmp (label, GNUNET_GNS_MASTERZONE_STR)) |
421 | { | 380 | { |
422 | GNUNET_break (0); | 381 | GNUNET_break (0); |
423 | return; | 382 | return; |
424 | } | 383 | } |
425 | for (c = 0; c < rd_count; c++) | 384 | for (unsigned int c = 0; c < rd_count; c++) |
426 | { | 385 | { |
427 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) | 386 | if (GNUNET_GNSRECORD_TYPE_NICK == rd[c].record_type) |
428 | { | 387 | { |
@@ -537,8 +496,7 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
537 | * Generate a `struct LookupNameResponseMessage` and send it to the | 496 | * Generate a `struct LookupNameResponseMessage` and send it to the |
538 | * given client using the given notification context. | 497 | * given client using the given notification context. |
539 | * | 498 | * |
540 | * @param nc notification context to use | 499 | * @param nc client to unicast to |
541 | * @param client client to unicast to | ||
542 | * @param request_id request ID to use | 500 | * @param request_id request ID to use |
543 | * @param zone_key zone key of the zone | 501 | * @param zone_key zone key of the zone |
544 | * @param name name | 502 | * @param name name |
@@ -546,21 +504,20 @@ merge_with_nick_records (const struct GNUNET_GNSRECORD_Data *nick_rd, | |||
546 | * @param rd array of records | 504 | * @param rd array of records |
547 | */ | 505 | */ |
548 | static void | 506 | static void |
549 | send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | 507 | send_lookup_response (struct NamestoreClient *nc, |
550 | struct GNUNET_SERVER_Client *client, | ||
551 | uint32_t request_id, | 508 | uint32_t request_id, |
552 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 509 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
553 | const char *name, | 510 | const char *name, |
554 | unsigned int rd_count, | 511 | unsigned int rd_count, |
555 | const struct GNUNET_GNSRECORD_Data *rd) | 512 | const struct GNUNET_GNSRECORD_Data *rd) |
556 | { | 513 | { |
514 | struct GNUNET_MQ_Envelope *env; | ||
557 | struct RecordResultMessage *zir_msg; | 515 | struct RecordResultMessage *zir_msg; |
558 | struct GNUNET_GNSRECORD_Data *nick; | 516 | struct GNUNET_GNSRECORD_Data *nick; |
559 | struct GNUNET_GNSRECORD_Data *res; | 517 | struct GNUNET_GNSRECORD_Data *res; |
560 | unsigned int res_count; | 518 | unsigned int res_count; |
561 | size_t name_len; | 519 | size_t name_len; |
562 | size_t rd_ser_len; | 520 | size_t rd_ser_len; |
563 | size_t msg_size; | ||
564 | char *name_tmp; | 521 | char *name_tmp; |
565 | char *rd_ser; | 522 | char *rd_ser; |
566 | 523 | ||
@@ -583,31 +540,30 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
583 | 540 | ||
584 | name_len = strlen (name) + 1; | 541 | name_len = strlen (name) + 1; |
585 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); | 542 | rd_ser_len = GNUNET_GNSRECORD_records_get_size (res_count, res); |
586 | msg_size = sizeof (struct RecordResultMessage) + name_len + rd_ser_len; | 543 | env = GNUNET_MQ_msg_extra (zir_msg, |
587 | (void) client_lookup (client); | 544 | name_len + rd_ser_len, |
588 | zir_msg = GNUNET_malloc (msg_size); | 545 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); |
589 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); | ||
590 | zir_msg->gns_header.header.size = htons (msg_size); | ||
591 | zir_msg->gns_header.r_id = htonl (request_id); | 546 | zir_msg->gns_header.r_id = htonl (request_id); |
592 | zir_msg->name_len = htons (name_len); | 547 | zir_msg->name_len = htons (name_len); |
593 | zir_msg->rd_count = htons (res_count); | 548 | zir_msg->rd_count = htons (res_count); |
594 | zir_msg->rd_len = htons (rd_ser_len); | 549 | zir_msg->rd_len = htons (rd_ser_len); |
595 | zir_msg->private_key = *zone_key; | 550 | zir_msg->private_key = *zone_key; |
596 | name_tmp = (char *) &zir_msg[1]; | 551 | name_tmp = (char *) &zir_msg[1]; |
597 | GNUNET_memcpy (name_tmp, name, name_len); | 552 | GNUNET_memcpy (name_tmp, |
553 | name, | ||
554 | name_len); | ||
598 | rd_ser = &name_tmp[name_len]; | 555 | rd_ser = &name_tmp[name_len]; |
599 | GNUNET_GNSRECORD_records_serialize (res_count, res, rd_ser_len, rd_ser); | 556 | GNUNET_GNSRECORD_records_serialize (res_count, |
557 | res, | ||
558 | rd_ser_len, | ||
559 | rd_ser); | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
601 | "Sending RECORD_RESULT message with %u records and size %zu\n", | 561 | "Sending RECORD_RESULT message with %u records\n", |
602 | res_count, | 562 | res_count); |
603 | msg_size); | 563 | GNUNET_MQ_send (nc->mq, |
604 | GNUNET_SERVER_notification_context_unicast (nc, | 564 | env); |
605 | client, | ||
606 | &zir_msg->gns_header.header, | ||
607 | GNUNET_NO); | ||
608 | if (rd != res) | 565 | if (rd != res) |
609 | GNUNET_free (res); | 566 | GNUNET_free (res); |
610 | GNUNET_free (zir_msg); | ||
611 | } | 567 | } |
612 | 568 | ||
613 | 569 | ||
@@ -619,22 +575,21 @@ send_lookup_response (struct GNUNET_SERVER_NotificationContext *nc, | |||
619 | * @param rid client's request ID | 575 | * @param rid client's request ID |
620 | */ | 576 | */ |
621 | static void | 577 | static void |
622 | send_store_response (struct GNUNET_SERVER_Client *client, | 578 | send_store_response (struct NamestoreClient *nc, |
623 | int res, | 579 | int res, |
624 | uint32_t rid) | 580 | uint32_t rid) |
625 | { | 581 | { |
626 | struct RecordStoreResponseMessage rcr_msg; | 582 | struct GNUNET_MQ_Envelope *env; |
583 | struct RecordStoreResponseMessage *rcr_msg; | ||
627 | 584 | ||
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
629 | "Sending `%s' message\n", | 586 | "Sending RECORD_STORE_RESPONSE message\n"); |
630 | "RECORD_STORE_RESPONSE"); | 587 | env = GNUNET_MQ_msg (rcr_msg, |
631 | rcr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | 588 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); |
632 | rcr_msg.gns_header.header.size = htons (sizeof (struct RecordStoreResponseMessage)); | 589 | rcr_msg->gns_header.r_id = htonl (rid); |
633 | rcr_msg.gns_header.r_id = htonl (rid); | 590 | rcr_msg->op_result = htonl (res); |
634 | rcr_msg.op_result = htonl (res); | 591 | GNUNET_MQ_send (nc->mq, |
635 | GNUNET_SERVER_notification_context_unicast (snc, client, | 592 | env); |
636 | &rcr_msg.gns_header.header, | ||
637 | GNUNET_NO); | ||
638 | } | 593 | } |
639 | 594 | ||
640 | 595 | ||
@@ -662,8 +617,8 @@ finish_cache_operation (void *cls, | |||
662 | GNUNET_CONTAINER_DLL_remove (cop_head, | 617 | GNUNET_CONTAINER_DLL_remove (cop_head, |
663 | cop_tail, | 618 | cop_tail, |
664 | cop); | 619 | cop); |
665 | if (NULL != cop->client) | 620 | if (NULL != cop->nc) |
666 | send_store_response (cop->client, | 621 | send_store_response (cop->nc, |
667 | success, | 622 | success, |
668 | cop->rid); | 623 | cop->rid); |
669 | GNUNET_free (cop); | 624 | GNUNET_free (cop); |
@@ -674,7 +629,7 @@ finish_cache_operation (void *cls, | |||
674 | * We just touched the plaintext information about a name in our zone; | 629 | * We just touched the plaintext information about a name in our zone; |
675 | * refresh the corresponding (encrypted) block in the namecache. | 630 | * refresh the corresponding (encrypted) block in the namecache. |
676 | * | 631 | * |
677 | * @param client client responsible for the request | 632 | * @param nc client responsible for the request, can be NULL |
678 | * @param rid request ID of the client | 633 | * @param rid request ID of the client |
679 | * @param zone_key private key of the zone | 634 | * @param zone_key private key of the zone |
680 | * @param name label for the records | 635 | * @param name label for the records |
@@ -682,7 +637,7 @@ finish_cache_operation (void *cls, | |||
682 | * @param rd records stored under the given @a name | 637 | * @param rd records stored under the given @a name |
683 | */ | 638 | */ |
684 | static void | 639 | static void |
685 | refresh_block (struct GNUNET_SERVER_Client *client, | 640 | refresh_block (struct NamestoreClient *nc, |
686 | uint32_t rid, | 641 | uint32_t rid, |
687 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 642 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
688 | const char *name, | 643 | const char *name, |
@@ -702,7 +657,10 @@ refresh_block (struct GNUNET_SERVER_Client *client, | |||
702 | if (NULL != nick) | 657 | if (NULL != nick) |
703 | { | 658 | { |
704 | nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 659 | nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; |
705 | merge_with_nick_records (nick, rd_count,rd, &res_count, &res); | 660 | merge_with_nick_records (nick, |
661 | rd_count,rd, | ||
662 | &res_count, | ||
663 | &res); | ||
706 | GNUNET_free (nick); | 664 | GNUNET_free (nick); |
707 | } | 665 | } |
708 | 666 | ||
@@ -726,7 +684,7 @@ refresh_block (struct GNUNET_SERVER_Client *client, | |||
726 | res_count, | 684 | res_count, |
727 | GNUNET_GNSRECORD_z2s (&pkey)); | 685 | GNUNET_GNSRECORD_z2s (&pkey)); |
728 | cop = GNUNET_new (struct CacheOperation); | 686 | cop = GNUNET_new (struct CacheOperation); |
729 | cop->client = client; | 687 | cop->nc = nc; |
730 | cop->rid = rid; | 688 | cop->rid = rid; |
731 | GNUNET_CONTAINER_DLL_insert (cop_head, | 689 | GNUNET_CONTAINER_DLL_insert (cop_head, |
732 | cop_tail, | 690 | cop_tail, |
@@ -824,75 +782,70 @@ lookup_it (void *cls, | |||
824 | /** | 782 | /** |
825 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | 783 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message |
826 | * | 784 | * |
827 | * @param cls unused | 785 | * @param cls client sending the message |
828 | * @param client client sending the message | 786 | * @param ll_msg message of type `struct LabelLookupMessage` |
829 | * @param message message of type 'struct RecordCreateMessage' | 787 | * @return #GNUNET_OK if @a ll_msg is well-formed |
830 | */ | 788 | */ |
831 | static void | 789 | static int |
832 | handle_record_lookup (void *cls, | 790 | check_record_lookup (void *cls, |
833 | struct GNUNET_SERVER_Client *client, | 791 | const struct LabelLookupMessage *ll_msg) |
834 | const struct GNUNET_MessageHeader *message) | ||
835 | { | 792 | { |
836 | const struct LabelLookupMessage *ll_msg; | ||
837 | struct LabelLookupResponseMessage *llr_msg; | ||
838 | struct RecordLookupContext rlc; | ||
839 | const char *name_tmp; | ||
840 | char *res_name; | ||
841 | char *conv_name; | ||
842 | uint32_t name_len; | 793 | uint32_t name_len; |
843 | size_t src_size; | 794 | size_t src_size; |
844 | size_t res_size; | 795 | const char *name_tmp; |
845 | int res; | ||
846 | |||
847 | if (ntohs (message->size) < sizeof (struct LabelLookupMessage)) | ||
848 | { | ||
849 | GNUNET_break (0); | ||
850 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
851 | return; | ||
852 | } | ||
853 | 796 | ||
854 | ll_msg = (const struct LabelLookupMessage *) message; | ||
855 | name_len = ntohl (ll_msg->label_len); | 797 | name_len = ntohl (ll_msg->label_len); |
856 | src_size = ntohs (message->size); | 798 | src_size = ntohs (ll_msg->gns_header.header.size); |
857 | 799 | if (name_len != src_size - sizeof (struct LabelLookupMessage)) | |
858 | if (name_len != src_size - sizeof (struct LabelLookupMessage)) | ||
859 | { | 800 | { |
860 | GNUNET_break (0); | 801 | GNUNET_break (0); |
861 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 802 | return GNUNET_SYSERR; |
862 | return; | ||
863 | } | 803 | } |
864 | 804 | ||
865 | name_tmp = (const char *) &ll_msg[1]; | 805 | name_tmp = (const char *) &ll_msg[1]; |
866 | if ('\0' != name_tmp[name_len -1]) | 806 | if ('\0' != name_tmp[name_len -1]) |
867 | { | 807 | { |
868 | GNUNET_break (0); | 808 | GNUNET_break (0); |
869 | GNUNET_SERVER_receive_done (client, | 809 | return GNUNET_SYSERR; |
870 | GNUNET_SYSERR); | ||
871 | return; | ||
872 | } | 810 | } |
811 | return GNUNET_OK; | ||
812 | } | ||
873 | 813 | ||
874 | GNUNET_SERVER_receive_done (client, | 814 | |
875 | GNUNET_OK); | 815 | /** |
816 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | ||
817 | * | ||
818 | * @param cls client sending the message | ||
819 | * @param ll_msg message of type `struct LabelLookupMessage` | ||
820 | */ | ||
821 | static void | ||
822 | handle_record_lookup (void *cls, | ||
823 | const struct LabelLookupMessage *ll_msg) | ||
824 | { | ||
825 | struct NamestoreClient *nc = cls; | ||
826 | struct GNUNET_MQ_Envelope *env; | ||
827 | struct LabelLookupResponseMessage *llr_msg; | ||
828 | struct RecordLookupContext rlc; | ||
829 | const char *name_tmp; | ||
830 | char *res_name; | ||
831 | char *conv_name; | ||
832 | uint32_t name_len; | ||
833 | int res; | ||
834 | |||
835 | name_len = ntohl (ll_msg->label_len); | ||
836 | name_tmp = (const char *) &ll_msg[1]; | ||
837 | GNUNET_SERVICE_client_continue (nc->client); | ||
876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 838 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
877 | "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", | 839 | "Received NAMESTORE_RECORD_LOOKUP message for name `%s'\n", |
878 | name_tmp); | 840 | name_tmp); |
879 | 841 | ||
880 | if (NULL == (client_lookup (client))) | ||
881 | { | ||
882 | GNUNET_break (0); | ||
883 | GNUNET_SERVER_receive_done (client, | ||
884 | GNUNET_SYSERR); | ||
885 | return; | ||
886 | } | ||
887 | |||
888 | conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); | 842 | conv_name = GNUNET_GNSRECORD_string_to_lowercase (name_tmp); |
889 | if (NULL == conv_name) | 843 | if (NULL == conv_name) |
890 | { | 844 | { |
891 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 845 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
892 | "Error converting name `%s'\n", | 846 | "Error converting name `%s'\n", |
893 | name_tmp); | 847 | name_tmp); |
894 | GNUNET_SERVER_receive_done (client, | 848 | GNUNET_SERVICE_client_drop (nc->client); |
895 | GNUNET_SYSERR); | ||
896 | return; | 849 | return; |
897 | } | 850 | } |
898 | rlc.label = conv_name; | 851 | rlc.label = conv_name; |
@@ -907,10 +860,9 @@ handle_record_lookup (void *cls, | |||
907 | &lookup_it, | 860 | &lookup_it, |
908 | &rlc); | 861 | &rlc); |
909 | GNUNET_free (conv_name); | 862 | GNUNET_free (conv_name); |
910 | res_size = sizeof (struct LabelLookupResponseMessage) + name_len + rlc.rd_ser_len; | 863 | env = GNUNET_MQ_msg_extra (llr_msg, |
911 | llr_msg = GNUNET_malloc (res_size); | 864 | name_len + rlc.rd_ser_len, |
912 | llr_msg->gns_header.header.size = htons (res_size); | 865 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); |
913 | llr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE); | ||
914 | llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; | 866 | llr_msg->gns_header.r_id = ll_msg->gns_header.r_id; |
915 | llr_msg->private_key = ll_msg->zone; | 867 | llr_msg->private_key = ll_msg->zone; |
916 | llr_msg->name_len = htons (name_len); | 868 | llr_msg->name_len = htons (name_len); |
@@ -927,31 +879,65 @@ handle_record_lookup (void *cls, | |||
927 | GNUNET_memcpy (&res_name[name_len], | 879 | GNUNET_memcpy (&res_name[name_len], |
928 | rlc.res_rd, | 880 | rlc.res_rd, |
929 | rlc.rd_ser_len); | 881 | rlc.rd_ser_len); |
930 | GNUNET_SERVER_notification_context_unicast (snc, | 882 | GNUNET_MQ_send (nc->mq, |
931 | client, | 883 | env); |
932 | &llr_msg->gns_header.header, | ||
933 | GNUNET_NO); | ||
934 | GNUNET_free_non_null (rlc.res_rd); | 884 | GNUNET_free_non_null (rlc.res_rd); |
935 | GNUNET_free (llr_msg); | 885 | } |
886 | |||
887 | |||
888 | /** | ||
889 | * Checks a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | ||
890 | * | ||
891 | * @param cls client sending the message | ||
892 | * @param rp_msg message of type `struct RecordStoreMessage` | ||
893 | * @return #GNUNET_OK if @a rp_msg is well-formed | ||
894 | */ | ||
895 | static int | ||
896 | check_record_store (void *cls, | ||
897 | const struct RecordStoreMessage *rp_msg) | ||
898 | { | ||
899 | size_t name_len; | ||
900 | size_t msg_size; | ||
901 | size_t msg_size_exp; | ||
902 | size_t rd_ser_len; | ||
903 | const char *name_tmp; | ||
904 | |||
905 | name_len = ntohs (rp_msg->name_len); | ||
906 | msg_size = ntohs (rp_msg->gns_header.header.size); | ||
907 | rd_ser_len = ntohs (rp_msg->rd_len); | ||
908 | msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len; | ||
909 | if (msg_size != msg_size_exp) | ||
910 | { | ||
911 | GNUNET_break (0); | ||
912 | return GNUNET_SYSERR; | ||
913 | } | ||
914 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) | ||
915 | { | ||
916 | GNUNET_break (0); | ||
917 | return GNUNET_SYSERR; | ||
918 | } | ||
919 | name_tmp = (const char *) &rp_msg[1]; | ||
920 | if ('\0' != name_tmp[name_len -1]) | ||
921 | { | ||
922 | GNUNET_break (0); | ||
923 | return GNUNET_SYSERR; | ||
924 | } | ||
925 | return GNUNET_OK; | ||
936 | } | 926 | } |
937 | 927 | ||
938 | 928 | ||
939 | /** | 929 | /** |
940 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | 930 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message |
941 | * | 931 | * |
942 | * @param cls unused | 932 | * @param cls client sending the message |
943 | * @param client client sending the message | 933 | * @param rp_msg message of type `struct RecordStoreMessage` |
944 | * @param message message of type 'struct RecordCreateMessage' | ||
945 | */ | 934 | */ |
946 | static void | 935 | static void |
947 | handle_record_store (void *cls, | 936 | handle_record_store (void *cls, |
948 | struct GNUNET_SERVER_Client *client, | 937 | const struct RecordStoreMessage *rp_msg) |
949 | const struct GNUNET_MessageHeader *message) | ||
950 | { | 938 | { |
951 | const struct RecordStoreMessage *rp_msg; | 939 | struct NamestoreClient *nc = cls; |
952 | size_t name_len; | 940 | size_t name_len; |
953 | size_t msg_size; | ||
954 | size_t msg_size_exp; | ||
955 | size_t rd_ser_len; | 941 | size_t rd_ser_len; |
956 | uint32_t rid; | 942 | uint32_t rid; |
957 | const char *name_tmp; | 943 | const char *name_tmp; |
@@ -964,44 +950,13 @@ handle_record_store (void *cls, | |||
964 | 950 | ||
965 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 951 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
966 | "Received NAMESTORE_RECORD_STORE message\n"); | 952 | "Received NAMESTORE_RECORD_STORE message\n"); |
967 | if (ntohs (message->size) < sizeof (struct RecordStoreMessage)) | ||
968 | { | ||
969 | GNUNET_break (0); | ||
970 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
971 | return; | ||
972 | } | ||
973 | rp_msg = (const struct RecordStoreMessage *) message; | ||
974 | rid = ntohl (rp_msg->gns_header.r_id); | 953 | rid = ntohl (rp_msg->gns_header.r_id); |
975 | name_len = ntohs (rp_msg->name_len); | 954 | name_len = ntohs (rp_msg->name_len); |
976 | msg_size = ntohs (message->size); | ||
977 | rd_count = ntohs (rp_msg->rd_count); | 955 | rd_count = ntohs (rp_msg->rd_count); |
978 | rd_ser_len = ntohs (rp_msg->rd_len); | 956 | rd_ser_len = ntohs (rp_msg->rd_len); |
979 | GNUNET_break (0 == ntohs (rp_msg->reserved)); | 957 | GNUNET_break (0 == ntohs (rp_msg->reserved)); |
980 | msg_size_exp = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len; | ||
981 | if (msg_size != msg_size_exp) | ||
982 | { | ||
983 | GNUNET_break (0); | ||
984 | GNUNET_SERVER_receive_done (client, | ||
985 | GNUNET_SYSERR); | ||
986 | return; | ||
987 | } | ||
988 | if ((0 == name_len) || (name_len > MAX_NAME_LEN)) | ||
989 | { | ||
990 | GNUNET_break (0); | ||
991 | GNUNET_SERVER_receive_done (client, | ||
992 | GNUNET_SYSERR); | ||
993 | return; | ||
994 | } | ||
995 | name_tmp = (const char *) &rp_msg[1]; | 958 | name_tmp = (const char *) &rp_msg[1]; |
996 | rd_ser = &name_tmp[name_len]; | 959 | rd_ser = &name_tmp[name_len]; |
997 | if ('\0' != name_tmp[name_len -1]) | ||
998 | { | ||
999 | GNUNET_break (0); | ||
1000 | GNUNET_SERVER_receive_done (client, | ||
1001 | GNUNET_SYSERR); | ||
1002 | return; | ||
1003 | } | ||
1004 | (void) client_lookup (client); | ||
1005 | { | 960 | { |
1006 | struct GNUNET_GNSRECORD_Data rd[rd_count]; | 961 | struct GNUNET_GNSRECORD_Data rd[rd_count]; |
1007 | 962 | ||
@@ -1012,8 +967,7 @@ handle_record_store (void *cls, | |||
1012 | rd)) | 967 | rd)) |
1013 | { | 968 | { |
1014 | GNUNET_break (0); | 969 | GNUNET_break (0); |
1015 | GNUNET_SERVER_receive_done (client, | 970 | GNUNET_SERVICE_client_drop (nc->client); |
1016 | GNUNET_SYSERR); | ||
1017 | return; | 971 | return; |
1018 | } | 972 | } |
1019 | 973 | ||
@@ -1026,7 +980,7 @@ handle_record_store (void *cls, | |||
1026 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 980 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1027 | "Error converting name `%s'\n", | 981 | "Error converting name `%s'\n", |
1028 | name_tmp); | 982 | name_tmp); |
1029 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 983 | GNUNET_SERVICE_client_drop (nc->client); |
1030 | return; | 984 | return; |
1031 | } | 985 | } |
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1052,12 +1006,11 @@ handle_record_store (void *cls, | |||
1052 | else | 1006 | else |
1053 | { | 1007 | { |
1054 | struct GNUNET_GNSRECORD_Data rd_clean[rd_count]; | 1008 | struct GNUNET_GNSRECORD_Data rd_clean[rd_count]; |
1055 | unsigned int i; | ||
1056 | unsigned int rd_clean_off; | 1009 | unsigned int rd_clean_off; |
1057 | 1010 | ||
1058 | /* remove "NICK" records, unless this is for the "+" label */ | 1011 | /* remove "NICK" records, unless this is for the "+" label */ |
1059 | rd_clean_off = 0; | 1012 | rd_clean_off = 0; |
1060 | for (i=0;i<rd_count;i++) | 1013 | for (unsigned int i=0;i<rd_count;i++) |
1061 | { | 1014 | { |
1062 | rd_clean[rd_clean_off] = rd[i]; | 1015 | rd_clean[rd_clean_off] = rd[i]; |
1063 | if ( (0 == strcmp (GNUNET_GNS_MASTERZONE_STR, | 1016 | if ( (0 == strcmp (GNUNET_GNS_MASTERZONE_STR, |
@@ -1083,8 +1036,7 @@ handle_record_store (void *cls, | |||
1083 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1084 | "Notifying monitor about changes under label `%s'\n", | 1037 | "Notifying monitor about changes under label `%s'\n", |
1085 | conv_name); | 1038 | conv_name); |
1086 | send_lookup_response (monitor_nc, | 1039 | send_lookup_response (zm->nc, |
1087 | zm->nc->client, | ||
1088 | 0, | 1040 | 0, |
1089 | &rp_msg->private_key, | 1041 | &rp_msg->private_key, |
1090 | conv_name, | 1042 | conv_name, |
@@ -1107,22 +1059,22 @@ handle_record_store (void *cls, | |||
1107 | } | 1059 | } |
1108 | if (GNUNET_OK == res) | 1060 | if (GNUNET_OK == res) |
1109 | { | 1061 | { |
1110 | refresh_block (client, rid, | 1062 | refresh_block (nc, |
1063 | rid, | ||
1111 | &rp_msg->private_key, | 1064 | &rp_msg->private_key, |
1112 | conv_name, | 1065 | conv_name, |
1113 | rd_count, rd); | 1066 | rd_count, |
1114 | GNUNET_SERVER_receive_done (client, | 1067 | rd); |
1115 | GNUNET_OK); | 1068 | GNUNET_SERVICE_client_continue (nc->client); |
1116 | GNUNET_free (conv_name); | 1069 | GNUNET_free (conv_name); |
1117 | return; | 1070 | return; |
1118 | } | 1071 | } |
1119 | GNUNET_free (conv_name); | 1072 | GNUNET_free (conv_name); |
1120 | } | 1073 | } |
1121 | send_store_response (client, | 1074 | send_store_response (nc, |
1122 | res, | 1075 | res, |
1123 | rid); | 1076 | rid); |
1124 | GNUNET_SERVER_receive_done (client, | 1077 | GNUNET_SERVICE_client_continue (nc->client); |
1125 | GNUNET_OK); | ||
1126 | } | 1078 | } |
1127 | 1079 | ||
1128 | 1080 | ||
@@ -1168,6 +1120,7 @@ handle_zone_to_name_it (void *cls, | |||
1168 | const struct GNUNET_GNSRECORD_Data *rd) | 1120 | const struct GNUNET_GNSRECORD_Data *rd) |
1169 | { | 1121 | { |
1170 | struct ZoneToNameCtx *ztn_ctx = cls; | 1122 | struct ZoneToNameCtx *ztn_ctx = cls; |
1123 | struct GNUNET_MQ_Envelope *env; | ||
1171 | struct ZoneToNameResponseMessage *ztnr_msg; | 1124 | struct ZoneToNameResponseMessage *ztnr_msg; |
1172 | int16_t res; | 1125 | int16_t res; |
1173 | size_t name_len; | 1126 | size_t name_len; |
@@ -1189,8 +1142,9 @@ handle_zone_to_name_it (void *cls, | |||
1189 | ztn_ctx->success = GNUNET_SYSERR; | 1142 | ztn_ctx->success = GNUNET_SYSERR; |
1190 | return; | 1143 | return; |
1191 | } | 1144 | } |
1192 | ztnr_msg = GNUNET_malloc (msg_size); | 1145 | env = GNUNET_MQ_msg_extra (ztnr_msg, |
1193 | ztnr_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | 1146 | name_len + rd_ser_len, |
1147 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | ||
1194 | ztnr_msg->gns_header.header.size = htons (msg_size); | 1148 | ztnr_msg->gns_header.header.size = htons (msg_size); |
1195 | ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); | 1149 | ztnr_msg->gns_header.r_id = htonl (ztn_ctx->rid); |
1196 | ztnr_msg->res = htons (res); | 1150 | ztnr_msg->res = htons (res); |
@@ -1199,40 +1153,38 @@ handle_zone_to_name_it (void *cls, | |||
1199 | ztnr_msg->name_len = htons (name_len); | 1153 | ztnr_msg->name_len = htons (name_len); |
1200 | ztnr_msg->zone = *zone_key; | 1154 | ztnr_msg->zone = *zone_key; |
1201 | name_tmp = (char *) &ztnr_msg[1]; | 1155 | name_tmp = (char *) &ztnr_msg[1]; |
1202 | if (NULL != name) | 1156 | GNUNET_memcpy (name_tmp, |
1203 | GNUNET_memcpy (name_tmp, name, name_len); | 1157 | name, |
1158 | name_len); | ||
1204 | rd_tmp = &name_tmp[name_len]; | 1159 | rd_tmp = &name_tmp[name_len]; |
1205 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_tmp); | 1160 | GNUNET_GNSRECORD_records_serialize (rd_count, |
1161 | rd, | ||
1162 | rd_ser_len, | ||
1163 | rd_tmp); | ||
1206 | ztn_ctx->success = GNUNET_OK; | 1164 | ztn_ctx->success = GNUNET_OK; |
1207 | GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, | 1165 | GNUNET_MQ_send (ztn_ctx->nc->mq, |
1208 | &ztnr_msg->gns_header.header, | 1166 | env); |
1209 | GNUNET_NO); | ||
1210 | GNUNET_free (ztnr_msg); | ||
1211 | } | 1167 | } |
1212 | 1168 | ||
1213 | 1169 | ||
1214 | /** | 1170 | /** |
1215 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message | 1171 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME message |
1216 | * | 1172 | * |
1217 | * @param cls unused | 1173 | * @param cls client client sending the message |
1218 | * @param client client sending the message | 1174 | * @param ztn_msg message of type 'struct ZoneToNameMessage' |
1219 | * @param message message of type 'struct ZoneToNameMessage' | ||
1220 | */ | 1175 | */ |
1221 | static void | 1176 | static void |
1222 | handle_zone_to_name (void *cls, | 1177 | handle_zone_to_name (void *cls, |
1223 | struct GNUNET_SERVER_Client *client, | 1178 | const struct ZoneToNameMessage *ztn_msg) |
1224 | const struct GNUNET_MessageHeader *message) | ||
1225 | { | 1179 | { |
1226 | struct NamestoreClient *nc; | 1180 | struct NamestoreClient *nc = cls; |
1227 | const struct ZoneToNameMessage *ztn_msg; | ||
1228 | struct ZoneToNameCtx ztn_ctx; | 1181 | struct ZoneToNameCtx ztn_ctx; |
1229 | struct ZoneToNameResponseMessage ztnr_msg; | 1182 | struct GNUNET_MQ_Envelope *env; |
1183 | struct ZoneToNameResponseMessage *ztnr_msg; | ||
1230 | 1184 | ||
1231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1232 | "Received `%s' message\n", | 1186 | "Received `%s' message\n", |
1233 | "ZONE_TO_NAME"); | 1187 | "ZONE_TO_NAME"); |
1234 | ztn_msg = (const struct ZoneToNameMessage *) message; | ||
1235 | nc = client_lookup (client); | ||
1236 | ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); | 1188 | ztn_ctx.rid = ntohl (ztn_msg->gns_header.r_id); |
1237 | ztn_ctx.nc = nc; | 1189 | ztn_ctx.nc = nc; |
1238 | ztn_ctx.success = GNUNET_NO; | 1190 | ztn_ctx.success = GNUNET_NO; |
@@ -1245,7 +1197,7 @@ handle_zone_to_name (void *cls, | |||
1245 | /* internal error, hang up instead of signalling something | 1197 | /* internal error, hang up instead of signalling something |
1246 | that might be wrong */ | 1198 | that might be wrong */ |
1247 | GNUNET_break (0); | 1199 | GNUNET_break (0); |
1248 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1200 | GNUNET_SERVICE_client_drop (nc->client); |
1249 | return; | 1201 | return; |
1250 | } | 1202 | } |
1251 | if (GNUNET_NO == ztn_ctx.success) | 1203 | if (GNUNET_NO == ztn_ctx.success) |
@@ -1253,17 +1205,14 @@ handle_zone_to_name (void *cls, | |||
1253 | /* no result found, send empty response */ | 1205 | /* no result found, send empty response */ |
1254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1255 | "Found no result for zone-to-name lookup.\n"); | 1207 | "Found no result for zone-to-name lookup.\n"); |
1256 | memset (&ztnr_msg, 0, sizeof (ztnr_msg)); | 1208 | env = GNUNET_MQ_msg (ztnr_msg, |
1257 | ztnr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); | 1209 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE); |
1258 | ztnr_msg.gns_header.header.size = htons (sizeof (ztnr_msg)); | 1210 | ztnr_msg->gns_header.r_id = ztn_msg->gns_header.r_id; |
1259 | ztnr_msg.gns_header.r_id = ztn_msg->gns_header.r_id; | 1211 | ztnr_msg->res = htons (GNUNET_NO); |
1260 | ztnr_msg.res = htons (GNUNET_NO); | 1212 | GNUNET_MQ_send (nc->mq, |
1261 | GNUNET_SERVER_notification_context_unicast (snc, | 1213 | env); |
1262 | client, | ||
1263 | &ztnr_msg.gns_header.header, | ||
1264 | GNUNET_NO); | ||
1265 | } | 1214 | } |
1266 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1215 | GNUNET_SERVICE_client_continue (nc->client); |
1267 | } | 1216 | } |
1268 | 1217 | ||
1269 | 1218 | ||
@@ -1324,13 +1273,12 @@ struct ZoneIterationProcResult | |||
1324 | */ | 1273 | */ |
1325 | static void | 1274 | static void |
1326 | zone_iterate_proc (void *cls, | 1275 | zone_iterate_proc (void *cls, |
1327 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, | 1276 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key, |
1328 | const char *name, | 1277 | const char *name, |
1329 | unsigned int rd_count, | 1278 | unsigned int rd_count, |
1330 | const struct GNUNET_GNSRECORD_Data *rd) | 1279 | const struct GNUNET_GNSRECORD_Data *rd) |
1331 | { | 1280 | { |
1332 | struct ZoneIterationProcResult *proc = cls; | 1281 | struct ZoneIterationProcResult *proc = cls; |
1333 | unsigned int i; | ||
1334 | int do_refresh_block; | 1282 | int do_refresh_block; |
1335 | 1283 | ||
1336 | if ((NULL == zone_key) && (NULL == name)) | 1284 | if ((NULL == zone_key) && (NULL == name)) |
@@ -1348,22 +1296,22 @@ zone_iterate_proc (void *cls, | |||
1348 | return; | 1296 | return; |
1349 | } | 1297 | } |
1350 | proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE; | 1298 | proc->res_iteration_finished = IT_SUCCESS_MORE_AVAILABLE; |
1351 | send_lookup_response (snc, | 1299 | send_lookup_response (proc->zi->nc, |
1352 | proc->zi->client->client, | ||
1353 | proc->zi->request_id, | 1300 | proc->zi->request_id, |
1354 | zone_key, | 1301 | zone_key, |
1355 | name, | 1302 | name, |
1356 | rd_count, | 1303 | rd_count, |
1357 | rd); | 1304 | rd); |
1358 | do_refresh_block = GNUNET_NO; | 1305 | do_refresh_block = GNUNET_NO; |
1359 | for (i=0;i<rd_count;i++) | 1306 | for (unsigned int i=0;i<rd_count;i++) |
1360 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) | 1307 | if (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) |
1361 | { | 1308 | { |
1362 | do_refresh_block = GNUNET_YES; | 1309 | do_refresh_block = GNUNET_YES; |
1363 | break; | 1310 | break; |
1364 | } | 1311 | } |
1365 | if (GNUNET_YES == do_refresh_block) | 1312 | if (GNUNET_YES == do_refresh_block) |
1366 | refresh_block (NULL, 0, | 1313 | refresh_block (NULL, |
1314 | 0, | ||
1367 | zone_key, | 1315 | zone_key, |
1368 | name, | 1316 | name, |
1369 | rd_count, | 1317 | rd_count, |
@@ -1381,7 +1329,8 @@ static void | |||
1381 | run_zone_iteration_round (struct ZoneIteration *zi) | 1329 | run_zone_iteration_round (struct ZoneIteration *zi) |
1382 | { | 1330 | { |
1383 | struct ZoneIterationProcResult proc; | 1331 | struct ZoneIterationProcResult proc; |
1384 | struct RecordResultMessage rrm; | 1332 | struct GNUNET_MQ_Envelope *env; |
1333 | struct RecordResultMessage *rrm; | ||
1385 | int ret; | 1334 | int ret; |
1386 | 1335 | ||
1387 | memset (&proc, 0, sizeof (proc)); | 1336 | memset (&proc, 0, sizeof (proc)); |
@@ -1411,16 +1360,13 @@ run_zone_iteration_round (struct ZoneIteration *zi) | |||
1411 | return; /* more results later */ | 1360 | return; /* more results later */ |
1412 | } | 1361 | } |
1413 | /* send empty response to indicate end of list */ | 1362 | /* send empty response to indicate end of list */ |
1414 | memset (&rrm, 0, sizeof (rrm)); | 1363 | env = GNUNET_MQ_msg (rrm, |
1415 | rrm.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); | 1364 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT); |
1416 | rrm.gns_header.header.size = htons (sizeof (rrm)); | 1365 | rrm->gns_header.r_id = htonl (zi->request_id); |
1417 | rrm.gns_header.r_id = htonl (zi->request_id); | 1366 | GNUNET_MQ_send (zi->nc->mq, |
1418 | GNUNET_SERVER_notification_context_unicast (snc, | 1367 | env); |
1419 | zi->client->client, | 1368 | GNUNET_CONTAINER_DLL_remove (zi->nc->op_head, |
1420 | &rrm.gns_header.header, | 1369 | zi->nc->op_tail, |
1421 | GNUNET_NO); | ||
1422 | GNUNET_CONTAINER_DLL_remove (zi->client->op_head, | ||
1423 | zi->client->op_tail, | ||
1424 | zi); | 1370 | zi); |
1425 | GNUNET_free (zi); | 1371 | GNUNET_free (zi); |
1426 | } | 1372 | } |
@@ -1429,67 +1375,49 @@ run_zone_iteration_round (struct ZoneIteration *zi) | |||
1429 | /** | 1375 | /** |
1430 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message | 1376 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START message |
1431 | * | 1377 | * |
1432 | * @param cls unused | 1378 | * @param cls the client sending the message |
1433 | * @param client the client sending the message | 1379 | * @param zis_msg message from the client |
1434 | * @param message message of type 'struct ZoneIterationStartMessage' | ||
1435 | */ | 1380 | */ |
1436 | static void | 1381 | static void |
1437 | handle_iteration_start (void *cls, | 1382 | handle_iteration_start (void *cls, |
1438 | struct GNUNET_SERVER_Client *client, | 1383 | const struct ZoneIterationStartMessage *zis_msg) |
1439 | const struct GNUNET_MessageHeader *message) | ||
1440 | { | 1384 | { |
1441 | const struct ZoneIterationStartMessage *zis_msg; | 1385 | struct NamestoreClient *nc = cls; |
1442 | struct NamestoreClient *nc; | ||
1443 | struct ZoneIteration *zi; | 1386 | struct ZoneIteration *zi; |
1444 | 1387 | ||
1445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); | 1388 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1446 | if (NULL == (nc = client_lookup (client))) | 1389 | "Received ZONE_ITERATION_START message\n"); |
1447 | { | ||
1448 | GNUNET_break (0); | ||
1449 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1450 | return; | ||
1451 | } | ||
1452 | zis_msg = (const struct ZoneIterationStartMessage *) message; | ||
1453 | zi = GNUNET_new (struct ZoneIteration); | 1390 | zi = GNUNET_new (struct ZoneIteration); |
1454 | zi->request_id = ntohl (zis_msg->gns_header.r_id); | 1391 | zi->request_id = ntohl (zis_msg->gns_header.r_id); |
1455 | zi->offset = 0; | 1392 | zi->offset = 0; |
1456 | zi->client = nc; | 1393 | zi->nc = nc; |
1457 | zi->zone = zis_msg->zone; | 1394 | zi->zone = zis_msg->zone; |
1458 | 1395 | ||
1459 | 1396 | GNUNET_CONTAINER_DLL_insert (nc->op_head, | |
1460 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | 1397 | nc->op_tail, |
1398 | zi); | ||
1461 | run_zone_iteration_round (zi); | 1399 | run_zone_iteration_round (zi); |
1462 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1400 | GNUNET_SERVICE_client_continue (nc->client); |
1463 | } | 1401 | } |
1464 | 1402 | ||
1465 | 1403 | ||
1466 | /** | 1404 | /** |
1467 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP message | 1405 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP message |
1468 | * | 1406 | * |
1469 | * @param cls unused | 1407 | * @param cls the client sending the message |
1470 | * @param client GNUNET_SERVER_Client sending the message | 1408 | * @param zis_msg message from the client |
1471 | * @param message message of type 'struct ZoneIterationStopMessage' | ||
1472 | */ | 1409 | */ |
1473 | static void | 1410 | static void |
1474 | handle_iteration_stop (void *cls, | 1411 | handle_iteration_stop (void *cls, |
1475 | struct GNUNET_SERVER_Client *client, | 1412 | const struct ZoneIterationStopMessage *zis_msg) |
1476 | const struct GNUNET_MessageHeader *message) | ||
1477 | { | 1413 | { |
1478 | struct NamestoreClient *nc; | 1414 | struct NamestoreClient *nc = cls; |
1479 | struct ZoneIteration *zi; | 1415 | struct ZoneIteration *zi; |
1480 | const struct ZoneIterationStopMessage *zis_msg; | ||
1481 | uint32_t rid; | 1416 | uint32_t rid; |
1482 | 1417 | ||
1483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1418 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1484 | "Received `%s' message\n", | 1419 | "Received `%s' message\n", |
1485 | "ZONE_ITERATION_STOP"); | 1420 | "ZONE_ITERATION_STOP"); |
1486 | if (NULL == (nc = client_lookup(client))) | ||
1487 | { | ||
1488 | GNUNET_break (0); | ||
1489 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1490 | return; | ||
1491 | } | ||
1492 | zis_msg = (const struct ZoneIterationStopMessage *) message; | ||
1493 | rid = ntohl (zis_msg->gns_header.r_id); | 1421 | rid = ntohl (zis_msg->gns_header.r_id); |
1494 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 1422 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
1495 | if (zi->request_id == rid) | 1423 | if (zi->request_id == rid) |
@@ -1497,42 +1425,33 @@ handle_iteration_stop (void *cls, | |||
1497 | if (NULL == zi) | 1425 | if (NULL == zi) |
1498 | { | 1426 | { |
1499 | GNUNET_break (0); | 1427 | GNUNET_break (0); |
1500 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1428 | GNUNET_SERVICE_client_drop (nc->client); |
1501 | return; | 1429 | return; |
1502 | } | 1430 | } |
1503 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); | 1431 | GNUNET_CONTAINER_DLL_remove (nc->op_head, |
1432 | nc->op_tail, | ||
1433 | zi); | ||
1504 | GNUNET_free (zi); | 1434 | GNUNET_free (zi); |
1505 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1435 | GNUNET_SERVICE_client_continue (nc->client); |
1506 | } | 1436 | } |
1507 | 1437 | ||
1508 | 1438 | ||
1509 | /** | 1439 | /** |
1510 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message | 1440 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT message |
1511 | * | 1441 | * |
1512 | * @param cls unused | 1442 | * @param cls the client sending the message |
1513 | * @param client GNUNET_SERVER_Client sending the message | 1443 | * @param message message from the client |
1514 | * @param message message of type 'struct ZoneIterationNextMessage' | ||
1515 | */ | 1444 | */ |
1516 | static void | 1445 | static void |
1517 | handle_iteration_next (void *cls, | 1446 | handle_iteration_next (void *cls, |
1518 | struct GNUNET_SERVER_Client *client, | 1447 | const struct ZoneIterationNextMessage *zis_msg) |
1519 | const struct GNUNET_MessageHeader *message) | ||
1520 | { | 1448 | { |
1521 | struct NamestoreClient *nc; | 1449 | struct NamestoreClient *nc = cls; |
1522 | struct ZoneIteration *zi; | 1450 | struct ZoneIteration *zi; |
1523 | const struct ZoneIterationNextMessage *zis_msg; | ||
1524 | uint32_t rid; | 1451 | uint32_t rid; |
1525 | 1452 | ||
1526 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1527 | "Received `%s' message\n", | 1454 | "Received ZONE_ITERATION_NEXT message\n"); |
1528 | "ZONE_ITERATION_NEXT"); | ||
1529 | if (NULL == (nc = client_lookup(client))) | ||
1530 | { | ||
1531 | GNUNET_break (0); | ||
1532 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1533 | return; | ||
1534 | } | ||
1535 | zis_msg = (const struct ZoneIterationNextMessage *) message; | ||
1536 | rid = ntohl (zis_msg->gns_header.r_id); | 1455 | rid = ntohl (zis_msg->gns_header.r_id); |
1537 | for (zi = nc->op_head; NULL != zi; zi = zi->next) | 1456 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
1538 | if (zi->request_id == rid) | 1457 | if (zi->request_id == rid) |
@@ -1540,11 +1459,11 @@ handle_iteration_next (void *cls, | |||
1540 | if (NULL == zi) | 1459 | if (NULL == zi) |
1541 | { | 1460 | { |
1542 | GNUNET_break (0); | 1461 | GNUNET_break (0); |
1543 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1462 | GNUNET_SERVICE_client_drop (nc->client); |
1544 | return; | 1463 | return; |
1545 | } | 1464 | } |
1546 | run_zone_iteration_round (zi); | 1465 | run_zone_iteration_round (zi); |
1547 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1466 | GNUNET_SERVICE_client_continue (nc->client); |
1548 | } | 1467 | } |
1549 | 1468 | ||
1550 | 1469 | ||
@@ -1556,14 +1475,13 @@ handle_iteration_next (void *cls, | |||
1556 | static void | 1475 | static void |
1557 | monitor_sync (struct ZoneMonitor *zm) | 1476 | monitor_sync (struct ZoneMonitor *zm) |
1558 | { | 1477 | { |
1559 | struct GNUNET_MessageHeader sync; | 1478 | struct GNUNET_MQ_Envelope *env; |
1560 | 1479 | struct GNUNET_MessageHeader *sync; | |
1561 | sync.size = htons (sizeof (struct GNUNET_MessageHeader)); | 1480 | |
1562 | sync.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); | 1481 | env = GNUNET_MQ_msg (sync, |
1563 | GNUNET_SERVER_notification_context_unicast (monitor_nc, | 1482 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC); |
1564 | zm->nc->client, | 1483 | GNUNET_MQ_send (zm->nc->mq, |
1565 | &sync, | 1484 | env); |
1566 | GNUNET_NO); | ||
1567 | } | 1485 | } |
1568 | 1486 | ||
1569 | 1487 | ||
@@ -1600,47 +1518,45 @@ monitor_iterate_cb (void *cls, | |||
1600 | monitor_sync (zm); | 1518 | monitor_sync (zm); |
1601 | return; | 1519 | return; |
1602 | } | 1520 | } |
1603 | send_lookup_response (monitor_nc, | 1521 | send_lookup_response (zm->nc, |
1604 | zm->nc->client, | ||
1605 | 0, | 1522 | 0, |
1606 | zone_key, | 1523 | zone_key, |
1607 | name, | 1524 | name, |
1608 | rd_count, | 1525 | rd_count, |
1609 | rd); | 1526 | rd); |
1610 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); | 1527 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, |
1528 | zm); | ||
1611 | } | 1529 | } |
1612 | 1530 | ||
1613 | 1531 | ||
1614 | /** | 1532 | /** |
1615 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message | 1533 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START message |
1616 | * | 1534 | * |
1617 | * @param cls unused | 1535 | * @param cls the client sending the message |
1618 | * @param client the client sending the message | 1536 | * @param message message from the client |
1619 | * @param message message of type 'struct ZoneMonitorStartMessage' | ||
1620 | */ | 1537 | */ |
1621 | static void | 1538 | static void |
1622 | handle_monitor_start (void *cls, | 1539 | handle_monitor_start (void *cls, |
1623 | struct GNUNET_SERVER_Client *client, | 1540 | const struct ZoneMonitorStartMessage *zis_msg) |
1624 | const struct GNUNET_MessageHeader *message) | ||
1625 | { | 1541 | { |
1626 | const struct ZoneMonitorStartMessage *zis_msg; | 1542 | struct NamestoreClient *nc = cls; |
1627 | struct ZoneMonitor *zm; | 1543 | struct ZoneMonitor *zm; |
1628 | 1544 | ||
1629 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1630 | "Received `%s' message\n", | 1546 | "Received ZONE_MONITOR_START message\n"); |
1631 | "ZONE_MONITOR_START"); | ||
1632 | zis_msg = (const struct ZoneMonitorStartMessage *) message; | ||
1633 | zm = GNUNET_new (struct ZoneMonitor); | 1547 | zm = GNUNET_new (struct ZoneMonitor); |
1634 | zm->offset = 0; | 1548 | zm->nc = nc; |
1635 | zm->nc = client_lookup (client); | ||
1636 | zm->zone = zis_msg->zone; | 1549 | zm->zone = zis_msg->zone; |
1637 | GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, zm); | 1550 | GNUNET_CONTAINER_DLL_insert (monitor_head, |
1638 | GNUNET_SERVER_client_mark_monitor (client); | 1551 | monitor_tail, |
1639 | GNUNET_SERVER_disable_receive_done_warning (client); | 1552 | zm); |
1640 | GNUNET_SERVER_notification_context_add (monitor_nc, | 1553 | GNUNET_SERVICE_client_mark_monitor (nc->client); |
1641 | client); | 1554 | GNUNET_SERVICE_client_disable_continue_warning (nc->client); |
1555 | GNUNET_notification_context_add (monitor_nc, | ||
1556 | nc->mq); | ||
1642 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) | 1557 | if (GNUNET_YES == ntohl (zis_msg->iterate_first)) |
1643 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, zm); | 1558 | zm->task = GNUNET_SCHEDULER_add_now (&monitor_next, |
1559 | zm); | ||
1644 | else | 1560 | else |
1645 | monitor_sync (zm); | 1561 | monitor_sync (zm); |
1646 | } | 1562 | } |
@@ -1659,14 +1575,17 @@ monitor_next (void *cls) | |||
1659 | 1575 | ||
1660 | zm->task = NULL; | 1576 | zm->task = NULL; |
1661 | ret = GSN_database->iterate_records (GSN_database->cls, | 1577 | ret = GSN_database->iterate_records (GSN_database->cls, |
1662 | (0 == memcmp (&zm->zone, &zero, sizeof (zero))) | 1578 | (0 == memcmp (&zm->zone, |
1579 | &zero, | ||
1580 | sizeof (zero))) | ||
1663 | ? NULL | 1581 | ? NULL |
1664 | : &zm->zone, | 1582 | : &zm->zone, |
1665 | zm->offset++, | 1583 | zm->offset++, |
1666 | &monitor_iterate_cb, zm); | 1584 | &monitor_iterate_cb, |
1585 | zm); | ||
1667 | if (GNUNET_SYSERR == ret) | 1586 | if (GNUNET_SYSERR == ret) |
1668 | { | 1587 | { |
1669 | GNUNET_SERVER_client_disconnect (zm->nc->client); | 1588 | GNUNET_SERVICE_client_drop (zm->nc->client); |
1670 | return; | 1589 | return; |
1671 | } | 1590 | } |
1672 | if (GNUNET_NO == ret) | 1591 | if (GNUNET_NO == ret) |
@@ -1682,35 +1601,20 @@ monitor_next (void *cls) | |||
1682 | * Process namestore requests. | 1601 | * Process namestore requests. |
1683 | * | 1602 | * |
1684 | * @param cls closure | 1603 | * @param cls closure |
1685 | * @param server the initialized server | ||
1686 | * @param cfg configuration to use | 1604 | * @param cfg configuration to use |
1605 | * @param service the initialized service | ||
1687 | */ | 1606 | */ |
1688 | static void | 1607 | static void |
1689 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 1608 | run (void *cls, |
1690 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1609 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1610 | struct GNUNET_SERVICE_Handle *service) | ||
1691 | { | 1611 | { |
1692 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
1693 | {&handle_record_store, NULL, | ||
1694 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, 0}, | ||
1695 | {&handle_record_lookup, NULL, | ||
1696 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, 0}, | ||
1697 | {&handle_zone_to_name, NULL, | ||
1698 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, sizeof (struct ZoneToNameMessage) }, | ||
1699 | {&handle_iteration_start, NULL, | ||
1700 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, sizeof (struct ZoneIterationStartMessage) }, | ||
1701 | {&handle_iteration_next, NULL, | ||
1702 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, sizeof (struct ZoneIterationNextMessage) }, | ||
1703 | {&handle_iteration_stop, NULL, | ||
1704 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, sizeof (struct ZoneIterationStopMessage) }, | ||
1705 | {&handle_monitor_start, NULL, | ||
1706 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, sizeof (struct ZoneMonitorStartMessage) }, | ||
1707 | {NULL, NULL, 0, 0} | ||
1708 | }; | ||
1709 | char *database; | 1612 | char *database; |
1710 | 1613 | ||
1711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | 1614 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1615 | "Starting namestore service\n"); | ||
1712 | GSN_cfg = cfg; | 1616 | GSN_cfg = cfg; |
1713 | monitor_nc = GNUNET_SERVER_notification_context_create (server, 1); | 1617 | monitor_nc = GNUNET_notification_context_create (1); |
1714 | namecache = GNUNET_NAMECACHE_connect (cfg); | 1618 | namecache = GNUNET_NAMECACHE_connect (cfg); |
1715 | /* Loading database plugin */ | 1619 | /* Loading database plugin */ |
1716 | if (GNUNET_OK != | 1620 | if (GNUNET_OK != |
@@ -1727,39 +1631,58 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
1727 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, | 1631 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, |
1728 | (void *) GSN_cfg); | 1632 | (void *) GSN_cfg); |
1729 | GNUNET_free (database); | 1633 | GNUNET_free (database); |
1634 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | ||
1635 | NULL); | ||
1730 | if (NULL == GSN_database) | 1636 | if (NULL == GSN_database) |
1731 | { | 1637 | { |
1732 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1638 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1733 | "Could not load database backend `%s'\n", | 1639 | "Could not load database backend `%s'\n", |
1734 | db_lib_name); | 1640 | db_lib_name); |
1735 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 1641 | GNUNET_SCHEDULER_shutdown (); |
1736 | return; | 1642 | return; |
1737 | } | 1643 | } |
1738 | |||
1739 | /* Configuring server handles */ | ||
1740 | GNUNET_SERVER_add_handlers (server, handlers); | ||
1741 | snc = GNUNET_SERVER_notification_context_create (server, 16); | ||
1742 | GNUNET_SERVER_disconnect_notify (server, | ||
1743 | &client_disconnect_notification, | ||
1744 | NULL); | ||
1745 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | ||
1746 | NULL); | ||
1747 | } | 1644 | } |
1748 | 1645 | ||
1749 | 1646 | ||
1750 | /** | 1647 | /** |
1751 | * The main function for the template service. | 1648 | * Define "main" method using service macro. |
1752 | * | ||
1753 | * @param argc number of arguments from the command line | ||
1754 | * @param argv command line arguments | ||
1755 | * @return 0 ok, 1 on error | ||
1756 | */ | 1649 | */ |
1757 | int | 1650 | GNUNET_SERVICE_MAIN |
1758 | main (int argc, char *const *argv) | 1651 | ("namestore", |
1759 | { | 1652 | GNUNET_SERVICE_OPTION_NONE, |
1760 | return (GNUNET_OK == | 1653 | &run, |
1761 | GNUNET_SERVICE_run (argc, argv, "namestore", | 1654 | &client_connect_cb, |
1762 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 1655 | &client_disconnect_cb, |
1763 | } | 1656 | NULL, |
1657 | GNUNET_MQ_hd_var_size (record_store, | ||
1658 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, | ||
1659 | struct RecordStoreMessage, | ||
1660 | NULL), | ||
1661 | GNUNET_MQ_hd_var_size (record_lookup, | ||
1662 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, | ||
1663 | struct LabelLookupMessage, | ||
1664 | NULL), | ||
1665 | GNUNET_MQ_hd_fixed_size (zone_to_name, | ||
1666 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME, | ||
1667 | struct ZoneToNameMessage, | ||
1668 | NULL), | ||
1669 | GNUNET_MQ_hd_fixed_size (iteration_start, | ||
1670 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START, | ||
1671 | struct ZoneIterationStartMessage, | ||
1672 | NULL), | ||
1673 | GNUNET_MQ_hd_fixed_size (iteration_next, | ||
1674 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT, | ||
1675 | struct ZoneIterationNextMessage, | ||
1676 | NULL), | ||
1677 | GNUNET_MQ_hd_fixed_size (iteration_stop, | ||
1678 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, | ||
1679 | struct ZoneIterationStopMessage, | ||
1680 | NULL), | ||
1681 | GNUNET_MQ_hd_fixed_size (monitor_start, | ||
1682 | GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START, | ||
1683 | struct ZoneMonitorStartMessage, | ||
1684 | NULL), | ||
1685 | GNUNET_MQ_handler_end ()); | ||
1686 | |||
1764 | 1687 | ||
1765 | /* end of gnunet-service-namestore.c */ | 1688 | /* end of gnunet-service-namestore.c */ |