From: Philipp Tölke Date: Wed, 12 Jan 2011 14:02:33 +0000 (+0000) Subject: fix usage of mesh_api X-Git-Tag: initial-import-from-subversion-38251~19334 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3bb064f4d3259505efabf867750c03aa30370fb0;hp=14839ad22bf671382d464c493d82e6ee0c629c07;p=oweals%2Fgnunet.git fix usage of mesh_api assert invariant in core_api fix mesh_api --- diff --git a/src/core/core_api.c b/src/core/core_api.c index 9001b21d9..c355b626e 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -1518,6 +1518,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, GNUNET_SERVER_MAX_MESSAGE_SIZE); th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle)); th->peer = pr; + GNUNET_assert(NULL != notify); th->get_message = notify; th->get_message_cls = notify_cls; th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index c424dfd99..82fb75c51 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -46,6 +46,13 @@ struct tunnel_message /* followed by another GNUNET_MessageHeader */ }; +struct notify_cls +{ + void* notify_cls; + GNUNET_CONNECTION_TransmitReadyNotify notify; + struct GNUNET_MESH_Tunnel *tunnel; +}; + struct GNUNET_MESH_Tunnel { /* The other peer this tunnel leads to; just unicast for the moment! */ @@ -53,9 +60,6 @@ struct GNUNET_MESH_Tunnel struct tunnel_id id; - void* notify_cls; - GNUNET_CONNECTION_TransmitReadyNotify notify; - /* The handlers and cls for outbound tunnels. Are NULL for inbound tunnels. */ GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; GNUNET_MESH_TunnelConnectHandler connect_handler; @@ -260,7 +264,7 @@ core_receive (void *cls, struct GNUNET_MESH_MessageHandler *handler; - for (handler = handle->handlers; handler != NULL; handler++) + for (handler = handle->handlers; handler->callback != NULL; handler++) { if ( (ntohs (rmessage->type) == handler->type) && ( (handler->expected_size == 0) @@ -273,7 +277,7 @@ core_receive (void *cls, /* handler->callback handles this message */ /* If no handler was found, drop the message but keep the channel open */ - if (handler == NULL) + if (handler->callback == NULL) return GNUNET_OK; struct tunnel_list_element *tunnel = handle->established_tunnels.head; @@ -341,6 +345,7 @@ GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle, memcpy (&tunnel->tunnel.id.target, peers, sizeof (struct GNUNET_PeerIdentity)); tunnel->tunnel.id.id = current_id++; + memcpy (&tunnel->tunnel.peer, peers, sizeof(struct GNUNET_PeerIdentity)); struct peer_list_element *element = handle->connected_peers.head; while (element != NULL) @@ -396,14 +401,17 @@ GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel) static size_t core_notify(void* cls, size_t size, void* buf) { - struct GNUNET_MESH_Tunnel *tunnel = cls; + struct notify_cls *ncls = cls; + struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel; struct tunnel_message* message = buf; void* cbuf = (void*) &message[1]; + GNUNET_assert(NULL != ncls->notify); + + size_t sent = ncls->notify(ncls->notify_cls, size - sizeof(struct tunnel_message), cbuf); - size_t sent = tunnel->notify(tunnel->notify_cls, size - sizeof(struct tunnel_message), cbuf); + GNUNET_free(ncls); - tunnel->notify = NULL; - tunnel->notify_cls = NULL; + if (0 == sent) return 0; sent += sizeof(struct tunnel_message); @@ -427,15 +435,18 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls) { - tunnel->notify_cls = notify_cls; - tunnel->notify = notify; + struct notify_cls *cls = GNUNET_malloc(sizeof(struct notify_cls)); + cls->notify_cls = notify_cls; + GNUNET_assert(NULL != notify); + cls->notify = notify; + cls->tunnel = tunnel; GNUNET_CORE_notify_transmit_ready(tunnel->handle->core, priority, maxdelay, &tunnel->peer, notify_size + sizeof(struct tunnel_message), &core_notify, - (void*)tunnel); + (void*)cls); /* aborting is not implemented yet */ return (struct GNUNET_MESH_TransmitHandle*) 1; @@ -468,6 +479,7 @@ GNUNET_MESH_connect (const struct ret->handlers = GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler)); + memset(ret->handlers, 0, len * sizeof(struct GNUNET_MESH_MessageHandler)); memcpy (ret->handlers, handlers, len * sizeof (struct GNUNET_MESH_MessageHandler)); diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c index 880a53b81..468658c48 100644 --- a/src/vpn/gnunet-daemon-vpn-helper.c +++ b/src/vpn/gnunet-daemon-vpn-helper.c @@ -263,8 +263,10 @@ message_token(void *cls, me->tunnel = *cls; } else - *cls = me->tunnel; - //FIXME: somehow call send_udp_to_peer + { + *cls = me->tunnel; + send_udp_to_peer(cls, (struct GNUNET_PeerIdentity*)1, NULL); + } GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Queued to send to peer %x\n", *((unsigned int*)&me->desc.peer)); } } diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 604bb6e1a..be62724ee 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -173,9 +173,9 @@ send_icmp_response(void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { static size_t send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) { - struct GNUNET_PeerIdentity *peer = cls; + struct GNUNET_MESH_Tunnel **tunnel = cls; struct GNUNET_MessageHeader *hdr = - (struct GNUNET_MessageHeader *) (peer + 1); + (struct GNUNET_MessageHeader *) (tunnel + 1); GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1); struct udp_pkt *udp = (struct udp_pkt *) (hc + 1); hdr->size = htons (sizeof (struct GNUNET_MessageHeader) + @@ -202,6 +202,7 @@ send_udp_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) { + if (peer == NULL) return; struct GNUNET_MESH_Tunnel **tunnel = cls; struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader *) (tunnel + 1);