fix #3275 with solution from https://gnunet.org/bugs/view.php?id=3275#c8029
[oweals/gnunet.git] / src / exit / gnunet-daemon-exit.c
index 3bdac2d517acc1375b82fe1528faabce0c3f8e39..c29638559b6baea02a500e7d658d41378ce9342d 100644 (file)
@@ -787,7 +787,7 @@ store_service (struct GNUNET_CONTAINER_MultiHashMap *service_map,
   char key[sizeof (struct GNUNET_HashCode) + sizeof (uint16_t)];
   struct GNUNET_HashCode desc;
 
-  GNUNET_CRYPTO_hash (name, strlen (name) + 1, &desc);
+  GNUNET_TUN_service_name_to_hash (name, &desc);
   service->name = GNUNET_strdup (name);
   memcpy (&key[0], &destination_port, sizeof (uint16_t));
   memcpy (&key[sizeof(uint16_t)], &desc, sizeof (struct GNUNET_HashCode));
@@ -1900,11 +1900,14 @@ receive_tcp_service (void *cls,
              GNUNET_i2s (&state->peer),
              GNUNET_h2s (&start->service_descriptor),
              (unsigned int) ntohs (start->tcp_header.destination_port));
-  if (NULL == (state->specifics.tcp_udp.serv = find_service (tcp_services, &start->service_descriptor,
-                                                            ntohs (start->tcp_header.destination_port))))
+  if (NULL == (state->specifics.tcp_udp.serv =
+               find_service (tcp_services,
+                             &start->service_descriptor,
+                             ntohs (start->tcp_header.destination_port))))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-               _("No service found for %s on port %d!\n"),
+               _("No service %s found for %s on port %d!\n"),
+                GNUNET_h2s (&start->service_descriptor),
                "TCP",
                ntohs (start->tcp_header.destination_port));
     GNUNET_STATISTICS_update (stats,
@@ -2978,11 +2981,14 @@ receive_udp_service (void *cls,
        GNUNET_i2s (&state->peer),
        GNUNET_h2s (&msg->service_descriptor),
        (unsigned int) ntohs (msg->destination_port));
-  if (NULL == (state->specifics.tcp_udp.serv = find_service (udp_services, &msg->service_descriptor,
-                                                            ntohs (msg->destination_port))))
+  if (NULL == (state->specifics.tcp_udp.serv =
+               find_service (udp_services,
+                             &msg->service_descriptor,
+                             ntohs (msg->destination_port))))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-               _("No service found for %s on port %d!\n"),
+               _("No service %s found for %s on port %d!\n"),
+                GNUNET_h2s (&msg->service_descriptor),
                "UDP",
                ntohs (msg->destination_port));
     GNUNET_STATISTICS_update (stats,
@@ -3015,7 +3021,7 @@ static void *
 new_channel (void *cls,
             struct GNUNET_MESH_Channel *channel,
             const struct GNUNET_PeerIdentity *initiator,
-            uint32_t port, enum MeshOption options)
+            uint32_t port, enum GNUNET_MESH_ChannelOption options)
 {
   struct ChannelState *s = GNUNET_new (struct ChannelState);
 
@@ -3213,6 +3219,12 @@ add_services (int proto,
   char *hostname;
   char *hostport;
   struct LocalService *serv;
+  char *n;
+  size_t slen;
+
+  slen = strlen (name);
+  GNUNET_assert (slen >= 8);
+  n = GNUNET_strndup (name, slen - 8 /* remove .gnunet. */);
 
   for (redirect = strtok (cpy, " "); redirect != NULL;
        redirect = strtok (NULL, " "))
@@ -3220,7 +3232,7 @@ add_services (int proto,
     if (NULL == (hostname = strstr (redirect, ":")))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "option `%s' for domain `%s' is not formatted correctly!\n",
+                 _("Option `%s' for domain `%s' is not formatted correctly!\n"),
                  redirect,
                  name);
       continue;
@@ -3230,9 +3242,9 @@ add_services (int proto,
     if (NULL == (hostport = strstr (hostname, ":")))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "option `%s' for domain `%s' is not formatted correctly!\n",
-                 redirect,
-                 name);
+                  _("Option `%s' for domain `%s' is not formatted correctly!\n"),
+                  redirect,
+                  name);
       continue;
     }
     hostport[0] = '\0';
