WiP
authorBart Polot <bart@net.in.tum.de>
Thu, 19 May 2011 13:34:47 +0000 (13:34 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 19 May 2011 13:34:47 +0000 (13:34 +0000)
src/include/gnunet_protocols.h
src/mesh/gnunet-service-mesh.c

index e6099dfd8701864cc2a924b47e0db9af7a55c070..35eb7d0b4a418cac5ce511f0fdd9db588ab2108e 100644 (file)
@@ -791,9 +791,9 @@ extern "C"
 #define GNUNET_MESSAGE_TYPE_MESH_HELLO 216
 
 
-/**
+/*******************************************************************************
  * MESH message types (WiP)
- */
+ ******************************************************************************/
 
 /**
  * Request the creation of a path
@@ -831,21 +831,63 @@ extern "C"
  */
 #define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY  262
 
-/* FIXME: Document */
+/**
+ * Connect to the mesh service, specifying subscriptions
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT                  272
+
+/**
+ * Ask the mesh service to create a new tunnel
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE            273
+
+/**
+ * Ask the mesh service to destroy a tunnel
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY           274
 
+/**
+ * Ask the mesh service to add a peer to an existing tunnel
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD         275
+
+/**
+ * Ask the mesh service to remove a peer from a tunnel
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_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
+
+/**
+ * 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
 
+/* FIXME needed? */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_REQUEST_TRANSMIT_READY   281
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_NOTIFY_TRANSMIT_READY    282
+
+/**
+ * Message client <-> mesh service to transport payload
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA                     283
+
+/**
+ * Message client->mesh to send data to all peers connected to a tunnel
+ */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST           284
 
 /**
@@ -853,9 +895,9 @@ extern "C"
  */
 #define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END   288
 
-/**
+/*******************************************************************************
  * MESH message types END
- */
+ ******************************************************************************/
 
 
 
index 4865ed7e883958300c066c6bfb6177bf5e2b6f73..ca2d652e74b0c1b5bd8653d0fa705678dad46d8e 100644 (file)
@@ -489,6 +489,31 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
 }
 
 
+/**
+ * Send another peer a notification to destroy a tunnel
+ * @param cls The tunnel to destroy
+ * @param size Size in the buffer
+ * @param buf Memory where to put the data to transmit
+ * @return Size of data put in buffer
+ */
+static size_t
+send_p2p_tunnel_destroy(void *cls, size_t size, void *buf)
+{
+    struct MeshTunnel                   *t = cls;
+    struct MeshClient                   *c;
+    struct GNUNET_MESH_TunnelMessage    *msg;
+
+    c = t->client;
+    msg = buf;
+    msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); /*FIXME*/
+    msg->header.size = htons(sizeof(struct GNUNET_MESH_TunnelMessage));
+    msg->tunnel_id = htonl(t->tid);
+
+    destroy_tunnel(c, t);
+    return sizeof(struct GNUNET_MESH_TunnelMessage);
+}
+
+
 /**
  * Core handler for path creation
  * struct GNUNET_CORE_MessageHandler
@@ -636,7 +661,7 @@ dht_get_response_handler(void *cls,
         GNUNET_SERVER_notify_transmit_ready(
             t->client->handle,
             sizeof(struct GNUNET_MESH_PeerControl),
-            GNUNET_TIME_relative_get_forever(),
+            GNUNET_TIME_UNIT_FOREVER_REL,
             &notify_client_connection_failure,
             peer_info
         );
@@ -664,7 +689,7 @@ dht_get_response_handler(void *cls,
     GNUNET_CORE_notify_transmit_ready(core_handle,
                                       0,
                                       0,
-                                      GNUNET_TIME_relative_get_forever(),
+                                      GNUNET_TIME_UNIT_FOREVER_REL,
                                       get_path[1],
                                       sizeof(struct GNUNET_MESH_ManipulatePath)
                                         + (p->length
@@ -885,7 +910,14 @@ handle_local_tunnel_destroy (void *cls,
     GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelID), &hash);
     t = GNUNET_CONTAINER_multihashmap_get(c->tunnel_ids, &hash);
     GNUNET_CONTAINER_multihashmap_remove_all(c->tunnel_ids, &hash);
-    destroy_tunnel(c, t);
+    GNUNET_CORE_notify_transmit_ready(core_handle,
+                                      1,
+                                      1,
+                                      GNUNET_TIME_UNIT_FOREVER_REL,
+                                      NULL,
+                                      sizeof(struct GNUNET_MESH_TunnelMessage),
+                                      &send_p2p_tunnel_destroy,
+                                      t);
 
     GNUNET_SERVER_receive_done(client, GNUNET_OK);
     return;
@@ -961,7 +993,7 @@ handle_local_connect_add (void *cls,
                         sizeof(struct GNUNET_PeerIdentity),
                         &key);
     peer_info->dhtget = GNUNET_DHT_get_start(dht_handle,
-                                            GNUNET_TIME_relative_get_forever(),
+                                            GNUNET_TIME_UNIT_FOREVER_REL,
                                             GNUNET_BLOCK_TYPE_ANY,
                                             &key,
                                             4,    /* replication level */