From 98760f1bfe7a96e87f762c6948825f12ab9bb736 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Wed, 27 Jul 2011 07:28:16 +0000 Subject: [PATCH] do not allow more than one notify_transmit_ready per tunnel --- src/mesh/mesh_api.c | 65 ++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 57bea77e1..fc22cbeb4 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -73,6 +73,8 @@ struct GNUNET_MESH_Tunnel */ uint16_t application_type; + struct GNUNET_MESH_TransmitHandle* notify_handle; + /* The context of the receive-function. */ void *ctx; }; @@ -611,6 +613,7 @@ core_notify(void* cls, size_t size, void* buf) { struct notify_cls *ncls = cls; struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel; + tunnel->notify_handle = NULL; struct tunnel_message* message = buf; void* cbuf = (void*) &message[1]; GNUNET_assert(NULL != ncls->notify); @@ -653,35 +656,47 @@ core_notify(void* cls, size_t size, void* buf) */ struct GNUNET_MESH_TransmitHandle * GNUNET_MESH_notify_transmit_ready (struct - GNUNET_MESH_Tunnel - *tunnel, - int cork, - uint32_t priority, - struct - GNUNET_TIME_Relative - maxdelay, - const struct GNUNET_PeerIdentity *target __attribute__((unused)), - size_t - notify_size, - GNUNET_CONNECTION_TransmitReadyNotify - notify, void *notify_cls) + GNUNET_MESH_Tunnel + *tunnel, + int cork, + uint32_t priority, + struct + GNUNET_TIME_Relative + maxdelay, + const struct GNUNET_PeerIdentity *target + __attribute__ ((unused)), + size_t notify_size, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls) { - struct notify_cls *cls = GNUNET_malloc(sizeof(struct notify_cls)); + if (NULL != tunnel->notify_handle) + { + GNUNET_break(0); + return NULL; + } + + struct notify_cls *cls = GNUNET_malloc (sizeof (struct notify_cls)); cls->notify_cls = notify_cls; - GNUNET_assert(NULL != notify); + GNUNET_assert (NULL != notify); cls->notify = notify; cls->tunnel = tunnel; - GNUNET_CORE_notify_transmit_ready(tunnel->handle->core, - cork, - priority, - maxdelay, - &tunnel->peer, - notify_size + sizeof(struct tunnel_message), - &core_notify, - (void*)cls); - - /* aborting is not implemented yet */ - return (struct GNUNET_MESH_TransmitHandle*) 1; + + tunnel->notify_handle = (struct GNUNET_MESH_TransmitHandle *) + GNUNET_CORE_notify_transmit_ready (tunnel->handle->core, cork, priority, + maxdelay, &tunnel->peer, + notify_size + + sizeof (struct tunnel_message), + &core_notify, (void *) cls); + + return tunnel->notify_handle; +} + +void +GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle + *th) +{ + GNUNET_CORE_notify_transmit_ready_cancel ((struct GNUNET_CORE_TransmitHandle + *) th); } void build_hello_message(struct GNUNET_MESH_Handle* handle, -- 2.25.1