aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-03 08:19:03 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-03 08:19:03 +0000
commitd7cf4a2a573e31c21630c08b038c2c648e5d3785 (patch)
treed0b4071d8d6be6b967805c8f6e987149374e1715 /src/hostlist
parentc3ff8f261c25be9fc76ea40ab2f4e3b1313d3c08 (diff)
downloadgnunet-d7cf4a2a573e31c21630c08b038c2c648e5d3785.tar.gz
gnunet-d7cf4a2a573e31c21630c08b038c2c648e5d3785.zip
add separate BINDTO options for IPv4 and IPv6
Diffstat (limited to 'src/hostlist')
-rw-r--r--src/hostlist/hostlist-server.c127
-rw-r--r--src/hostlist/hostlist.conf21
2 files changed, 92 insertions, 56 deletions
diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c
index b840eb693..adf9359c6 100644
--- a/src/hostlist/hostlist-server.c
+++ b/src/hostlist/hostlist-server.c
@@ -113,8 +113,6 @@ struct HostSet
113static struct HostSet *builder; 113static struct HostSet *builder;
114 114
115 115
116
117
118/** 116/**
119 * Function that assembles our response. 117 * Function that assembles our response.
120 */ 118 */
@@ -142,12 +140,12 @@ finish_response ()
142 140
143 141
144/** 142/**
145 * Set 'cls' to GNUNET_YES (we have an address!). 143 * Set @a cls to #GNUNET_YES (we have an address!).
146 * 144 *
147 * @param cls closure, an 'int*' 145 * @param cls closure, an `int *`
148 * @param address the address (ignored) 146 * @param address the address (ignored)
149 * @param expiration expiration time (call is ignored if this is in the past) 147 * @param expiration expiration time (call is ignored if this is in the past)
150 * @return GNUNET_SYSERR to stop iterating (unless expiration has occured) 148 * @return #GNUNET_SYSERR to stop iterating (unless expiration has occured)
151 */ 149 */
152static int 150static int
153check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address, 151check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address,
@@ -172,8 +170,10 @@ check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address,
172 * hostlist response construction. 170 * hostlist response construction.
173 */ 171 */
174static void 172static void
175host_processor (void *cls, const struct GNUNET_PeerIdentity *peer, 173host_processor (void *cls,
176 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 174 const struct GNUNET_PeerIdentity *peer,
175 const struct GNUNET_HELLO_Message *hello,
176 const char *err_msg)
177{ 177{
178 size_t old; 178 size_t old;
179 size_t s; 179 size_t s;
@@ -250,6 +250,7 @@ accept_policy_callback (void *cls, const struct sockaddr *addr,
250 return MHD_YES; /* accept all */ 250 return MHD_YES; /* accept all */
251} 251}
252 252
253
253/** 254/**
254 * Add headers to a request indicating that we allow Cross-Origin Resource 255 * Add headers to a request indicating that we allow Cross-Origin Resource
255 * Sharing. 256 * Sharing.
@@ -268,6 +269,7 @@ add_cors_headers(struct MHD_Response *response)
268 "86400"); 269 "86400");
269} 270}
270 271
272
271/** 273/**
272 * Main request handler. 274 * Main request handler.
273 */ 275 */
@@ -305,7 +307,8 @@ access_handler_callback (void *cls, struct MHD_Connection *connection,
305 if (NULL == *con_cls) 307 if (NULL == *con_cls)
306 { 308 {
307 (*con_cls) = &dummy; 309 (*con_cls) = &dummy;
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending 100 CONTINUE reply\n"); 310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
311 "Sending 100 CONTINUE reply\n");
309 return MHD_YES; /* send 100 continue */ 312 return MHD_YES; /* send 100 continue */
310 } 313 }
311 if (0 != *upload_data_size) 314 if (0 != *upload_data_size)
@@ -322,18 +325,19 @@ access_handler_callback (void *cls, struct MHD_Connection *connection,
322 if (NULL == response) 325 if (NULL == response)
323 { 326 {
324 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 327 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
325 _ 328 _("Could not handle hostlist request since I do not have a response yet\n"));
326 ("Could not handle hostlist request since I do not have a response yet\n"));
327 GNUNET_STATISTICS_update (stats, 329 GNUNET_STATISTICS_update (stats,
328 gettext_noop 330 gettext_noop
329 ("hostlist requests refused (not ready)"), 1, 331 ("hostlist requests refused (not ready)"), 1,
330 GNUNET_YES); 332 GNUNET_YES);
331 return MHD_NO; /* internal error, no response yet */ 333 return MHD_NO; /* internal error, no response yet */
332 } 334 }
333 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received request for our hostlist\n")); 335 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
334 GNUNET_STATISTICS_update (stats, gettext_noop ("hostlist requests processed"), 336 _("Received request for our hostlist\n"));
337 GNUNET_STATISTICS_update (stats,
338 gettext_noop ("hostlist requests processed"),
335 1, GNUNET_YES); 339 1, GNUNET_YES);
336 add_cors_headers(response); 340 add_cors_headers (response);
337 return MHD_queue_response (connection, MHD_HTTP_OK, response); 341 return MHD_queue_response (connection, MHD_HTTP_OK, response);
338} 342}
339 343
@@ -505,7 +509,6 @@ run_daemon (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
505 hostlist_task_v6 = prepare_daemon (daemon_handle); 509 hostlist_task_v6 = prepare_daemon (daemon_handle);
506} 510}
507 511
508#define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG
509 512
510/** 513/**
511 * Function that queries MHD's select sets and 514 * Function that queries MHD's select sets and
@@ -521,7 +524,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
521 struct GNUNET_NETWORK_FDSet *wrs; 524 struct GNUNET_NETWORK_FDSet *wrs;
522 struct GNUNET_NETWORK_FDSet *wws; 525 struct GNUNET_NETWORK_FDSet *wws;
523 int max; 526 int max;
524 UNSIGNED_MHD_LONG_LONG timeout; 527 MHD_UNSIGNED_LONG_LONG timeout;
525 int haveto; 528 int haveto;
526 struct GNUNET_TIME_Relative tv; 529 struct GNUNET_TIME_Relative tv;
527 530
@@ -552,7 +555,7 @@ prepare_daemon (struct MHD_Daemon *daemon_handle)
552/** 555/**
553 * Start server offering our hostlist. 556 * Start server offering our hostlist.
554 * 557 *
555 * @return GNUNET_OK on success 558 * @return #GNUNET_OK on success
556 */ 559 */
557int 560int
558GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c, 561GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
@@ -564,16 +567,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
564{ 567{
565 unsigned long long port; 568 unsigned long long port;
566 char *hostname; 569 char *hostname;
567 char *ip; 570 char *ipv4;
571 char *ipv6;
568 size_t size; 572 size_t size;
569 struct in_addr i4; 573 struct in_addr i4;
570 struct in6_addr i6; 574 struct in6_addr i6;
571 struct sockaddr_in v4; 575 struct sockaddr_in v4;
572 struct sockaddr_in6 v6; 576 struct sockaddr_in6 v6;
573 const struct sockaddr *sa; 577 const struct sockaddr *sa4;
578 const struct sockaddr *sa6;
574 579
575 advertising = advertise; 580 advertising = advertise;
576 if (!advertising) 581 if (! advertising)
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Advertising not enabled on this hostlist server\n"); 583 "Advertising not enabled on this hostlist server\n");
579 else 584 else
@@ -589,22 +594,27 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
589 return GNUNET_SYSERR; 594 return GNUNET_SYSERR;
590 } 595 }
591 if (GNUNET_OK != 596 if (GNUNET_OK !=
592 GNUNET_CONFIGURATION_get_value_number (cfg, "HOSTLIST", "HTTPPORT", 597 GNUNET_CONFIGURATION_get_value_number (cfg,
598 "HOSTLIST",
599 "HTTPPORT",
593 &port)) 600 &port))
594 return GNUNET_SYSERR; 601 return GNUNET_SYSERR;
595 if ((0 == port) || (port > UINT16_MAX)) 602 if ((0 == port) || (port > UINT16_MAX))
596 { 603 {
597 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
598 _("Invalid port number %llu. Exiting.\n"), port); 605 _("Invalid port number %llu. Exiting.\n"),
606 port);
599 return GNUNET_SYSERR; 607 return GNUNET_SYSERR;
600 } 608 }
601 609
602 if (GNUNET_SYSERR == 610 if (GNUNET_SYSERR ==
603 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", 611 GNUNET_CONFIGURATION_get_value_string (cfg,
604 "EXTERNAL_DNS_NAME", &hostname)) 612 "HOSTLIST",
613 "EXTERNAL_DNS_NAME",
614 &hostname))
605 hostname = GNUNET_RESOLVER_local_fqdn_get (); 615 hostname = GNUNET_RESOLVER_local_fqdn_get ();
606 616 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
607 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist service starts on %s:%llu\n"), 617 _("Hostlist service starts on %s:%llu\n"),
608 hostname, port); 618 hostname, port);
609 if (NULL != hostname) 619 if (NULL != hostname)
610 { 620 {
@@ -615,25 +625,36 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
615 } 625 }
616 else 626 else
617 { 627 {
618 GNUNET_asprintf (&hostlist_uri, "http://%s:%u/", hostname, 628 GNUNET_asprintf (&hostlist_uri,
629 "http://%s:%u/", hostname,
619 (unsigned int) port); 630 (unsigned int) port);
620 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 631 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
621 _("Address to obtain hostlist: `%s'\n"), hostlist_uri); 632 _("Address to obtain hostlist: `%s'\n"),
633 hostlist_uri);
622 } 634 }
623 GNUNET_free (hostname); 635 GNUNET_free (hostname);
624 } 636 }
625 637
626 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIP")) 638 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV4"))
627 { 639 {
628 GNUNET_break (GNUNET_OK == 640 GNUNET_break (GNUNET_OK ==
629 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", 641 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
630 "BINDTOIP", &ip)); 642 "BINDTOIP", &ipv4));
631 } 643 }
632 else 644 else
633 ip = NULL; 645 ipv4 = NULL;
634 if (NULL != ip) 646 if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIPV6"))
635 { 647 {
636 if (1 == inet_pton (AF_INET, ip, &i4)) 648 GNUNET_break (GNUNET_OK ==
649 GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
650 "BINDTOIP", &ipv6));
651 }
652 else
653 ipv6 = NULL;
654 sa4 = NULL;
655 if (NULL != ipv4)
656 {
657 if (1 == inet_pton (AF_INET, ipv4, &i4))
637 { 658 {
638 memset (&v4, 0, sizeof (v4)); 659 memset (&v4, 0, sizeof (v4));
639 v4.sin_family = AF_INET; 660 v4.sin_family = AF_INET;
@@ -642,9 +663,18 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
642#if HAVE_SOCKADDR_IN_SIN_LEN 663#if HAVE_SOCKADDR_IN_SIN_LEN
643 v4.sin_len = sizeof (v4); 664 v4.sin_len = sizeof (v4);
644#endif 665#endif
645 sa = (const struct sockaddr *) &v4; 666 sa4 = (const struct sockaddr *) &v4;
646 } 667 }
647 else if (1 == inet_pton (AF_INET6, ip, &i6)) 668 else
669 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
670 _("`%s' is not a valid IPv4 address! Ignoring BINDTOIPV4.\n"),
671 ipv4);
672 GNUNET_free (ipv4);
673 }
674 sa6 = NULL;
675 if (NULL != ipv6)
676 {
677 if (1 == inet_pton (AF_INET6, ipv6, &i6))
648 { 678 {
649 memset (&v6, 0, sizeof (v6)); 679 memset (&v6, 0, sizeof (v6));
650 v6.sin6_family = AF_INET6; 680 v6.sin6_family = AF_INET6;
@@ -653,19 +683,14 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
653#if HAVE_SOCKADDR_IN_SIN_LEN 683#if HAVE_SOCKADDR_IN_SIN_LEN
654 v6.sin6_len = sizeof (v6); 684 v6.sin6_len = sizeof (v6);
655#endif 685#endif
656 sa = (const struct sockaddr *) &v6; 686 sa6 = (const struct sockaddr *) &v6;
657 } 687 }
658 else 688 else
659 {
660 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 689 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
661 _("`%s' is not a valid IP address! Ignoring BINDTOIP.\n"), 690 _("`%s' is not a valid IPv6 address! Ignoring BINDTOIPV6.\n"),
662 ip); 691 ipv6);
663 sa = NULL; 692 GNUNET_free (ipv6);
664 }
665 GNUNET_free (ip);
666 } 693 }
667 else
668 sa = NULL;
669 694
670 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG, 695 daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6 | MHD_USE_DEBUG,
671 (uint16_t) port, 696 (uint16_t) port,
@@ -680,7 +705,7 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
680 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 705 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
681 (size_t) (16 * 1024), 706 (size_t) (16 * 1024),
682 MHD_OPTION_SOCK_ADDR, 707 MHD_OPTION_SOCK_ADDR,
683 sa, 708 sa6,
684 MHD_OPTION_END); 709 MHD_OPTION_END);
685 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG, 710 daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG | MHD_USE_DEBUG,
686 (uint16_t) port, 711 (uint16_t) port,
@@ -695,10 +720,11 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
695 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 720 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
696 (size_t) (16 * 1024), 721 (size_t) (16 * 1024),
697 MHD_OPTION_SOCK_ADDR, 722 MHD_OPTION_SOCK_ADDR,
698 sa, 723 sa4,
699 MHD_OPTION_END); 724 MHD_OPTION_END);
700 725
701 if ((NULL == daemon_handle_v6) && (NULL == daemon_handle_v4)) 726 if ( (NULL == daemon_handle_v6) &&
727 (NULL == daemon_handle_v4) )
702 { 728 {
703 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 729 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
704 _("Could not start hostlist HTTP server on port %u\n"), 730 _("Could not start hostlist HTTP server on port %u\n"),
@@ -709,13 +735,12 @@ GNUNET_HOSTLIST_server_start (const struct GNUNET_CONFIGURATION_Handle *c,
709 core = co; 735 core = co;
710 *server_ch = &connect_handler; 736 *server_ch = &connect_handler;
711 *server_dh = &disconnect_handler; 737 *server_dh = &disconnect_handler;
712 if (daemon_handle_v4 != NULL) 738 if (NULL != daemon_handle_v4)
713 hostlist_task_v4 = prepare_daemon (daemon_handle_v4); 739 hostlist_task_v4 = prepare_daemon (daemon_handle_v4);
714 if (daemon_handle_v6 != NULL) 740 if (NULL != daemon_handle_v6)
715 hostlist_task_v6 = prepare_daemon (daemon_handle_v6); 741 hostlist_task_v6 = prepare_daemon (daemon_handle_v6);
716 742 notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO,
717 notify = GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_notify, NULL); 743 &process_notify, NULL);
718
719 return GNUNET_OK; 744 return GNUNET_OK;
720} 745}
721 746
diff --git a/src/hostlist/hostlist.conf b/src/hostlist/hostlist.conf
index 7c63cb61b..90468f84a 100644
--- a/src/hostlist/hostlist.conf
+++ b/src/hostlist/hostlist.conf
@@ -1,8 +1,14 @@
1[hostlist] 1[hostlist]
2BINARY = gnunet-daemon-hostlist
3
2# port for hostlist http server 4# port for hostlist http server
3HTTPPORT = 8080 5HTTPPORT = 8080
6
7# External DNS name other peers should use to access this hostlist
8# EXTERNAL_DNS_NAME =
9
10# Where do we store URLs of other hostlists we have learned?
4HOSTLISTFILE = $GNUNET_CONFIG_HOME/hostlist/learned.txt 11HOSTLISTFILE = $GNUNET_CONFIG_HOME/hostlist/learned.txt
5BINARY = gnunet-daemon-hostlist
6 12
7# Options: 13# Options:
8# -p : provide a hostlist as a hostlist servers 14# -p : provide a hostlist as a hostlist servers
@@ -10,11 +16,16 @@ BINARY = gnunet-daemon-hostlist
10# -e : enable learning advertised hostlists 16# -e : enable learning advertised hostlists
11# -a : advertise hostlist to other servers 17# -a : advertise hostlist to other servers
12OPTIONS = -b 18OPTIONS = -b
13SERVERS = http://v10.gnunet.org/hostlist 19
20# Default list of hostlist servers for bootstrapping
21SERVERS = http://v10.gnunet.org/hostlist
14# http://silent.0xdeadc0de.eu:8080/ 22# http://silent.0xdeadc0de.eu:8080/
15# http://ioerror.gnunet.org:65535/ 23
16# bind hostlist http server to a specific IPv4 or IPv6 24# bind hostlist http server to a specific IPv4
17# BINDTOIP = 25# BINDTOIPV4 =
26
27# bind hostlist http server to a specific IPv6
28# BINDTOIPV6 =
18 29
19# Hostname or IP of proxy server for downloading hostlists 30# Hostname or IP of proxy server for downloading hostlists
20# PROXY = 31# PROXY =