diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/hostlist | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 177 | ||||
-rw-r--r-- | src/hostlist/hostlist-client.c | 1377 | ||||
-rw-r--r-- | src/hostlist/hostlist-client.h | 12 | ||||
-rw-r--r-- | src/hostlist/hostlist-server.c | 570 | ||||
-rw-r--r-- | src/hostlist/hostlist-server.h | 11 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist.c | 84 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_learning.c | 485 | ||||
-rw-r--r-- | src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | 96 |
8 files changed, 1335 insertions, 1477 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index f409dc9a6..c49aec765 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -129,12 +129,9 @@ static struct GNUNET_PeerIdentity me; | |||
129 | 129 | ||
130 | static void | 130 | static void |
131 | core_init (void *cls, | 131 | core_init (void *cls, |
132 | struct GNUNET_CORE_Handle * server, | 132 | struct GNUNET_CORE_Handle *server, |
133 | const struct GNUNET_PeerIdentity * | 133 | const struct GNUNET_PeerIdentity *my_identity, |
134 | my_identity, | 134 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
135 | const struct | ||
136 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * | ||
137 | publicKey) | ||
138 | { | 135 | { |
139 | me = *my_identity; | 136 | me = *my_identity; |
140 | } | 137 | } |
@@ -142,10 +139,11 @@ core_init (void *cls, | |||
142 | /** | 139 | /** |
143 | * Core handler for p2p hostlist advertisements | 140 | * Core handler for p2p hostlist advertisements |
144 | */ | 141 | */ |
145 | static int advertisement_handler (void *cls, | 142 | static int |
146 | const struct GNUNET_PeerIdentity * peer, | 143 | advertisement_handler (void *cls, |
147 | const struct GNUNET_MessageHeader * message, | 144 | const struct GNUNET_PeerIdentity *peer, |
148 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 145 | const struct GNUNET_MessageHeader *message, |
146 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
149 | { | 147 | { |
150 | GNUNET_assert (NULL != client_adv_handler); | 148 | GNUNET_assert (NULL != client_adv_handler); |
151 | return (*client_adv_handler) (cls, peer, message, atsi); | 149 | return (*client_adv_handler) (cls, peer, message, atsi); |
@@ -162,17 +160,17 @@ static int advertisement_handler (void *cls, | |||
162 | static void | 160 | static void |
163 | connect_handler (void *cls, | 161 | connect_handler (void *cls, |
164 | const struct | 162 | const struct |
165 | GNUNET_PeerIdentity * peer, | 163 | GNUNET_PeerIdentity *peer, |
166 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 164 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
167 | { | 165 | { |
168 | if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) | 166 | if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) |
169 | return; | 167 | return; |
170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
171 | "A new peer connected, notifying client and server\n"); | 169 | "A new peer connected, notifying client and server\n"); |
172 | if ( NULL != client_ch) | 170 | if (NULL != client_ch) |
173 | (*client_ch) (cls, peer, atsi); | 171 | (*client_ch) (cls, peer, atsi); |
174 | #if HAVE_MHD | 172 | #if HAVE_MHD |
175 | if ( NULL != server_ch) | 173 | if (NULL != server_ch) |
176 | (*server_ch) (cls, peer, atsi); | 174 | (*server_ch) (cls, peer, atsi); |
177 | #endif | 175 | #endif |
178 | } | 176 | } |
@@ -184,18 +182,16 @@ connect_handler (void *cls, | |||
184 | * @param peer peer identity this notification is about | 182 | * @param peer peer identity this notification is about |
185 | */ | 183 | */ |
186 | static void | 184 | static void |
187 | disconnect_handler (void *cls, | 185 | disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) |
188 | const struct | ||
189 | GNUNET_PeerIdentity * peer) | ||
190 | { | 186 | { |
191 | if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) | 187 | if (0 == memcmp (&me, peer, sizeof (struct GNUNET_PeerIdentity))) |
192 | return; | 188 | return; |
193 | /* call hostlist client disconnect handler*/ | 189 | /* call hostlist client disconnect handler */ |
194 | if ( NULL != client_dh) | 190 | if (NULL != client_dh) |
195 | (*client_dh) (cls, peer); | 191 | (*client_dh) (cls, peer); |
196 | #if HAVE_MHD | 192 | #if HAVE_MHD |
197 | /* call hostlist server disconnect handler*/ | 193 | /* call hostlist server disconnect handler */ |
198 | if ( NULL != server_dh) | 194 | if (NULL != server_dh) |
199 | (*server_dh) (cls, peer); | 195 | (*server_dh) (cls, peer); |
200 | #endif | 196 | #endif |
201 | } | 197 | } |
@@ -207,29 +203,27 @@ disconnect_handler (void *cls, | |||
207 | static void | 203 | static void |
208 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 204 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
209 | { | 205 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist daemon is shutting down\n"); |
211 | "Hostlist daemon is shutting down\n"); | ||
212 | if (core != NULL) | 207 | if (core != NULL) |
213 | { | 208 | { |
214 | GNUNET_CORE_disconnect (core); | 209 | GNUNET_CORE_disconnect (core); |
215 | core = NULL; | 210 | core = NULL; |
216 | } | 211 | } |
217 | if (bootstrapping) | 212 | if (bootstrapping) |
218 | { | 213 | { |
219 | GNUNET_HOSTLIST_client_stop (); | 214 | GNUNET_HOSTLIST_client_stop (); |
220 | } | 215 | } |
221 | #if HAVE_MHD | 216 | #if HAVE_MHD |
222 | if (provide_hostlist) | 217 | if (provide_hostlist) |
223 | { | 218 | { |
224 | GNUNET_HOSTLIST_server_stop (); | 219 | GNUNET_HOSTLIST_server_stop (); |
225 | } | 220 | } |
226 | #endif | 221 | #endif |
227 | if (stats != NULL) | 222 | if (stats != NULL) |
228 | { | 223 | { |
229 | GNUNET_STATISTICS_destroy (stats, | 224 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
230 | GNUNET_NO); | 225 | stats = NULL; |
231 | stats = NULL; | 226 | } |
232 | } | ||
233 | } | 227 | } |
234 | 228 | ||
235 | 229 | ||
@@ -241,67 +235,67 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
241 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | 235 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) |
242 | * @param cfg configuration | 236 | * @param cfg configuration |
243 | */ | 237 | */ |
244 | static void | 238 | static void |
245 | run (void *cls, | 239 | run (void *cls, |
246 | char *const *args, | 240 | char *const *args, |
247 | const char *cfgfile, | 241 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
248 | const struct GNUNET_CONFIGURATION_Handle * cfg) | ||
249 | { | 242 | { |
250 | static const struct GNUNET_CORE_MessageHandler learn_handlers[] = { | 243 | static const struct GNUNET_CORE_MessageHandler learn_handlers[] = { |
251 | { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, | 244 | {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, |
252 | { NULL, 0, 0 } | 245 | {NULL, 0, 0} |
253 | }; | 246 | }; |
254 | static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = { | 247 | static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = { |
255 | { NULL, 0, 0 } | 248 | {NULL, 0, 0} |
256 | }; | 249 | }; |
257 | if ( (! bootstrapping) && | 250 | if ((!bootstrapping) && (!learning) |
258 | (! learning) | ||
259 | #if HAVE_MHD | 251 | #if HAVE_MHD |
260 | && (! provide_hostlist) | 252 | && (!provide_hostlist) |
261 | #endif | 253 | #endif |
262 | ) | 254 | ) |
263 | { | 255 | { |
264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 256 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
265 | _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); | 257 | _ |
266 | return; | 258 | ("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); |
267 | } | 259 | return; |
260 | } | ||
268 | 261 | ||
269 | 262 | ||
270 | 263 | ||
271 | stats = GNUNET_STATISTICS_create ("hostlist", cfg); | 264 | stats = GNUNET_STATISTICS_create ("hostlist", cfg); |
272 | 265 | ||
273 | core = GNUNET_CORE_connect (cfg, | 266 | core = GNUNET_CORE_connect (cfg, |
274 | 1, | 267 | 1, |
275 | NULL, | 268 | NULL, |
276 | &core_init, | 269 | &core_init, |
277 | &connect_handler, &disconnect_handler, NULL, | 270 | &connect_handler, &disconnect_handler, NULL, |
278 | NULL, GNUNET_NO, | 271 | NULL, GNUNET_NO, |
279 | NULL, GNUNET_NO, | 272 | NULL, GNUNET_NO, |
280 | learning? learn_handlers : no_learn_handlers); | 273 | learning ? learn_handlers : no_learn_handlers); |
281 | 274 | ||
282 | if (bootstrapping) | 275 | if (bootstrapping) |
283 | { | 276 | { |
284 | GNUNET_HOSTLIST_client_start (cfg, stats, | 277 | GNUNET_HOSTLIST_client_start (cfg, stats, |
285 | &client_ch, &client_dh, &client_adv_handler, learning); | 278 | &client_ch, &client_dh, &client_adv_handler, |
286 | } | 279 | learning); |
280 | } | ||
287 | 281 | ||
288 | #if HAVE_MHD | 282 | #if HAVE_MHD |
289 | if (provide_hostlist) | 283 | if (provide_hostlist) |
290 | { | 284 | { |
291 | GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh, advertising ); | 285 | GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh, |
292 | } | 286 | advertising); |
287 | } | ||
293 | #endif | 288 | #endif |
294 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 289 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
295 | &cleaning_task, NULL); | 290 | &cleaning_task, NULL); |
296 | 291 | ||
297 | if (NULL == core) | 292 | if (NULL == core) |
298 | { | 293 | { |
299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
300 | _("Failed to connect to `%s' service.\n"), | 295 | _("Failed to connect to `%s' service.\n"), "core"); |
301 | "core"); | 296 | GNUNET_SCHEDULER_shutdown (); |
302 | GNUNET_SCHEDULER_shutdown (); | 297 | return; |
303 | return; | 298 | } |
304 | } | ||
305 | } | 299 | } |
306 | 300 | ||
307 | 301 | ||
@@ -317,33 +311,34 @@ main (int argc, char *const *argv) | |||
317 | { | 311 | { |
318 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 312 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
319 | #if HAVE_MHD | 313 | #if HAVE_MHD |
320 | { 'a', "advertise", NULL, | 314 | {'a', "advertise", NULL, |
321 | gettext_noop ("advertise our hostlist to other peers"), | 315 | gettext_noop ("advertise our hostlist to other peers"), |
322 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising }, | 316 | GNUNET_NO, &GNUNET_GETOPT_set_one, &advertising}, |
323 | #endif | 317 | #endif |
324 | { 'b', "bootstrap", NULL, | 318 | {'b', "bootstrap", NULL, |
325 | gettext_noop ("bootstrap using hostlists (it is highly recommended that you always use this option)"), | 319 | gettext_noop |
326 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping }, | 320 | ("bootstrap using hostlists (it is highly recommended that you always use this option)"), |
327 | { 'e', "enable-learning", NULL, | 321 | GNUNET_NO, &GNUNET_GETOPT_set_one, &bootstrapping}, |
328 | gettext_noop ("enable learning about hostlist servers from other peers"), | 322 | {'e', "enable-learning", NULL, |
329 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, | 323 | gettext_noop ("enable learning about hostlist servers from other peers"), |
324 | GNUNET_NO, &GNUNET_GETOPT_set_one, &learning}, | ||
330 | #if HAVE_MHD | 325 | #if HAVE_MHD |
331 | { 'p', "provide-hostlist", NULL, | 326 | {'p', "provide-hostlist", NULL, |
332 | gettext_noop ("provide a hostlist server"), | 327 | gettext_noop ("provide a hostlist server"), |
333 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, | 328 | GNUNET_NO, &GNUNET_GETOPT_set_one, &provide_hostlist}, |
334 | #endif | 329 | #endif |
335 | GNUNET_GETOPT_OPTION_END | 330 | GNUNET_GETOPT_OPTION_END |
336 | }; | 331 | }; |
337 | 332 | ||
338 | int ret; | 333 | int ret; |
334 | |||
339 | GNUNET_log_setup ("hostlist", "WARNING", NULL); | 335 | GNUNET_log_setup ("hostlist", "WARNING", NULL); |
340 | ret = (GNUNET_OK == | 336 | ret = (GNUNET_OK == |
341 | GNUNET_PROGRAM_run (argc, | 337 | GNUNET_PROGRAM_run (argc, |
342 | argv, | 338 | argv, |
343 | "hostlist", | 339 | "hostlist", |
344 | _("GNUnet hostlist server and client"), | 340 | _("GNUnet hostlist server and client"), |
345 | options, | 341 | options, &run, NULL)) ? 0 : 1; |
346 | &run, NULL)) ? 0 : 1; | ||
347 | 342 | ||
348 | return ret; | 343 | return ret; |
349 | } | 344 | } |
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index f104e79d4..422855f0e 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c | |||
@@ -58,12 +58,12 @@ struct Hostlist | |||
58 | /** | 58 | /** |
59 | * previous entry, used to manage entries in a double linked list | 59 | * previous entry, used to manage entries in a double linked list |
60 | */ | 60 | */ |
61 | struct Hostlist * prev; | 61 | struct Hostlist *prev; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * next entry, used to manage entries in a double linked list | 64 | * next entry, used to manage entries in a double linked list |
65 | */ | 65 | */ |
66 | struct Hostlist * next; | 66 | struct Hostlist *next; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * URI where hostlist can be obtained | 69 | * URI where hostlist can be obtained |
@@ -111,13 +111,13 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
111 | /** | 111 | /** |
112 | * Statistics handle. | 112 | * Statistics handle. |
113 | */ | 113 | */ |
114 | static struct GNUNET_STATISTICS_Handle *stats; | 114 | static struct GNUNET_STATISTICS_Handle *stats; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Transport handle. | 117 | * Transport handle. |
118 | */ | 118 | */ |
119 | static struct GNUNET_TRANSPORT_Handle *transport; | 119 | static struct GNUNET_TRANSPORT_Handle *transport; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Proxy that we are using (can be NULL). | 122 | * Proxy that we are using (can be NULL). |
123 | */ | 123 | */ |
@@ -186,17 +186,17 @@ static struct GNUNET_TIME_Absolute end_time; | |||
186 | /** | 186 | /** |
187 | * Head of the linked list used to store hostlists | 187 | * Head of the linked list used to store hostlists |
188 | */ | 188 | */ |
189 | static struct Hostlist * linked_list_head; | 189 | static struct Hostlist *linked_list_head; |
190 | 190 | ||
191 | /** | 191 | /** |
192 | * Tail of the linked list used to store hostlists | 192 | * Tail of the linked list used to store hostlists |
193 | */ | 193 | */ |
194 | static struct Hostlist * linked_list_tail; | 194 | static struct Hostlist *linked_list_tail; |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * Current hostlist used for downloading | 197 | * Current hostlist used for downloading |
198 | */ | 198 | */ |
199 | static struct Hostlist * current_hostlist; | 199 | static struct Hostlist *current_hostlist; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Size of the linke list used to store hostlists | 202 | * Size of the linke list used to store hostlists |
@@ -206,7 +206,7 @@ static unsigned int linked_list_size; | |||
206 | /** | 206 | /** |
207 | * Head of the linked list used to store hostlists | 207 | * Head of the linked list used to store hostlists |
208 | */ | 208 | */ |
209 | static struct Hostlist * hostlist_to_test; | 209 | static struct Hostlist *hostlist_to_test; |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Set to GNUNET_YES if the current URL had some problems. | 212 | * Set to GNUNET_YES if the current URL had some problems. |
@@ -232,6 +232,7 @@ static int stat_download_in_progress; | |||
232 | * Value saying if a preconfigured bootstrap server is used | 232 | * Value saying if a preconfigured bootstrap server is used |
233 | */ | 233 | */ |
234 | static unsigned int stat_use_bootstrap; | 234 | static unsigned int stat_use_bootstrap; |
235 | |||
235 | /** | 236 | /** |
236 | * Set if we are allowed to learn new hostlists and use them | 237 | * Set if we are allowed to learn new hostlists and use them |
237 | */ | 238 | */ |
@@ -263,13 +264,10 @@ static unsigned int stat_connection_count; | |||
263 | * @return number of bytes that were processed (always size*nmemb) | 264 | * @return number of bytes that were processed (always size*nmemb) |
264 | */ | 265 | */ |
265 | static size_t | 266 | static size_t |
266 | callback_download (void *ptr, | 267 | callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) |
267 | size_t size, | ||
268 | size_t nmemb, | ||
269 | void *ctx) | ||
270 | { | 268 | { |
271 | static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 269 | static char download_buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
272 | const char * cbuf = ptr; | 270 | const char *cbuf = ptr; |
273 | const struct GNUNET_MessageHeader *msg; | 271 | const struct GNUNET_MessageHeader *msg; |
274 | size_t total; | 272 | size_t total; |
275 | size_t cpy; | 273 | size_t cpy; |
@@ -278,85 +276,78 @@ callback_download (void *ptr, | |||
278 | 276 | ||
279 | total = size * nmemb; | 277 | total = size * nmemb; |
280 | stat_bytes_downloaded += total; | 278 | stat_bytes_downloaded += total; |
281 | if ( (total == 0) || (stat_bogus_url) ) | 279 | if ((total == 0) || (stat_bogus_url)) |
282 | { | 280 | { |
283 | return total; /* ok, no data or bogus data */ | 281 | return total; /* ok, no data or bogus data */ |
284 | } | 282 | } |
285 | 283 | ||
286 | GNUNET_STATISTICS_update (stats, | 284 | GNUNET_STATISTICS_update (stats, |
287 | gettext_noop ("# bytes downloaded from hostlist servers"), | 285 | gettext_noop |
288 | (int64_t) total, | 286 | ("# bytes downloaded from hostlist servers"), |
289 | GNUNET_NO); | 287 | (int64_t) total, GNUNET_NO); |
290 | left = total; | 288 | left = total; |
291 | while ( (left > 0) || | 289 | while ((left > 0) || (download_pos > 0)) |
292 | (download_pos > 0) ) | 290 | { |
291 | cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
292 | memcpy (&download_buffer[download_pos], cbuf, cpy); | ||
293 | cbuf += cpy; | ||
294 | download_pos += cpy; | ||
295 | left -= cpy; | ||
296 | if (download_pos < sizeof (struct GNUNET_MessageHeader)) | ||
297 | { | ||
298 | GNUNET_assert (left == 0); | ||
299 | break; | ||
300 | } | ||
301 | msg = (const struct GNUNET_MessageHeader *) download_buffer; | ||
302 | msize = ntohs (msg->size); | ||
303 | if (msize < sizeof (struct GNUNET_MessageHeader)) | ||
304 | { | ||
305 | GNUNET_STATISTICS_update (stats, | ||
306 | gettext_noop | ||
307 | ("# invalid HELLOs downloaded from hostlist servers"), | ||
308 | 1, GNUNET_NO); | ||
309 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
310 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
311 | "HELLO", current_url); | ||
312 | stat_hellos_obtained++; | ||
313 | stat_bogus_url = 1; | ||
314 | return total; | ||
315 | } | ||
316 | if (download_pos < msize) | ||
317 | { | ||
318 | GNUNET_assert (left == 0); | ||
319 | break; | ||
320 | } | ||
321 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) msg) == msize) | ||
293 | { | 322 | { |
294 | cpy = GNUNET_MIN (left, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - download_pos); | ||
295 | memcpy (&download_buffer[download_pos], | ||
296 | cbuf, | ||
297 | cpy); | ||
298 | cbuf += cpy; | ||
299 | download_pos += cpy; | ||
300 | left -= cpy; | ||
301 | if (download_pos < sizeof(struct GNUNET_MessageHeader)) | ||
302 | { | ||
303 | GNUNET_assert (left == 0); | ||
304 | break; | ||
305 | } | ||
306 | msg = (const struct GNUNET_MessageHeader *) download_buffer; | ||
307 | msize = ntohs(msg->size); | ||
308 | if (msize < sizeof(struct GNUNET_MessageHeader)) | ||
309 | { | ||
310 | GNUNET_STATISTICS_update (stats, | ||
311 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
312 | 1, | ||
313 | GNUNET_NO); | ||
314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
315 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
316 | "HELLO", | ||
317 | current_url); | ||
318 | stat_hellos_obtained++; | ||
319 | stat_bogus_url = 1; | ||
320 | return total; | ||
321 | } | ||
322 | if (download_pos < msize) | ||
323 | { | ||
324 | GNUNET_assert (left == 0); | ||
325 | break; | ||
326 | } | ||
327 | if (GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message*)msg) == msize) | ||
328 | { | ||
329 | #if DEBUG_HOSTLIST_CLIENT | 323 | #if DEBUG_HOSTLIST_CLIENT |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
331 | "Received valid `%s' message from hostlist server.\n", | 325 | "Received valid `%s' message from hostlist server.\n", |
332 | "HELLO"); | 326 | "HELLO"); |
333 | #endif | 327 | #endif |
334 | GNUNET_STATISTICS_update (stats, | 328 | GNUNET_STATISTICS_update (stats, |
335 | gettext_noop ("# valid HELLOs downloaded from hostlist servers"), | 329 | gettext_noop |
336 | 1, | 330 | ("# valid HELLOs downloaded from hostlist servers"), |
337 | GNUNET_NO); | 331 | 1, GNUNET_NO); |
338 | stat_hellos_obtained++; | 332 | stat_hellos_obtained++; |
339 | GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL); | 333 | GNUNET_TRANSPORT_offer_hello (transport, msg, NULL, NULL); |
340 | } | ||
341 | else | ||
342 | { | ||
343 | GNUNET_STATISTICS_update (stats, | ||
344 | gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), | ||
345 | 1, | ||
346 | GNUNET_NO); | ||
347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
348 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
349 | "HELLO", | ||
350 | current_url); | ||
351 | stat_bogus_url = GNUNET_YES; | ||
352 | stat_hellos_obtained++; | ||
353 | return total; | ||
354 | } | ||
355 | memmove (download_buffer, | ||
356 | &download_buffer[msize], | ||
357 | download_pos - msize); | ||
358 | download_pos -= msize; | ||
359 | } | 334 | } |
335 | else | ||
336 | { | ||
337 | GNUNET_STATISTICS_update (stats, | ||
338 | gettext_noop | ||
339 | ("# invalid HELLOs downloaded from hostlist servers"), | ||
340 | 1, GNUNET_NO); | ||
341 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
342 | _("Invalid `%s' message received from hostlist at `%s'\n"), | ||
343 | "HELLO", current_url); | ||
344 | stat_bogus_url = GNUNET_YES; | ||
345 | stat_hellos_obtained++; | ||
346 | return total; | ||
347 | } | ||
348 | memmove (download_buffer, &download_buffer[msize], download_pos - msize); | ||
349 | download_pos -= msize; | ||
350 | } | ||
360 | return total; | 351 | return total; |
361 | } | 352 | } |
362 | 353 | ||
@@ -374,55 +365,55 @@ get_bootstrap_server () | |||
374 | size_t urls; | 365 | size_t urls; |
375 | size_t pos; | 366 | size_t pos; |
376 | 367 | ||
377 | if (GNUNET_OK != | 368 | if (GNUNET_OK != |
378 | GNUNET_CONFIGURATION_get_value_string (cfg, | 369 | GNUNET_CONFIGURATION_get_value_string (cfg, |
379 | "HOSTLIST", | 370 | "HOSTLIST", "SERVERS", &servers)) |
380 | "SERVERS", | 371 | { |
381 | &servers)) | 372 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
382 | { | 373 | _ |
383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 374 | ("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
384 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 375 | "SERVERS", "HOSTLIST"); |
385 | "SERVERS", "HOSTLIST"); | 376 | return NULL; |
386 | return NULL; | 377 | } |
387 | } | ||
388 | 378 | ||
389 | urls = 0; | 379 | urls = 0; |
390 | if (strlen (servers) > 0) | 380 | if (strlen (servers) > 0) |
381 | { | ||
382 | urls++; | ||
383 | pos = strlen (servers) - 1; | ||
384 | while (pos > 0) | ||
391 | { | 385 | { |
392 | urls++; | 386 | if (servers[pos] == ' ') |
393 | pos = strlen (servers) - 1; | 387 | urls++; |
394 | while (pos > 0) | 388 | pos--; |
395 | { | ||
396 | if (servers[pos] == ' ') | ||
397 | urls++; | ||
398 | pos--; | ||
399 | } | ||
400 | } | 389 | } |
390 | } | ||
401 | if (urls == 0) | 391 | if (urls == 0) |
402 | { | 392 | { |
403 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
404 | _("No `%s' specified in `%s' configuration, will not bootstrap.\n"), | 394 | _ |
405 | "SERVERS", "HOSTLIST"); | 395 | ("No `%s' specified in `%s' configuration, will not bootstrap.\n"), |
406 | GNUNET_free (servers); | 396 | "SERVERS", "HOSTLIST"); |
407 | return NULL; | 397 | GNUNET_free (servers); |
408 | } | 398 | return NULL; |
399 | } | ||
409 | 400 | ||
410 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; | 401 | urls = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, urls) + 1; |
411 | pos = strlen (servers) - 1; | 402 | pos = strlen (servers) - 1; |
412 | while (pos > 0) | 403 | while (pos > 0) |
404 | { | ||
405 | if (servers[pos] == ' ') | ||
413 | { | 406 | { |
414 | if (servers[pos] == ' ') | 407 | urls--; |
415 | { | 408 | servers[pos] = '\0'; |
416 | urls--; | ||
417 | servers[pos] = '\0'; | ||
418 | } | ||
419 | if (urls == 0) | ||
420 | { | ||
421 | pos++; | ||
422 | break; | ||
423 | } | ||
424 | pos--; | ||
425 | } | 409 | } |
410 | if (urls == 0) | ||
411 | { | ||
412 | pos++; | ||
413 | break; | ||
414 | } | ||
415 | pos--; | ||
416 | } | ||
426 | ret = GNUNET_strdup (&servers[pos]); | 417 | ret = GNUNET_strdup (&servers[pos]); |
427 | GNUNET_free (servers); | 418 | GNUNET_free (servers); |
428 | return ret; | 419 | return ret; |
@@ -437,45 +428,44 @@ download_get_url () | |||
437 | { | 428 | { |
438 | uint32_t index; | 429 | uint32_t index; |
439 | unsigned int counter; | 430 | unsigned int counter; |
440 | struct Hostlist * pos; | 431 | struct Hostlist *pos; |
441 | 432 | ||
442 | if ( GNUNET_NO == stat_learning) | 433 | if (GNUNET_NO == stat_learning) |
443 | { | 434 | { |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
445 | "Using preconfigured bootstrap server\n"); | 436 | "Using preconfigured bootstrap server\n"); |
446 | current_hostlist = NULL; | 437 | current_hostlist = NULL; |
447 | return get_bootstrap_server(); | 438 | return get_bootstrap_server (); |
448 | } | 439 | } |
449 | 440 | ||
450 | if ( ( GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test) ) | 441 | if ((GNUNET_YES == stat_testing_hostlist) && (NULL != hostlist_to_test)) |
451 | { | 442 | { |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
453 | "Testing new advertised hostlist if it is obtainable\n"); | 444 | "Testing new advertised hostlist if it is obtainable\n"); |
454 | current_hostlist = hostlist_to_test; | 445 | current_hostlist = hostlist_to_test; |
455 | return strdup(hostlist_to_test->hostlist_uri); | 446 | return strdup (hostlist_to_test->hostlist_uri); |
456 | } | 447 | } |
457 | 448 | ||
458 | if ( (GNUNET_YES == stat_use_bootstrap) || | 449 | if ((GNUNET_YES == stat_use_bootstrap) || (linked_list_size == 0)) |
459 | (linked_list_size == 0) ) | ||
460 | { | 450 | { |
461 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
462 | "Using preconfigured bootstrap server\n"); | 452 | "Using preconfigured bootstrap server\n"); |
463 | current_hostlist = NULL; | 453 | current_hostlist = NULL; |
464 | return get_bootstrap_server(); | 454 | return get_bootstrap_server (); |
465 | } | 455 | } |
466 | index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 456 | index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
467 | linked_list_size); | 457 | linked_list_size); |
468 | counter = 0; | 458 | counter = 0; |
469 | pos = linked_list_head; | 459 | pos = linked_list_head; |
470 | while ( counter < index ) | 460 | while (counter < index) |
471 | { | 461 | { |
472 | pos = pos->next; | 462 | pos = pos->next; |
473 | counter ++; | 463 | counter++; |
474 | } | 464 | } |
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
476 | "Using learned hostlist `%s'\n", pos->hostlist_uri); | 466 | "Using learned hostlist `%s'\n", pos->hostlist_uri); |
477 | current_hostlist = pos; | 467 | current_hostlist = pos; |
478 | return strdup(pos->hostlist_uri); | 468 | return strdup (pos->hostlist_uri); |
479 | } | 469 | } |
480 | 470 | ||
481 | 471 | ||
@@ -486,7 +476,7 @@ download_get_url () | |||
486 | * Method to save hostlist to a file during hostlist client shutdown | 476 | * Method to save hostlist to a file during hostlist client shutdown |
487 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 477 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
488 | */ | 478 | */ |
489 | static void save_hostlist_file ( int shutdown ); | 479 | static void save_hostlist_file (int shutdown); |
490 | 480 | ||
491 | 481 | ||
492 | /** | 482 | /** |
@@ -495,7 +485,8 @@ static void save_hostlist_file ( int shutdown ); | |||
495 | * @param val2 value 2 | 485 | * @param val2 value 2 |
496 | * @return result | 486 | * @return result |
497 | */ | 487 | */ |
498 | static uint64_t checked_add (uint64_t val1, uint64_t val2) | 488 | static uint64_t |
489 | checked_add (uint64_t val1, uint64_t val2) | ||
499 | { | 490 | { |
500 | static uint64_t temp; | 491 | static uint64_t temp; |
501 | static uint64_t maxv; | 492 | static uint64_t maxv; |
@@ -503,8 +494,8 @@ static uint64_t checked_add (uint64_t val1, uint64_t val2) | |||
503 | maxv = 0; | 494 | maxv = 0; |
504 | maxv--; | 495 | maxv--; |
505 | 496 | ||
506 | temp = val1+val2; | 497 | temp = val1 + val2; |
507 | if ( temp < val1) | 498 | if (temp < val1) |
508 | return maxv; | 499 | return maxv; |
509 | else | 500 | else |
510 | return temp; | 501 | return temp; |
@@ -516,14 +507,13 @@ static uint64_t checked_add (uint64_t val1, uint64_t val2) | |||
516 | * @param val2 value 2 | 507 | * @param val2 value 2 |
517 | * @return result | 508 | * @return result |
518 | */ | 509 | */ |
519 | static uint64_t | 510 | static uint64_t |
520 | checked_sub (uint64_t val1, | 511 | checked_sub (uint64_t val1, uint64_t val2) |
521 | uint64_t val2) | ||
522 | { | 512 | { |
523 | if ( val1 <= val2) | 513 | if (val1 <= val2) |
524 | return 0; | 514 | return 0; |
525 | else | 515 | else |
526 | return (val1-val2); | 516 | return (val1 - val2); |
527 | } | 517 | } |
528 | 518 | ||
529 | /** | 519 | /** |
@@ -532,17 +522,17 @@ checked_sub (uint64_t val1, | |||
532 | * @return GNUNET_YES if existing in linked list, GNUNET_NO if not | 522 | * @return GNUNET_YES if existing in linked list, GNUNET_NO if not |
533 | */ | 523 | */ |
534 | static int | 524 | static int |
535 | linked_list_contains (const char * uri) | 525 | linked_list_contains (const char *uri) |
536 | { | 526 | { |
537 | struct Hostlist * pos; | 527 | struct Hostlist *pos; |
538 | 528 | ||
539 | pos = linked_list_head; | 529 | pos = linked_list_head; |
540 | while (pos != NULL) | 530 | while (pos != NULL) |
541 | { | 531 | { |
542 | if (0 == strcmp(pos->hostlist_uri, uri) ) | 532 | if (0 == strcmp (pos->hostlist_uri, uri)) |
543 | return GNUNET_YES; | 533 | return GNUNET_YES; |
544 | pos = pos->next; | 534 | pos = pos->next; |
545 | } | 535 | } |
546 | return GNUNET_NO; | 536 | return GNUNET_NO; |
547 | } | 537 | } |
548 | 538 | ||
@@ -552,21 +542,21 @@ linked_list_contains (const char * uri) | |||
552 | * @return hostlist with lowest quality | 542 | * @return hostlist with lowest quality |
553 | */ | 543 | */ |
554 | static struct Hostlist * | 544 | static struct Hostlist * |
555 | linked_list_get_lowest_quality ( ) | 545 | linked_list_get_lowest_quality () |
556 | { | 546 | { |
557 | struct Hostlist * pos; | 547 | struct Hostlist *pos; |
558 | struct Hostlist * lowest; | 548 | struct Hostlist *lowest; |
559 | 549 | ||
560 | if (linked_list_size == 0) | 550 | if (linked_list_size == 0) |
561 | return NULL; | 551 | return NULL; |
562 | lowest = linked_list_head; | 552 | lowest = linked_list_head; |
563 | pos = linked_list_head->next; | 553 | pos = linked_list_head->next; |
564 | while (pos != NULL) | 554 | while (pos != NULL) |
565 | { | 555 | { |
566 | if (pos->quality < lowest->quality) | 556 | if (pos->quality < lowest->quality) |
567 | lowest = pos; | 557 | lowest = pos; |
568 | pos = pos->next; | 558 | pos = pos->next; |
569 | } | 559 | } |
570 | return lowest; | 560 | return lowest; |
571 | } | 561 | } |
572 | 562 | ||
@@ -579,29 +569,28 @@ linked_list_get_lowest_quality ( ) | |||
579 | static void | 569 | static void |
580 | insert_hostlist () | 570 | insert_hostlist () |
581 | { | 571 | { |
582 | struct Hostlist * lowest_quality; | 572 | struct Hostlist *lowest_quality; |
583 | 573 | ||
584 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) | 574 | if (MAX_NUMBER_HOSTLISTS <= linked_list_size) |
585 | { | 575 | { |
586 | /* No free entries available, replace existing entry */ | 576 | /* No free entries available, replace existing entry */ |
587 | lowest_quality = linked_list_get_lowest_quality(); | 577 | lowest_quality = linked_list_get_lowest_quality (); |
588 | GNUNET_assert (lowest_quality != NULL); | 578 | GNUNET_assert (lowest_quality != NULL); |
589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
590 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", | 580 | "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", |
591 | lowest_quality->hostlist_uri, | 581 | lowest_quality->hostlist_uri, |
592 | (unsigned long long) lowest_quality->quality); | 582 | (unsigned long long) lowest_quality->quality); |
593 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, lowest_quality); | 583 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, |
594 | linked_list_size--; | 584 | lowest_quality); |
595 | GNUNET_free (lowest_quality); | 585 | linked_list_size--; |
596 | } | 586 | GNUNET_free (lowest_quality); |
597 | GNUNET_CONTAINER_DLL_insert(linked_list_head, | 587 | } |
598 | linked_list_tail, | 588 | GNUNET_CONTAINER_DLL_insert (linked_list_head, |
599 | hostlist_to_test); | 589 | linked_list_tail, hostlist_to_test); |
600 | linked_list_size++; | 590 | linked_list_size++; |
601 | GNUNET_STATISTICS_set (stats, | 591 | GNUNET_STATISTICS_set (stats, |
602 | gettext_noop("# advertised hostlist URIs"), | 592 | gettext_noop ("# advertised hostlist URIs"), |
603 | linked_list_size, | 593 | linked_list_size, GNUNET_NO); |
604 | GNUNET_NO); | ||
605 | stat_testing_hostlist = GNUNET_NO; | 594 | stat_testing_hostlist = GNUNET_NO; |
606 | } | 595 | } |
607 | 596 | ||
@@ -609,33 +598,36 @@ insert_hostlist () | |||
609 | /** | 598 | /** |
610 | * Method updating hostlist statistics | 599 | * Method updating hostlist statistics |
611 | */ | 600 | */ |
612 | static void update_hostlist ( ) | 601 | static void |
602 | update_hostlist () | ||
613 | { | 603 | { |
614 | char *stat; | 604 | char *stat; |
615 | if ( ((stat_use_bootstrap == GNUNET_NO) && ( NULL != current_hostlist )) || | 605 | |
616 | ((stat_testing_hostlist == GNUNET_YES) && ( NULL != current_hostlist )) ) | 606 | if (((stat_use_bootstrap == GNUNET_NO) && (NULL != current_hostlist)) || |
607 | ((stat_testing_hostlist == GNUNET_YES) && (NULL != current_hostlist))) | ||
617 | { | 608 | { |
618 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 609 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
619 | "Updating hostlist statics for URI `%s'\n",current_hostlist->hostlist_uri ); | 610 | "Updating hostlist statics for URI `%s'\n", |
620 | current_hostlist->hello_count = stat_hellos_obtained; | 611 | current_hostlist->hostlist_uri); |
621 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get(); | 612 | current_hostlist->hello_count = stat_hellos_obtained; |
622 | current_hostlist->quality = checked_add ( current_hostlist->quality, (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); | 613 | current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); |
623 | if ( GNUNET_YES == stat_download_successful ) | 614 | current_hostlist->quality = |
624 | { | 615 | checked_add (current_hostlist->quality, |
625 | current_hostlist->times_used++; | 616 | (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); |
626 | current_hostlist->quality = checked_add ( current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | 617 | if (GNUNET_YES == stat_download_successful) |
627 | GNUNET_asprintf (&stat, | 618 | { |
628 | gettext_noop("# advertised URI `%s' downloaded"), | 619 | current_hostlist->times_used++; |
629 | current_hostlist->hostlist_uri); | 620 | current_hostlist->quality = |
630 | 621 | checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); | |
631 | GNUNET_STATISTICS_update ( stats, | 622 | GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), |
632 | stat, | 623 | current_hostlist->hostlist_uri); |
633 | 1, | 624 | |
634 | GNUNET_YES); | 625 | GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); |
635 | GNUNET_free (stat); | 626 | GNUNET_free (stat); |
636 | } | 627 | } |
637 | else | 628 | else |
638 | current_hostlist->quality = checked_sub ( current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD ); | 629 | current_hostlist->quality = |
630 | checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); | ||
639 | } | 631 | } |
640 | current_hostlist = NULL; | 632 | current_hostlist = NULL; |
641 | /* Alternating the usage of preconfigured and learned hostlists */ | 633 | /* Alternating the usage of preconfigured and learned hostlists */ |
@@ -643,13 +635,13 @@ static void update_hostlist ( ) | |||
643 | if (stat_testing_hostlist == GNUNET_YES) | 635 | if (stat_testing_hostlist == GNUNET_YES) |
644 | return; | 636 | return; |
645 | 637 | ||
646 | if ( GNUNET_YES == stat_learning) | 638 | if (GNUNET_YES == stat_learning) |
647 | { | 639 | { |
648 | if (stat_use_bootstrap == GNUNET_YES) | 640 | if (stat_use_bootstrap == GNUNET_YES) |
649 | stat_use_bootstrap = GNUNET_NO; | 641 | stat_use_bootstrap = GNUNET_NO; |
650 | else | 642 | else |
651 | stat_use_bootstrap = GNUNET_YES; | 643 | stat_use_bootstrap = GNUNET_YES; |
652 | } | 644 | } |
653 | else | 645 | else |
654 | stat_use_bootstrap = GNUNET_YES; | 646 | stat_use_bootstrap = GNUNET_YES; |
655 | } | 647 | } |
@@ -658,53 +650,53 @@ static void update_hostlist ( ) | |||
658 | * Clean up the state from the task that downloaded the | 650 | * Clean up the state from the task that downloaded the |
659 | * hostlist and schedule the next task. | 651 | * hostlist and schedule the next task. |
660 | */ | 652 | */ |
661 | static void | 653 | static void |
662 | clean_up () | 654 | clean_up () |
663 | { | 655 | { |
664 | CURLMcode mret; | 656 | CURLMcode mret; |
665 | 657 | ||
666 | if ( (stat_testing_hostlist == GNUNET_YES) && | 658 | if ((stat_testing_hostlist == GNUNET_YES) && |
667 | (GNUNET_NO == stat_download_successful) && | 659 | (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) |
668 | (NULL != hostlist_to_test)) | ||
669 | { | 660 | { |
670 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 661 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
671 | _("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), | 662 | _ |
672 | hostlist_to_test->hostlist_uri); | 663 | ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), |
664 | hostlist_to_test->hostlist_uri); | ||
673 | } | 665 | } |
674 | 666 | ||
675 | if (stat_testing_hostlist == GNUNET_YES) | 667 | if (stat_testing_hostlist == GNUNET_YES) |
676 | { | 668 | { |
677 | stat_testing_hostlist = GNUNET_NO; | 669 | stat_testing_hostlist = GNUNET_NO; |
678 | } | 670 | } |
679 | if ( NULL != hostlist_to_test) | 671 | if (NULL != hostlist_to_test) |
680 | { | 672 | { |
681 | GNUNET_free (hostlist_to_test); | 673 | GNUNET_free (hostlist_to_test); |
682 | hostlist_to_test = NULL; | 674 | hostlist_to_test = NULL; |
683 | } | 675 | } |
684 | 676 | ||
685 | if (multi != NULL) | 677 | if (multi != NULL) |
678 | { | ||
679 | mret = curl_multi_remove_handle (multi, curl); | ||
680 | if (mret != CURLM_OK) | ||
686 | { | 681 | { |
687 | mret = curl_multi_remove_handle (multi, curl); | 682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
688 | if (mret != CURLM_OK) | 683 | _("%s failed at %s:%d: `%s'\n"), |
689 | { | 684 | "curl_multi_remove_handle", __FILE__, __LINE__, |
690 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 685 | curl_multi_strerror (mret)); |
691 | _("%s failed at %s:%d: `%s'\n"), | ||
692 | "curl_multi_remove_handle", __FILE__, __LINE__, | ||
693 | curl_multi_strerror (mret)); | ||
694 | } | ||
695 | mret = curl_multi_cleanup (multi); | ||
696 | if (mret != CURLM_OK) | ||
697 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
698 | _("%s failed at %s:%d: `%s'\n"), | ||
699 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
700 | curl_multi_strerror (mret)); | ||
701 | multi = NULL; | ||
702 | } | 686 | } |
687 | mret = curl_multi_cleanup (multi); | ||
688 | if (mret != CURLM_OK) | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
690 | _("%s failed at %s:%d: `%s'\n"), | ||
691 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
692 | curl_multi_strerror (mret)); | ||
693 | multi = NULL; | ||
694 | } | ||
703 | if (curl != NULL) | 695 | if (curl != NULL) |
704 | { | 696 | { |
705 | curl_easy_cleanup (curl); | 697 | curl_easy_cleanup (curl); |
706 | curl = NULL; | 698 | curl = NULL; |
707 | } | 699 | } |
708 | GNUNET_free_non_null (current_url); | 700 | GNUNET_free_non_null (current_url); |
709 | current_url = NULL; | 701 | current_url = NULL; |
710 | stat_bytes_downloaded = 0; | 702 | stat_bytes_downloaded = 0; |
@@ -720,8 +712,7 @@ clean_up () | |||
720 | * @param tc task context, unused | 712 | * @param tc task context, unused |
721 | */ | 713 | */ |
722 | static void | 714 | static void |
723 | task_download (void *cls, | 715 | task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
724 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
725 | 716 | ||
726 | 717 | ||
727 | /** | 718 | /** |
@@ -747,27 +738,28 @@ download_prepare () | |||
747 | FD_ZERO (&es); | 738 | FD_ZERO (&es); |
748 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 739 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
749 | if (mret != CURLM_OK) | 740 | if (mret != CURLM_OK) |
750 | { | 741 | { |
751 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 742 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
752 | _("%s failed at %s:%d: `%s'\n"), | 743 | _("%s failed at %s:%d: `%s'\n"), |
753 | "curl_multi_fdset", __FILE__, __LINE__, | 744 | "curl_multi_fdset", __FILE__, __LINE__, |
754 | curl_multi_strerror (mret)); | 745 | curl_multi_strerror (mret)); |
755 | clean_up (); | 746 | clean_up (); |
756 | return; | 747 | return; |
757 | } | 748 | } |
758 | mret = curl_multi_timeout (multi, &timeout); | 749 | mret = curl_multi_timeout (multi, &timeout); |
759 | if (mret != CURLM_OK) | 750 | if (mret != CURLM_OK) |
760 | { | 751 | { |
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
762 | _("%s failed at %s:%d: `%s'\n"), | 753 | _("%s failed at %s:%d: `%s'\n"), |
763 | "curl_multi_timeout", __FILE__, __LINE__, | 754 | "curl_multi_timeout", __FILE__, __LINE__, |
764 | curl_multi_strerror (mret)); | 755 | curl_multi_strerror (mret)); |
765 | clean_up (); | 756 | clean_up (); |
766 | return; | 757 | return; |
767 | } | 758 | } |
768 | rtime = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), | 759 | rtime = |
769 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 760 | GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), |
770 | timeout)); | 761 | GNUNET_TIME_relative_multiply |
762 | (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); | ||
771 | grs = GNUNET_NETWORK_fdset_create (); | 763 | grs = GNUNET_NETWORK_fdset_create (); |
772 | gws = GNUNET_NETWORK_fdset_create (); | 764 | gws = GNUNET_NETWORK_fdset_create (); |
773 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); | 765 | GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); |
@@ -777,13 +769,9 @@ download_prepare () | |||
777 | "Scheduling task for hostlist download using cURL\n"); | 769 | "Scheduling task for hostlist download using cURL\n"); |
778 | #endif | 770 | #endif |
779 | ti_download | 771 | ti_download |
780 | = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 772 | = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
781 | GNUNET_SCHEDULER_NO_TASK, | 773 | GNUNET_SCHEDULER_NO_TASK, |
782 | rtime, | 774 | rtime, grs, gws, &task_download, multi); |
783 | grs, | ||
784 | gws, | ||
785 | &task_download, | ||
786 | multi); | ||
787 | GNUNET_NETWORK_fdset_destroy (gws); | 775 | GNUNET_NETWORK_fdset_destroy (gws); |
788 | GNUNET_NETWORK_fdset_destroy (grs); | 776 | GNUNET_NETWORK_fdset_destroy (grs); |
789 | } | 777 | } |
@@ -797,108 +785,107 @@ download_prepare () | |||
797 | * @param tc task context, unused | 785 | * @param tc task context, unused |
798 | */ | 786 | */ |
799 | static void | 787 | static void |
800 | task_download (void *cls, | 788 | task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
801 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
802 | { | 789 | { |
803 | int running; | 790 | int running; |
804 | struct CURLMsg *msg; | 791 | struct CURLMsg *msg; |
805 | CURLMcode mret; | 792 | CURLMcode mret; |
806 | 793 | ||
807 | ti_download = GNUNET_SCHEDULER_NO_TASK; | 794 | ti_download = GNUNET_SCHEDULER_NO_TASK; |
808 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 795 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
809 | { | 796 | { |
810 | #if DEBUG_HOSTLIST_CLIENT | 797 | #if DEBUG_HOSTLIST_CLIENT |
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
812 | "Shutdown requested while trying to download hostlist from `%s'\n", | 799 | "Shutdown requested while trying to download hostlist from `%s'\n", |
813 | current_url); | 800 | current_url); |
814 | #endif | 801 | #endif |
815 | update_hostlist(); | 802 | update_hostlist (); |
816 | clean_up (); | 803 | clean_up (); |
817 | return; | 804 | return; |
818 | } | 805 | } |
819 | if (GNUNET_TIME_absolute_get_remaining (end_time).rel_value == 0) | 806 | if (GNUNET_TIME_absolute_get_remaining (end_time).rel_value == 0) |
820 | { | 807 | { |
821 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 808 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
822 | _("Timeout trying to download hostlist from `%s'\n"), | 809 | _("Timeout trying to download hostlist from `%s'\n"), |
823 | current_url); | 810 | current_url); |
824 | update_hostlist(); | 811 | update_hostlist (); |
825 | clean_up (); | 812 | clean_up (); |
826 | return; | 813 | return; |
827 | } | 814 | } |
828 | #if DEBUG_HOSTLIST_CLIENT | 815 | #if DEBUG_HOSTLIST_CLIENT |
829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 816 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
830 | "Ready for processing hostlist client request\n"); | 817 | "Ready for processing hostlist client request\n"); |
831 | #endif | 818 | #endif |
832 | 819 | ||
833 | do | 820 | do |
821 | { | ||
822 | running = 0; | ||
823 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | ||
824 | { | ||
825 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
826 | _("Download limit of %u bytes exceeded, stopping download\n"), | ||
827 | MAX_BYTES_PER_HOSTLISTS); | ||
828 | clean_up (); | ||
829 | return; | ||
830 | } | ||
831 | mret = curl_multi_perform (multi, &running); | ||
832 | if (running == 0) | ||
834 | { | 833 | { |
835 | running = 0; | 834 | do |
836 | if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) | 835 | { |
836 | msg = curl_multi_info_read (multi, &running); | ||
837 | GNUNET_break (msg != NULL); | ||
838 | if (msg == NULL) | ||
839 | break; | ||
840 | switch (msg->msg) | ||
837 | { | 841 | { |
838 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 842 | case CURLMSG_DONE: |
839 | _("Download limit of %u bytes exceeded, stopping download\n"), | 843 | if ((msg->data.result != CURLE_OK) && |
840 | MAX_BYTES_PER_HOSTLISTS); | 844 | (msg->data.result != CURLE_GOT_NOTHING)) |
841 | clean_up(); | 845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
842 | return; | 846 | _("%s failed for `%s' at %s:%d: `%s'\n"), |
847 | "curl_multi_perform", | ||
848 | current_url, | ||
849 | __FILE__, | ||
850 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
851 | else | ||
852 | { | ||
853 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
854 | _("Download of hostlist `%s' completed.\n"), | ||
855 | current_url); | ||
856 | stat_download_successful = GNUNET_YES; | ||
857 | update_hostlist (); | ||
858 | if (GNUNET_YES == stat_testing_hostlist) | ||
859 | { | ||
860 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
861 | _ | ||
862 | ("Adding successfully tested hostlist `%s' datastore.\n"), | ||
863 | current_url); | ||
864 | insert_hostlist (); | ||
865 | hostlist_to_test = NULL; | ||
866 | stat_testing_hostlist = GNUNET_NO; | ||
867 | } | ||
868 | } | ||
869 | clean_up (); | ||
870 | return; | ||
871 | default: | ||
872 | break; | ||
843 | } | 873 | } |
844 | mret = curl_multi_perform (multi, &running); | 874 | |
845 | if (running == 0) | 875 | } |
846 | { | 876 | while ((running > 0)); |
847 | do | ||
848 | { | ||
849 | msg = curl_multi_info_read (multi, &running); | ||
850 | GNUNET_break (msg != NULL); | ||
851 | if (msg == NULL) | ||
852 | break; | ||
853 | switch (msg->msg) | ||
854 | { | ||
855 | case CURLMSG_DONE: | ||
856 | if ( (msg->data.result != CURLE_OK) && | ||
857 | (msg->data.result != CURLE_GOT_NOTHING) ) | ||
858 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
859 | _("%s failed for `%s' at %s:%d: `%s'\n"), | ||
860 | "curl_multi_perform", | ||
861 | current_url, | ||
862 | __FILE__, | ||
863 | __LINE__, | ||
864 | curl_easy_strerror (msg->data.result)); | ||
865 | else | ||
866 | { | ||
867 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
868 | _("Download of hostlist `%s' completed.\n"), | ||
869 | current_url); | ||
870 | stat_download_successful = GNUNET_YES; | ||
871 | update_hostlist(); | ||
872 | if (GNUNET_YES == stat_testing_hostlist) | ||
873 | { | ||
874 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
875 | _("Adding successfully tested hostlist `%s' datastore.\n"), | ||
876 | current_url); | ||
877 | insert_hostlist(); | ||
878 | hostlist_to_test = NULL; | ||
879 | stat_testing_hostlist = GNUNET_NO; | ||
880 | } | ||
881 | } | ||
882 | clean_up (); | ||
883 | return; | ||
884 | default: | ||
885 | break; | ||
886 | } | ||
887 | |||
888 | } | ||
889 | while ( (running > 0) ); | ||
890 | } | ||
891 | } | 877 | } |
878 | } | ||
892 | while (mret == CURLM_CALL_MULTI_PERFORM); | 879 | while (mret == CURLM_CALL_MULTI_PERFORM); |
893 | 880 | ||
894 | if (mret != CURLM_OK) | 881 | if (mret != CURLM_OK) |
895 | { | 882 | { |
896 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 883 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
897 | _("%s failed at %s:%d: `%s'\n"), | 884 | _("%s failed at %s:%d: `%s'\n"), |
898 | "curl_multi_perform", __FILE__, __LINE__, | 885 | "curl_multi_perform", __FILE__, __LINE__, |
899 | curl_multi_strerror (mret)); | 886 | curl_multi_strerror (mret)); |
900 | clean_up (); | 887 | clean_up (); |
901 | } | 888 | } |
902 | download_prepare (); | 889 | download_prepare (); |
903 | } | 890 | } |
904 | 891 | ||
@@ -908,7 +895,7 @@ task_download (void *cls, | |||
908 | * data. | 895 | * data. |
909 | */ | 896 | */ |
910 | static void | 897 | static void |
911 | download_hostlist () | 898 | download_hostlist () |
912 | { | 899 | { |
913 | CURLcode ret; | 900 | CURLcode ret; |
914 | CURLMcode mret; | 901 | CURLMcode mret; |
@@ -920,132 +907,110 @@ download_hostlist () | |||
920 | curl = curl_easy_init (); | 907 | curl = curl_easy_init (); |
921 | multi = NULL; | 908 | multi = NULL; |
922 | if (curl == NULL) | 909 | if (curl == NULL) |
923 | { | 910 | { |
924 | GNUNET_break (0); | 911 | GNUNET_break (0); |
925 | clean_up (); | 912 | clean_up (); |
926 | return; | 913 | return; |
927 | } | 914 | } |
928 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 915 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
929 | _("Bootstrapping using hostlist at `%s'.\n"), | 916 | _("Bootstrapping using hostlist at `%s'.\n"), current_url); |
930 | current_url); | ||
931 | 917 | ||
932 | stat_download_in_progress = GNUNET_YES; | 918 | stat_download_in_progress = GNUNET_YES; |
933 | stat_download_successful = GNUNET_NO; | 919 | stat_download_successful = GNUNET_NO; |
934 | stat_hellos_obtained = 0; | 920 | stat_hellos_obtained = 0; |
935 | stat_bytes_downloaded = 0; | 921 | stat_bytes_downloaded = 0; |
936 | 922 | ||
937 | GNUNET_STATISTICS_update (stats, | 923 | GNUNET_STATISTICS_update (stats, |
938 | gettext_noop ("# hostlist downloads initiated"), | 924 | gettext_noop ("# hostlist downloads initiated"), |
939 | 1, | 925 | 1, GNUNET_NO); |
940 | GNUNET_NO); | ||
941 | if (proxy != NULL) | 926 | if (proxy != NULL) |
942 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); | 927 | CURL_EASY_SETOPT (curl, CURLOPT_PROXY, proxy); |
943 | download_pos = 0; | 928 | download_pos = 0; |
944 | stat_bogus_url = 0; | 929 | stat_bogus_url = 0; |
945 | CURL_EASY_SETOPT (curl, | 930 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEFUNCTION, &callback_download); |
946 | CURLOPT_WRITEFUNCTION, | ||
947 | &callback_download); | ||
948 | if (ret != CURLE_OK) | 931 | if (ret != CURLE_OK) |
949 | { | 932 | { |
950 | clean_up (); | 933 | clean_up (); |
951 | return; | 934 | return; |
952 | } | 935 | } |
953 | CURL_EASY_SETOPT (curl, | 936 | CURL_EASY_SETOPT (curl, CURLOPT_WRITEDATA, NULL); |
954 | CURLOPT_WRITEDATA, | ||
955 | NULL); | ||
956 | if (ret != CURLE_OK) | 937 | if (ret != CURLE_OK) |
957 | { | 938 | { |
958 | clean_up (); | 939 | clean_up (); |
959 | return; | 940 | return; |
960 | } | 941 | } |
961 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); | 942 | CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); |
962 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); | 943 | CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); |
963 | /* no need to abort if the above failed */ | 944 | /* no need to abort if the above failed */ |
964 | CURL_EASY_SETOPT (curl, | 945 | CURL_EASY_SETOPT (curl, CURLOPT_URL, current_url); |
965 | CURLOPT_URL, | ||
966 | current_url); | ||
967 | if (ret != CURLE_OK) | 946 | if (ret != CURLE_OK) |
968 | { | 947 | { |
969 | clean_up (); | 948 | clean_up (); |
970 | return; | 949 | return; |
971 | } | 950 | } |
972 | CURL_EASY_SETOPT (curl, | 951 | CURL_EASY_SETOPT (curl, CURLOPT_FAILONERROR, 1); |
973 | CURLOPT_FAILONERROR, | ||
974 | 1); | ||
975 | #if 0 | 952 | #if 0 |
976 | CURL_EASY_SETOPT (curl, | 953 | CURL_EASY_SETOPT (curl, CURLOPT_VERBOSE, 1); |
977 | CURLOPT_VERBOSE, | ||
978 | 1); | ||
979 | #endif | 954 | #endif |
980 | CURL_EASY_SETOPT (curl, | 955 | CURL_EASY_SETOPT (curl, CURLOPT_BUFFERSIZE, GNUNET_SERVER_MAX_MESSAGE_SIZE); |
981 | CURLOPT_BUFFERSIZE, | ||
982 | GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
983 | if (0 == strncmp (current_url, "http", 4)) | 956 | if (0 == strncmp (current_url, "http", 4)) |
984 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); | 957 | CURL_EASY_SETOPT (curl, CURLOPT_USERAGENT, "GNUnet"); |
985 | CURL_EASY_SETOPT (curl, | 958 | CURL_EASY_SETOPT (curl, CURLOPT_CONNECTTIMEOUT, 60L); |
986 | CURLOPT_CONNECTTIMEOUT, | 959 | CURL_EASY_SETOPT (curl, CURLOPT_TIMEOUT, 60L); |
987 | 60L); | ||
988 | CURL_EASY_SETOPT (curl, | ||
989 | CURLOPT_TIMEOUT, | ||
990 | 60L); | ||
991 | #if 0 | 960 | #if 0 |
992 | /* this should no longer be needed; we're now single-threaded! */ | 961 | /* this should no longer be needed; we're now single-threaded! */ |
993 | CURL_EASY_SETOPT (curl, | 962 | CURL_EASY_SETOPT (curl, CURLOPT_NOSIGNAL, 1); |
994 | CURLOPT_NOSIGNAL, | ||
995 | 1); | ||
996 | #endif | 963 | #endif |
997 | multi = curl_multi_init (); | 964 | multi = curl_multi_init (); |
998 | if (multi == NULL) | 965 | if (multi == NULL) |
999 | { | 966 | { |
1000 | GNUNET_break (0); | 967 | GNUNET_break (0); |
1001 | /* clean_up (); */ | 968 | /* clean_up (); */ |
1002 | return; | 969 | return; |
1003 | } | 970 | } |
1004 | mret = curl_multi_add_handle (multi, curl); | 971 | mret = curl_multi_add_handle (multi, curl); |
1005 | if (mret != CURLM_OK) | 972 | if (mret != CURLM_OK) |
1006 | { | 973 | { |
974 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
975 | _("%s failed at %s:%d: `%s'\n"), | ||
976 | "curl_multi_add_handle", __FILE__, __LINE__, | ||
977 | curl_multi_strerror (mret)); | ||
978 | mret = curl_multi_cleanup (multi); | ||
979 | if (mret != CURLM_OK) | ||
1007 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 980 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1008 | _("%s failed at %s:%d: `%s'\n"), | 981 | _("%s failed at %s:%d: `%s'\n"), |
1009 | "curl_multi_add_handle", __FILE__, __LINE__, | 982 | "curl_multi_cleanup", __FILE__, __LINE__, |
1010 | curl_multi_strerror (mret)); | 983 | curl_multi_strerror (mret)); |
1011 | mret = curl_multi_cleanup (multi); | 984 | multi = NULL; |
1012 | if (mret != CURLM_OK) | 985 | clean_up (); |
1013 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 986 | return; |
1014 | _("%s failed at %s:%d: `%s'\n"), | 987 | } |
1015 | "curl_multi_cleanup", __FILE__, __LINE__, | ||
1016 | curl_multi_strerror (mret)); | ||
1017 | multi = NULL; | ||
1018 | clean_up (); | ||
1019 | return; | ||
1020 | } | ||
1021 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); | 988 | end_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); |
1022 | download_prepare (); | 989 | download_prepare (); |
1023 | } | 990 | } |
1024 | 991 | ||
1025 | 992 | ||
1026 | static void | 993 | static void |
1027 | task_download_dispatcher (void *cls, | 994 | task_download_dispatcher (void *cls, |
1028 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 995 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1029 | { | 996 | { |
1030 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; | 997 | ti_download_dispatcher_task = GNUNET_SCHEDULER_NO_TASK; |
1031 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 998 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1032 | return; | 999 | return; |
1033 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download is initiated...\n"); |
1034 | "Download is initiated...\n"); | 1001 | if (GNUNET_NO == stat_download_in_progress) |
1035 | if ( GNUNET_NO == stat_download_in_progress ) | 1002 | { |
1036 | { | 1003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download can start immediately...\n"); |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1004 | download_hostlist (); |
1038 | "Download can start immediately...\n"); | 1005 | } |
1039 | download_hostlist(); | 1006 | else |
1040 | } | 1007 | { |
1041 | else | 1008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1042 | { | 1009 | "Download in progess, have to wait...\n"); |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1010 | ti_download_dispatcher_task = |
1044 | "Download in progess, have to wait...\n"); | 1011 | GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL, |
1045 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_delayed (WAITING_INTERVALL, | 1012 | &task_download_dispatcher, NULL); |
1046 | &task_download_dispatcher, | 1013 | } |
1047 | NULL); | ||
1048 | } | ||
1049 | } | 1014 | } |
1050 | 1015 | ||
1051 | /** | 1016 | /** |
@@ -1054,8 +1019,7 @@ task_download_dispatcher (void *cls, | |||
1054 | * this task again for a later time. | 1019 | * this task again for a later time. |
1055 | */ | 1020 | */ |
1056 | static void | 1021 | static void |
1057 | task_check (void *cls, | 1022 | task_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1058 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1059 | { | 1023 | { |
1060 | static int once; | 1024 | static int once; |
1061 | struct GNUNET_TIME_Relative delay; | 1025 | struct GNUNET_TIME_Relative delay; |
@@ -1066,40 +1030,40 @@ task_check (void *cls, | |||
1066 | 1030 | ||
1067 | if (stat_connection_count < MIN_CONNECTIONS) | 1031 | if (stat_connection_count < MIN_CONNECTIONS) |
1068 | { | 1032 | { |
1069 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher, | 1033 | ti_download_dispatcher_task = |
1070 | NULL); | 1034 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1071 | } | 1035 | } |
1072 | 1036 | ||
1073 | if (stats == NULL) | 1037 | if (stats == NULL) |
1074 | { | 1038 | { |
1075 | curl_global_cleanup (); | 1039 | curl_global_cleanup (); |
1076 | return; /* in shutdown */ | 1040 | return; /* in shutdown */ |
1077 | } | 1041 | } |
1078 | delay = hostlist_delay; | 1042 | delay = hostlist_delay; |
1079 | if (hostlist_delay.rel_value == 0) | 1043 | if (hostlist_delay.rel_value == 0) |
1080 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; | 1044 | hostlist_delay = GNUNET_TIME_UNIT_SECONDS; |
1081 | else | 1045 | else |
1082 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); | 1046 | hostlist_delay = GNUNET_TIME_relative_multiply (hostlist_delay, 2); |
1083 | if (hostlist_delay.rel_value > GNUNET_TIME_UNIT_HOURS.rel_value * (1 + stat_connection_count)) | 1047 | if (hostlist_delay.rel_value > |
1084 | hostlist_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | 1048 | GNUNET_TIME_UNIT_HOURS.rel_value * (1 + stat_connection_count)) |
1085 | (1 + stat_connection_count)); | 1049 | hostlist_delay = |
1050 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, | ||
1051 | (1 + stat_connection_count)); | ||
1086 | GNUNET_STATISTICS_set (stats, | 1052 | GNUNET_STATISTICS_set (stats, |
1087 | gettext_noop("# milliseconds between hostlist downloads"), | 1053 | gettext_noop |
1088 | hostlist_delay.rel_value, | 1054 | ("# milliseconds between hostlist downloads"), |
1089 | GNUNET_YES); | 1055 | hostlist_delay.rel_value, GNUNET_YES); |
1090 | if (0 == once) | 1056 | if (0 == once) |
1091 | { | 1057 | { |
1092 | delay = GNUNET_TIME_UNIT_ZERO; | 1058 | delay = GNUNET_TIME_UNIT_ZERO; |
1093 | once = 1; | 1059 | once = 1; |
1094 | } | 1060 | } |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1061 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1096 | _("Have %u/%u connections. Will consider downloading hostlist in %llums\n"), | 1062 | _ |
1097 | stat_connection_count, | 1063 | ("Have %u/%u connections. Will consider downloading hostlist in %llums\n"), |
1098 | MIN_CONNECTIONS, | 1064 | stat_connection_count, MIN_CONNECTIONS, |
1099 | (unsigned long long) delay.rel_value); | 1065 | (unsigned long long) delay.rel_value); |
1100 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, | 1066 | ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); |
1101 | &task_check, | ||
1102 | NULL); | ||
1103 | } | 1067 | } |
1104 | 1068 | ||
1105 | 1069 | ||
@@ -1111,14 +1075,14 @@ task_check (void *cls, | |||
1111 | */ | 1075 | */ |
1112 | static void | 1076 | static void |
1113 | task_testing_intervall_reset (void *cls, | 1077 | task_testing_intervall_reset (void *cls, |
1114 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1078 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1115 | { | 1079 | { |
1116 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; | 1080 | ti_testing_intervall_task = GNUNET_SCHEDULER_NO_TASK; |
1117 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1081 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1118 | return; | 1082 | return; |
1119 | stat_testing_allowed = GNUNET_OK; | 1083 | stat_testing_allowed = GNUNET_OK; |
1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1121 | "Testing new hostlist advertisements is allowed again\n"); | 1085 | "Testing new hostlist advertisements is allowed again\n"); |
1122 | } | 1086 | } |
1123 | 1087 | ||
1124 | 1088 | ||
@@ -1129,22 +1093,19 @@ task_testing_intervall_reset (void *cls, | |||
1129 | * @param tc TaskContext | 1093 | * @param tc TaskContext |
1130 | */ | 1094 | */ |
1131 | static void | 1095 | static void |
1132 | task_hostlist_saving (void *cls, | 1096 | task_hostlist_saving (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1133 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1134 | { | 1097 | { |
1135 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; | 1098 | ti_saving_task = GNUNET_SCHEDULER_NO_TASK; |
1136 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1099 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1137 | return; | 1100 | return; |
1138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1101 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Scheduled saving of hostlists\n")); |
1139 | _("Scheduled saving of hostlists\n")); | 1102 | save_hostlist_file (GNUNET_NO); |
1140 | save_hostlist_file ( GNUNET_NO ); | ||
1141 | 1103 | ||
1142 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1143 | _("Hostlists will be saved to file again in %llums\n"), | 1105 | _("Hostlists will be saved to file again in %llums\n"), |
1144 | (unsigned long long) SAVING_INTERVALL.rel_value); | 1106 | (unsigned long long) SAVING_INTERVALL.rel_value); |
1145 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, | 1107 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, |
1146 | &task_hostlist_saving, | 1108 | &task_hostlist_saving, NULL); |
1147 | NULL); | ||
1148 | } | 1109 | } |
1149 | 1110 | ||
1150 | 1111 | ||
@@ -1157,16 +1118,15 @@ task_hostlist_saving (void *cls, | |||
1157 | */ | 1118 | */ |
1158 | static void | 1119 | static void |
1159 | handler_connect (void *cls, | 1120 | handler_connect (void *cls, |
1160 | const struct | 1121 | const struct |
1161 | GNUNET_PeerIdentity * peer, | 1122 | GNUNET_PeerIdentity *peer, |
1162 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1123 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1163 | { | 1124 | { |
1164 | GNUNET_assert (stat_connection_count < UINT_MAX); | 1125 | GNUNET_assert (stat_connection_count < UINT_MAX); |
1165 | stat_connection_count++; | 1126 | stat_connection_count++; |
1166 | GNUNET_STATISTICS_update (stats, | 1127 | GNUNET_STATISTICS_update (stats, |
1167 | gettext_noop ("# active connections"), | 1128 | gettext_noop ("# active connections"), |
1168 | 1, | 1129 | 1, GNUNET_NO); |
1169 | GNUNET_NO); | ||
1170 | } | 1130 | } |
1171 | 1131 | ||
1172 | 1132 | ||
@@ -1177,16 +1137,13 @@ handler_connect (void *cls, | |||
1177 | * @param peer peer identity this notification is about | 1137 | * @param peer peer identity this notification is about |
1178 | */ | 1138 | */ |
1179 | static void | 1139 | static void |
1180 | handler_disconnect (void *cls, | 1140 | handler_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
1181 | const struct | ||
1182 | GNUNET_PeerIdentity * peer) | ||
1183 | { | 1141 | { |
1184 | GNUNET_assert (stat_connection_count > 0); | 1142 | GNUNET_assert (stat_connection_count > 0); |
1185 | stat_connection_count--; | 1143 | stat_connection_count--; |
1186 | GNUNET_STATISTICS_update (stats, | 1144 | GNUNET_STATISTICS_update (stats, |
1187 | gettext_noop ("# active connections"), | 1145 | gettext_noop ("# active connections"), |
1188 | -1, | 1146 | -1, GNUNET_NO); |
1189 | GNUNET_NO); | ||
1190 | } | 1147 | } |
1191 | 1148 | ||
1192 | 1149 | ||
@@ -1202,76 +1159,74 @@ handler_disconnect (void *cls, | |||
1202 | */ | 1159 | */ |
1203 | static int | 1160 | static int |
1204 | handler_advertisement (void *cls, | 1161 | handler_advertisement (void *cls, |
1205 | const struct GNUNET_PeerIdentity * peer, | 1162 | const struct GNUNET_PeerIdentity *peer, |
1206 | const struct GNUNET_MessageHeader * message, | 1163 | const struct GNUNET_MessageHeader *message, |
1207 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1164 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1208 | { | 1165 | { |
1209 | size_t size; | 1166 | size_t size; |
1210 | size_t uri_size; | 1167 | size_t uri_size; |
1211 | const struct GNUNET_MessageHeader * incoming; | 1168 | const struct GNUNET_MessageHeader *incoming; |
1212 | const char *uri; | 1169 | const char *uri; |
1213 | struct Hostlist * hostlist; | 1170 | struct Hostlist *hostlist; |
1214 | 1171 | ||
1215 | GNUNET_assert (ntohs (message->type) == GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 1172 | GNUNET_assert (ntohs (message->type) == |
1173 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | ||
1216 | size = ntohs (message->size); | 1174 | size = ntohs (message->size); |
1217 | if (size <= sizeof(struct GNUNET_MessageHeader)) | 1175 | if (size <= sizeof (struct GNUNET_MessageHeader)) |
1218 | { | 1176 | { |
1219 | GNUNET_break_op (0); | 1177 | GNUNET_break_op (0); |
1220 | return GNUNET_SYSERR; | 1178 | return GNUNET_SYSERR; |
1221 | } | 1179 | } |
1222 | incoming = (const struct GNUNET_MessageHeader *) message; | 1180 | incoming = (const struct GNUNET_MessageHeader *) message; |
1223 | uri = (const char*) &incoming[1]; | 1181 | uri = (const char *) &incoming[1]; |
1224 | uri_size = size - sizeof (struct GNUNET_MessageHeader); | 1182 | uri_size = size - sizeof (struct GNUNET_MessageHeader); |
1225 | if (uri [uri_size - 1] != '\0') | 1183 | if (uri[uri_size - 1] != '\0') |
1226 | { | 1184 | { |
1227 | GNUNET_break_op (0); | 1185 | GNUNET_break_op (0); |
1228 | return GNUNET_SYSERR; | 1186 | return GNUNET_SYSERR; |
1229 | } | 1187 | } |
1230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1231 | "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", | 1189 | "Hostlist client recieved advertisement from `%s' containing URI `%s'\n", |
1232 | GNUNET_i2s (peer), | 1190 | GNUNET_i2s (peer), uri); |
1233 | uri); | ||
1234 | if (GNUNET_NO != linked_list_contains (uri)) | 1191 | if (GNUNET_NO != linked_list_contains (uri)) |
1235 | { | 1192 | { |
1236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); |
1237 | "URI `%s' is already known\n", | 1194 | return GNUNET_OK; |
1238 | uri); | 1195 | } |
1239 | return GNUNET_OK; | ||
1240 | } | ||
1241 | 1196 | ||
1242 | if ( GNUNET_NO == stat_testing_allowed ) | 1197 | if (GNUNET_NO == stat_testing_allowed) |
1243 | { | 1198 | { |
1244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1245 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); | 1200 | "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); |
1246 | return GNUNET_SYSERR; | 1201 | return GNUNET_SYSERR; |
1247 | } | 1202 | } |
1248 | if ( GNUNET_YES == stat_testing_hostlist ) | 1203 | if (GNUNET_YES == stat_testing_hostlist) |
1249 | { | 1204 | { |
1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); | 1206 | "Currently not accepting new advertisements: we are already testing a hostlist\n"); |
1252 | return GNUNET_SYSERR; | 1207 | return GNUNET_SYSERR; |
1253 | } | 1208 | } |
1254 | 1209 | ||
1255 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); | 1210 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); |
1256 | hostlist->hostlist_uri = (const char*) &hostlist[1]; | 1211 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1257 | memcpy (&hostlist[1], uri, uri_size); | 1212 | memcpy (&hostlist[1], uri, uri_size); |
1258 | hostlist->time_creation = GNUNET_TIME_absolute_get(); | 1213 | hostlist->time_creation = GNUNET_TIME_absolute_get (); |
1259 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero(); | 1214 | hostlist->time_last_usage = GNUNET_TIME_absolute_get_zero (); |
1260 | hostlist->quality = HOSTLIST_INITIAL; | 1215 | hostlist->quality = HOSTLIST_INITIAL; |
1261 | hostlist_to_test = hostlist; | 1216 | hostlist_to_test = hostlist; |
1262 | 1217 | ||
1263 | stat_testing_hostlist = GNUNET_YES; | 1218 | stat_testing_hostlist = GNUNET_YES; |
1264 | stat_testing_allowed = GNUNET_NO; | 1219 | stat_testing_allowed = GNUNET_NO; |
1265 | ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, | 1220 | ti_testing_intervall_task = GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, |
1266 | &task_testing_intervall_reset, | 1221 | &task_testing_intervall_reset, |
1267 | NULL); | 1222 | NULL); |
1268 | 1223 | ||
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Testing new hostlist advertisements is locked for the next %u ms\n", | 1225 | "Testing new hostlist advertisements is locked for the next %u ms\n", |
1271 | TESTING_INTERVAL.rel_value); | 1226 | TESTING_INTERVAL.rel_value); |
1272 | 1227 | ||
1273 | ti_download_dispatcher_task = GNUNET_SCHEDULER_add_now (&task_download_dispatcher, | 1228 | ti_download_dispatcher_task = |
1274 | NULL); | 1229 | GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); |
1275 | 1230 | ||
1276 | return GNUNET_OK; | 1231 | return GNUNET_OK; |
1277 | } | 1232 | } |
@@ -1290,26 +1245,23 @@ static void | |||
1290 | primary_task (void *cls, int success) | 1245 | primary_task (void *cls, int success) |
1291 | { | 1246 | { |
1292 | if (stats == NULL) | 1247 | if (stats == NULL) |
1293 | return; /* in shutdown */ | 1248 | return; /* in shutdown */ |
1294 | #if DEBUG_HOSTLIST_CLIENT | 1249 | #if DEBUG_HOSTLIST_CLIENT |
1295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1296 | "Statistics request done, scheduling hostlist download\n"); | 1251 | "Statistics request done, scheduling hostlist download\n"); |
1297 | #endif | 1252 | #endif |
1298 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, | 1253 | ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); |
1299 | NULL); | ||
1300 | } | 1254 | } |
1301 | 1255 | ||
1302 | 1256 | ||
1303 | static int | 1257 | static int |
1304 | process_stat (void *cls, | 1258 | process_stat (void *cls, |
1305 | const char *subsystem, | 1259 | const char *subsystem, |
1306 | const char *name, | 1260 | const char *name, uint64_t value, int is_persistent) |
1307 | uint64_t value, | ||
1308 | int is_persistent) | ||
1309 | { | 1261 | { |
1310 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1311 | _("Initial time between hostlist downloads is %llums\n"), | 1263 | _("Initial time between hostlist downloads is %llums\n"), |
1312 | (unsigned long long) value); | 1264 | (unsigned long long) value); |
1313 | hostlist_delay.rel_value = value; | 1265 | hostlist_delay.rel_value = value; |
1314 | return GNUNET_OK; | 1266 | return GNUNET_OK; |
1315 | } | 1267 | } |
@@ -1317,13 +1269,14 @@ process_stat (void *cls, | |||
1317 | /** | 1269 | /** |
1318 | * Method to load persistent hostlist file during hostlist client startup | 1270 | * Method to load persistent hostlist file during hostlist client startup |
1319 | */ | 1271 | */ |
1320 | static void | 1272 | static void |
1321 | load_hostlist_file () | 1273 | load_hostlist_file () |
1322 | { | 1274 | { |
1323 | char *filename; | 1275 | char *filename; |
1324 | char *uri; | 1276 | char *uri; |
1325 | char *emsg; | 1277 | char *emsg; |
1326 | struct Hostlist * hostlist; | 1278 | struct Hostlist *hostlist; |
1279 | |||
1327 | uri = NULL; | 1280 | uri = NULL; |
1328 | uint32_t times_used; | 1281 | uint32_t times_used; |
1329 | uint32_t hellos_returned; | 1282 | uint32_t hellos_returned; |
@@ -1333,74 +1286,75 @@ load_hostlist_file () | |||
1333 | uint32_t counter; | 1286 | uint32_t counter; |
1334 | 1287 | ||
1335 | if (GNUNET_OK != | 1288 | if (GNUNET_OK != |
1336 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1289 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1337 | "HOSTLIST", | 1290 | "HOSTLIST", |
1338 | "HOSTLISTFILE", | 1291 | "HOSTLISTFILE", &filename)) |
1339 | &filename)) | 1292 | { |
1340 | { | 1293 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1341 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1294 | _ |
1342 | _("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"), | 1295 | ("No `%s' specified in `%s' configuration, cannot load hostlists from file.\n"), |
1343 | "HOSTLISTFILE", "HOSTLIST"); | 1296 | "HOSTLISTFILE", "HOSTLIST"); |
1344 | return; | 1297 | return; |
1345 | } | 1298 | } |
1346 | 1299 | ||
1347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1300 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1348 | _("Loading saved hostlist entries from file `%s' \n"), filename); | 1301 | _("Loading saved hostlist entries from file `%s' \n"), filename); |
1349 | if ( GNUNET_NO == GNUNET_DISK_file_test (filename) ) | 1302 | if (GNUNET_NO == GNUNET_DISK_file_test (filename)) |
1350 | { | 1303 | { |
1351 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1304 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1352 | _("Hostlist file `%s' is not existing\n"), filename); | 1305 | _("Hostlist file `%s' is not existing\n"), filename); |
1353 | GNUNET_free ( filename ); | 1306 | GNUNET_free (filename); |
1354 | return; | 1307 | return; |
1355 | } | 1308 | } |
1356 | 1309 | ||
1357 | struct GNUNET_BIO_ReadHandle * rh = GNUNET_BIO_read_open (filename); | 1310 | struct GNUNET_BIO_ReadHandle *rh = GNUNET_BIO_read_open (filename); |
1311 | |||
1358 | if (NULL == rh) | 1312 | if (NULL == rh) |
1359 | { | 1313 | { |
1360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1361 | _("Could not open file `%s' for reading to load hostlists: %s\n"), | 1315 | _ |
1362 | filename, | 1316 | ("Could not open file `%s' for reading to load hostlists: %s\n"), |
1363 | STRERROR (errno)); | 1317 | filename, STRERROR (errno)); |
1364 | GNUNET_free (filename); | 1318 | GNUNET_free (filename); |
1365 | return; | 1319 | return; |
1366 | } | 1320 | } |
1367 | 1321 | ||
1368 | counter = 0; | 1322 | counter = 0; |
1369 | while ( (GNUNET_OK == GNUNET_BIO_read_string (rh, "url" , &uri, MAX_URL_LEN)) && | 1323 | while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && |
1370 | (NULL != uri) && | 1324 | (NULL != uri) && |
1371 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && | 1325 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && |
1372 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && | 1326 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && |
1373 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && | 1327 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && |
1374 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && | 1328 | (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && |
1375 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned)) ) | 1329 | (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) |
1376 | { | 1330 | { |
1377 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1); | 1331 | hostlist = GNUNET_malloc (sizeof (struct Hostlist) + strlen (uri) + 1); |
1378 | hostlist->hello_count = hellos_returned; | 1332 | hostlist->hello_count = hellos_returned; |
1379 | hostlist->hostlist_uri = (const char *) &hostlist[1]; | 1333 | hostlist->hostlist_uri = (const char *) &hostlist[1]; |
1380 | memcpy (&hostlist[1], uri, strlen(uri)+1); | 1334 | memcpy (&hostlist[1], uri, strlen (uri) + 1); |
1381 | hostlist->quality = quality; | 1335 | hostlist->quality = quality; |
1382 | hostlist->time_creation.abs_value = created; | 1336 | hostlist->time_creation.abs_value = created; |
1383 | hostlist->time_last_usage.abs_value = last_used; | 1337 | hostlist->time_last_usage.abs_value = last_used; |
1384 | GNUNET_CONTAINER_DLL_insert(linked_list_head, linked_list_tail, hostlist); | 1338 | GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, hostlist); |
1385 | linked_list_size++; | 1339 | linked_list_size++; |
1386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1387 | "Added hostlist entry eith URI `%s' \n", hostlist->hostlist_uri); | 1341 | "Added hostlist entry eith URI `%s' \n", |
1388 | GNUNET_free (uri); | 1342 | hostlist->hostlist_uri); |
1389 | uri = NULL; | 1343 | GNUNET_free (uri); |
1390 | counter++; | 1344 | uri = NULL; |
1391 | if ( counter >= MAX_NUMBER_HOSTLISTS ) break; | 1345 | counter++; |
1392 | } | 1346 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1347 | break; | ||
1348 | } | ||
1393 | 1349 | ||
1394 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1350 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1395 | _("%u hostlist URIs loaded from file\n"), counter); | 1351 | _("%u hostlist URIs loaded from file\n"), counter); |
1396 | GNUNET_STATISTICS_set (stats, | 1352 | GNUNET_STATISTICS_set (stats, |
1397 | gettext_noop("# hostlist URIs read from file"), | 1353 | gettext_noop ("# hostlist URIs read from file"), |
1398 | counter, | 1354 | counter, GNUNET_YES); |
1399 | GNUNET_YES); | ||
1400 | GNUNET_STATISTICS_set (stats, | 1355 | GNUNET_STATISTICS_set (stats, |
1401 | gettext_noop("# advertised hostlist URIs"), | 1356 | gettext_noop ("# advertised hostlist URIs"), |
1402 | linked_list_size, | 1357 | linked_list_size, GNUNET_NO); |
1403 | GNUNET_NO); | ||
1404 | 1358 | ||
1405 | GNUNET_free_non_null (uri); | 1359 | GNUNET_free_non_null (uri); |
1406 | emsg = NULL; | 1360 | emsg = NULL; |
@@ -1415,89 +1369,87 @@ load_hostlist_file () | |||
1415 | * Method to save persistent hostlist file during hostlist client shutdown | 1369 | * Method to save persistent hostlist file during hostlist client shutdown |
1416 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed | 1370 | * @param shutdown set if called because of shutdown, entries in linked list will be destroyed |
1417 | */ | 1371 | */ |
1418 | static void save_hostlist_file ( int shutdown ) | 1372 | static void |
1373 | save_hostlist_file (int shutdown) | ||
1419 | { | 1374 | { |
1420 | char *filename; | 1375 | char *filename; |
1421 | struct Hostlist *pos; | 1376 | struct Hostlist *pos; |
1422 | struct GNUNET_BIO_WriteHandle * wh; | 1377 | struct GNUNET_BIO_WriteHandle *wh; |
1423 | int ok; | 1378 | int ok; |
1424 | uint32_t counter; | 1379 | uint32_t counter; |
1425 | 1380 | ||
1426 | if (GNUNET_OK != | 1381 | if (GNUNET_OK != |
1427 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1382 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
1428 | "HOSTLIST", | 1383 | "HOSTLIST", |
1429 | "HOSTLISTFILE", | 1384 | "HOSTLISTFILE", &filename)) |
1430 | &filename)) | 1385 | { |
1431 | { | 1386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1432 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1387 | _ |
1433 | _("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), | 1388 | ("No `%s' specified in `%s' configuration, cannot save hostlists to file.\n"), |
1434 | "HOSTLISTFILE", "HOSTLIST"); | 1389 | "HOSTLISTFILE", "HOSTLIST"); |
1435 | return; | 1390 | return; |
1436 | } | 1391 | } |
1437 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) | 1392 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) |
1438 | { | 1393 | { |
1439 | GNUNET_free (filename); | 1394 | GNUNET_free (filename); |
1440 | return; | 1395 | return; |
1441 | } | 1396 | } |
1442 | wh = GNUNET_BIO_write_open (filename); | 1397 | wh = GNUNET_BIO_write_open (filename); |
1443 | if ( NULL == wh) | 1398 | if (NULL == wh) |
1444 | { | 1399 | { |
1445 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1400 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1446 | _("Could not open file `%s' for writing to save hostlists: %s\n"), | 1401 | _ |
1447 | filename, | 1402 | ("Could not open file `%s' for writing to save hostlists: %s\n"), |
1448 | STRERROR (errno)); | 1403 | filename, STRERROR (errno)); |
1449 | GNUNET_free (filename); | 1404 | GNUNET_free (filename); |
1450 | return; | 1405 | return; |
1451 | } | 1406 | } |
1452 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1407 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1453 | _("Writing %u hostlist URIs to `%s'\n" ), | 1408 | _("Writing %u hostlist URIs to `%s'\n"), |
1454 | linked_list_size, filename); | 1409 | linked_list_size, filename); |
1455 | /* add code to write hostlists to file using bio */ | 1410 | /* add code to write hostlists to file using bio */ |
1456 | ok = GNUNET_YES; | 1411 | ok = GNUNET_YES; |
1457 | counter = 0; | 1412 | counter = 0; |
1458 | while (NULL != (pos = linked_list_head)) | 1413 | while (NULL != (pos = linked_list_head)) |
1414 | { | ||
1415 | if (GNUNET_YES == shutdown) | ||
1416 | { | ||
1417 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); | ||
1418 | linked_list_size--; | ||
1419 | } | ||
1420 | if (GNUNET_YES == ok) | ||
1459 | { | 1421 | { |
1460 | if ( GNUNET_YES == shutdown) | 1422 | if ((GNUNET_OK != |
1423 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | ||
1424 | (GNUNET_OK != | ||
1425 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || | ||
1426 | (GNUNET_OK != | ||
1427 | GNUNET_BIO_write_int64 (wh, pos->quality)) || | ||
1428 | (GNUNET_OK != | ||
1429 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) || | ||
1430 | (GNUNET_OK != | ||
1431 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) || | ||
1432 | (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) | ||
1461 | { | 1433 | { |
1462 | GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, pos); | 1434 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1463 | linked_list_size--; | 1435 | _("Error writing hostlist URIs to file `%s'\n"), filename); |
1436 | ok = GNUNET_NO; | ||
1464 | } | 1437 | } |
1465 | if (GNUNET_YES == ok) | 1438 | } |
1466 | { | 1439 | |
1467 | if ( (GNUNET_OK != | 1440 | if (GNUNET_YES == shutdown) |
1468 | GNUNET_BIO_write_string (wh, pos->hostlist_uri)) || | 1441 | GNUNET_free (pos); |
1469 | (GNUNET_OK != | 1442 | counter++; |
1470 | GNUNET_BIO_write_int32 (wh, pos->times_used)) || | 1443 | if (counter >= MAX_NUMBER_HOSTLISTS) |
1471 | (GNUNET_OK != | 1444 | break; |
1472 | GNUNET_BIO_write_int64 (wh, pos->quality)) || | 1445 | } |
1473 | (GNUNET_OK != | ||
1474 | GNUNET_BIO_write_int64 (wh, pos->time_last_usage.abs_value)) || | ||
1475 | (GNUNET_OK != | ||
1476 | GNUNET_BIO_write_int64 (wh, pos->time_creation.abs_value)) || | ||
1477 | (GNUNET_OK != | ||
1478 | GNUNET_BIO_write_int32 (wh, pos->hello_count))) | ||
1479 | { | ||
1480 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1481 | _("Error writing hostlist URIs to file `%s'\n"), | ||
1482 | filename); | ||
1483 | ok = GNUNET_NO; | ||
1484 | } | ||
1485 | } | ||
1486 | |||
1487 | if ( GNUNET_YES == shutdown) | ||
1488 | GNUNET_free (pos); | ||
1489 | counter ++; | ||
1490 | if ( counter >= MAX_NUMBER_HOSTLISTS) break; | ||
1491 | } | ||
1492 | GNUNET_STATISTICS_set (stats, | 1446 | GNUNET_STATISTICS_set (stats, |
1493 | gettext_noop("# hostlist URIs written to file"), | 1447 | gettext_noop ("# hostlist URIs written to file"), |
1494 | counter, | 1448 | counter, GNUNET_YES); |
1495 | GNUNET_YES); | ||
1496 | 1449 | ||
1497 | if ( GNUNET_OK != GNUNET_BIO_write_close ( wh ) ) | 1450 | if (GNUNET_OK != GNUNET_BIO_write_close (wh)) |
1498 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1451 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1499 | _("Error writing hostlist URIs to file `%s'\n"), | 1452 | _("Error writing hostlist URIs to file `%s'\n"), filename); |
1500 | filename); | ||
1501 | GNUNET_free (filename); | 1453 | GNUNET_free (filename); |
1502 | } | 1454 | } |
1503 | 1455 | ||
@@ -1506,33 +1458,30 @@ static void save_hostlist_file ( int shutdown ) | |||
1506 | */ | 1458 | */ |
1507 | int | 1459 | int |
1508 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | 1460 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
1509 | struct GNUNET_STATISTICS_Handle *st, | 1461 | struct GNUNET_STATISTICS_Handle *st, |
1510 | GNUNET_CORE_ConnectEventHandler *ch, | 1462 | GNUNET_CORE_ConnectEventHandler *ch, |
1511 | GNUNET_CORE_DisconnectEventHandler *dh, | 1463 | GNUNET_CORE_DisconnectEventHandler *dh, |
1512 | GNUNET_CORE_MessageCallback *msgh, | 1464 | GNUNET_CORE_MessageCallback *msgh, int learn) |
1513 | int learn) | ||
1514 | { | 1465 | { |
1515 | char *filename; | 1466 | char *filename; |
1516 | int result; | 1467 | int result; |
1517 | 1468 | ||
1518 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 1469 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
1519 | { | 1470 | { |
1520 | GNUNET_break (0); | 1471 | GNUNET_break (0); |
1521 | return GNUNET_SYSERR; | 1472 | return GNUNET_SYSERR; |
1522 | } | 1473 | } |
1523 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); | 1474 | transport = GNUNET_TRANSPORT_connect (c, NULL, NULL, NULL, NULL, NULL); |
1524 | if (NULL == transport) | 1475 | if (NULL == transport) |
1525 | { | 1476 | { |
1526 | curl_global_cleanup (); | 1477 | curl_global_cleanup (); |
1527 | return GNUNET_SYSERR; | 1478 | return GNUNET_SYSERR; |
1528 | } | 1479 | } |
1529 | cfg = c; | 1480 | cfg = c; |
1530 | stats = st; | 1481 | stats = st; |
1531 | if (GNUNET_OK != | 1482 | if (GNUNET_OK != |
1532 | GNUNET_CONFIGURATION_get_value_string (cfg, | 1483 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1533 | "HOSTLIST", | 1484 | "HOSTLIST", "HTTP-PROXY", &proxy)) |
1534 | "HTTP-PROXY", | ||
1535 | &proxy)) | ||
1536 | proxy = NULL; | 1485 | proxy = NULL; |
1537 | stat_learning = learn; | 1486 | stat_learning = learn; |
1538 | *ch = &handler_connect; | 1487 | *ch = &handler_connect; |
@@ -1543,51 +1492,49 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1543 | stat_testing_hostlist = GNUNET_NO; | 1492 | stat_testing_hostlist = GNUNET_NO; |
1544 | stat_testing_allowed = GNUNET_YES; | 1493 | stat_testing_allowed = GNUNET_YES; |
1545 | 1494 | ||
1546 | if ( GNUNET_YES == stat_learning ) | 1495 | if (GNUNET_YES == stat_learning) |
1547 | { | 1496 | { |
1548 | *msgh = &handler_advertisement; | 1497 | *msgh = &handler_advertisement; |
1549 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1498 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1550 | _("Learning is enabled on this peer\n")); | 1499 | _("Learning is enabled on this peer\n")); |
1551 | load_hostlist_file (); | 1500 | load_hostlist_file (); |
1552 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1501 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1553 | _("Hostlists will be saved to file again in %llums\n"), | 1502 | _("Hostlists will be saved to file again in %llums\n"), |
1554 | (unsigned long long) SAVING_INTERVALL.rel_value); | 1503 | (unsigned long long) SAVING_INTERVALL.rel_value); |
1555 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, | 1504 | ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVALL, |
1556 | &task_hostlist_saving, | 1505 | &task_hostlist_saving, NULL); |
1557 | NULL); | ||
1558 | } | 1506 | } |
1559 | else | 1507 | else |
1560 | { | 1508 | { |
1561 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1509 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1562 | _("Learning is not enabled on this peer\n")); | 1510 | _("Learning is not enabled on this peer\n")); |
1563 | *msgh = NULL; | 1511 | *msgh = NULL; |
1564 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, | 1512 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
1565 | "HOSTLIST", | 1513 | "HOSTLIST", |
1566 | "HOSTLISTFILE", | 1514 | "HOSTLISTFILE", |
1567 | &filename)) | 1515 | &filename)) |
1568 | { | 1516 | { |
1569 | if ( GNUNET_YES == GNUNET_DISK_file_test (filename) ) | 1517 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
1570 | { | 1518 | { |
1571 | result = remove (filename); | 1519 | result = remove (filename); |
1572 | if (result == 0) | 1520 | if (result == 0) |
1573 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1521 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1574 | _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), | 1522 | _ |
1575 | filename); | 1523 | ("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), |
1524 | filename); | ||
1576 | else | 1525 | else |
1577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1578 | _("Hostlist file `%s' could not be removed\n"), | 1527 | _("Hostlist file `%s' could not be removed\n"), filename); |
1579 | filename); | ||
1580 | } | 1528 | } |
1581 | } | 1529 | } |
1582 | GNUNET_free ( filename ); | 1530 | GNUNET_free (filename); |
1583 | } | 1531 | } |
1584 | GNUNET_STATISTICS_get (stats, | 1532 | GNUNET_STATISTICS_get (stats, |
1585 | "hostlist", | 1533 | "hostlist", |
1586 | gettext_noop("# milliseconds between hostlist downloads"), | 1534 | gettext_noop |
1587 | GNUNET_TIME_UNIT_MINUTES, | 1535 | ("# milliseconds between hostlist downloads"), |
1588 | &primary_task, | 1536 | GNUNET_TIME_UNIT_MINUTES, &primary_task, &process_stat, |
1589 | &process_stat, | 1537 | NULL); |
1590 | NULL); | ||
1591 | return GNUNET_OK; | 1538 | return GNUNET_OK; |
1592 | } | 1539 | } |
1593 | 1540 | ||
@@ -1598,42 +1545,40 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
1598 | void | 1545 | void |
1599 | GNUNET_HOSTLIST_client_stop () | 1546 | GNUNET_HOSTLIST_client_stop () |
1600 | { | 1547 | { |
1601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1602 | "Hostlist client shutdown\n"); | ||
1603 | #if DEBUG_HOSTLIST_CLIENT | 1549 | #if DEBUG_HOSTLIST_CLIENT |
1604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1550 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); |
1605 | "Hostlist client shutdown\n"); | ||
1606 | #endif | 1551 | #endif |
1607 | if ( GNUNET_YES == stat_learning ) | 1552 | if (GNUNET_YES == stat_learning) |
1608 | save_hostlist_file ( GNUNET_YES ); | 1553 | save_hostlist_file (GNUNET_YES); |
1609 | 1554 | ||
1610 | if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) | 1555 | if (ti_saving_task != GNUNET_SCHEDULER_NO_TASK) |
1611 | { | 1556 | { |
1612 | GNUNET_SCHEDULER_cancel (ti_saving_task); | 1557 | GNUNET_SCHEDULER_cancel (ti_saving_task); |
1613 | } | 1558 | } |
1614 | 1559 | ||
1615 | if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) | 1560 | if (ti_download_dispatcher_task != GNUNET_SCHEDULER_NO_TASK) |
1616 | { | 1561 | { |
1617 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); | 1562 | GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); |
1618 | } | 1563 | } |
1619 | if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) | 1564 | if (ti_testing_intervall_task != GNUNET_SCHEDULER_NO_TASK) |
1620 | { | 1565 | { |
1621 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); | 1566 | GNUNET_SCHEDULER_cancel (ti_testing_intervall_task); |
1622 | } | 1567 | } |
1623 | if (ti_download != GNUNET_SCHEDULER_NO_TASK) | 1568 | if (ti_download != GNUNET_SCHEDULER_NO_TASK) |
1624 | { | 1569 | { |
1625 | GNUNET_SCHEDULER_cancel (ti_download); | 1570 | GNUNET_SCHEDULER_cancel (ti_download); |
1626 | } | 1571 | } |
1627 | if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) | 1572 | if (ti_check_download != GNUNET_SCHEDULER_NO_TASK) |
1628 | { | 1573 | { |
1629 | GNUNET_SCHEDULER_cancel (ti_check_download); | 1574 | GNUNET_SCHEDULER_cancel (ti_check_download); |
1630 | curl_global_cleanup (); | 1575 | curl_global_cleanup (); |
1631 | } | 1576 | } |
1632 | if (transport != NULL) | 1577 | if (transport != NULL) |
1633 | { | 1578 | { |
1634 | GNUNET_TRANSPORT_disconnect (transport); | 1579 | GNUNET_TRANSPORT_disconnect (transport); |
1635 | transport = NULL; | 1580 | transport = NULL; |
1636 | } | 1581 | } |
1637 | GNUNET_assert (NULL == transport); | 1582 | GNUNET_assert (NULL == transport); |
1638 | GNUNET_free_non_null (proxy); | 1583 | GNUNET_free_non_null (proxy); |
1639 | proxy = NULL; | 1584 | proxy = NULL; |
diff --git a/src/hostlist/hostlist-client.h b/src/hostlist/hostlist-client.h index b29b96a04..80ead64bb 100644 --- a/src/hostlist/hostlist-client.h +++ b/src/hostlist/hostlist-client.h | |||
@@ -91,18 +91,16 @@ | |||
91 | */ | 91 | */ |
92 | int | 92 | int |
93 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, | 93 | GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, |
94 | struct GNUNET_STATISTICS_Handle *st, | 94 | struct GNUNET_STATISTICS_Handle *st, |
95 | GNUNET_CORE_ConnectEventHandler *ch, | 95 | GNUNET_CORE_ConnectEventHandler *ch, |
96 | GNUNET_CORE_DisconnectEventHandler *dh, | 96 | GNUNET_CORE_DisconnectEventHandler *dh, |
97 | GNUNET_CORE_MessageCallback *msgh, | 97 | GNUNET_CORE_MessageCallback *msgh, int learn); |
98 | int learn); | ||
99 | 98 | ||
100 | 99 | ||
101 | /** | 100 | /** |
102 | * Stop downloading hostlists from hostlist servers as necessary. | 101 | * Stop downloading hostlists from hostlist servers as necessary. |
103 | */ | 102 | */ |
104 | void | 103 | void GNUNET_HOSTLIST_client_stop (void); |
105 | GNUNET_HOSTLIST_client_stop (void); | ||
106 | 104 | ||
107 | 105 | ||
108 | #endif | 106 | #endif |
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index c8e17f33a..e30b3c1e0 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c | |||
@@ -51,7 +51,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
51 | 51 | ||
52 | /** | 52 | /** |
53 | * For keeping statistics. | 53 | * For keeping statistics. |
54 | */ | 54 | */ |
55 | static struct GNUNET_STATISTICS_Handle *stats; | 55 | static struct GNUNET_STATISTICS_Handle *stats; |
56 | 56 | ||
57 | /** | 57 | /** |
@@ -107,7 +107,7 @@ static int advertising; | |||
107 | /** | 107 | /** |
108 | * Buffer for the hostlist address | 108 | * Buffer for the hostlist address |
109 | */ | 109 | */ |
110 | static char * hostlist_uri; | 110 | static char *hostlist_uri; |
111 | 111 | ||
112 | 112 | ||
113 | /** | 113 | /** |
@@ -125,16 +125,14 @@ finish_response (struct HostSet *results) | |||
125 | #endif | 125 | #endif |
126 | response = MHD_create_response_from_data (results->size, | 126 | response = MHD_create_response_from_data (results->size, |
127 | results->data, MHD_YES, MHD_NO); | 127 | results->data, MHD_YES, MHD_NO); |
128 | if ( (daemon_handle_v4 == NULL) && | 128 | if ((daemon_handle_v4 == NULL) && (daemon_handle_v6 == NULL)) |
129 | (daemon_handle_v6 == NULL) ) | ||
130 | { | 129 | { |
131 | MHD_destroy_response (response); | 130 | MHD_destroy_response (response); |
132 | response = NULL; | 131 | response = NULL; |
133 | } | 132 | } |
134 | GNUNET_STATISTICS_set (stats, | 133 | GNUNET_STATISTICS_set (stats, |
135 | gettext_noop("bytes in hostlist"), | 134 | gettext_noop ("bytes in hostlist"), |
136 | results->size, | 135 | results->size, GNUNET_YES); |
137 | GNUNET_YES); | ||
138 | GNUNET_free (results); | 136 | GNUNET_free (results); |
139 | } | 137 | } |
140 | 138 | ||
@@ -151,21 +149,19 @@ finish_response (struct HostSet *results) | |||
151 | */ | 149 | */ |
152 | static int | 150 | static int |
153 | check_has_addr (void *cls, | 151 | check_has_addr (void *cls, |
154 | const char *tname, | 152 | const char *tname, |
155 | struct GNUNET_TIME_Absolute expiration, | 153 | struct GNUNET_TIME_Absolute expiration, |
156 | const void *addr, | 154 | const void *addr, uint16_t addrlen) |
157 | uint16_t addrlen) | ||
158 | { | 155 | { |
159 | int *arg = cls; | 156 | int *arg = cls; |
160 | 157 | ||
161 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) | 158 | if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) |
162 | { | 159 | { |
163 | GNUNET_STATISTICS_update (stats, | 160 | GNUNET_STATISTICS_update (stats, |
164 | gettext_noop("expired addresses encountered"), | 161 | gettext_noop ("expired addresses encountered"), |
165 | 1, | 162 | 1, GNUNET_YES); |
166 | GNUNET_YES); | 163 | return GNUNET_YES; /* ignore this address */ |
167 | return GNUNET_YES; /* ignore this address */ | 164 | } |
168 | } | ||
169 | *arg = GNUNET_YES; | 165 | *arg = GNUNET_YES; |
170 | return GNUNET_SYSERR; | 166 | return GNUNET_SYSERR; |
171 | } | 167 | } |
@@ -177,74 +173,66 @@ check_has_addr (void *cls, | |||
177 | */ | 173 | */ |
178 | static void | 174 | static void |
179 | host_processor (void *cls, | 175 | host_processor (void *cls, |
180 | const struct GNUNET_PeerIdentity * peer, | 176 | const struct GNUNET_PeerIdentity *peer, |
181 | const struct GNUNET_HELLO_Message *hello, | 177 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
182 | const char *err_msg) | ||
183 | { | 178 | { |
184 | struct HostSet *results = cls; | 179 | struct HostSet *results = cls; |
185 | size_t old; | 180 | size_t old; |
186 | size_t s; | 181 | size_t s; |
187 | int has_addr; | 182 | int has_addr; |
188 | 183 | ||
189 | if (err_msg != NULL) | 184 | if (err_msg != NULL) |
190 | { | 185 | { |
191 | GNUNET_assert (NULL == peer); | 186 | GNUNET_assert (NULL == peer); |
192 | pitr = NULL; | 187 | pitr = NULL; |
193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
194 | _("Error in communication with PEERINFO service: %s\n"), | 189 | _("Error in communication with PEERINFO service: %s\n"), |
195 | err_msg); | 190 | err_msg); |
196 | return; | 191 | return; |
197 | } | 192 | } |
198 | if (peer == NULL) | 193 | if (peer == NULL) |
199 | { | 194 | { |
200 | pitr = NULL; | 195 | pitr = NULL; |
201 | finish_response (results); | 196 | finish_response (results); |
202 | return; | 197 | return; |
203 | } | 198 | } |
204 | if (hello == NULL) | 199 | if (hello == NULL) |
205 | return; | 200 | return; |
206 | has_addr = GNUNET_NO; | 201 | has_addr = GNUNET_NO; |
207 | GNUNET_HELLO_iterate_addresses (hello, | 202 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr); |
208 | GNUNET_NO, | ||
209 | &check_has_addr, | ||
210 | &has_addr); | ||
211 | if (GNUNET_NO == has_addr) | 203 | if (GNUNET_NO == has_addr) |
212 | { | 204 | { |
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
214 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", | 206 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", |
215 | GNUNET_i2s (peer)); | 207 | GNUNET_i2s (peer)); |
216 | GNUNET_STATISTICS_update (stats, | 208 | GNUNET_STATISTICS_update (stats, |
217 | gettext_noop("HELLOs without addresses encountered (ignored)"), | 209 | gettext_noop |
218 | 1, | 210 | ("HELLOs without addresses encountered (ignored)"), |
219 | GNUNET_NO); | 211 | 1, GNUNET_NO); |
220 | return; | 212 | return; |
221 | } | 213 | } |
222 | old = results->size; | 214 | old = results->size; |
223 | s = GNUNET_HELLO_size(hello); | 215 | s = GNUNET_HELLO_size (hello); |
224 | #if DEBUG_HOSTLIST_SERVER | 216 | #if DEBUG_HOSTLIST_SERVER |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
226 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", | 218 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", |
227 | (unsigned int) s, | 219 | (unsigned int) s, "HELLO", GNUNET_i2s (peer)); |
228 | "HELLO", | ||
229 | GNUNET_i2s (peer)); | ||
230 | #endif | 220 | #endif |
231 | if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) || (old + s >= MAX_BYTES_PER_HOSTLISTS) ) | 221 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || |
232 | { | 222 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) |
233 | GNUNET_STATISTICS_update (stats, | 223 | { |
234 | gettext_noop("bytes not included in hostlist (size limit)"), | 224 | GNUNET_STATISTICS_update (stats, |
235 | s, | 225 | gettext_noop |
236 | GNUNET_NO); | 226 | ("bytes not included in hostlist (size limit)"), |
237 | return; /* too large, skip! */ | 227 | s, GNUNET_NO); |
238 | } | 228 | return; /* too large, skip! */ |
229 | } | ||
239 | #if DEBUG_HOSTLIST_SERVER | 230 | #if DEBUG_HOSTLIST_SERVER |
240 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
241 | "Adding peer `%s' to hostlist (%u bytes)\n", | 232 | "Adding peer `%s' to hostlist (%u bytes)\n", |
242 | GNUNET_i2s (peer), | 233 | GNUNET_i2s (peer), (unsigned int) s); |
243 | (unsigned int) s); | ||
244 | #endif | 234 | #endif |
245 | GNUNET_array_grow (results->data, | 235 | GNUNET_array_grow (results->data, results->size, old + s); |
246 | results->size, | ||
247 | old + s); | ||
248 | memcpy (&results->data[old], hello, s); | 236 | memcpy (&results->data[old], hello, s); |
249 | } | 237 | } |
250 | 238 | ||
@@ -258,13 +246,13 @@ accept_policy_callback (void *cls, | |||
258 | const struct sockaddr *addr, socklen_t addrlen) | 246 | const struct sockaddr *addr, socklen_t addrlen) |
259 | { | 247 | { |
260 | if (NULL == response) | 248 | if (NULL == response) |
261 | { | 249 | { |
262 | #if DEBUG_HOSTLIST_SERVER | 250 | #if DEBUG_HOSTLIST_SERVER |
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
264 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | 252 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); |
265 | #endif | 253 | #endif |
266 | return MHD_NO; | 254 | return MHD_NO; |
267 | } | 255 | } |
268 | return MHD_YES; /* accept all */ | 256 | return MHD_YES; /* accept all */ |
269 | } | 257 | } |
270 | 258 | ||
@@ -279,58 +267,54 @@ access_handler_callback (void *cls, | |||
279 | const char *method, | 267 | const char *method, |
280 | const char *version, | 268 | const char *version, |
281 | const char *upload_data, | 269 | const char *upload_data, |
282 | size_t*upload_data_size, void **con_cls) | 270 | size_t * upload_data_size, void **con_cls) |
283 | { | 271 | { |
284 | static int dummy; | 272 | static int dummy; |
285 | 273 | ||
286 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 274 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
287 | { | 275 | { |
288 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 276 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
289 | _("Refusing `%s' request to hostlist server\n"), | 277 | _("Refusing `%s' request to hostlist server\n"), method); |
290 | method); | 278 | GNUNET_STATISTICS_update (stats, |
291 | GNUNET_STATISTICS_update (stats, | 279 | gettext_noop |
292 | gettext_noop("hostlist requests refused (not HTTP GET)"), | 280 | ("hostlist requests refused (not HTTP GET)"), 1, |
293 | 1, | 281 | GNUNET_YES); |
294 | GNUNET_YES); | 282 | return MHD_NO; |
295 | return MHD_NO; | 283 | } |
296 | } | ||
297 | if (NULL == *con_cls) | 284 | if (NULL == *con_cls) |
298 | { | 285 | { |
299 | (*con_cls) = &dummy; | 286 | (*con_cls) = &dummy; |
300 | #if DEBUG_HOSTLIST_SERVER | 287 | #if DEBUG_HOSTLIST_SERVER |
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Sending 100 CONTINUE reply\n")); |
302 | _("Sending 100 CONTINUE reply\n")); | ||
303 | #endif | 289 | #endif |
304 | return MHD_YES; /* send 100 continue */ | 290 | return MHD_YES; /* send 100 continue */ |
305 | } | 291 | } |
306 | if (*upload_data_size != 0) | 292 | if (*upload_data_size != 0) |
307 | { | 293 | { |
308 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
309 | _("Refusing `%s' request with %llu bytes of upload data\n"), | 295 | _("Refusing `%s' request with %llu bytes of upload data\n"), |
310 | method, | 296 | method, (unsigned long long) *upload_data_size); |
311 | (unsigned long long) *upload_data_size); | 297 | GNUNET_STATISTICS_update (stats, |
312 | GNUNET_STATISTICS_update (stats, | 298 | gettext_noop |
313 | gettext_noop("hostlist requests refused (upload data)"), | 299 | ("hostlist requests refused (upload data)"), 1, |
314 | 1, | 300 | GNUNET_YES); |
315 | GNUNET_YES); | 301 | return MHD_NO; /* do not support upload data */ |
316 | return MHD_NO; /* do not support upload data */ | 302 | } |
317 | } | ||
318 | if (response == NULL) | 303 | if (response == NULL) |
319 | { | 304 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 305 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
321 | _("Could not handle hostlist request since I do not have a response yet\n")); | 306 | _ |
322 | GNUNET_STATISTICS_update (stats, | 307 | ("Could not handle hostlist request since I do not have a response yet\n")); |
323 | gettext_noop("hostlist requests refused (not ready)"), | 308 | GNUNET_STATISTICS_update (stats, |
324 | 1, | 309 | gettext_noop |
325 | GNUNET_YES); | 310 | ("hostlist requests refused (not ready)"), 1, |
326 | return MHD_NO; /* internal error, no response yet */ | 311 | GNUNET_YES); |
327 | } | 312 | return MHD_NO; /* internal error, no response yet */ |
328 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | } |
329 | _("Received request for our hostlist\n")); | 314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n")); |
330 | GNUNET_STATISTICS_update (stats, | 315 | GNUNET_STATISTICS_update (stats, |
331 | gettext_noop("hostlist requests processed"), | 316 | gettext_noop ("hostlist requests processed"), |
332 | 1, | 317 | 1, GNUNET_YES); |
333 | GNUNET_YES); | ||
334 | return MHD_queue_response (connection, MHD_HTTP_OK, response); | 318 | return MHD_queue_response (connection, MHD_HTTP_OK, response); |
335 | } | 319 | } |
336 | 320 | ||
@@ -342,41 +326,38 @@ access_handler_callback (void *cls, | |||
342 | * @param buf buffer to copy message to | 326 | * @param buf buffer to copy message to |
343 | */ | 327 | */ |
344 | static size_t | 328 | static size_t |
345 | adv_transmit_ready ( void *cls, size_t size, void *buf) | 329 | adv_transmit_ready (void *cls, size_t size, void *buf) |
346 | { | 330 | { |
347 | static uint64_t hostlist_adv_count; | 331 | static uint64_t hostlist_adv_count; |
348 | 332 | ||
349 | size_t transmission_size; | 333 | size_t transmission_size; |
350 | size_t uri_size; /* Including \0 termination! */ | 334 | size_t uri_size; /* Including \0 termination! */ |
351 | struct GNUNET_MessageHeader header; | 335 | struct GNUNET_MessageHeader header; |
352 | char *cbuf; | 336 | char *cbuf; |
353 | 337 | ||
354 | if (buf == NULL) | 338 | if (buf == NULL) |
355 | { | 339 | { |
356 | GNUNET_log ( GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
357 | "Transmission failed, buffer invalid!\n" ); | 341 | "Transmission failed, buffer invalid!\n"); |
358 | return 0; | 342 | return 0; |
359 | } | 343 | } |
360 | uri_size = strlen ( hostlist_uri ) + 1; | 344 | uri_size = strlen (hostlist_uri) + 1; |
361 | transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size; | 345 | transmission_size = sizeof (struct GNUNET_MessageHeader) + uri_size; |
362 | header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 346 | header.type = htons (GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
363 | header.size = htons (transmission_size); | 347 | header.size = htons (transmission_size); |
364 | GNUNET_assert (size >= transmission_size); | 348 | GNUNET_assert (size >= transmission_size); |
365 | memcpy (buf, &header, sizeof (struct GNUNET_MessageHeader)); | 349 | memcpy (buf, &header, sizeof (struct GNUNET_MessageHeader)); |
366 | cbuf = buf; | 350 | cbuf = buf; |
367 | memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)], | 351 | memcpy (&cbuf[sizeof (struct GNUNET_MessageHeader)], hostlist_uri, uri_size); |
368 | hostlist_uri, uri_size); | 352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 353 | "Sent advertisement message: Copied %u bytes into buffer!\n", |
370 | "Sent advertisement message: Copied %u bytes into buffer!\n", | 354 | (unsigned int) transmission_size); |
371 | (unsigned int) transmission_size); | ||
372 | hostlist_adv_count++; | 355 | hostlist_adv_count++; |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
374 | " # Sent advertisement message: %u\n", | 357 | " # Sent advertisement message: %u\n", hostlist_adv_count); |
375 | hostlist_adv_count); | ||
376 | GNUNET_STATISTICS_update (stats, | 358 | GNUNET_STATISTICS_update (stats, |
377 | gettext_noop("# hostlist advertisements send"), | 359 | gettext_noop ("# hostlist advertisements send"), |
378 | 1, | 360 | 1, GNUNET_NO); |
379 | GNUNET_NO); | ||
380 | return transmission_size; | 361 | return transmission_size; |
381 | } | 362 | } |
382 | 363 | ||
@@ -391,41 +372,42 @@ adv_transmit_ready ( void *cls, size_t size, void *buf) | |||
391 | static void | 372 | static void |
392 | connect_handler (void *cls, | 373 | connect_handler (void *cls, |
393 | const struct | 374 | const struct |
394 | GNUNET_PeerIdentity * peer, | 375 | GNUNET_PeerIdentity *peer, |
395 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 376 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
396 | { | 377 | { |
397 | size_t size; | 378 | size_t size; |
398 | 379 | ||
399 | if ( !advertising ) | 380 | if (!advertising) |
400 | return; | 381 | return; |
401 | if (hostlist_uri == NULL) | 382 | if (hostlist_uri == NULL) |
402 | return; | 383 | return; |
403 | size = strlen (hostlist_uri) + 1; | 384 | size = strlen (hostlist_uri) + 1; |
404 | if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 385 | if (size + sizeof (struct GNUNET_MessageHeader) >= |
405 | { | 386 | GNUNET_SERVER_MAX_MESSAGE_SIZE) |
406 | GNUNET_break (0); | 387 | { |
407 | return; | 388 | GNUNET_break (0); |
408 | } | 389 | return; |
390 | } | ||
409 | size += sizeof (struct GNUNET_MessageHeader); | 391 | size += sizeof (struct GNUNET_MessageHeader); |
410 | if (NULL == core) | 392 | if (NULL == core) |
411 | { | 393 | { |
412 | GNUNET_break (0); | 394 | GNUNET_break (0); |
413 | return; | 395 | return; |
414 | } | 396 | } |
415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
416 | "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n", | 398 | "Asked core to transmit advertisement message with a size of %u bytes to peer `%s'\n", |
417 | size,GNUNET_i2s(peer)); | 399 | size, GNUNET_i2s (peer)); |
418 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 400 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, |
419 | GNUNET_YES, | 401 | GNUNET_YES, |
420 | 0, | 402 | 0, |
421 | GNUNET_ADV_TIMEOUT, | 403 | GNUNET_ADV_TIMEOUT, |
422 | peer, | 404 | peer, |
423 | size, | 405 | size, |
424 | &adv_transmit_ready, NULL)) | 406 | &adv_transmit_ready, NULL)) |
425 | { | 407 | { |
426 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
427 | _("Advertisement message could not be queued by core\n")); | 409 | _("Advertisement message could not be queued by core\n")); |
428 | } | 410 | } |
429 | } | 411 | } |
430 | 412 | ||
431 | 413 | ||
@@ -436,9 +418,7 @@ connect_handler (void *cls, | |||
436 | * @param peer peer identity this notification is about | 418 | * @param peer peer identity this notification is about |
437 | */ | 419 | */ |
438 | static void | 420 | static void |
439 | disconnect_handler (void *cls, | 421 | disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) |
440 | const struct | ||
441 | GNUNET_PeerIdentity * peer) | ||
442 | { | 422 | { |
443 | /* nothing to do */ | 423 | /* nothing to do */ |
444 | } | 424 | } |
@@ -455,27 +435,26 @@ disconnect_handler (void *cls, | |||
455 | static void | 435 | static void |
456 | process_notify (void *cls, | 436 | process_notify (void *cls, |
457 | const struct GNUNET_PeerIdentity *peer, | 437 | const struct GNUNET_PeerIdentity *peer, |
458 | const struct GNUNET_HELLO_Message *hello, | 438 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
459 | const char *err_msg) | ||
460 | { | 439 | { |
461 | struct HostSet *results; | 440 | struct HostSet *results; |
441 | |||
462 | #if DEBUG_HOSTLIST_SERVER | 442 | #if DEBUG_HOSTLIST_SERVER |
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
464 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 444 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
465 | #endif | 445 | #endif |
466 | if (err_msg != NULL) | 446 | if (err_msg != NULL) |
467 | { | 447 | { |
468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 448 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
469 | _("Error in communication with PEERINFO service\n")); | 449 | _("Error in communication with PEERINFO service\n")); |
470 | /* return; */ | 450 | /* return; */ |
471 | } | 451 | } |
472 | results = GNUNET_malloc(sizeof(struct HostSet)); | 452 | results = GNUNET_malloc (sizeof (struct HostSet)); |
473 | GNUNET_assert (peerinfo != NULL); | 453 | GNUNET_assert (peerinfo != NULL); |
474 | pitr = GNUNET_PEERINFO_iterate (peerinfo, | 454 | pitr = GNUNET_PEERINFO_iterate (peerinfo, |
475 | NULL, | 455 | NULL, |
476 | GNUNET_TIME_UNIT_MINUTES, | 456 | GNUNET_TIME_UNIT_MINUTES, |
477 | &host_processor, | 457 | &host_processor, results); |
478 | results); | ||
479 | } | 458 | } |
480 | 459 | ||
481 | /** | 460 | /** |
@@ -491,8 +470,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle); | |||
491 | * and schedule the next run. | 470 | * and schedule the next run. |
492 | */ | 471 | */ |
493 | static void | 472 | static void |
494 | run_daemon (void *cls, | 473 | run_daemon (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
495 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
496 | { | 474 | { |
497 | struct MHD_Daemon *daemon_handle = cls; | 475 | struct MHD_Daemon *daemon_handle = cls; |
498 | 476 | ||
@@ -502,7 +480,7 @@ run_daemon (void *cls, | |||
502 | hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 480 | hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
503 | 481 | ||
504 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 482 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
505 | return; | 483 | return; |
506 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); | 484 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); |
507 | if (daemon_handle == daemon_handle_v4) | 485 | if (daemon_handle == daemon_handle_v4) |
508 | hostlist_task_v4 = prepare_daemon (daemon_handle); | 486 | hostlist_task_v4 = prepare_daemon (daemon_handle); |
@@ -529,20 +507,15 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
529 | unsigned long long timeout; | 507 | unsigned long long timeout; |
530 | int haveto; | 508 | int haveto; |
531 | struct GNUNET_TIME_Relative tv; | 509 | struct GNUNET_TIME_Relative tv; |
532 | 510 | ||
533 | FD_ZERO(&rs); | 511 | FD_ZERO (&rs); |
534 | FD_ZERO(&ws); | 512 | FD_ZERO (&ws); |
535 | FD_ZERO(&es); | 513 | FD_ZERO (&es); |
536 | wrs = GNUNET_NETWORK_fdset_create (); | 514 | wrs = GNUNET_NETWORK_fdset_create (); |
537 | wes = GNUNET_NETWORK_fdset_create (); | 515 | wes = GNUNET_NETWORK_fdset_create (); |
538 | wws = GNUNET_NETWORK_fdset_create (); | 516 | wws = GNUNET_NETWORK_fdset_create (); |
539 | max = -1; | 517 | max = -1; |
540 | GNUNET_assert (MHD_YES == | 518 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); |
541 | MHD_get_fdset (daemon_handle, | ||
542 | &rs, | ||
543 | &ws, | ||
544 | &es, | ||
545 | &max)); | ||
546 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 519 | haveto = MHD_get_timeout (daemon_handle, &timeout); |
547 | if (haveto == MHD_YES) | 520 | if (haveto == MHD_YES) |
548 | tv.rel_value = (uint64_t) timeout; | 521 | tv.rel_value = (uint64_t) timeout; |
@@ -552,12 +525,8 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
552 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 525 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); |
553 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); | 526 | GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); |
554 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 527 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
555 | GNUNET_SCHEDULER_NO_TASK, | 528 | GNUNET_SCHEDULER_NO_TASK, |
556 | tv, | 529 | tv, wrs, wws, &run_daemon, daemon_handle); |
557 | wrs, | ||
558 | wws, | ||
559 | &run_daemon, | ||
560 | daemon_handle); | ||
561 | GNUNET_NETWORK_fdset_destroy (wrs); | 530 | GNUNET_NETWORK_fdset_destroy (wrs); |
562 | GNUNET_NETWORK_fdset_destroy (wws); | 531 | GNUNET_NETWORK_fdset_destroy (wws); |
563 | GNUNET_NETWORK_fdset_destroy (wes); | 532 | GNUNET_NETWORK_fdset_destroy (wes); |
@@ -573,9 +542,9 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
573 | */ | 542 | */ |
574 | int | 543 | int |
575 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | 544 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, |
576 | struct GNUNET_STATISTICS_Handle *st, | 545 | struct GNUNET_STATISTICS_Handle *st, |
577 | struct GNUNET_CORE_Handle *co, | 546 | struct GNUNET_CORE_Handle *co, |
578 | GNUNET_CORE_ConnectEventHandler *server_ch, | 547 | GNUNET_CORE_ConnectEventHandler *server_ch, |
579 | GNUNET_CORE_DisconnectEventHandler *server_dh, | 548 | GNUNET_CORE_DisconnectEventHandler *server_dh, |
580 | int advertise) | 549 | int advertise) |
581 | { | 550 | { |
@@ -584,102 +553,100 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
584 | size_t size; | 553 | size_t size; |
585 | 554 | ||
586 | advertising = advertise; | 555 | advertising = advertise; |
587 | if ( !advertising ) | 556 | if (!advertising) |
588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
589 | "Advertising not enabled on this hostlist server\n"); | 558 | "Advertising not enabled on this hostlist server\n"); |
590 | else | 559 | else |
591 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 560 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
592 | "Advertising enabled on this hostlist server\n"); | 561 | "Advertising enabled on this hostlist server\n"); |
593 | cfg = c; | 562 | cfg = c; |
594 | stats = st; | 563 | stats = st; |
595 | peerinfo = GNUNET_PEERINFO_connect (cfg); | 564 | peerinfo = GNUNET_PEERINFO_connect (cfg); |
596 | if (peerinfo == NULL) | 565 | if (peerinfo == NULL) |
597 | { | 566 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 567 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
599 | _("Could not access PEERINFO service. Exiting.\n")); | 568 | _("Could not access PEERINFO service. Exiting.\n")); |
600 | return GNUNET_SYSERR; | 569 | return GNUNET_SYSERR; |
601 | } | 570 | } |
602 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | 571 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
603 | "HOSTLIST", | 572 | "HOSTLIST", |
604 | "HTTPPORT", | 573 | "HTTPPORT", &port)) |
605 | &port)) | ||
606 | return GNUNET_SYSERR; | 574 | return GNUNET_SYSERR; |
607 | if ( (port == 0) || | 575 | if ((port == 0) || (port > UINT16_MAX)) |
608 | (port > UINT16_MAX) ) | 576 | { |
609 | { | 577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
610 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 578 | _("Invalid port number %llu. Exiting.\n"), port); |
611 | _("Invalid port number %llu. Exiting.\n"), | 579 | return GNUNET_SYSERR; |
612 | port); | 580 | } |
613 | return GNUNET_SYSERR; | ||
614 | } | ||
615 | 581 | ||
616 | if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 582 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, |
617 | "HOSTLIST", | 583 | "HOSTLIST", |
618 | "EXTERNAL_DNS_NAME", | 584 | "EXTERNAL_DNS_NAME", |
619 | &hostname)) | 585 | &hostname)) |
620 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 586 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
621 | 587 | ||
622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 588 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
623 | _("Hostlist service starts on %s:%llu\n"), | 589 | _("Hostlist service starts on %s:%llu\n"), hostname, port); |
624 | hostname, port); | ||
625 | if (NULL != hostname) | 590 | if (NULL != hostname) |
591 | { | ||
592 | size = strlen (hostname); | ||
593 | if (size + 15 > MAX_URL_LEN) | ||
626 | { | 594 | { |
627 | size = strlen (hostname); | 595 | GNUNET_break (0); |
628 | if (size + 15 > MAX_URL_LEN) | ||
629 | { | ||
630 | GNUNET_break (0); | ||
631 | } | ||
632 | else | ||
633 | { | ||
634 | GNUNET_asprintf (&hostlist_uri, | ||
635 | "http://%s:%u/", | ||
636 | hostname, | ||
637 | (unsigned int) port); | ||
638 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
639 | _("Address to obtain hostlist: `%s'\n"), | ||
640 | hostlist_uri); | ||
641 | } | ||
642 | GNUNET_free ( hostname ); | ||
643 | } | 596 | } |
644 | daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | 597 | else |
598 | { | ||
599 | GNUNET_asprintf (&hostlist_uri, | ||
600 | "http://%s:%u/", hostname, (unsigned int) port); | ||
601 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
602 | _("Address to obtain hostlist: `%s'\n"), hostlist_uri); | ||
603 | } | ||
604 | GNUNET_free (hostname); | ||
605 | } | ||
606 | daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | ||
645 | #if DEBUG_HOSTLIST_SERVER | 607 | #if DEBUG_HOSTLIST_SERVER |
646 | | MHD_USE_DEBUG | 608 | | MHD_USE_DEBUG |
647 | #endif | 609 | #endif |
648 | , | 610 | , |
649 | (unsigned short) port, | 611 | (unsigned short) port, |
650 | &accept_policy_callback, | 612 | &accept_policy_callback, |
651 | NULL, | 613 | NULL, |
652 | &access_handler_callback, | 614 | &access_handler_callback, |
653 | NULL, | 615 | NULL, |
654 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, | 616 | MHD_OPTION_CONNECTION_LIMIT, |
655 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 617 | (unsigned int) 16, |
656 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 618 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
657 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), | 619 | (unsigned int) 1, |
658 | MHD_OPTION_END); | 620 | MHD_OPTION_CONNECTION_TIMEOUT, |
621 | (unsigned int) 16, | ||
622 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | ||
623 | (size_t) (16 * 1024), MHD_OPTION_END); | ||
659 | daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | 624 | daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG |
660 | #if DEBUG_HOSTLIST_SERVER | 625 | #if DEBUG_HOSTLIST_SERVER |
661 | | MHD_USE_DEBUG | 626 | | MHD_USE_DEBUG |
662 | #endif | 627 | #endif |
663 | , | 628 | , |
664 | (unsigned short) port, | 629 | (unsigned short) port, |
665 | &accept_policy_callback, | 630 | &accept_policy_callback, |
666 | NULL, | 631 | NULL, |
667 | &access_handler_callback, | 632 | &access_handler_callback, |
668 | NULL, | 633 | NULL, |
669 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 16, | 634 | MHD_OPTION_CONNECTION_LIMIT, |
670 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | 635 | (unsigned int) 16, |
671 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | 636 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
672 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (16 * 1024), | 637 | (unsigned int) 1, |
673 | MHD_OPTION_END); | 638 | MHD_OPTION_CONNECTION_TIMEOUT, |
674 | 639 | (unsigned int) 16, | |
675 | if ( (daemon_handle_v6 == NULL) && | 640 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
676 | (daemon_handle_v4 == NULL) ) | 641 | (size_t) (16 * 1024), MHD_OPTION_END); |
677 | { | 642 | |
678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 643 | if ((daemon_handle_v6 == NULL) && (daemon_handle_v4 == NULL)) |
679 | _("Could not start hostlist HTTP server on port %u\n"), | 644 | { |
680 | (unsigned short) port); | 645 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
681 | return GNUNET_SYSERR; | 646 | _("Could not start hostlist HTTP server on port %u\n"), |
682 | } | 647 | (unsigned short) port); |
648 | return GNUNET_SYSERR; | ||
649 | } | ||
683 | 650 | ||
684 | core = co; | 651 | core = co; |
685 | 652 | ||
@@ -691,7 +658,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
691 | if (daemon_handle_v6 != NULL) | 658 | if (daemon_handle_v6 != NULL) |
692 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); | 659 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); |
693 | 660 | ||
694 | notify = GNUNET_PEERINFO_notify ( cfg, process_notify, NULL); | 661 | notify = GNUNET_PEERINFO_notify (cfg, process_notify, NULL); |
695 | 662 | ||
696 | return GNUNET_OK; | 663 | return GNUNET_OK; |
697 | } | 664 | } |
@@ -703,49 +670,48 @@ void | |||
703 | GNUNET_HOSTLIST_server_stop () | 670 | GNUNET_HOSTLIST_server_stop () |
704 | { | 671 | { |
705 | #if DEBUG_HOSTLIST_SERVER | 672 | #if DEBUG_HOSTLIST_SERVER |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); |
707 | "Hostlist server shutdown\n"); | ||
708 | #endif | 674 | #endif |
709 | if (NULL != notify) | 675 | if (NULL != notify) |
710 | { | 676 | { |
711 | GNUNET_PEERINFO_notify_cancel (notify); | 677 | GNUNET_PEERINFO_notify_cancel (notify); |
712 | notify = NULL; | 678 | notify = NULL; |
713 | } | 679 | } |
714 | if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6) | 680 | if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v6) |
715 | { | 681 | { |
716 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); | 682 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); |
717 | hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; | 683 | hostlist_task_v6 = GNUNET_SCHEDULER_NO_TASK; |
718 | } | 684 | } |
719 | if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4) | 685 | if (GNUNET_SCHEDULER_NO_TASK != hostlist_task_v4) |
720 | { | 686 | { |
721 | GNUNET_SCHEDULER_cancel (hostlist_task_v4); | 687 | GNUNET_SCHEDULER_cancel (hostlist_task_v4); |
722 | hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK; | 688 | hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK; |
723 | } | 689 | } |
724 | if (pitr != NULL) | 690 | if (pitr != NULL) |
725 | { | 691 | { |
726 | GNUNET_PEERINFO_iterate_cancel (pitr); | 692 | GNUNET_PEERINFO_iterate_cancel (pitr); |
727 | pitr = NULL; | 693 | pitr = NULL; |
728 | } | 694 | } |
729 | if (NULL != daemon_handle_v4) | 695 | if (NULL != daemon_handle_v4) |
730 | { | 696 | { |
731 | MHD_stop_daemon (daemon_handle_v4); | 697 | MHD_stop_daemon (daemon_handle_v4); |
732 | daemon_handle_v4 = NULL; | 698 | daemon_handle_v4 = NULL; |
733 | } | 699 | } |
734 | if (NULL != daemon_handle_v6) | 700 | if (NULL != daemon_handle_v6) |
735 | { | 701 | { |
736 | MHD_stop_daemon (daemon_handle_v6); | 702 | MHD_stop_daemon (daemon_handle_v6); |
737 | daemon_handle_v6 = NULL; | 703 | daemon_handle_v6 = NULL; |
738 | } | 704 | } |
739 | if (response != NULL) | 705 | if (response != NULL) |
740 | { | 706 | { |
741 | MHD_destroy_response (response); | 707 | MHD_destroy_response (response); |
742 | response = NULL; | 708 | response = NULL; |
743 | } | 709 | } |
744 | if (peerinfo != NULL) | 710 | if (peerinfo != NULL) |
745 | { | 711 | { |
746 | GNUNET_PEERINFO_disconnect (peerinfo); | 712 | GNUNET_PEERINFO_disconnect (peerinfo); |
747 | peerinfo = NULL; | 713 | peerinfo = NULL; |
748 | } | 714 | } |
749 | cfg = NULL; | 715 | cfg = NULL; |
750 | stats = NULL; | 716 | stats = NULL; |
751 | core = NULL; | 717 | core = NULL; |
diff --git a/src/hostlist/hostlist-server.h b/src/hostlist/hostlist-server.h index 98ce2179b..7b7e37a4d 100644 --- a/src/hostlist/hostlist-server.h +++ b/src/hostlist/hostlist-server.h | |||
@@ -40,18 +40,17 @@ | |||
40 | */ | 40 | */ |
41 | int | 41 | int |
42 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | 42 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, |
43 | struct GNUNET_STATISTICS_Handle *st, | 43 | struct GNUNET_STATISTICS_Handle *st, |
44 | struct GNUNET_CORE_Handle *core, | 44 | struct GNUNET_CORE_Handle *core, |
45 | GNUNET_CORE_ConnectEventHandler *server_ch, | 45 | GNUNET_CORE_ConnectEventHandler *server_ch, |
46 | GNUNET_CORE_DisconnectEventHandler *server_dh, | 46 | GNUNET_CORE_DisconnectEventHandler *server_dh, |
47 | int advertise); | 47 | int advertise); |
48 | 48 | ||
49 | 49 | ||
50 | /** | 50 | /** |
51 | * Stop server offering our hostlist. | 51 | * Stop server offering our hostlist. |
52 | */ | 52 | */ |
53 | void | 53 | void GNUNET_HOSTLIST_server_stop (void); |
54 | GNUNET_HOSTLIST_server_stop (void); | ||
55 | 54 | ||
56 | 55 | ||
57 | #endif | 56 | #endif |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 7e42dda59..5cca8becd 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c | |||
@@ -40,7 +40,7 @@ | |||
40 | static int ok; | 40 | static int ok; |
41 | 41 | ||
42 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 42 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
43 | 43 | ||
44 | struct PeerContext | 44 | struct PeerContext |
45 | { | 45 | { |
46 | struct GNUNET_CONFIGURATION_Handle *cfg; | 46 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -60,15 +60,15 @@ static void | |||
60 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 60 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
61 | { | 61 | { |
62 | if (p1.th != NULL) | 62 | if (p1.th != NULL) |
63 | { | 63 | { |
64 | GNUNET_TRANSPORT_disconnect (p1.th); | 64 | GNUNET_TRANSPORT_disconnect (p1.th); |
65 | p1.th = NULL; | 65 | p1.th = NULL; |
66 | } | 66 | } |
67 | if (p2.th != NULL) | 67 | if (p2.th != NULL) |
68 | { | 68 | { |
69 | GNUNET_TRANSPORT_disconnect (p2.th); | 69 | GNUNET_TRANSPORT_disconnect (p2.th); |
70 | p2.th = NULL; | 70 | p2.th = NULL; |
71 | } | 71 | } |
72 | GNUNET_SCHEDULER_shutdown (); | 72 | GNUNET_SCHEDULER_shutdown (); |
73 | } | 73 | } |
74 | 74 | ||
@@ -80,7 +80,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
80 | { | 80 | { |
81 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 81 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
82 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
83 | "Timeout trying to connect peers, test failed.\n"); | 83 | "Timeout trying to connect peers, test failed.\n"); |
84 | clean_up (NULL, tc); | 84 | clean_up (NULL, tc); |
85 | } | 85 | } |
86 | 86 | ||
@@ -96,32 +96,31 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
96 | */ | 96 | */ |
97 | static void | 97 | static void |
98 | notify_connect (void *cls, | 98 | notify_connect (void *cls, |
99 | const struct GNUNET_PeerIdentity * peer, | 99 | const struct GNUNET_PeerIdentity *peer, |
100 | const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) | 100 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
101 | uint32_t ats_count) | ||
101 | { | 102 | { |
102 | if (peer == NULL) | 103 | if (peer == NULL) |
103 | return; | 104 | return; |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
105 | "Peers connected, shutting down.\n"); | ||
106 | ok = 0; | 106 | ok = 0; |
107 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 107 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
108 | { | 108 | { |
109 | GNUNET_SCHEDULER_cancel (timeout_task); | 109 | GNUNET_SCHEDULER_cancel (timeout_task); |
110 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 110 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
111 | } | 111 | } |
112 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 112 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | static void | 116 | static void |
117 | process_hello (void *cls, | 117 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
118 | const struct GNUNET_MessageHeader *message) | ||
119 | { | 118 | { |
120 | struct PeerContext *p = cls; | 119 | struct PeerContext *p = cls; |
121 | 120 | ||
122 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); | 121 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); |
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
124 | "Received HELLO, starting hostlist service.\n"); | 123 | "Received HELLO, starting hostlist service.\n"); |
125 | } | 124 | } |
126 | 125 | ||
127 | 126 | ||
@@ -131,35 +130,34 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
131 | p->cfg = GNUNET_CONFIGURATION_create (); | 130 | p->cfg = GNUNET_CONFIGURATION_create (); |
132 | #if START_ARM | 131 | #if START_ARM |
133 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 132 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
134 | "gnunet-service-arm", | 133 | "gnunet-service-arm", |
135 | #if VERBOSE | 134 | #if VERBOSE |
136 | "-L", "DEBUG", | 135 | "-L", "DEBUG", |
137 | #endif | 136 | #endif |
138 | "-c", cfgname, NULL); | 137 | "-c", cfgname, NULL); |
139 | #endif | 138 | #endif |
140 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 139 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
141 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, | 140 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, |
142 | ¬ify_connect, NULL); | 141 | ¬ify_connect, NULL); |
143 | GNUNET_assert (p->th != NULL); | 142 | GNUNET_assert (p->th != NULL); |
144 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 143 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
145 | } | 144 | } |
146 | 145 | ||
147 | 146 | ||
148 | static void | 147 | static void |
149 | waitpid_task (void *cls, | 148 | waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
150 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
151 | { | 149 | { |
152 | struct PeerContext *p = cls; | 150 | struct PeerContext *p = cls; |
153 | 151 | ||
154 | #if START_ARM | 152 | #if START_ARM |
155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
156 | "Killing ARM process.\n"); | ||
157 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 154 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 155 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
159 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 156 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
160 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 157 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
162 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 159 | "ARM process %u stopped\n", |
160 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
163 | GNUNET_OS_process_close (p->arm_proc); | 161 | GNUNET_OS_process_close (p->arm_proc); |
164 | p->arm_proc = NULL; | 162 | p->arm_proc = NULL; |
165 | #endif | 163 | #endif |
@@ -170,10 +168,8 @@ waitpid_task (void *cls, | |||
170 | static void | 168 | static void |
171 | stop_arm (struct PeerContext *p) | 169 | stop_arm (struct PeerContext *p) |
172 | { | 170 | { |
173 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
174 | "Asking ARM to stop core service\n"); | 172 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
175 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
176 | &waitpid_task, p); | ||
177 | } | 173 | } |
178 | 174 | ||
179 | 175 | ||
@@ -191,17 +187,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
191 | static void | 187 | static void |
192 | run (void *cls, | 188 | run (void *cls, |
193 | char *const *args, | 189 | char *const *args, |
194 | const char *cfgfile, | 190 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
195 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
196 | { | 191 | { |
197 | GNUNET_assert (ok == 1); | 192 | GNUNET_assert (ok == 1); |
198 | ok++; | 193 | ok++; |
199 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 194 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
200 | &timeout_error, | ||
201 | NULL); | ||
202 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 195 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
203 | &shutdown_task, | 196 | &shutdown_task, NULL); |
204 | NULL); | ||
205 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 197 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
206 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 198 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
207 | } | 199 | } |
@@ -223,7 +215,7 @@ check () | |||
223 | ok = 1; | 215 | ok = 1; |
224 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 216 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
225 | argv, "test-gnunet-daemon-hostlist", | 217 | argv, "test-gnunet-daemon-hostlist", |
226 | "nohelp", options, &run, &ok); | 218 | "nohelp", options, &run, &ok); |
227 | return ok; | 219 | return ok; |
228 | } | 220 | } |
229 | 221 | ||
@@ -231,7 +223,7 @@ check () | |||
231 | int | 223 | int |
232 | main (int argc, char *argv[]) | 224 | main (int argc, char *argv[]) |
233 | { | 225 | { |
234 | 226 | ||
235 | int ret; | 227 | int ret; |
236 | 228 | ||
237 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 229 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
@@ -248,7 +240,7 @@ main (int argc, char *argv[]) | |||
248 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 240 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
249 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); | 241 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); |
250 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist"); | 242 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist"); |
251 | return ret; | 243 | return ret; |
252 | } | 244 | } |
253 | 245 | ||
254 | /* end of test_gnunet_daemon_hostlist.c */ | 246 | /* end of test_gnunet_daemon_hostlist.c */ |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index f821a7320..7ecca8a85 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c | |||
@@ -43,7 +43,7 @@ | |||
43 | 43 | ||
44 | #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | 44 | #define CHECK_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
45 | 45 | ||
46 | 46 | ||
47 | struct PeerContext | 47 | struct PeerContext |
48 | { | 48 | { |
49 | struct GNUNET_CONFIGURATION_Handle *cfg; | 49 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -66,7 +66,7 @@ static int learned_hostlist_saved; | |||
66 | 66 | ||
67 | static int learned_hostlist_downloaded; | 67 | static int learned_hostlist_downloaded; |
68 | 68 | ||
69 | static char * current_adv_uri; | 69 | static char *current_adv_uri; |
70 | 70 | ||
71 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 71 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
72 | 72 | ||
@@ -78,106 +78,99 @@ static struct PeerContext adv_peer; | |||
78 | 78 | ||
79 | static struct PeerContext learn_peer; | 79 | static struct PeerContext learn_peer; |
80 | 80 | ||
81 | static struct GNUNET_STATISTICS_GetHandle * download_stats; | 81 | static struct GNUNET_STATISTICS_GetHandle *download_stats; |
82 | 82 | ||
83 | static struct GNUNET_STATISTICS_GetHandle * urisrecv_stat; | 83 | static struct GNUNET_STATISTICS_GetHandle *urisrecv_stat; |
84 | 84 | ||
85 | static struct GNUNET_STATISTICS_GetHandle * advsent_stat; | 85 | static struct GNUNET_STATISTICS_GetHandle *advsent_stat; |
86 | 86 | ||
87 | 87 | ||
88 | static void | 88 | static void |
89 | shutdown_testcase() | 89 | shutdown_testcase () |
90 | { | 90 | { |
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown testcase....\n"); |
92 | "Shutdown testcase....\n"); | ||
93 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 92 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
94 | { | 93 | { |
95 | GNUNET_SCHEDULER_cancel (timeout_task); | 94 | GNUNET_SCHEDULER_cancel (timeout_task); |
96 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 95 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
97 | } | 96 | } |
98 | if (NULL != download_stats) | 97 | if (NULL != download_stats) |
99 | { | 98 | { |
100 | GNUNET_STATISTICS_get_cancel (download_stats); | 99 | GNUNET_STATISTICS_get_cancel (download_stats); |
101 | download_stats = NULL; | 100 | download_stats = NULL; |
102 | } | 101 | } |
103 | if (NULL != urisrecv_stat) | 102 | if (NULL != urisrecv_stat) |
104 | { | 103 | { |
105 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 104 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
106 | urisrecv_stat = NULL; | 105 | urisrecv_stat = NULL; |
107 | } | 106 | } |
108 | if (NULL != advsent_stat) | 107 | if (NULL != advsent_stat) |
109 | { | 108 | { |
110 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 109 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
111 | advsent_stat = NULL; | 110 | advsent_stat = NULL; |
112 | } | 111 | } |
113 | if (check_task != GNUNET_SCHEDULER_NO_TASK) | 112 | if (check_task != GNUNET_SCHEDULER_NO_TASK) |
114 | { | 113 | { |
115 | GNUNET_SCHEDULER_cancel (check_task); | 114 | GNUNET_SCHEDULER_cancel (check_task); |
116 | check_task = GNUNET_SCHEDULER_NO_TASK; | 115 | check_task = GNUNET_SCHEDULER_NO_TASK; |
117 | } | 116 | } |
118 | if (NULL != current_adv_uri) | 117 | if (NULL != current_adv_uri) |
119 | { | 118 | { |
120 | GNUNET_free (current_adv_uri); | 119 | GNUNET_free (current_adv_uri); |
121 | current_adv_uri = NULL; | 120 | current_adv_uri = NULL; |
122 | } | 121 | } |
123 | if (adv_peer.th != NULL) | 122 | if (adv_peer.th != NULL) |
124 | { | 123 | { |
125 | GNUNET_TRANSPORT_disconnect (adv_peer.th); | 124 | GNUNET_TRANSPORT_disconnect (adv_peer.th); |
126 | adv_peer.th = NULL; | 125 | adv_peer.th = NULL; |
127 | } | 126 | } |
128 | if (learn_peer.th != NULL) | 127 | if (learn_peer.th != NULL) |
129 | { | 128 | { |
130 | GNUNET_TRANSPORT_disconnect (learn_peer.th); | 129 | GNUNET_TRANSPORT_disconnect (learn_peer.th); |
131 | learn_peer.th = NULL; | 130 | learn_peer.th = NULL; |
132 | } | 131 | } |
133 | if (adv_peer.core != NULL) | 132 | if (adv_peer.core != NULL) |
134 | { | 133 | { |
135 | GNUNET_CORE_disconnect (adv_peer.core); | 134 | GNUNET_CORE_disconnect (adv_peer.core); |
136 | adv_peer.core = NULL; | 135 | adv_peer.core = NULL; |
137 | } | 136 | } |
138 | if (learn_peer.core != NULL) | 137 | if (learn_peer.core != NULL) |
139 | { | 138 | { |
140 | GNUNET_CORE_disconnect (learn_peer.core); | 139 | GNUNET_CORE_disconnect (learn_peer.core); |
141 | learn_peer.core = NULL; | 140 | learn_peer.core = NULL; |
142 | } | 141 | } |
143 | #if START_ARM | 142 | #if START_ARM |
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
145 | "Killing hostlist server ARM process.\n"); | 144 | "Killing hostlist server ARM process.\n"); |
146 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM)) | 145 | if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM)) |
147 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 146 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
148 | "kill"); | 147 | if (GNUNET_OS_process_wait (adv_peer.arm_proc) != GNUNET_OK) |
149 | if (GNUNET_OS_process_wait(adv_peer.arm_proc) != GNUNET_OK) | 148 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
150 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
151 | "waitpid"); | ||
152 | GNUNET_OS_process_close (adv_peer.arm_proc); | 149 | GNUNET_OS_process_close (adv_peer.arm_proc); |
153 | adv_peer.arm_proc = NULL; | 150 | adv_peer.arm_proc = NULL; |
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Killing hostlist client ARM process.\n"); | 152 | "Killing hostlist client ARM process.\n"); |
156 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM)) | 153 | if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM)) |
157 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 154 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
158 | "kill"); | 155 | if (GNUNET_OS_process_wait (learn_peer.arm_proc) != GNUNET_OK) |
159 | if (GNUNET_OS_process_wait(learn_peer.arm_proc) != GNUNET_OK) | 156 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
160 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
161 | "waitpid"); | ||
162 | GNUNET_OS_process_close (learn_peer.arm_proc); | 157 | GNUNET_OS_process_close (learn_peer.arm_proc); |
163 | learn_peer.arm_proc = NULL; | 158 | learn_peer.arm_proc = NULL; |
164 | #endif | 159 | #endif |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n"); |
166 | "Shutdown complete....\n"); | ||
167 | } | 161 | } |
168 | 162 | ||
169 | /** | 163 | /** |
170 | * Timeout, give up. | 164 | * Timeout, give up. |
171 | */ | 165 | */ |
172 | static void | 166 | static void |
173 | timeout_error (void *cls, | 167 | timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
174 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
175 | { | 168 | { |
176 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 169 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
178 | "Timeout while executing testcase, test failed.\n"); | 171 | "Timeout while executing testcase, test failed.\n"); |
179 | timeout = GNUNET_YES; | 172 | timeout = GNUNET_YES; |
180 | shutdown_testcase(); | 173 | shutdown_testcase (); |
181 | } | 174 | } |
182 | 175 | ||
183 | 176 | ||
@@ -190,21 +183,17 @@ process_downloads_done (void *cls, int success) | |||
190 | 183 | ||
191 | static int | 184 | static int |
192 | process_downloads (void *cls, | 185 | process_downloads (void *cls, |
193 | const char *subsystem, | 186 | const char *subsystem, |
194 | const char *name, | 187 | const char *name, uint64_t value, int is_persistent) |
195 | uint64_t value, | ||
196 | int is_persistent) | ||
197 | { | 188 | { |
198 | if ( (value >= 2) && | 189 | if ((value >= 2) && (learned_hostlist_downloaded == GNUNET_NO)) |
199 | (learned_hostlist_downloaded == GNUNET_NO) ) | 190 | { |
200 | { | 191 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 192 | "Peer has successfully downloaded advertised URI\n"); |
202 | "Peer has successfully downloaded advertised URI\n"); | 193 | learned_hostlist_downloaded = GNUNET_YES; |
203 | learned_hostlist_downloaded = GNUNET_YES; | 194 | if ((learned_hostlist_saved == GNUNET_YES) && (adv_sent == GNUNET_YES)) |
204 | if ( (learned_hostlist_saved == GNUNET_YES) && | 195 | shutdown_testcase (); |
205 | (adv_sent == GNUNET_YES) ) | 196 | } |
206 | shutdown_testcase(); | ||
207 | } | ||
208 | return GNUNET_OK; | 197 | return GNUNET_OK; |
209 | } | 198 | } |
210 | 199 | ||
@@ -218,22 +207,18 @@ process_uris_recv_done (void *cls, int success) | |||
218 | 207 | ||
219 | static int | 208 | static int |
220 | process_uris_recv (void *cls, | 209 | process_uris_recv (void *cls, |
221 | const char *subsystem, | 210 | const char *subsystem, |
222 | const char *name, | 211 | const char *name, uint64_t value, int is_persistent) |
223 | uint64_t value, | ||
224 | int is_persistent) | ||
225 | { | 212 | { |
226 | if ( ((struct PeerContext *) cls == &learn_peer) && | 213 | if (((struct PeerContext *) cls == &learn_peer) && |
227 | (value == 1) && | 214 | (value == 1) && (learned_hostlist_saved == GNUNET_NO)) |
228 | (learned_hostlist_saved == GNUNET_NO) ) | 215 | { |
229 | { | 216 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
230 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 217 | "Peer has successfully saved advertised URI\n"); |
231 | "Peer has successfully saved advertised URI\n"); | 218 | learned_hostlist_saved = GNUNET_YES; |
232 | learned_hostlist_saved = GNUNET_YES; | 219 | if ((learned_hostlist_downloaded == GNUNET_YES) && (adv_sent == GNUNET_YES)) |
233 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | 220 | shutdown_testcase (); |
234 | (adv_sent == GNUNET_YES) ) | 221 | } |
235 | shutdown_testcase(); | ||
236 | } | ||
237 | return GNUNET_OK; | 222 | return GNUNET_OK; |
238 | } | 223 | } |
239 | 224 | ||
@@ -247,20 +232,18 @@ process_adv_sent_done (void *cls, int success) | |||
247 | 232 | ||
248 | static int | 233 | static int |
249 | process_adv_sent (void *cls, | 234 | process_adv_sent (void *cls, |
250 | const char *subsystem, | 235 | const char *subsystem, |
251 | const char *name, | 236 | const char *name, uint64_t value, int is_persistent) |
252 | uint64_t value, | ||
253 | int is_persistent) | ||
254 | { | 237 | { |
255 | if ( (value >= 1) && (adv_sent == GNUNET_NO)) | 238 | if ((value >= 1) && (adv_sent == GNUNET_NO)) |
256 | { | 239 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
258 | "Server has successfully sent advertisement\n"); | 241 | "Server has successfully sent advertisement\n"); |
259 | adv_sent = GNUNET_YES; | 242 | adv_sent = GNUNET_YES; |
260 | if ( (learned_hostlist_downloaded == GNUNET_YES) && | 243 | if ((learned_hostlist_downloaded == GNUNET_YES) && |
261 | (learned_hostlist_saved == GNUNET_YES) ) | 244 | (learned_hostlist_saved == GNUNET_YES)) |
262 | shutdown_testcase(); | 245 | shutdown_testcase (); |
263 | } | 246 | } |
264 | return GNUNET_OK; | 247 | return GNUNET_OK; |
265 | } | 248 | } |
266 | 249 | ||
@@ -269,8 +252,7 @@ process_adv_sent (void *cls, | |||
269 | * Check the server statistics regularly | 252 | * Check the server statistics regularly |
270 | */ | 253 | */ |
271 | static void | 254 | static void |
272 | check_statistics (void *cls, | 255 | check_statistics (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
273 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
274 | { | 256 | { |
275 | char *stat; | 257 | char *stat; |
276 | 258 | ||
@@ -278,105 +260,102 @@ check_statistics (void *cls, | |||
278 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 260 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
279 | return; | 261 | return; |
280 | GNUNET_asprintf (&stat, | 262 | GNUNET_asprintf (&stat, |
281 | gettext_noop("# advertised URI `%s' downloaded"), | 263 | gettext_noop ("# advertised URI `%s' downloaded"), |
282 | current_adv_uri); | 264 | current_adv_uri); |
283 | if (NULL != learn_peer.stats) | 265 | if (NULL != learn_peer.stats) |
284 | { | 266 | { |
285 | if (NULL != download_stats) | 267 | if (NULL != download_stats) |
286 | GNUNET_STATISTICS_get_cancel (download_stats); | 268 | GNUNET_STATISTICS_get_cancel (download_stats); |
287 | download_stats = GNUNET_STATISTICS_get (learn_peer.stats, | 269 | download_stats = GNUNET_STATISTICS_get (learn_peer.stats, |
288 | "hostlist", | 270 | "hostlist", |
289 | stat, | 271 | stat, |
290 | GNUNET_TIME_UNIT_MINUTES, | 272 | GNUNET_TIME_UNIT_MINUTES, |
291 | &process_downloads_done, | 273 | &process_downloads_done, |
292 | &process_downloads, | 274 | &process_downloads, &learn_peer); |
293 | &learn_peer); | 275 | if (NULL != urisrecv_stat) |
294 | if (NULL != urisrecv_stat) | 276 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); |
295 | GNUNET_STATISTICS_get_cancel (urisrecv_stat); | 277 | urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, |
296 | urisrecv_stat = GNUNET_STATISTICS_get (learn_peer.stats, | 278 | "hostlist", |
297 | "hostlist", | 279 | gettext_noop |
298 | gettext_noop("# advertised hostlist URIs"), | 280 | ("# advertised hostlist URIs"), |
299 | GNUNET_TIME_UNIT_MINUTES, | 281 | GNUNET_TIME_UNIT_MINUTES, |
300 | &process_uris_recv_done, | 282 | &process_uris_recv_done, |
301 | &process_uris_recv, | 283 | &process_uris_recv, &learn_peer); |
302 | &learn_peer); | 284 | } |
303 | } | ||
304 | GNUNET_free (stat); | 285 | GNUNET_free (stat); |
305 | if ( NULL != adv_peer.stats) | 286 | if (NULL != adv_peer.stats) |
306 | { | 287 | { |
307 | if (NULL != advsent_stat) | 288 | if (NULL != advsent_stat) |
308 | GNUNET_STATISTICS_get_cancel (advsent_stat); | 289 | GNUNET_STATISTICS_get_cancel (advsent_stat); |
309 | advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, | 290 | advsent_stat = GNUNET_STATISTICS_get (adv_peer.stats, |
310 | "hostlist", | 291 | "hostlist", |
311 | gettext_noop("# hostlist advertisements send"), | 292 | gettext_noop |
312 | GNUNET_TIME_UNIT_MINUTES, | 293 | ("# hostlist advertisements send"), |
313 | &process_adv_sent_done, | 294 | GNUNET_TIME_UNIT_MINUTES, |
314 | &process_adv_sent, | 295 | &process_adv_sent_done, |
315 | NULL); | 296 | &process_adv_sent, NULL); |
316 | } | 297 | } |
317 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 298 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, |
318 | &check_statistics, | 299 | &check_statistics, NULL); |
319 | NULL); | ||
320 | } | 300 | } |
321 | 301 | ||
322 | 302 | ||
323 | /** | 303 | /** |
324 | * Core handler for p2p hostlist advertisements | 304 | * Core handler for p2p hostlist advertisements |
325 | */ | 305 | */ |
326 | static int | 306 | static int |
327 | ad_arrive_handler (void *cls, | 307 | ad_arrive_handler (void *cls, |
328 | const struct GNUNET_PeerIdentity * peer, | 308 | const struct GNUNET_PeerIdentity *peer, |
329 | const struct GNUNET_MessageHeader * message, | 309 | const struct GNUNET_MessageHeader *message, |
330 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 310 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
331 | { | 311 | { |
332 | char *hostname; | 312 | char *hostname; |
333 | char *expected_uri; | 313 | char *expected_uri; |
334 | unsigned long long port; | 314 | unsigned long long port; |
335 | const struct GNUNET_MessageHeader * incoming; | 315 | const struct GNUNET_MessageHeader *incoming; |
336 | const char *end; | 316 | const char *end; |
337 | 317 | ||
338 | if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, | 318 | if (-1 == GNUNET_CONFIGURATION_get_value_number (adv_peer.cfg, |
339 | "HOSTLIST", | 319 | "HOSTLIST", |
340 | "HTTPPORT", | 320 | "HTTPPORT", &port)) |
341 | &port)) | 321 | { |
342 | { | 322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 323 | "Could not read advertising server's configuration\n"); |
344 | "Could not read advertising server's configuration\n" ); | 324 | return GNUNET_SYSERR; |
345 | return GNUNET_SYSERR; | 325 | } |
346 | } | 326 | |
347 | 327 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | |
348 | if ( GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (adv_peer.cfg, | 328 | "HOSTLIST", |
349 | "HOSTLIST", | 329 | "EXTERNAL_DNS_NAME", |
350 | "EXTERNAL_DNS_NAME", | 330 | &hostname)) |
351 | &hostname)) | ||
352 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 331 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
353 | GNUNET_asprintf (&expected_uri, | 332 | GNUNET_asprintf (&expected_uri, |
354 | "http://%s:%u/", | 333 | "http://%s:%u/", |
355 | hostname != NULL ? hostname : "localhost", | 334 | hostname != NULL ? hostname : "localhost", |
356 | (unsigned int) port); | 335 | (unsigned int) port); |
357 | incoming = (const struct GNUNET_MessageHeader *) message; | 336 | incoming = (const struct GNUNET_MessageHeader *) message; |
358 | end = (const char*) &incoming[1]; | 337 | end = (const char *) &incoming[1]; |
359 | if ('\0' != end[ntohs(message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) | 338 | if ('\0' != |
360 | { | 339 | end[ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 1]) |
361 | GNUNET_break (0); | 340 | { |
362 | GNUNET_free (expected_uri); | 341 | GNUNET_break (0); |
363 | GNUNET_free_non_null (hostname); | 342 | GNUNET_free (expected_uri); |
364 | return GNUNET_SYSERR; | 343 | GNUNET_free_non_null (hostname); |
365 | } | 344 | return GNUNET_SYSERR; |
345 | } | ||
366 | current_adv_uri = GNUNET_strdup (end); | 346 | current_adv_uri = GNUNET_strdup (end); |
367 | if ( 0 == strcmp( expected_uri, current_adv_uri ) ) | 347 | if (0 == strcmp (expected_uri, current_adv_uri)) |
368 | { | 348 | { |
369 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
370 | "Received hostlist advertisement with URI `%s' as expected\n", | 350 | "Received hostlist advertisement with URI `%s' as expected\n", |
371 | current_adv_uri); | 351 | current_adv_uri); |
372 | adv_arrived = GNUNET_YES; | 352 | adv_arrived = GNUNET_YES; |
373 | adv_sent = GNUNET_YES; | 353 | adv_sent = GNUNET_YES; |
374 | } | 354 | } |
375 | else | 355 | else |
376 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
377 | "Expected URI `%s' and recieved URI `%s' differ\n", | 357 | "Expected URI `%s' and recieved URI `%s' differ\n", |
378 | expected_uri, | 358 | expected_uri, current_adv_uri); |
379 | current_adv_uri); | ||
380 | GNUNET_free (expected_uri); | 359 | GNUNET_free (expected_uri); |
381 | GNUNET_free_non_null (hostname); | 360 | GNUNET_free_non_null (hostname); |
382 | return GNUNET_OK; | 361 | return GNUNET_OK; |
@@ -387,83 +366,79 @@ ad_arrive_handler (void *cls, | |||
387 | * List of handlers if we are learning. | 366 | * List of handlers if we are learning. |
388 | */ | 367 | */ |
389 | static struct GNUNET_CORE_MessageHandler learn_handlers[] = { | 368 | static struct GNUNET_CORE_MessageHandler learn_handlers[] = { |
390 | { &ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, | 369 | {&ad_arrive_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, |
391 | { NULL, 0, 0 } | 370 | {NULL, 0, 0} |
392 | }; | 371 | }; |
393 | 372 | ||
394 | 373 | ||
395 | static void | 374 | static void |
396 | setup_learn_peer (struct PeerContext *p, | 375 | setup_learn_peer (struct PeerContext *p, const char *cfgname) |
397 | const char *cfgname) | ||
398 | { | 376 | { |
399 | char * filename; | 377 | char *filename; |
400 | unsigned int result; | 378 | unsigned int result; |
401 | 379 | ||
402 | p->cfg = GNUNET_CONFIGURATION_create (); | 380 | p->cfg = GNUNET_CONFIGURATION_create (); |
403 | #if START_ARM | 381 | #if START_ARM |
404 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 382 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
405 | "gnunet-service-arm", | 383 | "gnunet-service-arm", |
406 | #if VERBOSE | 384 | #if VERBOSE |
407 | "-L", "DEBUG", | 385 | "-L", "DEBUG", |
408 | #endif | 386 | #endif |
409 | "-c", cfgname, NULL); | 387 | "-c", cfgname, NULL); |
410 | #endif | 388 | #endif |
411 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 389 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
412 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, | 390 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, |
413 | "HOSTLIST", | 391 | "HOSTLIST", |
414 | "HOSTLISTFILE", | 392 | "HOSTLISTFILE", |
415 | &filename)) | 393 | &filename)) |
394 | { | ||
395 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | ||
416 | { | 396 | { |
417 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 397 | result = UNLINK (filename); |
418 | { | 398 | if (result == 0) |
419 | result = UNLINK (filename); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
420 | if (result == 0) | 400 | _("Hostlist file `%s' was removed\n"), filename); |
421 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
422 | _("Hostlist file `%s' was removed\n"),filename); | ||
423 | } | ||
424 | GNUNET_free (filename); | ||
425 | } | 401 | } |
402 | GNUNET_free (filename); | ||
403 | } | ||
426 | p->core = GNUNET_CORE_connect (p->cfg, | 404 | p->core = GNUNET_CORE_connect (p->cfg, |
427 | 1, | 405 | 1, |
428 | NULL, | 406 | NULL, |
429 | NULL, | 407 | NULL, |
430 | NULL, NULL, NULL, | 408 | NULL, NULL, NULL, |
431 | NULL, GNUNET_NO, | 409 | NULL, GNUNET_NO, |
432 | NULL, GNUNET_NO, | 410 | NULL, GNUNET_NO, learn_handlers); |
433 | learn_handlers ); | 411 | GNUNET_assert (NULL != p->core); |
434 | GNUNET_assert ( NULL != p->core ); | ||
435 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 412 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
436 | GNUNET_assert ( NULL != p->stats ); | 413 | GNUNET_assert (NULL != p->stats); |
437 | } | 414 | } |
438 | 415 | ||
439 | 416 | ||
440 | static void | 417 | static void |
441 | setup_adv_peer (struct PeerContext *p, | 418 | setup_adv_peer (struct PeerContext *p, const char *cfgname) |
442 | const char *cfgname) | ||
443 | { | 419 | { |
444 | p->cfg = GNUNET_CONFIGURATION_create (); | 420 | p->cfg = GNUNET_CONFIGURATION_create (); |
445 | #if START_ARM | 421 | #if START_ARM |
446 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 422 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
447 | "gnunet-service-arm", | 423 | "gnunet-service-arm", |
448 | #if VERBOSE | 424 | #if VERBOSE |
449 | "-L", "DEBUG", | 425 | "-L", "DEBUG", |
450 | #endif | 426 | #endif |
451 | "-c", cfgname, NULL); | 427 | "-c", cfgname, NULL); |
452 | #endif | 428 | #endif |
453 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 429 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
454 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); | 430 | p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); |
455 | GNUNET_assert ( NULL != p->stats ); | 431 | GNUNET_assert (NULL != p->stats); |
456 | } | 432 | } |
457 | 433 | ||
458 | 434 | ||
459 | static void | 435 | static void |
460 | run (void *cls, | 436 | run (void *cls, |
461 | char *const *args, | 437 | char *const *args, |
462 | const char *cfgfile, | 438 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
463 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
464 | { | 439 | { |
465 | timeout = GNUNET_NO; | 440 | timeout = GNUNET_NO; |
466 | adv_sent =GNUNET_NO; | 441 | adv_sent = GNUNET_NO; |
467 | 442 | ||
468 | adv_arrived = 0; | 443 | adv_arrived = 0; |
469 | learned_hostlist_saved = GNUNET_NO; | 444 | learned_hostlist_saved = GNUNET_NO; |
@@ -473,13 +448,10 @@ run (void *cls, | |||
473 | 448 | ||
474 | setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); | 449 | setup_adv_peer (&adv_peer, "test_learning_adv_peer.conf"); |
475 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); | 450 | setup_learn_peer (&learn_peer, "test_learning_learn_peer.conf"); |
476 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 451 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
477 | &timeout_error, | ||
478 | NULL); | ||
479 | 452 | ||
480 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, | 453 | check_task = GNUNET_SCHEDULER_add_delayed (CHECK_INTERVALL, |
481 | &check_statistics, | 454 | &check_statistics, NULL); |
482 | NULL); | ||
483 | } | 455 | } |
484 | 456 | ||
485 | 457 | ||
@@ -487,7 +459,8 @@ static int | |||
487 | check () | 459 | check () |
488 | { | 460 | { |
489 | unsigned int failed; | 461 | unsigned int failed; |
490 | char *const argv[] = { | 462 | |
463 | char *const argv[] = { | ||
491 | "test-gnunet-daemon-hostlist-learning", | 464 | "test-gnunet-daemon-hostlist-learning", |
492 | "-c", "learning_data.conf", | 465 | "-c", "learning_data.conf", |
493 | #if VERBOSE | 466 | #if VERBOSE |
@@ -501,39 +474,37 @@ check () | |||
501 | 474 | ||
502 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 475 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
503 | argv, "test-gnunet-daemon-hostlist-learning", | 476 | argv, "test-gnunet-daemon-hostlist-learning", |
504 | "nohelp", options, | 477 | "nohelp", options, &run, NULL); |
505 | &run, NULL); | ||
506 | failed = GNUNET_NO; | 478 | failed = GNUNET_NO; |
507 | if (timeout == GNUNET_YES) | 479 | if (timeout == GNUNET_YES) |
508 | { | 480 | { |
509 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n"); |
510 | "Testcase timeout\n"); | 482 | failed = GNUNET_YES; |
511 | failed = GNUNET_YES; | 483 | } |
512 | } | ||
513 | if (adv_arrived != GNUNET_YES) | 484 | if (adv_arrived != GNUNET_YES) |
514 | { | 485 | { |
515 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 486 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
516 | "Learning peer did not receive advertisement from server\n"); | 487 | "Learning peer did not receive advertisement from server\n"); |
517 | failed = GNUNET_YES; | 488 | failed = GNUNET_YES; |
518 | } | 489 | } |
519 | if ( learned_hostlist_saved == GNUNET_NO ) | 490 | if (learned_hostlist_saved == GNUNET_NO) |
520 | { | 491 | { |
521 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 492 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
522 | "Advertised hostlist was not saved in datastore\n"); | 493 | "Advertised hostlist was not saved in datastore\n"); |
523 | failed = GNUNET_YES; | 494 | failed = GNUNET_YES; |
524 | } | 495 | } |
525 | if (learned_hostlist_downloaded == GNUNET_NO) | 496 | if (learned_hostlist_downloaded == GNUNET_NO) |
526 | { | 497 | { |
527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
528 | "Advertised hostlist could not be downloaded from server\n"); | 499 | "Advertised hostlist could not be downloaded from server\n"); |
529 | failed = GNUNET_YES; | 500 | failed = GNUNET_YES; |
530 | } | 501 | } |
531 | if (adv_sent == GNUNET_NO) | 502 | if (adv_sent == GNUNET_NO) |
532 | { | 503 | { |
533 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 504 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
534 | "Advertised was not sent from server to client\n"); | 505 | "Advertised was not sent from server to client\n"); |
535 | failed = GNUNET_YES; | 506 | failed = GNUNET_YES; |
536 | } | 507 | } |
537 | if (GNUNET_YES == failed) | 508 | if (GNUNET_YES == failed) |
538 | return GNUNET_YES; | 509 | return GNUNET_YES; |
539 | return GNUNET_NO; | 510 | return GNUNET_NO; |
@@ -542,7 +513,7 @@ check () | |||
542 | 513 | ||
543 | int | 514 | int |
544 | main (int argc, char *argv[]) | 515 | main (int argc, char *argv[]) |
545 | { | 516 | { |
546 | int ret; | 517 | int ret; |
547 | 518 | ||
548 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 519 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
@@ -565,12 +536,12 @@ main (int argc, char *argv[]) | |||
565 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 536 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
566 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); | 537 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); |
567 | if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file")) | 538 | if (GNUNET_YES == GNUNET_DISK_file_test ("hostlists_learn_peer.file")) |
568 | { | 539 | { |
569 | if (0 == UNLINK("hostlists_learn_peer.file")) | 540 | if (0 == UNLINK ("hostlists_learn_peer.file")) |
570 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 541 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
571 | "Hostlist file hostlists_learn_peer.file was removed\n"); | 542 | "Hostlist file hostlists_learn_peer.file was removed\n"); |
572 | } | 543 | } |
573 | return ret; | 544 | return ret; |
574 | } | 545 | } |
575 | 546 | ||
576 | /* end of test_gnunet_daemon_hostlist.c */ | 547 | /* end of test_gnunet_daemon_hostlist.c */ |
diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index 7b6c858d4..d1227da4c 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c | |||
@@ -41,7 +41,7 @@ | |||
41 | static int ok; | 41 | static int ok; |
42 | 42 | ||
43 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; | 43 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; |
44 | 44 | ||
45 | struct PeerContext | 45 | struct PeerContext |
46 | { | 46 | { |
47 | struct GNUNET_CONFIGURATION_Handle *cfg; | 47 | struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -61,15 +61,15 @@ static void | |||
61 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 61 | clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
62 | { | 62 | { |
63 | if (p1.th != NULL) | 63 | if (p1.th != NULL) |
64 | { | 64 | { |
65 | GNUNET_TRANSPORT_disconnect (p1.th); | 65 | GNUNET_TRANSPORT_disconnect (p1.th); |
66 | p1.th = NULL; | 66 | p1.th = NULL; |
67 | } | 67 | } |
68 | if (p2.th != NULL) | 68 | if (p2.th != NULL) |
69 | { | 69 | { |
70 | GNUNET_TRANSPORT_disconnect (p2.th); | 70 | GNUNET_TRANSPORT_disconnect (p2.th); |
71 | p2.th = NULL; | 71 | p2.th = NULL; |
72 | } | 72 | } |
73 | GNUNET_SCHEDULER_shutdown (); | 73 | GNUNET_SCHEDULER_shutdown (); |
74 | } | 74 | } |
75 | 75 | ||
@@ -81,7 +81,7 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
81 | { | 81 | { |
82 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 82 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 83 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
84 | "Timeout trying to connect peers, test failed.\n"); | 84 | "Timeout trying to connect peers, test failed.\n"); |
85 | clean_up (NULL, tc); | 85 | clean_up (NULL, tc); |
86 | } | 86 | } |
87 | 87 | ||
@@ -97,35 +97,34 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
97 | */ | 97 | */ |
98 | static void | 98 | static void |
99 | notify_connect (void *cls, | 99 | notify_connect (void *cls, |
100 | const struct GNUNET_PeerIdentity * peer, | 100 | const struct GNUNET_PeerIdentity *peer, |
101 | const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) | 101 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
102 | uint32_t ats_count) | ||
102 | { | 103 | { |
103 | if (peer == NULL) | 104 | if (peer == NULL) |
104 | return; | 105 | return; |
105 | #if VERBOSE | 106 | #if VERBOSE |
106 | fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer)); | 107 | fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer)); |
107 | #endif | 108 | #endif |
108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n"); |
109 | "Peers connected, shutting down.\n"); | ||
110 | ok = 0; | 110 | ok = 0; |
111 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 111 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
112 | { | 112 | { |
113 | GNUNET_SCHEDULER_cancel (timeout_task); | 113 | GNUNET_SCHEDULER_cancel (timeout_task); |
114 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 114 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
115 | } | 115 | } |
116 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | 116 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | static void | 120 | static void |
121 | process_hello (void *cls, | 121 | process_hello (void *cls, const struct GNUNET_MessageHeader *message) |
122 | const struct GNUNET_MessageHeader *message) | ||
123 | { | 122 | { |
124 | struct PeerContext *p = cls; | 123 | struct PeerContext *p = cls; |
125 | 124 | ||
126 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); | 125 | GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); |
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
128 | "Received HELLO, starting hostlist service.\n"); | 127 | "Received HELLO, starting hostlist service.\n"); |
129 | } | 128 | } |
130 | 129 | ||
131 | 130 | ||
@@ -135,35 +134,34 @@ setup_peer (struct PeerContext *p, const char *cfgname) | |||
135 | p->cfg = GNUNET_CONFIGURATION_create (); | 134 | p->cfg = GNUNET_CONFIGURATION_create (); |
136 | #if START_ARM | 135 | #if START_ARM |
137 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | 136 | p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", |
138 | "gnunet-service-arm", | 137 | "gnunet-service-arm", |
139 | #if VERBOSE | 138 | #if VERBOSE |
140 | "-L", "DEBUG", | 139 | "-L", "DEBUG", |
141 | #endif | 140 | #endif |
142 | "-c", cfgname, NULL); | 141 | "-c", cfgname, NULL); |
143 | #endif | 142 | #endif |
144 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 143 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
145 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, | 144 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, |
146 | ¬ify_connect, NULL); | 145 | ¬ify_connect, NULL); |
147 | GNUNET_assert (p->th != NULL); | 146 | GNUNET_assert (p->th != NULL); |
148 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); | 147 | GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); |
149 | } | 148 | } |
150 | 149 | ||
151 | 150 | ||
152 | static void | 151 | static void |
153 | waitpid_task (void *cls, | 152 | waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
154 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
155 | { | 153 | { |
156 | struct PeerContext *p = cls; | 154 | struct PeerContext *p = cls; |
157 | 155 | ||
158 | #if START_ARM | 156 | #if START_ARM |
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); |
160 | "Killing ARM process.\n"); | ||
161 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 158 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) |
162 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 159 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
163 | if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) | 160 | if (GNUNET_OS_process_wait (p->arm_proc) != GNUNET_OK) |
164 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | 161 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); |
165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
166 | "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); | 163 | "ARM process %u stopped\n", |
164 | GNUNET_OS_process_get_pid (p->arm_proc)); | ||
167 | GNUNET_OS_process_close (p->arm_proc); | 165 | GNUNET_OS_process_close (p->arm_proc); |
168 | p->arm_proc = NULL; | 166 | p->arm_proc = NULL; |
169 | #endif | 167 | #endif |
@@ -174,10 +172,8 @@ waitpid_task (void *cls, | |||
174 | static void | 172 | static void |
175 | stop_arm (struct PeerContext *p) | 173 | stop_arm (struct PeerContext *p) |
176 | { | 174 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking ARM to stop core service\n"); |
178 | "Asking ARM to stop core service\n"); | 176 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &waitpid_task, p); |
179 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
180 | &waitpid_task, p); | ||
181 | } | 177 | } |
182 | 178 | ||
183 | 179 | ||
@@ -195,17 +191,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
195 | static void | 191 | static void |
196 | run (void *cls, | 192 | run (void *cls, |
197 | char *const *args, | 193 | char *const *args, |
198 | const char *cfgfile, | 194 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
200 | { | 195 | { |
201 | GNUNET_assert (ok == 1); | 196 | GNUNET_assert (ok == 1); |
202 | ok++; | 197 | ok++; |
203 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 198 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_error, NULL); |
204 | &timeout_error, | ||
205 | NULL); | ||
206 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 199 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
207 | &shutdown_task, | 200 | &shutdown_task, NULL); |
208 | NULL); | ||
209 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); | 201 | setup_peer (&p1, "test_gnunet_daemon_hostlist_peer1.conf"); |
210 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); | 202 | setup_peer (&p2, "test_gnunet_daemon_hostlist_peer2.conf"); |
211 | } | 203 | } |
@@ -227,7 +219,7 @@ check () | |||
227 | ok = 1; | 219 | ok = 1; |
228 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 220 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
229 | argv, "test-gnunet-daemon-hostlist", | 221 | argv, "test-gnunet-daemon-hostlist", |
230 | "nohelp", options, &run, &ok); | 222 | "nohelp", options, &run, &ok); |
231 | return ok; | 223 | return ok; |
232 | } | 224 | } |
233 | 225 | ||
@@ -235,7 +227,7 @@ check () | |||
235 | int | 227 | int |
236 | main (int argc, char *argv[]) | 228 | main (int argc, char *argv[]) |
237 | { | 229 | { |
238 | 230 | ||
239 | int ret; | 231 | int ret; |
240 | 232 | ||
241 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 233 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
@@ -250,16 +242,16 @@ main (int argc, char *argv[]) | |||
250 | NULL); | 242 | NULL); |
251 | ret = check (); | 243 | ret = check (); |
252 | if (ret == 0) | 244 | if (ret == 0) |
253 | { | 245 | { |
254 | fprintf (stderr, "."); | 246 | fprintf (stderr, "."); |
255 | /* now do it again */ | 247 | /* now do it again */ |
256 | ret = check (); | 248 | ret = check (); |
257 | fprintf (stderr, ".\n"); | 249 | fprintf (stderr, ".\n"); |
258 | } | 250 | } |
259 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); | 251 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1"); |
260 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); | 252 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2"); |
261 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); | 253 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-3"); |
262 | return ret; | 254 | return ret; |
263 | } | 255 | } |
264 | 256 | ||
265 | /* end of test_gnunet_daemon_hostlist_reconnect.c */ | 257 | /* end of test_gnunet_daemon_hostlist_reconnect.c */ |