View Issue Details

IDProjectCategoryView StatusLast Update
0002140GNUnethostlist daemonpublic2012-06-02 19:15
ReporterChristian Grothoff Assigned Tovminko  
PrioritylowSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product VersionGit master 
Target Version0.9.3Fixed in Version0.9.3 
Summary0002140: add BINDTO option for hostlist
DescriptionJake wants to be able to offer the hostlist only for a specific IP. For this, we'd need a new configuration option (or two, one for IPv4, one for IPv6) and then parse the IP and pass it to MHD.
TagsNo tags attached.
Attached Files
gnunet-bug2140-fix.patch (3,513 bytes)   
Index: src/hostlist/hostlist.conf
===================================================================
--- src/hostlist/hostlist.conf	(revision 20436)
+++ src/hostlist/hostlist.conf	(working copy)
@@ -10,5 +10,6 @@
 SERVERS = http://v9.gnunet.org:58080/ http://ioerror.gnunet.org:65535/
 # proxy for downloading hostlists
 HTTP-PROXY = 
+# bind hostlist http server to a specific IPv4 or IPv6
+# BINDTOIP =
 
-
Index: src/hostlist/hostlist-server.c
===================================================================
--- src/hostlist/hostlist-server.c	(revision 20436)
+++ src/hostlist/hostlist-server.c	(working copy)
@@ -537,7 +537,13 @@
 {
   unsigned long long port;
   char *hostname;
+  char *ip;
   size_t size;
+  struct in_addr i4;
+  struct in6_addr i6;
+  struct sockaddr_in v4;
+  struct sockaddr_in6 v6;
+  const struct sockaddr *sa;
 
   advertising = advertise;
   if (!advertising)
@@ -589,6 +595,50 @@
     }
     GNUNET_free (hostname);
   }
+
+  if (GNUNET_CONFIGURATION_have_value (cfg, "HOSTLIST", "BINDTOIP"))
+  {
+    GNUNET_break (GNUNET_OK ==
+                  GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST",
+                                                         "BINDTOIP", &ip));
+  }
+  else 
+    ip = NULL;
+  if (ip != NULL)
+  {
+    if (1 == inet_pton (AF_INET, ip, &i4))
+    {
+      memset (&v4, 0, sizeof (v4));
+      v4.sin_family = AF_INET;
+      v4.sin_addr = i4;
+      v4.sin_port = htons (port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+      v4.sin_len = sizeof (v4);
+#endif
+      sa = (const struct sockaddr *) &v4;
+    }
+    else if (1 == inet_pton (AF_INET6, ip, &i6))
+    {
+      memset (&v6, 0, sizeof (v6));
+      v6.sin6_family = AF_INET6;
+      v6.sin6_addr = i6;
+      v6.sin6_port = htons (port);
+#if HAVE_SOCKADDR_IN_SIN_LEN
+      v6.sin6_len = sizeof (v6);
+#endif
+      sa = (const struct sockaddr *) &v6;
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _("`%s' is not a valid IP address! Ignoring BINDTOIP.\n"),
+                  ip);
+      sa = NULL;
+    }
+  }
+  else
+    sa = NULL;
+
   daemon_handle_v6 = MHD_start_daemon (MHD_USE_IPv6
 #if DEBUG_HOSTLIST_SERVER
                                        | MHD_USE_DEBUG
@@ -603,7 +653,10 @@
                                        MHD_OPTION_CONNECTION_TIMEOUT,
                                        (unsigned int) 16,
                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT,
-                                       (size_t) (16 * 1024), MHD_OPTION_END);
+                                       (size_t) (16 * 1024),
+                                       MHD_OPTION_SOCK_ADDR,
+                                       sa,
+                                       MHD_OPTION_END);
   daemon_handle_v4 = MHD_start_daemon (MHD_NO_FLAG
 #if DEBUG_HOSTLIST_SERVER
                                        | MHD_USE_DEBUG
@@ -618,7 +671,10 @@
                                        MHD_OPTION_CONNECTION_TIMEOUT,
                                        (unsigned int) 16,
                                        MHD_OPTION_CONNECTION_MEMORY_LIMIT,
-                                       (size_t) (16 * 1024), MHD_OPTION_END);
+                                       (size_t) (16 * 1024),
+                                       MHD_OPTION_SOCK_ADDR,
+                                       sa,
+                                       MHD_OPTION_END);
 
   if ((daemon_handle_v6 == NULL) && (daemon_handle_v4 == NULL))
   {
gnunet-bug2140-fix.patch (3,513 bytes)   

Activities

vminko

2012-03-11 22:54

reporter   ~0005597

The proposed fix is attached.

Christian Grothoff

2012-03-11 23:51

manager   ~0005599

Committed as SNV 20445. Thanks!

Issue History

Date Modified Username Field Change
2012-02-06 14:45 Christian Grothoff New Issue
2012-02-06 14:45 Christian Grothoff Status new => assigned
2012-02-06 14:45 Christian Grothoff Assigned To => Matthias Wachs
2012-02-06 20:05 Christian Grothoff Assigned To Matthias Wachs =>
2012-02-06 20:05 Christian Grothoff Priority normal => low
2012-02-06 20:05 Christian Grothoff Status assigned => confirmed
2012-02-06 20:05 Christian Grothoff Description Updated
2012-02-21 21:52 Christian Grothoff Target Version => 0.9.4
2012-03-11 22:53 vminko File Added: gnunet-bug2140-fix.patch
2012-03-11 22:54 vminko Note Added: 0005597
2012-03-11 23:51 Christian Grothoff Assigned To => vminko
2012-03-11 23:51 Christian Grothoff Status confirmed => assigned
2012-03-11 23:51 Christian Grothoff Note Added: 0005599
2012-03-11 23:51 Christian Grothoff Status assigned => resolved
2012-03-11 23:51 Christian Grothoff Fixed in Version => 0.9.3
2012-03-11 23:51 Christian Grothoff Resolution open => fixed
2012-03-11 23:52 Christian Grothoff Target Version 0.9.4 => 0.9.3
2012-06-02 19:15 Christian Grothoff Status resolved => closed