diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-04 12:02:43 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-04-04 12:02:43 +0000 |
commit | 425e9cdea733ca7be9a901abff7a070c460fa84d (patch) | |
tree | c4e2919e2f4183a324801c061fb2d57a3b232ddc /src/peerinfo | |
parent | 6713f0ce7d70cdb5cb0172157e647b8dfb6852ff (diff) | |
download | gnunet-425e9cdea733ca7be9a901abff7a070c460fa84d.tar.gz gnunet-425e9cdea733ca7be9a901abff7a070c460fa84d.zip |
peerinfo API change + changes in code using api
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 18 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.h | 48 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 16 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 25 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 4 |
5 files changed, 87 insertions, 24 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 68024a90a..55d4177cf 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -90,6 +90,7 @@ static char *networkIdDirectory; | |||
90 | static struct GNUNET_STATISTICS_Handle *stats; | 90 | static struct GNUNET_STATISTICS_Handle *stats; |
91 | 91 | ||
92 | 92 | ||
93 | |||
93 | /** | 94 | /** |
94 | * Notify all clients in the notify list about the | 95 | * Notify all clients in the notify list about the |
95 | * given host entry changing. | 96 | * given host entry changing. |
@@ -638,9 +639,10 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client, | |||
638 | { | 639 | { |
639 | const struct ListPeerMessage *lpm; | 640 | const struct ListPeerMessage *lpm; |
640 | struct GNUNET_SERVER_TransmitContext *tc; | 641 | struct GNUNET_SERVER_TransmitContext *tc; |
642 | int friend_only; | ||
641 | 643 | ||
642 | lpm = (const struct ListPeerMessage *) message; | 644 | lpm = (const struct ListPeerMessage *) message; |
643 | GNUNET_break (0 == ntohl (lpm->reserved)); | 645 | friend_only = ntohl (lpm->include_friend_only); |
644 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", | 646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", |
645 | "GET", GNUNET_i2s (&lpm->peer)); | 647 | "GET", GNUNET_i2s (&lpm->peer)); |
646 | tc = GNUNET_SERVER_transmit_context_create (client); | 648 | tc = GNUNET_SERVER_transmit_context_create (client); |
@@ -663,8 +665,12 @@ static void | |||
663 | handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, | 665 | handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, |
664 | const struct GNUNET_MessageHeader *message) | 666 | const struct GNUNET_MessageHeader *message) |
665 | { | 667 | { |
668 | const struct ListAllPeersMessage *lapm; | ||
666 | struct GNUNET_SERVER_TransmitContext *tc; | 669 | struct GNUNET_SERVER_TransmitContext *tc; |
670 | int friend_only; | ||
667 | 671 | ||
672 | lapm = (const struct ListAllPeersMessage *) message; | ||
673 | friend_only = ntohl (lapm->include_friend_only); | ||
668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); | 674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); |
669 | tc = GNUNET_SERVER_transmit_context_create (client); | 675 | tc = GNUNET_SERVER_transmit_context_create (client); |
670 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); | 676 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); |
@@ -709,7 +715,11 @@ static void | |||
709 | handle_notify (void *cls, struct GNUNET_SERVER_Client *client, | 715 | handle_notify (void *cls, struct GNUNET_SERVER_Client *client, |
710 | const struct GNUNET_MessageHeader *message) | 716 | const struct GNUNET_MessageHeader *message) |
711 | { | 717 | { |
712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); | 718 | struct NotifyMessage *nm = (struct NotifyMessage *) message; |
719 | int friend_only; | ||
720 | |||
721 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); | ||
722 | friend_only = ntohl (nm->include_friend_only); | ||
713 | GNUNET_SERVER_client_mark_monitor (client); | 723 | GNUNET_SERVER_client_mark_monitor (client); |
714 | GNUNET_SERVER_notification_context_add (notify_list, client); | 724 | GNUNET_SERVER_notification_context_add (notify_list, client); |
715 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); | 725 | GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); |
@@ -773,9 +783,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
773 | {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, | 783 | {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, |
774 | sizeof (struct ListPeerMessage)}, | 784 | sizeof (struct ListPeerMessage)}, |
775 | {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, | 785 | {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, |
776 | sizeof (struct GNUNET_MessageHeader)}, | 786 | sizeof (struct ListAllPeersMessage)}, |
777 | {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, | 787 | {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, |
778 | sizeof (struct GNUNET_MessageHeader)}, | 788 | sizeof (struct NotifyMessage)}, |
779 | {NULL, NULL, 0, 0} | 789 | {NULL, NULL, 0, 0} |
780 | }; | 790 | }; |
781 | char *peerdir; | 791 | char *peerdir; |
diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h index e61848757..97f819aff 100644 --- a/src/peerinfo/peerinfo.h +++ b/src/peerinfo/peerinfo.h | |||
@@ -31,22 +31,22 @@ | |||
31 | GNUNET_NETWORK_STRUCT_BEGIN | 31 | GNUNET_NETWORK_STRUCT_BEGIN |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Message requesting a listing of all known peers, | 34 | * Message requesting a listing of peers, |
35 | * possibly restricted to the specified peer identity. | 35 | * restricted to the specified peer identity. |
36 | */ | 36 | */ |
37 | struct ListPeerMessage | 37 | struct ListPeerMessage |
38 | { | 38 | { |
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET or | 41 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET |
42 | * GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL. | 42 | * . |
43 | */ | 43 | */ |
44 | struct GNUNET_MessageHeader header; | 44 | struct GNUNET_MessageHeader header; |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Always zero. | 47 | * Include friend only HELLOs and peers in callbacks |
48 | */ | 48 | */ |
49 | uint32_t reserved GNUNET_PACKED; | 49 | uint32_t include_friend_only GNUNET_PACKED; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Restrict to peers with this identity (optional | 52 | * Restrict to peers with this identity (optional |
@@ -56,6 +56,42 @@ struct ListPeerMessage | |||
56 | 56 | ||
57 | }; | 57 | }; |
58 | 58 | ||
59 | /** | ||
60 | * Message requesting a listing of all peers, | ||
61 | * restricted to the specified peer identity. | ||
62 | */ | ||
63 | struct ListAllPeersMessage | ||
64 | { | ||
65 | /** | ||
66 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL | ||
67 | */ | ||
68 | struct GNUNET_MessageHeader header; | ||
69 | |||
70 | /** | ||
71 | * Include friend only HELLOs and peers in callbacks | ||
72 | */ | ||
73 | uint32_t include_friend_only GNUNET_PACKED; | ||
74 | |||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Header for all communications. | ||
80 | */ | ||
81 | struct NotifyMessage | ||
82 | { | ||
83 | /** | ||
84 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY | ||
85 | */ | ||
86 | struct GNUNET_MessageHeader header; | ||
87 | |||
88 | /** | ||
89 | * Include friend only HELLOs and peers in callbacks | ||
90 | */ | ||
91 | uint32_t include_friend_only GNUNET_PACKED; | ||
92 | |||
93 | }; | ||
94 | |||
59 | 95 | ||
60 | /** | 96 | /** |
61 | * Message used to inform the client about | 97 | * Message used to inform the client about |
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index 175397c78..faa56e908 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -692,6 +692,7 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
692 | * better to use 'GNUNET_PEERINFO_notify'. | 692 | * better to use 'GNUNET_PEERINFO_notify'. |
693 | * | 693 | * |
694 | * @param h handle to the peerinfo service | 694 | * @param h handle to the peerinfo service |
695 | * @param include_friend_only include HELLO messages for friends only | ||
695 | * @param peer restrict iteration to this peer only (can be NULL) | 696 | * @param peer restrict iteration to this peer only (can be NULL) |
696 | * @param timeout how long to wait until timing out | 697 | * @param timeout how long to wait until timing out |
697 | * @param callback the method to call for each peer | 698 | * @param callback the method to call for each peer |
@@ -700,11 +701,12 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
700 | */ | 701 | */ |
701 | struct GNUNET_PEERINFO_IteratorContext * | 702 | struct GNUNET_PEERINFO_IteratorContext * |
702 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | 703 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, |
704 | int include_friend_only, | ||
703 | const struct GNUNET_PeerIdentity *peer, | 705 | const struct GNUNET_PeerIdentity *peer, |
704 | struct GNUNET_TIME_Relative timeout, | 706 | struct GNUNET_TIME_Relative timeout, |
705 | GNUNET_PEERINFO_Processor callback, void *callback_cls) | 707 | GNUNET_PEERINFO_Processor callback, void *callback_cls) |
706 | { | 708 | { |
707 | struct GNUNET_MessageHeader *lapm; | 709 | struct ListAllPeersMessage *lapm; |
708 | struct ListPeerMessage *lpm; | 710 | struct ListPeerMessage *lpm; |
709 | struct GNUNET_PEERINFO_IteratorContext *ic; | 711 | struct GNUNET_PEERINFO_IteratorContext *ic; |
710 | struct GNUNET_PEERINFO_AddContext *ac; | 712 | struct GNUNET_PEERINFO_AddContext *ac; |
@@ -716,11 +718,12 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
716 | "Requesting list of peers from PEERINFO service\n"); | 718 | "Requesting list of peers from PEERINFO service\n"); |
717 | ac = | 719 | ac = |
718 | GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + | 720 | GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + |
719 | sizeof (struct GNUNET_MessageHeader)); | 721 | sizeof (struct ListAllPeersMessage)); |
720 | ac->size = sizeof (struct GNUNET_MessageHeader); | 722 | ac->size = sizeof (struct ListAllPeersMessage); |
721 | lapm = (struct GNUNET_MessageHeader *) &ac[1]; | 723 | lapm = (struct ListAllPeersMessage *) &ac[1]; |
722 | lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); | 724 | lapm->header.size = htons (sizeof (struct ListAllPeersMessage)); |
723 | lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 725 | lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
726 | lapm->include_friend_only = htonl (include_friend_only); | ||
724 | } | 727 | } |
725 | else | 728 | else |
726 | { | 729 | { |
@@ -734,6 +737,7 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
734 | lpm = (struct ListPeerMessage *) &ac[1]; | 737 | lpm = (struct ListPeerMessage *) &ac[1]; |
735 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); | 738 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); |
736 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 739 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
740 | lpm->include_friend_only = htonl (include_friend_only); | ||
737 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 741 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
738 | ic->have_peer = GNUNET_YES; | 742 | ic->have_peer = GNUNET_YES; |
739 | ic->peer = *peer; | 743 | ic->peer = *peer; |
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index b9e83c9e7..4520decfd 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -69,6 +69,11 @@ struct GNUNET_PEERINFO_NotifyContext | |||
69 | */ | 69 | */ |
70 | GNUNET_SCHEDULER_TaskIdentifier task; | 70 | GNUNET_SCHEDULER_TaskIdentifier task; |
71 | 71 | ||
72 | /** | ||
73 | * Include friend only HELLOs in callbacks | ||
74 | */ | ||
75 | |||
76 | int include_friend_only; | ||
72 | }; | 77 | }; |
73 | 78 | ||
74 | 79 | ||
@@ -195,7 +200,7 @@ static size_t | |||
195 | transmit_notify_request (void *cls, size_t size, void *buf) | 200 | transmit_notify_request (void *cls, size_t size, void *buf) |
196 | { | 201 | { |
197 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 202 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
198 | struct GNUNET_MessageHeader hdr; | 203 | struct NotifyMessage nm; |
199 | 204 | ||
200 | nc->init = NULL; | 205 | nc->init = NULL; |
201 | if (buf == NULL) | 206 | if (buf == NULL) |
@@ -205,10 +210,11 @@ transmit_notify_request (void *cls, size_t size, void *buf) | |||
205 | request_notifications (nc); | 210 | request_notifications (nc); |
206 | return 0; | 211 | return 0; |
207 | } | 212 | } |
208 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 213 | GNUNET_assert (size >= sizeof (struct NotifyMessage)); |
209 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); | 214 | nm.header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); |
210 | hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); | 215 | nm.header.size = htons (sizeof (struct NotifyMessage)); |
211 | memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader)); | 216 | nm.include_friend_only = htonl (nc->include_friend_only); |
217 | memcpy (buf, &nm, sizeof (struct NotifyMessage)); | ||
212 | receive_notifications (nc); | 218 | receive_notifications (nc); |
213 | return sizeof (struct GNUNET_MessageHeader); | 219 | return sizeof (struct GNUNET_MessageHeader); |
214 | } | 220 | } |
@@ -226,7 +232,7 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
226 | GNUNET_assert (NULL == nc->init); | 232 | GNUNET_assert (NULL == nc->init); |
227 | nc->init = | 233 | nc->init = |
228 | GNUNET_CLIENT_notify_transmit_ready (nc->client, | 234 | GNUNET_CLIENT_notify_transmit_ready (nc->client, |
229 | sizeof (struct GNUNET_MessageHeader), | 235 | sizeof (struct NotifyMessage), |
230 | GNUNET_TIME_UNIT_FOREVER_REL, | 236 | GNUNET_TIME_UNIT_FOREVER_REL, |
231 | GNUNET_YES, &transmit_notify_request, | 237 | GNUNET_YES, &transmit_notify_request, |
232 | nc); | 238 | nc); |
@@ -238,13 +244,19 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) | |||
238 | * changes. Initially calls the given function for all known | 244 | * changes. Initially calls the given function for all known |
239 | * peers and then only signals changes. | 245 | * peers and then only signals changes. |
240 | * | 246 | * |
247 | * If include_friend_only is set to GNUNET_YES peerinfo will include HELLO | ||
248 | * messages which are intended for friend to friend mode and which do not | ||
249 | * have to be gossiped. Otherwise these messages are skipped. | ||
250 | * | ||
241 | * @param cfg configuration to use | 251 | * @param cfg configuration to use |
252 | * @param include_friend_only include HELLO messages for friends only | ||
242 | * @param callback the method to call for each peer | 253 | * @param callback the method to call for each peer |
243 | * @param callback_cls closure for callback | 254 | * @param callback_cls closure for callback |
244 | * @return NULL on error | 255 | * @return NULL on error |
245 | */ | 256 | */ |
246 | struct GNUNET_PEERINFO_NotifyContext * | 257 | struct GNUNET_PEERINFO_NotifyContext * |
247 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, | 258 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, |
259 | int include_friend_only, | ||
248 | GNUNET_PEERINFO_Processor callback, void *callback_cls) | 260 | GNUNET_PEERINFO_Processor callback, void *callback_cls) |
249 | { | 261 | { |
250 | struct GNUNET_PEERINFO_NotifyContext *nc; | 262 | struct GNUNET_PEERINFO_NotifyContext *nc; |
@@ -262,6 +274,7 @@ GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
262 | nc->client = client; | 274 | nc->client = client; |
263 | nc->callback = callback; | 275 | nc->callback = callback; |
264 | nc->callback_cls = callback_cls; | 276 | nc->callback_cls = callback_cls; |
277 | nc->include_friend_only = include_friend_only; | ||
265 | request_notifications (nc); | 278 | request_notifications (nc); |
266 | return nc; | 279 | return nc; |
267 | } | 280 | } |
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 59ea0ac8a..d3dcc2fd0 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -120,7 +120,7 @@ process (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
120 | /* try again */ | 120 | /* try again */ |
121 | retries++; | 121 | retries++; |
122 | add_peer (); | 122 | add_peer (); |
123 | ic = GNUNET_PEERINFO_iterate (h, NULL, | 123 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, |
124 | GNUNET_TIME_relative_multiply | 124 | GNUNET_TIME_relative_multiply |
125 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, | 125 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, |
126 | cls); | 126 | cls); |
@@ -152,7 +152,7 @@ run (void *cls, | |||
152 | h = GNUNET_PEERINFO_connect (cfg); | 152 | h = GNUNET_PEERINFO_connect (cfg); |
153 | GNUNET_assert (NULL != h); | 153 | GNUNET_assert (NULL != h); |
154 | add_peer (); | 154 | add_peer (); |
155 | ic = GNUNET_PEERINFO_iterate (h, NULL, | 155 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, |
156 | GNUNET_TIME_relative_multiply | 156 | GNUNET_TIME_relative_multiply |
157 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); | 157 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); |
158 | } | 158 | } |