aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/Makefile.am2
-rw-r--r--src/mesh/gnunet-service-mesh.c8
-rw-r--r--src/mesh/mesh.h3
-rw-r--r--src/mesh/mesh_api.c2
-rw-r--r--src/mesh/mesh_api_new.c144
-rw-r--r--src/mesh/test_mesh_api.c4
-rw-r--r--src/mesh/test_mesh_small.c7
7 files changed, 115 insertions, 55 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index 1131c07c6..cea6152e2 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -69,7 +69,7 @@ test_mesh_small_DEPENDENCIES = \
69 libgnunetmeshnew.la 69 libgnunetmeshnew.la
70 70
71if ENABLE_TEST_RUN 71if ENABLE_TEST_RUN
72TESTS = test_mesh_small 72TESTS = test_mesh_api
73endif 73endif
74 74
75EXTRA_DIST = \ 75EXTRA_DIST = \
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index c396303a8..f5e8aa8e8 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -286,7 +286,7 @@ struct MESH_TunnelID
286 286
287 /** 287 /**
288 * Tunnel number to differentiate all the tunnels owned by the node oid 288 * Tunnel number to differentiate all the tunnels owned by the node oid
289 * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_MARK ) 289 * ( tid < GNUNET_MESH_LOCAL_TUNNEL_ID_CLI )
290 */ 290 */
291 MESH_TunnelNumber tid; 291 MESH_TunnelNumber tid;
292}; 292};
@@ -309,7 +309,7 @@ struct MeshTunnel
309 struct MESH_TunnelID id; 309 struct MESH_TunnelID id;
310 310
311 /** 311 /**
312 * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK or 0 ) 312 * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI or 0 )
313 */ 313 */
314 MESH_TunnelNumber local_tid; 314 MESH_TunnelNumber local_tid;
315 315
@@ -2187,7 +2187,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2187 2187
2188 t_msg = (struct GNUNET_MESH_TunnelMessage *) message; 2188 t_msg = (struct GNUNET_MESH_TunnelMessage *) message;
2189 /* Sanity check for tunnel numbering */ 2189 /* Sanity check for tunnel numbering */
2190 if (0 == (ntohl (t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_MARK)) 2190 if (0 == (ntohl (t_msg->tunnel_id) & GNUNET_MESH_LOCAL_TUNNEL_ID_CLI))
2191 { 2191 {
2192 GNUNET_break (0); 2192 GNUNET_break (0);
2193 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2193 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -2203,7 +2203,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2203 2203
2204 t = GNUNET_malloc (sizeof (struct MeshTunnel)); 2204 t = GNUNET_malloc (sizeof (struct MeshTunnel));
2205 while (NULL != retrieve_tunnel_by_pi (myid, next_tid)) 2205 while (NULL != retrieve_tunnel_by_pi (myid, next_tid))
2206 next_tid = (next_tid + 1) % GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; 2206 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
2207 t->id.tid = next_tid++; 2207 t->id.tid = next_tid++;
2208 t->id.oid = myid; 2208 t->id.oid = myid;
2209 t->local_tid = ntohl (t_msg->tunnel_id); 2209 t->local_tid = ntohl (t_msg->tunnel_id);
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index 874e29a91..41fc13110 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -67,7 +67,8 @@
67/************************** CONSTANTS ******************************/ 67/************************** CONSTANTS ******************************/
68/******************************************************************************/ 68/******************************************************************************/
69 69
70#define GNUNET_MESH_LOCAL_TUNNEL_ID_MARK 0x80000000 70#define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
71#define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
71 72
72 73
73/******************************************************************************/ 74/******************************************************************************/
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 8476be396..615593621 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -921,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
921 GNUNET_free (handle); 921 GNUNET_free (handle);
922} 922}
923 923
924/* end of mesh_api.c */ 924/* end of mesh_api.c */ \ No newline at end of file
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index a2e05e822..fa2bd6682 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011 Christian Grothoff (and other contributing authors)
@@ -159,7 +158,12 @@ struct GNUNET_MESH_Handle
159 struct GNUNET_MESH_Tunnel *tunnels_tail; 158 struct GNUNET_MESH_Tunnel *tunnels_tail;
160 159
161 /** 160 /**
162 * Callback for tunnel disconnection 161 * Callback for inbound tunnel creation
162 */
163 GNUNET_MESH_InboundTunnelNotificationHandler *new_tunnel;
164
165 /**
166 * Callback for inbound tunnel disconnection
163 */ 167 */
164 GNUNET_MESH_TunnelEndHandler *cleaner; 168 GNUNET_MESH_TunnelEndHandler *cleaner;
165 169
@@ -246,16 +250,11 @@ struct GNUNET_MESH_Tunnel
246 GNUNET_MESH_TunnelConnectHandler connect_handler; 250 GNUNET_MESH_TunnelConnectHandler connect_handler;
247 251
248 /** 252 /**
249 * Callback to execute when peers disconnect to the tunnel 253 * Callback to execute when peers disconnect from the tunnel
250 */ 254 */
251 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler; 255 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
252 256
253 /** 257 /**
254 * All peers added to the tunnel
255 */
256 struct GNUNET_MESH_Peer **peers;
257
258 /**
259 * Closure for the connect/disconnect handlers 258 * Closure for the connect/disconnect handlers
260 */ 259 */
261 void *cls; 260 void *cls;
@@ -275,12 +274,22 @@ struct GNUNET_MESH_Tunnel
275 */ 274 */
276 GNUNET_PEER_Id owner; 275 GNUNET_PEER_Id owner;
277 276
277 /**
278 * All peers added to the tunnel
279 */
280 struct GNUNET_MESH_Peer **peers;
281
278 /** 282 /**
279 * List of application types that have been requested for this tunnel 283 * List of application types that have been requested for this tunnel
280 */ 284 */
281 GNUNET_MESH_ApplicationType *apps; 285 GNUNET_MESH_ApplicationType *apps;
282 286
283 /** 287 /**
288 * Any data the caller wants to put in here
289 */
290 void *ctx;
291
292 /**
284 * Number of peers added to the tunnel 293 * Number of peers added to the tunnel
285 */ 294 */
286 unsigned int npeers; 295 unsigned int npeers;
@@ -336,20 +345,22 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
336 struct GNUNET_MESH_Tunnel *t; 345 struct GNUNET_MESH_Tunnel *t;
337 346
338 t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); 347 t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel));
348 GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t);
339 t->mesh = h; 349 t->mesh = h;
340 if (0 == tid) 350 if (0 == tid)
341 { 351 {
342 t->tid = h->next_tid++; 352 t->tid = h->next_tid;
353 while (NULL != retrieve_tunnel (h, h->next_tid))
354 {
355 h->next_tid++;
356 h->next_tid &= ~GNUNET_MESH_LOCAL_TUNNEL_ID_SERV;
357 h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
358 }
343 } 359 }
344 else 360 else
345 { 361 {
346 /* FIXME keep double numbering?
347 * client numbers from 0x8... anx service from 0xB... ? */
348 t->tid = tid; 362 t->tid = tid;
349 h->next_tid = tid + 1;
350 } 363 }
351 h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range
352 GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t);
353 return t; 364 return t;
354} 365}
355 366
@@ -373,6 +384,29 @@ destroy_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
373 GNUNET_break (0); 384 GNUNET_break (0);
374 return; 385 return;
375 } 386 }
387 /* TODO remove data packets from queue */
388 GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
389 for (i = 0; i < t->npeers; i++)
390 {
391 if (NULL != t->disconnect_handler && t->peers[i]->connected)
392 {
393 GNUNET_PEER_resolve (t->peers[i]->id, &pi);
394 t->disconnect_handler (t->cls, &pi);
395 }
396 GNUNET_PEER_change_rc (t->peers[i]->id, -1);
397 GNUNET_free (t->peers[i]);
398 }
399 if (NULL != h->cleaner && 0 != t->owner)
400 h->cleaner (h->cls, t, t->ctx);
401 if (0 != t->owner)
402 GNUNET_PEER_change_rc (t->owner, -1);
403 if (0 != t->napps && t->apps)
404 GNUNET_free (t->apps);
405 if (t->npeers > 0)
406 GNUNET_free (t->peers);
407 GNUNET_free (t);
408 return;
409 }
376 GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); 410 GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
377 for (i = 0; i < t->npeers; i++) 411 for (i = 0; i < t->npeers; i++)
378 { 412 {
@@ -518,7 +552,6 @@ send_packet (struct GNUNET_MESH_Handle *h,
518/** 552/**
519 * Reconnect to the service, retransmit all infomation to try to restore the 553 * Reconnect to the service, retransmit all infomation to try to restore the
520 * original state. 554 * original state.
521 * FIXME: notify user about it? (call all disconnect callbacks?)
522 * 555 *
523 * @param h handle to the mesh 556 * @param h handle to the mesh
524 * 557 *
@@ -549,25 +582,42 @@ reconnect (struct GNUNET_MESH_Handle *h)
549 GNUNET_break (0); 582 GNUNET_break (0);
550 return GNUNET_NO; 583 return GNUNET_NO;
551 } 584 }
585 /* Rebuild all tunnels */
552 for (t = h->tunnels_head; NULL != t; t = t->next) 586 for (t = h->tunnels_head; NULL != t; t = t->next)
553 { 587 {
554 struct GNUNET_MESH_TunnelMessage msg; 588 struct GNUNET_MESH_TunnelMessage tmsg;
589 struct GNUNET_MESH_PeerControl pmsg;
555 590
556 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 591 tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
557 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 592 tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
558 msg.tunnel_id = htonl (t->tid); 593 tmsg.tunnel_id = htonl (t->tid);
559 send_packet (h, &msg.header); 594 send_packet (h, &tmsg.header);
595
596 pmsg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
597 pmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD);
598 pmsg.tunnel_id = htonl (t->tid);
599
600 /* Reconnect all peers */
560 for (i = 0; i < t->npeers; i++) 601 for (i = 0; i < t->npeers; i++)
561 { 602 {
562 struct GNUNET_MESH_PeerControl msg; 603 GNUNET_PEER_resolve (t->peers[i]->id, &pmsg.peer);
604 if (NULL != t->disconnect_handler && t->peers[i]->connected)
605 t->disconnect_handler (t->cls, &pmsg.peer);
606 /* If the tunnel was "by type", dont connect individual peers */
607 if (0 == t->napps)
608 send_packet (t->mesh, &pmsg.header);
609 }
610 /* Reconnect all types, if any */
611 for (i = 0; i < t->napps; i++)
612 {
613 struct GNUNET_MESH_ConnectPeerByType msg;
563 614
564 msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); 615 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
565 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); 616 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
566 msg.tunnel_id = htonl (t->tid); 617 msg.tunnel_id = htonl (t->tid);
567 GNUNET_PEER_resolve (t->peers[i]->id, &msg.peer); 618 msg.type = htonl (t->apps[i]);
568 send_packet (t->mesh, &msg.header); 619 send_packet (t->mesh, &msg.header);
569 } 620 }
570 /* FIXME what about connects by type? */
571 } 621 }
572 return GNUNET_YES; 622 return GNUNET_YES;
573} 623}
@@ -591,13 +641,12 @@ process_tunnel_create (struct GNUNET_MESH_Handle *h,
591 MESH_TunnelNumber tid; 641 MESH_TunnelNumber tid;
592 642
593 tid = ntohl (msg->tunnel_id); 643 tid = ntohl (msg->tunnel_id);
594 if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) 644 if (tid <= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)
595 { 645 {
596 GNUNET_break (0); 646 GNUNET_break (0);
597 return; 647 return;
598 } 648 }
599 t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); 649 t = create_tunnel (h, tid);
600 t->cls = h->cls;
601 t->mesh = h; 650 t->mesh = h;
602 t->tid = tid; 651 t->tid = tid;
603 GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); 652 GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t);
@@ -748,9 +797,8 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
748 797
749 atsi.type = 0; 798 atsi.type = 0;
750 atsi.value = 0; 799 atsi.value = 0;
751 /* FIXME ctx */
752 if (GNUNET_OK == 800 if (GNUNET_OK ==
753 handler->callback (h->cls, t, NULL, peer, payload, &atsi)) 801 handler->callback (h->cls, t, &t->ctx, peer, payload, &atsi))
754 { 802 {
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "MESH: callback completed successfully\n"); 804 "MESH: callback completed successfully\n");
@@ -966,23 +1014,25 @@ send_packet (struct GNUNET_MESH_Handle *h,
966 * Connect to the mesh service. 1014 * Connect to the mesh service.
967 * 1015 *
968 * @param cfg configuration to use 1016 * @param cfg configuration to use
969 * @param cls closure for the various callbacks that follow
970 * (including handlers in the handlers array)
971 * @param queue_size size of the data message queue, shared among all tunnels 1017 * @param queue_size size of the data message queue, shared among all tunnels
972 * (each tunnel is guaranteed to accept at least one message, 1018 * (each tunnel is guaranteed to accept at least one message,
973 * no matter what is the status of other tunnels) 1019 * no matter what is the status of other tunnels)
1020 * @param cls closure for the various callbacks that follow
1021 * (including handlers in the handlers array)
1022 * @param new_tunnel function called when an *inbound* tunnel is created
974 * @param cleaner function called when an *inbound* tunnel is destroyed 1023 * @param cleaner function called when an *inbound* tunnel is destroyed
975 * @param handlers callbacks for messages we care about, NULL-terminated 1024 * @param handlers callbacks for messages we care about, NULL-terminated
976 * note that the mesh is allowed to drop notifications about 1025 * note that the mesh is allowed to drop notifications about
977 * inbound messages if the client does not process them fast 1026 * inbound messages if the client does not process them fast
978 * enough (for this notification type, a bounded queue is used) 1027 * enough (for this notification type, a bounded queue is used)
979 * @param stypes Application Types the client claims to offer 1028 * @param stypes list of the applications that this client claims to provide
980 * @return handle to the mesh service 1029 * @return handle to the mesh service NULL on error
981 * NULL on error (in this case, init is never called) 1030 * (in this case, init is never called)
982 */ 1031 */
983struct GNUNET_MESH_Handle * 1032struct GNUNET_MESH_Handle *
984GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1033GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
985 unsigned int queue_size, void *cls, 1034 unsigned int queue_size, void *cls,
1035 GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
986 GNUNET_MESH_TunnelEndHandler cleaner, 1036 GNUNET_MESH_TunnelEndHandler cleaner,
987 const struct GNUNET_MESH_MessageHandler *handlers, 1037 const struct GNUNET_MESH_MessageHandler *handlers,
988 const GNUNET_MESH_ApplicationType *stypes) 1038 const GNUNET_MESH_ApplicationType *stypes)
@@ -999,6 +1049,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
999 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); 1049 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
1000 h->cfg = cfg; 1050 h->cfg = cfg;
1001 h->max_queue_size = queue_size; 1051 h->max_queue_size = queue_size;
1052 h->new_tunnel = new_tunnel;
1002 h->cleaner = cleaner; 1053 h->cleaner = cleaner;
1003 h->client = GNUNET_CLIENT_connect ("mesh", cfg); 1054 h->client = GNUNET_CLIENT_connect ("mesh", cfg);
1004 if (h->client == NULL) 1055 if (h->client == NULL)
@@ -1010,7 +1061,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1010 h->cls = cls; 1061 h->cls = cls;
1011 h->message_handlers = handlers; 1062 h->message_handlers = handlers;
1012 h->applications = stypes; 1063 h->applications = stypes;
1013 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; 1064 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
1014 1065
1015 /* count handlers and apps, calculate size */ 1066 /* count handlers and apps, calculate size */
1016 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ; 1067 for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
@@ -1052,6 +1103,12 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1052void 1103void
1053GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 1104GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1054{ 1105{
1106 struct GNUNET_MESH_Tunnel *t;
1107
1108 for (t = handle->tunnels_head; NULL != t; t = t->next)
1109 {
1110 destroy_tunnel (handle, t->tid);
1111 }
1055 if (NULL != handle->th) 1112 if (NULL != handle->th)
1056 { 1113 {
1057 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 1114 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
@@ -1069,12 +1126,13 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1069 * and to broadcast). 1126 * and to broadcast).
1070 * 1127 *
1071 * @param h mesh handle 1128 * @param h mesh handle
1129 * @param tunnel_ctx client's tunnel context to associate with the tunnel
1072 * @param connect_handler function to call when peers are actually connected 1130 * @param connect_handler function to call when peers are actually connected
1073 * @param disconnect_handler function to call when peers are disconnected 1131 * @param disconnect_handler function to call when peers are disconnected
1074 * @param handler_cls closure for connect/disconnect handlers 1132 * @param handler_cls closure for connect/disconnect handlers
1075 */ 1133 */
1076struct GNUNET_MESH_Tunnel * 1134struct GNUNET_MESH_Tunnel *
1077GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 1135GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
1078 GNUNET_MESH_TunnelConnectHandler connect_handler, 1136 GNUNET_MESH_TunnelConnectHandler connect_handler,
1079 GNUNET_MESH_TunnelDisconnectHandler 1137 GNUNET_MESH_TunnelDisconnectHandler
1080 disconnect_handler, void *handler_cls) 1138 disconnect_handler, void *handler_cls)
@@ -1087,6 +1145,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
1087 t->connect_handler = connect_handler; 1145 t->connect_handler = connect_handler;
1088 t->disconnect_handler = disconnect_handler; 1146 t->disconnect_handler = disconnect_handler;
1089 t->cls = handler_cls; 1147 t->cls = handler_cls;
1148 t->ctx = tunnel_ctx;
1090 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 1149 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
1091 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1150 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1092 msg.tunnel_id = htonl (t->tid); 1151 msg.tunnel_id = htonl (t->tid);
@@ -1114,8 +1173,8 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun)
1114 1173
1115 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 1174 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
1116 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1175 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
1117 msg.tunnel_id = htonl (tun->tid); 1176 msg.tunnel_id = htonl (t->tid);
1118 GNUNET_free (tun); 1177 destroy_tunnel (h, t->tid);
1119 send_packet (h, &msg.header); 1178 send_packet (h, &msg.header);
1120} 1179}
1121 1180
@@ -1219,7 +1278,6 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
1219 struct GNUNET_MESH_ConnectPeerByType msg; 1278 struct GNUNET_MESH_ConnectPeerByType msg;
1220 1279
1221 GNUNET_array_append (tunnel->apps, tunnel->napps, app_type); 1280 GNUNET_array_append (tunnel->apps, tunnel->napps, app_type);
1222 /* FIXME: add a new api call disconnect by type? */
1223 1281
1224 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType)); 1282 msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectPeerByType));
1225 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE); 1283 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE);
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 312e72375..060db9c8a 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -104,7 +104,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
104 struct GNUNET_MESH_Tunnel *t; 104 struct GNUNET_MESH_Tunnel *t;
105 105
106 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0; 106 test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
107 mesh = GNUNET_MESH_connect (cfg, 10, NULL, NULL, handlers, app); 107 mesh = GNUNET_MESH_connect (cfg, 10, NULL, NULL, NULL, handlers, app);
108 if (NULL == mesh) 108 if (NULL == mesh)
109 { 109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n"); 110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
@@ -115,7 +115,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n"); 115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
116 } 116 }
117 117
118 t = GNUNET_MESH_tunnel_create (mesh, NULL, NULL, NULL); 118 t = GNUNET_MESH_tunnel_create (mesh, NULL, NULL, NULL, NULL);
119 119
120 GNUNET_MESH_tunnel_destroy (t); 120 GNUNET_MESH_tunnel_destroy (t);
121 121
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 53f00a24f..2cd74d6ef 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -204,7 +204,7 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
204 */ 204 */
205static void 205static void
206tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, 206tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
207 void **tunnel_ctx) 207 void *tunnel_ctx)
208{ 208{
209#if VERBOSE 209#if VERBOSE
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel disconnected\n"); 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel disconnected\n");
@@ -263,12 +263,13 @@ connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
264 "connecting to mesh service of peer %s\n", GNUNET_i2s (&d->id)); 264 "connecting to mesh service of peer %s\n", GNUNET_i2s (&d->id));
265#endif 265#endif
266 h = GNUNET_MESH_connect (d->cfg, 10, NULL, &tunnel_cleaner, handlers, &app); 266 h = GNUNET_MESH_connect (d->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers,
267 &app);
267#if VERBOSE 268#if VERBOSE
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected to mesh service of peer %s\n", 269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected to mesh service of peer %s\n",
269 GNUNET_i2s (&d->id)); 270 GNUNET_i2s (&d->id));
270#endif 271#endif
271 t = GNUNET_MESH_tunnel_create (h, &ch, &dh, NULL); 272 t = GNUNET_MESH_tunnel_create (h, NULL, &ch, &dh, NULL);
272 GNUNET_MESH_tunnel_destroy (t); 273 GNUNET_MESH_tunnel_destroy (t);
273 GNUNET_MESH_disconnect (h); 274 GNUNET_MESH_disconnect (h);
274} 275}