diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-05-04 22:16:24 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-05-04 22:16:24 +0200 |
commit | 80f480c752fd8dfa1be51d78fce314d9f0650b50 (patch) | |
tree | 459c21a3fde3b5f66194ac9960632de53586c5f0 /src/hostlist | |
parent | 3d2a951fa12546c09809f0a4d7e789ef8e971b03 (diff) | |
download | gnunet-80f480c752fd8dfa1be51d78fce314d9f0650b50.tar.gz gnunet-80f480c752fd8dfa1be51d78fce314d9f0650b50.zip |
simplify MQ logic to always carry the same kinds of flags, and extend transport API to pass them to (TNG) service
Diffstat (limited to 'src/hostlist')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist_server.c | 268 |
1 files changed, 132 insertions, 136 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist_server.c b/src/hostlist/gnunet-daemon-hostlist_server.c index 529fe4e62..8764586d6 100644 --- a/src/hostlist/gnunet-daemon-hostlist_server.c +++ b/src/hostlist/gnunet-daemon-hostlist_server.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -38,7 +38,8 @@ | |||
38 | * How long until our hostlist advertisment transmission via CORE should | 38 | * How long until our hostlist advertisment transmission via CORE should |
39 | * time out? | 39 | * time out? |
40 | */ | 40 | */ |
41 | #define GNUNET_ADV_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 41 | #define GNUNET_ADV_TIMEOUT \ |
42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | ||
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
@@ -121,7 +122,6 @@ struct HostSet | |||
121 | * Number of bytes in @e data. | 122 | * Number of bytes in @e data. |
122 | */ | 123 | */ |
123 | unsigned int size; | 124 | unsigned int size; |
124 | |||
125 | }; | 125 | }; |
126 | 126 | ||
127 | 127 | ||
@@ -140,15 +140,11 @@ static struct HostSet *builder; | |||
140 | static void | 140 | static void |
141 | add_cors_headers (struct MHD_Response *response) | 141 | add_cors_headers (struct MHD_Response *response) |
142 | { | 142 | { |
143 | MHD_add_response_header (response, | 143 | MHD_add_response_header (response, "Access-Control-Allow-Origin", "*"); |
144 | "Access-Control-Allow-Origin", | ||
145 | "*"); | ||
146 | MHD_add_response_header (response, | 144 | MHD_add_response_header (response, |
147 | "Access-Control-Allow-Methods", | 145 | "Access-Control-Allow-Methods", |
148 | "GET, OPTIONS"); | 146 | "GET, OPTIONS"); |
149 | MHD_add_response_header (response, | 147 | MHD_add_response_header (response, "Access-Control-Max-Age", "86400"); |
150 | "Access-Control-Max-Age", | ||
151 | "86400"); | ||
152 | } | 148 | } |
153 | 149 | ||
154 | 150 | ||
@@ -163,18 +159,19 @@ finish_response () | |||
163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
164 | "Creating hostlist response with %u bytes\n", | 160 | "Creating hostlist response with %u bytes\n", |
165 | (unsigned int) builder->size); | 161 | (unsigned int) builder->size); |
166 | response = | 162 | response = MHD_create_response_from_buffer (builder->size, |
167 | MHD_create_response_from_buffer (builder->size, | 163 | builder->data, |
168 | builder->data, | 164 | MHD_RESPMEM_MUST_FREE); |
169 | MHD_RESPMEM_MUST_FREE); | ||
170 | add_cors_headers (response); | 165 | add_cors_headers (response); |
171 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) | 166 | if ((NULL == daemon_handle_v4) && (NULL == daemon_handle_v6)) |
172 | { | 167 | { |
173 | MHD_destroy_response (response); | 168 | MHD_destroy_response (response); |
174 | response = NULL; | 169 | response = NULL; |
175 | } | 170 | } |
176 | GNUNET_STATISTICS_set (stats, gettext_noop ("bytes in hostlist"), | 171 | GNUNET_STATISTICS_set (stats, |
177 | builder->size, GNUNET_YES); | 172 | gettext_noop ("bytes in hostlist"), |
173 | builder->size, | ||
174 | GNUNET_YES); | ||
178 | GNUNET_free (builder); | 175 | GNUNET_free (builder); |
179 | builder = NULL; | 176 | builder = NULL; |
180 | } | 177 | } |
@@ -198,9 +195,10 @@ check_has_addr (void *cls, | |||
198 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 195 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
199 | { | 196 | { |
200 | GNUNET_STATISTICS_update (stats, | 197 | GNUNET_STATISTICS_update (stats, |
201 | gettext_noop ("expired addresses encountered"), 1, | 198 | gettext_noop ("expired addresses encountered"), |
199 | 1, | ||
202 | GNUNET_YES); | 200 | GNUNET_YES); |
203 | return GNUNET_YES; /* ignore this address */ | 201 | return GNUNET_YES; /* ignore this address */ |
204 | } | 202 | } |
205 | *arg = GNUNET_YES; | 203 | *arg = GNUNET_YES; |
206 | return GNUNET_SYSERR; | 204 | return GNUNET_SYSERR; |
@@ -234,7 +232,7 @@ host_processor (void *cls, | |||
234 | GNUNET_free (builder); | 232 | GNUNET_free (builder); |
235 | builder = NULL; | 233 | builder = NULL; |
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
237 | _("Error in communication with PEERINFO service: %s\n"), | 235 | _ ("Error in communication with PEERINFO service: %s\n"), |
238 | err_msg); | 236 | err_msg); |
239 | return; | 237 | return; |
240 | } | 238 | } |
@@ -247,19 +245,17 @@ host_processor (void *cls, | |||
247 | if (NULL == hello) | 245 | if (NULL == hello) |
248 | return; | 246 | return; |
249 | has_addr = GNUNET_NO; | 247 | has_addr = GNUNET_NO; |
250 | GNUNET_HELLO_iterate_addresses (hello, | 248 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_has_addr, &has_addr); |
251 | GNUNET_NO, | ||
252 | &check_has_addr, | ||
253 | &has_addr); | ||
254 | if (GNUNET_NO == has_addr) | 249 | if (GNUNET_NO == has_addr) |
255 | { | 250 | { |
256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
257 | "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", |
258 | GNUNET_i2s (peer)); | 253 | GNUNET_i2s (peer)); |
259 | GNUNET_STATISTICS_update (stats, | 254 | GNUNET_STATISTICS_update (stats, |
260 | gettext_noop | 255 | gettext_noop ( |
261 | ("HELLOs without addresses encountered (ignored)"), | 256 | "HELLOs without addresses encountered (ignored)"), |
262 | 1, GNUNET_NO); | 257 | 1, |
258 | GNUNET_NO); | ||
263 | return; | 259 | return; |
264 | } | 260 | } |
265 | old = builder->size; | 261 | old = builder->size; |
@@ -269,26 +265,23 @@ host_processor (void *cls, | |||
269 | (unsigned int) s, | 265 | (unsigned int) s, |
270 | "HELLO", | 266 | "HELLO", |
271 | GNUNET_i2s (peer)); | 267 | GNUNET_i2s (peer)); |
272 | if ( (old + s >= GNUNET_MAX_MALLOC_CHECKED) || | 268 | if ((old + s >= GNUNET_MAX_MALLOC_CHECKED) || |
273 | (old + s >= MAX_BYTES_PER_HOSTLISTS) ) | 269 | (old + s >= MAX_BYTES_PER_HOSTLISTS)) |
274 | { | 270 | { |
275 | /* too large, skip! */ | 271 | /* too large, skip! */ |
276 | GNUNET_STATISTICS_update (stats, | 272 | GNUNET_STATISTICS_update (stats, |
277 | gettext_noop | 273 | gettext_noop ( |
278 | ("bytes not included in hostlist (size limit)"), | 274 | "bytes not included in hostlist (size limit)"), |
279 | s, GNUNET_NO); | 275 | s, |
276 | GNUNET_NO); | ||
280 | return; | 277 | return; |
281 | } | 278 | } |
282 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
283 | "Adding peer `%s' to hostlist (%u bytes)\n", | 280 | "Adding peer `%s' to hostlist (%u bytes)\n", |
284 | GNUNET_i2s (peer), | 281 | GNUNET_i2s (peer), |
285 | (unsigned int) s); | 282 | (unsigned int) s); |
286 | GNUNET_array_grow (builder->data, | 283 | GNUNET_array_grow (builder->data, builder->size, old + s); |
287 | builder->size, | 284 | GNUNET_memcpy (&builder->data[old], hello, s); |
288 | old + s); | ||
289 | GNUNET_memcpy (&builder->data[old], | ||
290 | hello, | ||
291 | s); | ||
292 | } | 285 | } |
293 | 286 | ||
294 | 287 | ||
@@ -308,11 +301,12 @@ accept_policy_callback (void *cls, | |||
308 | { | 301 | { |
309 | if (NULL == response) | 302 | if (NULL == response) |
310 | { | 303 | { |
311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 304 | GNUNET_log ( |
312 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | 305 | GNUNET_ERROR_TYPE_DEBUG, |
306 | "Received request for hostlist, but I am not yet ready; rejecting!\n"); | ||
313 | return MHD_NO; | 307 | return MHD_NO; |
314 | } | 308 | } |
315 | return MHD_YES; /* accept all */ | 309 | return MHD_YES; /* accept all */ |
316 | } | 310 | } |
317 | 311 | ||
318 | 312 | ||
@@ -369,9 +363,9 @@ access_handler_callback (void *cls, | |||
369 | struct MHD_Response *options_response; | 363 | struct MHD_Response *options_response; |
370 | int rc; | 364 | int rc; |
371 | 365 | ||
372 | options_response = MHD_create_response_from_buffer (0, NULL, | 366 | options_response = |
373 | MHD_RESPMEM_PERSISTENT); | 367 | MHD_create_response_from_buffer (0, NULL, MHD_RESPMEM_PERSISTENT); |
374 | add_cors_headers(options_response); | 368 | add_cors_headers (options_response); |
375 | rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); | 369 | rc = MHD_queue_response (connection, MHD_HTTP_OK, options_response); |
376 | MHD_destroy_response (options_response); | 370 | MHD_destroy_response (options_response); |
377 | return rc; | 371 | return rc; |
@@ -379,10 +373,12 @@ access_handler_callback (void *cls, | |||
379 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 373 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
380 | { | 374 | { |
381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 375 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
382 | _("Refusing `%s' request to hostlist server\n"), method); | 376 | _ ("Refusing `%s' request to hostlist server\n"), |
377 | method); | ||
383 | GNUNET_STATISTICS_update (stats, | 378 | GNUNET_STATISTICS_update (stats, |
384 | gettext_noop | 379 | gettext_noop ( |
385 | ("hostlist requests refused (not HTTP GET)"), 1, | 380 | "hostlist requests refused (not HTTP GET)"), |
381 | 1, | ||
386 | GNUNET_YES); | 382 | GNUNET_YES); |
387 | return MHD_NO; | 383 | return MHD_NO; |
388 | } | 384 | } |
@@ -394,29 +390,35 @@ access_handler_callback (void *cls, | |||
394 | if (0 != *upload_data_size) | 390 | if (0 != *upload_data_size) |
395 | { | 391 | { |
396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
397 | _("Refusing `%s' request with %llu bytes of upload data\n"), | 393 | _ ("Refusing `%s' request with %llu bytes of upload data\n"), |
398 | method, (unsigned long long) *upload_data_size); | 394 | method, |
395 | (unsigned long long) *upload_data_size); | ||
399 | GNUNET_STATISTICS_update (stats, | 396 | GNUNET_STATISTICS_update (stats, |
400 | gettext_noop | 397 | gettext_noop ( |
401 | ("hostlist requests refused (upload data)"), 1, | 398 | "hostlist requests refused (upload data)"), |
399 | 1, | ||
402 | GNUNET_YES); | 400 | GNUNET_YES); |
403 | return MHD_NO; /* do not support upload data */ | 401 | return MHD_NO; /* do not support upload data */ |
404 | } | 402 | } |
405 | if (NULL == response) | 403 | if (NULL == response) |
406 | { | 404 | { |
407 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 405 | GNUNET_log ( |
408 | _("Could not handle hostlist request since I do not have a response yet\n")); | 406 | GNUNET_ERROR_TYPE_WARNING, |
407 | _ ( | ||
408 | "Could not handle hostlist request since I do not have a response yet\n")); | ||
409 | GNUNET_STATISTICS_update (stats, | 409 | GNUNET_STATISTICS_update (stats, |
410 | gettext_noop | 410 | gettext_noop ( |
411 | ("hostlist requests refused (not ready)"), 1, | 411 | "hostlist requests refused (not ready)"), |
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, GNUNET_YES); | 420 | 1, |
421 | GNUNET_YES); | ||
420 | return MHD_queue_response (connection, MHD_HTTP_OK, response); | 422 | return MHD_queue_response (connection, MHD_HTTP_OK, response); |
421 | } | 423 | } |
422 | 424 | ||
@@ -434,27 +436,19 @@ static void | |||
434 | adv_transmit (struct GNUNET_MQ_Handle *mq) | 436 | adv_transmit (struct GNUNET_MQ_Handle *mq) |
435 | { | 437 | { |
436 | static uint64_t hostlist_adv_count; | 438 | static uint64_t hostlist_adv_count; |
437 | const void *extra; | 439 | size_t uri_size; /* Including \0 termination! */ |
438 | uint64_t flags; | ||
439 | size_t uri_size; /* Including \0 termination! */ | ||
440 | struct GNUNET_MessageHeader *header; | 440 | struct GNUNET_MessageHeader *header; |
441 | struct GNUNET_MQ_Envelope *env; | 441 | struct GNUNET_MQ_Envelope *env; |
442 | 442 | ||
443 | extra = GNUNET_CORE_get_mq_options (GNUNET_YES, | ||
444 | GNUNET_CORE_PRIO_BEST_EFFORT, | ||
445 | &flags); | ||
446 | uri_size = strlen (hostlist_uri) + 1; | 443 | uri_size = strlen (hostlist_uri) + 1; |
447 | env = GNUNET_MQ_msg_extra (header, | 444 | env = GNUNET_MQ_msg_extra (header, |
448 | uri_size, | 445 | uri_size, |
449 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); | 446 | GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT); |
450 | GNUNET_memcpy (&header[1], | 447 | GNUNET_memcpy (&header[1], hostlist_uri, uri_size); |
451 | hostlist_uri, | ||
452 | uri_size); | ||
453 | GNUNET_MQ_env_set_options (env, | 448 | GNUNET_MQ_env_set_options (env, |
454 | flags, | 449 | GNUNET_MQ_PREF_CORK_ALLOWED | |
455 | extra); | 450 | GNUNET_MQ_PREF_UNRELIABLE); |
456 | GNUNET_MQ_send (mq, | 451 | GNUNET_MQ_send (mq, env); |
457 | env); | ||
458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
459 | "Sent advertisement message: Copied %u bytes into buffer!\n", | 453 | "Sent advertisement message: Copied %u bytes into buffer!\n", |
460 | (unsigned int) uri_size); | 454 | (unsigned int) uri_size); |
@@ -463,7 +457,8 @@ adv_transmit (struct GNUNET_MQ_Handle *mq) | |||
463 | " # Sent advertisement message: %llu\n", | 457 | " # Sent advertisement message: %llu\n", |
464 | (unsigned long long) hostlist_adv_count); | 458 | (unsigned long long) hostlist_adv_count); |
465 | GNUNET_STATISTICS_update (stats, | 459 | GNUNET_STATISTICS_update (stats, |
466 | gettext_noop ("# hostlist advertisements send"), 1, | 460 | gettext_noop ("# hostlist advertisements send"), |
461 | 1, | ||
467 | GNUNET_NO); | 462 | GNUNET_NO); |
468 | } | 463 | } |
469 | 464 | ||
@@ -479,7 +474,7 @@ adv_transmit (struct GNUNET_MQ_Handle *mq) | |||
479 | static void * | 474 | static void * |
480 | connect_handler (void *cls, | 475 | connect_handler (void *cls, |
481 | const struct GNUNET_PeerIdentity *peer, | 476 | const struct GNUNET_PeerIdentity *peer, |
482 | struct GNUNET_MQ_Handle *mq) | 477 | struct GNUNET_MQ_Handle *mq) |
483 | { | 478 | { |
484 | size_t size; | 479 | size_t size; |
485 | 480 | ||
@@ -488,8 +483,7 @@ connect_handler (void *cls, | |||
488 | if (NULL == hostlist_uri) | 483 | if (NULL == hostlist_uri) |
489 | return NULL; | 484 | return NULL; |
490 | size = strlen (hostlist_uri) + 1; | 485 | size = strlen (hostlist_uri) + 1; |
491 | if (size + sizeof (struct GNUNET_MessageHeader) >= | 486 | if (size + sizeof (struct GNUNET_MessageHeader) >= GNUNET_MAX_MESSAGE_SIZE) |
492 | GNUNET_MAX_MESSAGE_SIZE) | ||
493 | { | 487 | { |
494 | GNUNET_break (0); | 488 | GNUNET_break (0); |
495 | return NULL; | 489 | return NULL; |
@@ -500,10 +494,11 @@ connect_handler (void *cls, | |||
500 | GNUNET_break (0); | 494 | GNUNET_break (0); |
501 | return NULL; | 495 | return NULL; |
502 | } | 496 | } |
503 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 497 | GNUNET_log ( |
504 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", | 498 | GNUNET_ERROR_TYPE_DEBUG, |
505 | (unsigned int) size, | 499 | "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n", |
506 | GNUNET_i2s (peer)); | 500 | (unsigned int) size, |
501 | GNUNET_i2s (peer)); | ||
507 | adv_transmit (mq); | 502 | adv_transmit (mq); |
508 | return NULL; | 503 | return NULL; |
509 | } | 504 | } |
@@ -528,8 +523,8 @@ process_notify (void *cls, | |||
528 | "Peerinfo is notifying us to rebuild our hostlist\n"); | 523 | "Peerinfo is notifying us to rebuild our hostlist\n"); |
529 | if (NULL != err_msg) | 524 | if (NULL != err_msg) |
530 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 525 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
531 | _("Error in communication with PEERINFO service: %s\n"), | 526 | _ ("Error in communication with PEERINFO service: %s\n"), |
532 | err_msg); | 527 | err_msg); |
533 | if (NULL != builder) | 528 | if (NULL != builder) |
534 | { | 529 | { |
535 | /* restart re-build already in progress ... */ | 530 | /* restart re-build already in progress ... */ |
@@ -547,10 +542,8 @@ process_notify (void *cls, | |||
547 | builder = GNUNET_new (struct HostSet); | 542 | builder = GNUNET_new (struct HostSet); |
548 | } | 543 | } |
549 | GNUNET_assert (NULL != peerinfo); | 544 | GNUNET_assert (NULL != peerinfo); |
550 | builder->pitr | 545 | builder->pitr = |
551 | = GNUNET_PEERINFO_iterate (peerinfo, | 546 | GNUNET_PEERINFO_iterate (peerinfo, GNUNET_NO, NULL, &host_processor, NULL); |
552 | GNUNET_NO, NULL, | ||
553 | &host_processor, NULL); | ||
554 | } | 547 | } |
555 | 548 | ||
556 | 549 | ||
@@ -594,7 +587,7 @@ run_daemon (void *cls) | |||
594 | static struct GNUNET_SCHEDULER_Task * | 587 | static struct GNUNET_SCHEDULER_Task * |
595 | prepare_daemon (struct MHD_Daemon *daemon_handle) | 588 | prepare_daemon (struct MHD_Daemon *daemon_handle) |
596 | { | 589 | { |
597 | struct GNUNET_SCHEDULER_Task * ret; | 590 | struct GNUNET_SCHEDULER_Task *ret; |
598 | fd_set rs; | 591 | fd_set rs; |
599 | fd_set ws; | 592 | fd_set ws; |
600 | fd_set es; | 593 | fd_set es; |
@@ -611,9 +604,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
611 | wrs = GNUNET_NETWORK_fdset_create (); | 604 | wrs = GNUNET_NETWORK_fdset_create (); |
612 | wws = GNUNET_NETWORK_fdset_create (); | 605 | wws = GNUNET_NETWORK_fdset_create (); |
613 | max = -1; | 606 | max = -1; |
614 | GNUNET_assert (MHD_YES == | 607 | GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max)); |
615 | MHD_get_fdset (daemon_handle, | ||
616 | &rs, &ws, &es, &max)); | ||
617 | haveto = MHD_get_timeout (daemon_handle, &timeout); | 608 | haveto = MHD_get_timeout (daemon_handle, &timeout); |
618 | if (haveto == MHD_YES) | 609 | if (haveto == MHD_YES) |
619 | tv.rel_value_us = (uint64_t) timeout * 1000LL; | 610 | tv.rel_value_us = (uint64_t) timeout * 1000LL; |
@@ -622,8 +613,11 @@ prepare_daemon (struct MHD_Daemon *daemon_handle) | |||
622 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); | 613 | GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); |
623 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); | 614 | GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); |
624 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, | 615 | ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, |
625 | tv, wrs, wws, | 616 | tv, |
626 | &run_daemon, daemon_handle); | 617 | wrs, |
618 | wws, | ||
619 | &run_daemon, | ||
620 | daemon_handle); | ||
627 | GNUNET_NETWORK_fdset_destroy (wrs); | 621 | GNUNET_NETWORK_fdset_destroy (wrs); |
628 | GNUNET_NETWORK_fdset_destroy (wws); | 622 | GNUNET_NETWORK_fdset_destroy (wws); |
629 | return ret; | 623 | return ret; |
@@ -676,19 +670,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
676 | if (NULL == peerinfo) | 670 | if (NULL == peerinfo) |
677 | { | 671 | { |
678 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 672 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
679 | _("Could not access PEERINFO service. Exiting.\n")); | 673 | _ ("Could not access PEERINFO service. Exiting.\n")); |
680 | return GNUNET_SYSERR; | 674 | return GNUNET_SYSERR; |
681 | } | 675 | } |
682 | if (GNUNET_OK != | 676 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
683 | GNUNET_CONFIGURATION_get_value_number (cfg, | 677 | "HOSTLIST", |
684 | "HOSTLIST", | 678 | "HTTPPORT", |
685 | "HTTPPORT", | 679 | &port)) |
686 | &port)) | ||
687 | return GNUNET_SYSERR; | 680 | return GNUNET_SYSERR; |
688 | if ((0 == port) || (port > UINT16_MAX)) | 681 | if ((0 == port) || (port > UINT16_MAX)) |
689 | { | 682 | { |
690 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 683 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
691 | _("Invalid port number %llu. Exiting.\n"), | 684 | _ ("Invalid port number %llu. Exiting.\n"), |
692 | port); | 685 | port); |
693 | return GNUNET_SYSERR; | 686 | return GNUNET_SYSERR; |
694 | } | 687 | } |
@@ -700,8 +693,9 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
700 | &hostname)) | 693 | &hostname)) |
701 | hostname = GNUNET_RESOLVER_local_fqdn_get (); | 694 | hostname = GNUNET_RESOLVER_local_fqdn_get (); |
702 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 695 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
703 | _("Hostlist service starts on %s:%llu\n"), | 696 | _ ("Hostlist service starts on %s:%llu\n"), |
704 | hostname, port); | 697 | hostname, |
698 | port); | ||
705 | if (NULL != hostname) | 699 | if (NULL != hostname) |
706 | { | 700 | { |
707 | size = strlen (hostname); | 701 | size = strlen (hostname); |
@@ -712,10 +706,11 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
712 | else | 706 | else |
713 | { | 707 | { |
714 | GNUNET_asprintf (&hostlist_uri, | 708 | GNUNET_asprintf (&hostlist_uri, |
715 | "http://%s:%u/", hostname, | 709 | "http://%s:%u/", |
710 | hostname, | ||
716 | (unsigned int) port); | 711 | (unsigned int) port); |
717 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 712 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
718 | _("Address to obtain hostlist: `%s'\n"), | 713 | _ ("Address to obtain hostlist: `%s'\n"), |
719 | hostlist_uri); | 714 | hostlist_uri); |
720 | } | 715 | } |
721 | GNUNET_free (hostname); | 716 | GNUNET_free (hostname); |
@@ -723,29 +718,28 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
723 | 718 | ||
724 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) | 719 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4")) |
725 | { | 720 | { |
726 | if (GNUNET_OK != | 721 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
727 | GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", | 722 | "HOSTLIST", |
728 | "BINDTOIP", &ipv4)) | 723 | "BINDTOIP", |
724 | &ipv4)) | ||
729 | { | 725 | { |
730 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 726 | GNUNET_log ( |
731 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | 727 | GNUNET_ERROR_TYPE_WARNING, |
728 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV4.\n")); | ||
732 | } | 729 | } |
733 | |||
734 | } | 730 | } |
735 | else | 731 | else |
736 | ipv4 = NULL; | 732 | ipv4 = NULL; |
737 | if (GNUNET_CONFIGURATION_have_value (cfg, | 733 | if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6")) |
738 | "HOSTLIST", | 734 | { |
739 | "BINDTOIPV6")) | 735 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
740 | { | 736 | "HOSTLIST", |
741 | if (GNUNET_OK != | 737 | "BINDTOIP", |
742 | GNUNET_CONFIGURATION_get_value_string (cfg, | 738 | &ipv6)) |
743 | "HOSTLIST", | 739 | { |
744 | "BINDTOIP", | 740 | GNUNET_log ( |
745 | &ipv6)) | 741 | GNUNET_ERROR_TYPE_WARNING, |
746 | { | 742 | _ ("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); |
747 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
748 | _("BINDTOIP does not a valid IPv4 address! Ignoring BINDTOIPV6.\n")); | ||
749 | } | 743 | } |
750 | } | 744 | } |
751 | else | 745 | else |
@@ -766,7 +760,8 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
766 | } | 760 | } |
767 | else | 761 | else |
768 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 762 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
769 | _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), | 763 | _ ( |
764 | "`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"), | ||
770 | ipv4); | 765 | ipv4); |
771 | GNUNET_free (ipv4); | 766 | GNUNET_free (ipv4); |
772 | } | 767 | } |
@@ -786,15 +781,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
786 | } | 781 | } |
787 | else | 782 | else |
788 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 783 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
789 | _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), | 784 | _ ( |
785 | "`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"), | ||
790 | ipv6); | 786 | ipv6); |
791 | GNUNET_free (ipv6); | 787 | GNUNET_free (ipv6); |
792 | } | 788 | } |
793 | 789 | ||
794 | 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, |
795 | (uint16_t) port, | 791 | (uint16_t) port, |
796 | &accept_policy_callback, NULL, | 792 | &accept_policy_callback, |
797 | &access_handler_callback, NULL, | 793 | NULL, |
794 | &access_handler_callback, | ||
795 | NULL, | ||
798 | MHD_OPTION_CONNECTION_LIMIT, | 796 | MHD_OPTION_CONNECTION_LIMIT, |
799 | (unsigned int) 128, | 797 | (unsigned int) 128, |
800 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 798 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
@@ -807,9 +805,11 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
807 | sa6, | 805 | sa6, |
808 | MHD_OPTION_END); | 806 | MHD_OPTION_END); |
809 | 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, |
810 | (uint16_t) port, | 808 | (uint16_t) port, |
811 | &accept_policy_callback, NULL, | 809 | &accept_policy_callback, |
812 | &access_handler_callback, NULL, | 810 | NULL, |
811 | &access_handler_callback, | ||
812 | NULL, | ||
813 | MHD_OPTION_CONNECTION_LIMIT, | 813 | MHD_OPTION_CONNECTION_LIMIT, |
814 | (unsigned int) 128, | 814 | (unsigned int) 128, |
815 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, | 815 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, |
@@ -822,11 +822,10 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
822 | sa4, | 822 | sa4, |
823 | MHD_OPTION_END); | 823 | MHD_OPTION_END); |
824 | 824 | ||
825 | if ( (NULL == daemon_handle_v6) && | 825 | if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) |
826 | (NULL == daemon_handle_v4) ) | ||
827 | { | 826 | { |
828 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 827 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
829 | _("Could not start hostlist HTTP server on port %u\n"), | 828 | _ ("Could not start hostlist HTTP server on port %u\n"), |
830 | (unsigned short) port); | 829 | (unsigned short) port); |
831 | return GNUNET_SYSERR; | 830 | return GNUNET_SYSERR; |
832 | } | 831 | } |
@@ -837,9 +836,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
837 | hostlist_task_v4 = prepare_daemon (daemon_handle_v4); | 836 | hostlist_task_v4 = prepare_daemon (daemon_handle_v4); |
838 | if (NULL != daemon_handle_v6) | 837 | if (NULL != daemon_handle_v6) |
839 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); | 838 | hostlist_task_v6 = prepare_daemon (daemon_handle_v6); |
840 | notify = GNUNET_PEERINFO_notify (cfg, | 839 | notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL); |
841 | GNUNET_NO, | ||
842 | &process_notify, NULL); | ||
843 | return GNUNET_OK; | 840 | return GNUNET_OK; |
844 | } | 841 | } |
845 | 842 | ||
@@ -850,8 +847,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
850 | void | 847 | void |
851 | GNUNET_HOSTLIST_server_stop () | 848 | GNUNET_HOSTLIST_server_stop () |
852 | { | 849 | { |
853 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist server shutdown\n"); |
854 | "Hostlist server shutdown\n"); | ||
855 | if (NULL != hostlist_task_v6) | 851 | if (NULL != hostlist_task_v6) |
856 | { | 852 | { |
857 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); | 853 | GNUNET_SCHEDULER_cancel (hostlist_task_v6); |