changes to the mesh-api
authorPhilipp Tölke <toelke@in.tum.de>
Mon, 10 Jan 2011 21:41:44 +0000 (21:41 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Mon, 10 Jan 2011 21:41:44 +0000 (21:41 +0000)
src/include/gnunet_mesh_service.h
src/mesh/mesh_api.c

index 8adde254e700480583fe88f3d7476e43b046096a..1ff5e3becf081e2f89630c5f0ae0162d382f9fd9 100644 (file)
@@ -68,7 +68,7 @@ struct GNUNET_MESH_Tunnel;
  */
 typedef int
   (*GNUNET_MESH_MessageCallback) (void *cls,
-                                  const struct GNUNET_MESH_Tunnel *tunnel,
+                                  struct GNUNET_MESH_Tunnel *tunnel,
                                  void **tunnel_ctx,
                                   const struct GNUNET_MessageHeader *message,
                                  const struct GNUNET_TRANSPORT_ATS_Information *atsi);
@@ -133,6 +133,16 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
                      const struct GNUNET_MESH_MessageHandler *handlers);
 
 
+/**
+ * Get the peer on the other side of this tunnel if it is just one. Return NULL otherwise
+ * 
+ * @param tunnel the tunnel
+ * @return the peer or NULL
+ */
+const struct GNUNET_PeerIdentity*
+GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel);
+
+
 /**
  * Disconnect from the mesh service.
  *
index 32996e0db2991797c2fc95f26795f2b45eab735d..f1f9b17ab8086bc7658f6784fd379b41612b731d 100644 (file)
@@ -103,6 +103,25 @@ struct GNUNET_MESH_Handle
   GNUNET_MESH_TunnelEndHandler *cleaner;
 };
 
+static void
+send_end_connect(void* cls,
+                    const struct GNUNET_SCHEDULER_TaskContext* tc)
+{
+  struct GNUNET_MESH_Tunnel* tunnel = cls;
+
+  tunnel->connect_handler(tunnel->handler_cls, NULL, NULL);
+}
+
+static void
+send_self_connect(void* cls,
+                       const struct GNUNET_SCHEDULER_TaskContext* tc)
+{
+  struct GNUNET_MESH_Tunnel* tunnel = cls;
+
+  tunnel->connect_handler(tunnel->handler_cls, &tunnel->handle->myself, NULL);
+  GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
+}
+
 static void
 core_startup (void *cls,
              struct GNUNET_CORE_Handle *core,
@@ -160,6 +179,7 @@ core_connect (void *cls,
                                             tunnel);
          tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
                                          peer, atsi);
+         GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
          tunnel = next;
        }
       else
@@ -349,7 +369,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
                                         handle->established_tunnels.tail,
                                         handle->established_tunnels.tail,
                                         tunnel);
-      connect_handler (handler_cls, &handle->myself, NULL);
+      GNUNET_SCHEDULER_add_now(send_self_connect, tunnel);
     }
   else
     {
@@ -363,6 +383,12 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
   return &tunnel->tunnel;
 }
 
+const struct GNUNET_PeerIdentity*
+GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel)
+{
+  return &tunnel->peer;
+}
+
 static size_t
 core_notify(void* cls, size_t size, void* buf)
 {