gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16688 - in gnunet/src: include mesh


From: gnunet
Subject: [GNUnet-SVN] r16688 - in gnunet/src: include mesh
Date: Fri, 2 Sep 2011 14:38:18 +0200

Author: bartpolot
Date: 2011-09-02 14:38:18 +0200 (Fri, 02 Sep 2011)
New Revision: 16688

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api_new.c
Log:
Added tunnel destroy, changed message types in client <-> service protocol

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2011-09-02 11:31:38 UTC (rev 
16687)
+++ gnunet/src/include/gnunet_protocols.h       2011-09-02 12:38:18 UTC (rev 
16688)
@@ -876,7 +876,6 @@
 
 /**
  * Transport data back in the mesh (end->origin)
- * (not sure if this is the right way, should be some other solution)
  */
 #define GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN              262
 
@@ -908,38 +907,22 @@
 /**
  * Ask the mesh service to add a peer to an existing tunnel
  */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD 275
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD         275
 
 /**
  * Ask the mesh service to remove a peer from a tunnel
  */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL 276
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL         276
 
 /**
  * Ask the mesh service to add a peer offering a service to an existing tunnel
  */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE     277
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE 277
 
 /**
- * Ask the mesh service to cancel a peer connection request
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL      278
-
-/**
- * Notify a mesh client that a peer has connected to a tunnel
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED           279
-
-/**
- * Notify a mesh client that a peer has disconnected from a tunnel
- */
-#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED        280
-
-
-/**
  * 640kb should be enough for everybody
  */
-#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END   288
+#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END            288
 
 
 

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-09-02 11:31:38 UTC (rev 
16687)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-09-02 12:38:18 UTC (rev 
16688)
@@ -1682,7 +1682,7 @@
       return GNUNET_OK;
     }
     peer_info->state = MESH_PEER_READY;
-    pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+    pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
     pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
     pc.tunnel_id = htonl (t->local_tid);
     GNUNET_PEER_resolve (peer_info->id, &pc.peer);
@@ -2494,7 +2494,7 @@
                                          get_peer_info (&pc.peer),
                                          
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
       pc.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
-      pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED);
+      pc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
       pc.tunnel_id = htonl (t->local_tid);
       GNUNET_SERVER_notification_context_unicast (nc, client, NULL, GNUNET_NO);
     }
@@ -2679,13 +2679,13 @@
    GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
    sizeof (struct GNUNET_MESH_TunnelMessage)},
   {&handle_local_connect_add, NULL,
-   GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD,
    sizeof (struct GNUNET_MESH_PeerControl)},
   {&handle_local_connect_del, NULL,
-   GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL,
    sizeof (struct GNUNET_MESH_PeerControl)},
   {&handle_local_connect_by_type, NULL,
-   GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE,
    sizeof (struct GNUNET_MESH_ConnectPeerByType)},
   {&handle_local_unicast, NULL,
    GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-09-02 11:31:38 UTC (rev 16687)
+++ gnunet/src/mesh/mesh_api_new.c      2011-09-02 12:38:18 UTC (rev 16688)
@@ -325,10 +325,10 @@
 
 
 /**
- * Get the tunnel handler for the tunnel specified by id from the given handle
+ * Create a new tunnel and insert it in the tunnel list of the mesh handle
  * @param h Mesh handle
- * @param tid ID of the wanted tunnel
- * @return handle to the required tunnel or NULL if not found
+ * @param tid desired tid of the tunnel, 0 to assign one automatically
+ * @return handle to the created tunnel
  */
 static struct GNUNET_MESH_Tunnel *
 create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
@@ -343,6 +343,8 @@
   }
   else
   {
+    /* FIXME keep double numbering?
+     * client numbers from 0x8... anx service from 0xB... ? */
     t->tid = tid;
     h->next_tid = tid + 1;
   }
