2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file peerinfo/gnunet-service-peerinfo.c
23 * @brief maintains list of known peers
25 * Code to maintain the list of currently known hosts (in memory
26 * structure of data/hosts/).
28 * @author Christian Grothoff
31 * - notify clients when addresses in HELLO expire (#1933)
35 #include "gnunet_util_lib.h"
36 #include "gnunet_hello_lib.h"
37 #include "gnunet_protocols.h"
38 #include "gnunet_statistics_service.h"
42 * How often do we scan the HOST_DIR for new entries?
44 #define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
47 * How often do we discard old entries in data/hosts/?
49 #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60)
53 * In-memory cache of known hosts.
59 * Identity of the peer.
61 struct GNUNET_PeerIdentity identity;
64 * Hello for the peer (can be NULL)
66 struct GNUNET_HELLO_Message *hello;
72 * The in-memory list of known hosts, mapping of
73 * host IDs to 'struct HostEntry*' values.
75 static struct GNUNET_CONTAINER_MultiHashMap *hostmap;
78 * Clients to immediately notify about all changes.
80 static struct GNUNET_SERVER_NotificationContext *notify_list;
83 * Directory where the hellos are stored in (data/hosts)
85 static char *networkIdDirectory;
88 * Handle for reporting statistics.
90 static struct GNUNET_STATISTICS_Handle *stats;
94 * Notify all clients in the notify list about the
95 * given host entry changing.
97 * @param he entry of the host for which we generate a notification
98 * @return generated notification message
100 static struct InfoMessage *
101 make_info_message (const struct HostEntry *he)
103 struct InfoMessage *im;
106 hs = (NULL == he->hello) ? 0 : GNUNET_HELLO_size (he->hello);
107 im = GNUNET_malloc (sizeof (struct InfoMessage) + hs);
108 im->header.size = htons (hs + sizeof (struct InfoMessage));
109 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
110 im->peer = he->identity;
111 if (he->hello != NULL)
112 memcpy (&im[1], he->hello, hs);
118 * Address iterator that causes expired entries to be discarded.
120 * @param cls pointer to the current time
121 * @param address the address
122 * @param expiration expiration time for the address
123 * @return GNUNET_NO if expiration smaller than the current time
126 discard_expired (void *cls, const struct GNUNET_HELLO_Address *address,
127 struct GNUNET_TIME_Absolute expiration)
129 const struct GNUNET_TIME_Absolute *now = cls;
131 if (now->abs_value > expiration.abs_value)
133 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
134 _("Removing expired address of transport `%s'\n"),
135 address->transport_name);
143 * Address iterator that counts the remaining addresses.
145 * @param cls pointer to the counter
146 * @param address the address
147 * @param expiration expiration time for the address
148 * @return GNUNET_OK (always)
151 count_addresses (void *cls, const struct GNUNET_HELLO_Address *address,
152 struct GNUNET_TIME_Absolute expiration)
154 unsigned int *cnt = cls;
162 * Get the filename under which we would store the GNUNET_HELLO_Message
163 * for the given host and protocol.
165 * @param id peer for which we need the filename for the HELLO
166 * @return filename of the form DIRECTORY/HOSTID
169 get_host_filename (const struct GNUNET_PeerIdentity *id)
171 struct GNUNET_CRYPTO_HashAsciiEncoded fil;
174 if (NULL == networkIdDirectory)
176 GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil);
177 GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil);
183 * Broadcast information about the given entry to all
186 * @param entry entry to broadcast about
189 notify_all (struct HostEntry *entry)
191 struct InfoMessage *msg;
193 msg = make_info_message (entry);
194 GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header,
201 * Try to read the HELLO in the given filename and discard expired
202 * addresses. Removes the file if the HELLO is mal-formed. If all
203 * addresses are expired, the HELLO is also removed (but the HELLO
204 * with the public key is still returned if it was found and valid).
206 * @param fn name of the file
207 * @param unlink_garbage if GNUNET_YES, try to remove useless files
208 * @return HELLO of the file, NULL on error
210 static struct GNUNET_HELLO_Message *
211 read_host_file (const char *fn,
214 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
215 const struct GNUNET_HELLO_Message *hello;
216 struct GNUNET_HELLO_Message *hello_clean;
218 struct GNUNET_TIME_Absolute now;
221 if (GNUNET_YES != GNUNET_DISK_file_test (fn))
223 size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
224 hello = (const struct GNUNET_HELLO_Message *) buffer;
225 if ((size < sizeof (struct GNUNET_MessageHeader)) ||
226 (size != ntohs ((((const struct GNUNET_MessageHeader *) hello)->size)))
227 || (size != GNUNET_HELLO_size (hello)))
229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
230 _("Failed to parse HELLO in file `%s'\n"),
232 if ( (GNUNET_YES == unlink_garbage) &&
234 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
237 now = GNUNET_TIME_absolute_get ();
239 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired,
242 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses,
246 /* no addresses left, remove from disk */
247 if ( (GNUNET_YES == unlink_garbage) &&
249 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
256 * Add a host to the list.
258 * @param identity the identity of the host
261 add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
263 struct HostEntry *entry;
266 entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey);
269 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1,
271 entry = GNUNET_malloc (sizeof (struct HostEntry));
272 entry->identity = *identity;
273 GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry,
274 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
275 fn = get_host_filename (identity);
278 entry->hello = read_host_file (fn, GNUNET_YES);
286 * Remove a file that should not be there. LOG
287 * success or failure.
289 * @param fullname name of the file to remove
292 remove_garbage (const char *fullname)
294 if (0 == UNLINK (fullname))
295 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
297 ("File `%s' in directory `%s' does not match naming convention. "
298 "Removed.\n"), fullname, networkIdDirectory);
300 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
306 * Closure for 'hosts_directory_scan_callback'.
308 struct DirScanContext
311 * GNUNET_YES if we should remove files that are broken,
312 * GNUNET_NO if the directory we are iterating over should
313 * be treated as read-only by us.
318 * Counter for the number of (valid) entries found, incremented
319 * by one for each match.
321 unsigned int matched;
326 * Function that is called on each HELLO file in a particular directory.
327 * Try to parse the file and add the HELLO to our list.
329 * @param cls pointer to 'unsigned int' to increment for each file, or NULL
330 * if the file is from a read-only, read-once resource directory
331 * @param fullname name of the file to parse
332 * @return GNUNET_OK (continue iteration)
335 hosts_directory_scan_callback (void *cls, const char *fullname)
337 struct DirScanContext *dsc = cls;
338 struct GNUNET_PeerIdentity identity;
339 const char *filename;
340 struct HostEntry *entry;
341 struct GNUNET_HELLO_Message *hello;
342 struct GNUNET_PeerIdentity id;
344 if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
345 return GNUNET_OK; /* ignore non-files */
346 if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
348 if (GNUNET_YES == dsc->remove_files)
349 remove_garbage (fullname);
353 &fullname[strlen (fullname) -
354 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1];
355 if (DIR_SEPARATOR != filename[-1])
357 if (GNUNET_YES == dsc->remove_files)
358 remove_garbage (fullname);
362 GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey))
364 /* odd filename, but might still be valid, try getting identity from HELLO */
365 if ( (NULL != (hello = read_host_file (filename,
366 dsc->remove_files))) &&
368 GNUNET_HELLO_get_id (hello,
371 /* ok, found something valid, remember HELLO */
372 entry = GNUNET_malloc (sizeof (struct HostEntry));
373 entry->identity = id;
374 GNUNET_CONTAINER_multihashmap_put (hostmap, &entry->identity.hashPubKey, entry,
375 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
376 entry->hello = hello;
381 if (GNUNET_YES == dsc->remove_files)
382 remove_garbage (fullname);
386 add_host_to_known_hosts (&identity);
392 * Call this method periodically to scan data/hosts for new hosts.
395 * @param tc scheduler context, aborted if reason is shutdown
398 cron_scan_directory_data_hosts (void *cls,
399 const struct GNUNET_SCHEDULER_TaskContext *tc)
401 static unsigned int retries;
402 struct DirScanContext dsc;
404 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
406 if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory))
408 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
409 GNUNET_SCHEDULER_PRIORITY_IDLE,
410 &cron_scan_directory_data_hosts, NULL);
414 dsc.remove_files = GNUNET_YES;
415 GNUNET_DISK_directory_scan (networkIdDirectory,
416 &hosts_directory_scan_callback, &dsc);
417 if ((0 == dsc.matched) && (0 == (++retries & 31)))
418 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
419 _("Still no peers found in `%s'!\n"), networkIdDirectory);
420 GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ,
421 GNUNET_SCHEDULER_PRIORITY_IDLE,
422 &cron_scan_directory_data_hosts,
428 * Bind a host address (hello) to a hostId.
430 * @param peer the peer for which this is a hello
431 * @param hello the verified (!) hello message
434 bind_address (const struct GNUNET_PeerIdentity *peer,
435 const struct GNUNET_HELLO_Message *hello)
438 struct HostEntry *host;
439 struct GNUNET_HELLO_Message *mrg;
440 struct GNUNET_TIME_Absolute delta;
443 add_host_to_known_hosts (peer);
444 host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey);
445 GNUNET_assert (NULL != host);
446 if (NULL == host->hello)
448 host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello));
449 memcpy (host->hello, hello, GNUNET_HELLO_size (hello));
453 mrg = GNUNET_HELLO_merge (host->hello, hello);
454 delta = GNUNET_HELLO_equals (mrg, host->hello, GNUNET_TIME_absolute_get ());
455 if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
457 /* no differences, just ignore the update */
461 GNUNET_free (host->hello);
464 fn = get_host_filename (peer);
466 (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) )
469 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses,
473 /* no valid addresses, don't put HELLO on disk; in fact,
474 if one exists on disk, remove it */
480 GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello),
481 GNUNET_DISK_PERM_USER_READ |
482 GNUNET_DISK_PERM_USER_WRITE |
483 GNUNET_DISK_PERM_GROUP_READ |
484 GNUNET_DISK_PERM_OTHER_READ))
485 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn);
488 GNUNET_free_non_null (fn);
494 * Do transmit info about peer to given host.
496 * @param cls NULL to hit all hosts, otherwise specifies a particular target
498 * @param value information to transmit
499 * @return GNUNET_YES (continue to iterate)
502 add_to_tc (void *cls, const struct GNUNET_HashCode * key, void *value)
504 struct GNUNET_SERVER_TransmitContext *tc = cls;
505 struct HostEntry *pos = value;
506 struct InfoMessage *im;
508 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
511 im = (struct InfoMessage *) buf;
512 if (pos->hello != NULL)
514 hs = GNUNET_HELLO_size (pos->hello);
516 GNUNET_SERVER_MAX_MESSAGE_SIZE -
517 sizeof (struct InfoMessage));
518 memcpy (&im[1], pos->hello, hs);
520 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
521 im->header.size = htons (sizeof (struct InfoMessage) + hs);
522 im->reserved = htonl (0);
523 im->peer = pos->identity;
524 GNUNET_SERVER_transmit_context_append_message (tc, &im->header);
530 * @brief delete expired HELLO entries in data/hosts/
532 * @param cls pointer to current time (struct GNUNET_TIME_Absolute)
533 * @param fn filename to test to see if the HELLO expired
534 * @return GNUNET_OK (continue iteration)
537 discard_hosts_helper (void *cls, const char *fn)
539 struct GNUNET_TIME_Absolute *now = cls;
540 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
541 const struct GNUNET_HELLO_Message *hello;
542 struct GNUNET_HELLO_Message *new_hello;
546 size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer));
547 if (size < sizeof (struct GNUNET_MessageHeader))
549 if (0 != UNLINK (fn))
550 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
551 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
554 hello = (const struct GNUNET_HELLO_Message *) buffer;
556 GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now);
558 if (NULL != new_hello)
559 (void) GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_addresses, &cnt);
560 if ( (NULL != new_hello) && (0 < cnt) )
562 GNUNET_DISK_fn_write (fn, new_hello, GNUNET_HELLO_size (new_hello),
563 GNUNET_DISK_PERM_USER_READ |
564 GNUNET_DISK_PERM_USER_WRITE |
565 GNUNET_DISK_PERM_GROUP_READ |
566 GNUNET_DISK_PERM_OTHER_READ);
570 if (0 != UNLINK (fn))
571 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
572 GNUNET_ERROR_TYPE_BULK, "unlink", fn);
574 GNUNET_free_non_null (new_hello);
580 * Call this method periodically to scan data/hosts for ancient
584 * @param tc scheduler context, aborted if reason is shutdown
587 cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
589 struct GNUNET_TIME_Absolute now;
591 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
593 now = GNUNET_TIME_absolute_get ();
594 GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now);
595 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts,
601 * Handle HELLO-message.
604 * @param client identification of the client
605 * @param message the actual message
608 handle_hello (void *cls, struct GNUNET_SERVER_Client *client,
609 const struct GNUNET_MessageHeader *message)
611 const struct GNUNET_HELLO_Message *hello;
612 struct GNUNET_PeerIdentity pid;
614 hello = (const struct GNUNET_HELLO_Message *) message;
615 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
618 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
622 "HELLO", GNUNET_i2s (&pid));
623 bind_address (&pid, hello);
624 GNUNET_SERVER_receive_done (client, GNUNET_OK);
629 * Handle GET-message.
632 * @param client identification of the client
633 * @param message the actual message
636 handle_get (void *cls, struct GNUNET_SERVER_Client *client,
637 const struct GNUNET_MessageHeader *message)
639 const struct ListPeerMessage *lpm;
640 struct GNUNET_SERVER_TransmitContext *tc;
642 lpm = (const struct ListPeerMessage *) message;
643 GNUNET_break (0 == ntohl (lpm->reserved));
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n",
645 "GET", GNUNET_i2s (&lpm->peer));
646 tc = GNUNET_SERVER_transmit_context_create (client);
647 GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey,
649 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
650 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
651 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
656 * Handle GET-ALL-message.
659 * @param client identification of the client
660 * @param message the actual message
663 handle_get_all (void *cls, struct GNUNET_SERVER_Client *client,
664 const struct GNUNET_MessageHeader *message)
666 struct GNUNET_SERVER_TransmitContext *tc;
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL");
669 tc = GNUNET_SERVER_transmit_context_create (client);
670 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc);
671 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
672 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
673 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
678 * Pass the given client the information we have in the respective
679 * host entry; the client is already in the notification context.
681 * @param cls the 'struct GNUNET_SERVER_Client' to notify
682 * @param key key for the value (unused)
683 * @param value the 'struct HostEntry' to notify the client about
684 * @return GNUNET_YES (always, continue to iterate)
687 do_notify_entry (void *cls, const struct GNUNET_HashCode * key, void *value)
689 struct GNUNET_SERVER_Client *client = cls;
690 struct HostEntry *he = value;
691 struct InfoMessage *msg;
693 msg = make_info_message (he);
694 GNUNET_SERVER_notification_context_unicast (notify_list, client, &msg->header,
702 * Handle NOTIFY-message.
705 * @param client identification of the client
706 * @param message the actual message
709 handle_notify (void *cls, struct GNUNET_SERVER_Client *client,
710 const struct GNUNET_MessageHeader *message)
712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY");
713 GNUNET_SERVER_client_mark_monitor (client);
714 GNUNET_SERVER_notification_context_add (notify_list, client);
715 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client);
716 GNUNET_SERVER_receive_done (client, GNUNET_OK);
721 * Release memory taken by a host entry.
724 * @param key key of the host entry
725 * @param value the 'struct HostEntry' to free
726 * @return GNUNET_YES (continue to iterate)
729 free_host_entry (void *cls, const struct GNUNET_HashCode * key, void *value)
731 struct HostEntry *he = value;
733 GNUNET_free_non_null (he->hello);
740 * Clean up our state. Called during shutdown.
743 * @param tc scheduler task context, unused
746 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
748 GNUNET_SERVER_notification_context_destroy (notify_list);
750 GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL);
751 GNUNET_CONTAINER_multihashmap_destroy (hostmap);
754 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
761 * Start up peerinfo service.
764 * @param server the initialized server
765 * @param cfg configuration to use
768 run (void *cls, struct GNUNET_SERVER_Handle *server,
769 const struct GNUNET_CONFIGURATION_Handle *cfg)
771 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
772 {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0},
773 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
774 sizeof (struct ListPeerMessage)},
775 {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
776 sizeof (struct GNUNET_MessageHeader)},
777 {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
778 sizeof (struct GNUNET_MessageHeader)},
783 struct DirScanContext dsc;
786 hostmap = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
787 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
788 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
789 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO");
790 if (GNUNET_YES != noio)
792 GNUNET_assert (GNUNET_OK ==
793 GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo",
795 &networkIdDirectory));
796 GNUNET_DISK_directory_create (networkIdDirectory);
797 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
798 &cron_scan_directory_data_hosts, NULL);
799 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
800 &cron_clean_data_hosts, NULL);
801 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
802 GNUNET_asprintf (&peerdir,
806 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
807 _("Importing HELLOs from `%s'\n"),
810 dsc.remove_files = GNUNET_NO;
811 GNUNET_DISK_directory_scan (peerdir,
812 &hosts_directory_scan_callback, &dsc);
813 GNUNET_free (peerdir);
815 GNUNET_SERVER_add_handlers (server, handlers);
816 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
823 * The main function for the peerinfo service.
825 * @param argc number of arguments from the command line
826 * @param argv command line arguments
827 * @return 0 ok, 1 on error
830 main (int argc, char *const *argv)
836 GNUNET_SERVICE_run (argc, argv, "peerinfo", GNUNET_SERVICE_OPTION_NONE,
837 &run, NULL)) ? 0 : 1;
838 GNUNET_free_non_null (networkIdDirectory);
843 /* end of gnunet-service-peerinfo.c */