diff options
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist_server.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 881 |
1 files changed, 441 insertions, 440 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index b4e0df34e..43513930a 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c | |||
@@ -39,7 +39,7 @@ | |||
39 | * time out? | 39 | * time out? |
40 | */ | 40 | */ |
41 | #define GNUNET_ADV_TIMEOUT \ | 41 | #define GNUNET_ADV_TIMEOUT \ |
42 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -106,7 +106,8 @@ static char *hostlist_uri; | |||
106 | /** | 106 | /** |
107 | * Context for #host_processor(). | 107 | * Context for #host_processor(). |
108 | */ | 108 | */ |
109 | struct HostSet { | 109 | struct HostSet |
110 | { | ||
110 | /** | 111 | /** |
111 | * Iterator used to build @e data (NULL when done). | 112 | * Iterator used to build @e data (NULL when done). |
112 | */ | 113 | */ |
@@ -137,13 +138,13 @@ static struct HostSet *builder; | |||
137 | * @param response response to add headers to | 138 | * @param response response to add headers to |
138 | */ | 139 | */ |
139 | static void | 140 | static void |
140 | add_cors_headers(struct MHD_Response *response) | 141 | add_cors_headers (struct MHD_Response *response) |
141 | { | 142 | { |
142 | MHD_add_response_header(response, "Access-Control-Allow-Origin", "*"); | 143 | MHD_add_response_header (response, "Access-Control-Allow-Origin", "*"); |
143 | MHD_add_response_header(response, | 144 | MHD_add_response_header (response, |
144 | "Access-Control-Allow-Methods", | 145 | "Access-Control-Allow-Methods", |
145 | "GET, OPTIONS"); | 146 | "GET, OPTIONS"); |
146 | MHD_add_response_header(response, "Access-Control-Max-Age", "86400"); | 147 | MHD_add_response_header (response, "Access-Control-Max-Age", "86400"); |
147 | } | 148 | } |
148 | 149 | ||
149 | 150 | ||
@@ -151,27 +152,27 @@ add_cors_headers(struct MHD_Response *response) | |||
151 | * Function that assembles our response. | 152 | * Function that assembles our response. |
152 | */ | 153 | */ |
153 | static void | 154 | static void |
154 | finish_response() | 155 | finish_response () |
155 | { | 156 | { |
156 | if (NULL != response) | 157 | if (NULL != response) |
157 | MHD_destroy_response(response); | 158 | MHD_destroy_response (response); |
158 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
159 | "Creating hostlist response with %u bytes\n", | 160 | "Creating hostlist response with %u bytes\n", |
160 | (unsigned int)builder->size); | 161 | (unsigned int) builder->size); |
161 | response = MHD_create_response_from_buffer(builder->size, | 162 | response = MHD_create_response_from_buffer (builder->size, |
162 | builder->data, | 163 | builder->data, |
163 | MHD_RESPMEM_MUST_FREE); | 164 | MHD_RESPMEM_MUST_FREE); |
164 | add_cors_headers(response); | 165 | add_cors_headers (response); |
165 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) | 166 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) |
166 | { | 167 | { |
167 | MHD_destroy_response(response); | 168 | MHD_destroy_response (response); |
168 | response = NULL; | 169 | response = NULL; |
169 | } | 170 | } |
170 | GNUNET_STATISTICS_set(stats, | 171 | GNUNET_STATISTICS_set (stats, |
171 | gettext_noop("bytes in hostlist"), | 172 | gettext_noop ("bytes in hostlist"), |
172 | builder->size, | 173 | builder->size, |
173 | GNUNET_YES); | 174 | GNUNET_YES); |
174 | GNUNET_free(builder); | 175 | GNUNET_free (builder); |
175 | builder = NULL; | 176 | builder = NULL; |
176 | } | 177 | } |
177 | 178 | ||
@@ -185,20 +186,20 @@ finish_response() | |||
185 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) | 186 | * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured) |
186 | */ | 187 | */ |
187 | static int | 188 | static int |
188 | check_has_addr(void *cls, | 189 | check_has_addr (void *cls, |
189 | const struct GNUNET_HELLO_Address *address, | 190 | const struct GNUNET_HELLO_Address *address, |
190 | struct GNUNET_TIME_Absolute expiration) | 191 | struct GNUNET_TIME_Absolute expiration) |
191 | { | 192 | { |
192 | int *arg = cls; | 193 | int *arg = cls; |
193 | 194 | ||
194 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) | 195 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
195 | { | 196 | { |
196 | GNUNET_STATISTICS_update(stats, | 197 | GNUNET_STATISTICS_update (stats, |
197 | gettext_noop("expired addresses encountered"), | 198 | gettext_noop ("expired addresses encountered"), |
198 | 1, | 199 | 1, |
199 | GNUNET_YES); | 200 | GNUNET_YES); |
200 | return GNUNET_YES; /* ignore this address */ | 201 | return GNUNET_YES; /* ignore this address */ |
201 | } | 202 | } |
202 | *arg = GNUNET_YES; | 203 | *arg = GNUNET_YES; |
203 | return GNUNET_SYSERR; | 204 | return GNUNET_SYSERR; |
204 | } | 205 | } |
@@ -214,73 +215,73 @@ check_has_addr(void *cls, | |||
214 | * @param err_msg message | 215 | * @param err_msg message |
215 | */ | 216 | */ |
216 | static void | 217 | static void |
217 | host_processor(void *cls, | 218 | host_processor (void *cls, |
218 | const struct GNUNET_PeerIdentity *peer, | 219 | const struct GNUNET_PeerIdentity *peer, |
219 | const struct GNUNET_HELLO_Message *hello, | 220 | const struct GNUNET_HELLO_Message *hello, |
220 | const char *err_msg) | 221 | const char *err_msg) |
221 | { | 222 | { |
222 | size_t old; | 223 | size_t old; |
223 | size_t s; | 224 | size_t s; |
224 | int has_addr; | 225 | int has_addr; |
225 | 226 | ||
226 | if (NULL != err_msg) | 227 | if (NULL != err_msg) |
227 | { | 228 | { |
228 | GNUNET_assert(NULL == peer); | 229 | GNUNET_assert (NULL == peer); |
229 | builder->pitr = NULL; | 230 | builder->pitr = NULL; |
230 | GNUNET_free_non_null(builder->data); | 231 | GNUNET_free_non_null (builder->data); |
231 | GNUNET_free(builder); | 232 | GNUNET_free (builder); |
232 | builder = NULL; | 233 | builder = NULL; |
233 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
234 | _("Error in communication with PEERINFO service: %s\n"), | 235 | _ ("Error in communication with PEERINFO service: %s\n"), |
235 | err_msg); | 236 | err_msg); |
236 | return; | 237 | return; |
237 | } | 238 | } |
238 | if (NULL == peer) | 239 | if (NULL == peer) |
239 | { | 240 | { |
240 | builder->pitr = NULL; | 241 | builder->pitr = NULL; |
241 | finish_response(); | 242 | finish_response (); |
242 | return; | 243 | return; |
243 | } | 244 | } |
244 | if (NULL == hello) | 245 | if (NULL == hello) |
245 | return; | 246 | return; |
246 | has_addr = GNUNET_NO; | 247 | has_addr = GNUNET_NO; |
247 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, &check_has_addr, &has_addr); | 248 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr); |
248 | if (GNUNET_NO == has_addr) | 249 | if (GNUNET_NO == has_addr) |
249 | { | 250 | { |
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
251 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", | 252 | "HELLO for peer `%4s' has no address, not suitable for hostlist!\n", |
252 | GNUNET_i2s(peer)); | 253 | GNUNET_i2s (peer)); |
253 | GNUNET_STATISTICS_update(stats, | 254 | GNUNET_STATISTICS_update (stats, |
254 | gettext_noop( | 255 | gettext_noop ( |
255 | "HELLOs without addresses encountered (ignored)"), | 256 | "HELLOs without addresses encountered (ignored)"), |
256 | 1, | 257 | 1, |
257 | GNUNET_NO); | 258 | GNUNET_NO); |
258 | return; | 259 | return; |
259 | } | 260 | } |
260 | old = builder->size; | 261 | old = builder->size; |
261 | s = GNUNET_HELLO_size(hello); | 262 | s = GNUNET_HELLO_size (hello); |
262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
263 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", | 264 | "Received %u bytes of `%s' from peer `%s' for hostlist.\n", |
264 | (unsigned int)s, | 265 | (unsigned int) s, |
265 | "HELLO", | 266 | "HELLO", |
266 | GNUNET_i2s(peer)); | 267 | GNUNET_i2s (peer)); |
267 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || | 268 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || |
268 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) | 269 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) |
269 | { | 270 | { |
270 | /* too large, skip! */ | 271 | /* too large, skip! */ |
271 | GNUNET_STATISTICS_update(stats, | 272 | GNUNET_STATISTICS_update (stats, |
272 | gettext_noop( | 273 | gettext_noop ( |
273 | "bytes not included in hostlist (size limit)"), | 274 | "bytes not included in hostlist (size limit)"), |
274 | s, | 275 | s, |
275 | GNUNET_NO); | 276 | GNUNET_NO); |
276 | return; | 277 | return; |
277 | } | 278 | } |
278 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
279 | "Adding peer `%s' to hostlist (%u bytes)\n", | 280 | "Adding peer `%s' to hostlist (%u bytes)\n", |
280 | GNUNET_i2s(peer), | 281 | GNUNET_i2s (peer), |
281 | (unsigned int)s); | 282 | (unsigned int) s); |
282 | GNUNET_array_grow(builder->data, builder->size, old + s); | 283 | GNUNET_array_grow (builder->data, builder->size, old + s); |
283 | GNUNET_memcpy(&builder->data[old], hello, s); | 284 | GNUNET_memcpy (&builder->data[old], hello, s); |
284 | } | 285 | } |
285 | 286 | ||
286 | 287 | ||
@@ -294,17 +295,17 @@ host_processor(void *cls, | |||
294 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) | 295 | * @return #MHD_YES if connection is allowed, #MHD_NO if not (we are not ready) |
295 | */ | 296 | */ |
296 | static int | 297 | static int |
297 | accept_policy_callback(void *cls, | 298 | accept_policy_callback (void *cls, |
298 | const struct sockaddr *addr, | 299 | const struct sockaddr *addr, |
299 | socklen_t addrlen) | 300 | socklen_t addrlen) |
300 | { | 301 | { |
301 | if (NULL == response) | 302 | if (NULL == response) |
302 | { | 303 | { |
303 | GNUNET_log( | 304 | GNUNET_log ( |
304 | GNUNET_ERROR_TYPE_DEBUG, | 305 | GNUNET_ERROR_TYPE_DEBUG, |
305 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | 306 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); |
306 | return MHD_NO; | 307 | return MHD_NO; |
307 | } | 308 | } |
308 | return MHD_YES; /* accept all */ | 309 | return MHD_YES; /* accept all */ |
309 | } | 310 | } |
310 | 311 | ||
@@ -345,80 +346,80 @@ accept_policy_callback(void *cls, | |||
345 | * error while handling the request | 346 | * error while handling the request |
346 | */ | 347 | */ |
347 | static int | 348 | static int |
348 | access_handler_callback(void *cls, | 349 | access_handler_callback (void *cls, |
349 | struct MHD_Connection *connection, | 350 | struct MHD_Connection *connection, |
350 | const char *url, | 351 | const char *url, |
351 | const char *method, | 352 | const char *method, |
352 | const char *version, | 353 | const char *version, |
353 | const char *upload_data, | 354 | const char *upload_data, |
354 | size_t *upload_data_size, | 355 | size_t *upload_data_size, |
355 | void **con_cls) | 356 | void **con_cls) |
356 | { | 357 | { |
357 | static int dummy; | 358 | static int dummy; |
358 | 359 | ||
359 | /* CORS pre-flight request */ | 360 | /* CORS pre-flight request */ |
360 | if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method)) | 361 | if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method)) |
361 | { | 362 | { |
362 | struct MHD_Response *options_response; | 363 | struct MHD_Response *options_response; |
363 | int rc; | 364 | int rc; |
364 | 365 | ||
365 | options_response = | 366 | options_response = |
366 | MHD_create_response_from_buffer(0, NULL, MHD_RESPMEM_PERSISTENT); | 367 | MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT); |
367 | add_cors_headers(options_response); | 368 | add_cors_headers (options_response); |
368 | rc = MHD_queue_response(connection, MHD_HTTP_OK, options_response); | 369 | rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); |
369 | MHD_destroy_response(options_response); | 370 | MHD_destroy_response (options_response); |
370 | return rc; | 371 | return rc; |
371 | } | 372 | } |
372 | if (0 != strcmp(method, MHD_HTTP_METHOD_GET)) | 373 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
373 | { | 374 | { |
374 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
375 | _("Refusing `%s' request to hostlist server\n"), | 376 | _ ("Refusing `%s' request to hostlist server\n"), |
376 | method); | 377 | method); |
377 | GNUNET_STATISTICS_update(stats, | 378 | GNUNET_STATISTICS_update (stats, |
378 | gettext_noop( | 379 | gettext_noop ( |
379 | "hostlist requests refused (not HTTP GET)"), | 380 | "hostlist requests refused (not HTTP GET)"), |
380 | 1, | 381 | 1, |
381 | GNUNET_YES); | 382 | GNUNET_YES); |
382 | return MHD_NO; | 383 | return MHD_NO; |
383 | } | 384 | } |
384 | if (NULL == *con_cls) | 385 | if (NULL == *con_cls) |
385 | { | 386 | { |
386 | (*con_cls) = &dummy; | 387 | (*con_cls) = &dummy; |
387 | return MHD_YES; | 388 | return MHD_YES; |
388 | } | 389 | } |
389 | if (0 != *upload_data_size) | 390 | if (0 != *upload_data_size) |
390 | { | 391 | { |
391 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
392 | _("Refusing `%s' request with %llu bytes of upload data\n"), | 393 | _ ("Refusing `%s' request with %llu bytes of upload data\n"), |
393 | method, | 394 | method, |
394 | (unsigned long long)*upload_data_size); | 395 | (unsigned long long) *upload_data_size); |
395 | GNUNET_STATISTICS_update(stats, | 396 | GNUNET_STATISTICS_update (stats, |
396 | gettext_noop( | 397 | gettext_noop ( |
397 | "hostlist requests refused (upload data)"), | 398 | "hostlist requests refused (upload data)"), |
398 | 1, | 399 | 1, |
399 | GNUNET_YES); | 400 | GNUNET_YES); |
400 | return MHD_NO; /* do not support upload data */ | 401 | return MHD_NO; /* do not support upload data */ |
401 | } | 402 | } |
402 | if (NULL == response) | 403 | if (NULL == response) |
403 | { | 404 | { |
404 | GNUNET_log( | 405 | GNUNET_log ( |
405 | GNUNET_ERROR_TYPE_WARNING, | 406 | GNUNET_ERROR_TYPE_WARNING, |
406 | _( | 407 | _ ( |
407 | "Could not handle hostlist request since I do not have a response yet\n")); | 408 | "Could not handle hostlist request since I do not have a response yet\n")); |
408 | GNUNET_STATISTICS_update(stats, | 409 | GNUNET_STATISTICS_update (stats, |
409 | gettext_noop( | 410 | gettext_noop ( |
410 | "hostlist requests refused (not ready)"), | 411 | "hostlist requests refused (not ready)"), |
411 | 1, | 412 | 1, |
412 | GNUNET_YES); | 413 | GNUNET_YES); |
413 | return MHD_NO; /* internal error, no response yet */ | 414 | return MHD_NO; /* internal error, no response yet */ |
414 | } | 415 | } |
415 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 416 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
416 | _("Received request for our hostlist\n")); | 417 | _ ("Received request for our hostlist\n")); |
417 | GNUNET_STATISTICS_update(stats, | 418 | GNUNET_STATISTICS_update (stats, |
418 | gettext_noop("hostlist requests processed"), | 419 | gettext_noop ("hostlist requests processed"), |
419 | 1, | 420 | 1, |
420 | GNUNET_YES); | 421 | GNUNET_YES); |
421 | return MHD_queue_response(connection, MHD_HTTP_OK, response); | 422 | return MHD_queue_response (connection, MHD_HTTP_OK, response); |
422 | } | 423 | } |
423 | 424 | ||
424 | 425 | ||
@@ -432,33 +433,33 @@ access_handler_callback(void *cls, | |||
432 | * @return number of bytes copied to @a buf | 433 | * @return number of bytes copied to @a buf |
433 | */ | 434 | */ |
434 | static void | 435 | static void |
435 | adv_transmit(struct GNUNET_MQ_Handle *mq) | 436 | adv_transmit (struct GNUNET_MQ_Handle *mq) |
436 | { | 437 | { |
437 | static uint64_t hostlist_adv_count; | 438 | static uint64_t hostlist_adv_count; |
438 | size_t uri_size; /* Including \0 termination! */ | 439 | size_t uri_size; /* Including \0 termination! */ |
439 | struct GNUNET_MessageHeader *header; | 440 | struct GNUNET_MessageHeader *header; |
440 | struct GNUNET_MQ_Envelope *env; | 441 | struct GNUNET_MQ_Envelope *env; |
441 | 442 | ||
442 | uri_size = strlen(hostlist_uri) + 1; | 443 | uri_size = strlen (hostlist_uri) + 1; |
443 | env = GNUNET_MQ_msg_extra(header, | 444 | env = GNUNET_MQ_msg_extra (header, |
444 | uri_size, | 445 | uri_size, |
445 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 446 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
446 | GNUNET_memcpy(&header[1], hostlist_uri, uri_size); | 447 | GNUNET_memcpy (&header[1], hostlist_uri, uri_size); |
447 | GNUNET_MQ_env_set_options(env, | 448 | GNUNET_MQ_env_set_options (env, |
448 | GNUNET_MQ_PREF_CORK_ALLOWED | | 449 | GNUNET_MQ_PREF_CORK_ALLOWED |
449 | GNUNET_MQ_PREF_UNRELIABLE); | 450 | | GNUNET_MQ_PREF_UNRELIABLE); |
450 | GNUNET_MQ_send(mq, env); | 451 | GNUNET_MQ_send (mq, env); |
451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
452 | "Sent advertisement message: Copied %u bytes into buffer!\n", | 453 | "Sent advertisement message: Copied %u bytes into buffer!\n", |
453 | (unsigned int)uri_size); | 454 | (unsigned int) uri_size); |
454 | hostlist_adv_count++; | 455 | hostlist_adv_count++; |
455 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
456 | " # Sent advertisement message: %llu\n", | 457 | " # Sent advertisement message: %llu\n", |
457 | (unsigned long long)hostlist_adv_count); | 458 | (unsigned long long) hostlist_adv_count); |
458 | GNUNET_STATISTICS_update(stats, | 459 | GNUNET_STATISTICS_update (stats, |
459 | gettext_noop("# hostlist advertisements send"), | 460 | gettext_noop ("# hostlist advertisements send"), |
460 | 1, | 461 | 1, |
461 | GNUNET_NO); | 462 | GNUNET_NO); |
462 | } | 463 | } |
463 | 464 | ||
464 | 465 | ||
@@ -471,34 +472,34 @@ adv_transmit(struct GNUNET_MQ_Handle *mq) | |||
471 | * @return NULL (must!) | 472 | * @return NULL (must!) |
472 | */ | 473 | */ |
473 | static void * | 474 | static void * |
474 | connect_handler(void *cls, | 475 | connect_handler (void *cls, |
475 | const struct GNUNET_PeerIdentity *peer, | 476 | const struct GNUNET_PeerIdentity *peer, |
476 | struct GNUNET_MQ_Handle *mq) | 477 | struct GNUNET_MQ_Handle *mq) |
477 | { | 478 | { |
478 | size_t size; | 479 | size_t size; |
479 | 480 | ||
480 | if (!advertising) | 481 | if (! advertising) |
481 | return NULL; | 482 | return NULL; |
482 | if (NULL == hostlist_uri) | 483 | if (NULL == hostlist_uri) |
483 | return NULL; | 484 | return NULL; |
484 | size = strlen(hostlist_uri) + 1; | 485 | size = strlen (hostlist_uri) + 1; |
485 | if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) | 486 | if (size + sizeof(struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) |
486 | { | 487 | { |
487 | GNUNET_break(0); | 488 | GNUNET_break (0); |
488 | return NULL; | 489 | return NULL; |
489 | } | 490 | } |
490 | size += sizeof(struct GNUNET_MessageHeader); | 491 | size += sizeof(struct GNUNET_MessageHeader); |
491 | if (NULL == core) | 492 | if (NULL == core) |
492 | { | 493 | { |
493 | GNUNET_break(0); | 494 | GNUNET_break (0); |
494 | return NULL; | 495 | return NULL; |
495 | } | 496 | } |
496 | GNUNET_log( | 497 | GNUNET_log ( |
497 | GNUNET_ERROR_TYPE_DEBUG, | 498 | GNUNET_ERROR_TYPE_DEBUG, |
498 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", | 499 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", |
499 | (unsigned int)size, | 500 | (unsigned int) size, |
500 | GNUNET_i2s(peer)); | 501 | GNUNET_i2s (peer)); |
501 | adv_transmit(mq); | 502 | adv_transmit (mq); |
502 | return NULL; | 503 | return NULL; |
503 | } | 504 | } |
504 | 505 | ||
@@ -513,36 +514,36 @@ connect_handler(void *cls, | |||
513 | * @param err_msg NULL if successful, otherwise contains error message | 514 | * @param err_msg NULL if successful, otherwise contains error message |
514 | */ | 515 | */ |
515 | static void | 516 | static void |
516 | process_notify(void *cls, | 517 | process_notify (void *cls, |
517 | const struct GNUNET_PeerIdentity *peer, | 518 | const struct GNUNET_PeerIdentity *peer, |
518 | const struct GNUNET_HELLO_Message *hello, | 519 | const struct GNUNET_HELLO_Message *hello, |
519 | const char *err_msg) | 520 | const char *err_msg) |
520 | { | 521 | { |
521 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
522 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 523 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
523 | if (NULL != err_msg) | 524 | if (NULL != err_msg) |
524 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 525 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
525 | _("Error in communication with PEERINFO service: %s\n"), | 526 | _ ("Error in communication with PEERINFO service: %s\n"), |
526 | err_msg); | 527 | err_msg); |
527 | if (NULL != builder) | 528 | if (NULL != builder) |
529 | { | ||
530 | /* restart re-build already in progress ... */ | ||
531 | if (NULL != builder->pitr) | ||
528 | { | 532 | { |
529 | /* restart re-build already in progress ... */ | 533 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); |
530 | if (NULL != builder->pitr) | 534 | builder->pitr = NULL; |
531 | { | ||
532 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
533 | builder->pitr = NULL; | ||
534 | } | ||
535 | GNUNET_free_non_null(builder->data); | ||
536 | builder->size = 0; | ||
537 | builder->data = NULL; | ||
538 | } | 535 | } |
536 | GNUNET_free_non_null (builder->data); | ||
537 | builder->size = 0; | ||
538 | builder->data = NULL; | ||
539 | } | ||
539 | else | 540 | else |
540 | { | 541 | { |
541 | builder = GNUNET_new(struct HostSet); | 542 | builder = GNUNET_new (struct HostSet); |
542 | } | 543 | } |
543 | GNUNET_assert(NULL != peerinfo); | 544 | GNUNET_assert (NULL != peerinfo); |
544 | builder->pitr = | 545 | builder->pitr = |
545 | GNUNET_PEERINFO_iterate(peerinfo, GNUNET_NO, NULL, &host_processor, NULL); | 546 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL); |
546 | } | 547 | } |
547 | 548 | ||
548 | 549 | ||
@@ -551,7 +552,7 @@ process_notify(void *cls, | |||
551 | * starts the task waiting for them. | 552 | * starts the task waiting for them. |
552 | */ | 553 | */ |
553 | static struct GNUNET_SCHEDULER_Task * | 554 | static struct GNUNET_SCHEDULER_Task * |
554 | prepare_daemon(struct MHD_Daemon *daemon_handle); | 555 | prepare_daemon (struct MHD_Daemon *daemon_handle); |
555 | 556 | ||
556 | 557 | ||
557 | /** | 558 | /** |
@@ -561,7 +562,7 @@ prepare_daemon(struct MHD_Daemon *daemon_handle); | |||
561 | * @param cls the `struct MHD_Daemon` of the HTTP server to run | 562 | * @param cls the `struct MHD_Daemon` of the HTTP server to run |
562 | */ | 563 | */ |
563 | static void | 564 | static void |
564 | run_daemon(void *cls) | 565 | run_daemon (void *cls) |
565 | { | 566 | { |
566 | struct MHD_Daemon *daemon_handle = cls; | 567 | struct MHD_Daemon *daemon_handle = cls; |
567 | 568 | ||
@@ -569,11 +570,11 @@ run_daemon(void *cls) | |||
569 | hostlist_task_v4 = NULL; | 570 | hostlist_task_v4 = NULL; |
570 | else | 571 | else |
571 | hostlist_task_v6 = NULL; | 572 | hostlist_task_v6 = NULL; |
572 | GNUNET_assert(MHD_YES == MHD_run(daemon_handle)); | 573 | GNUNET_assert (MHD_YES == MHD_run (daemon_handle)); |
573 | if (daemon_handle == daemon_handle_v4) | 574 | if (daemon_handle == daemon_handle_v4) |
574 | hostlist_task_v4 = prepare_daemon(daemon_handle); | 575 | hostlist_task_v4 = prepare_daemon (daemon_handle); |
575 | else | 576 | else |
576 | hostlist_task_v6 = prepare_daemon(daemon_handle); | 577 | hostlist_task_v6 = prepare_daemon (daemon_handle); |
577 | } | 578 | } |
578 | 579 | ||
579 | 580 | ||
@@ -584,7 +585,7 @@ run_daemon(void *cls) | |||
584 | * @param daemon_handle HTTP server to prepare to run | 585 | * @param daemon_handle HTTP server to prepare to run |
585 | */ | 586 | */ |
586 | static struct GNUNET_SCHEDULER_Task * | 587 | static struct GNUNET_SCHEDULER_Task * |
587 | prepare_daemon(struct MHD_Daemon *daemon_handle) | 588 | prepare_daemon (struct MHD_Daemon *daemon_handle) |
588 | { | 589 | { |
589 | struct GNUNET_SCHEDULER_Task *ret; | 590 | struct GNUNET_SCHEDULER_Task *ret; |
590 | fd_set rs; | 591 | fd_set rs; |
@@ -597,28 +598,28 @@ prepare_daemon(struct MHD_Daemon *daemon_handle) | |||
597 | int haveto; | 598 | int haveto; |
598 | struct GNUNET_TIME_Relative tv; | 599 | struct GNUNET_TIME_Relative tv; |
599 | 600 | ||
600 | FD_ZERO(&rs); | 601 | FD_ZERO (&rs); |
601 | FD_ZERO(&ws); | 602 | FD_ZERO (&ws); |
602 | FD_ZERO(&es); | 603 | FD_ZERO (&es); |
603 | wrs = GNUNET_NETWORK_fdset_create(); | 604 | wrs = GNUNET_NETWORK_fdset_create (); |
604 | wws = GNUNET_NETWORK_fdset_create(); | 605 | wws = GNUNET_NETWORK_fdset_create (); |
605 | max = -1; | 606 | max = -1; |
606 | GNUNET_assert(MHD_YES == MHD_get_fdset(daemon_handle, &rs, &ws, &es, &max)); | 607 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); |
607 | haveto = MHD_get_timeout(daemon_handle, &timeout); | 608 | haveto = MHD_get_timeout (daemon_handle, &timeout); |
608 | if (haveto == MHD_YES) | 609 | if (haveto == MHD_YES) |
609 | tv.rel_value_us = (uint64_t)timeout * 1000LL; | 610 | tv.rel_value_us = (uint64_t) timeout * 1000LL; |
610 | else | 611 | else |
611 | tv = GNUNET_TIME_UNIT_FOREVER_REL; | 612 | tv = GNUNET_TIME_UNIT_FOREVER_REL; |
612 | GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1); | 613 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); |
613 | GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1); | 614 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); |
614 | ret = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, | 615 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
615 | tv, | 616 | tv, |
616 | wrs, | 617 | wrs, |
617 | wws, | 618 | wws, |
618 | &run_daemon, | 619 | &run_daemon, |
619 | daemon_handle); | 620 | daemon_handle); |
620 | GNUNET_NETWORK_fdset_destroy(wrs); | 621 | GNUNET_NETWORK_fdset_destroy (wrs); |
621 | GNUNET_NETWORK_fdset_destroy(wws); | 622 | GNUNET_NETWORK_fdset_destroy (wws); |
622 | return ret; | 623 | return ret; |
623 | } | 624 | } |
624 | 625 | ||
@@ -634,11 +635,11 @@ prepare_daemon(struct MHD_Daemon *daemon_handle) | |||
634 | * @return #GNUNET_OK on success | 635 | * @return #GNUNET_OK on success |
635 | */ | 636 | */ |
636 | int | 637 | int |
637 | GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | 638 | GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, |
638 | struct GNUNET_STATISTICS_Handle *st, | 639 | struct GNUNET_STATISTICS_Handle *st, |
639 | struct GNUNET_CORE_Handle *co, | 640 | struct GNUNET_CORE_Handle *co, |
640 | GNUNET_CORE_ConnectEventHandler *server_ch, | 641 | GNUNET_CORE_ConnectEventHandler *server_ch, |
641 | int advertise) | 642 | int advertise) |
642 | { | 643 | { |
643 | unsigned long long port; | 644 | unsigned long long port; |
644 | char *hostname; | 645 | char *hostname; |
@@ -653,189 +654,189 @@ GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
653 | const struct sockaddr *sa6; | 654 | const struct sockaddr *sa6; |
654 | 655 | ||
655 | advertising = advertise; | 656 | advertising = advertise; |
656 | if (!advertising) | 657 | if (! advertising) |
657 | { | 658 | { |
658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
659 | "Advertising not enabled on this hostlist server\n"); | 660 | "Advertising not enabled on this hostlist server\n"); |
660 | } | 661 | } |
661 | else | 662 | else |
662 | { | 663 | { |
663 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 664 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
664 | "Advertising enabled on this hostlist server\n"); | 665 | "Advertising enabled on this hostlist server\n"); |
665 | } | 666 | } |
666 | cfg = c; | 667 | cfg = c; |
667 | stats = st; | 668 | stats = st; |
668 | peerinfo = GNUNET_PEERINFO_connect(cfg); | 669 | peerinfo = GNUNET_PEERINFO_connect (cfg); |
669 | if (NULL == peerinfo) | 670 | if (NULL == peerinfo) |
670 | { | 671 | { |
671 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
672 | _("Could not access PEERINFO service. Exiting.\n")); | 673 | _ ("Could not access PEERINFO service. Exiting.\n")); |
673 | return GNUNET_SYSERR; | 674 | return GNUNET_SYSERR; |
674 | } | 675 | } |
675 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 676 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
676 | "HOSTLIST", | 677 | "HOSTLIST", |
677 | "HTTPPORT", | 678 | "HTTPPORT", |
678 | &port)) | 679 | &port)) |
679 | return GNUNET_SYSERR; | 680 | return GNUNET_SYSERR; |
680 | if ((0 == port) || (port > UINT16_MAX)) | 681 | if ((0 == port) || (port > UINT16_MAX)) |
681 | { | 682 | { |
682 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 683 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
683 | _("Invalid port number %llu. Exiting.\n"), | 684 | _ ("Invalid port number %llu. Exiting.\n"), |
684 | port); | 685 | port); |
685 | return GNUNET_SYSERR; | 686 | return GNUNET_SYSERR; |
686 | } | 687 | } |
687 | 688 | ||
688 | if (GNUNET_SYSERR == | 689 | if (GNUNET_SYSERR == |
689 | GNUNET_CONFIGURATION_get_value_string(cfg, | 690 | GNUNET_CONFIGURATION_get_value_string (cfg, |
690 | "HOSTLIST", | 691 | "HOSTLIST", |
691 | "EXTERNAL_DNS_NAME", | 692 | "EXTERNAL_DNS_NAME", |
692 | &hostname)) | 693 | &hostname)) |
693 | hostname = GNUNET_RESOLVER_local_fqdn_get(); | 694 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
694 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
695 | _("Hostlist service starts on %s:%llu\n"), | 696 | _ ("Hostlist service starts on %s:%llu\n"), |
696 | hostname, | 697 | hostname, |
697 | port); | 698 | port); |
698 | if (NULL != hostname) | 699 | if (NULL != hostname) |
700 | { | ||
701 | size = strlen (hostname); | ||
702 | if (size + 15 > MAX_URL_LEN) | ||
699 | { | 703 | { |
700 | size = strlen(hostname); | 704 | GNUNET_break (0); |
701 | if (size + 15 > MAX_URL_LEN) | ||
702 | { | ||
703 | GNUNET_break(0); | ||
704 | } | ||
705 | else | ||
706 | { | ||
707 | GNUNET_asprintf(&hostlist_uri, | ||
708 | "http://%s:%u/", | ||
709 | hostname, | ||
710 | (unsigned int)port); | ||
711 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
712 | _("Address to obtain hostlist: `%s'\n"), | ||
713 | hostlist_uri); | ||
714 | } | ||
715 | GNUNET_free(hostname); | ||
716 | } | 705 | } |
706 | else | ||
707 | { | ||
708 | GNUNET_asprintf (&hostlist_uri, | ||
709 | "http://%s:%u/", | ||
710 | hostname, | ||
711 | (unsigned int) port); | ||
712 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
713 | _ ("Address to obtain hostlist: `%s'\n"), | ||
714 | hostlist_uri); | ||
715 | } | ||
716 | GNUNET_free (hostname); | ||
717 | } | ||
717 | 718 | ||
718 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV4")) | 719 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) |
720 | { | ||
721 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, | ||
722 | "HOSTLIST", | ||
723 | "BINDTOIP", | ||
724 | &ipv4)) | ||
719 | { | 725 | { |
720 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 726 | GNUNET_log ( |
721 | "HOSTLIST", | 727 | GNUNET_ERROR_TYPE_WARNING, |
722 | "BINDTOIP", | 728 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); |
723 | &ipv4)) | ||
724 | { | ||
725 | GNUNET_log( | ||
726 | GNUNET_ERROR_TYPE_WARNING, | ||
727 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | ||
728 | } | ||
729 | } | 729 | } |
730 | } | ||
730 | else | 731 | else |
731 | ipv4 = NULL; | 732 | ipv4 = NULL; |
732 | if (GNUNET_CONFIGURATION_have_value(cfg, "HOSTLIST", "BINDTOIPV6")) | 733 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6")) |
733 | { | 734 | { |
734 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, | 735 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
735 | "HOSTLIST", | 736 | "HOSTLIST", |
736 | "BINDTOIP", | 737 | "BINDTOIP", |
737 | &ipv6)) | 738 | &ipv6)) |
738 | { | 739 | { |
739 | GNUNET_log( | 740 | GNUNET_log ( |
740 | GNUNET_ERROR_TYPE_WARNING, | 741 | GNUNET_ERROR_TYPE_WARNING, |
741 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); | 742 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); |
742 | } | ||
743 | } | 743 | } |
744 | } | ||
744 | else | 745 | else |
745 | ipv6 = NULL; | 746 | ipv6 = NULL; |
746 | sa4 = NULL; | 747 | sa4 = NULL; |
747 | if (NULL != ipv4) | 748 | if (NULL != ipv4) |
749 | { | ||
750 | if (1 == inet_pton (AF_INET, ipv4, &i4)) | ||
748 | { | 751 | { |
749 | if (1 == inet_pton(AF_INET, ipv4, &i4)) | 752 | memset (&v4, 0, sizeof(v4)); |
750 | { | 753 | v4.sin_family = AF_INET; |
751 | memset(&v4, 0, sizeof(v4)); | 754 | v4.sin_addr = i4; |
752 | v4.sin_family = AF_INET; | 755 | v4.sin_port = htons (port); |
753 | v4.sin_addr = i4; | ||
754 | v4.sin_port = htons(port); | ||
755 | #if HAVE_SOCKADDR_IN_SIN_LEN | 756 | #if HAVE_SOCKADDR_IN_SIN_LEN |
756 | v4.sin_len = sizeof(v4); | 757 | v4.sin_len = sizeof(v4); |
757 | #endif | 758 | #endif |
758 | sa4 = (const struct sockaddr *)&v4; | 759 | sa4 = (const struct sockaddr *) &v4; |
759 | } | 760 | } |
760 | else | 761 | else |
761 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
762 | _( | 763 | _ ( |
763 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), | 764 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), |
764 | ipv4); | 765 | ipv4); |
765 | GNUNET_free(ipv4); | 766 | GNUNET_free (ipv4); |
766 | } | 767 | } |
767 | sa6 = NULL; | 768 | sa6 = NULL; |
768 | if (NULL != ipv6) | 769 | if (NULL != ipv6) |
770 | { | ||
771 | if (1 == inet_pton (AF_INET6, ipv6, &i6)) | ||
769 | { | 772 | { |
770 | if (1 == inet_pton(AF_INET6, ipv6, &i6)) | 773 | memset (&v6, 0, sizeof(v6)); |
771 | { | 774 | v6.sin6_family = AF_INET6; |
772 | memset(&v6, 0, sizeof(v6)); | 775 | v6.sin6_addr = i6; |
773 | v6.sin6_family = AF_INET6; | 776 | v6.sin6_port = htons (port); |
774 | v6.sin6_addr = i6; | ||
775 | v6.sin6_port = htons(port); | ||
776 | #if HAVE_SOCKADDR_IN_SIN_LEN | 777 | #if HAVE_SOCKADDR_IN_SIN_LEN |
777 | v6.sin6_len = sizeof(v6); | 778 | v6.sin6_len = sizeof(v6); |
778 | #endif | 779 | #endif |
779 | sa6 = (const struct sockaddr *)&v6; | 780 | sa6 = (const struct sockaddr *) &v6; |
780 | } | 781 | } |
781 | else | 782 | else |
782 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 783 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
783 | _( | 784 | _ ( |
784 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), | 785 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), |
785 | ipv6); | 786 | ipv6); |
786 | GNUNET_free(ipv6); | 787 | GNUNET_free (ipv6); |
787 | } | 788 | } |
788 | 789 | ||
789 | daemon_handle_v6 = MHD_start_daemon(MHD_USE_IPv6 | MHD_USE_DEBUG, | 790 | daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG, |
790 | (uint16_t)port, | 791 | (uint16_t) port, |
791 | &accept_policy_callback, | 792 | &accept_policy_callback, |
792 | NULL, | 793 | NULL, |
793 | &access_handler_callback, | 794 | &access_handler_callback, |
794 | NULL, | 795 | NULL, |
795 | MHD_OPTION_CONNECTION_LIMIT, | 796 | MHD_OPTION_CONNECTION_LIMIT, |
796 | (unsigned int)128, | 797 | (unsigned int) 128, |
797 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 798 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
798 | (unsigned int)32, | 799 | (unsigned int) 32, |
799 | MHD_OPTION_CONNECTION_TIMEOUT, | 800 | MHD_OPTION_CONNECTION_TIMEOUT, |
800 | (unsigned int)16, | 801 | (unsigned int) 16, |
801 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 802 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
802 | (size_t)(16 * 1024), | 803 | (size_t) (16 * 1024), |
803 | MHD_OPTION_SOCK_ADDR, | 804 | MHD_OPTION_SOCK_ADDR, |
804 | sa6, | 805 | sa6, |
805 | MHD_OPTION_END); | 806 | MHD_OPTION_END); |
806 | daemon_handle_v4 = MHD_start_daemon(MHD_NO_FLAG | MHD_USE_DEBUG, | 807 | daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, |
807 | (uint16_t)port, | 808 | (uint16_t) port, |
808 | &accept_policy_callback, | 809 | &accept_policy_callback, |
809 | NULL, | 810 | NULL, |
810 | &access_handler_callback, | 811 | &access_handler_callback, |
811 | NULL, | 812 | NULL, |
812 | MHD_OPTION_CONNECTION_LIMIT, | 813 | MHD_OPTION_CONNECTION_LIMIT, |
813 | (unsigned int)128, | 814 | (unsigned int) 128, |
814 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 815 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
815 | (unsigned int)32, | 816 | (unsigned int) 32, |
816 | MHD_OPTION_CONNECTION_TIMEOUT, | 817 | MHD_OPTION_CONNECTION_TIMEOUT, |
817 | (unsigned int)16, | 818 | (unsigned int) 16, |
818 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 819 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
819 | (size_t)(16 * 1024), | 820 | (size_t) (16 * 1024), |
820 | MHD_OPTION_SOCK_ADDR, | 821 | MHD_OPTION_SOCK_ADDR, |
821 | sa4, | 822 | sa4, |
822 | MHD_OPTION_END); | 823 | MHD_OPTION_END); |
823 | 824 | ||
824 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) | 825 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) |
825 | { | 826 | { |
826 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 827 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
827 | _("Could not start hostlist HTTP server on port %u\n"), | 828 | _ ("Could not start hostlist HTTP server on port %u\n"), |
828 | (unsigned short)port); | 829 | (unsigned short) port); |
829 | return GNUNET_SYSERR; | 830 | return GNUNET_SYSERR; |
830 | } | 831 | } |
831 | 832 | ||
832 | core = co; | 833 | core = co; |
833 | *server_ch = &connect_handler; | 834 | *server_ch = &connect_handler; |
834 | if (NULL != daemon_handle_v4) | 835 | if (NULL != daemon_handle_v4) |
835 | hostlist_task_v4 = prepare_daemon(daemon_handle_v4); | 836 | hostlist_task_v4 = prepare_daemon (daemon_handle_v4); |
836 | if (NULL != daemon_handle_v6) | 837 | if (NULL != daemon_handle_v6) |
837 | hostlist_task_v6 = prepare_daemon(daemon_handle_v6); | 838 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); |
838 | notify = GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_notify, NULL); | 839 | notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL); |
839 | return GNUNET_OK; | 840 | return GNUNET_OK; |
840 | } | 841 | } |
841 | 842 | ||
@@ -844,55 +845,55 @@ GNUNET_HOSTLIST_server_start(const struct GNUNET_CONFIGURATION_Handle *c, | |||
844 | * Stop server offering our hostlist. | 845 | * Stop server offering our hostlist. |
845 | */ | 846 | */ |
846 | void | 847 | void |
847 | GNUNET_HOSTLIST_server_stop() | 848 | GNUNET_HOSTLIST_server_stop () |
848 | { | 849 | { |
849 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); | 850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); |
850 | if (NULL != hostlist_task_v6) | 851 | if (NULL != hostlist_task_v6) |
851 | { | 852 | { |
852 | GNUNET_SCHEDULER_cancel(hostlist_task_v6); | 853 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); |
853 | hostlist_task_v6 = NULL; | 854 | hostlist_task_v6 = NULL; |
854 | } | 855 | } |
855 | if (NULL != hostlist_task_v4) | 856 | if (NULL != hostlist_task_v4) |
856 | { | 857 | { |
857 | GNUNET_SCHEDULER_cancel(hostlist_task_v4); | 858 | GNUNET_SCHEDULER_cancel (hostlist_task_v4); |
858 | hostlist_task_v4 = NULL; | 859 | hostlist_task_v4 = NULL; |
859 | } | 860 | } |
860 | if (NULL != daemon_handle_v4) | 861 | if (NULL != daemon_handle_v4) |
861 | { | 862 | { |
862 | MHD_stop_daemon(daemon_handle_v4); | 863 | MHD_stop_daemon (daemon_handle_v4); |
863 | daemon_handle_v4 = NULL; | 864 | daemon_handle_v4 = NULL; |
864 | } | 865 | } |
865 | if (NULL != daemon_handle_v6) | 866 | if (NULL != daemon_handle_v6) |
866 | { | 867 | { |
867 | MHD_stop_daemon(daemon_handle_v6); | 868 | MHD_stop_daemon (daemon_handle_v6); |
868 | daemon_handle_v6 = NULL; | 869 | daemon_handle_v6 = NULL; |
869 | } | 870 | } |
870 | if (NULL != response) | 871 | if (NULL != response) |
871 | { | 872 | { |
872 | MHD_destroy_response(response); | 873 | MHD_destroy_response (response); |
873 | response = NULL; | 874 | response = NULL; |
874 | } | 875 | } |
875 | if (NULL != notify) | 876 | if (NULL != notify) |
876 | { | 877 | { |
877 | GNUNET_PEERINFO_notify_cancel(notify); | 878 | GNUNET_PEERINFO_notify_cancel (notify); |
878 | notify = NULL; | 879 | notify = NULL; |
879 | } | 880 | } |
880 | if (NULL != builder) | 881 | if (NULL != builder) |
882 | { | ||
883 | if (NULL != builder->pitr) | ||
881 | { | 884 | { |
882 | if (NULL != builder->pitr) | 885 | GNUNET_PEERINFO_iterate_cancel (builder->pitr); |
883 | { | 886 | builder->pitr = NULL; |
884 | GNUNET_PEERINFO_iterate_cancel(builder->pitr); | ||
885 | builder->pitr = NULL; | ||
886 | } | ||
887 | GNUNET_free_non_null(builder->data); | ||
888 | GNUNET_free(builder); | ||
889 | builder = NULL; | ||
890 | } | 887 | } |
888 | GNUNET_free_non_null (builder->data); | ||
889 | GNUNET_free (builder); | ||
890 | builder = NULL; | ||
891 | } | ||
891 | if (NULL != peerinfo) | 892 | if (NULL != peerinfo) |
892 | { | 893 | { |
893 | GNUNET_PEERINFO_disconnect(peerinfo); | 894 | GNUNET_PEERINFO_disconnect (peerinfo); |
894 | peerinfo = NULL; | 895 | peerinfo = NULL; |
895 | } | 896 | } |
896 | cfg = NULL; | 897 | cfg = NULL; |
897 | stats = NULL; | 898 | stats = NULL; |
898 | core = NULL; | 899 | core = NULL; |