@@ -353,6 +355,42 @@
 
 
 /**
+ * Get the tunnel handler for the tunnel specified by id from the given handle
+ * @param h Mesh handle
+ * @param tid ID of the wanted tunnel
+ * @return handle to the required tunnel or NULL if not found
+ */
+static void
+destroy_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
+{
+    struct GNUNET_MESH_Tunnel *t;
+    struct GNUNET_PeerIdentity pi;
+    unsigned int i;
+
+    t = retrieve_tunnel(h, tid);
+    if (NULL == t)
+    {
+        GNUNET_break (0);
+        return;
+    }
+    GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
+    for (i = 0; i < t->npeers; i++)
+    {
+        GNUNET_PEER_resolve(t->peers[i]->id, &pi);
+        t->disconnect_handler(t->cls, &pi);
+        GNUNET_PEER_change_rc(t->peers[i]->id, -1);
+        GNUNET_free (t->peers[i]);
+    }
+    h->cleaner(h->cls, t, NULL); /* FIXME ctx? */
+    if (0 != t->owner)
+        GNUNET_PEER_change_rc(t->owner, -1);
+    GNUNET_free(t->peers);
+    GNUNET_free(t);
+    return;
+}
+
+
+/**
  * Get the peer descriptor for the peer with id from the given tunnel
  * @param t Tunnel handle
  * @param id Short form ID of the wanted peer
@@ -524,7 +562,7 @@
       struct GNUNET_MESH_PeerControl msg;
 
       msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
-      msg.header.type = htons 
(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
+      msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
       msg.tunnel_id = htonl (t->tid);
       GNUNET_PEER_resolve (t->peers[i]->id, &msg.peer);
       send_packet (t->mesh, &msg.header);
@@ -562,11 +600,36 @@
   t->cls = h->cls;
   t->mesh = h;
   t->tid = tid;
+  GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
   return;
 }
 
 
 /**
+ * Process the tunnel destroy notification and free associated resources
+ *
+ * @param h     The mesh handle
+ * @param msg   A message with the details of the tunnel being destroyed
+ */
+static void
+process_tunnel_destroy (struct GNUNET_MESH_Handle *h,
+                        const struct GNUNET_MESH_TunnelMessage *msg)
+{
+    struct GNUNET_MESH_Tunnel *t;
+    MESH_TunnelNumber tid;
+
+    tid = ntohl (msg->tunnel_id);
+    t = retrieve_tunnel(h, tid);
+    
+    t->cls = h->cls;
+    t->mesh = h;
+    t->tid = tid;
+    GNUNET_CONTAINER_DLL_insert(h->tunnels_head, h->tunnels_tail, t);
+    return;
+}
+
+
+/**
  * Process the new peer event and notify the upper level of it
  *
  * @param h     The mesh handle
@@ -606,7 +669,7 @@
     p = add_peer_to_tunnel (t, &msg->peer);
   atsi.type = 0;
   atsi.value = 0;
-  if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type)
+  if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == msg->header.type)
   {
     if (NULL != t->connect_handler)
     {
@@ -726,9 +789,13 @@
   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE:
     process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg);
     break;
+    /* Notify of a tunnel disconnection */
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY:
+    process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg);
+    break;
     /* Notify of a new peer or a peer disconnect in the tunnel */
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED:
-  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED:
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD:
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL:
     process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg);
     break;
     /* Notify of a new data packet in the tunnel */
@@ -1084,7 +1151,7 @@
   add_peer_to_tunnel (tunnel, peer);
 
   msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
   msg.tunnel_id = htonl (tunnel->tid);
   msg.peer = *peer;
   send_packet (tunnel->mesh, &msg.header);
@@ -1130,7 +1197,7 @@
   GNUNET_array_grow (tunnel->peers, tunnel->npeers, tunnel->npeers - 1);
 
   msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
-  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL);
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
   msg.tunnel_id = htonl (tunnel->tid);
   memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
   send_packet (tunnel->mesh, &msg.header);
@@ -1155,7 +1222,7 @@
   /* FIXME: add a new api call disconnect by type? */
 
   msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
-  msg.header.type = htons 
(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE);
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
   msg.tunnel_id = htonl (tunnel->tid);
   msg.type = htonl (app_type);
   send_packet (tunnel->mesh, &msg.header);




reply via email to

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