gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10142 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r10142 - gnunet/src/transport
Date: Mon, 25 Jan 2010 11:46:32 +0100

Author: nevans
Date: 2010-01-25 11:46:32 +0100 (Mon, 25 Jan 2010)
New Revision: 10142

Modified:
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_udp.c
Log:
resolver for udp plugin, don't propagate welcomes in tcp

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2010-01-25 09:28:20 UTC (rev 
10141)
+++ gnunet/src/transport/plugin_transport_tcp.c 2010-01-25 10:46:32 UTC (rev 
10142)
@@ -52,7 +52,7 @@
 
 
 /**
- * Initial handshake message for a session.  
+ * Initial handshake message for a session.
  */
 struct WelcomeMessage
 {
@@ -334,7 +334,7 @@
   ret->last_quota_update = GNUNET_TIME_absolute_get ();
   ret->quota_in = plugin->env->default_quota_in;
   ret->expecting_welcome = GNUNET_YES;
-  ret->pending_messages = create_welcome (plugin);  
+  ret->pending_messages = create_welcome (plugin);
   return ret;
 }
 
@@ -511,9 +511,9 @@
                        "Notifying transport service about loss of data 
connection with `%4s'.\n",
                        GNUNET_i2s (&session->target));
 #endif
-      /* Data session that actually went past the 
+      /* Data session that actually went past the
          initial handshake; transport service may
-         know about this one, so we need to 
+         know about this one, so we need to
          notify transport service about disconnect */
       session->plugin->env->receive (session->plugin->env->cls,
                                      &session->target, NULL,
@@ -599,7 +599,7 @@
                        "tcp",
                        "Asked to transmit to `%4s' without address and I have 
no existing connection (failing).\n",
                        GNUNET_i2s (target));
-#endif      
+#endif
       return -1;
     }
   if (session == NULL)
@@ -624,7 +624,7 @@
                           "Failed to create connection to `%4s' at `%s'\n",
                           GNUNET_i2s (target),
                           GNUNET_a2s (addr, addrlen));
-#endif      
+#endif
          return -1;
        }
 
@@ -663,7 +663,7 @@
     }
   else
     {
-      /* FIXME: this could be done faster by keeping 
+      /* FIXME: this could be done faster by keeping
         track of the tail of the list... */
       while (NULL != pme->next)
         pme = pme->next;
@@ -725,7 +725,7 @@
          session->client = NULL;
        }
       /* rest of the clean-up of the session will be done as part of
-        disconnect_notify which should be triggered any time now 
+        disconnect_notify which should be triggered any time now
         (or which may be triggering this call in the first place) */
     }
 }
@@ -985,7 +985,7 @@
       GNUNET_SERVER_client_keep (client);
       session = create_session (plugin,
                                &wm->clientIdentity, client);
-      if (GNUNET_OK == 
+      if (GNUNET_OK ==
          GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
        {
 #if DEBUG_TCP
@@ -1091,6 +1091,16 @@
 
   msize = ntohs (message->size);
   session = find_session_by_client (plugin, client);
+
+  if (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == ntohs(message->type))
+  {
+#if DEBUG_TCP
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                   "tcp", "Received a welcome, NOT sending to clients!\n");
+#endif
+    return; /* We don't want to propogate WELCOME messages up! */
+  }
+
   if ( (NULL == session) || (GNUNET_NO != session->expecting_welcome))
     {
       GNUNET_break_op (0);
@@ -1128,7 +1138,7 @@
  * Handlers for the various TCP messages.
  */
 static struct GNUNET_SERVER_MessageHandler my_handlers[] = {
-  {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, 
+  {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
    sizeof (struct WelcomeMessage)},
   {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
   {NULL, NULL, 0, 0}
@@ -1315,7 +1325,7 @@
                      aport);
   GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify,
                                    plugin);
-  /* FIXME: do the two calls below periodically again and 
+  /* FIXME: do the two calls below periodically again and
      not just once (since the info we get might change...) */
   GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
   plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2010-01-25 09:28:20 UTC (rev 
10141)
+++ gnunet/src/transport/plugin_transport_udp.c 2010-01-25 10:46:32 UTC (rev 
10142)
@@ -53,6 +53,12 @@
 static struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
 
 /**
+ * How long until we give up on transmitting the welcome message?
+ */
+#define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 5)
+
+
+/**
  * Message-Packet header.
  */
 struct UDPMessage
@@ -100,6 +106,11 @@
   struct GNUNET_SERVICE_Context *service;
 
   /**
+   * Handle for request of hostname resolution, non-NULL if pending.
+   */
+  struct GNUNET_RESOLVER_RequestHandle *hostname_dns;
+
+  /**
    * ID of task used to update our addresses when one expires.
    */
   GNUNET_SCHEDULER_TaskIdentifier address_update_task;
@@ -239,6 +250,69 @@
 }
 
 
+/**
+ * Add the IP of our network interface to the list of
+ * our external IP addresses.
+ */
+static int
+process_interfaces (void *cls,
+                    const char *name,
+                    int isDefault,
+                    const struct sockaddr *addr, socklen_t addrlen)
+{
+  struct Plugin *plugin = cls;
+  int af;
+  struct sockaddr_in *v4;
+  struct sockaddr_in6 *v6;
+
+  af = addr->sa_family;
+  if (af == AF_INET)
+    {
+      v4 = (struct sockaddr_in *) addr;
+      v4->sin_port = htons (plugin->adv_port);
+    }
+  else
+    {
+      GNUNET_assert (af == AF_INET6);
+      v6 = (struct sockaddr_in6 *) addr;
+      v6->sin6_port = htons (plugin->adv_port);
+    }
+  GNUNET_log_from (GNUNET_ERROR_TYPE_INFO |
+                   GNUNET_ERROR_TYPE_BULK,
+                   "udp", _("Found address `%s' (%s)\n"),
+                   GNUNET_a2s (addr, addrlen), name);
+  plugin->env->notify_address (plugin->env->cls,
+                               "udp",
+                               addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL);
+
+  return GNUNET_OK;
+}
+
+
+/**
+ * Function called by the resolver for each address obtained from DNS
+ * for our own hostname.  Add the addresses to the list of our
+ * external IP addresses.
+ *
+ * @param cls closure
+ * @param addr one of the addresses of the host, NULL for the last address
+ * @param addrlen length of the address
+ */
+static void
+process_hostname_ips (void *cls,
+                      const struct sockaddr *addr, socklen_t addrlen)
+{
+  struct Plugin *plugin = cls;
+
+  if (addr == NULL)
+    {
+      plugin->hostname_dns = NULL;
+      return;
+    }
+  process_interfaces (plugin, "<hostname>", GNUNET_YES, addr, addrlen);
+}
+
+
 /*
  * @param cls the plugin handle
  * @param tc the scheduling context (for rescheduling this function again)
@@ -667,6 +741,16 @@
 
   plugin->service = service;
 
+  /* FIXME: do the two calls below periodically again and
+     not just once (since the info we get might change...) */
+  GNUNET_OS_network_interfaces_list (&process_interfaces, plugin);
+  plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched,
+                                                           env->cfg,
+                                                           AF_UNSPEC,
+                                                           
HOSTNAME_RESOLVE_TIMEOUT,
+                                                           
&process_hostname_ips,
+                                                           plugin);
+
   udp_sock = udp_transport_server_start (plugin);
 
   GNUNET_assert (udp_sock != NULL);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]