gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27134 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r27134 - gnunet/src/mesh
Date: Tue, 14 May 2013 17:55:50 +0200

Author: bartpolot
Date: 2013-05-14 17:55:50 +0200 (Tue, 14 May 2013)
New Revision: 27134

Modified:
   gnunet/src/mesh/gnunet-service-mesh-new.c
   gnunet/src/mesh/mesh2.h
   gnunet/src/mesh/mesh2_api.c
   gnunet/src/mesh/mesh2_protocol.h
Log:
- Added tunnel port parameter

Modified: gnunet/src/mesh/gnunet-service-mesh-new.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-new.c   2013-05-14 15:50:59 UTC (rev 
27133)
+++ gnunet/src/mesh/gnunet-service-mesh-new.c   2013-05-14 15:55:50 UTC (rev 
27134)
@@ -294,6 +294,11 @@
   struct MESH_TunnelID id;
 
     /**
+     * Port of the tunnel.
+     */
+  uint32_t port;
+
+    /**
      * State of the tunnel.
      */
   enum MeshTunnelState state;
@@ -1196,7 +1201,7 @@
   neighbor = peer_get_short (t->next_hop);
   queue_add (t,
              GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE,
-             sizeof (struct GNUNET_MESH_ManipulatePath) +
+             sizeof (struct GNUNET_MESH_CreateTunnel) +
                 (t->path->length * sizeof (struct GNUNET_PeerIdentity)),
              neighbor,
              t);
@@ -2419,7 +2424,7 @@
 send_core_path_create (void *cls, size_t size, void *buf)
 {
   struct MeshTunnel *t = cls;
-  struct GNUNET_MESH_ManipulatePath *msg;
+  struct GNUNET_MESH_CreateTunnel *msg;
   struct GNUNET_PeerIdentity *peer_ptr;
   struct MeshPeerPath *p = t->path;
   size_t size_needed;
@@ -2428,7 +2433,7 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATE PATH sending...\n");
   size_needed =
-      sizeof (struct GNUNET_MESH_ManipulatePath) +
+      sizeof (struct GNUNET_MESH_CreateTunnel) +
       p->length * sizeof (struct GNUNET_PeerIdentity);
 
   if (size < size_needed || NULL == buf)
@@ -2436,7 +2441,7 @@
     GNUNET_break (0);
     return 0;
   }
-  msg = (struct GNUNET_MESH_ManipulatePath *) buf;
+  msg = (struct GNUNET_MESH_CreateTunnel *) buf;
   msg->header.size = htons (size_needed);
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE);
   msg->tid = ntohl (t->id.tid);
@@ -2444,8 +2449,8 @@
   opt = 0;
   if (GNUNET_YES == t->nobuffer)
     opt |= MESH_TUNNEL_OPT_NOBUFFER;
-  msg->opt = htonl(opt);
-  msg->reserved = 0;
+  msg->opt = htonl (opt);
+  msg->port = htonl (t->port);
 
   peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
   for (i = 0; i < p->length; i++)
@@ -2871,7 +2876,7 @@
   uint16_t size;
   uint16_t i;
   MESH_TunnelNumber tid;
-  struct GNUNET_MESH_ManipulatePath *msg;
+  struct GNUNET_MESH_CreateTunnel *msg;
   struct GNUNET_PeerIdentity *pi;
   struct GNUNET_HashCode hash;
   struct MeshPeerPath *path;
@@ -2883,13 +2888,13 @@
               "Received a path create msg [%s]\n",
               GNUNET_i2s (&my_full_id));
   size = ntohs (message->size);
