2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/mesh_api.c
23 * @brief mesh service; API for the Mesh. This is used to talk to arbitrary peers
24 * as of 2011-01Jan-06 this is a mockup.
25 * @author Philipp Tölke
28 #include <gnunet_constants.h>
29 #include <gnunet_mesh_service.h>
30 #include <gnunet_core_service.h>
31 #include <gnunet_container_lib.h>
32 #include <gnunet_applications.h>
36 uint32_t id GNUNET_PACKED;
37 struct GNUNET_PeerIdentity initiator;
38 struct GNUNET_PeerIdentity target;
41 static uint32_t current_id = 0;
45 struct GNUNET_MessageHeader hdr;
47 /* followed by another GNUNET_MessageHeader */
53 GNUNET_CONNECTION_TransmitReadyNotify notify;
54 struct GNUNET_MESH_Tunnel *tunnel;
57 struct GNUNET_MESH_Tunnel
59 /* The other peer this tunnel leads to; just unicast for the moment! */
60 struct GNUNET_PeerIdentity peer;
64 /* The handlers and cls for outbound tunnels. Are NULL for inbound tunnels. */
65 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
66 GNUNET_MESH_TunnelConnectHandler connect_handler;
69 struct GNUNET_MESH_Handle* handle;
71 /* The application-type requested for this tunnel. Is only needed for pending
74 uint16_t application_type;
76 /* The context of the receive-function. */
80 struct tunnel_list_element
82 struct GNUNET_MESH_Tunnel tunnel;
83 struct tunnel_list_element *next, *prev;
88 struct tunnel_list_element *head, *tail;
91 struct type_list_element
93 GNUNET_MESH_ApplicationType type;
94 struct type_list_element *next, *prev;
97 struct peer_list_element
99 struct GNUNET_PeerIdentity peer;
101 /* list of application-types */
102 struct type_list_element *type_head, *type_tail;
104 struct GNUNET_TRANSPORT_ATS_Information atsi;
105 struct peer_list_element *next, *prev;
110 struct peer_list_element *head, *tail;
113 struct GNUNET_MESH_Handle
115 struct GNUNET_CORE_Handle *core;
116 struct GNUNET_MESH_MessageHandler *handlers;
117 struct GNUNET_PeerIdentity myself;
118 unsigned int connected_to_core;
119 struct peer_list connected_peers;
120 struct tunnel_list established_tunnels;
121 struct tunnel_list pending_tunnels;
122 struct tunnel_list pending_by_type_tunnels;
124 GNUNET_MESH_TunnelEndHandler *cleaner;
125 size_t hello_message_size;
126 uint16_t *hello_message;
130 send_end_connect(void* cls,
131 const struct GNUNET_SCHEDULER_TaskContext* tc)
133 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
136 struct GNUNET_MESH_Tunnel* tunnel = cls;
138 tunnel->connect_handler(tunnel->handler_cls, NULL, NULL);
142 send_self_connect(void* cls,
143 const struct GNUNET_SCHEDULER_TaskContext* tc)
145 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
148 struct GNUNET_MESH_Tunnel* tunnel = cls;
150 tunnel->connect_handler(tunnel->handler_cls, &tunnel->handle->myself, NULL);
151 GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
155 call_connect_handler (void *cls,
156 const struct GNUNET_SCHEDULER_TaskContext *tc)
158 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
161 struct GNUNET_MESH_Tunnel *tunnel = cls;
163 tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer,
165 GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
169 core_startup (void *cls,
170 struct GNUNET_CORE_Handle *core __attribute__((unused)),
171 const struct GNUNET_PeerIdentity *my_identity,
172 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey __attribute__((unused)))
174 struct GNUNET_MESH_Handle *handle = cls;
175 memcpy (&handle->myself, my_identity, sizeof (struct GNUNET_PeerIdentity));
176 handle->connected_to_core = GNUNET_YES;
180 send_hello_message (void *cls, size_t size, void *buf)
182 if (cls == NULL) return 0;
184 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
186 struct GNUNET_MESH_Handle *handle = cls;
187 struct GNUNET_MessageHeader *hdr = buf;
189 size_t sent = sizeof(struct GNUNET_MessageHeader) + handle->hello_message_size;
191 hdr->type = htons(GNUNET_MESSAGE_TYPE_MESH_HELLO);
192 hdr->size = htons(size);
194 memcpy(hdr+1, handle->hello_message, handle->hello_message_size);
200 * Core calls this if we are connected to a new peer.
202 * The peer is added to the connected_peers-list.
206 core_connect (void *cls,
207 const struct GNUNET_PeerIdentity *peer,
208 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
210 struct GNUNET_MESH_Handle *handle = cls;
212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are connected to peer %s\n", GNUNET_i2s(peer));
214 /* Send a hello to this peer */
215 GNUNET_CORE_notify_transmit_ready(handle->core,
218 GNUNET_TIME_UNIT_SECONDS,
220 sizeof(struct GNUNET_MessageHeader) + handle->hello_message_size,
224 /* put the new peer into the list of connected peers */
225 struct peer_list_element *element =
226 GNUNET_malloc (sizeof (struct peer_list_element));
227 memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity));
230 memcpy (&element->atsi, atsi,
231 sizeof (struct GNUNET_TRANSPORT_ATS_Information));
233 GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head,
234 handle->connected_peers.tail,
235 handle->connected_peers.tail, element);
237 struct tunnel_list_element *tunnel = handle->pending_tunnels.head;
238 while (tunnel != NULL)
241 memcmp (&tunnel->tunnel.peer, peer,
242 sizeof (struct GNUNET_PeerIdentity)))
244 struct tunnel_list_element *next = tunnel->next;
245 GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
246 handle->pending_tunnels.tail, tunnel);
247 GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
248 handle->established_tunnels.tail,
249 handle->established_tunnels.tail,
251 tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
253 GNUNET_SCHEDULER_add_now(send_end_connect, tunnel);
257 tunnel = tunnel->next;
262 * Core calls this if we disconnect a peer
264 * Remove this peer from the list of connected peers
265 * Close all tunnels this peer belongs to
268 core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
270 struct GNUNET_MESH_Handle *handle = cls;
272 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are no longer connected to peer %s\n", GNUNET_i2s(peer));
274 struct peer_list_element *element = handle->connected_peers.head;
275 while (element != NULL)
278 memcmp (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)))
280 element = element->next;
284 GNUNET_CONTAINER_DLL_remove (handle->connected_peers.head,
285 handle->connected_peers.tail, element);
286 while (element->type_head != NULL)
288 struct type_list_element* tail = element->type_tail;
289 GNUNET_CONTAINER_DLL_remove(element->type_head, element->type_tail, tail);
292 GNUNET_free (element);
295 struct tunnel_list_element *telement = handle->established_tunnels.head;
296 while (telement != NULL)
299 memcmp (&telement->tunnel.peer, peer,
300 sizeof (struct GNUNET_PeerIdentity)))
302 /* disconnect tunnels */
303 /* outbound tunnels */
304 if (telement->tunnel.connect_handler != NULL && NULL != telement->tunnel.disconnect_handler)
305 telement->tunnel.disconnect_handler (telement->tunnel.handler_cls,
307 /* inbound tunnels */
308 else if (NULL != handle->cleaner)
309 handle->cleaner (handle->cls, &telement->tunnel,
310 &telement->tunnel.ctx);
312 struct tunnel_list_element *next = telement->next;
313 GNUNET_CONTAINER_DLL_remove (handle->established_tunnels.head,
314 handle->established_tunnels.tail,
316 GNUNET_free (telement);
321 telement = telement->next;
327 * Receive a message from core.
328 * This is a hello-message, containing the application-types the other peer can receive
331 receive_hello (void *cls,
332 const struct GNUNET_PeerIdentity *other,
333 const struct GNUNET_MessageHeader *message,
334 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
336 struct GNUNET_MESH_Handle *handle = cls;
337 uint16_t *num = (uint16_t *) (message + 1);
338 uint16_t *ports = num + 1;
341 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "The peer %s tells us he supports %d application-types.\n", GNUNET_i2s(other), *num);
343 struct peer_list_element *element = handle->connected_peers.head;
344 while (element != NULL)
347 memcmp (&element->peer, other, sizeof (struct GNUNET_PeerIdentity)))
349 element = element->next;
352 for (i = 0; i < *num; i++)
354 struct type_list_element* new_type = GNUNET_malloc(sizeof *new_type);
355 new_type->type = (GNUNET_MESH_ApplicationType)ntohs (ports[i]);
356 GNUNET_CONTAINER_DLL_insert(element->type_head, element->type_tail, new_type);
359 struct tunnel_list_element *tunnel = handle->pending_by_type_tunnels.head;
360 while (tunnel != NULL)
362 struct tunnel_list_element *next = tunnel->next;
363 for (i = 0; i < *num; i++)
365 if (ntohs (ports[i]) == tunnel->tunnel.application_type)
367 GNUNET_CONTAINER_DLL_remove (handle->pending_tunnels.head,
368 handle->pending_tunnels.tail,
370 GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.
372 handle->established_tunnels.
374 handle->established_tunnels.
376 tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
377 &tunnel->tunnel.peer, atsi);
378 GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
382 if (ntohs (ports[i]) == tunnel->tunnel.application_type)
385 tunnel = tunnel->next;
391 * Receive a message from core.
394 core_receive (void *cls,
395 const struct GNUNET_PeerIdentity *other,
396 const struct GNUNET_MessageHeader *message,
397 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
399 struct GNUNET_MESH_Handle *handle = cls;
400 struct tunnel_message *tmessage = (struct tunnel_message *) message;
401 struct GNUNET_MessageHeader *rmessage =
402 (struct GNUNET_MessageHeader *) (tmessage + 1);
404 struct GNUNET_MESH_MessageHandler *handler;
406 for (handler = handle->handlers; handler->callback != NULL; handler++)
408 if ( (ntohs (rmessage->type) == handler->type)
409 && ( (handler->expected_size == 0)
410 || (handler->expected_size == ntohs (rmessage->size))) )
416 /* handler->callback handles this message */
418 /* If no handler was found, drop the message but keep the channel open */
419 if (handler->callback == NULL)
421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer %s; dropping it.\n",
422 ntohs(rmessage->type), GNUNET_i2s(other));
426 struct tunnel_list_element *tunnel = handle->established_tunnels.head;
428 while (tunnel != NULL)
430 if (tunnel->tunnel.id.id == tmessage->id.id &&
432 memcmp (&tmessage->id.initiator, &tunnel->tunnel.id.initiator,
433 sizeof (struct GNUNET_PeerIdentity)))
435 memcmp (&tmessage->id.target, &tunnel->tunnel.id.target,
436 sizeof (struct GNUNET_PeerIdentity))))
438 tunnel = tunnel->next;
441 /* if no tunnel was found: create a new inbound tunnel */
444 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New inbound tunnel from peer %s; first message has type %d.\n",
445 GNUNET_i2s(other), ntohs(rmessage->type));
446 tunnel = GNUNET_malloc (sizeof (struct tunnel_list_element));
447 tunnel->tunnel.connect_handler = NULL;
448 tunnel->tunnel.disconnect_handler = NULL;
449 tunnel->tunnel.handler_cls = NULL;
450 tunnel->tunnel.ctx = NULL;
451 tunnel->tunnel.handle = handle;
452 memcpy (&tunnel->tunnel.peer, other,
453 sizeof (struct GNUNET_PeerIdentity));
454 memcpy (&tunnel->tunnel.id, &tmessage->id, sizeof (struct tunnel_id));
456 GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
457 handle->established_tunnels.tail,
458 handle->established_tunnels.tail,
462 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Inbound message from peer %s; type %d.\n",
463 GNUNET_i2s(other), ntohs(rmessage->type));
465 return handler->callback (handle->cls, &tunnel->tunnel,
466 &tunnel->tunnel.ctx, other, rmessage, atsi);
469 struct GNUNET_MESH_Tunnel *
470 GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Handle *handle,
471 struct GNUNET_TIME_Relative timeout,
472 GNUNET_MESH_ApplicationType application_type,
473 GNUNET_MESH_TunnelConnectHandler
475 GNUNET_MESH_TunnelDisconnectHandler
479 /* Look in the list of connected peers */
480 struct peer_list_element *element = handle->connected_peers.head;
481 while (element != NULL)
483 struct type_list_element* i;
484 for (i = element->type_head; i != NULL; i = i->next)
485 if (application_type == i->type)
486 return GNUNET_MESH_peer_request_connect_all (handle, timeout, 1,
491 element = element->next;
494 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n", application_type);
496 /* Put into pending list */
497 struct tunnel_list_element *tunnel =
498 GNUNET_malloc (sizeof (struct tunnel_list_element));
500 tunnel->tunnel.connect_handler = connect_handler;
501 tunnel->tunnel.disconnect_handler = disconnect_handler;
502 tunnel->tunnel.handler_cls = handler_cls;
503 tunnel->tunnel.ctx = NULL;
504 tunnel->tunnel.handle = handle;
505 memcpy (&tunnel->tunnel.id.initiator, &handle->myself,
506 sizeof (struct GNUNET_PeerIdentity));
507 tunnel->tunnel.id.id = current_id++;
508 tunnel->tunnel.application_type = application_type;
510 GNUNET_CONTAINER_DLL_insert_after (handle->pending_by_type_tunnels.head,
511 handle->pending_by_type_tunnels.tail,
512 handle->pending_by_type_tunnels.tail,
514 return &tunnel->tunnel;
519 struct GNUNET_MESH_Tunnel *
520 GNUNET_MESH_peer_request_connect_all (struct GNUNET_MESH_Handle *handle,
521 struct GNUNET_TIME_Relative timeout,
522 unsigned int num_peers,
523 const struct GNUNET_PeerIdentity *peers,
524 GNUNET_MESH_TunnelConnectHandler
526 GNUNET_MESH_TunnelDisconnectHandler
527 disconnect_handler, void *handler_cls)
532 struct tunnel_list_element *tunnel =
533 GNUNET_malloc (sizeof (struct tunnel_list_element));
535 tunnel->tunnel.connect_handler = connect_handler;
536 tunnel->tunnel.disconnect_handler = disconnect_handler;
537 tunnel->tunnel.handler_cls = handler_cls;
538 tunnel->tunnel.ctx = NULL;
539 tunnel->tunnel.handle = handle;
540 memcpy (&tunnel->tunnel.id.initiator, &handle->myself,
541 sizeof (struct GNUNET_PeerIdentity));
542 memcpy (&tunnel->tunnel.id.target, peers,
543 sizeof (struct GNUNET_PeerIdentity));
544 tunnel->tunnel.id.id = current_id++;
545 memcpy (&tunnel->tunnel.peer, peers, sizeof(struct GNUNET_PeerIdentity));
547 struct peer_list_element *element = handle->connected_peers.head;
548 while (element != NULL)
551 memcmp (&element->peer, peers, sizeof (struct GNUNET_PeerIdentity)))
553 element = element->next;
558 /* we are connected to this peer */
559 GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
560 handle->established_tunnels.tail,
561 handle->established_tunnels.tail,
563 GNUNET_SCHEDULER_add_now(call_connect_handler, tunnel);
566 memcmp (peers, &handle->myself,
567 sizeof (struct GNUNET_PeerIdentity)))
569 /* we are the peer */
570 GNUNET_CONTAINER_DLL_insert_after (handle->established_tunnels.head,
571 handle->established_tunnels.tail,
572 handle->established_tunnels.tail,
574 GNUNET_SCHEDULER_add_now(send_self_connect, tunnel);
578 /* we are not connected to this peer */
579 GNUNET_CONTAINER_DLL_insert_after (handle->pending_tunnels.head,
580 handle->pending_tunnels.tail,
581 handle->pending_tunnels.tail,
583 (void) GNUNET_CORE_peer_request_connect (handle->core,
588 return &tunnel->tunnel;
591 const struct GNUNET_PeerIdentity*
592 GNUNET_MESH_get_peer(const struct GNUNET_MESH_Tunnel* tunnel)
594 return &tunnel->peer;
598 core_notify(void* cls, size_t size, void* buf)
600 struct notify_cls *ncls = cls;
601 struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel;
602 struct tunnel_message* message = buf;
603 void* cbuf = (void*) &message[1];
604 GNUNET_assert(NULL != ncls->notify);
606 size_t sent = ncls->notify(ncls->notify_cls, size - sizeof(struct tunnel_message), cbuf);
610 if (0 == sent) return 0;
612 sent += sizeof(struct tunnel_message);
614 message->hdr.type = htons(GNUNET_MESSAGE_TYPE_MESH);
615 message->hdr.size = htons(sent);
616 memcpy(&message->id, &tunnel->id, sizeof(struct tunnel_id));
622 * Ask the mesh to call "notify" once it is ready to transmit the
623 * given number of bytes to the specified "target". If we are not yet
624 * connected to the specified peer, a call to this function will cause
625 * us to try to establish a connection.
627 * @param tunnel tunnel to use for transmission
628 * @param cork is corking allowed for this transmission?
629 * @param priority how important is the message?
630 * @param maxdelay how long can the message wait?
631 * @param target destination for the message, NULL for multicast to all tunnel targets
632 * @param notify_size how many bytes of buffer space does notify want?
633 * @param notify function to call when buffer space is available;
634 * will be called with NULL on timeout or if the overall queue
635 * for this peer is larger than queue_size and this is currently
636 * the message with the lowest priority
637 * @param notify_cls closure for notify
638 * @return non-NULL if the notify callback was queued,
639 * NULL if we can not even queue the request (insufficient
640 * memory); if NULL is returned, "notify" will NOT be called.
642 struct GNUNET_MESH_TransmitHandle *
643 GNUNET_MESH_notify_transmit_ready (struct
651 const struct GNUNET_PeerIdentity *target __attribute__((unused)),
654 GNUNET_CONNECTION_TransmitReadyNotify
655 notify, void *notify_cls)
657 struct notify_cls *cls = GNUNET_malloc(sizeof(struct notify_cls));
658 cls->notify_cls = notify_cls;
659 GNUNET_assert(NULL != notify);
660 cls->notify = notify;
661 cls->tunnel = tunnel;
662 GNUNET_CORE_notify_transmit_ready(tunnel->handle->core,
667 notify_size + sizeof(struct tunnel_message),
671 /* aborting is not implemented yet */
672 return (struct GNUNET_MESH_TransmitHandle*) 1;
675 void build_hello_message(struct GNUNET_MESH_Handle* handle,
676 const GNUNET_MESH_ApplicationType *stypes)
679 const GNUNET_MESH_ApplicationType *t;
681 for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++);
683 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
685 handle->hello_message_size = sizeof(uint16_t) + /* For the number of types */
686 num * sizeof(GNUNET_MESH_ApplicationType); /* For the types */
688 uint16_t *nums = GNUNET_malloc(handle->hello_message_size);
689 GNUNET_MESH_ApplicationType *types = (GNUNET_MESH_ApplicationType*)(nums + 1);
694 for (i = 0; i < num; i++)
696 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n", stypes[i]);
697 types[i] = htons(stypes[i]);
700 handle->hello_message = nums;
704 struct GNUNET_MESH_Handle *
705 GNUNET_MESH_connect (const struct
706 GNUNET_CONFIGURATION_Handle
708 GNUNET_MESH_TunnelEndHandler
710 const struct GNUNET_MESH_MessageHandler *handlers,
711 const GNUNET_MESH_ApplicationType *stypes)
713 struct GNUNET_MESH_Handle *ret =
714 GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
716 ret->connected_to_core = GNUNET_NO;
717 ret->connected_peers.head = NULL;
718 ret->connected_peers.tail = NULL;
719 ret->cleaner = cleaner;
722 const struct GNUNET_MESH_MessageHandler *it;
723 unsigned int len = 1;
724 for (it = handlers; it->callback != NULL; it++)
730 GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler));
731 memset(ret->handlers, 0, len * sizeof(struct GNUNET_MESH_MessageHandler));
732 memcpy (ret->handlers, handlers,
733 len * sizeof (struct GNUNET_MESH_MessageHandler));
735 build_hello_message(ret, stypes);
737 static const struct GNUNET_CORE_MessageHandler core_handlers[] = {
738 {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},
739 {&receive_hello, GNUNET_MESSAGE_TYPE_MESH_HELLO, 0},
743 ret->core = GNUNET_CORE_connect (cfg,
751 GNUNET_NO, NULL, GNUNET_NO, core_handlers);
756 GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
758 GNUNET_free (handle->handlers);
759 GNUNET_free (handle->hello_message);
760 GNUNET_CORE_disconnect (handle->core);
762 struct peer_list_element *element = handle->connected_peers.head;
763 while (element != NULL)
765 struct peer_list_element *next = element->next;
766 while (element->type_head != NULL)
768 struct type_list_element* tail = element->type_tail;
769 GNUNET_CONTAINER_DLL_remove(element->type_head, element->type_tail, tail);
772 GNUNET_free (element);
776 struct tunnel_list_element *tunnel = handle->pending_tunnels.head;
777 while (tunnel != NULL)
779 struct tunnel_list_element *next = tunnel->next;
780 GNUNET_free (tunnel);
783 tunnel = handle->established_tunnels.head;;
784 while (tunnel != NULL)
786 struct tunnel_list_element *next = tunnel->next;
787 GNUNET_free (tunnel);
791 GNUNET_free (handle);
794 /* end of mesh_api.c */