diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-13 13:57:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-13 13:57:50 +0000 |
commit | c8e04709c3941b832261c4eff9dbee058a46c841 (patch) | |
tree | c48e1ee07de182bf72ec756b116876722a3a56b2 /src | |
parent | 7eb62f023c9d6b808e3d9d4cd296d9901a2b32d8 (diff) | |
download | gnunet-c8e04709c3941b832261c4eff9dbee058a46c841.tar.gz gnunet-c8e04709c3941b832261c4eff9dbee058a46c841.zip |
-adding capability to install static list of HELLOs with the original software to avoid need for hostlist server accessibility
Diffstat (limited to 'src')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 72 |
1 files changed, 60 insertions, 12 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index d6e52d4b4..90ab6d5bf 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -32,12 +32,9 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include "platform.h" | 34 | #include "platform.h" |
35 | #include "gnunet_crypto_lib.h" | 35 | #include "gnunet_util_lib.h" |
36 | #include "gnunet_container_lib.h" | ||
37 | #include "gnunet_disk_lib.h" | ||
38 | #include "gnunet_hello_lib.h" | 36 | #include "gnunet_hello_lib.h" |
39 | #include "gnunet_protocols.h" | 37 | #include "gnunet_protocols.h" |
40 | #include "gnunet_service_lib.h" | ||
41 | #include "gnunet_statistics_service.h" | 38 | #include "gnunet_statistics_service.h" |
42 | #include "peerinfo.h" | 39 | #include "peerinfo.h" |
43 | 40 | ||
@@ -51,6 +48,7 @@ | |||
51 | */ | 48 | */ |
52 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) | 49 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) |
53 | 50 | ||
51 | |||
54 | /** | 52 | /** |
55 | * In-memory cache of known hosts. | 53 | * In-memory cache of known hosts. |
56 | */ | 54 | */ |
@@ -95,6 +93,9 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
95 | /** | 93 | /** |
96 | * Notify all clients in the notify list about the | 94 | * Notify all clients in the notify list about the |
97 | * given host entry changing. | 95 | * given host entry changing. |
96 | * | ||
97 | * @param he entry of the host for which we generate a notification | ||
98 | * @return generated notification message | ||
98 | */ | 99 | */ |
99 | static struct InfoMessage * | 100 | static struct InfoMessage * |
100 | make_info_message (const struct HostEntry *he) | 101 | make_info_message (const struct HostEntry *he) |
@@ -141,6 +142,8 @@ discard_expired (void *cls, const struct GNUNET_HELLO_Address *address, | |||
141 | /** | 142 | /** |
142 | * Get the filename under which we would store the GNUNET_HELLO_Message | 143 | * Get the filename under which we would store the GNUNET_HELLO_Message |
143 | * for the given host and protocol. | 144 | * for the given host and protocol. |
145 | * | ||
146 | * @param id peer for which we need the filename for the HELLO | ||
144 | * @return filename of the form DIRECTORY/HOSTID | 147 | * @return filename of the form DIRECTORY/HOSTID |
145 | */ | 148 | */ |
146 | static char * | 149 | static char * |
@@ -229,6 +232,8 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
229 | /** | 232 | /** |
230 | * Remove a file that should not be there. LOG | 233 | * Remove a file that should not be there. LOG |
231 | * success or failure. | 234 | * success or failure. |
235 | * | ||
236 | * @param fullname name of the file to remove | ||
232 | */ | 237 | */ |
233 | static void | 238 | static void |
234 | remove_garbage (const char *fullname) | 239 | remove_garbage (const char *fullname) |
@@ -244,6 +249,15 @@ remove_garbage (const char *fullname) | |||
244 | } | 249 | } |
245 | 250 | ||
246 | 251 | ||
252 | /** | ||
253 | * Function that is called on each HELLO file in a particular directory. | ||
254 | * Try to parse the file and add the HELLO to our list. | ||
255 | * | ||
256 | * @param cls pointer to 'unsigned int' to increment for each file, or NULL | ||
257 | * if the file is from a read-only, read-once resource directory | ||
258 | * @param fullname name of the file to parse | ||
259 | * @return GNUNET_OK (continue iteration) | ||
260 | */ | ||
247 | static int | 261 | static int |
248 | hosts_directory_scan_callback (void *cls, const char *fullname) | 262 | hosts_directory_scan_callback (void *cls, const char *fullname) |
249 | { | 263 | { |
@@ -255,7 +269,8 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
255 | return GNUNET_OK; /* ignore non-files */ | 269 | return GNUNET_OK; /* ignore non-files */ |
256 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) | 270 | if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) |
257 | { | 271 | { |
258 | remove_garbage (fullname); | 272 | if (NULL != matched) |
273 | remove_garbage (fullname); | ||
259 | return GNUNET_OK; | 274 | return GNUNET_OK; |
260 | } | 275 | } |
261 | filename = | 276 | filename = |
@@ -263,16 +278,19 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
263 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; | 278 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; |
264 | if (filename[-1] != DIR_SEPARATOR) | 279 | if (filename[-1] != DIR_SEPARATOR) |
265 | { | 280 | { |
266 | remove_garbage (fullname); | 281 | if (NULL != matched) |
282 | remove_garbage (fullname); | ||
267 | return GNUNET_OK; | 283 | return GNUNET_OK; |
268 | } | 284 | } |
269 | if (GNUNET_OK != | 285 | if (GNUNET_OK != |
270 | GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) | 286 | GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) |
271 | { | 287 | { |
272 | remove_garbage (fullname); | 288 | if (NULL != matched) |
289 | remove_garbage (fullname); | ||
273 | return GNUNET_OK; | 290 | return GNUNET_OK; |
274 | } | 291 | } |
275 | (*matched)++; | 292 | if (NULL != matched) |
293 | (*matched)++; | ||
276 | add_host_to_known_hosts (&identity); | 294 | add_host_to_known_hosts (&identity); |
277 | return GNUNET_OK; | 295 | return GNUNET_OK; |
278 | } | 296 | } |
@@ -280,6 +298,9 @@ hosts_directory_scan_callback (void *cls, const char *fullname) | |||
280 | 298 | ||
281 | /** | 299 | /** |
282 | * Call this method periodically to scan data/hosts for new hosts. | 300 | * Call this method periodically to scan data/hosts for new hosts. |
301 | * | ||
302 | * @param cls unused | ||
303 | * @param tc scheduler context, aborted if reason is shutdown | ||
283 | */ | 304 | */ |
284 | static void | 305 | static void |
285 | cron_scan_directory_data_hosts (void *cls, | 306 | cron_scan_directory_data_hosts (void *cls, |
@@ -362,7 +383,6 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
362 | } | 383 | } |
363 | 384 | ||
364 | 385 | ||
365 | |||
366 | /** | 386 | /** |
367 | * Do transmit info about peer to given host. | 387 | * Do transmit info about peer to given host. |
368 | * | 388 | * |
@@ -401,6 +421,10 @@ add_to_tc (void *cls, const GNUNET_HashCode * key, void *value) | |||
401 | 421 | ||
402 | /** | 422 | /** |
403 | * @brief delete expired HELLO entries in data/hosts/ | 423 | * @brief delete expired HELLO entries in data/hosts/ |
424 | * | ||
425 | * @param cls pointer to current time (struct GNUNET_TIME_Absolute) | ||
426 | * @param fn filename to test to see if the HELLO expired | ||
427 | * @return GNUNET_OK (continue iteration) | ||
404 | */ | 428 | */ |
405 | static int | 429 | static int |
406 | discard_hosts_helper (void *cls, const char *fn) | 430 | discard_hosts_helper (void *cls, const char *fn) |
@@ -442,7 +466,11 @@ discard_hosts_helper (void *cls, const char *fn) | |||
442 | 466 | ||
443 | 467 | ||
444 | /** | 468 | /** |
445 | * Call this method periodically to scan data/hosts for new hosts. | 469 | * Call this method periodically to scan data/hosts for ancient |
470 | * HELLOs to expire. | ||
471 | * | ||
472 | * @param cls unused | ||
473 | * @param tc scheduler context, aborted if reason is shutdown | ||
446 | */ | 474 | */ |
447 | static void | 475 | static void |
448 | cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 476 | cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -541,6 +569,9 @@ handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, | |||
541 | } | 569 | } |
542 | 570 | ||
543 | 571 | ||
572 | /** | ||
573 | * FIXME. | ||
574 | */ | ||
544 | static int | 575 | static int |
545 | do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) | 576 | do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) |
546 | { | 577 | { |
@@ -576,6 +607,9 @@ handle_notify (void *cls, struct GNUNET_SERVER_Client *client, | |||
576 | } | 607 | } |
577 | 608 | ||
578 | 609 | ||
610 | /** | ||
611 | * FIXME. | ||
612 | */ | ||
579 | static int | 613 | static int |
580 | free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) | 614 | free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) |
581 | { | 615 | { |
@@ -586,6 +620,7 @@ free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) | |||
586 | return GNUNET_YES; | 620 | return GNUNET_YES; |
587 | } | 621 | } |
588 | 622 | ||
623 | |||
589 | /** | 624 | /** |
590 | * Clean up our state. Called during shutdown. | 625 | * Clean up our state. Called during shutdown. |
591 | * | 626 | * |
@@ -608,7 +643,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
608 | 643 | ||
609 | 644 | ||
610 | /** | 645 | /** |
611 | * Process statistics requests. | 646 | * Start up peerinfo service. |
612 | * | 647 | * |
613 | * @param cls closure | 648 | * @param cls closure |
614 | * @param server the initialized server | 649 | * @param server the initialized server |
@@ -628,6 +663,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
628 | sizeof (struct GNUNET_MessageHeader)}, | 663 | sizeof (struct GNUNET_MessageHeader)}, |
629 | {NULL, NULL, 0, 0} | 664 | {NULL, NULL, 0, 0} |
630 | }; | 665 | }; |
666 | char *peerdir; | ||
667 | char *ip; | ||
631 | 668 | ||
632 | hostmap = GNUNET_CONTAINER_multihashmap_create (1024); | 669 | hostmap = GNUNET_CONTAINER_multihashmap_create (1024); |
633 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); | 670 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); |
@@ -644,11 +681,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
644 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 681 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
645 | NULL); | 682 | NULL); |
646 | GNUNET_SERVER_add_handlers (server, handlers); | 683 | GNUNET_SERVER_add_handlers (server, handlers); |
684 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | ||
685 | GNUNET_asprintf (&peerdir, | ||
686 | "%shellos", | ||
687 | ip); | ||
688 | GNUNET_free (ip); | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
690 | _("Importing HELLOs from `%s'\n"), | ||
691 | peerdir); | ||
692 | GNUNET_DISK_directory_scan (peerdir, | ||
693 | &hosts_directory_scan_callback, NULL); | ||
694 | GNUNET_free (peerdir); | ||
647 | } | 695 | } |
648 | 696 | ||
649 | 697 | ||
650 | /** | 698 | /** |
651 | * The main function for the statistics service. | 699 | * The main function for the peerinfo service. |
652 | * | 700 | * |
653 | * @param argc number of arguments from the command line | 701 | * @param argc number of arguments from the command line |
654 | * @param argv command line arguments | 702 | * @param argv command line arguments |