gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r28340 - msh/src


From: gnunet
Subject: [GNUnet-SVN] r28340 - msh/src
Date: Tue, 30 Jul 2013 20:42:38 +0200

Author: harsha
Date: 2013-07-30 20:42:38 +0200 (Tue, 30 Jul 2013)
New Revision: 28340

Modified:
   msh/src/addressmap.c
   msh/src/addressmap.h
   msh/src/mshd.c
   msh/src/mtypes.h
   msh/src/util.c
   msh/src/util.h
Log:
- send port numbers too in instance address messages


Modified: msh/src/addressmap.c
===================================================================
--- msh/src/addressmap.c        2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/addressmap.c        2013-07-30 18:42:38 UTC (rev 28340)
@@ -77,7 +77,13 @@
 #define instance_address_ip(iaddr) \
   (NULL == iaddr ? 0 : ((uint32_t) iaddr->ip))
 
+/**
+ * Get the port number from an instance address
+ */
+#define instance_address_port(iaddr) \
+  (iaddr->port)
 
+
 /**
  * Create an instance address structure from its port number and ip address
  *
@@ -231,7 +237,7 @@
 {
 
   /**
-   * the size of the above array
+   * the size of the following array
    */
   unsigned int size;
 
@@ -469,6 +475,8 @@
   _iaddr_msgs = GNUNET_malloc (sizeof (struct MSH_MSG_InstanceAdresses *) * n);
   for (cnt = 0; cnt < m->size; cnt++)
   {
+    struct InstanceAddr *head;
+
     GNUNET_assert (NULL != (iainfo = m->map[cnt]));
     msize = sizeof (struct MSH_MSG_InstanceAdresses) 
         + (sizeof (uint32_t) * iainfo->naddrs);
@@ -477,11 +485,15 @@
     _iaddr_msgs[cnt]->rank = htons (iainfo->rank);
     _iaddr_msgs[cnt]->nips = htons (iainfo->naddrs);
     iaddr = iainfo->addr_head;
+    head = iaddr;
+    _iaddr_msgs[cnt]->port = htons (instance_address_port (head));
     for (nip = 0; nip < iainfo->naddrs; nip++, iaddr = iaddr->next)
     {
       GNUNET_assert (NULL != iaddr);
       GNUNET_assert (0 != htonl (instance_address_ip (iaddr)));
-      _iaddr_msgs[cnt]->ipaddrs[nip] = htonl (instance_address_ip (iaddr));    
  
+      GNUNET_assert (instance_address_port (head) == 
+                     instance_address_port (iaddr));
+      _iaddr_msgs[cnt]->ipaddrs[nip] = htonl (instance_address_ip (iaddr));
     }
   }
   *iaddr_msgs = _iaddr_msgs;
@@ -527,11 +539,39 @@
   iainfo = instance_address_info_create (rank);
   for (cnt = 0; cnt < n; cnt++)
   {
-    iaddr = instance_address_create_sockaddr_in 
-        (0, (in_addr_t) ntohl (iaddr_msg->ipaddrs[cnt]));
+    iaddr = instance_address_create_sockaddr_in
+        (ntohs (iaddr_msg->port),
+         (in_addr_t) ntohl (iaddr_msg->ipaddrs[cnt]));
     instance_address_info_add_address (iainfo, iaddr);
   }
   n = addressmap_intersect (m, iainfo);
   instance_address_info_destroy (iainfo);
   return n;
 }
+
+
+/**
+ * Print the addressmap
+ *
+ * @param m the address map
+ */
+void
+addressmap_print (AddressMap *m)
+{
+  struct InstanceAddrInfo *iainfo;
+  struct InstanceAddr *iaddr;
+  unsigned int cnt;
+  unsigned int dnt;
+
+  for (cnt = 0; cnt < m->size; cnt++)
+  {
+    iainfo = m->map[cnt];
+    GNUNET_assert (NULL != iainfo);
+    iaddr = iainfo->addr_head;
+    for (dnt = 0; dnt < iainfo->naddrs; dnt++, iaddr = iaddr->next)
+    {
+      GNUNET_assert (NULL != iaddr);
+      printf ("Instance %u: %s:%u\n", iainfo->rank, ip2str (iaddr->ip), 
iaddr->port);
+    }
+  }
+}

Modified: msh/src/addressmap.h
===================================================================
--- msh/src/addressmap.h        2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/addressmap.h        2013-07-30 18:42:38 UTC (rev 28340)
@@ -244,6 +244,13 @@
                           const struct MSH_MSG_InstanceAdresses *iaddr_msg);
 
 
+/**
+ * Print the addressmap
+ *
+ * @param m the address map
+ */
+void
+addressmap_print (AddressMap *m);
 
 
 #endif  /* ADDRESSMAP_H_ */

Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c      2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/mshd.c      2013-07-30 18:42:38 UTC (rev 28340)
@@ -73,6 +73,9 @@
 };
 
 
