diff options
Diffstat (limited to 'src/peerinfo/peerinfo_api.c')
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 376 |
1 files changed, 172 insertions, 204 deletions
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index b6ccdfd07..444ae98e2 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -37,8 +37,7 @@ | |||
37 | * @param cls closure | 37 | * @param cls closure |
38 | * @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error | 38 | * @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error |
39 | */ | 39 | */ |
40 | typedef void (*TransmissionContinuation)(void *cls, | 40 | typedef void (*TransmissionContinuation) (void *cls, int success); |
41 | int success); | ||
42 | 41 | ||
43 | 42 | ||
44 | /** | 43 | /** |
@@ -50,7 +49,7 @@ struct TransmissionQueueEntry | |||
50 | * This is a linked list. | 49 | * This is a linked list. |
51 | */ | 50 | */ |
52 | struct TransmissionQueueEntry *next; | 51 | struct TransmissionQueueEntry *next; |
53 | 52 | ||
54 | /** | 53 | /** |
55 | * This is a linked list. | 54 | * This is a linked list. |
56 | */ | 55 | */ |
@@ -61,7 +60,7 @@ struct TransmissionQueueEntry | |||
61 | * case we must consider sending the next entry immediately). | 60 | * case we must consider sending the next entry immediately). |
62 | */ | 61 | */ |
63 | TransmissionContinuation cont; | 62 | TransmissionContinuation cont; |
64 | 63 | ||
65 | /** | 64 | /** |
66 | * Closure for 'cont'. | 65 | * Closure for 'cont'. |
67 | */ | 66 | */ |
@@ -158,29 +157,27 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | |||
158 | struct TransmissionQueueEntry *tqe; | 157 | struct TransmissionQueueEntry *tqe; |
159 | 158 | ||
160 | while (NULL != (tqe = h->tq_head)) | 159 | while (NULL != (tqe = h->tq_head)) |
161 | { | 160 | { |
162 | GNUNET_CONTAINER_DLL_remove (h->tq_head, | 161 | GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); |
163 | h->tq_tail, | 162 | if (tqe->cont != NULL) |
164 | tqe); | 163 | tqe->cont (tqe->cont_cls, GNUNET_SYSERR); |
165 | if (tqe->cont != NULL) | 164 | GNUNET_free (tqe); |
166 | tqe->cont (tqe->cont_cls, GNUNET_SYSERR); | 165 | } |
167 | GNUNET_free (tqe); | ||
168 | } | ||
169 | if (h->th != NULL) | 166 | if (h->th != NULL) |
170 | { | 167 | { |
171 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | 168 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
172 | h->th = NULL; | 169 | h->th = NULL; |
173 | } | 170 | } |
174 | if (NULL != h->client) | 171 | if (NULL != h->client) |
175 | { | 172 | { |
176 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); | 173 | GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); |
177 | h->client = NULL; | 174 | h->client = NULL; |
178 | } | 175 | } |
179 | if (GNUNET_SCHEDULER_NO_TASK != h->r_task) | 176 | if (GNUNET_SCHEDULER_NO_TASK != h->r_task) |
180 | { | 177 | { |
181 | GNUNET_SCHEDULER_cancel (h->r_task); | 178 | GNUNET_SCHEDULER_cancel (h->r_task); |
182 | h->r_task = GNUNET_SCHEDULER_NO_TASK; | 179 | h->r_task = GNUNET_SCHEDULER_NO_TASK; |
183 | } | 180 | } |
184 | GNUNET_free (h); | 181 | GNUNET_free (h); |
185 | } | 182 | } |
186 | 183 | ||
@@ -191,8 +188,7 @@ GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) | |||
191 | * | 188 | * |
192 | * @param h handle to the service | 189 | * @param h handle to the service |
193 | */ | 190 | */ |
194 | static void | 191 | static void trigger_transmit (struct GNUNET_PEERINFO_Handle *h); |
195 | trigger_transmit (struct GNUNET_PEERINFO_Handle *h); | ||
196 | 192 | ||
197 | 193 | ||
198 | /** | 194 | /** |
@@ -200,8 +196,7 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h); | |||
200 | * | 196 | * |
201 | * @param h handle to the service | 197 | * @param h handle to the service |
202 | */ | 198 | */ |
203 | static void | 199 | static void reconnect (struct GNUNET_PEERINFO_Handle *h); |
204 | reconnect (struct GNUNET_PEERINFO_Handle *h); | ||
205 | 200 | ||
206 | /** | 201 | /** |
207 | * Task scheduled to re-try connecting to the peerinfo service. | 202 | * Task scheduled to re-try connecting to the peerinfo service. |
@@ -210,8 +205,7 @@ reconnect (struct GNUNET_PEERINFO_Handle *h); | |||
210 | * @param ts scheduler context | 205 | * @param ts scheduler context |
211 | */ | 206 | */ |
212 | static void | 207 | static void |
213 | reconnect_task (void *cls, | 208 | reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
214 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
215 | { | 209 | { |
216 | struct GNUNET_PEERINFO_Handle *h = cls; | 210 | struct GNUNET_PEERINFO_Handle *h = cls; |
217 | 211 | ||
@@ -229,28 +223,27 @@ static void | |||
229 | reconnect (struct GNUNET_PEERINFO_Handle *h) | 223 | reconnect (struct GNUNET_PEERINFO_Handle *h) |
230 | { | 224 | { |
231 | if (h->r_task != GNUNET_SCHEDULER_NO_TASK) | 225 | if (h->r_task != GNUNET_SCHEDULER_NO_TASK) |
232 | { | 226 | { |
233 | GNUNET_SCHEDULER_cancel (h->r_task); | 227 | GNUNET_SCHEDULER_cancel (h->r_task); |
234 | h->r_task = GNUNET_SCHEDULER_NO_TASK; | 228 | h->r_task = GNUNET_SCHEDULER_NO_TASK; |
235 | } | 229 | } |
236 | if (NULL != h->th) | 230 | if (NULL != h->th) |
237 | { | 231 | { |
238 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); | 232 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
239 | h->th = NULL; | 233 | h->th = NULL; |
240 | } | 234 | } |
241 | if (NULL != h->client) | 235 | if (NULL != h->client) |
242 | { | 236 | { |
243 | GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); | 237 | GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); |
244 | h->client = NULL; | 238 | h->client = NULL; |
245 | } | 239 | } |
246 | h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg); | 240 | h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg); |
247 | if (NULL == h->client) | 241 | if (NULL == h->client) |
248 | { | 242 | { |
249 | h->r_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 243 | h->r_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
250 | &reconnect_task, | 244 | &reconnect_task, h); |
251 | h); | 245 | return; |
252 | return; | 246 | } |
253 | } | ||
254 | trigger_transmit (h); | 247 | trigger_transmit (h); |
255 | } | 248 | } |
256 | 249 | ||
@@ -275,31 +268,25 @@ do_transmit (void *cls, size_t size, void *buf) | |||
275 | if (tqe == NULL) | 268 | if (tqe == NULL) |
276 | return 0; | 269 | return 0; |
277 | if (buf == NULL) | 270 | if (buf == NULL) |
278 | { | 271 | { |
279 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 272 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
280 | _("Failed to transmit message to `%s' service.\n"), | 273 | _("Failed to transmit message to `%s' service.\n"), "PEERINFO"); |
281 | "PEERINFO"); | 274 | GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); |
282 | GNUNET_CONTAINER_DLL_remove (h->tq_head, | 275 | reconnect (h); |
283 | h->tq_tail, | 276 | if (tqe->cont != NULL) |
284 | tqe); | 277 | tqe->cont (tqe->cont_cls, GNUNET_SYSERR); |
285 | reconnect (h); | 278 | GNUNET_free (tqe); |
286 | if (tqe->cont != NULL) | 279 | return 0; |
287 | tqe->cont (tqe->cont_cls, GNUNET_SYSERR); | 280 | } |
288 | GNUNET_free (tqe); | ||
289 | return 0; | ||
290 | } | ||
291 | ret = tqe->size; | 281 | ret = tqe->size; |
292 | GNUNET_assert (size >= ret); | 282 | GNUNET_assert (size >= ret); |
293 | memcpy (buf, &tqe[1], ret); | 283 | memcpy (buf, &tqe[1], ret); |
294 | #if DEBUG_PEERINFO | 284 | #if DEBUG_PEERINFO |
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
296 | "Transmitting request of size %u to `%s' service.\n", | 286 | "Transmitting request of size %u to `%s' service.\n", |
297 | ret, | 287 | ret, "PEERINFO"); |
298 | "PEERINFO"); | ||
299 | #endif | 288 | #endif |
300 | GNUNET_CONTAINER_DLL_remove (h->tq_head, | 289 | GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); |
301 | h->tq_tail, | ||
302 | tqe); | ||
303 | if (tqe->cont != NULL) | 290 | if (tqe->cont != NULL) |
304 | tqe->cont (tqe->cont_cls, GNUNET_OK); | 291 | tqe->cont (tqe->cont_cls, GNUNET_OK); |
305 | else | 292 | else |
@@ -327,15 +314,15 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h) | |||
327 | if (h->in_receive == GNUNET_YES) | 314 | if (h->in_receive == GNUNET_YES) |
328 | return; | 315 | return; |
329 | if (NULL == h->client) | 316 | if (NULL == h->client) |
330 | { | 317 | { |
331 | reconnect (h); | 318 | reconnect (h); |
332 | return; | 319 | return; |
333 | } | 320 | } |
334 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 321 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, |
335 | tqe->size, | 322 | tqe->size, |
336 | GNUNET_TIME_absolute_get_remaining (tqe->timeout), | 323 | GNUNET_TIME_absolute_get_remaining |
337 | GNUNET_YES, | 324 | (tqe->timeout), GNUNET_YES, |
338 | &do_transmit, h); | 325 | &do_transmit, h); |
339 | } | 326 | } |
340 | 327 | ||
341 | 328 | ||
@@ -352,28 +339,24 @@ trigger_transmit (struct GNUNET_PEERINFO_Handle *h) | |||
352 | */ | 339 | */ |
353 | void | 340 | void |
354 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, | 341 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, |
355 | const struct GNUNET_HELLO_Message *hello) | 342 | const struct GNUNET_HELLO_Message *hello) |
356 | { | 343 | { |
357 | uint16_t hs = GNUNET_HELLO_size (hello); | 344 | uint16_t hs = GNUNET_HELLO_size (hello); |
358 | struct TransmissionQueueEntry *tqe; | 345 | struct TransmissionQueueEntry *tqe; |
359 | 346 | ||
360 | #if DEBUG_PEERINFO | 347 | #if DEBUG_PEERINFO |
361 | struct GNUNET_PeerIdentity peer; | 348 | struct GNUNET_PeerIdentity peer; |
349 | |||
362 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer)); | 350 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer)); |
363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
364 | "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n", | 352 | "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n", |
365 | GNUNET_i2s(&peer), | 353 | GNUNET_i2s (&peer), hs, "HELLO"); |
366 | hs, | ||
367 | "HELLO"); | ||
368 | #endif | 354 | #endif |
369 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + hs); | 355 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + hs); |
370 | tqe->size = hs; | 356 | tqe->size = hs; |
371 | tqe->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 357 | tqe->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
372 | memcpy (&tqe[1], hello, hs); | 358 | memcpy (&tqe[1], hello, hs); |
373 | GNUNET_CONTAINER_DLL_insert_after (h->tq_head, | 359 | GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe); |
374 | h->tq_tail, | ||
375 | h->tq_tail, | ||
376 | tqe); | ||
377 | trigger_transmit (h); | 360 | trigger_transmit (h); |
378 | } | 361 | } |
379 | 362 | ||
@@ -428,8 +411,7 @@ struct GNUNET_PEERINFO_IteratorContext | |||
428 | * @param msg message received, NULL on timeout or fatal error | 411 | * @param msg message received, NULL on timeout or fatal error |
429 | */ | 412 | */ |
430 | static void | 413 | static void |
431 | peerinfo_handler (void *cls, | 414 | peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
432 | const struct GNUNET_MessageHeader *msg) | ||
433 | { | 415 | { |
434 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; | 416 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
435 | const struct InfoMessage *im; | 417 | const struct InfoMessage *im; |
@@ -438,79 +420,76 @@ peerinfo_handler (void *cls, | |||
438 | 420 | ||
439 | ic->h->in_receive = GNUNET_NO; | 421 | ic->h->in_receive = GNUNET_NO; |
440 | if (msg == NULL) | 422 | if (msg == NULL) |
441 | { | 423 | { |
442 | reconnect (ic->h); | 424 | reconnect (ic->h); |
443 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 425 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
444 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | 426 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
445 | if (ic->callback != NULL) | 427 | if (ic->callback != NULL) |
446 | ic->callback (ic->callback_cls, NULL, NULL, | 428 | ic->callback (ic->callback_cls, NULL, NULL, |
447 | _("Failed to receive response from `PEERINFO' service.")); | 429 | _("Failed to receive response from `PEERINFO' service.")); |
448 | GNUNET_free (ic); | 430 | GNUNET_free (ic); |
449 | return; | 431 | return; |
450 | } | 432 | } |
451 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END) | 433 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END) |
452 | { | 434 | { |
453 | #if DEBUG_PEERINFO | 435 | #if DEBUG_PEERINFO |
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 436 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
455 | "Received end of list of peers from `%s' service\n", | 437 | "Received end of list of peers from `%s' service\n", |
456 | "PEERINFO"); | 438 | "PEERINFO"); |
457 | #endif | 439 | #endif |
458 | trigger_transmit (ic->h); | 440 | trigger_transmit (ic->h); |
459 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 441 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
460 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | 442 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
461 | if (ic->callback != NULL) | 443 | if (ic->callback != NULL) |
462 | ic->callback (ic->callback_cls, NULL, NULL, NULL); | 444 | ic->callback (ic->callback_cls, NULL, NULL, NULL); |
463 | GNUNET_free (ic); | 445 | GNUNET_free (ic); |
464 | return; | 446 | return; |
465 | } | 447 | } |
466 | ms = ntohs (msg->size); | 448 | ms = ntohs (msg->size); |
467 | if ((ms < sizeof (struct InfoMessage)) || | 449 | if ((ms < sizeof (struct InfoMessage)) || |
468 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) | 450 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) |
451 | { | ||
452 | GNUNET_break (0); | ||
453 | reconnect (ic->h); | ||
454 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
455 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | ||
456 | if (ic->callback != NULL) | ||
457 | ic->callback (ic->callback_cls, NULL, NULL, | ||
458 | _("Received invalid message from `PEERINFO' service.\n")); | ||
459 | GNUNET_free (ic); | ||
460 | return; | ||
461 | } | ||
462 | im = (const struct InfoMessage *) msg; | ||
463 | GNUNET_break (0 == ntohl (im->reserved)); | ||
464 | hello = NULL; | ||
465 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
466 | { | ||
467 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
468 | if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) | ||
469 | { | 469 | { |
470 | GNUNET_break (0); | 470 | GNUNET_break (0); |
471 | reconnect (ic->h); | 471 | reconnect (ic->h); |
472 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 472 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
473 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | 473 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
474 | if (ic->callback != NULL) | 474 | if (ic->callback != NULL) |
475 | ic->callback (ic->callback_cls, NULL, NULL, | 475 | ic->callback (ic->callback_cls, NULL, NULL, |
476 | _("Received invalid message from `PEERINFO' service.\n")); | 476 | _("Received invalid message from `PEERINFO' service.\n")); |
477 | GNUNET_free (ic); | 477 | GNUNET_free (ic); |
478 | return; | 478 | return; |
479 | } | 479 | } |
480 | im = (const struct InfoMessage *) msg; | 480 | } |
481 | GNUNET_break (0 == ntohl (im->reserved)); | ||
482 | hello = NULL; | ||
483 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
484 | { | ||
485 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
486 | if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) | ||
487 | { | ||
488 | GNUNET_break (0); | ||
489 | reconnect (ic->h); | ||
490 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
491 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | ||
492 | if (ic->callback != NULL) | ||
493 | ic->callback (ic->callback_cls, NULL, NULL, | ||
494 | _("Received invalid message from `PEERINFO' service.\n")); | ||
495 | GNUNET_free (ic); | ||
496 | return; | ||
497 | } | ||
498 | } | ||
499 | #if DEBUG_PEERINFO | 481 | #if DEBUG_PEERINFO |
500 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
501 | "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", | 483 | "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", |
502 | (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), | 484 | (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), |
503 | "HELLO", | 485 | "HELLO", GNUNET_i2s (&im->peer), "PEERINFO"); |
504 | GNUNET_i2s (&im->peer), | ||
505 | "PEERINFO"); | ||
506 | #endif | 486 | #endif |
507 | ic->h->in_receive = GNUNET_YES; | 487 | ic->h->in_receive = GNUNET_YES; |
508 | if (ic->callback != NULL) | 488 | if (ic->callback != NULL) |
509 | ic->callback (ic->callback_cls, &im->peer, hello, NULL); | 489 | ic->callback (ic->callback_cls, &im->peer, hello, NULL); |
510 | GNUNET_CLIENT_receive (ic->h->client, | 490 | GNUNET_CLIENT_receive (ic->h->client, |
511 | &peerinfo_handler, | 491 | &peerinfo_handler, |
512 | ic, | 492 | ic, GNUNET_TIME_absolute_get_remaining (ic->timeout)); |
513 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); | ||
514 | } | 493 | } |
515 | 494 | ||
516 | 495 | ||
@@ -522,37 +501,35 @@ peerinfo_handler (void *cls, | |||
522 | * @param transmit_success GNUNET_OK if transmission worked | 501 | * @param transmit_success GNUNET_OK if transmission worked |
523 | */ | 502 | */ |
524 | static void | 503 | static void |
525 | iterator_start_receive (void *cls, | 504 | iterator_start_receive (void *cls, int transmit_success) |
526 | int transmit_success) | ||
527 | { | 505 | { |
528 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; | 506 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
529 | 507 | ||
530 | if (GNUNET_OK != transmit_success) | 508 | if (GNUNET_OK != transmit_success) |
509 | { | ||
510 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
531 | { | 511 | { |
532 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 512 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
533 | { | 513 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
534 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | 514 | } |
535 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 515 | reconnect (ic->h); |
536 | } | 516 | if (ic->callback != NULL) |
537 | reconnect (ic->h); | 517 | ic->callback (ic->callback_cls, NULL, NULL, |
538 | if (ic->callback != NULL) | 518 | _ |
539 | ic->callback (ic->callback_cls, NULL, NULL, | 519 | ("Failed to transmit iteration request to `PEERINFO' service\n")); |
540 | _("Failed to transmit iteration request to `PEERINFO' service\n")); | 520 | GNUNET_free (ic); |
541 | GNUNET_free (ic); | 521 | return; |
542 | return; | 522 | } |
543 | } | ||
544 | #if DEBUG_PEERINFO | 523 | #if DEBUG_PEERINFO |
545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
546 | "Waiting for response from `%s' service.\n", | 525 | "Waiting for response from `%s' service.\n", "PEERINFO"); |
547 | "PEERINFO"); | ||
548 | #endif | 526 | #endif |
549 | ic->h->in_receive = GNUNET_YES; | 527 | ic->h->in_receive = GNUNET_YES; |
550 | ic->in_receive = GNUNET_YES; | 528 | ic->in_receive = GNUNET_YES; |
551 | ic->tqe = NULL; | 529 | ic->tqe = NULL; |
552 | GNUNET_CLIENT_receive (ic->h->client, | 530 | GNUNET_CLIENT_receive (ic->h->client, |
553 | &peerinfo_handler, | 531 | &peerinfo_handler, |
554 | ic, | 532 | ic, GNUNET_TIME_absolute_get_remaining (ic->timeout)); |
555 | GNUNET_TIME_absolute_get_remaining (ic->timeout)); | ||
556 | } | 533 | } |
557 | 534 | ||
558 | 535 | ||
@@ -563,21 +540,19 @@ iterator_start_receive (void *cls, | |||
563 | * @param tc scheduler context | 540 | * @param tc scheduler context |
564 | */ | 541 | */ |
565 | static void | 542 | static void |
566 | signal_timeout (void *cls, | 543 | signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
567 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
568 | { | 544 | { |
569 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; | 545 | struct GNUNET_PEERINFO_IteratorContext *ic = cls; |
570 | 546 | ||
571 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 547 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
572 | if (! ic->in_receive) | 548 | if (!ic->in_receive) |
573 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, | 549 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); |
574 | ic->h->tq_tail, | ||
575 | ic->tqe); | ||
576 | else | 550 | else |
577 | reconnect (ic->h); | 551 | reconnect (ic->h); |
578 | ic->callback (ic->callback_cls, | 552 | ic->callback (ic->callback_cls, |
579 | NULL, NULL, | 553 | NULL, NULL, |
580 | _("Timeout transmitting iteration request to `PEERINFO' service.\n")); | 554 | _ |
555 | ("Timeout transmitting iteration request to `PEERINFO' service.\n")); | ||
581 | ic->callback = NULL; | 556 | ic->callback = NULL; |
582 | GNUNET_free_non_null (ic->tqe); | 557 | GNUNET_free_non_null (ic->tqe); |
583 | GNUNET_free (ic); | 558 | GNUNET_free (ic); |
@@ -602,10 +577,9 @@ signal_timeout (void *cls, | |||
602 | */ | 577 | */ |
603 | struct GNUNET_PEERINFO_IteratorContext * | 578 | struct GNUNET_PEERINFO_IteratorContext * |
604 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | 579 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, |
605 | const struct GNUNET_PeerIdentity *peer, | 580 | const struct GNUNET_PeerIdentity *peer, |
606 | struct GNUNET_TIME_Relative timeout, | 581 | struct GNUNET_TIME_Relative timeout, |
607 | GNUNET_PEERINFO_Processor callback, | 582 | GNUNET_PEERINFO_Processor callback, void *callback_cls) |
608 | void *callback_cls) | ||
609 | { | 583 | { |
610 | struct GNUNET_MessageHeader *lapm; | 584 | struct GNUNET_MessageHeader *lapm; |
611 | struct ListPeerMessage *lpm; | 585 | struct ListPeerMessage *lpm; |
@@ -613,33 +587,33 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
613 | struct TransmissionQueueEntry *tqe; | 587 | struct TransmissionQueueEntry *tqe; |
614 | 588 | ||
615 | if (peer == NULL) | 589 | if (peer == NULL) |
616 | { | 590 | { |
617 | #if DEBUG_PEERINFO | 591 | #if DEBUG_PEERINFO |
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
619 | "Requesting list of peers from PEERINFO service\n"); | 593 | "Requesting list of peers from PEERINFO service\n"); |
620 | #endif | 594 | #endif |
621 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + | 595 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + |
622 | sizeof (struct GNUNET_MessageHeader)); | 596 | sizeof (struct GNUNET_MessageHeader)); |
623 | tqe->size = sizeof (struct GNUNET_MessageHeader); | 597 | tqe->size = sizeof (struct GNUNET_MessageHeader); |
624 | lapm = (struct GNUNET_MessageHeader *) &tqe[1]; | 598 | lapm = (struct GNUNET_MessageHeader *) &tqe[1]; |
625 | lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); | 599 | lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); |
626 | lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 600 | lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
627 | } | 601 | } |
628 | else | 602 | else |
629 | { | 603 | { |
630 | #if DEBUG_PEERINFO | 604 | #if DEBUG_PEERINFO |
631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
632 | "Requesting information on peer `%4s' from PEERINFO service\n", | 606 | "Requesting information on peer `%4s' from PEERINFO service\n", |
633 | GNUNET_i2s (peer)); | 607 | GNUNET_i2s (peer)); |
634 | #endif | 608 | #endif |
635 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + | 609 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + |
636 | sizeof (struct ListPeerMessage)); | 610 | sizeof (struct ListPeerMessage)); |
637 | tqe->size = sizeof (struct ListPeerMessage); | 611 | tqe->size = sizeof (struct ListPeerMessage); |
638 | lpm = (struct ListPeerMessage *) &tqe[1]; | 612 | lpm = (struct ListPeerMessage *) &tqe[1]; |
639 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); | 613 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); |
640 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 614 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
641 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 615 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
642 | } | 616 | } |
643 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); | 617 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); |
644 | ic->h = h; | 618 | ic->h = h; |
645 | ic->tqe = tqe; | 619 | ic->tqe = tqe; |
@@ -647,16 +621,12 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
647 | ic->callback_cls = callback_cls; | 621 | ic->callback_cls = callback_cls; |
648 | ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 622 | ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
649 | ic->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, | 623 | ic->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout, |
650 | &signal_timeout, | 624 | &signal_timeout, ic); |
651 | ic); | ||
652 | tqe->timeout = ic->timeout; | 625 | tqe->timeout = ic->timeout; |
653 | tqe->cont = &iterator_start_receive; | 626 | tqe->cont = &iterator_start_receive; |
654 | tqe->cont_cls = ic; | 627 | tqe->cont_cls = ic; |
655 | tqe->timeout = ic->timeout; | 628 | tqe->timeout = ic->timeout; |
656 | GNUNET_CONTAINER_DLL_insert_after (h->tq_head, | 629 | GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe); |
657 | h->tq_tail, | ||
658 | h->tq_tail, | ||
659 | tqe); | ||
660 | trigger_transmit (h); | 630 | trigger_transmit (h); |
661 | return ic; | 631 | return ic; |
662 | } | 632 | } |
@@ -671,16 +641,14 @@ void | |||
671 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) | 641 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) |
672 | { | 642 | { |
673 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 643 | if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
674 | { | 644 | { |
675 | GNUNET_SCHEDULER_cancel (ic->timeout_task); | 645 | GNUNET_SCHEDULER_cancel (ic->timeout_task); |
676 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 646 | ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
677 | } | 647 | } |
678 | ic->callback = NULL; | 648 | ic->callback = NULL; |
679 | if (GNUNET_YES == ic->in_receive) | 649 | if (GNUNET_YES == ic->in_receive) |
680 | return; /* need to finish processing */ | 650 | return; /* need to finish processing */ |
681 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, | 651 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); |
682 | ic->h->tq_tail, | ||
683 | ic->tqe); | ||
684 | GNUNET_free (ic->tqe); | 652 | GNUNET_free (ic->tqe); |
685 | GNUNET_free (ic); | 653 | GNUNET_free (ic); |
686 | } | 654 | } |