From 02530f44ebadfe7c7758cdbad94d7fcddf28827f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Mon, 10 Jan 2011 21:41:44 +0000 Subject: [PATCH] changes to the mesh-api --- src/include/gnunet_mesh_service.h | 12 +++++++++++- src/mesh/mesh_api.c | 28 +++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 8adde254e..1ff5e3bec 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -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. * diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 32996e0db..f1f9b17ab 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -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) { -- 2.25.1