aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-24 20:29:31 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-24 20:29:31 +0000
commit474599b488b51b998464321ff25219d366b31e94 (patch)
treee67a59eed6930a98cba04c7087638f823997f2f5 /src/peerinfo
parent3bca0a62abc14e5fe36e1c80ff487e0051dad562 (diff)
downloadgnunet-474599b488b51b998464321ff25219d366b31e94.tar.gz
gnunet-474599b488b51b998464321ff25219d366b31e94.zip
convert peerinfo to new service MQ API
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c632
1 files changed, 322 insertions, 310 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 07a7d704c..bc4a2a10d 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2014 GNUnet e.V. 3 Copyright (C) 2001-2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -69,22 +69,6 @@ struct HostEntry
69 69
70}; 70};
71 71
72/**
73 * Transmit context for GET requests
74 */
75struct TransmitContext
76{
77 /**
78 * Server transmit context
79 */
80 struct GNUNET_SERVER_TransmitContext *tc;
81
82 /**
83 * Include friend only HELLOs #GNUNET_YES or #GNUNET_NO
84 */
85 int friend_only;
86};
87
88 72
89/** 73/**
90 * Result of reading a file 74 * Result of reading a file
@@ -104,33 +88,6 @@ struct ReadHostFileContext
104 88
105 89
106/** 90/**
107 * Client notification context
108 */
109struct NotificationContext
110{
111 /**
112 * Next in DLL
113 */
114 struct NotificationContext *prev;
115
116 /**
117 * Previous in DLL
118 */
119 struct NotificationContext *next;
120
121 /**
122 * Server client
123 */
124 struct GNUNET_SERVER_Client *client;
125
126 /**
127 * Interested in friend only HELLO?
128 */
129 int include_friend_only;
130};
131
132
133/**
134 * The in-memory list of known hosts, mapping of 91 * The in-memory list of known hosts, mapping of
135 * host IDs to 'struct HostEntry*' values. 92 * host IDs to 'struct HostEntry*' values.
136 */ 93 */
@@ -139,7 +96,13 @@ static struct GNUNET_CONTAINER_MultiPeerMap *hostmap;
139/** 96/**
140 * Clients to immediately notify about all changes. 97 * Clients to immediately notify about all changes.
141 */ 98 */
142static struct GNUNET_SERVER_NotificationContext *notify_list; 99static struct GNUNET_NotificationContext *notify_list;
100
101/**
102 * Clients to immediately notify about all changes,
103 * even for friend-only HELLOs.
104 */
105static struct GNUNET_NotificationContext *notify_friend_only_list;
143 106
144/** 107/**
145 * Directory where the hellos are stored in (peerinfo/) 108 * Directory where the hellos are stored in (peerinfo/)
@@ -152,16 +115,6 @@ static char *networkIdDirectory;
152static struct GNUNET_STATISTICS_Handle *stats; 115static struct GNUNET_STATISTICS_Handle *stats;
153 116
154/** 117/**
155 * DLL of notification contexts: head
156 */
157static struct NotificationContext *nc_head;
158
159/**
160 * DLL of notification contexts: tail
161 */
162static struct NotificationContext *nc_tail;
163
164/**
165 * Handle for task to run #cron_clean_data_hosts() 118 * Handle for task to run #cron_clean_data_hosts()
166 */ 119 */
167static struct GNUNET_SCHEDULER_Task *cron_clean; 120static struct GNUNET_SCHEDULER_Task *cron_clean;
@@ -189,17 +142,17 @@ make_info_message (const struct HostEntry *he,
189 size_t hs; 142 size_t hs;
190 143
191 if (GNUNET_YES == include_friend_only) 144 if (GNUNET_YES == include_friend_only)
192 src = he->friend_only_hello; 145 src = he->friend_only_hello;
193 else 146 else
194 src = he->hello; 147 src = he->hello;
195
196 hs = (NULL == src) ? 0 : GNUNET_HELLO_size (src); 148 hs = (NULL == src) ? 0 : GNUNET_HELLO_size (src);
197 im = GNUNET_malloc (sizeof (struct InfoMessage) + hs); 149 im = GNUNET_malloc (sizeof (struct InfoMessage) + hs);
198 im->header.size = htons (hs + sizeof (struct InfoMessage)); 150 im->header.size = htons (hs + sizeof (struct InfoMessage));
199 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); 151 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
200 im->peer = he->identity; 152 im->peer = he->identity;
201 if (NULL != src) 153 GNUNET_memcpy (&im[1],
202 GNUNET_memcpy (&im[1], src, hs); 154 src,
155 hs);
203 return im; 156 return im;
204} 157}
205 158
@@ -264,7 +217,10 @@ get_host_filename (const struct GNUNET_PeerIdentity *id)
264 217
265 if (NULL == networkIdDirectory) 218 if (NULL == networkIdDirectory)
266 return NULL; 219 return NULL;
267 GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, 220 GNUNET_asprintf (&fn,
221 "%s%s%s",
222 networkIdDirectory,
223 DIR_SEPARATOR_STR,
268 GNUNET_i2s_full (id)); 224 GNUNET_i2s_full (id));
269 return fn; 225 return fn;
270} 226}
@@ -281,31 +237,21 @@ notify_all (struct HostEntry *entry)
281{ 237{
282 struct InfoMessage *msg_pub; 238 struct InfoMessage *msg_pub;
283 struct InfoMessage *msg_friend; 239 struct InfoMessage *msg_friend;
284 struct NotificationContext *cur;
285 240
286 msg_pub = make_info_message (entry, GNUNET_NO);
287 msg_friend = make_info_message (entry, GNUNET_YES);
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 "Notifying all clients about peer `%s'\n", 242 "Notifying all clients about peer `%s'\n",
290 GNUNET_i2s(&entry->identity)); 243 GNUNET_i2s(&entry->identity));
291 for (cur = nc_head; NULL != cur; cur = cur->next) 244 msg_pub = make_info_message (entry,
292 { 245 GNUNET_NO);
293 if (GNUNET_NO == cur->include_friend_only) 246 GNUNET_notification_context_broadcast (notify_list,
294 { 247 &msg_pub->header,
295 GNUNET_SERVER_notification_context_unicast (notify_list, 248 GNUNET_NO);
296 cur->client,
297 &msg_pub->header,
298 GNUNET_NO);
299 }
300 if (GNUNET_YES == cur->include_friend_only)
301 {
302 GNUNET_SERVER_notification_context_unicast (notify_list,
303 cur->client,
304 &msg_friend->header,
305 GNUNET_NO);
306 }
307 }
308 GNUNET_free (msg_pub); 249 GNUNET_free (msg_pub);
250 msg_friend = make_info_message (entry,
251 GNUNET_YES);
252 GNUNET_notification_context_broadcast (notify_friend_only_list,
253 &msg_friend->header,
254 GNUNET_NO);
309 GNUNET_free (msg_friend); 255 GNUNET_free (msg_friend);
310} 256}
311 257
@@ -351,7 +297,9 @@ read_host_file (const char *fn,
351 297
352 if (GNUNET_YES != GNUNET_DISK_file_test (fn)) 298 if (GNUNET_YES != GNUNET_DISK_file_test (fn))
353 return; 299 return;
354 size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); 300 size_total = GNUNET_DISK_fn_read (fn,
301 buffer,
302 sizeof (buffer));
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Read %d bytes from `%s'\n", 304 "Read %d bytes from `%s'\n",
357 (int) size_total, 305 (int) size_total,
@@ -360,7 +308,8 @@ read_host_file (const char *fn,
360 { 308 {
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
362 _("Failed to parse HELLO in file `%s': %s\n"), 310 _("Failed to parse HELLO in file `%s': %s\n"),
363 fn, "Fail has invalid size"); 311 fn,
312 "File has invalid size");
364 if ( (GNUNET_YES == unlink_garbage) && 313 if ( (GNUNET_YES == unlink_garbage) &&
365 (0 != UNLINK (fn)) && 314 (0 != UNLINK (fn)) &&
366 (ENOENT != errno) ) 315 (ENOENT != errno) )
@@ -392,9 +341,9 @@ read_host_file (const char *fn,
392 } 341 }
393 else 342 else
394 { 343 {
395 if ((GNUNET_YES == unlink_garbage) && 344 if ( (GNUNET_YES == unlink_garbage) &&
396 (0 != TRUNCATE (fn, read_pos)) && 345 (0 != TRUNCATE (fn, read_pos)) &&
397 (ENOENT != errno) ) 346 (ENOENT != errno) )
398 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 347 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
399 "truncate", 348 "truncate",
400 fn); 349 fn);
@@ -403,8 +352,10 @@ read_host_file (const char *fn,
403 } 352 }
404 353
405 now = GNUNET_TIME_absolute_get (); 354 now = GNUNET_TIME_absolute_get ();
406 hello_clean = GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, 355 hello_clean = GNUNET_HELLO_iterate_addresses (hello,
407 &discard_expired, &now); 356 GNUNET_YES,
357 &discard_expired,
358 &now);
408 if (NULL == hello_clean) 359 if (NULL == hello_clean)
409 { 360 {
410 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -419,8 +370,10 @@ read_host_file (const char *fn,
419 return; 370 return;
420 } 371 }
421 left = 0; 372 left = 0;
422 (void) GNUNET_HELLO_iterate_addresses (hello_clean, GNUNET_NO, 373 (void) GNUNET_HELLO_iterate_addresses (hello_clean,
423 &count_addresses, &left); 374 GNUNET_NO,
375 &count_addresses,
376 &left);
424 377
425 if (0 == left) 378 if (0 == left)
426 { 379 {
@@ -482,13 +435,16 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
482 struct ReadHostFileContext r; 435 struct ReadHostFileContext r;
483 char *fn; 436 char *fn;
484 437
485 entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity); 438 entry = GNUNET_CONTAINER_multipeermap_get (hostmap,
439 identity);
486 if (NULL == entry) 440 if (NULL == entry)
487 { 441 {
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "Adding new peer `%s'\n", 443 "Adding new peer `%s'\n",
490 GNUNET_i2s (identity)); 444 GNUNET_i2s (identity));
491 GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, 445 GNUNET_STATISTICS_update (stats,
446 gettext_noop ("# peers known"),
447 1,
492 GNUNET_NO); 448 GNUNET_NO);
493 entry = GNUNET_new (struct HostEntry); 449 entry = GNUNET_new (struct HostEntry);
494 entry->identity = *identity; 450 entry->identity = *identity;
@@ -501,11 +457,15 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity)
501 fn = get_host_filename (identity); 457 fn = get_host_filename (identity);
502 if (NULL != fn) 458 if (NULL != fn)
503 { 459 {
504 read_host_file (fn, GNUNET_YES, &r); 460 read_host_file (fn,
461 GNUNET_YES,
462 &r);
505 if (NULL != r.hello) 463 if (NULL != r.hello)
506 update_hello (identity, r.hello); 464 update_hello (identity,
465 r.hello);
507 if (NULL != r.friend_only_hello) 466 if (NULL != r.friend_only_hello)
508 update_hello (identity, r.friend_only_hello); 467 update_hello (identity,
468 r.friend_only_hello);
509 GNUNET_free_non_null (r.hello); 469 GNUNET_free_non_null (r.hello);
510 GNUNET_free_non_null (r.friend_only_hello); 470 GNUNET_free_non_null (r.friend_only_hello);
511 GNUNET_free (fn); 471 GNUNET_free (fn);
@@ -580,18 +540,25 @@ hosts_directory_scan_callback (void *cls,
580 if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) 540 if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
581 return GNUNET_OK; /* ignore non-files */ 541 return GNUNET_OK; /* ignore non-files */
582 542
583 filename = strrchr (fullname, DIR_SEPARATOR); 543 filename = strrchr (fullname,
584 if ((NULL == filename) || (1 > strlen (filename))) 544 DIR_SEPARATOR);
545 if ( (NULL == filename) ||
546 (1 > strlen (filename)) )
585 filename = fullname; 547 filename = fullname;
586 else 548 else
587 filename ++; 549 filename ++;
588 550
589 read_host_file (fullname, dsc->remove_files, &r); 551 read_host_file (fullname,
590 if ( (NULL == r.hello) && (NULL == r.friend_only_hello)) 552 dsc->remove_files,
553 &r);
554 if ( (NULL == r.hello) &&
555 (NULL == r.friend_only_hello))
591 return GNUNET_OK; 556 return GNUNET_OK;
592 if (NULL != r.friend_only_hello) 557 if (NULL != r.friend_only_hello)
593 { 558 {
594 if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) 559 if (GNUNET_OK !=
560 GNUNET_HELLO_get_id (r.friend_only_hello,
561 &id_friend))
595 if (GNUNET_YES == dsc->remove_files) 562 if (GNUNET_YES == dsc->remove_files)
596 { 563 {
597 remove_garbage (fullname); 564 remove_garbage (fullname);
@@ -601,7 +568,9 @@ hosts_directory_scan_callback (void *cls,
601 } 568 }
602 if (NULL != r.hello) 569 if (NULL != r.hello)
603 { 570 {
604 if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) 571 if (GNUNET_OK !=
572 GNUNET_HELLO_get_id (r.hello,
573 &id_public))
605 if (GNUNET_YES == dsc->remove_files) 574 if (GNUNET_YES == dsc->remove_files)
606 { 575 {
607 remove_garbage (fullname); 576 remove_garbage (fullname);
@@ -610,8 +579,11 @@ hosts_directory_scan_callback (void *cls,
610 id = id_public; 579 id = id_public;
611 } 580 }
612 581
613 if ( (NULL != r.hello) && (NULL != r.friend_only_hello) && 582 if ( (NULL != r.hello) &&
614 (0 != memcmp (&id_friend, &id_public, sizeof (id_friend))) ) 583 (NULL != r.friend_only_hello) &&
584 (0 != memcmp (&id_friend,
585 &id_public,
586 sizeof (id_friend))) )
615 { 587 {
616 /* HELLOs are not for the same peer */ 588 /* HELLOs are not for the same peer */
617 GNUNET_break (0); 589 GNUNET_break (0);
@@ -683,8 +655,10 @@ cron_scan_directory_data_hosts (void *cls)
683 _("Scanning directory `%s'\n"), 655 _("Scanning directory `%s'\n"),
684 networkIdDirectory); 656 networkIdDirectory);
685 GNUNET_DISK_directory_scan (networkIdDirectory, 657 GNUNET_DISK_directory_scan (networkIdDirectory,
686 &hosts_directory_scan_callback, &dsc); 658 &hosts_directory_scan_callback,
687 if ((0 == dsc.matched) && (0 == (++retries & 31))) 659 &dsc);
660 if ( (0 == dsc.matched) &&
661 (0 == (++retries & 31)) )
688 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 662 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
689 _("Still no peers found in `%s'!\n"), 663 _("Still no peers found in `%s'!\n"),
690 networkIdDirectory); 664 networkIdDirectory);
@@ -712,8 +686,10 @@ update_friend_hello (const struct GNUNET_HELLO_Message *hello,
712 686
713 if (NULL != friend_hello) 687 if (NULL != friend_hello)
714 { 688 {
715 res = GNUNET_HELLO_merge (hello, friend_hello); 689 res = GNUNET_HELLO_merge (hello,
716 GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); 690 friend_hello);
691 GNUNET_assert (GNUNET_YES ==
692 GNUNET_HELLO_is_friend_only (res));
717 return res; 693 return res;
718 } 694 }
719 695
@@ -783,8 +759,11 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
783 } 759 }
784 else 760 else
785 { 761 {
786 mrg = GNUNET_HELLO_merge ((*dest), hello); 762 mrg = GNUNET_HELLO_merge ((*dest),
787 delta = GNUNET_HELLO_equals (mrg, (*dest), GNUNET_TIME_absolute_get ()); 763 hello);
764 delta = GNUNET_HELLO_equals (mrg,
765 (*dest),
766 GNUNET_TIME_absolute_get ());
788 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) 767 if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
789 { 768 {
790 /* no differences, just ignore the update */ 769 /* no differences, just ignore the update */
@@ -803,7 +782,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
803 (GNUNET_NO == friend_hello_type) ) 782 (GNUNET_NO == friend_hello_type) )
804 { 783 {
805 /* Update friend only hello */ 784 /* Update friend only hello */
806 mrg = update_friend_hello (host->hello, host->friend_only_hello); 785 mrg = update_friend_hello (host->hello,
786 host->friend_only_hello);
807 if (NULL != host->friend_only_hello) 787 if (NULL != host->friend_only_hello)
808 GNUNET_free (host->friend_only_hello); 788 GNUNET_free (host->friend_only_hello);
809 host->friend_only_hello = mrg; 789 host->friend_only_hello = mrg;
@@ -862,8 +842,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
862 if (GNUNET_YES == store_hello) 842 if (GNUNET_YES == store_hello)
863 { 843 {
864 GNUNET_memcpy (buffer, 844 GNUNET_memcpy (buffer,
865 host->hello, 845 host->hello,
866 GNUNET_HELLO_size (host->hello)); 846 GNUNET_HELLO_size (host->hello));
867 pos += GNUNET_HELLO_size (host->hello); 847 pos += GNUNET_HELLO_size (host->hello);
868 } 848 }
869 if (GNUNET_YES == store_friend_hello) 849 if (GNUNET_YES == store_friend_hello)
@@ -886,7 +866,8 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
886 "Stored %s %s HELLO in %s with total size %u\n", 866 "Stored %s %s HELLO in %s with total size %u\n",
887 (GNUNET_YES == store_friend_hello) ? "friend-only": "", 867 (GNUNET_YES == store_friend_hello) ? "friend-only": "",
888 (GNUNET_YES == store_hello) ? "public": "", 868 (GNUNET_YES == store_hello) ? "public": "",
889 fn, size); 869 fn,
870 size);
890 GNUNET_free (buffer); 871 GNUNET_free (buffer);
891 } 872 }
892 } 873 }
@@ -896,6 +877,23 @@ update_hello (const struct GNUNET_PeerIdentity *peer,
896 877
897 878
898/** 879/**
880 * Closure for #add_to_tc()
881 */
882struct TransmitContext
883{
884 /**
885 * Client to transmit to
886 */
887 struct GNUNET_SERVICE_Client *client;
888
889 /**
890 * Include friend only HELLOs #GNUNET_YES or #GNUNET_NO
891 */
892 int friend_only;
893};
894
895
896/**
899 * Do transmit info about peer to given host. 897 * Do transmit info about peer to given host.
900 * 898 *
901 * @param cls NULL to hit all hosts, otherwise specifies a particular target 899 * @param cls NULL to hit all hosts, otherwise specifies a particular target
@@ -912,10 +910,9 @@ add_to_tc (void *cls,
912 struct HostEntry *pos = value; 910 struct HostEntry *pos = value;
913 struct InfoMessage *im; 911 struct InfoMessage *im;
914 uint16_t hs; 912 uint16_t hs;
915 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; 913 struct GNUNET_MQ_Envelope *env;
916 914
917 hs = 0; 915 hs = 0;
918 im = (struct InfoMessage *) buf;
919 916
920 if ( (NULL != pos->hello) && 917 if ( (NULL != pos->hello) &&
921 (GNUNET_NO == tc->friend_only) ) 918 (GNUNET_NO == tc->friend_only) )
@@ -924,10 +921,16 @@ add_to_tc (void *cls,
924 hs = GNUNET_HELLO_size (pos->hello); 921 hs = GNUNET_HELLO_size (pos->hello);
925 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 922 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
926 sizeof (struct InfoMessage)); 923 sizeof (struct InfoMessage));
927 GNUNET_memcpy (&im[1], pos->hello, hs); 924 env = GNUNET_MQ_msg_extra (im,
925 hs,
926 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
927 GNUNET_memcpy (&im[1],
928 pos->hello,
929 hs);
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "Sending public HELLO with size %u for peer `%4s'\n", 931 "Sending public HELLO with size %u for peer `%s'\n",
930 hs, GNUNET_i2s (key)); 932 hs,
933 GNUNET_i2s (key));
931 } 934 }
932 else if ( (NULL != pos->friend_only_hello) && 935 else if ( (NULL != pos->friend_only_hello) &&
933 (GNUNET_YES == tc->friend_only) ) 936 (GNUNET_YES == tc->friend_only) )
@@ -936,24 +939,28 @@ add_to_tc (void *cls,
936 hs = GNUNET_HELLO_size (pos->friend_only_hello); 939 hs = GNUNET_HELLO_size (pos->friend_only_hello);
937 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE - 940 GNUNET_assert (hs < GNUNET_SERVER_MAX_MESSAGE_SIZE -
938 sizeof (struct InfoMessage)); 941 sizeof (struct InfoMessage));
939 GNUNET_memcpy (&im[1], pos->friend_only_hello, hs); 942 env = GNUNET_MQ_msg_extra (im,
943 hs,
944 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
945 GNUNET_memcpy (&im[1],
946 pos->friend_only_hello,
947 hs);
940 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
941 "Sending friend-only HELLO with size %u for peer `%4s'\n", 949 "Sending friend-only HELLO with size %u for peer `%s'\n",
942 hs, 950 hs,
943 GNUNET_i2s (key)); 951 GNUNET_i2s (key));
944 } 952 }
945 else 953 else
946 { 954 {
955 env = GNUNET_MQ_msg (im,
956 GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
948 "Adding no HELLO for peer `%s'\n", 958 "Adding no HELLO for peer `%s'\n",
949 GNUNET_i2s (key)); 959 GNUNET_i2s (key));
950 } 960 }
951
952 im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
953 im->header.size = htons (sizeof (struct InfoMessage) + hs);
954 im->reserved = htonl (0);
955 im->peer = pos->identity; 961 im->peer = pos->identity;
956 GNUNET_SERVER_transmit_context_append_message (tc->tc, &im->header); 962 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client),
963 env);
957 return GNUNET_YES; 964 return GNUNET_YES;
958} 965}
959 966
@@ -1004,23 +1011,28 @@ discard_hosts_helper (void *cls,
1004 if (0 != UNLINK (fn)) 1011 if (0 != UNLINK (fn))
1005 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1012 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
1006 GNUNET_ERROR_TYPE_BULK, 1013 GNUNET_ERROR_TYPE_BULK,
1007 "unlink", fn); 1014 "unlink",
1015 fn);
1008 GNUNET_free (writebuffer); 1016 GNUNET_free (writebuffer);
1009 return GNUNET_OK; 1017 return GNUNET_OK;
1010 } 1018 }
1011 new_hello = GNUNET_HELLO_iterate_addresses (hello, 1019 new_hello = GNUNET_HELLO_iterate_addresses (hello,
1012 GNUNET_YES, 1020 GNUNET_YES,
1013 &discard_expired, now); 1021 &discard_expired,
1022 now);
1014 cnt = 0; 1023 cnt = 0;
1015 if (NULL != new_hello) 1024 if (NULL != new_hello)
1016 (void) GNUNET_HELLO_iterate_addresses (hello, 1025 (void) GNUNET_HELLO_iterate_addresses (hello,
1017 GNUNET_NO, 1026 GNUNET_NO,
1018 &count_addresses, &cnt); 1027 &count_addresses,
1028 &cnt);
1019 if ( (NULL != new_hello) && (0 < cnt) ) 1029 if ( (NULL != new_hello) && (0 < cnt) )
1020 { 1030 {
1021 /* Store new HELLO to write it when done */ 1031 /* Store new HELLO to write it when done */
1022 new_hello_size = GNUNET_HELLO_size (new_hello); 1032 new_hello_size = GNUNET_HELLO_size (new_hello);
1023 GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size); 1033 GNUNET_memcpy (&writebuffer[write_pos],
1034 new_hello,
1035 new_hello_size);
1024 write_pos += new_hello_size; 1036 write_pos += new_hello_size;
1025 } 1037 }
1026 read_pos += cur_hello_size; 1038 read_pos += cur_hello_size;
@@ -1073,167 +1085,170 @@ cron_clean_data_hosts (void *cls)
1073 1085
1074 1086
1075/** 1087/**
1076 * Handle HELLO-message. 1088 * Check HELLO-message.
1077 * 1089 *
1078 * @param cls closure 1090 * @param cls identification of the client
1079 * @param client identification of the client 1091 * @param hello the actual message
1080 * @param message the actual message 1092 * @return #GNUNET_OK if @a hello is well-formed
1081 */ 1093 */
1082static void 1094static int
1083handle_hello (void *cls, 1095check_hello (void *cls,
1084 struct GNUNET_SERVER_Client *client, 1096 const struct GNUNET_HELLO_Message *hello)
1085 const struct GNUNET_MessageHeader *message)
1086{ 1097{
1087 const struct GNUNET_HELLO_Message *hello;
1088 struct GNUNET_PeerIdentity pid; 1098 struct GNUNET_PeerIdentity pid;
1089 1099
1090 hello = (const struct GNUNET_HELLO_Message *) message; 1100 if (GNUNET_OK !=
1091 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) 1101 GNUNET_HELLO_get_id (hello,
1102 &pid))
1092 { 1103 {
1093 GNUNET_break (0); 1104 GNUNET_break (0);
1094 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1105 return GNUNET_SYSERR;
1095 return;
1096 } 1106 }
1107 return GNUNET_OK;
1108}
1109
1110
1111/**
1112 * Handle HELLO-message.
1113 *
1114 * @param cls identification of the client
1115 * @param hello the actual message
1116 */
1117static void
1118handle_hello (void *cls,
1119 const struct GNUNET_HELLO_Message *hello)
1120{
1121 struct GNUNET_SERVICE_Client *client = cls;
1122 struct GNUNET_PeerIdentity pid;
1123
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1098 "`%s' message received for peer `%4s'\n", 1125 "HELLO message received for peer `%s'\n",
1099 "HELLO",
1100 GNUNET_i2s (&pid)); 1126 GNUNET_i2s (&pid));
1127 GNUNET_assert (GNUNET_OK ==
1128 GNUNET_HELLO_get_id (hello,
1129 &pid));
1101 add_host_to_known_hosts (&pid); 1130 add_host_to_known_hosts (&pid);
1102 update_hello (&pid, hello); 1131 update_hello (&pid,
1103 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1132 hello);
1133 GNUNET_SERVICE_client_continue (client);
1104} 1134}
1105 1135
1106 1136
1107/** 1137/**
1108 * Handle GET-message. 1138 * Handle GET-message.
1109 * 1139 *
1110 * @param cls closure 1140 * @param cls identification of the client
1111 * @param client identification of the client 1141 * @param lpm the actual message
1112 * @param message the actual message
1113 */ 1142 */
1114static void 1143static void
1115handle_get (void *cls, 1144handle_get (void *cls,
1116 struct GNUNET_SERVER_Client *client, 1145 const struct ListPeerMessage *lpm)
1117 const struct GNUNET_MessageHeader *message)
1118{ 1146{
1119 const struct ListPeerMessage *lpm; 1147 struct GNUNET_SERVICE_Client *client = cls;
1120 struct TransmitContext tcx; 1148 struct TransmitContext tcx;
1149 struct GNUNET_MessageHeader *msg;
1150 struct GNUNET_MQ_Envelope *env;
1121 1151
1122 lpm = (const struct ListPeerMessage *) message;
1123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1124 "`%s' message received for peer `%4s'\n", 1153 "GET message received for peer `%s'\n",
1125 "GET",
1126 GNUNET_i2s (&lpm->peer)); 1154 GNUNET_i2s (&lpm->peer));
1127 tcx.friend_only = ntohl (lpm->include_friend_only); 1155 tcx.friend_only = ntohl (lpm->include_friend_only);
1128 tcx.tc = GNUNET_SERVER_transmit_context_create (client); 1156 tcx.client = client;
1129 GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, &lpm->peer, 1157 GNUNET_CONTAINER_multipeermap_get_multiple (hostmap,
1130 &add_to_tc, &tcx); 1158 &lpm->peer,
1131 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0, 1159 &add_to_tc,
1132 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1160 &tcx);
1133 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL); 1161 env = GNUNET_MQ_msg (msg,
1162 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1163 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1164 env);
1165 GNUNET_SERVICE_client_continue (client);
1134} 1166}
1135 1167
1136 1168
1137/** 1169/**
1138 * Handle GET-ALL-message. 1170 * Handle GET-ALL-message.
1139 * 1171 *
1140 * @param cls closure 1172 * @param cls identification of the client
1141 * @param client identification of the client 1173 * @param lapm the actual message
1142 * @param message the actual message
1143 */ 1174 */
1144static void 1175static void
1145handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, 1176handle_get_all (void *cls,
1146 const struct GNUNET_MessageHeader *message) 1177 const struct ListAllPeersMessage *lapm)
1147{ 1178{
1148 const struct ListAllPeersMessage *lapm; 1179 struct GNUNET_SERVICE_Client *client = cls;
1149 struct TransmitContext tcx; 1180 struct TransmitContext tcx;
1181 struct GNUNET_MQ_Envelope *env;
1182 struct GNUNET_MessageHeader *msg;
1150 1183
1151 lapm = (const struct ListAllPeersMessage *) message;
1152 tcx.friend_only = ntohl (lapm->include_friend_only);
1153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1154 "`%s' message received\n", 1185 "GET_ALL message received\n");
1155 "GET_ALL"); 1186 tcx.friend_only = ntohl (lapm->include_friend_only);
1156 GNUNET_SERVER_disable_receive_done_warning (client); 1187 tcx.client = client;
1157 tcx.tc = GNUNET_SERVER_transmit_context_create (client);
1158 GNUNET_CONTAINER_multipeermap_iterate (hostmap, 1188 GNUNET_CONTAINER_multipeermap_iterate (hostmap,
1159 &add_to_tc, 1189 &add_to_tc,
1160 &tcx); 1190 &tcx);
1161 GNUNET_SERVER_transmit_context_append_data (tcx.tc, NULL, 0, 1191 env = GNUNET_MQ_msg (msg,
1162 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); 1192 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1163 GNUNET_SERVER_transmit_context_run (tcx.tc, GNUNET_TIME_UNIT_FOREVER_REL); 1193 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1194 env);
1195 GNUNET_SERVICE_client_continue (client);
1164} 1196}
1165 1197
1166 1198
1167
1168/** 1199/**
1169 * Pass the given client the information we have in the respective 1200 * Handle NOTIFY-message.
1170 * host entry; the client is already in the notification context.
1171 * 1201 *
1172 * @param cls the `struct GNUNET_SERVER_Client` to notify 1202 * @param cls identification of the client
1173 * @param key key for the value (unused) 1203 * @param nm the actual message
1174 * @param value the `struct HostEntry` to notify the client about
1175 * @return #GNUNET_YES (always, continue to iterate)
1176 */ 1204 */
1177static int 1205static void
1178do_notify_entry (void *cls, 1206handle_notify (void *cls,
1179 const struct GNUNET_PeerIdentity *key, 1207 const struct NotifyMessage *nm)
1180 void *value)
1181{ 1208{
1182 struct NotificationContext *nc = cls; 1209 struct GNUNET_SERVICE_Client *client = cls;
1183 struct HostEntry *he = value; 1210 struct GNUNET_MQ_Handle *mq;
1184 struct InfoMessage *msg; 1211 struct TransmitContext tcx;
1185 1212 struct GNUNET_MQ_Envelope *env;
1186 if ( (NULL == he->hello) && 1213 struct GNUNET_MessageHeader *msg;
1187 (GNUNET_NO == nc->include_friend_only) )
1188 {
1189 /* We have no public hello */
1190 return GNUNET_YES;
1191 }
1192
1193 if ( (NULL == he->friend_only_hello) &&
1194 (GNUNET_YES == nc->include_friend_only) )
1195 {
1196 /* We have no friend hello */
1197 return GNUNET_YES;
1198 }
1199 1214
1200 msg = make_info_message (he, nc->include_friend_only); 1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1201 GNUNET_SERVER_notification_context_unicast (notify_list, 1216 "NOTIFY message received\n");
1202 nc->client, 1217 mq = GNUNET_SERVICE_client_get_mq (client);
1203 &msg->header, 1218 GNUNET_SERVICE_client_mark_monitor (client);
1204 GNUNET_NO); 1219 if (ntohl (nm->include_friend_only))
1205 GNUNET_free (msg); 1220 GNUNET_notification_context_add (notify_friend_only_list,
1206 return GNUNET_YES; 1221 mq);
1222 else
1223 GNUNET_notification_context_add (notify_list,
1224 mq);
1225 tcx.friend_only = ntohl (nm->include_friend_only);
1226 tcx.client = client;
1227 GNUNET_CONTAINER_multipeermap_iterate (hostmap,
1228 &add_to_tc,
1229 &tcx);
1230 env = GNUNET_MQ_msg (msg,
1231 GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
1232 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
1233 env);
1234 GNUNET_SERVICE_client_continue (client);
1207} 1235}
1208 1236
1209 1237
1210/** 1238/**
1211 * Handle NOTIFY-message. 1239 * Client connect callback
1212 * 1240 *
1213 * @param cls closure 1241 * @param cls unused
1214 * @param client identification of the client 1242 * @param client server client
1215 * @param message the actual message 1243 * @param mq for @a client
1244 * @return @a client
1216 */ 1245 */
1217static void 1246static void *
1218handle_notify (void *cls, 1247client_connect_cb (void *cls,
1219 struct GNUNET_SERVER_Client *client, 1248 struct GNUNET_SERVICE_Client *client,
1220 const struct GNUNET_MessageHeader *message) 1249 struct GNUNET_MQ_Handle *mq)
1221{ 1250{
1222 struct NotifyMessage *nm = (struct NotifyMessage *) message; 1251 return client;
1223 struct NotificationContext *nc;
1224
1225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1226 "`%s' message received\n",
1227 "NOTIFY");
1228 nc = GNUNET_new (struct NotificationContext);
1229 nc->client = client;
1230 nc->include_friend_only = ntohl (nm->include_friend_only);
1231
1232 GNUNET_CONTAINER_DLL_insert (nc_head, nc_tail, nc);
1233 GNUNET_SERVER_client_mark_monitor (client);
1234 GNUNET_SERVER_notification_context_add (notify_list, client);
1235 GNUNET_CONTAINER_multipeermap_iterate (hostmap, &do_notify_entry, nc);
1236 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1237} 1252}
1238 1253
1239 1254
@@ -1242,20 +1257,14 @@ handle_notify (void *cls,
1242 * 1257 *
1243 * @param cls unused 1258 * @param cls unused
1244 * @param client server client 1259 * @param client server client
1260 * @param app_ctx should be @a client
1245 */ 1261 */
1246static void 1262static void
1247disconnect_cb (void *cls, 1263client_disconnect_cb (void *cls,
1248 struct GNUNET_SERVER_Client *client) 1264 struct GNUNET_SERVICE_Client *client,
1265 void *app_ctx)
1249{ 1266{
1250 struct NotificationContext *cur; 1267 GNUNET_assert (app_ctx == client);
1251
1252 for (cur = nc_head; NULL != cur; cur = cur->next)
1253 if (cur->client == client)
1254 break;
1255 if (NULL == cur)
1256 return;
1257 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur);
1258 GNUNET_free (cur);
1259} 1268}
1260 1269
1261 1270
@@ -1289,25 +1298,19 @@ free_host_entry (void *cls,
1289static void 1298static void
1290shutdown_task (void *cls) 1299shutdown_task (void *cls)
1291{ 1300{
1292 struct NotificationContext *cur; 1301 GNUNET_notification_context_destroy (notify_list);
1293 struct NotificationContext *next;
1294
1295 GNUNET_SERVER_notification_context_destroy (notify_list);
1296 notify_list = NULL; 1302 notify_list = NULL;
1303 GNUNET_notification_context_destroy (notify_friend_only_list);
1304 notify_friend_only_list = NULL;
1297 1305
1298 for (cur = nc_head; NULL != cur; cur = next)
1299 {
1300 next = cur->next;
1301 GNUNET_CONTAINER_DLL_remove (nc_head, nc_tail, cur);
1302 GNUNET_free (cur);
1303 }
1304 GNUNET_CONTAINER_multipeermap_iterate (hostmap, 1306 GNUNET_CONTAINER_multipeermap_iterate (hostmap,
1305 &free_host_entry, 1307 &free_host_entry,
1306 NULL); 1308 NULL);
1307 GNUNET_CONTAINER_multipeermap_destroy (hostmap); 1309 GNUNET_CONTAINER_multipeermap_destroy (hostmap);
1308 if (NULL != stats) 1310 if (NULL != stats)
1309 { 1311 {
1310 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1312 GNUNET_STATISTICS_destroy (stats,
1313 GNUNET_NO);
1311 stats = NULL; 1314 stats = NULL;
1312 } 1315 }
1313 if (NULL != cron_clean) 1316 if (NULL != cron_clean)
@@ -1320,6 +1323,11 @@ shutdown_task (void *cls)
1320 GNUNET_SCHEDULER_cancel (cron_scan); 1323 GNUNET_SCHEDULER_cancel (cron_scan);
1321 cron_scan = NULL; 1324 cron_scan = NULL;
1322 } 1325 }
1326 if (NULL != networkIdDirectory)
1327 {
1328 GNUNET_free (networkIdDirectory);
1329 networkIdDirectory = NULL;
1330 }
1323} 1331}
1324 1332
1325 1333
@@ -1327,37 +1335,37 @@ shutdown_task (void *cls)
1327 * Start up peerinfo service. 1335 * Start up peerinfo service.
1328 * 1336 *
1329 * @param cls closure 1337 * @param cls closure
1330 * @param server the initialized server
1331 * @param cfg configuration to use 1338 * @param cfg configuration to use
1339 * @param service the initialized service
1332 */ 1340 */
1333static void 1341static void
1334run (void *cls, 1342run (void *cls,
1335 struct GNUNET_SERVER_Handle *server, 1343 const struct GNUNET_CONFIGURATION_Handle *cfg,
1336 const struct GNUNET_CONFIGURATION_Handle *cfg) 1344 struct GNUNET_SERVICE_Handle *service)
1337{ 1345{
1338 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1339 {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0},
1340 {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET,
1341 sizeof (struct ListPeerMessage)},
1342 {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
1343 sizeof (struct ListAllPeersMessage)},
1344 {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
1345 sizeof (struct NotifyMessage)},
1346 {NULL, NULL, 0, 0}
1347 };
1348 char *peerdir; 1346 char *peerdir;
1349 char *ip; 1347 char *ip;
1350 struct DirScanContext dsc; 1348 struct DirScanContext dsc;
1351 int noio; 1349 int noio;
1352 int use_included; 1350 int use_included;
1353 1351
1354 hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 1352 hostmap
1355 stats = GNUNET_STATISTICS_create ("peerinfo", cfg); 1353 = GNUNET_CONTAINER_multipeermap_create (1024,
1356 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 1354 GNUNET_YES);
1357 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); 1355 stats
1358 use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1356 = GNUNET_STATISTICS_create ("peerinfo",
1359 "peerinfo", 1357 cfg);
1360 "USE_INCLUDED_HELLOS"); 1358 notify_list
1359 = GNUNET_notification_context_create (0);
1360 notify_friend_only_list
1361 = GNUNET_notification_context_create (0);
1362 noio = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1363 "peerinfo",
1364 "NO_IO");
1365 use_included
1366 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1367 "peerinfo",
1368 "USE_INCLUDED_HELLOS");
1361 if (GNUNET_SYSERR == use_included) 1369 if (GNUNET_SYSERR == use_included)
1362 use_included = GNUNET_NO; 1370 use_included = GNUNET_NO;
1363 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1371 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
@@ -1365,7 +1373,8 @@ run (void *cls,
1365 if (GNUNET_YES != noio) 1373 if (GNUNET_YES != noio)
1366 { 1374 {
1367 GNUNET_assert (GNUNET_OK == 1375 GNUNET_assert (GNUNET_OK ==
1368 GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo", 1376 GNUNET_CONFIGURATION_get_value_filename (cfg,
1377 "peerinfo",
1369 "HOSTS", 1378 "HOSTS",
1370 &networkIdDirectory)); 1379 &networkIdDirectory));
1371 if (GNUNET_OK != 1380 if (GNUNET_OK !=
@@ -1375,20 +1384,22 @@ run (void *cls,
1375 return; 1384 return;
1376 } 1385 }
1377 1386
1378 cron_scan = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1387 cron_scan
1379 &cron_scan_directory_data_hosts, 1388 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1380 NULL); 1389 &cron_scan_directory_data_hosts,
1390 NULL);
1381 1391
1382 cron_clean = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 1392 cron_clean
1383 &cron_clean_data_hosts, 1393 = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
1384 NULL); 1394 &cron_clean_data_hosts,
1395 NULL);
1385 if (GNUNET_YES == use_included) 1396 if (GNUNET_YES == use_included)
1386 { 1397 {
1387 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 1398 ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
1388 GNUNET_asprintf (&peerdir, 1399 GNUNET_asprintf (&peerdir,
1389 "%shellos", 1400 "%shellos",
1390 ip); 1401 ip);
1391 GNUNET_free(ip); 1402 GNUNET_free (ip);
1392 1403
1393 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1404 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1394 _("Importing HELLOs from `%s'\n"), 1405 _("Importing HELLOs from `%s'\n"),
@@ -1403,39 +1414,40 @@ run (void *cls,
1403 } 1414 }
1404 else 1415 else
1405 { 1416 {
1406 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1417 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1407 _("Skipping import of included HELLOs\n")); 1418 _("Skipping import of included HELLOs\n"));
1408 } 1419 }
1409 } 1420 }
1410 GNUNET_SERVER_add_handlers (server, handlers);
1411 GNUNET_SERVER_disconnect_notify (server,
1412 &disconnect_cb,
1413 NULL);
1414} 1421}
1415 1422
1416 1423
1417/** 1424/**
1418 * The main function for the peerinfo service. 1425 * Define "main" method using service macro.
1419 *
1420 * @param argc number of arguments from the command line
1421 * @param argv command line arguments
1422 * @return 0 ok, 1 on error
1423 */ 1426 */
1424int 1427GNUNET_SERVICE_MAIN
1425main (int argc, 1428("peerinfo",
1426 char *const *argv) 1429 GNUNET_SERVICE_OPTION_NONE,
1427{ 1430 &run,
1428 int ret; 1431 &client_connect_cb,
1429 1432 &client_disconnect_cb,
1430 ret = 1433 NULL,
1431 (GNUNET_OK == 1434 GNUNET_MQ_hd_var_size (hello,
1432 GNUNET_SERVICE_run (argc, argv, 1435 GNUNET_MESSAGE_TYPE_HELLO,
1433 "peerinfo", 1436 struct GNUNET_HELLO_Message,
1434 GNUNET_SERVICE_OPTION_NONE, 1437 NULL),
1435 &run, NULL)) ? 0 : 1; 1438 GNUNET_MQ_hd_fixed_size (get,
1436 GNUNET_free_non_null (networkIdDirectory); 1439 GNUNET_MESSAGE_TYPE_PEERINFO_GET,
1437 return ret; 1440 struct ListPeerMessage,
1438} 1441 NULL),
1442 GNUNET_MQ_hd_fixed_size (get_all,
1443 GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL,
1444 struct ListAllPeersMessage,
1445 NULL),
1446 GNUNET_MQ_hd_fixed_size (notify,
1447 GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY,
1448 struct NotifyMessage,
1449 NULL),
1450 GNUNET_MQ_handler_end ());
1439 1451
1440 1452
1441/* end of gnunet-service-peerinfo.c */ 1453/* end of gnunet-service-peerinfo.c */