@@ -3244,14 +3256,16 @@ add_services (int proto,
     if (!((local_port > 0) && (local_port < 65536)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "`%s' is not a valid port number (for domain `%s')!", redirect,
-                 name);
+                  _("`%s' is not a valid port number (for domain `%s')!"),
+                  redirect,
+                  name);
       continue;
     }
     if (!((remote_port > 0) && (remote_port < 65536)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "`%s' is not a valid port number (for domain `%s')!", hostport,
+                 _("`%s' is not a valid port number (for domain `%s')!"),
+                  hostport,
                  name);
       continue;
     }
@@ -3285,7 +3299,7 @@ add_services (int proto,
        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                    _("No addresses found for hostname `%s' of service `%s'!\n"),
                    hostname,
-                   name);
+                   n);
        GNUNET_free (serv);
        continue;
       }
@@ -3298,7 +3312,7 @@ add_services (int proto,
        {
          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                      _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"),
-                     name);
+                     n);
          freeaddrinfo (res);
          GNUNET_free (serv);
          continue;
@@ -3310,7 +3324,7 @@ add_services (int proto,
        {
          GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                      _("Service `%s' configured for IPv4, but IPv4 is disabled!\n"),
-                     name);
+                     n);
          freeaddrinfo (res);
          GNUNET_free (serv);
          continue;
@@ -3322,17 +3336,18 @@ add_services (int proto,
        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                    _("No IP addresses found for hostname `%s' of service `%s'!\n"),
                    hostname,
-                   name);
+                   n);
        GNUNET_free (serv);
        continue;
       }
       freeaddrinfo (res);
     }
     store_service ((IPPROTO_UDP == proto) ? udp_services : tcp_services,
-                  name,
+                  n,
                   local_port,
                   serv);
   }
+  GNUNET_free (n);
 }
 
 
@@ -3543,7 +3558,7 @@ run (void *cls,
 
   dns_exit = NULL;
   if ( (GNUNET_YES ==
-       GNUNET_CONFIGURATION_get_value_yesno (cfg_, "exit", "ENABLE_DNS")) &&
+       GNUNET_CONFIGURATION_get_value_yesno (cfg_, "exit", "EXIT_DNS")) &&
        ( (GNUNET_OK !=
          GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
                                                 "DNS_RESOLVER",
@@ -3557,20 +3572,14 @@ run (void *cls,
     GNUNET_free_non_null (dns_exit);
     dns_exit = NULL;
   }
-  if (NULL != dns_exit)
-    dnsstub = GNUNET_DNSSTUB_start (dns_exit);
-
-
   app_idx = 0;
   if (GNUNET_YES == ipv4_exit)
   {
-    // FIXME use regex to put info
     apptypes[app_idx] = GNUNET_APPLICATION_TYPE_IPV4_GATEWAY;
     app_idx++;
   }
   if (GNUNET_YES == ipv6_exit)
   {
-    // FIXME use regex to put info
     apptypes[app_idx] = GNUNET_APPLICATION_TYPE_IPV6_GATEWAY;
     app_idx++;
   }
@@ -3702,11 +3711,18 @@ run (void *cls,
 
   connections_map = GNUNET_CONTAINER_multihashmap_create (65536, GNUNET_NO);
   connections_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+  if (0 == app_idx)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("No useful service enabled.  Exiting.\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
   mesh_handle
     = GNUNET_MESH_connect (cfg, NULL,
                           &new_channel,
                           &clean_channel, handlers,
-                           apptypes); // FIXME use ports
+                           apptypes);
   if (NULL == mesh_handle)
   {
     GNUNET_SCHEDULER_shutdown ();