-  if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
+  if (size < sizeof (struct GNUNET_MESH_CreateTunnel))
   {
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
 
-  size -= sizeof (struct GNUNET_MESH_ManipulatePath);
+  size -= sizeof (struct GNUNET_MESH_CreateTunnel);
   if (size % sizeof (struct GNUNET_PeerIdentity))
   {
     GNUNET_break_op (0);
@@ -2902,7 +2907,7 @@
     return GNUNET_OK;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "    path has %u hops.\n", size);
-  msg = (struct GNUNET_MESH_ManipulatePath *) message;
+  msg = (struct GNUNET_MESH_CreateTunnel *) message;
 
   tid = ntohl (msg->tid);
   pi = (struct GNUNET_PeerIdentity *) &msg[1];
@@ -3023,79 +3028,6 @@
 
 
 /**
- * Core handler for path destruction
- *
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
- */
-static int
-handle_mesh_path_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
-                          const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_MESH_ManipulatePath *msg;
-  struct GNUNET_PeerIdentity *pi;
-  struct MeshTunnel *t;
-  unsigned int own_pos;
-  unsigned int i;
-  size_t size;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Received a PATH DESTROY msg from %s\n", GNUNET_i2s (peer));
-  size = ntohs (message->size);
-  if (size < sizeof (struct GNUNET_MESH_ManipulatePath))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_OK;
-  }
-
-  size -= sizeof (struct GNUNET_MESH_ManipulatePath);
-  if (size % sizeof (struct GNUNET_PeerIdentity))
-  {
-    GNUNET_break_op (0);
-    return GNUNET_OK;
-  }
-  size /= sizeof (struct GNUNET_PeerIdentity);
-  if (size < 2)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_OK;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "    path has %u hops.\n", size);
-
-  msg = (struct GNUNET_MESH_ManipulatePath *) message;
-  pi = (struct GNUNET_PeerIdentity *) &msg[1];
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "    path is for tunnel %s [%X].\n", GNUNET_i2s (pi),
-              msg->tid);
-  t = tunnel_get (pi, ntohl (msg->tid));
-  if (NULL == t)
-  {
-    /* TODO notify back: we don't know this tunnel */
-    GNUNET_break_op (0);
-    return GNUNET_OK;
-  }
-  own_pos = 0;
-  for (i = 0; i < size; i++)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  %u: %s\n", i, GNUNET_i2s (&pi[i]));
-    if (GNUNET_PEER_search (&pi[i]) == myid)
-      own_pos = i;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  Own position: %u\n", own_pos);
-  if (own_pos < size - 1)
-    send_prebuilt_message (message, t->next_hop, t);
-  else
-    send_client_tunnel_destroy (t);
-
-  return GNUNET_OK;
-}
-
-
-/**
  * Core handler for notifications of broken paths
  *
  * @param cls closure
@@ -3650,7 +3582,6 @@
  */
 static struct GNUNET_CORE_MessageHandler core_handlers[] = {
   {&handle_mesh_path_create, GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE, 0},
-  {&handle_mesh_path_destroy, GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY, 0},
   {&handle_mesh_path_broken, GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN,
    sizeof (struct GNUNET_MESH_PathBroken)},
   {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY,
@@ -3994,6 +3925,7 @@
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  t->port = ntohl (t->port);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n",
               GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
 

Modified: gnunet/src/mesh/mesh2.h
===================================================================
--- gnunet/src/mesh/mesh2.h     2013-05-14 15:50:59 UTC (rev 27133)
+++ gnunet/src/mesh/mesh2.h     2013-05-14 15:55:50 UTC (rev 27134)
@@ -113,7 +113,9 @@
      */
   struct GNUNET_MessageHeader header;
   uint16_t types GNUNET_PACKED;
+  uint16_t ports GNUNET_PACKED;
   /* uint16_t                 list_types[types]           */
+  /* uint32_t                 list_ports[ports]           */
 };
 
 
@@ -125,6 +127,7 @@
  */
 typedef uint32_t MESH_TunnelNumber;
 
+
 /**
  * Message for a client to create and destroy tunnels.
  */
@@ -132,7 +135,6 @@
 {
     /**
      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
-     *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[MAX|MIN]
      *
      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
      */
@@ -147,6 +149,11 @@
      * Tunnel's peer
      */
   struct GNUNET_PeerIdentity peer;
+
+    /**
+     * Port of the tunnel.
+     */
+  uint32_t port GNUNET_PACKED;
 };
 
 
@@ -173,9 +180,14 @@
   struct GNUNET_PeerIdentity peer;
 
     /**
+     * Port for this tunnel
+     */
+  uint32_t port GNUNET_PACKED;
+
+    /**
      * Tunnel options (speed, buffering)
      */
-  uint32_t opt;
+  uint32_t opt GNUNET_PACKED;
 };
 
 

Modified: gnunet/src/mesh/mesh2_api.c
===================================================================
--- gnunet/src/mesh/mesh2_api.c 2013-05-14 15:50:59 UTC (rev 27133)
+++ gnunet/src/mesh/mesh2_api.c 2013-05-14 15:55:50 UTC (rev 27134)
@@ -117,6 +117,21 @@
      */
   const struct GNUNET_MESH_MessageHandler *message_handlers;
 
+  /**
+   * Number of handlers in the handlers array.
+   */
+  unsigned int n_handlers;
+
+  /**
+   * Ports open.
+   */
+  uint32_t *ports;
+
+  /**
+   * Number of ports.
+   */
+  unsigned int n_ports;
+
     /**
      * Double linked list of the tunnels this client is connected to, head.
      */
@@ -163,11 +178,6 @@
   MESH_TunnelNumber next_tid;
 
     /**
-     * Number of handlers in the handlers array.
-     */
-  unsigned int n_handlers;
-
-    /**
      * Have we started the task to receive messages from the service
      * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message.
      */
@@ -265,6 +275,11 @@
   MESH_TunnelNumber tid;
 
     /**
+     * Port number.
+     */
+  uint32_t port;
+
+    /**
      * Other end of the tunnel.
      */
   GNUNET_PEER_Id peer;
@@ -633,23 +648,32 @@
     char buf[size] GNUNET_ALIGN;
     struct GNUNET_MESH_ClientConnect *msg;
     uint16_t *types;
-    uint16_t ntypes;
+    uint32_t *ports;
+    uint16_t i;
 
     /* build connection packet */
     msg = (struct GNUNET_MESH_ClientConnect *) buf;
     msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
     msg->header.size = htons (size);
