diff options
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 332 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 376 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 128 | ||||
-rwxr-xr-x | src/peerinfo/perf_peerinfo_api.c | 83 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 96 |
5 files changed, 464 insertions, 551 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index d5d153b65..160993649 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -130,13 +130,13 @@ discard_expired (void *cls, | |||
130 | const void *addr, uint16_t addrlen) | 130 | const void *addr, uint16_t addrlen) |
131 | { | 131 | { |
132 | const struct GNUNET_TIME_Absolute *now = cls; | 132 | const struct GNUNET_TIME_Absolute *now = cls; |
133 | |||
133 | if (now->abs_value > expiration.abs_value) | 134 | if (now->abs_value > expiration.abs_value) |
134 | { | 135 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 136 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
136 | _("Removing expired address of transport `%s'\n"), | 137 | _("Removing expired address of transport `%s'\n"), tname); |
137 | tname); | 138 | return GNUNET_NO; |
138 | return GNUNET_NO; | 139 | } |
139 | } | ||
140 | return GNUNET_OK; | 140 | return GNUNET_OK; |
141 | } | 141 | } |
142 | 142 | ||
@@ -153,8 +153,7 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
153 | char *fn; | 153 | char *fn; |
154 | 154 | ||
155 | GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); | 155 | GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); |
156 | GNUNET_asprintf (&fn, | 156 | GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); |
157 | "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); | ||
158 | return fn; | 157 | return fn; |
159 | } | 158 | } |
160 | 159 | ||
@@ -172,8 +171,7 @@ notify_all (struct HostEntry *entry) | |||
172 | 171 | ||
173 | msg = make_info_message (entry); | 172 | msg = make_info_message (entry); |
174 | GNUNET_SERVER_notification_context_broadcast (notify_list, | 173 | GNUNET_SERVER_notification_context_broadcast (notify_list, |
175 | &msg->header, | 174 | &msg->header, GNUNET_NO); |
176 | GNUNET_NO); | ||
177 | GNUNET_free (msg); | 175 | GNUNET_free (msg); |
178 | } | 176 | } |
179 | 177 | ||
@@ -194,46 +192,41 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
194 | struct GNUNET_TIME_Absolute now; | 192 | struct GNUNET_TIME_Absolute now; |
195 | char *fn; | 193 | char *fn; |
196 | 194 | ||
197 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, | 195 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); |
198 | &identity->hashPubKey); | ||
199 | if (entry != NULL) | 196 | if (entry != NULL) |
200 | return; | 197 | return; |
201 | GNUNET_STATISTICS_update (stats, | 198 | GNUNET_STATISTICS_update (stats, |
202 | gettext_noop ("# peers known"), | 199 | gettext_noop ("# peers known"), 1, GNUNET_NO); |
203 | 1, | ||
204 | GNUNET_NO); | ||
205 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 200 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
206 | entry->identity = *identity; | 201 | entry->identity = *identity; |
207 | 202 | ||
208 | fn = get_host_filename (identity); | 203 | fn = get_host_filename (identity); |
209 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) | 204 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) |
205 | { | ||
206 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | ||
207 | hello = (const struct GNUNET_HELLO_Message *) buffer; | ||
208 | if ((size < sizeof (struct GNUNET_MessageHeader)) || | ||
209 | (size != ntohs ((((const struct GNUNET_MessageHeader *) hello)->size))) | ||
210 | || (size != GNUNET_HELLO_size (hello))) | ||
210 | { | 211 | { |
211 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 212 | GNUNET_break (0); |
212 | hello = (const struct GNUNET_HELLO_Message *) buffer; | 213 | if (0 != UNLINK (fn)) |
213 | if ( (size < sizeof (struct GNUNET_MessageHeader)) || | 214 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
214 | (size != ntohs((((const struct GNUNET_MessageHeader*) hello)->size))) || | ||
215 | (size != GNUNET_HELLO_size (hello)) ) | ||
216 | { | ||
217 | GNUNET_break (0); | ||
218 | if (0 != UNLINK (fn)) | ||
219 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
220 | "unlink", | ||
221 | fn); | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | now = GNUNET_TIME_absolute_get (); | ||
226 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | ||
227 | GNUNET_YES, | ||
228 | &discard_expired, &now); | ||
229 | entry->hello = hello_clean; | ||
230 | } | ||
231 | } | 215 | } |
216 | else | ||
217 | { | ||
218 | now = GNUNET_TIME_absolute_get (); | ||
219 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | ||
220 | GNUNET_YES, | ||
221 | &discard_expired, &now); | ||
222 | entry->hello = hello_clean; | ||
223 | } | ||
224 | } | ||
232 | GNUNET_free (fn); | 225 | GNUNET_free (fn); |
233 | GNUNET_CONTAINER_multihashmap_put (hostmap, | 226 | GNUNET_CONTAINER_multihashmap_put (hostmap, |
234 | &identity->hashPubKey, | 227 | &identity->hashPubKey, |
235 | entry, | 228 | entry, |
236 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 229 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
237 | notify_all (entry); | 230 | notify_all (entry); |
238 | } | 231 | } |
239 | 232 | ||
@@ -257,8 +250,7 @@ remove_garbage (const char *fullname) | |||
257 | 250 | ||
258 | 251 | ||
259 | static int | 252 | static int |
260 | hosts_directory_scan_callback (void *cls, | 253 | hosts_directory_scan_callback (void *cls, const char *fullname) |
261 | const char *fullname) | ||
262 | { | 254 | { |
263 | unsigned int *matched = cls; | 255 | unsigned int *matched = cls; |
264 | struct GNUNET_PeerIdentity identity; | 256 | struct GNUNET_PeerIdentity identity; |
@@ -267,24 +259,24 @@ hosts_directory_scan_callback (void *cls, | |||
267 | if (GNUNET_DISK_file_test (fullname) != GNUNET_YES) | 259 | if (GNUNET_DISK_file_test (fullname) != GNUNET_YES) |
268 | return GNUNET_OK; /* ignore non-files */ | 260 | return GNUNET_OK; /* ignore non-files */ |
269 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) | 261 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) |
270 | { | 262 | { |
271 | remove_garbage (fullname); | 263 | remove_garbage (fullname); |
272 | return GNUNET_OK; | 264 | return GNUNET_OK; |
273 | } | 265 | } |
274 | filename = | 266 | filename = |
275 | &fullname[strlen (fullname) - | 267 | &fullname[strlen (fullname) - |
276 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; | 268 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; |
277 | if (filename[-1] != DIR_SEPARATOR) | 269 | if (filename[-1] != DIR_SEPARATOR) |
278 | { | 270 | { |
279 | remove_garbage (fullname); | 271 | remove_garbage (fullname); |
280 | return GNUNET_OK; | 272 | return GNUNET_OK; |
281 | } | 273 | } |
282 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, | 274 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, |
283 | &identity.hashPubKey)) | 275 | &identity.hashPubKey)) |
284 | { | 276 | { |
285 | remove_garbage (fullname); | 277 | remove_garbage (fullname); |
286 | return GNUNET_OK; | 278 | return GNUNET_OK; |
287 | } | 279 | } |
288 | (*matched)++; | 280 | (*matched)++; |
289 | add_host_to_known_hosts (&identity); | 281 | add_host_to_known_hosts (&identity); |
290 | return GNUNET_OK; | 282 | return GNUNET_OK; |
@@ -305,11 +297,11 @@ cron_scan_directory_data_hosts (void *cls, | |||
305 | return; | 297 | return; |
306 | count = 0; | 298 | count = 0; |
307 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) | 299 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) |
308 | { | 300 | { |
309 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, | 301 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, |
310 | &cron_scan_directory_data_hosts, NULL); | 302 | &cron_scan_directory_data_hosts, NULL); |
311 | return; | 303 | return; |
312 | } | 304 | } |
313 | GNUNET_DISK_directory_scan (networkIdDirectory, | 305 | GNUNET_DISK_directory_scan (networkIdDirectory, |
314 | &hosts_directory_scan_callback, &count); | 306 | &hosts_directory_scan_callback, &count); |
315 | if ((0 == count) && (0 == (++retries & 31))) | 307 | if ((0 == count) && (0 == (++retries & 31))) |
@@ -337,42 +329,39 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
337 | struct GNUNET_TIME_Absolute delta; | 329 | struct GNUNET_TIME_Absolute delta; |
338 | 330 | ||
339 | add_host_to_known_hosts (peer); | 331 | add_host_to_known_hosts (peer); |
340 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, | 332 | host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); |
341 | &peer->hashPubKey); | ||
342 | GNUNET_assert (host != NULL); | 333 | GNUNET_assert (host != NULL); |
343 | if (host->hello == NULL) | 334 | if (host->hello == NULL) |
344 | { | 335 | { |
345 | host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); | 336 | host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
346 | memcpy (host->hello, hello, GNUNET_HELLO_size (hello)); | 337 | memcpy (host->hello, hello, GNUNET_HELLO_size (hello)); |
347 | } | 338 | } |
348 | else | 339 | else |
340 | { | ||
341 | mrg = GNUNET_HELLO_merge (host->hello, hello); | ||
342 | delta = GNUNET_HELLO_equals (mrg, host->hello, GNUNET_TIME_absolute_get ()); | ||
343 | if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
349 | { | 344 | { |
350 | mrg = GNUNET_HELLO_merge (host->hello, hello); | 345 | GNUNET_free (mrg); |
351 | delta = GNUNET_HELLO_equals (mrg, | 346 | return; |
352 | host->hello, | ||
353 | GNUNET_TIME_absolute_get ()); | ||
354 | if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) | ||
355 | { | ||
356 | GNUNET_free (mrg); | ||
357 | return; | ||
358 | } | ||
359 | GNUNET_free (host->hello); | ||
360 | host->hello = mrg; | ||
361 | } | 347 | } |
348 | GNUNET_free (host->hello); | ||
349 | host->hello = mrg; | ||
350 | } | ||
362 | fn = get_host_filename (peer); | 351 | fn = get_host_filename (peer); |
363 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) | 352 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) |
364 | { | 353 | { |
365 | if (GNUNET_SYSERR == | 354 | if (GNUNET_SYSERR == |
366 | GNUNET_DISK_fn_write (fn, | 355 | GNUNET_DISK_fn_write (fn, |
367 | host->hello, | 356 | host->hello, |
368 | GNUNET_HELLO_size (host->hello), | 357 | GNUNET_HELLO_size (host->hello), |
369 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | 358 | GNUNET_DISK_PERM_USER_READ | |
370 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ)) | 359 | GNUNET_DISK_PERM_USER_WRITE | |
371 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 360 | GNUNET_DISK_PERM_GROUP_READ | |
372 | "write", | 361 | GNUNET_DISK_PERM_OTHER_READ)) |
373 | fn); | 362 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
374 | 363 | ||
375 | } | 364 | } |
376 | GNUNET_free (fn); | 365 | GNUNET_free (fn); |
377 | notify_all (host); | 366 | notify_all (host); |
378 | } | 367 | } |
@@ -388,9 +377,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
388 | * @return GNUNET_YES (continue to iterate) | 377 | * @return GNUNET_YES (continue to iterate) |
389 | */ | 378 | */ |
390 | static int | 379 | static int |
391 | add_to_tc (void *cls, | 380 | add_to_tc (void *cls, const GNUNET_HashCode * key, void *value) |
392 | const GNUNET_HashCode *key, | ||
393 | void *value) | ||
394 | { | 381 | { |
395 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 382 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
396 | struct HostEntry *pos = value; | 383 | struct HostEntry *pos = value; |
@@ -401,19 +388,18 @@ add_to_tc (void *cls, | |||
401 | hs = 0; | 388 | hs = 0; |
402 | im = (struct InfoMessage *) buf; | 389 | im = (struct InfoMessage *) buf; |
403 | if (pos->hello != NULL) | 390 | if (pos->hello != NULL) |
404 | { | 391 | { |
405 | hs = GNUNET_HELLO_size (pos->hello); | 392 | hs = GNUNET_HELLO_size (pos->hello); |
406 | GNUNET_assert (hs < | 393 | GNUNET_assert (hs < |
407 | GNUNET_SERVER_MAX_MESSAGE_SIZE - | 394 | GNUNET_SERVER_MAX_MESSAGE_SIZE - |
408 | sizeof (struct InfoMessage)); | 395 | sizeof (struct InfoMessage)); |
409 | memcpy (&im[1], pos->hello, hs); | 396 | memcpy (&im[1], pos->hello, hs); |
410 | } | 397 | } |
411 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 398 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
412 | im->header.size = htons (sizeof (struct InfoMessage) + hs); | 399 | im->header.size = htons (sizeof (struct InfoMessage) + hs); |
413 | im->reserved = htonl (0); | 400 | im->reserved = htonl (0); |
414 | im->peer = pos->identity; | 401 | im->peer = pos->identity; |
415 | GNUNET_SERVER_transmit_context_append_message (tc, | 402 | GNUNET_SERVER_transmit_context_append_message (tc, &im->header); |
416 | &im->header); | ||
417 | return GNUNET_YES; | 403 | return GNUNET_YES; |
418 | } | 404 | } |
419 | 405 | ||
@@ -432,31 +418,33 @@ discard_hosts_helper (void *cls, const char *fn) | |||
432 | 418 | ||
433 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); | 419 | size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); |
434 | if (size < sizeof (struct GNUNET_MessageHeader)) | 420 | if (size < sizeof (struct GNUNET_MessageHeader)) |
435 | { | 421 | { |
436 | if (0 != UNLINK (fn)) | 422 | if (0 != UNLINK (fn)) |
437 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 423 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
438 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 424 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); |
439 | return GNUNET_OK; | 425 | return GNUNET_OK; |
440 | } | 426 | } |
441 | hello = (const struct GNUNET_HELLO_Message *) buffer; | 427 | hello = (const struct GNUNET_HELLO_Message *) buffer; |
442 | new_hello = GNUNET_HELLO_iterate_addresses (hello, | 428 | new_hello = GNUNET_HELLO_iterate_addresses (hello, |
443 | GNUNET_YES, | 429 | GNUNET_YES, |
444 | &discard_expired, now); | 430 | &discard_expired, now); |
445 | if (new_hello != NULL) | 431 | if (new_hello != NULL) |
446 | { | 432 | { |
447 | GNUNET_DISK_fn_write (fn, | 433 | GNUNET_DISK_fn_write (fn, |
448 | new_hello, | 434 | new_hello, |
449 | GNUNET_HELLO_size (new_hello), | 435 | GNUNET_HELLO_size (new_hello), |
450 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | 436 | GNUNET_DISK_PERM_USER_READ | |
451 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ); | 437 | GNUNET_DISK_PERM_USER_WRITE | |
452 | GNUNET_free (new_hello); | 438 | GNUNET_DISK_PERM_GROUP_READ | |
453 | } | 439 | GNUNET_DISK_PERM_OTHER_READ); |
440 | GNUNET_free (new_hello); | ||
441 | } | ||
454 | else | 442 | else |
455 | { | 443 | { |
456 | if (0 != UNLINK (fn)) | 444 | if (0 != UNLINK (fn)) |
457 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | 445 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | |
458 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | 446 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); |
459 | } | 447 | } |
460 | return GNUNET_OK; | 448 | return GNUNET_OK; |
461 | } | 449 | } |
462 | 450 | ||
@@ -465,16 +453,14 @@ discard_hosts_helper (void *cls, const char *fn) | |||
465 | * Call this method periodically to scan data/hosts for new hosts. | 453 | * Call this method periodically to scan data/hosts for new hosts. |
466 | */ | 454 | */ |
467 | static void | 455 | static void |
468 | cron_clean_data_hosts (void *cls, | 456 | cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
469 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
470 | { | 457 | { |
471 | struct GNUNET_TIME_Absolute now; | 458 | struct GNUNET_TIME_Absolute now; |
472 | 459 | ||
473 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 460 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
474 | return; | 461 | return; |
475 | now = GNUNET_TIME_absolute_get (); | 462 | now = GNUNET_TIME_absolute_get (); |
476 | GNUNET_DISK_directory_scan (networkIdDirectory, | 463 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); |
477 | &discard_hosts_helper, &now); | ||
478 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 464 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, |
479 | &cron_clean_data_hosts, NULL); | 465 | &cron_clean_data_hosts, NULL); |
480 | } | 466 | } |
@@ -489,24 +475,23 @@ cron_clean_data_hosts (void *cls, | |||
489 | */ | 475 | */ |
490 | static void | 476 | static void |
491 | handle_hello (void *cls, | 477 | handle_hello (void *cls, |
492 | struct GNUNET_SERVER_Client *client, | 478 | struct GNUNET_SERVER_Client *client, |
493 | const struct GNUNET_MessageHeader *message) | 479 | const struct GNUNET_MessageHeader *message) |
494 | { | 480 | { |
495 | const struct GNUNET_HELLO_Message *hello; | 481 | const struct GNUNET_HELLO_Message *hello; |
496 | struct GNUNET_PeerIdentity pid; | 482 | struct GNUNET_PeerIdentity pid; |
497 | 483 | ||
498 | hello = (const struct GNUNET_HELLO_Message *) message; | 484 | hello = (const struct GNUNET_HELLO_Message *) message; |
499 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) | 485 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
500 | { | 486 | { |
501 | GNUNET_break (0); | 487 | GNUNET_break (0); |
502 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 488 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
503 | return; | 489 | return; |
504 | } | 490 | } |
505 | #if DEBUG_PEERINFO | 491 | #if DEBUG_PEERINFO |
506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
507 | "`%s' message received for peer `%4s'\n", | 493 | "`%s' message received for peer `%4s'\n", |
508 | "HELLO", | 494 | "HELLO", GNUNET_i2s (&pid)); |
509 | GNUNET_i2s (&pid)); | ||
510 | #endif | 495 | #endif |
511 | bind_address (&pid, hello); | 496 | bind_address (&pid, hello); |
512 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 497 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -532,17 +517,15 @@ handle_get (void *cls, | |||
532 | GNUNET_break (0 == ntohl (lpm->reserved)); | 517 | GNUNET_break (0 == ntohl (lpm->reserved)); |
533 | #if DEBUG_PEERINFO | 518 | #if DEBUG_PEERINFO |
534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
535 | "`%s' message received for peer `%4s'\n", | 520 | "`%s' message received for peer `%4s'\n", |
536 | "GET", | 521 | "GET", GNUNET_i2s (&lpm->peer)); |
537 | GNUNET_i2s (&lpm->peer)); | ||
538 | #endif | 522 | #endif |
539 | tc = GNUNET_SERVER_transmit_context_create (client); | 523 | tc = GNUNET_SERVER_transmit_context_create (client); |
540 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, | 524 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, |
541 | &lpm->peer.hashPubKey, | 525 | &lpm->peer.hashPubKey, |
542 | &add_to_tc, | 526 | &add_to_tc, tc); |
543 | tc); | ||
544 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 527 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
545 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 528 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
546 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 529 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
547 | } | 530 | } |
548 | 531 | ||
@@ -562,24 +545,18 @@ handle_get_all (void *cls, | |||
562 | struct GNUNET_SERVER_TransmitContext *tc; | 545 | struct GNUNET_SERVER_TransmitContext *tc; |
563 | 546 | ||
564 | #if DEBUG_PEERINFO | 547 | #if DEBUG_PEERINFO |
565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); |
566 | "`%s' message received\n", | ||
567 | "GET_ALL"); | ||
568 | #endif | 549 | #endif |
569 | tc = GNUNET_SERVER_transmit_context_create (client); | 550 | tc = GNUNET_SERVER_transmit_context_create (client); |
570 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | 551 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); |
571 | &add_to_tc, | ||
572 | tc); | ||
573 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 552 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
574 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 553 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
575 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 554 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
576 | } | 555 | } |
577 | 556 | ||
578 | 557 | ||
579 | static int | 558 | static int |
580 | do_notify_entry (void *cls, | 559 | do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) |
581 | const GNUNET_HashCode *key, | ||
582 | void *value) | ||
583 | { | 560 | { |
584 | struct GNUNET_SERVER_Client *client = cls; | 561 | struct GNUNET_SERVER_Client *client = cls; |
585 | struct HostEntry *he = value; | 562 | struct HostEntry *he = value; |
@@ -587,9 +564,7 @@ do_notify_entry (void *cls, | |||
587 | 564 | ||
588 | msg = make_info_message (he); | 565 | msg = make_info_message (he); |
589 | GNUNET_SERVER_notification_context_unicast (notify_list, | 566 | GNUNET_SERVER_notification_context_unicast (notify_list, |
590 | client, | 567 | client, &msg->header, GNUNET_NO); |
591 | &msg->header, | ||
592 | GNUNET_NO); | ||
593 | GNUNET_free (msg); | 568 | GNUNET_free (msg); |
594 | return GNUNET_YES; | 569 | return GNUNET_YES; |
595 | } | 570 | } |
@@ -604,27 +579,20 @@ do_notify_entry (void *cls, | |||
604 | */ | 579 | */ |
605 | static void | 580 | static void |
606 | handle_notify (void *cls, | 581 | handle_notify (void *cls, |
607 | struct GNUNET_SERVER_Client *client, | 582 | struct GNUNET_SERVER_Client *client, |
608 | const struct GNUNET_MessageHeader *message) | 583 | const struct GNUNET_MessageHeader *message) |
609 | { | 584 | { |
610 | #if DEBUG_PEERINFO | 585 | #if DEBUG_PEERINFO |
611 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); |
612 | "`%s' message received\n", | ||
613 | "NOTIFY"); | ||
614 | #endif | 587 | #endif |
615 | GNUNET_SERVER_notification_context_add (notify_list, | 588 | GNUNET_SERVER_notification_context_add (notify_list, client); |
616 | client); | 589 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); |
617 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | ||
618 | &do_notify_entry, | ||
619 | client); | ||
620 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 590 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
621 | } | 591 | } |
622 | 592 | ||
623 | 593 | ||
624 | static int | 594 | static int |
625 | free_host_entry (void *cls, | 595 | free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) |
626 | const GNUNET_HashCode *key, | ||
627 | void *value) | ||
628 | { | 596 | { |
629 | struct HostEntry *he = value; | 597 | struct HostEntry *he = value; |
630 | 598 | ||
@@ -640,20 +608,17 @@ free_host_entry (void *cls, | |||
640 | * @param tc scheduler task context, unused | 608 | * @param tc scheduler task context, unused |
641 | */ | 609 | */ |
642 | static void | 610 | static void |
643 | shutdown_task (void *cls, | 611 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
644 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
645 | { | 612 | { |
646 | GNUNET_SERVER_notification_context_destroy (notify_list); | 613 | GNUNET_SERVER_notification_context_destroy (notify_list); |
647 | notify_list = NULL; | 614 | notify_list = NULL; |
648 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, | 615 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL); |
649 | &free_host_entry, | ||
650 | NULL); | ||
651 | GNUNET_CONTAINER_multihashmap_destroy (hostmap); | 616 | GNUNET_CONTAINER_multihashmap_destroy (hostmap); |
652 | if (stats != NULL) | 617 | if (stats != NULL) |
653 | { | 618 | { |
654 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 619 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
655 | stats = NULL; | 620 | stats = NULL; |
656 | } | 621 | } |
657 | } | 622 | } |
658 | 623 | ||
659 | 624 | ||
@@ -690,11 +655,11 @@ run (void *cls, | |||
690 | &networkIdDirectory)); | 655 | &networkIdDirectory)); |
691 | GNUNET_DISK_directory_create (networkIdDirectory); | 656 | GNUNET_DISK_directory_create (networkIdDirectory); |
692 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 657 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
693 | &cron_scan_directory_data_hosts, NULL); | 658 | &cron_scan_directory_data_hosts, NULL); |
694 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 659 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
695 | &cron_clean_data_hosts, NULL); | 660 | &cron_clean_data_hosts, NULL); |
696 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 661 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
697 | &shutdown_task, NULL); | 662 | &shutdown_task, NULL); |
698 | GNUNET_SERVER_add_handlers (server, handlers); | 663 | GNUNET_SERVER_add_handlers (server, handlers); |
699 | } | 664 | } |
700 | 665 | ||
@@ -712,11 +677,10 @@ main (int argc, char *const *argv) | |||
712 | int ret; | 677 | int ret; |
713 | 678 | ||
714 | ret = (GNUNET_OK == | 679 | ret = (GNUNET_OK == |
715 | GNUNET_SERVICE_run (argc, | 680 | GNUNET_SERVICE_run (argc, |
716 | argv, | 681 | argv, |
717 | "peerinfo", | 682 | "peerinfo", |
718 | GNUNET_SERVICE_OPTION_NONE, | 683 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
719 | &run, NULL)) ? 0 : 1; | ||
720 | GNUNET_free_non_null (networkIdDirectory); | 684 | GNUNET_free_non_null (networkIdDirectory); |
721 | return ret; | 685 | return ret; |
722 | } | 686 | } |
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 | } |
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index eb6e29ce5..0c7474f4a 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -76,8 +76,7 @@ struct GNUNET_PEERINFO_NotifyContext | |||
76 | * | 76 | * |
77 | * @param nc our context | 77 | * @param nc our context |
78 | */ | 78 | */ |
79 | static void | 79 | static void request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); |
80 | request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); | ||
81 | 80 | ||
82 | 81 | ||
83 | /** | 82 | /** |
@@ -86,8 +85,7 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); | |||
86 | * | 85 | * |
87 | * @param nc our context | 86 | * @param nc our context |
88 | */ | 87 | */ |
89 | static void | 88 | static void receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); |
90 | receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); | ||
91 | 89 | ||
92 | 90 | ||
93 | /** | 91 | /** |
@@ -95,23 +93,21 @@ receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); | |||
95 | * | 93 | * |
96 | * @param cls the 'struct GNUNET_PEERINFO_NotifyContext' | 94 | * @param cls the 'struct GNUNET_PEERINFO_NotifyContext' |
97 | * @param tc scheduler context | 95 | * @param tc scheduler context |
98 | */ | 96 | */ |
99 | static void | 97 | static void |
100 | reconnect (void *cls, | 98 | reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
101 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
102 | { | 99 | { |
103 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 100 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
104 | 101 | ||
105 | nc->task = GNUNET_SCHEDULER_NO_TASK; | 102 | nc->task = GNUNET_SCHEDULER_NO_TASK; |
106 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | 103 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); |
107 | if (NULL == nc->client) | 104 | if (NULL == nc->client) |
108 | { | 105 | { |
109 | /* ugh */ | 106 | /* ugh */ |
110 | nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 107 | nc->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
111 | &reconnect, | 108 | &reconnect, nc); |
112 | nc); | 109 | return; |
113 | return; | 110 | } |
114 | } | ||
115 | request_notifications (nc); | 111 | request_notifications (nc); |
116 | } | 112 | } |
117 | 113 | ||
@@ -124,9 +120,7 @@ reconnect (void *cls, | |||
124 | * @param msg message received, NULL on timeout or fatal error | 120 | * @param msg message received, NULL on timeout or fatal error |
125 | */ | 121 | */ |
126 | static void | 122 | static void |
127 | process_notification (void *cls, | 123 | process_notification (void *cls, const struct GNUNET_MessageHeader *msg) |
128 | const struct | ||
129 | GNUNET_MessageHeader * msg) | ||
130 | { | 124 | { |
131 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 125 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
132 | const struct InfoMessage *im; | 126 | const struct InfoMessage *im; |
@@ -134,14 +128,27 @@ process_notification (void *cls, | |||
134 | uint16_t ms; | 128 | uint16_t ms; |
135 | 129 | ||
136 | if (msg == NULL) | 130 | if (msg == NULL) |
137 | { | 131 | { |
138 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 132 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); |
139 | reconnect (nc, NULL); | 133 | reconnect (nc, NULL); |
140 | return; | 134 | return; |
141 | } | 135 | } |
142 | ms = ntohs (msg->size); | 136 | ms = ntohs (msg->size); |
143 | if ((ms < sizeof (struct InfoMessage)) || | 137 | if ((ms < sizeof (struct InfoMessage)) || |
144 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) | 138 | (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) |
139 | { | ||
140 | GNUNET_break (0); | ||
141 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | ||
142 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | ||
143 | request_notifications (nc); | ||
144 | return; | ||
145 | } | ||
146 | im = (const struct InfoMessage *) msg; | ||
147 | hello = NULL; | ||
148 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
149 | { | ||
150 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
151 | if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) | ||
145 | { | 152 | { |
146 | GNUNET_break (0); | 153 | GNUNET_break (0); |
147 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 154 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); |
@@ -149,24 +156,11 @@ process_notification (void *cls, | |||
149 | request_notifications (nc); | 156 | request_notifications (nc); |
150 | return; | 157 | return; |
151 | } | 158 | } |
152 | im = (const struct InfoMessage *) msg; | 159 | } |
153 | hello = NULL; | ||
154 | if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) | ||
155 | { | ||
156 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
157 | if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) | ||
158 | { | ||
159 | GNUNET_break (0); | ||
160 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | ||
161 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | ||
162 | request_notifications (nc); | ||
163 | return; | ||
164 | } | ||
165 | } | ||
166 | #if DEBUG_PEERINFO | 160 | #if DEBUG_PEERINFO |
167 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
168 | "Received information about peer `%s' from peerinfo database\n", | 162 | "Received information about peer `%s' from peerinfo database\n", |
169 | GNUNET_i2s (&im->peer)); | 163 | GNUNET_i2s (&im->peer)); |
170 | #endif | 164 | #endif |
171 | nc->callback (nc->callback_cls, &im->peer, hello, NULL); | 165 | nc->callback (nc->callback_cls, &im->peer, hello, NULL); |
172 | receive_notifications (nc); | 166 | receive_notifications (nc); |
@@ -183,9 +177,8 @@ static void | |||
183 | receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | 177 | receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) |
184 | { | 178 | { |
185 | GNUNET_CLIENT_receive (nc->client, | 179 | GNUNET_CLIENT_receive (nc->client, |
186 | &process_notification, | 180 | &process_notification, |
187 | nc, | 181 | nc, GNUNET_TIME_UNIT_FOREVER_REL); |
188 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
189 | } | 182 | } |
190 | 183 | ||
191 | 184 | ||
@@ -197,22 +190,20 @@ receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
197 | * @param buf where the callee should write the message | 190 | * @param buf where the callee should write the message |
198 | * @return number of bytes written to buf | 191 | * @return number of bytes written to buf |
199 | */ | 192 | */ |
200 | static size_t | 193 | static size_t |
201 | transmit_notify_request (void *cls, | 194 | transmit_notify_request (void *cls, size_t size, void *buf) |
202 | size_t size, | ||
203 | void *buf) | ||
204 | { | 195 | { |
205 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 196 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
206 | struct GNUNET_MessageHeader hdr; | 197 | struct GNUNET_MessageHeader hdr; |
207 | 198 | ||
208 | nc->init = NULL; | 199 | nc->init = NULL; |
209 | if (buf == NULL) | 200 | if (buf == NULL) |
210 | { | 201 | { |
211 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 202 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); |
212 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); | 203 | nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); |
213 | request_notifications (nc); | 204 | request_notifications (nc); |
214 | return 0; | 205 | return 0; |
215 | } | 206 | } |
216 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 207 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
217 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); | 208 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); |
218 | hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); | 209 | hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); |
@@ -232,12 +223,12 @@ static void | |||
232 | request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | 223 | request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) |
233 | { | 224 | { |
234 | GNUNET_assert (NULL == nc->init); | 225 | GNUNET_assert (NULL == nc->init); |
235 | nc->init =GNUNET_CLIENT_notify_transmit_ready (nc->client, | 226 | nc->init = GNUNET_CLIENT_notify_transmit_ready (nc->client, |
236 | sizeof (struct GNUNET_MessageHeader), | 227 | sizeof (struct |
237 | GNUNET_TIME_UNIT_FOREVER_REL, | 228 | GNUNET_MessageHeader), |
238 | GNUNET_YES, | 229 | GNUNET_TIME_UNIT_FOREVER_REL, |
239 | &transmit_notify_request, | 230 | GNUNET_YES, |
240 | nc); | 231 | &transmit_notify_request, nc); |
241 | } | 232 | } |
242 | 233 | ||
243 | 234 | ||
@@ -253,24 +244,23 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
253 | */ | 244 | */ |
254 | struct GNUNET_PEERINFO_NotifyContext * | 245 | struct GNUNET_PEERINFO_NotifyContext * |
255 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, | 246 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, |
256 | GNUNET_PEERINFO_Processor callback, | 247 | GNUNET_PEERINFO_Processor callback, void *callback_cls) |
257 | void *callback_cls) | ||
258 | { | 248 | { |
259 | struct GNUNET_PEERINFO_NotifyContext *nc; | 249 | struct GNUNET_PEERINFO_NotifyContext *nc; |
260 | struct GNUNET_CLIENT_Connection *client; | 250 | struct GNUNET_CLIENT_Connection *client; |
261 | 251 | ||
262 | client = GNUNET_CLIENT_connect ("peerinfo", cfg); | 252 | client = GNUNET_CLIENT_connect ("peerinfo", cfg); |
263 | if (client == NULL) | 253 | if (client == NULL) |
264 | { | 254 | { |
265 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
266 | _("Could not connect to `%s' service.\n"), "peerinfo"); | 256 | _("Could not connect to `%s' service.\n"), "peerinfo"); |
267 | return NULL; | 257 | return NULL; |
268 | } | 258 | } |
269 | nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext)); | 259 | nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext)); |
270 | nc->cfg = cfg; | 260 | nc->cfg = cfg; |
271 | nc->client = client; | 261 | nc->client = client; |
272 | nc->callback = callback; | 262 | nc->callback = callback; |
273 | nc->callback_cls = callback_cls; | 263 | nc->callback_cls = callback_cls; |
274 | request_notifications (nc); | 264 | request_notifications (nc); |
275 | return nc; | 265 | return nc; |
276 | } | 266 | } |
@@ -285,10 +275,10 @@ void | |||
285 | GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) | 275 | GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) |
286 | { | 276 | { |
287 | if (NULL != nc->init) | 277 | if (NULL != nc->init) |
288 | { | 278 | { |
289 | GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init); | 279 | GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init); |
290 | nc->init = NULL; | 280 | nc->init = NULL; |
291 | } | 281 | } |
292 | if (NULL != nc->client) | 282 | if (NULL != nc->client) |
293 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); | 283 | GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); |
294 | if (GNUNET_SCHEDULER_NO_TASK != nc->task) | 284 | if (GNUNET_SCHEDULER_NO_TASK != nc->task) |
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c index 4f490671e..d0eadaf94 100755 --- a/src/peerinfo/perf_peerinfo_api.c +++ b/src/peerinfo/perf_peerinfo_api.c | |||
@@ -54,12 +54,9 @@ check_it (void *cls, | |||
54 | { | 54 | { |
55 | #if DEBUG | 55 | #if DEBUG |
56 | if (addrlen > 0) | 56 | if (addrlen > 0) |
57 | { | 57 | { |
58 | fprintf (stderr, | 58 | fprintf (stderr, "name: %s, addr: %s\n", tname, (const char *) addr); |
59 | "name: %s, addr: %s\n", | 59 | } |
60 | tname, | ||
61 | (const char*) addr); | ||
62 | } | ||
63 | #endif | 60 | #endif |
64 | return GNUNET_OK; | 61 | return GNUNET_OK; |
65 | } | 62 | } |
@@ -75,13 +72,12 @@ address_generator (void *cls, size_t max, void *buf) | |||
75 | if (*agc == 0) | 72 | if (*agc == 0) |
76 | return 0; | 73 | return 0; |
77 | 74 | ||
78 | GNUNET_asprintf(&address, "Address%d", *agc); | 75 | GNUNET_asprintf (&address, "Address%d", *agc); |
79 | 76 | ||
80 | ret = GNUNET_HELLO_add_address ("peerinfotest", | 77 | ret = GNUNET_HELLO_add_address ("peerinfotest", |
81 | GNUNET_TIME_relative_to_absolute | 78 | GNUNET_TIME_relative_to_absolute |
82 | (GNUNET_TIME_UNIT_HOURS), | 79 | (GNUNET_TIME_UNIT_HOURS), |
83 | address, strlen(address) + 1, | 80 | address, strlen (address) + 1, buf, max); |
84 | buf, max); | ||
85 | GNUNET_free (address); | 81 | GNUNET_free (address); |
86 | *agc = 0; | 82 | *agc = 0; |
87 | return ret; | 83 | return ret; |
@@ -106,53 +102,53 @@ add_peer (size_t i) | |||
106 | static void | 102 | static void |
107 | process (void *cls, | 103 | process (void *cls, |
108 | const struct GNUNET_PeerIdentity *peer, | 104 | const struct GNUNET_PeerIdentity *peer, |
109 | const struct GNUNET_HELLO_Message *hello, | 105 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
110 | const char * err_msg) | ||
111 | { | 106 | { |
112 | if (peer == NULL) | 107 | if (peer == NULL) |
113 | { | 108 | { |
114 | #if DEBUG | 109 | #if DEBUG |
115 | fprintf(stderr, "Process received NULL response\n"); | 110 | fprintf (stderr, "Process received NULL response\n"); |
116 | #endif | 111 | #endif |
117 | } | 112 | } |
118 | else | 113 | else |
119 | { | 114 | { |
120 | #if DEBUG | 115 | #if DEBUG |
121 | fprintf(stderr, "Processed a peer\n"); | 116 | fprintf (stderr, "Processed a peer\n"); |
122 | #endif | 117 | #endif |
123 | numpeers++; | 118 | numpeers++; |
124 | if (0 && (hello != NULL)) | 119 | if (0 && (hello != NULL)) |
125 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL); | 120 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL); |
126 | 121 | ||
127 | } | 122 | } |
128 | } | 123 | } |
129 | 124 | ||
130 | 125 | ||
131 | static void | 126 | static void |
132 | run (void *cls, | 127 | run (void *cls, |
133 | char *const *args, | 128 | char *const *args, |
134 | const char *cfgfile, | 129 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
135 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
136 | { | 130 | { |
137 | size_t i; | 131 | size_t i; |
132 | |||
138 | cfg = c; | 133 | cfg = c; |
139 | h = GNUNET_PEERINFO_connect (cfg); | 134 | h = GNUNET_PEERINFO_connect (cfg); |
140 | GNUNET_assert (h != NULL); | 135 | GNUNET_assert (h != NULL); |
141 | for (i = 0; i < NUM_REQUESTS; i++) | 136 | for (i = 0; i < NUM_REQUESTS; i++) |
142 | { | 137 | { |
143 | add_peer (i); | 138 | add_peer (i); |
144 | ic[i] = GNUNET_PEERINFO_iterate (h, | 139 | ic[i] = GNUNET_PEERINFO_iterate (h, |
145 | NULL, | 140 | NULL, |
146 | GNUNET_TIME_relative_multiply | 141 | GNUNET_TIME_relative_multiply |
147 | (GNUNET_TIME_UNIT_SECONDS, 30), | 142 | (GNUNET_TIME_UNIT_SECONDS, 30), |
148 | &process, cls); | 143 | &process, cls); |
149 | } | 144 | } |
150 | } | 145 | } |
151 | 146 | ||
152 | static int | 147 | static int |
153 | check () | 148 | check () |
154 | { | 149 | { |
155 | int ok = 0; | 150 | int ok = 0; |
151 | |||
156 | char *const argv[] = { "perf-peerinfo-api", | 152 | char *const argv[] = { "perf-peerinfo-api", |
157 | "-c", | 153 | "-c", |
158 | "test_peerinfo_api_data.conf", | 154 | "test_peerinfo_api_data.conf", |
@@ -165,33 +161,32 @@ check () | |||
165 | }; | 161 | }; |
166 | #if START_SERVICE | 162 | #if START_SERVICE |
167 | struct GNUNET_OS_Process *proc; | 163 | struct GNUNET_OS_Process *proc; |
164 | |||
168 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 165 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
169 | GNUNET_GETOPT_OPTION_END | 166 | GNUNET_GETOPT_OPTION_END |
170 | }; | 167 | }; |
171 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", | 168 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", |
172 | "gnunet-service-peerinfo", | 169 | "gnunet-service-peerinfo", |
173 | #if DEBUG_PEERINFO | 170 | #if DEBUG_PEERINFO |
174 | "-L", "DEBUG", | 171 | "-L", "DEBUG", |
175 | #else | 172 | #else |
176 | "-L", "ERROR", | 173 | "-L", "ERROR", |
177 | #endif | 174 | #endif |
178 | "-c", "test_peerinfo_api_data.conf", NULL); | 175 | "-c", "test_peerinfo_api_data.conf", NULL); |
179 | #endif | 176 | #endif |
180 | GNUNET_assert (NULL != proc); | 177 | GNUNET_assert (NULL != proc); |
181 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 178 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
182 | argv, "perf-peerinfo-api", "nohelp", | 179 | argv, "perf-peerinfo-api", "nohelp", options, &run, &ok); |
183 | options, &run, &ok); | ||
184 | fprintf (stderr, | 180 | fprintf (stderr, |
185 | "Received %u/%u calls before timeout\n", | 181 | "Received %u/%u calls before timeout\n", |
186 | numpeers, | 182 | numpeers, NUM_REQUESTS * NUM_REQUESTS / 2); |
187 | NUM_REQUESTS * NUM_REQUESTS / 2); | ||
188 | GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s"); | 183 | GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s"); |
189 | #if START_SERVICE | 184 | #if START_SERVICE |
190 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 185 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
191 | { | 186 | { |
192 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 187 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
193 | ok = 1; | 188 | ok = 1; |
194 | } | 189 | } |
195 | GNUNET_OS_process_wait (proc); | 190 | GNUNET_OS_process_wait (proc); |
196 | GNUNET_OS_process_close (proc); | 191 | GNUNET_OS_process_close (proc); |
197 | proc = NULL; | 192 | proc = NULL; |
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 460a3764d..e740f1fc9 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -53,11 +53,11 @@ check_it (void *cls, | |||
53 | unsigned int *agc = cls; | 53 | unsigned int *agc = cls; |
54 | 54 | ||
55 | if (addrlen > 0) | 55 | if (addrlen > 0) |
56 | { | 56 | { |
57 | GNUNET_assert (0 == strcmp ("peerinfotest", tname)); | 57 | GNUNET_assert (0 == strcmp ("peerinfotest", tname)); |
58 | GNUNET_assert (0 == strncmp ("Address", addr, addrlen)); | 58 | GNUNET_assert (0 == strncmp ("Address", addr, addrlen)); |
59 | (*agc) -= (1 << (addrlen - 1)); | 59 | (*agc) -= (1 << (addrlen - 1)); |
60 | } | 60 | } |
61 | return GNUNET_OK; | 61 | return GNUNET_OK; |
62 | } | 62 | } |
63 | 63 | ||
@@ -100,67 +100,63 @@ add_peer () | |||
100 | static void | 100 | static void |
101 | process (void *cls, | 101 | process (void *cls, |
102 | const struct GNUNET_PeerIdentity *peer, | 102 | const struct GNUNET_PeerIdentity *peer, |
103 | const struct GNUNET_HELLO_Message *hello, | 103 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
104 | const char * err_msg) | ||
105 | { | 104 | { |
106 | int *ok = cls; | 105 | int *ok = cls; |
107 | unsigned int agc; | 106 | unsigned int agc; |
108 | 107 | ||
109 | if (err_msg != NULL) | 108 | if (err_msg != NULL) |
110 | { | 109 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
112 | _("Error in communication with PEERINFO service\n")); | 111 | _("Error in communication with PEERINFO service\n")); |
113 | } | 112 | } |
114 | 113 | ||
115 | if (peer == NULL) | 114 | if (peer == NULL) |
115 | { | ||
116 | ic = NULL; | ||
117 | if ((3 == *ok) && (retries < 50)) | ||
116 | { | 118 | { |
117 | ic = NULL; | 119 | /* try again */ |
118 | if ( (3 == *ok) && | 120 | retries++; |
119 | (retries < 50) ) | 121 | add_peer (); |
120 | { | 122 | ic = GNUNET_PEERINFO_iterate (h, |
121 | /* try again */ | 123 | NULL, |
122 | retries++; | 124 | GNUNET_TIME_relative_multiply |
123 | add_peer (); | 125 | (GNUNET_TIME_UNIT_SECONDS, 15), |
124 | ic = GNUNET_PEERINFO_iterate (h, | 126 | &process, cls); |
125 | NULL, | ||
126 | GNUNET_TIME_relative_multiply | ||
127 | (GNUNET_TIME_UNIT_SECONDS, 15), | ||
128 | &process, cls); | ||
129 | return; | ||
130 | } | ||
131 | GNUNET_assert (peer == NULL); | ||
132 | GNUNET_assert (2 == *ok); | ||
133 | GNUNET_PEERINFO_disconnect (h); | ||
134 | h = NULL; | ||
135 | *ok = 0; | ||
136 | return; | 127 | return; |
137 | } | 128 | } |
129 | GNUNET_assert (peer == NULL); | ||
130 | GNUNET_assert (2 == *ok); | ||
131 | GNUNET_PEERINFO_disconnect (h); | ||
132 | h = NULL; | ||
133 | *ok = 0; | ||
134 | return; | ||
135 | } | ||
138 | if (hello != NULL) | 136 | if (hello != NULL) |
139 | { | 137 | { |
140 | GNUNET_assert (3 == *ok); | 138 | GNUNET_assert (3 == *ok); |
141 | agc = 3; | 139 | agc = 3; |
142 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); | 140 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); |
143 | GNUNET_assert (agc == 0); | 141 | GNUNET_assert (agc == 0); |
144 | *ok = 2; | 142 | *ok = 2; |
145 | } | 143 | } |
146 | } | 144 | } |
147 | 145 | ||
148 | 146 | ||
149 | static void | 147 | static void |
150 | run (void *cls, | 148 | run (void *cls, |
151 | char *const *args, | 149 | char *const *args, |
152 | const char *cfgfile, | 150 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
153 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
154 | { | 151 | { |
155 | cfg = c; | 152 | cfg = c; |
156 | h = GNUNET_PEERINFO_connect (cfg); | 153 | h = GNUNET_PEERINFO_connect (cfg); |
157 | GNUNET_assert (h != NULL); | 154 | GNUNET_assert (h != NULL); |
158 | add_peer (); | 155 | add_peer (); |
159 | ic = GNUNET_PEERINFO_iterate (h, | 156 | ic = GNUNET_PEERINFO_iterate (h, |
160 | NULL, | 157 | NULL, |
161 | GNUNET_TIME_relative_multiply | 158 | GNUNET_TIME_relative_multiply |
162 | (GNUNET_TIME_UNIT_SECONDS, 15), | 159 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); |
163 | &process, cls); | ||
164 | } | 160 | } |
165 | 161 | ||
166 | 162 | ||
@@ -169,6 +165,7 @@ check () | |||
169 | { | 165 | { |
170 | int ok = 3; | 166 | int ok = 3; |
171 | struct GNUNET_OS_Process *proc; | 167 | struct GNUNET_OS_Process *proc; |
168 | |||
172 | char *const argv[] = { "test-peerinfo-api", | 169 | char *const argv[] = { "test-peerinfo-api", |
173 | "-c", | 170 | "-c", |
174 | "test_peerinfo_api_data.conf", | 171 | "test_peerinfo_api_data.conf", |
@@ -181,20 +178,19 @@ check () | |||
181 | GNUNET_GETOPT_OPTION_END | 178 | GNUNET_GETOPT_OPTION_END |
182 | }; | 179 | }; |
183 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", | 180 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", |
184 | "gnunet-service-peerinfo", | 181 | "gnunet-service-peerinfo", |
185 | #if DEBUG_PEERINFO | 182 | #if DEBUG_PEERINFO |
186 | "-L", "DEBUG", | 183 | "-L", "DEBUG", |
187 | #endif | 184 | #endif |
188 | "-c", "test_peerinfo_api_data.conf", NULL); | 185 | "-c", "test_peerinfo_api_data.conf", NULL); |
189 | GNUNET_assert (NULL != proc); | 186 | GNUNET_assert (NULL != proc); |
190 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 187 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
191 | argv, "test-peerinfo-api", "nohelp", | 188 | argv, "test-peerinfo-api", "nohelp", options, &run, &ok); |
192 | options, &run, &ok); | ||
193 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 189 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
194 | { | 190 | { |
195 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 191 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
196 | ok = 1; | 192 | ok = 1; |
197 | } | 193 | } |
198 | GNUNET_OS_process_wait (proc); | 194 | GNUNET_OS_process_wait (proc); |
199 | GNUNET_OS_process_close (proc); | 195 | GNUNET_OS_process_close (proc); |
200 | proc = NULL; | 196 | proc = NULL; |