+/**
+ * Context information for reading from incoming connections
+ */
 struct ReadContext
 {
   /**
@@ -98,6 +101,26 @@
 
 
 /**
+ * The mode of the current listen socket; 
+ */
+enum ListenMode
+{
+  /**
+   * Mode in which the listen socket accepts connections from other instances
+   * and closes them immediately after reading some data.  The incoming
+   * connections are used to verify which IP addresses of this instance are
+   * reachable from other instances
+   */
+  LISTEN_MODE_PROBE,
+
+  /**
+   * In this mode the listen socket accepts requests for starting remote 
processes
+   */
+  LISTEN_MODE_SERV
+};
+
+
+/**
  * Mapping for instance addresses
  */
 AddressMap *addrmap;
@@ -215,35 +238,6 @@
 uint16_t listen_port;
 
 
-static char *
-saddr2str (const struct sockaddr *addr, const socklen_t addrlen)
-{
-  static char hostip[NI_MAXHOST];
-
-  if (0 != getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, 
-                        NI_NUMERICHOST))
-  {
-    LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "getnameinfo");
-    return NULL;
-  }
-  return hostip;
-}
-
-
-char *
-ip2str (const in_addr_t ip)
-{
-  static char hostip[NI_MAXHOST];
-  
-  GNUNET_break (0 < snprintf (hostip, NI_MAXHOST, "%u.%u.%u.%u",
-                           ip >> 24, 
-                           (ip >> 16) % 256,
-                           (ip >> 8) % 256,
-                           ip % 256));
-  return hostip;
-}
-
-
 /**
  * Callback function invoked for each interface found.
  *
@@ -387,6 +381,7 @@
   }
   LOG_DEBUG ("Verification phase complete; commencing reduction phase\n");
   GNUNET_break (GNUNET_OK == reduce_ntree ());
+  addressmap_print (addrmap);  
 }
 
 
@@ -905,6 +900,7 @@
                                       &sigpipe_read, NULL);
   addrlen = sizeof (struct sockaddr_in);
   (void) memset (&addr, 0, addrlen);
+  addr.sin_addr.s_addr = INADDR_ANY;   /* bind to all available addresses */
   listen_socket = open_listen_socket ((struct sockaddr *) &addr, addrlen, 
rwidth);
   listen_port = ntohs (addr.sin_port);
   if (NULL == listen_socket)
@@ -913,7 +909,8 @@
   {
     GNUNET_break (0);
     goto clo_ret;
-  }  
+  }
+  LOG_DEBUG ("Listening on port %u\n", listen_port);
   GNUNET_OS_network_interfaces_list (&net_if_processor, NULL);
   if (0 == nips)
   {

Modified: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h    2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/mtypes.h    2013-07-30 18:42:38 UTC (rev 28340)
@@ -88,6 +88,11 @@
   uint16_t rank GNUNET_PACKED;
 
   /**
+   * The port number on which the instance is listening
+   */
+  uint16_t port GNUNET_PACKED;
+
+  /**
    * The number of addresses
    */
   uint16_t nips GNUNET_PACKED;

Modified: msh/src/util.c
===================================================================
--- msh/src/util.c      2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/util.c      2013-07-30 18:42:38 UTC (rev 28340)
@@ -88,3 +88,32 @@
   }
   return sock;
 }
+
+
+char *
+saddr2str (const struct sockaddr *addr, const socklen_t addrlen)
+{
+  static char hostip[NI_MAXHOST];
+
+  if (0 != getnameinfo (addr, addrlen, hostip, NI_MAXHOST, NULL, 0, 
+                        NI_NUMERICHOST))
+  {
+    LOG_STRERROR ("getnameinfo");
+    return NULL;
+  }
+  return hostip;
+}
+
+
+char *
+ip2str (const in_addr_t ip)
+{
+  static char hostip[NI_MAXHOST];
+  
+  GNUNET_break (0 < snprintf (hostip, NI_MAXHOST, "%u.%u.%u.%u",
+                           ip >> 24, 
+                           (ip >> 16) % 256,
+                           (ip >> 8) % 256,
+                           ip % 256));
+  return hostip;
+}

Modified: msh/src/util.h
===================================================================
--- msh/src/util.h      2013-07-30 15:43:08 UTC (rev 28339)
+++ msh/src/util.h      2013-07-30 18:42:38 UTC (rev 28340)
@@ -18,5 +18,25 @@
 open_listen_socket (struct sockaddr *addr, const socklen_t addrlen, int 
backlog);
 
 
+/**
+ * Creates a new non-blocking socket and binds it to the given address and 
makes
+ * it a listen socket
+ *
+ * @param addr the address to bind to
+ * @param addrlen the length of the addr
+ * @param backlog the max length of the pending connections.  This will be
+ *          passed to listen()
+ * @return the socket's fd; -1 on error
+ */
+int
+open_socket (const struct sockaddr *addr, const socklen_t addrlen);
+
+char *
+saddr2str (const struct sockaddr *addr, const socklen_t addrlen);
+
+char *
+ip2str (const in_addr_t ip);
+
+
 #endif /* #ifndef MSH_UTIL_H */
 /* end of MSH_UTIL_H */




reply via email to

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