diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-08 13:06:54 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-08 13:06:54 +0000 |
commit | 967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f (patch) | |
tree | bf7a9af6761b62d3e8abfc95469d470547fb93cc /src/hostlist | |
parent | e8757f03baa17eddef096da91122a282a39e9cb7 (diff) | |
download | gnunet-967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f.tar.gz gnunet-967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f.zip |
hostlist client gets notified when hostlist advertisments arrive
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 60 | ||||
-rw-r--r-- | src/hostlist/hostlist-client.c | 33 | ||||
-rw-r--r-- | src/hostlist/hostlist-client.h | 4 |
3 files changed, 75 insertions, 22 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 9f3453890..2197a50b1 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -75,6 +75,12 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
75 | struct GNUNET_CORE_Handle *core; | 75 | struct GNUNET_CORE_Handle *core; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Handle to the hostlist client's advertisement handler | ||
79 | */ | ||
80 | GNUNET_CORE_MessageCallback client_adv_handler = NULL; | ||
81 | |||
82 | |||
83 | /** | ||
78 | * gnunet-daemon-hostlist command line options. | 84 | * gnunet-daemon-hostlist command line options. |
79 | */ | 85 | */ |
80 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 86 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
@@ -112,20 +118,41 @@ core_init (void *cls, | |||
112 | /** | 118 | /** |
113 | * Core handler for p2p hostlist advertisements | 119 | * Core handler for p2p hostlist advertisements |
114 | */ | 120 | */ |
115 | static int handle_hostlist_advertisement (void *cls, | 121 | static int advertisement_handler (void *cls, |
116 | const struct GNUNET_PeerIdentity * peer, | 122 | const struct GNUNET_PeerIdentity * peer, |
117 | const struct GNUNET_MessageHeader * message, | 123 | const struct GNUNET_MessageHeader * message, |
118 | struct GNUNET_TIME_Relative latency, | 124 | struct GNUNET_TIME_Relative latency, |
119 | uint32_t distance) | 125 | uint32_t distance) |
120 | { | 126 | { |
121 | #if DEBUG_HOSTLIST_LEARNING | 127 | if (advertising && (NULL != client_adv_handler)) |
122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | { |
123 | _("Recieved hostlist advertisement\n")); | 129 | (*client_adv_handler) (cls, peer, message, latency, distance); |
124 | #endif | 130 | return GNUNET_YES; |
131 | } | ||
132 | return GNUNET_NO; | ||
133 | } | ||
125 | 134 | ||
126 | return GNUNET_OK; | 135 | /** |
136 | * Method called whenever a given peer connects. | ||
137 | * | ||
138 | * @param cls closure | ||
139 | * @param peer peer identity this notification is about | ||
140 | * @param latency reported latency of the connection with 'other' | ||
141 | * @param distance reported distance (DV) to 'other' | ||
142 | */ | ||
143 | static void | ||
144 | connect_handler (void *cls, | ||
145 | const struct | ||
146 | GNUNET_PeerIdentity * peer, | ||
147 | struct GNUNET_TIME_Relative latency, | ||
148 | uint32_t distance) | ||
149 | { | ||
150 | /* call hostlist client connection handler*/ | ||
151 | |||
152 | /* do my own stuff */ | ||
127 | } | 153 | } |
128 | 154 | ||
155 | |||
129 | /** | 156 | /** |
130 | * Last task run during shutdown. Disconnects us from | 157 | * Last task run during shutdown. Disconnects us from |
131 | * the other services. | 158 | * the other services. |
@@ -161,7 +188,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
161 | * service. | 188 | * service. |
162 | */ | 189 | */ |
163 | static struct GNUNET_CORE_MessageHandler handlers[] = { | 190 | static struct GNUNET_CORE_MessageHandler handlers[] = { |
164 | { &handle_hostlist_advertisement, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, | 191 | { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, |
165 | { NULL, 0, 0 } | 192 | { NULL, 0, 0 } |
166 | }; | 193 | }; |
167 | 194 | ||
@@ -184,14 +211,6 @@ run (void *cls, | |||
184 | GNUNET_CORE_ConnectEventHandler ch = NULL; | 211 | GNUNET_CORE_ConnectEventHandler ch = NULL; |
185 | GNUNET_CORE_DisconnectEventHandler dh = NULL; | 212 | GNUNET_CORE_DisconnectEventHandler dh = NULL; |
186 | 213 | ||
187 | |||
188 | |||
189 | struct GNUNET_CORE_MessageHandler null_handler[] = { | ||
190 | { NULL, 0, 0 } | ||
191 | }; | ||
192 | |||
193 | struct GNUNET_CORE_MessageHandler *used_handler = null_handler; | ||
194 | |||
195 | if ( (! bootstrapping) && | 214 | if ( (! bootstrapping) && |
196 | (! learning) && | 215 | (! learning) && |
197 | (! provide_hostlist) ) | 216 | (! provide_hostlist) ) |
@@ -204,7 +223,7 @@ run (void *cls, | |||
204 | if (bootstrapping) | 223 | if (bootstrapping) |
205 | { | 224 | { |
206 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, | 225 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, |
207 | &ch, &dh); | 226 | &ch, &dh, &client_adv_handler); |
208 | } | 227 | } |
209 | if (provide_hostlist) | 228 | if (provide_hostlist) |
210 | { | 229 | { |
@@ -212,9 +231,14 @@ run (void *cls, | |||
212 | } | 231 | } |
213 | if (learning) | 232 | if (learning) |
214 | { | 233 | { |
215 | used_handler = handlers; | 234 | |
216 | } | 235 | } |
217 | 236 | ||
237 | |||
238 | struct GNUNET_TIME_Relative a; | ||
239 | advertisement_handler(NULL,NULL,NULL,a,6); | ||
240 | |||
241 | |||
218 | core = GNUNET_CORE_connect (sched, cfg, | 242 | core = GNUNET_CORE_connect (sched, cfg, |
219 | GNUNET_TIME_UNIT_FOREVER_REL, | 243 | GNUNET_TIME_UNIT_FOREVER_REL, |
220 | NULL, | 244 | NULL, |
@@ -222,7 +246,7 @@ run (void *cls, | |||
222 | NULL, ch, dh, | 246 | NULL, ch, dh, |
223 | NULL, GNUNET_NO, | 247 | NULL, GNUNET_NO, |
224 | NULL, GNUNET_NO, | 248 | NULL, GNUNET_NO, |
225 | used_handler); | 249 | handlers); |
226 | 250 | ||
227 | GNUNET_SCHEDULER_add_delayed (sched, | 251 | GNUNET_SCHEDULER_add_delayed (sched, |
228 | GNUNET_TIME_UNIT_FOREVER_REL, | 252 | GNUNET_TIME_UNIT_FOREVER_REL, |
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index 1c0deb511..3824972d8 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
33 | #include <curl/curl.h> | 33 | #include <curl/curl.h> |
34 | 34 | ||
35 | #define DEBUG_HOSTLIST_CLIENT GNUNET_NO | 35 | #define DEBUG_HOSTLIST_CLIENT GNUNET_YES |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Number of connections that we must have to NOT download | 38 | * Number of connections that we must have to NOT download |
@@ -695,7 +695,7 @@ connect_handler (void *cls, | |||
695 | 695 | ||
696 | 696 | ||
697 | /** | 697 | /** |
698 | * Method called whenever a given peer connects. | 698 | * Method called whenever a given peer disconnects. |
699 | * | 699 | * |
700 | * @param cls closure | 700 | * @param cls closure |
701 | * @param peer peer identity this notification is about | 701 | * @param peer peer identity this notification is about |
@@ -712,6 +712,31 @@ disconnect_handler (void *cls, | |||
712 | GNUNET_NO); | 712 | GNUNET_NO); |
713 | } | 713 | } |
714 | 714 | ||
715 | /** | ||
716 | * Method called whenever an advertisement message arrives. | ||
717 | * | ||
718 | * @param cls closure (always NULL) | ||
719 | * @param client identification of the client | ||
720 | * @param message the actual message | ||
721 | * @return GNUNET_OK to keep the connection open, | ||
722 | * GNUNET_SYSERR to close it (signal serious error) | ||
723 | */ | ||
724 | static int | ||
725 | advertisement_handler (void *cls, | ||
726 | const struct GNUNET_PeerIdentity * peer, | ||
727 | const struct GNUNET_MessageHeader * message, | ||
728 | struct GNUNET_TIME_Relative latency, | ||
729 | uint32_t distance) | ||
730 | { | ||
731 | #if DEBUG_HOSTLIST_CLIENT | ||
732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
733 | "Hostlist client recieved advertisement message\n"); | ||
734 | #endif | ||
735 | |||
736 | /* put code to use message here */ | ||
737 | |||
738 | return GNUNET_YES; | ||
739 | } | ||
715 | 740 | ||
716 | /** | 741 | /** |
717 | * Continuation called by the statistics code once | 742 | * Continuation called by the statistics code once |
@@ -757,7 +782,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
757 | struct GNUNET_SCHEDULER_Handle *s, | 782 | struct GNUNET_SCHEDULER_Handle *s, |
758 | struct GNUNET_STATISTICS_Handle *st, | 783 | struct GNUNET_STATISTICS_Handle *st, |
759 | GNUNET_CORE_ConnectEventHandler *ch, | 784 | GNUNET_CORE_ConnectEventHandler *ch, |
760 | GNUNET_CORE_DisconnectEventHandler *dh) | 785 | GNUNET_CORE_DisconnectEventHandler *dh, |
786 | GNUNET_CORE_MessageCallback *msgh) | ||
761 | { | 787 | { |
762 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 788 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
763 | { | 789 | { |
@@ -781,6 +807,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
781 | proxy = NULL; | 807 | proxy = NULL; |
782 | *ch = &connect_handler; | 808 | *ch = &connect_handler; |
783 | *dh = &disconnect_handler; | 809 | *dh = &disconnect_handler; |
810 | *msgh = &advertisement_handler; | ||
784 | GNUNET_STATISTICS_get (stats, | 811 | GNUNET_STATISTICS_get (stats, |
785 | "hostlist", | 812 | "hostlist", |
786 | gettext_noop("Minimum time between hostlist downloads"), | 813 | gettext_noop("Minimum time between hostlist downloads"), |
diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h index 888d2099a..378a91996 100644 --- a/src/hostlist/hostlist-client.h +++ b/src/hostlist/hostlist-client.h | |||
@@ -40,6 +40,7 @@ | |||
40 | * @param st hande for publishing statistics | 40 | * @param st hande for publishing statistics |
41 | * @param ch set to handler for connect notifications | 41 | * @param ch set to handler for connect notifications |
42 | * @param dh set to handler for disconnect notifications | 42 | * @param dh set to handler for disconnect notifications |
43 | * @param msgh set to handler for message handler notifications | ||
43 | * @return GNUNET_OK on success | 44 | * @return GNUNET_OK on success |
44 | */ | 45 | */ |
45 | int | 46 | int |
@@ -47,7 +48,8 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
47 | struct GNUNET_SCHEDULER_Handle *s, | 48 | struct GNUNET_SCHEDULER_Handle *s, |
48 | struct GNUNET_STATISTICS_Handle *st, | 49 | struct GNUNET_STATISTICS_Handle *st, |
49 | GNUNET_CORE_ConnectEventHandler *ch, | 50 | GNUNET_CORE_ConnectEventHandler *ch, |
50 | GNUNET_CORE_DisconnectEventHandler *dh); | 51 | GNUNET_CORE_DisconnectEventHandler *dh, |
52 | GNUNET_CORE_MessageCallback *msgh); | ||
51 | 53 | ||
52 | 54 | ||
53 | /** | 55 | /** |