-    types = (uint16_t *) & msg[1];
-    for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
+    msg->types = htons (h->n_handlers);
+    msg->ports = htons (h->n_ports);
+    types = (uint16_t *) &msg[1];
+    for (i = 0; i < h->n_handlers; i++)
     {
-      types[ntypes] = htons (h->message_handlers[ntypes].type);
+      types[i] = htons (h->message_handlers[i].type);
       LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n",
-           h->message_handlers[ntypes].type);
+           h->message_handlers[i].type);
     }
-    msg->types = htons (ntypes);
+    ports = (uint32_t *) &types[h->n_handlers];
+    for (i = 0; i < h->n_ports; i++)
+    {
+      ports[i] = htonl (h->ports[i]);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, " port %u\n",
+           h->ports[i]);
+    }
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "Sending %lu bytes long message %d types\n",
-         ntohs (msg->header.size), ntypes);
+         "Sending %lu bytes long message %u types and %u ports\n",
+         ntohs (msg->header.size), h->n_handlers, h->n_ports);
     send_packet (h, &msg->header, NULL);
   }
 }
@@ -803,12 +827,13 @@
     GNUNET_PEER_change_rc (t->peer, 1);
     t->mesh = h;
     t->tid = tid;
+    t->port = ntohl (msg->port);
     if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0)
       t->buffering = GNUNET_NO;
     else
       t->buffering = GNUNET_YES;
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  created tunnel %p\n", t);
-    t->ctx = h->new_tunnel (h->cls, t, &msg->peer);
+    t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port);
     LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
   }
   else
@@ -1340,7 +1365,8 @@
 GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
                      GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
                      GNUNET_MESH_TunnelEndHandler cleaner,
-                     const struct GNUNET_MESH_MessageHandler *handlers)
+                     const struct GNUNET_MESH_MessageHandler *handlers,
+                     uint32_t *ports)
 {
   struct GNUNET_MESH_Handle *h;
 
@@ -1359,6 +1385,7 @@
   }
   h->cls = cls;
   h->message_handlers = handlers;
+  h->ports = ports;
   h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
   h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
   h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1367,6 +1394,9 @@
   for (h->n_handlers = 0;
        handlers && handlers[h->n_handlers].type;
        h->n_handlers++) ;
+  for (h->n_ports = 0;
+       ports && ports[h->n_ports];
+       h->n_ports++) ;
   send_connect (h);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n");
   return h;
@@ -1455,7 +1485,8 @@
 struct GNUNET_MESH_Tunnel *
 GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 
                            void *tunnel_ctx,
-                           const struct GNUNET_PeerIdentity *peer)
+                           const struct GNUNET_PeerIdentity *peer,
+                           uint32_t port)
 {
   struct GNUNET_MESH_Tunnel *t;
   struct GNUNET_MESH_TunnelMessage msg;
@@ -1468,6 +1499,7 @@
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
   msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
   msg.tunnel_id = htonl (t->tid);
+  msg.port = htonl (port);
   msg.peer = *peer;
   send_packet (h, &msg.header, t);
   return t;

Modified: gnunet/src/mesh/mesh2_protocol.h
===================================================================
--- gnunet/src/mesh/mesh2_protocol.h    2013-05-14 15:50:59 UTC (rev 27133)
+++ gnunet/src/mesh/mesh2_protocol.h    2013-05-14 15:55:50 UTC (rev 27134)
@@ -45,12 +45,12 @@
 GNUNET_NETWORK_STRUCT_BEGIN
 
 /**
- * Message for mesh path management
+ * Message for mesh path creation.
  */
-struct GNUNET_MESH_ManipulatePath
+struct GNUNET_MESH_CreateTunnel
 {
     /**
-     * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_[CREATE|CHANGE|ADD|DESTROY]
+     * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE
      *
      * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
      *       path_length * sizeof (struct GNUNET_PeerIdentity)
@@ -69,18 +69,39 @@
   uint32_t opt GNUNET_PACKED;
 
     /**
-     * 64 bit alignment padding.
+     * Destination port.
      */
-  uint32_t reserved GNUNET_PACKED;
+  uint32_t port GNUNET_PACKED;
 
     /**
+     * FIXME do not add the first hop
      * path_length structs defining the *whole* path from the origin [0] to the
      * final destination [path_length-1].
      */
   /* struct GNUNET_PeerIdentity peers[path_length]; */
 };
 
+/**
+ * Message for mesh path destruction.
+ */
+struct GNUNET_MESH_DestroyTunnel
+{
+  /**
+   * Type: GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY
+   *
+   * Size: sizeof(struct GNUNET_MESH_ManipulatePath) +
+   *       path_length * sizeof (struct GNUNET_PeerIdentity)
+   */
+  struct GNUNET_MessageHeader header;
+  
+  /**
+   * Global id of the tunnel this path belongs to,
+   * unique in conjunction with the origin.
+   */
+  uint32_t tid GNUNET_PACKED;
+};
 
+
 /**
  * Message for mesh data traffic to a particular destination from origin.
  */




reply via email to

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