diff options
Diffstat (limited to 'src/peerinfo/gnunet-service-peerinfo.c')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 101 |
1 files changed, 41 insertions, 60 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 160993649..26fec5289 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -124,10 +124,9 @@ make_info_message (const struct HostEntry *he) | |||
124 | * @return GNUNET_NO if expiration smaller than the current time | 124 | * @return GNUNET_NO if expiration smaller than the current time |
125 | */ | 125 | */ |
126 | static int | 126 | static int |
127 | discard_expired (void *cls, | 127 | discard_expired (void *cls, const char *tname, |
128 | const char *tname, | 128 | struct GNUNET_TIME_Absolute expiration, const void *addr, |
129 | struct GNUNET_TIME_Absolute expiration, | 129 | uint16_t addrlen) |
130 | const void *addr, uint16_t addrlen) | ||
131 | { | 130 | { |
132 | const struct GNUNET_TIME_Absolute *now = cls; | 131 | const struct GNUNET_TIME_Absolute *now = cls; |
133 | 132 | ||
@@ -170,8 +169,8 @@ notify_all (struct HostEntry *entry) | |||
170 | struct InfoMessage *msg; | 169 | struct InfoMessage *msg; |
171 | 170 | ||
172 | msg = make_info_message (entry); | 171 | msg = make_info_message (entry); |
173 | GNUNET_SERVER_notification_context_broadcast (notify_list, | 172 | GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header, |
174 | &msg->header, GNUNET_NO); | 173 | GNUNET_NO); |
175 | GNUNET_free (msg); | 174 | GNUNET_free (msg); |
176 | } | 175 | } |
177 | 176 | ||
@@ -195,8 +194,8 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
195 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); | 194 | entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); |
196 | if (entry != NULL) | 195 | if (entry != NULL) |
197 | return; | 196 | return; |
198 | GNUNET_STATISTICS_update (stats, | 197 | GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, |
199 | gettext_noop ("# peers known"), 1, GNUNET_NO); | 198 | GNUNET_NO); |
200 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 199 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
201 | entry->identity = *identity; | 200 | entry->identity = *identity; |
202 | 201 | ||
@@ -216,16 +215,14 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
216 | else | 215 | else |
217 | { | 216 | { |
218 | now = GNUNET_TIME_absolute_get (); | 217 | now = GNUNET_TIME_absolute_get (); |
219 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, | 218 | hello_clean = |
220 | GNUNET_YES, | 219 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, |
221 | &discard_expired, &now); | 220 | &now); |
222 | entry->hello = hello_clean; | 221 | entry->hello = hello_clean; |
223 | } | 222 | } |
224 | } | 223 | } |
225 | GNUNET_free (fn); | 224 | GNUNET_free (fn); |
226 | GNUNET_CONTAINER_multihashmap_put (hostmap, | 225 | GNUNET_CONTAINER_multihashmap_put (hostmap, &identity->hashPubKey, entry, |
227 | &identity->hashPubKey, | ||
228 | entry, | ||
229 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 226 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
230 | notify_all (entry); | 227 | notify_all (entry); |
231 | } | 228 | } |
@@ -244,8 +241,8 @@ remove_garbage (const char *fullname) | |||
244 | ("File `%s' in directory `%s' does not match naming convention. " | 241 | ("File `%s' in directory `%s' does not match naming convention. " |
245 | "Removed.\n"), fullname, networkIdDirectory); | 242 | "Removed.\n"), fullname, networkIdDirectory); |
246 | else | 243 | else |
247 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | | 244 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
248 | GNUNET_ERROR_TYPE_BULK, "unlink", fullname); | 245 | "unlink", fullname); |
249 | } | 246 | } |
250 | 247 | ||
251 | 248 | ||
@@ -271,8 +268,8 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
271 | remove_garbage (fullname); | 268 | remove_garbage (fullname); |
272 | return GNUNET_OK; | 269 | return GNUNET_OK; |
273 | } | 270 | } |
274 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (filename, | 271 | if (GNUNET_OK != |
275 | &identity.hashPubKey)) | 272 | GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) |
276 | { | 273 | { |
277 | remove_garbage (fullname); | 274 | remove_garbage (fullname); |
278 | return GNUNET_OK; | 275 | return GNUNET_OK; |
@@ -305,11 +302,10 @@ cron_scan_directory_data_hosts (void *cls, | |||
305 | GNUNET_DISK_directory_scan (networkIdDirectory, | 302 | GNUNET_DISK_directory_scan (networkIdDirectory, |
306 | &hosts_directory_scan_callback, &count); | 303 | &hosts_directory_scan_callback, &count); |
307 | if ((0 == count) && (0 == (++retries & 31))) | 304 | if ((0 == count) && (0 == (++retries & 31))) |
308 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | | 305 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
309 | GNUNET_ERROR_TYPE_BULK, | ||
310 | _("Still no peers found in `%s'!\n"), networkIdDirectory); | 306 | _("Still no peers found in `%s'!\n"), networkIdDirectory); |
311 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, | 307 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ, &cron_scan_directory_data_hosts, |
312 | &cron_scan_directory_data_hosts, NULL); | 308 | NULL); |
313 | } | 309 | } |
314 | 310 | ||
315 | 311 | ||
@@ -352,9 +348,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
352 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) | 348 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) |
353 | { | 349 | { |
354 | if (GNUNET_SYSERR == | 350 | if (GNUNET_SYSERR == |
355 | GNUNET_DISK_fn_write (fn, | 351 | GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello), |
356 | host->hello, | ||
357 | GNUNET_HELLO_size (host->hello), | ||
358 | GNUNET_DISK_PERM_USER_READ | | 352 | GNUNET_DISK_PERM_USER_READ | |
359 | GNUNET_DISK_PERM_USER_WRITE | | 353 | GNUNET_DISK_PERM_USER_WRITE | |
360 | GNUNET_DISK_PERM_GROUP_READ | | 354 | GNUNET_DISK_PERM_GROUP_READ | |
@@ -425,14 +419,11 @@ discard_hosts_helper (void *cls, const char *fn) | |||
425 | return GNUNET_OK; | 419 | return GNUNET_OK; |
426 | } | 420 | } |
427 | hello = (const struct GNUNET_HELLO_Message *) buffer; | 421 | hello = (const struct GNUNET_HELLO_Message *) buffer; |
428 | new_hello = GNUNET_HELLO_iterate_addresses (hello, | 422 | new_hello = |
429 | GNUNET_YES, | 423 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); |
430 | &discard_expired, now); | ||
431 | if (new_hello != NULL) | 424 | if (new_hello != NULL) |
432 | { | 425 | { |
433 | GNUNET_DISK_fn_write (fn, | 426 | GNUNET_DISK_fn_write (fn, new_hello, GNUNET_HELLO_size (new_hello), |
434 | new_hello, | ||
435 | GNUNET_HELLO_size (new_hello), | ||
436 | GNUNET_DISK_PERM_USER_READ | | 427 | GNUNET_DISK_PERM_USER_READ | |
437 | GNUNET_DISK_PERM_USER_WRITE | | 428 | GNUNET_DISK_PERM_USER_WRITE | |
438 | GNUNET_DISK_PERM_GROUP_READ | | 429 | GNUNET_DISK_PERM_GROUP_READ | |
@@ -461,8 +452,8 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
461 | return; | 452 | return; |
462 | now = GNUNET_TIME_absolute_get (); | 453 | now = GNUNET_TIME_absolute_get (); |
463 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); | 454 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); |
464 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 455 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, |
465 | &cron_clean_data_hosts, NULL); | 456 | NULL); |
466 | } | 457 | } |
467 | 458 | ||
468 | 459 | ||
@@ -474,8 +465,7 @@ cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
474 | * @param message the actual message | 465 | * @param message the actual message |
475 | */ | 466 | */ |
476 | static void | 467 | static void |
477 | handle_hello (void *cls, | 468 | handle_hello (void *cls, struct GNUNET_SERVER_Client *client, |
478 | struct GNUNET_SERVER_Client *client, | ||
479 | const struct GNUNET_MessageHeader *message) | 469 | const struct GNUNET_MessageHeader *message) |
480 | { | 470 | { |
481 | const struct GNUNET_HELLO_Message *hello; | 471 | const struct GNUNET_HELLO_Message *hello; |
@@ -489,8 +479,7 @@ handle_hello (void *cls, | |||
489 | return; | 479 | return; |
490 | } | 480 | } |
491 | #if DEBUG_PEERINFO | 481 | #if DEBUG_PEERINFO |
492 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", |
493 | "`%s' message received for peer `%4s'\n", | ||
494 | "HELLO", GNUNET_i2s (&pid)); | 483 | "HELLO", GNUNET_i2s (&pid)); |
495 | #endif | 484 | #endif |
496 | bind_address (&pid, hello); | 485 | bind_address (&pid, hello); |
@@ -506,8 +495,7 @@ handle_hello (void *cls, | |||
506 | * @param message the actual message | 495 | * @param message the actual message |
507 | */ | 496 | */ |
508 | static void | 497 | static void |
509 | handle_get (void *cls, | 498 | handle_get (void *cls, struct GNUNET_SERVER_Client *client, |
510 | struct GNUNET_SERVER_Client *client, | ||
511 | const struct GNUNET_MessageHeader *message) | 499 | const struct GNUNET_MessageHeader *message) |
512 | { | 500 | { |
513 | const struct ListPeerMessage *lpm; | 501 | const struct ListPeerMessage *lpm; |
@@ -516,13 +504,11 @@ handle_get (void *cls, | |||
516 | lpm = (const struct ListPeerMessage *) message; | 504 | lpm = (const struct ListPeerMessage *) message; |
517 | GNUNET_break (0 == ntohl (lpm->reserved)); | 505 | GNUNET_break (0 == ntohl (lpm->reserved)); |
518 | #if DEBUG_PEERINFO | 506 | #if DEBUG_PEERINFO |
519 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", |
520 | "`%s' message received for peer `%4s'\n", | ||
521 | "GET", GNUNET_i2s (&lpm->peer)); | 508 | "GET", GNUNET_i2s (&lpm->peer)); |
522 | #endif | 509 | #endif |
523 | tc = GNUNET_SERVER_transmit_context_create (client); | 510 | tc = GNUNET_SERVER_transmit_context_create (client); |
524 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, | 511 | GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey, |
525 | &lpm->peer.hashPubKey, | ||
526 | &add_to_tc, tc); | 512 | &add_to_tc, tc); |
527 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 513 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
528 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 514 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
@@ -538,8 +524,7 @@ handle_get (void *cls, | |||
538 | * @param message the actual message | 524 | * @param message the actual message |
539 | */ | 525 | */ |
540 | static void | 526 | static void |
541 | handle_get_all (void *cls, | 527 | handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, |
542 | struct GNUNET_SERVER_Client *client, | ||
543 | const struct GNUNET_MessageHeader *message) | 528 | const struct GNUNET_MessageHeader *message) |
544 | { | 529 | { |
545 | struct GNUNET_SERVER_TransmitContext *tc; | 530 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -563,8 +548,8 @@ do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) | |||
563 | struct InfoMessage *msg; | 548 | struct InfoMessage *msg; |
564 | 549 | ||
565 | msg = make_info_message (he); | 550 | msg = make_info_message (he); |
566 | GNUNET_SERVER_notification_context_unicast (notify_list, | 551 | GNUNET_SERVER_notification_context_unicast (notify_list, client, &msg->header, |
567 | client, &msg->header, GNUNET_NO); | 552 | GNUNET_NO); |
568 | GNUNET_free (msg); | 553 | GNUNET_free (msg); |
569 | return GNUNET_YES; | 554 | return GNUNET_YES; |
570 | } | 555 | } |
@@ -578,8 +563,7 @@ do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) | |||
578 | * @param message the actual message | 563 | * @param message the actual message |
579 | */ | 564 | */ |
580 | static void | 565 | static void |
581 | handle_notify (void *cls, | 566 | handle_notify (void *cls, struct GNUNET_SERVER_Client *client, |
582 | struct GNUNET_SERVER_Client *client, | ||
583 | const struct GNUNET_MessageHeader *message) | 567 | const struct GNUNET_MessageHeader *message) |
584 | { | 568 | { |
585 | #if DEBUG_PEERINFO | 569 | #if DEBUG_PEERINFO |
@@ -630,8 +614,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
630 | * @param cfg configuration to use | 614 | * @param cfg configuration to use |
631 | */ | 615 | */ |
632 | static void | 616 | static void |
633 | run (void *cls, | 617 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
634 | struct GNUNET_SERVER_Handle *server, | ||
635 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 618 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
636 | { | 619 | { |
637 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 620 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
@@ -649,8 +632,7 @@ run (void *cls, | |||
649 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); | 632 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); |
650 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); | 633 | notify_list = GNUNET_SERVER_notification_context_create (server, 0); |
651 | GNUNET_assert (GNUNET_OK == | 634 | GNUNET_assert (GNUNET_OK == |
652 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 635 | GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo", |
653 | "peerinfo", | ||
654 | "HOSTS", | 636 | "HOSTS", |
655 | &networkIdDirectory)); | 637 | &networkIdDirectory)); |
656 | GNUNET_DISK_directory_create (networkIdDirectory); | 638 | GNUNET_DISK_directory_create (networkIdDirectory); |
@@ -658,8 +640,8 @@ run (void *cls, | |||
658 | &cron_scan_directory_data_hosts, NULL); | 640 | &cron_scan_directory_data_hosts, NULL); |
659 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 641 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
660 | &cron_clean_data_hosts, NULL); | 642 | &cron_clean_data_hosts, NULL); |
661 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 643 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
662 | &shutdown_task, NULL); | 644 | NULL); |
663 | GNUNET_SERVER_add_handlers (server, handlers); | 645 | GNUNET_SERVER_add_handlers (server, handlers); |
664 | } | 646 | } |
665 | 647 | ||
@@ -676,11 +658,10 @@ main (int argc, char *const *argv) | |||
676 | { | 658 | { |
677 | int ret; | 659 | int ret; |
678 | 660 | ||
679 | ret = (GNUNET_OK == | 661 | ret = |
680 | GNUNET_SERVICE_run (argc, | 662 | (GNUNET_OK == |
681 | argv, | 663 | GNUNET_SERVICE_run (argc, argv, "peerinfo", GNUNET_SERVICE_OPTION_NONE, |
682 | "peerinfo", | 664 | &run, NULL)) ? 0 : 1; |
683 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | ||
684 | GNUNET_free_non_null (networkIdDirectory); | 665 | GNUNET_free_non_null (networkIdDirectory); |
685 | return ret; | 666 | return ret; |
686 | } | 667 | } |