aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-07-23 14:32:08 +0000
committerBart Polot <bart@net.in.tum.de>2013-07-23 14:32:08 +0000
commit62c9b45a9dc8ee12b01066afe7fa90be76814a34 (patch)
treeab7ebda1837b5ddd840144f97d858a3acb0c43e8 /src/mesh
parent4219b8991d43d947d1336e195fc379113ec07851 (diff)
downloadgnunet-62c9b45a9dc8ee12b01066afe7fa90be76814a34.tar.gz
gnunet-62c9b45a9dc8ee12b01066afe7fa90be76814a34.zip
Change MESH API to use Tunnel to use Channel
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api_enc.c658
1 files changed, 324 insertions, 334 deletions
diff --git a/src/mesh/mesh_api_enc.c b/src/mesh/mesh_api_enc.c
index be80edd5b..e1990c2ee 100644
--- a/src/mesh/mesh_api_enc.c
+++ b/src/mesh/mesh_api_enc.c
@@ -31,7 +31,6 @@
31#include "mesh_protocol.h" 31#include "mesh_protocol.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__) 33#define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__)
34#define DEBUG_ACK GNUNET_YES
35 34
36/******************************************************************************/ 35/******************************************************************************/
37/************************ DATA STRUCTURES ****************************/ 36/************************ DATA STRUCTURES ****************************/
@@ -54,9 +53,9 @@ struct GNUNET_MESH_TransmitHandle
54 struct GNUNET_MESH_TransmitHandle *prev; 53 struct GNUNET_MESH_TransmitHandle *prev;
55 54
56 /** 55 /**
57 * Tunnel this message is sent on / for (may be NULL for control messages). 56 * Channel this message is sent on / for (may be NULL for control messages).
58 */ 57 */
59 struct GNUNET_MESH_Tunnel *tunnel; 58 struct GNUNET_MESH_Channel *channel;
60 59
61 /** 60 /**
62 * Callback to obtain the message to transmit, or NULL if we 61 * Callback to obtain the message to transmit, or NULL if we
@@ -103,7 +102,7 @@ struct GNUNET_MESH_Handle
103 struct GNUNET_CLIENT_Connection *client; 102 struct GNUNET_CLIENT_Connection *client;
104 103
105 /** 104 /**
106 * Set of handlers used for processing incoming messages in the tunnels 105 * Set of handlers used for processing incoming messages in the channels
107 */ 106 */
108 const struct GNUNET_MESH_MessageHandler *message_handlers; 107 const struct GNUNET_MESH_MessageHandler *message_handlers;
109 108
@@ -123,24 +122,24 @@ struct GNUNET_MESH_Handle
123 unsigned int n_ports; 122 unsigned int n_ports;
124 123
125 /** 124 /**
126 * Double linked list of the tunnels this client is connected to, head. 125 * Double linked list of the channels this client is connected to, head.
127 */ 126 */
128 struct GNUNET_MESH_Tunnel *tunnels_head; 127 struct GNUNET_MESH_Channel *channels_head;
129 128
130 /** 129 /**
131 * Double linked list of the tunnels this client is connected to, tail. 130 * Double linked list of the channels this client is connected to, tail.
132 */ 131 */
133 struct GNUNET_MESH_Tunnel *tunnels_tail; 132 struct GNUNET_MESH_Channel *channels_tail;
134 133
135 /** 134 /**
136 * Callback for inbound tunnel creation 135 * Callback for inbound channel creation
137 */ 136 */
138 GNUNET_MESH_InboundTunnelNotificationHandler *new_tunnel; 137 GNUNET_MESH_InboundChannelNotificationHandler *new_channel;
139 138
140 /** 139 /**
141 * Callback for inbound tunnel disconnection 140 * Callback for inbound channel disconnection
142 */ 141 */
143 GNUNET_MESH_TunnelEndHandler *cleaner; 142 GNUNET_MESH_ChannelEndHandler *cleaner;
144 143
145 /** 144 /**
146 * Handle to cancel pending transmissions in case of disconnection 145 * Handle to cancel pending transmissions in case of disconnection
@@ -163,9 +162,9 @@ struct GNUNET_MESH_Handle
163 struct GNUNET_MESH_TransmitHandle *th_tail; 162 struct GNUNET_MESH_TransmitHandle *th_tail;
164 163
165 /** 164 /**
166 * tid of the next tunnel to create (to avoid reusing IDs often) 165 * chid of the next channel to create (to avoid reusing IDs often)
167 */ 166 */
168 MESH_TunnelNumber next_tid; 167 MESH_ChannelNumber next_chid;
169 168
170 /** 169 /**
171 * Have we started the task to receive messages from the service 170 * Have we started the task to receive messages from the service
@@ -191,27 +190,22 @@ struct GNUNET_MESH_Handle
191 /** 190 /**
192 * Monitor callback 191 * Monitor callback
193 */ 192 */
194 GNUNET_MESH_TunnelsCB tunnels_cb; 193 GNUNET_MESH_ChannelsCB channels_cb;
195 194
196 /** 195 /**
197 * Monitor callback closure. 196 * Monitor callback closure.
198 */ 197 */
199 void *tunnels_cls; 198 void *channels_cls;
200 199
201 /** 200 /**
202 * Tunnel callback. 201 * Channel callback.
203 */ 202 */
204 GNUNET_MESH_TunnelCB tunnel_cb; 203 GNUNET_MESH_ChannelCB channel_cb;
205 204
206 /** 205 /**
207 * Tunnel callback closure. 206 * Channel callback closure.
208 */ 207 */
209 void *tunnel_cls; 208 void *channel_cls;
210
211#if DEBUG_ACK
212 unsigned int acks_sent;
213 unsigned int acks_recv;
214#endif
215}; 209};
216 210
217 211
@@ -226,9 +220,9 @@ struct GNUNET_MESH_Peer
226 GNUNET_PEER_Id id; 220 GNUNET_PEER_Id id;
227 221
228 /** 222 /**
229 * Tunnel this peer belongs to 223 * Channel this peer belongs to
230 */ 224 */
231 struct GNUNET_MESH_Tunnel *t; 225 struct GNUNET_MESH_Channel *t;
232 226
233 /** 227 /**
234 * Flag indicating whether service has informed about its connection 228 * Flag indicating whether service has informed about its connection
@@ -239,30 +233,30 @@ struct GNUNET_MESH_Peer
239 233
240 234
241/** 235/**
242 * Opaque handle to a tunnel. 236 * Opaque handle to a channel.
243 */ 237 */
244struct GNUNET_MESH_Tunnel 238struct GNUNET_MESH_Channel
245{ 239{
246 240
247 /** 241 /**
248 * DLL next 242 * DLL next
249 */ 243 */
250 struct GNUNET_MESH_Tunnel *next; 244 struct GNUNET_MESH_Channel *next;
251 245
252 /** 246 /**
253 * DLL prev 247 * DLL prev
254 */ 248 */
255 struct GNUNET_MESH_Tunnel *prev; 249 struct GNUNET_MESH_Channel *prev;
256 250
257 /** 251 /**
258 * Handle to the mesh this tunnel belongs to 252 * Handle to the mesh this channel belongs to
259 */ 253 */
260 struct GNUNET_MESH_Handle *mesh; 254 struct GNUNET_MESH_Handle *mesh;
261 255
262 /** 256 /**
263 * Local ID of the tunnel 257 * Local ID of the channel
264 */ 258 */
265 MESH_TunnelNumber tid; 259 MESH_ChannelNumber chid;
266 260
267 /** 261 /**
268 * Port number. 262 * Port number.
@@ -270,7 +264,7 @@ struct GNUNET_MESH_Tunnel
270 uint32_t port; 264 uint32_t port;
271 265
272 /** 266 /**
273 * Other end of the tunnel. 267 * Other end of the channel.
274 */ 268 */
275 GNUNET_PEER_Id peer; 269 GNUNET_PEER_Id peer;
276 270
@@ -280,22 +274,22 @@ struct GNUNET_MESH_Tunnel
280 void *ctx; 274 void *ctx;
281 275
282 /** 276 /**
283 * Size of packet queued in this tunnel 277 * Size of packet queued in this channel
284 */ 278 */
285 unsigned int packet_size; 279 unsigned int packet_size;
286 280
287 /** 281 /**
288 * Is the tunnel allowed to buffer? 282 * Is the channel allowed to buffer?
289 */ 283 */
290 int nobuffer; 284 int nobuffer;
291 285
292 /** 286 /**
293 * Is the tunnel realiable? 287 * Is the channel realiable?
294 */ 288 */
295 int reliable; 289 int reliable;
296 290
297 /** 291 /**
298 * If reliable, is the tunnel out of order? 292 * If reliable, is the channel out of order?
299 */ 293 */
300 int ooorder; 294 int ooorder;
301 295
@@ -319,9 +313,9 @@ struct MeshMQState
319 struct GNUNET_MESH_TransmitHandle *th; 313 struct GNUNET_MESH_TransmitHandle *th;
320 314
321 /** 315 /**
322 * Tunnel to send the data over. 316 * Channel to send the data over.
323 */ 317 */
324 struct GNUNET_MESH_Tunnel *tunnel; 318 struct GNUNET_MESH_Channel *channel;
325}; 319};
326 320
327 321
@@ -374,17 +368,17 @@ static size_t
374message_ready_size (struct GNUNET_MESH_Handle *h) 368message_ready_size (struct GNUNET_MESH_Handle *h)
375{ 369{
376 struct GNUNET_MESH_TransmitHandle *th; 370 struct GNUNET_MESH_TransmitHandle *th;
377 struct GNUNET_MESH_Tunnel *t; 371 struct GNUNET_MESH_Channel *ch;
378 372
379 for (th = h->th_head; NULL != th; th = th->next) 373 for (th = h->th_head; NULL != th; th = th->next)
380 { 374 {
381 t = th->tunnel; 375 ch = th->channel;
382 if (GNUNET_NO == th_is_payload (th)) 376 if (GNUNET_NO == th_is_payload (th))
383 { 377 {
384 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message internal\n"); 378 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message internal\n");
385 return th->size; 379 return th->size;
386 } 380 }
387 if (GNUNET_YES == t->allow_send) 381 if (GNUNET_YES == ch->allow_send)
388 { 382 {
389 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n"); 383 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n");
390 return th->size; 384 return th->size;
@@ -395,100 +389,102 @@ message_ready_size (struct GNUNET_MESH_Handle *h)
395 389
396 390
397/** 391/**
398 * Get the tunnel handler for the tunnel specified by id from the given handle 392 * Get the channel handler for the channel specified by id from the given handle
399 * @param h Mesh handle 393 * @param h Mesh handle
400 * @param tid ID of the wanted tunnel 394 * @param chid ID of the wanted channel
401 * @return handle to the required tunnel or NULL if not found 395 * @return handle to the required channel or NULL if not found
402 */ 396 */
403static struct GNUNET_MESH_Tunnel * 397static struct GNUNET_MESH_Channel *
404retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) 398retrieve_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid)
405{ 399{
406 struct GNUNET_MESH_Tunnel *t; 400 struct GNUNET_MESH_Channel *ch;
407 401
408 t = h->tunnels_head; 402 ch = h->channels_head;
409 while (t != NULL) 403 while (ch != NULL)
410 { 404 {
411 if (t->tid == tid) 405 if (ch->chid == chid)
412 return t; 406 return ch;
413 t = t->next; 407 ch = ch->next;
414 } 408 }
415 return NULL; 409 return NULL;
416} 410}
417 411
418 412
419/** 413/**
420 * Create a new tunnel and insert it in the tunnel list of the mesh handle 414 * Create a new channel and insert it in the channel list of the mesh handle
415 *
421 * @param h Mesh handle 416 * @param h Mesh handle
422 * @param tid desired tid of the tunnel, 0 to assign one automatically 417 * @param chid Desired chid of the channel, 0 to assign one automatically.
423 * @return handle to the created tunnel 418 *
419 * @return Handle to the created channel.
424 */ 420 */
425static struct GNUNET_MESH_Tunnel * 421static struct GNUNET_MESH_Channel *
426create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) 422create_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid)
427{ 423{
428 struct GNUNET_MESH_Tunnel *t; 424 struct GNUNET_MESH_Channel *ch;
429 425
430 t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); 426 ch = GNUNET_malloc (sizeof (struct GNUNET_MESH_Channel));
431 GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); 427 GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch);
432 t->mesh = h; 428 ch->mesh = h;
433 if (0 == tid) 429 if (0 == chid)
434 { 430 {
435 t->tid = h->next_tid; 431 ch->chid = h->next_chid;
436 while (NULL != retrieve_tunnel (h, h->next_tid)) 432 while (NULL != retrieve_channel (h, h->next_chid))
437 { 433 {
438 h->next_tid++; 434 h->next_chid++;
439 h->next_tid &= ~GNUNET_MESH_LOCAL_TUNNEL_ID_SERV; 435 h->next_chid &= ~GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
440 h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 436 h->next_chid |= GNUNET_MESH_LOCAL_CHANNEL_ID_CLI;
441 } 437 }
442 } 438 }
443 else 439 else
444 { 440 {
445 t->tid = tid; 441 ch->chid = chid;
446 } 442 }
447 t->allow_send = GNUNET_NO; 443 ch->allow_send = GNUNET_NO;
448 t->nobuffer = GNUNET_NO; 444 ch->nobuffer = GNUNET_NO;
449 return t; 445 return ch;
450} 446}
451 447
452 448
453/** 449/**
454 * Destroy the specified tunnel. 450 * Destroy the specified channel.
455 * - Destroys all peers, calling the disconnect callback on each if needed 451 * - Destroys all peers, calling the disconnect callback on each if needed
456 * - Cancels all outgoing traffic for that tunnel, calling respective notifys 452 * - Cancels all outgoing traffic for that channel, calling respective notifys
457 * - Calls cleaner if tunnel was inbound 453 * - Calls cleaner if channel was inbound
458 * - Frees all memory used 454 * - Frees all memory used
459 * 455 *
460 * @param t Pointer to the tunnel. 456 * @param t Pointer to the channel.
461 * @param call_cleaner Whether to call the cleaner handler. 457 * @param call_cleaner Whether to call the cleaner handler.
462 * 458 *
463 * @return Handle to the required tunnel or NULL if not found. 459 * @return Handle to the required channel or NULL if not found.
464 */ 460 */
465static void 461static void
466destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner) 462destroy_channel (struct GNUNET_MESH_Channel *ch, int call_cleaner)
467{ 463{
468 struct GNUNET_MESH_Handle *h; 464 struct GNUNET_MESH_Handle *h;
469 struct GNUNET_MESH_TransmitHandle *th; 465 struct GNUNET_MESH_TransmitHandle *th;
470 struct GNUNET_MESH_TransmitHandle *next; 466 struct GNUNET_MESH_TransmitHandle *next;
471 467
472 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_tunnel %X\n", t->tid); 468 LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_channel %X\n", ch->chid);
473 469
474 if (NULL == t) 470 if (NULL == ch)
475 { 471 {
476 GNUNET_break (0); 472 GNUNET_break (0);
477 return; 473 return;
478 } 474 }
479 h = t->mesh; 475 h = ch->mesh;
480 476
481 GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); 477 GNUNET_CONTAINER_DLL_remove (h->channels_head, h->channels_tail, ch);
482 478
483 /* signal tunnel destruction */ 479 /* signal channel destruction */
484 if ( (NULL != h->cleaner) && (0 != t->peer) && (GNUNET_YES == call_cleaner) ) 480 if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) )
485 h->cleaner (h->cls, t, t->ctx); 481 h->cleaner (h->cls, ch, ch->ctx);
486 482
487 /* check that clients did not leave messages behind in the queue */ 483 /* check that clients did not leave messages behind in the queue */
488 for (th = h->th_head; NULL != th; th = next) 484 for (th = h->th_head; NULL != th; th = next)
489 { 485 {
490 next = th->next; 486 next = th->next;
491 if (th->tunnel != t) 487 if (th->channel != ch)
492 continue; 488 continue;
493 /* Clients should have aborted their requests already. 489 /* Clients should have aborted their requests already.
494 * Management traffic should be ok, as clients can't cancel that */ 490 * Management traffic should be ok, as clients can't cancel that */
@@ -509,9 +505,9 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner)
509 h->th = NULL; 505 h->th = NULL;
510 } 506 }
511 507
512 if (0 != t->peer) 508 if (0 != ch->peer)
513 GNUNET_PEER_change_rc (t->peer, -1); 509 GNUNET_PEER_change_rc (ch->peer, -1);
514 GNUNET_free (t); 510 GNUNET_free (ch);
515 return; 511 return;
516} 512}
517 513
@@ -528,9 +524,9 @@ timeout_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
528 struct GNUNET_MESH_TransmitHandle *th = cls; 524 struct GNUNET_MESH_TransmitHandle *th = cls;
529 struct GNUNET_MESH_Handle *mesh; 525 struct GNUNET_MESH_Handle *mesh;
530 526
531 mesh = th->tunnel->mesh; 527 mesh = th->channel->mesh;
532 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); 528 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th);
533 th->tunnel->packet_size = 0; 529 th->channel->packet_size = 0;
534 if (GNUNET_YES == th_is_payload (th)) 530 if (GNUNET_YES == th_is_payload (th))
535 th->notify (th->notify_cls, 0, NULL); 531 th->notify (th->notify_cls, 0, NULL);
536 GNUNET_free (th); 532 GNUNET_free (th);
@@ -570,34 +566,30 @@ add_to_queue (struct GNUNET_MESH_Handle *h,
570 * 566 *
571 * @param h mesh handle 567 * @param h mesh handle
572 * @param msg message to transmit 568 * @param msg message to transmit
573 * @param tunnel tunnel this send is related to (NULL if N/A) 569 * @param channel channel this send is related to (NULL if N/A)
574 */ 570 */
575static void 571static void
576send_packet (struct GNUNET_MESH_Handle *h, 572send_packet (struct GNUNET_MESH_Handle *h,
577 const struct GNUNET_MessageHeader *msg, 573 const struct GNUNET_MessageHeader *msg,
578 struct GNUNET_MESH_Tunnel *tunnel); 574 struct GNUNET_MESH_Channel *channel);
579 575
580 576
581/** 577/**
582 * Send an ack on the tunnel to confirm the processing of a message. 578 * Send an ack on the channel to confirm the processing of a message.
583 * 579 *
584 * @param t Tunnel on which to send the ACK. 580 * @param ch Channel on which to send the ACK.
585 */ 581 */
586static void 582static void
587send_ack (struct GNUNET_MESH_Tunnel *t) 583send_ack (struct GNUNET_MESH_Channel *ch)
588{ 584{
589 struct GNUNET_MESH_LocalAck msg; 585 struct GNUNET_MESH_LocalAck msg;
590 586
591 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on tunnel %X\n", t->tid); 587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", ch->chid);
592 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK); 588 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
593 msg.header.size = htons (sizeof (msg)); 589 msg.header.size = htons (sizeof (msg));
594 msg.tunnel_id = htonl (t->tid); 590 msg.channel_id = htonl (ch->chid);
595
596#if DEBUG_ACK
597 t->mesh->acks_sent++;
598#endif
599 591
600 send_packet (t->mesh, &msg.header, t); 592 send_packet (ch->mesh, &msg.header, ch);
601 return; 593 return;
602} 594}
603 595
@@ -663,7 +655,7 @@ send_connect (struct GNUNET_MESH_Handle *h)
663static int 655static int
664do_reconnect (struct GNUNET_MESH_Handle *h) 656do_reconnect (struct GNUNET_MESH_Handle *h)
665{ 657{
666 struct GNUNET_MESH_Tunnel *t; 658 struct GNUNET_MESH_Channel *ch;
667 659
668 LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n"); 660 LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
669 LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n"); 661 LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n");
@@ -704,36 +696,36 @@ do_reconnect (struct GNUNET_MESH_Handle *h)
704 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 696 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
705 } 697 }
706 send_connect (h); 698 send_connect (h);
707 /* Rebuild all tunnels */ 699 /* Rebuild all channels */
708 for (t = h->tunnels_head; NULL != t; t = t->next) 700 for (ch = h->channels_head; NULL != ch; ch = ch->next)
709 { 701 {
710 struct GNUNET_MESH_TunnelMessage tmsg; 702 struct GNUNET_MESH_ChannelMessage tmsg;
711 uint32_t options; 703 uint32_t options;
712 704
713 if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 705 if (ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
714 { 706 {
715 /* Tunnel was created by service (incoming tunnel) */ 707 /* Channel was created by service (incoming channel) */
716 /* TODO: Notify service of missing tunnel, to request 708 /* TODO: Notify service of missing channel, to request
717 * creator to recreate path (find a path to him via DHT?) 709 * creator to recreate path (find a path to him via DHT?)
718 */ 710 */
719 continue; 711 continue;
720 } 712 }
721 t->allow_send = GNUNET_NO; 713 ch->allow_send = GNUNET_NO;
722 tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 714 tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_CREATE);
723 tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 715 tmsg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage));
724 tmsg.tunnel_id = htonl (t->tid); 716 tmsg.channel_id = htonl (ch->chid);
725 tmsg.port = htonl (t->port); 717 tmsg.port = htonl (ch->port);
726 GNUNET_PEER_resolve (t->peer, &tmsg.peer); 718 GNUNET_PEER_resolve (ch->peer, &tmsg.peer);
727 719
728 options = 0; 720 options = 0;
729 if (GNUNET_YES == t->nobuffer) 721 if (GNUNET_YES == ch->nobuffer)
730 options |= GNUNET_MESH_OPTION_NOBUFFER; 722 options |= GNUNET_MESH_OPTION_NOBUFFER;
731 723
732 if (GNUNET_YES == t->reliable) 724 if (GNUNET_YES == ch->reliable)
733 options |= GNUNET_MESH_OPTION_RELIABLE; 725 options |= GNUNET_MESH_OPTION_RELIABLE;
734 726
735 tmsg.opt = htonl (options); 727 tmsg.opt = htonl (options);
736 send_packet (h, &tmsg.header, t); 728 send_packet (h, &tmsg.header, ch);
737 } 729 }
738 return GNUNET_YES; 730 return GNUNET_YES;
739} 731}
@@ -780,61 +772,64 @@ reconnect (struct GNUNET_MESH_Handle *h)
780/******************************************************************************/ 772/******************************************************************************/
781 773
782/** 774/**
783 * Process the new tunnel notification and add it to the tunnels in the handle 775 * Process the new channel notification and add it to the channels in the handle
784 * 776 *
785 * @param h The mesh handle 777 * @param h The mesh handle
786 * @param msg A message with the details of the new incoming tunnel 778 * @param msg A message with the details of the new incoming channel
787 */ 779 */
788static void 780static void
789process_tunnel_created (struct GNUNET_MESH_Handle *h, 781process_channel_created (struct GNUNET_MESH_Handle *h,
790 const struct GNUNET_MESH_TunnelMessage *msg) 782 const struct GNUNET_MESH_ChannelMessage *msg)
791{ 783{
792 struct GNUNET_MESH_Tunnel *t; 784 struct GNUNET_MESH_Channel *ch;
793 MESH_TunnelNumber tid; 785 MESH_ChannelNumber chid;
794 uint32_t port; 786 uint32_t port;
795 787
796 tid = ntohl (msg->tunnel_id); 788 chid = ntohl (msg->channel_id);
797 port = ntohl (msg->port); 789 port = ntohl (msg->port);
798 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming tunnel %X:%u\n", tid, port); 790 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X:%u\n", chid, port);
799 if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 791 if (chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
800 { 792 {
801 GNUNET_break (0); 793 GNUNET_break (0);
802 return; 794 return;
803 } 795 }
804 if (NULL != h->new_tunnel) 796 if (NULL != h->new_channel)
805 { 797 {
806 t = create_tunnel (h, tid); 798 ch = create_channel (h, chid);
807 t->allow_send = GNUNET_NO; 799 ch->allow_send = GNUNET_NO;
808 t->peer = GNUNET_PEER_intern (&msg->peer); 800 ch->peer = GNUNET_PEER_intern (&msg->peer);
809 t->mesh = h; 801 ch->mesh = h;
810 t->tid = tid; 802 ch->chid = chid;
811 t->port = port; 803 ch->port = port;
812 if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) 804 if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER))
813 t->nobuffer = GNUNET_YES; 805 ch->nobuffer = GNUNET_YES;
814 else 806 else
815 t->nobuffer = GNUNET_NO; 807 ch->nobuffer = GNUNET_NO;
808
816 if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE)) 809 if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE))
817 t->reliable = GNUNET_YES; 810 ch->reliable = GNUNET_YES;
818 else 811 else
819 t->reliable = GNUNET_NO; 812 ch->reliable = GNUNET_NO;
820 if (GNUNET_YES == t->reliable && 813
814 if (GNUNET_YES == ch->reliable &&
821 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER)) 815 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER))
822 t->ooorder = GNUNET_YES; 816 ch->ooorder = GNUNET_YES;
823 else 817 else
824 t->ooorder = GNUNET_NO; 818 ch->ooorder = GNUNET_NO;
825 LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); 819
826 t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port); 820 LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", t);
821 ch->ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port);
827 LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); 822 LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
828 } 823 }
829 else 824 else
830 { 825 {
831 struct GNUNET_MESH_TunnelMessage d_msg; 826 struct GNUNET_MESH_ChannelMessage d_msg;
832 827
833 LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming tunnels\n"); 828 LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n");
834 829
835 d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 830 d_msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_DESTROY);
836 d_msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 831 d_msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage));
837 d_msg.tunnel_id = msg->tunnel_id; 832 d_msg.channel_id = msg->channel_id;
838 memset (&d_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 833 memset (&d_msg.peer, 0, sizeof (struct GNUNET_PeerIdentity));
839 d_msg.port = 0; 834 d_msg.port = 0;
840 d_msg.opt = 0; 835 d_msg.opt = 0;
@@ -846,29 +841,29 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
846 841
847 842
848/** 843/**
849 * Process the tunnel destroy notification and free associated resources 844 * Process the channel destroy notification and free associated resources
850 * 845 *
851 * @param h The mesh handle 846 * @param h The mesh handle
852 * @param msg A message with the details of the tunnel being destroyed 847 * @param msg A message with the details of the channel being destroyed
853 */ 848 */
854static void 849static void
855process_tunnel_destroy (struct GNUNET_MESH_Handle *h, 850process_channel_destroy (struct GNUNET_MESH_Handle *h,
856 const struct GNUNET_MESH_TunnelMessage *msg) 851 const struct GNUNET_MESH_ChannelMessage *msg)
857{ 852{
858 struct GNUNET_MESH_Tunnel *t; 853 struct GNUNET_MESH_Channel *ch;
859 MESH_TunnelNumber tid; 854 MESH_ChannelNumber chid;
860 855
861 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel from service\n"); 856 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel from service\n");
862 tid = ntohl (msg->tunnel_id); 857 chid = ntohl (msg->channel_id);
863 t = retrieve_tunnel (h, tid); 858 ch = retrieve_channel (h, chid);
864 859
865 if (NULL == t) 860 if (NULL == ch)
866 { 861 {
867 LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X unknown\n", tid); 862 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid);
868 return; 863 return;
869 } 864 }
870 LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X destroyed\n", t->tid); 865 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X destroyed\n", ch->chid);
871 destroy_tunnel (t, GNUNET_YES); 866 destroy_channel (ch, GNUNET_YES);
872} 867}
873 868
874 869
@@ -885,7 +880,7 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
885 const struct GNUNET_MessageHeader *payload; 880 const struct GNUNET_MessageHeader *payload;
886 const struct GNUNET_MESH_MessageHandler *handler; 881 const struct GNUNET_MESH_MessageHandler *handler;
887 struct GNUNET_MESH_LocalData *dmsg; 882 struct GNUNET_MESH_LocalData *dmsg;
888 struct GNUNET_MESH_Tunnel *t; 883 struct GNUNET_MESH_Channel *ch;
889 unsigned int i; 884 unsigned int i;
890 uint16_t type; 885 uint16_t type;
891 886
@@ -893,14 +888,14 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
893 888
894 dmsg = (struct GNUNET_MESH_LocalData *) message; 889 dmsg = (struct GNUNET_MESH_LocalData *) message;
895 890
896 t = retrieve_tunnel (h, ntohl (dmsg->tid)); 891 ch = retrieve_channel (h, ntohl (dmsg->chid));
897 payload = (struct GNUNET_MessageHeader *) &dmsg[1]; 892 payload = (struct GNUNET_MessageHeader *) &dmsg[1];
898 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on tunnel %s [%X]\n", 893 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
899 t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? "fwd" : "bck", 894 ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "fwd" : "bck",
900 GNUNET_i2s (GNUNET_PEER_resolve2(t->peer)), ntohl (dmsg->tid)); 895 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (dmsg->chid));
901 if (NULL == t) 896 if (NULL == ch)
902 { 897 {
903 /* Tunnel was ignored/destroyed, probably service didn't get it yet */ 898 /* Channel was ignored/destroyed, probably service didn't get it yet */
904 LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n"); 899 LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n");
905 return; 900 return;
906 } 901 }
@@ -915,10 +910,10 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
915 if (handler->type == type) 910 if (handler->type == type)
916 { 911 {
917 if (GNUNET_OK != 912 if (GNUNET_OK !=
918 handler->callback (h->cls, t, &t->ctx, payload)) 913 handler->callback (h->cls, ch, &ch->ctx, payload))
919 { 914 {
920 LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n"); 915 LOG (GNUNET_ERROR_TYPE_DEBUG, "callback caused disconnection\n");
921 GNUNET_MESH_tunnel_destroy (t); 916 GNUNET_MESH_channel_destroy (ch);
922 return; 917 return;
923 } 918 }
924 else 919 else
@@ -943,26 +938,26 @@ process_ack (struct GNUNET_MESH_Handle *h,
943 const struct GNUNET_MessageHeader *message) 938 const struct GNUNET_MessageHeader *message)
944{ 939{
945 struct GNUNET_MESH_LocalAck *msg; 940 struct GNUNET_MESH_LocalAck *msg;
946 struct GNUNET_MESH_Tunnel *t; 941 struct GNUNET_MESH_Channel *ch;
947 MESH_TunnelNumber tid; 942 MESH_ChannelNumber chid;
948 943
949 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); 944 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
950 h->acks_recv++; 945 h->acks_recv++;
951 msg = (struct GNUNET_MESH_LocalAck *) message; 946 msg = (struct GNUNET_MESH_LocalAck *) message;
952 tid = ntohl (msg->tunnel_id); 947 chid = ntohl (msg->channel_id);
953 t = retrieve_tunnel (h, tid); 948 ch = retrieve_channel (h, chid);
954 if (NULL == t) 949 if (NULL == ch)
955 { 950 {
956 LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown tunnel %X\n", tid); 951 LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown channel %X\n", chid);
957 return; 952 return;
958 } 953 }
959 LOG (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X!\n", t->tid); 954 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid);
960 t->allow_send = GNUNET_YES; 955 ch->allow_send = GNUNET_YES;
961 if (NULL == h->th && 0 < t->packet_size) 956 if (NULL == h->th && 0 < ch->packet_size)
962 { 957 {
963 LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n"); 958 LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n");
964 h->th = 959 h->th =
965 GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size, 960 GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size,
966 GNUNET_TIME_UNIT_FOREVER_REL, 961 GNUNET_TIME_UNIT_FOREVER_REL,
967 GNUNET_YES, &send_callback, h); 962 GNUNET_YES, &send_callback, h);
968 } 963 }
@@ -970,20 +965,20 @@ process_ack (struct GNUNET_MESH_Handle *h,
970 965
971 966
972/** 967/**
973 * Process a local reply about info on all tunnels, pass info to the user. 968 * Process a local reply about info on all channels, pass info to the user.
974 * 969 *
975 * @param h Mesh handle. 970 * @param h Mesh handle.
976 * @param message Message itself. 971 * @param message Message itself.
977 */ 972 */
978static void 973static void
979process_get_tunnels (struct GNUNET_MESH_Handle *h, 974process_get_channels (struct GNUNET_MESH_Handle *h,
980 const struct GNUNET_MessageHeader *message) 975 const struct GNUNET_MessageHeader *message)
981{ 976{
982 struct GNUNET_MESH_LocalMonitor *msg; 977 struct GNUNET_MESH_LocalMonitor *msg;
983 978
984 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); 979 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
985 980
986 if (NULL == h->tunnels_cb) 981 if (NULL == h->channels_cb)
987 { 982 {
988 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); 983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
989 return; 984 return;
@@ -996,35 +991,35 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
996 { 991 {
997 GNUNET_break_op (0); 992 GNUNET_break_op (0);
998 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 993 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
999 "Get tunnels message: size %hu - expected %u\n", 994 "Get channels message: size %hu - expected %u\n",
1000 ntohs (message->size), 995 ntohs (message->size),
1001 sizeof (struct GNUNET_MESH_LocalMonitor)); 996 sizeof (struct GNUNET_MESH_LocalMonitor));
1002 return; 997 return;
1003 } 998 }
1004 h->tunnels_cb (h->tunnels_cls, 999 h->channels_cb (h->channels_cls,
1005 ntohl (msg->tunnel_id), 1000 ntohl (msg->channel_id),
1006 &msg->owner, 1001 &msg->owner,
1007 &msg->destination); 1002 &msg->destination);
1008} 1003}
1009 1004
1010 1005
1011 1006
1012/** 1007/**
1013 * Process a local monitor_tunnel reply, pass info to the user. 1008 * Process a local monitor_channel reply, pass info to the user.
1014 * 1009 *
1015 * @param h Mesh handle. 1010 * @param h Mesh handle.
1016 * @param message Message itself. 1011 * @param message Message itself.
1017 */ 1012 */
1018static void 1013static void
1019process_show_tunnel (struct GNUNET_MESH_Handle *h, 1014process_show_channel (struct GNUNET_MESH_Handle *h,
1020 const struct GNUNET_MessageHeader *message) 1015 const struct GNUNET_MessageHeader *message)
1021{ 1016{
1022 struct GNUNET_MESH_LocalMonitor *msg; 1017 struct GNUNET_MESH_LocalMonitor *msg;
1023 size_t esize; 1018 size_t esize;
1024 1019
1025 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Tunnel messasge received\n"); 1020 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
1026 1021
1027 if (NULL == h->tunnel_cb) 1022 if (NULL == h->channel_cb)
1028 { 1023 {
1029 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n"); 1024 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " ignored\n");
1030 return; 1025 return;
@@ -1037,20 +1032,20 @@ process_show_tunnel (struct GNUNET_MESH_Handle *h,
1037 { 1032 {
1038 GNUNET_break_op (0); 1033 GNUNET_break_op (0);
1039 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1034 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1040 "Show tunnel message: size %hu - expected %u\n", 1035 "Show channel message: size %hu - expected %u\n",
1041 ntohs (message->size), 1036 ntohs (message->size),
1042 esize); 1037 esize);
1043 1038
1044 h->tunnel_cb (h->tunnel_cls, NULL, NULL); 1039 h->channel_cb (h->channel_cls, NULL, NULL);
1045 h->tunnel_cb = NULL; 1040 h->channel_cb = NULL;
1046 h->tunnel_cls = NULL; 1041 h->channel_cls = NULL;
1047 1042
1048 return; 1043 return;
1049 } 1044 }
1050 1045
1051 h->tunnel_cb (h->tunnel_cls, 1046 h->channel_cb (h->channel_cls,
1052 &msg->destination, 1047 &msg->destination,
1053 &msg->owner); 1048 &msg->owner);
1054} 1049}
1055 1050
1056 1051
@@ -1079,26 +1074,26 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg)
1079 GNUNET_MESH_DEBUG_M2S (type)); 1074 GNUNET_MESH_DEBUG_M2S (type));
1080 switch (type) 1075 switch (type)
1081 { 1076 {
1082 /* Notify of a new incoming tunnel */ 1077 /* Notify of a new incoming channel */
1083 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: 1078 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_CREATE:
1084 process_tunnel_created (h, (struct GNUNET_MESH_TunnelMessage *) msg); 1079 process_channel_created (h, (struct GNUNET_MESH_ChannelMessage *) msg);
1085 break; 1080 break;
1086 /* Notify of a tunnel disconnection */ 1081 /* Notify of a channel disconnection */
1087 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: 1082 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_DESTROY:
1088 process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg); 1083 process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg);
1089 break; 1084 break;
1090 /* Notify of a new data packet in the tunnel */ 1085 /* Notify of a new data packet in the channel */
1091 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA: 1086 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA:
1092 process_incoming_data (h, msg); 1087 process_incoming_data (h, msg);
1093 break; 1088 break;
1094 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK: 1089 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
1095 process_ack (h, msg); 1090 process_ack (h, msg);
1096 break; 1091 break;
1097 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: 1092 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
1098 process_get_tunnels (h, msg); 1093 process_get_channels (h, msg);
1099 break; 1094 break;
1100 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: 1095 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
1101 process_show_tunnel (h, msg); 1096 process_show_channel (h, msg);
1102 break; 1097 break;
1103 default: 1098 default:
1104 /* We shouldn't get any other packages, log and ignore */ 1099 /* We shouldn't get any other packages, log and ignore */
@@ -1140,7 +1135,7 @@ send_callback (void *cls, size_t size, void *buf)
1140 struct GNUNET_MESH_Handle *h = cls; 1135 struct GNUNET_MESH_Handle *h = cls;
1141 struct GNUNET_MESH_TransmitHandle *th; 1136 struct GNUNET_MESH_TransmitHandle *th;
1142 struct GNUNET_MESH_TransmitHandle *next; 1137 struct GNUNET_MESH_TransmitHandle *next;
1143 struct GNUNET_MESH_Tunnel *t; 1138 struct GNUNET_MESH_Channel *ch;
1144 char *cbuf = buf; 1139 char *cbuf = buf;
1145 size_t tsize; 1140 size_t tsize;
1146 size_t psize; 1141 size_t psize;
@@ -1160,20 +1155,20 @@ send_callback (void *cls, size_t size, void *buf)
1160 nsize = message_ready_size (h); 1155 nsize = message_ready_size (h);
1161 while ((NULL != (th = next)) && (0 < nsize) && (size >= nsize)) 1156 while ((NULL != (th = next)) && (0 < nsize) && (size >= nsize))
1162 { 1157 {
1163 t = th->tunnel; 1158 ch = th->channel;
1164 if (GNUNET_YES == th_is_payload (th)) 1159 if (GNUNET_YES == th_is_payload (th))
1165 { 1160 {
1166 struct GNUNET_MESH_LocalData *dmsg; 1161 struct GNUNET_MESH_LocalData *dmsg;
1167 struct GNUNET_MessageHeader *mh; 1162 struct GNUNET_MessageHeader *mh;
1168 1163
1169 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n"); 1164 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n");
1170 if (GNUNET_NO == t->allow_send) 1165 if (GNUNET_NO == ch->allow_send)
1171 { 1166 {
1172 /* This tunnel is not ready to transmit yet, try next message */ 1167 /* This channel is not ready to transmit yet, try next message */
1173 next = th->next; 1168 next = th->next;
1174 continue; 1169 continue;
1175 } 1170 }
1176 t->packet_size = 0; 1171 ch->packet_size = 0;
1177 GNUNET_assert (size >= th->size); 1172 GNUNET_assert (size >= th->size);
1178 dmsg = (struct GNUNET_MESH_LocalData *) cbuf; 1173 dmsg = (struct GNUNET_MESH_LocalData *) cbuf;
1179 mh = (struct GNUNET_MessageHeader *) &dmsg[1]; 1174 mh = (struct GNUNET_MessageHeader *) &dmsg[1];
@@ -1185,11 +1180,11 @@ send_callback (void *cls, size_t size, void *buf)
1185 psize += sizeof (struct GNUNET_MESH_LocalData); 1180 psize += sizeof (struct GNUNET_MESH_LocalData);
1186 GNUNET_assert (size >= psize); 1181 GNUNET_assert (size >= psize);
1187 dmsg->header.size = htons (psize); 1182 dmsg->header.size = htons (psize);
1188 dmsg->tid = htonl (t->tid); 1183 dmsg->chid = htonl (ch->chid);
1189 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA); 1184 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
1190 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n", 1185 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n",
1191 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type))); 1186 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
1192 t->allow_send = GNUNET_NO; 1187 ch->allow_send = GNUNET_NO;
1193 } 1188 }
1194 else 1189 else
1195 { 1190 {
@@ -1254,12 +1249,12 @@ send_callback (void *cls, size_t size, void *buf)
1254 * 1249 *
1255 * @param h mesh handle 1250 * @param h mesh handle
1256 * @param msg message to transmit 1251 * @param msg message to transmit
1257 * @param tunnel tunnel this send is related to (NULL if N/A) 1252 * @param channel channel this send is related to (NULL if N/A)
1258 */ 1253 */
1259static void 1254static void
1260send_packet (struct GNUNET_MESH_Handle *h, 1255send_packet (struct GNUNET_MESH_Handle *h,
1261 const struct GNUNET_MessageHeader *msg, 1256 const struct GNUNET_MessageHeader *msg,
1262 struct GNUNET_MESH_Tunnel *tunnel) 1257 struct GNUNET_MESH_Channel *channel)
1263{ 1258{
1264 struct GNUNET_MESH_TransmitHandle *th; 1259 struct GNUNET_MESH_TransmitHandle *th;
1265 size_t msize; 1260 size_t msize;
@@ -1270,7 +1265,7 @@ send_packet (struct GNUNET_MESH_Handle *h,
1270 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize); 1265 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize);
1271 th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1266 th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1272 th->size = msize; 1267 th->size = msize;
1273 th->tunnel = tunnel; 1268 th->channel = channel;
1274 memcpy (&th[1], msg, msize); 1269 memcpy (&th[1], msg, msize);
1275 add_to_queue (h, th); 1270 add_to_queue (h, th);
1276 LOG (GNUNET_ERROR_TYPE_DEBUG, " queued\n"); 1271 LOG (GNUNET_ERROR_TYPE_DEBUG, " queued\n");
@@ -1290,8 +1285,8 @@ send_packet (struct GNUNET_MESH_Handle *h,
1290 1285
1291struct GNUNET_MESH_Handle * 1286struct GNUNET_MESH_Handle *
1292GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, 1287GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1293 GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, 1288 GNUNET_MESH_InboundChannelNotificationHandler new_channel,
1294 GNUNET_MESH_TunnelEndHandler cleaner, 1289 GNUNET_MESH_ChannelEndHandler cleaner,
1295 const struct GNUNET_MESH_MessageHandler *handlers, 1290 const struct GNUNET_MESH_MessageHandler *handlers,
1296 const uint32_t *ports) 1291 const uint32_t *ports)
1297{ 1292{
@@ -1301,7 +1296,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1301 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); 1296 h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
1302 LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h); 1297 LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h);
1303 h->cfg = cfg; 1298 h->cfg = cfg;
1304 h->new_tunnel = new_tunnel; 1299 h->new_channel = new_channel;
1305 h->cleaner = cleaner; 1300 h->cleaner = cleaner;
1306 h->client = GNUNET_CLIENT_connect ("mesh", cfg); 1301 h->client = GNUNET_CLIENT_connect ("mesh", cfg);
1307 if (h->client == NULL) 1302 if (h->client == NULL)
@@ -1313,21 +1308,21 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1313 h->cls = cls; 1308 h->cls = cls;
1314 h->message_handlers = handlers; 1309 h->message_handlers = handlers;
1315 h->ports = ports; 1310 h->ports = ports;
1316 h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 1311 h->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_CLI;
1317 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 1312 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1318 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 1313 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1319 1314
1320 if (NULL != ports && ports[0] != 0 && NULL == new_tunnel) 1315 if (NULL != ports && ports[0] != 0 && NULL == new_channel)
1321 { 1316 {
1322 GNUNET_break (0); 1317 GNUNET_break (0);
1323 LOG (GNUNET_ERROR_TYPE_DEBUG, 1318 LOG (GNUNET_ERROR_TYPE_DEBUG,
1324 "no new tunnel handler given, ports parameter is useless!!\n"); 1319 "no new channel handler given, ports parameter is useless!!\n");
1325 } 1320 }
1326 if ((NULL == ports || ports[0] == 0) && NULL != new_tunnel) 1321 if ((NULL == ports || ports[0] == 0) && NULL != new_channel)
1327 { 1322 {
1328 GNUNET_break (0); 1323 GNUNET_break (0);
1329 LOG (GNUNET_ERROR_TYPE_DEBUG, 1324 LOG (GNUNET_ERROR_TYPE_DEBUG,
1330 "no ports given, new tunnel handler will never be called!!\n"); 1325 "no ports given, new channel handler will never be called!!\n");
1331 } 1326 }
1332 /* count handlers */ 1327 /* count handlers */
1333 for (h->n_handlers = 0; 1328 for (h->n_handlers = 0;
@@ -1345,28 +1340,23 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1345void 1340void
1346GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) 1341GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1347{ 1342{
1348 struct GNUNET_MESH_Tunnel *t; 1343 struct GNUNET_MESH_Channel *ch;
1349 struct GNUNET_MESH_Tunnel *aux; 1344 struct GNUNET_MESH_Channel *aux;
1350 struct GNUNET_MESH_TransmitHandle *th; 1345 struct GNUNET_MESH_TransmitHandle *th;
1351 1346
1352 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH DISCONNECT\n"); 1347 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH DISCONNECT\n");
1353 1348
1354#if DEBUG_ACK 1349 ch = handle->channels_head;
1355 LOG (GNUNET_ERROR_TYPE_INFO, "Sent %d ACKs\n", handle->acks_sent); 1350 while (NULL != ch)
1356 LOG (GNUNET_ERROR_TYPE_INFO, "Recv %d ACKs\n\n", handle->acks_recv);
1357#endif
1358
1359 t = handle->tunnels_head;
1360 while (NULL != t)
1361 { 1351 {
1362 aux = t->next; 1352 aux = ch->next;
1363 if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 1353 if (ch->chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
1364 { 1354 {
1365 GNUNET_break (0); 1355 GNUNET_break (0);
1366 LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X not destroyed\n", t->tid); 1356 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", ch->chid);
1367 } 1357 }
1368 destroy_tunnel (t, GNUNET_YES); 1358 destroy_channel (ch, GNUNET_YES);
1369 t = aux; 1359 ch = aux;
1370 } 1360 }
1371 while ( (th = handle->th_head) != NULL) 1361 while ( (th = handle->th_head) != NULL)
1372 { 1362 {
@@ -1380,9 +1370,9 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1380 switch (ntohs(msg->type)) 1370 switch (ntohs(msg->type))
1381 { 1371 {
1382 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT: 1372 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT:
1383 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY: 1373 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_DESTROY:
1384 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS: 1374 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
1385 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL: 1375 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
1386 break; 1376 break;
1387 default: 1377 default:
1388 GNUNET_break (0); 1378 GNUNET_break (0);
@@ -1414,40 +1404,40 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1414 1404
1415 1405
1416/** 1406/**
1417 * Create a new tunnel (we're initiator and will be allowed to add/remove peers 1407 * Create a new channel (we're initiator and will be allowed to add/remove peers
1418 * and to broadcast). 1408 * and to broadcast).
1419 * 1409 *
1420 * @param h mesh handle 1410 * @param h mesh handle
1421 * @param tunnel_ctx client's tunnel context to associate with the tunnel 1411 * @param channel_ctx client's channel context to associate with the channel
1422 * @param peer peer identity the tunnel should go to 1412 * @param peer peer identity the channel should go to
1423 * @param port Port number. 1413 * @param port Port number.
1424 * @param nobuffer Flag for disabling buffering on relay nodes. 1414 * @param nobuffer Flag for disabling buffering on relay nodes.
1425 * @param reliable Flag for end-to-end reliability. 1415 * @param reliable Flag for end-to-end reliability.
1426 * 1416 *
1427 * @return handle to the tunnel 1417 * @return handle to the channel
1428 */ 1418 */
1429struct GNUNET_MESH_Tunnel * 1419struct GNUNET_MESH_Channel *
1430GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 1420GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
1431 void *tunnel_ctx, 1421 void *channel_ctx,
1432 const struct GNUNET_PeerIdentity *peer, 1422 const struct GNUNET_PeerIdentity *peer,
1433 uint32_t port, 1423 uint32_t port,
1434 int nobuffer, 1424 int nobuffer,
1435 int reliable) 1425 int reliable)
1436{ 1426{
1437 struct GNUNET_MESH_Tunnel *t; 1427 struct GNUNET_MESH_Channel *ch;
1438 struct GNUNET_MESH_TunnelMessage msg; 1428 struct GNUNET_MESH_ChannelMessage msg;
1439 1429
1440 LOG (GNUNET_ERROR_TYPE_DEBUG, 1430 LOG (GNUNET_ERROR_TYPE_DEBUG,
1441 "Creating new tunnel to %s:%u\n", 1431 "Creating new channel to %s:%u\n",
1442 GNUNET_i2s (peer), port); 1432 GNUNET_i2s (peer), port);
1443 t = create_tunnel (h, 0); 1433 ch = create_channel (h, 0);
1444 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", t); 1434 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch);
1445 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", t->tid); 1435 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", ch->chid);
1446 t->ctx = tunnel_ctx; 1436 ch->ctx = channel_ctx;
1447 t->peer = GNUNET_PEER_intern (peer); 1437 ch->peer = GNUNET_PEER_intern (peer);
1448 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); 1438 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_CREATE);
1449 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1439 msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage));
1450 msg.tunnel_id = htonl (t->tid); 1440 msg.channel_id = htonl (ch->chid);
1451 msg.port = htonl (port); 1441 msg.port = htonl (port);
1452 msg.peer = *peer; 1442 msg.peer = *peer;
1453 msg.opt = 0; 1443 msg.opt = 0;
@@ -1456,25 +1446,25 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
1456 if (GNUNET_YES == nobuffer) 1446 if (GNUNET_YES == nobuffer)
1457 msg.opt |= GNUNET_MESH_OPTION_NOBUFFER; 1447 msg.opt |= GNUNET_MESH_OPTION_NOBUFFER;
1458 msg.opt = htonl (msg.opt); 1448 msg.opt = htonl (msg.opt);
1459 t->allow_send = 0; 1449 ch->allow_send = 0;
1460 send_packet (h, &msg.header, t); 1450 send_packet (h, &msg.header, ch);
1461 return t; 1451 return ch;
1462} 1452}
1463 1453
1464 1454
1465void 1455void
1466GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel) 1456GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel)
1467{ 1457{
1468 struct GNUNET_MESH_Handle *h; 1458 struct GNUNET_MESH_Handle *h;
1469 struct GNUNET_MESH_TunnelMessage msg; 1459 struct GNUNET_MESH_ChannelMessage msg;
1470 struct GNUNET_MESH_TransmitHandle *th; 1460 struct GNUNET_MESH_TransmitHandle *th;
1471 1461
1472 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel\n"); 1462 LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel\n");
1473 h = tunnel->mesh; 1463 h = channel->mesh;
1474 1464
1475 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); 1465 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CHANNEL_DESTROY);
1476 msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); 1466 msg.header.size = htons (sizeof (struct GNUNET_MESH_ChannelMessage));
1477 msg.tunnel_id = htonl (tunnel->tid); 1467 msg.channel_id = htonl (channel->chid);
1478 memset (&msg.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 1468 memset (&msg.peer, 0, sizeof (struct GNUNET_PeerIdentity));
1479 msg.port = 0; 1469 msg.port = 0;
1480 msg.opt = 0; 1470 msg.opt = 0;
@@ -1482,7 +1472,7 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
1482 while (th != NULL) 1472 while (th != NULL)
1483 { 1473 {
1484 struct GNUNET_MESH_TransmitHandle *aux; 1474 struct GNUNET_MESH_TransmitHandle *aux;
1485 if (th->tunnel == tunnel) 1475 if (th->channel == channel)
1486 { 1476 {
1487 aux = th->next; 1477 aux = th->next;
1488 /* FIXME call the handler? */ 1478 /* FIXME call the handler? */
@@ -1496,39 +1486,39 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
1496 th = th->next; 1486 th = th->next;
1497 } 1487 }
1498 1488
1499 destroy_tunnel (tunnel, GNUNET_YES); 1489 destroy_channel (channel, GNUNET_YES);
1500 send_packet (h, &msg.header, NULL); 1490 send_packet (h, &msg.header, NULL);
1501} 1491}
1502 1492
1503 1493
1504/** 1494/**
1505 * Get information about a tunnel. 1495 * Get information about a channel.
1506 * 1496 *
1507 * @param tunnel Tunnel handle. 1497 * @param channel Channel handle.
1508 * @param option Query (GNUNET_MESH_OPTION_*). 1498 * @param option Query (GNUNET_MESH_OPTION_*).
1509 * @param ... dependant on option, currently not used 1499 * @param ... dependant on option, currently not used
1510 * 1500 *
1511 * @return Union with an answer to the query. 1501 * @return Union with an answer to the query.
1512 */ 1502 */
1513const union MeshTunnelInfo * 1503const union MeshChannelInfo *
1514GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel, 1504GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel,
1515 enum MeshTunnelOption option, ...) 1505 enum MeshChannelOption option, ...)
1516{ 1506{
1517 const union MeshTunnelInfo *ret; 1507 const union MeshChannelInfo *ret;
1518 1508
1519 switch (option) 1509 switch (option)
1520 { 1510 {
1521 case GNUNET_MESH_OPTION_NOBUFFER: 1511 case GNUNET_MESH_OPTION_NOBUFFER:
1522 ret = (const union MeshTunnelInfo *) &tunnel->nobuffer; 1512 ret = (const union MeshChannelInfo *) &channel->nobuffer;
1523 break; 1513 break;
1524 case GNUNET_MESH_OPTION_RELIABLE: 1514 case GNUNET_MESH_OPTION_RELIABLE:
1525 ret = (const union MeshTunnelInfo *) &tunnel->reliable; 1515 ret = (const union MeshChannelInfo *) &channel->reliable;
1526 break; 1516 break;
1527 case GNUNET_MESH_OPTION_OOORDER: 1517 case GNUNET_MESH_OPTION_OOORDER:
1528 ret = (const union MeshTunnelInfo *) &tunnel->ooorder; 1518 ret = (const union MeshChannelInfo *) &channel->ooorder;
1529 break; 1519 break;
1530 case GNUNET_MESH_OPTION_PEER: 1520 case GNUNET_MESH_OPTION_PEER:
1531 ret = (const union MeshTunnelInfo *) &tunnel->peer; 1521 ret = (const union MeshChannelInfo *) &channel->peer;
1532 break; 1522 break;
1533 default: 1523 default:
1534 GNUNET_break (0); 1524 GNUNET_break (0);
@@ -1539,7 +1529,7 @@ GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel,
1539} 1529}
1540 1530
1541struct GNUNET_MESH_TransmitHandle * 1531struct GNUNET_MESH_TransmitHandle *
1542GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, 1532GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Channel *channel, int cork,
1543 struct GNUNET_TIME_Relative maxdelay, 1533 struct GNUNET_TIME_Relative maxdelay,
1544 size_t notify_size, 1534 size_t notify_size,
1545 GNUNET_CONNECTION_TransmitReadyNotify notify, 1535 GNUNET_CONNECTION_TransmitReadyNotify notify,
@@ -1547,36 +1537,36 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
1547{ 1537{
1548 struct GNUNET_MESH_TransmitHandle *th; 1538 struct GNUNET_MESH_TransmitHandle *th;
1549 1539
1550 GNUNET_assert (NULL != tunnel); 1540 GNUNET_assert (NULL != channel);
1551 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n"); 1541 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n");
1552 LOG (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", tunnel->tid); 1542 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid);
1553 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", tunnel->allow_send); 1543 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send);
1554 if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 1544 if (channel->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
1555 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); 1545 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n");
1556 else 1546 else
1557 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); 1547 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n");
1558 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size); 1548 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size);
1559 GNUNET_assert (NULL != notify); 1549 GNUNET_assert (NULL != notify);
1560 GNUNET_assert (0 == tunnel->packet_size); // Only one data packet allowed 1550 GNUNET_assert (0 == channel->packet_size); // Only one data packet allowed
1561 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle)); 1551 th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
1562 th->tunnel = tunnel; 1552 th->channel = channel;
1563 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay); 1553 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
1564 th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData); 1554 th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData);
1565 tunnel->packet_size = th->size; 1555 channel->packet_size = th->size;
1566 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size); 1556 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size %u\n", th->size);
1567 th->notify = notify; 1557 th->notify = notify;
1568 th->notify_cls = notify_cls; 1558 th->notify_cls = notify_cls;
1569 add_to_queue (tunnel->mesh, th); 1559 add_to_queue (channel->mesh, th);
1570 if (NULL != tunnel->mesh->th) 1560 if (NULL != channel->mesh->th)
1571 return th; 1561 return th;
1572 if (GNUNET_NO == tunnel->allow_send) 1562 if (GNUNET_NO == channel->allow_send)
1573 return th; 1563 return th;
1574 LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n"); 1564 LOG (GNUNET_ERROR_TYPE_DEBUG, " call client notify tmt rdy\n");
1575 tunnel->mesh->th = 1565 channel->mesh->th =
1576 GNUNET_CLIENT_notify_transmit_ready (tunnel->mesh->client, th->size, 1566 GNUNET_CLIENT_notify_transmit_ready (channel->mesh->client, th->size,
1577 GNUNET_TIME_UNIT_FOREVER_REL, 1567 GNUNET_TIME_UNIT_FOREVER_REL,
1578 GNUNET_YES, &send_callback, 1568 GNUNET_YES, &send_callback,
1579 tunnel->mesh); 1569 channel->mesh);
1580 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY END\n"); 1570 LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY END\n");
1581 return th; 1571 return th;
1582} 1572}
@@ -1587,8 +1577,8 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
1587{ 1577{
1588 struct GNUNET_MESH_Handle *mesh; 1578 struct GNUNET_MESH_Handle *mesh;
1589 1579
1590 th->tunnel->packet_size = 0; 1580 th->channel->packet_size = 0;
1591 mesh = th->tunnel->mesh; 1581 mesh = th->channel->mesh;
1592 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1582 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1593 GNUNET_SCHEDULER_cancel (th->timeout_task); 1583 GNUNET_SCHEDULER_cancel (th->timeout_task);
1594 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); 1584 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th);
@@ -1602,16 +1592,16 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
1602} 1592}
1603 1593
1604void 1594void
1605GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel) 1595GNUNET_MESH_receive_done (struct GNUNET_MESH_Channel *channel)
1606{ 1596{
1607 send_ack (tunnel); 1597 send_ack (channel);
1608} 1598}
1609 1599
1610 1600
1611/** 1601/**
1612 * Request information about the running mesh peer. 1602 * Request information about the running mesh peer.
1613 * The callback will be called for every tunnel known to the service, 1603 * The callback will be called for every channel known to the service,
1614 * listing all active peers that blong to the tunnel. 1604 * listing all active peers that blong to the channel.
1615 * 1605 *
1616 * If called again on the same handle, it will overwrite the previous 1606 * If called again on the same handle, it will overwrite the previous
1617 * callback and cls. To retrieve the cls, monitor_cancel must be 1607 * callback and cls. To retrieve the cls, monitor_cancel must be
@@ -1624,17 +1614,17 @@ GNUNET_MESH_receive_done (struct GNUNET_MESH_Tunnel *tunnel)
1624 * @param callback_cls Closure for @c callback. 1614 * @param callback_cls Closure for @c callback.
1625 */ 1615 */
1626void 1616void
1627GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, 1617GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
1628 GNUNET_MESH_TunnelsCB callback, 1618 GNUNET_MESH_ChannelsCB callback,
1629 void *callback_cls) 1619 void *callback_cls)
1630{ 1620{
1631 struct GNUNET_MessageHeader msg; 1621 struct GNUNET_MessageHeader msg;
1632 1622
1633 msg.size = htons (sizeof (msg)); 1623 msg.size = htons (sizeof (msg));
1634 msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); 1624 msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS);
1635 send_packet (h, &msg, NULL); 1625 send_packet (h, &msg, NULL);
1636 h->tunnels_cb = callback; 1626 h->channels_cb = callback;
1637 h->tunnels_cls = callback_cls; 1627 h->channels_cls = callback_cls;
1638 1628
1639 return; 1629 return;
1640} 1630}
@@ -1648,46 +1638,46 @@ GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
1648 * @return Closure given to GNUNET_MESH_monitor, if any. 1638 * @return Closure given to GNUNET_MESH_monitor, if any.
1649 */ 1639 */
1650void * 1640void *
1651GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h) 1641GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h)
1652{ 1642{
1653 void *cls; 1643 void *cls;
1654 1644
1655 cls = h->tunnels_cls; 1645 cls = h->channels_cls;
1656 h->tunnels_cb = NULL; 1646 h->channels_cb = NULL;
1657 h->tunnels_cls = NULL; 1647 h->channels_cls = NULL;
1658 return cls; 1648 return cls;
1659} 1649}
1660 1650
1661 1651
1662/** 1652/**
1663 * Request information about a specific tunnel of the running mesh peer. 1653 * Request information about a specific channel of the running mesh peer.
1664 * 1654 *
1665 * WARNING: unstable API, likely to change in the future! 1655 * WARNING: unstable API, likely to change in the future!
1666 * FIXME Add destination option. 1656 * FIXME Add destination option.
1667 * 1657 *
1668 * @param h Handle to the mesh peer. 1658 * @param h Handle to the mesh peer.
1669 * @param initiator ID of the owner of the tunnel. 1659 * @param initiator ID of the owner of the channel.
1670 * @param tunnel_number Tunnel number. 1660 * @param channel_number Channel number.
1671 * @param callback Function to call with the requested data. 1661 * @param callback Function to call with the requested data.
1672 * @param callback_cls Closure for @c callback. 1662 * @param callback_cls Closure for @c callback.
1673 */ 1663 */
1674void 1664void
1675GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, 1665GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
1676 struct GNUNET_PeerIdentity *initiator, 1666 struct GNUNET_PeerIdentity *initiator,
1677 unsigned int tunnel_number, 1667 unsigned int channel_number,
1678 GNUNET_MESH_TunnelCB callback, 1668 GNUNET_MESH_ChannelCB callback,
1679 void *callback_cls) 1669 void *callback_cls)
1680{ 1670{
1681 struct GNUNET_MESH_LocalMonitor msg; 1671 struct GNUNET_MESH_LocalMonitor msg;
1682 1672
1683 msg.header.size = htons (sizeof (msg)); 1673 msg.header.size = htons (sizeof (msg));
1684 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); 1674 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
1685 msg.owner = *initiator; 1675 msg.owner = *initiator;
1686 msg.tunnel_id = htonl (tunnel_number); 1676 msg.channel_id = htonl (channel_number);
1687 msg.reserved = 0; 1677 msg.reserved = 0;
1688 send_packet (h, &msg.header, NULL); 1678 send_packet (h, &msg.header, NULL);
1689 h->tunnel_cb = callback; 1679 h->channel_cb = callback;
1690 h->tunnel_cls = callback_cls; 1680 h->channel_cls = callback_cls;
1691 1681
1692 return; 1682 return;
1693} 1683}
@@ -1744,7 +1734,7 @@ mesh_mq_send_impl (struct GNUNET_MQ_Handle *mq,
1744 GNUNET_assert (NULL == state->th); 1734 GNUNET_assert (NULL == state->th);
1745 GNUNET_MQ_impl_send_commit (mq); 1735 GNUNET_MQ_impl_send_commit (mq);
1746 state->th = 1736 state->th =
1747 GNUNET_MESH_notify_transmit_ready (state->tunnel, 1737 GNUNET_MESH_notify_transmit_ready (state->channel,
1748 /* FIXME: add option for corking */ 1738 /* FIXME: add option for corking */
1749 GNUNET_NO, 1739 GNUNET_NO,
1750 GNUNET_TIME_UNIT_FOREVER_REL, 1740 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -1776,21 +1766,21 @@ mesh_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
1776 1766
1777 1767
1778/** 1768/**
1779 * Create a message queue for a mesh tunnel. 1769 * Create a message queue for a mesh channel.
1780 * The message queue can only be used to transmit messages, 1770 * The message queue can only be used to transmit messages,
1781 * not to receive them. 1771 * not to receive them.
1782 * 1772 *
1783 * @param tunnel the tunnel to create the message qeue for 1773 * @param channel the channel to create the message qeue for
1784 * @return a message queue to messages over the tunnel 1774 * @return a message queue to messages over the channel
1785 */ 1775 */
1786struct GNUNET_MQ_Handle * 1776struct GNUNET_MQ_Handle *
1787GNUNET_MESH_mq_create (struct GNUNET_MESH_Tunnel *tunnel) 1777GNUNET_MESH_mq_create (struct GNUNET_MESH_Channel *channel)
1788{ 1778{
1789 struct GNUNET_MQ_Handle *mq; 1779 struct GNUNET_MQ_Handle *mq;
1790 struct MeshMQState *state; 1780 struct MeshMQState *state;
1791 1781
1792 state = GNUNET_new (struct MeshMQState); 1782 state = GNUNET_new (struct MeshMQState);
1793 state->tunnel = tunnel; 1783 state->channel = channel;
1794 1784
1795 mq = GNUNET_MQ_queue_for_callbacks (mesh_mq_send_impl, 1785 mq = GNUNET_MQ_queue_for_callbacks (mesh_mq_send_impl,
1796 mesh_mq_destroy_impl, 1786 mesh_mq_destroy_impl,