aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cadet/cadet.h21
-rw-r--r--src/cadet/cadet_api.c109
-rw-r--r--src/cadet/cadet_protocol.h12
-rw-r--r--src/cadet/gnunet-service-cadet-new.c335
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c80
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c64
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c38
-rw-r--r--src/cadet/gnunet-service-cadet_local.c126
-rw-r--r--src/cadet/gnunet-service-cadet_local.h14
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c56
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.h6
11 files changed, 417 insertions, 444 deletions
diff --git a/src/cadet/cadet.h b/src/cadet/cadet.h
index a8cd6831a..97372cb80 100644
--- a/src/cadet/cadet.h
+++ b/src/cadet/cadet.h
@@ -147,7 +147,7 @@ struct GNUNET_CADET_LocalChannelCreateMessage
147 /** 147 /**
148 * ID of a channel controlled by this client. 148 * ID of a channel controlled by this client.
149 */ 149 */
150 struct GNUNET_CADET_ClientChannelNumber channel_id; 150 struct GNUNET_CADET_ClientChannelNumber ccn;
151 151
152 /** 152 /**
153 * Channel's peer 153 * Channel's peer
@@ -179,7 +179,7 @@ struct GNUNET_CADET_LocalChannelDestroyMessage
179 /** 179 /**
180 * ID of a channel controlled by this client. 180 * ID of a channel controlled by this client.
181 */ 181 */
182 struct GNUNET_CADET_ClientChannelNumber channel_id; 182 struct GNUNET_CADET_ClientChannelNumber ccn;
183}; 183};
184 184
185 185
@@ -196,7 +196,7 @@ struct GNUNET_CADET_LocalData
196 /** 196 /**
197 * ID of the channel 197 * ID of the channel
198 */ 198 */
199 struct GNUNET_CADET_ClientChannelNumber channel_id; 199 struct GNUNET_CADET_ClientChannelNumber ccn;
200 200
201 /** 201 /**
202 * Payload follows 202 * Payload follows
@@ -218,13 +218,15 @@ struct GNUNET_CADET_LocalAck
218 /** 218 /**
219 * ID of the channel allowed to send more data. 219 * ID of the channel allowed to send more data.
220 */ 220 */
221 struct GNUNET_CADET_ClientChannelNumber channel_id; 221 struct GNUNET_CADET_ClientChannelNumber ccn;
222 222
223}; 223};
224 224
225 225
226/** 226/**
227 * Message to inform the client about channels in the service. 227 * Message to inform the client about channels in the service.
228 *
229 * TODO: split into two messages!
228 */ 230 */
229struct GNUNET_CADET_LocalInfo 231struct GNUNET_CADET_LocalInfo
230{ 232{
@@ -237,12 +239,7 @@ struct GNUNET_CADET_LocalInfo
237 /** 239 /**
238 * ID of the channel allowed to send more data. 240 * ID of the channel allowed to send more data.
239 */ 241 */
240 struct GNUNET_CADET_ClientChannelNumber channel_id; 242 struct GNUNET_CADET_ClientChannelNumber ccn;
241
242 /**
243 * ID of the owner of the channel (can be local peer).
244 */
245// struct GNUNET_PeerIdentity owner;
246 243
247 /** 244 /**
248 * ID of the destination of the channel (can be local peer). 245 * ID of the destination of the channel (can be local peer).
@@ -253,6 +250,8 @@ struct GNUNET_CADET_LocalInfo
253 250
254/** 251/**
255 * Message to inform the client about one of the peers in the service. 252 * Message to inform the client about one of the peers in the service.
253 *
254 * TODO: split into two messages!
256 */ 255 */
257struct GNUNET_CADET_LocalInfoPeer 256struct GNUNET_CADET_LocalInfoPeer
258{ 257{
@@ -284,6 +283,8 @@ struct GNUNET_CADET_LocalInfoPeer
284 283
285/** 284/**
286 * Message to inform the client about one of the tunnels in the service. 285 * Message to inform the client about one of the tunnels in the service.
286 *
287 * TODO: split into two messages!
287 */ 288 */
288struct GNUNET_CADET_LocalInfoTunnel 289struct GNUNET_CADET_LocalInfoTunnel
289{ 290{
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 494aab612..83ff2b3b7 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -169,7 +169,7 @@ struct GNUNET_CADET_Handle
169 /** 169 /**
170 * child of the next channel to create (to avoid reusing IDs often) 170 * child of the next channel to create (to avoid reusing IDs often)
171 */ 171 */
172 struct GNUNET_CADET_ClientChannelNumber next_chid; 172 struct GNUNET_CADET_ClientChannelNumber next_ccn;
173 173
174 /** 174 /**
175 * Configuration given by the client, in case of reconnection 175 * Configuration given by the client, in case of reconnection
@@ -238,7 +238,7 @@ struct GNUNET_CADET_Channel
238 /** 238 /**
239 * Local ID of the channel 239 * Local ID of the channel
240 */ 240 */
241 struct GNUNET_CADET_ClientChannelNumber chid; 241 struct GNUNET_CADET_ClientChannelNumber ccn;
242 242
243 /** 243 /**
244 * Channel's port, if any. 244 * Channel's port, if any.
@@ -361,17 +361,17 @@ find_port (const struct GNUNET_CADET_Handle *h,
361 * Get the channel handler for the channel specified by id from the given handle 361 * Get the channel handler for the channel specified by id from the given handle
362 * 362 *
363 * @param h Cadet handle 363 * @param h Cadet handle
364 * @param chid ID of the wanted channel 364 * @param ccn ID of the wanted channel
365 * @return handle to the required channel or NULL if not found 365 * @return handle to the required channel or NULL if not found
366 */ 366 */
367static struct GNUNET_CADET_Channel * 367static struct GNUNET_CADET_Channel *
368retrieve_channel (struct GNUNET_CADET_Handle *h, 368retrieve_channel (struct GNUNET_CADET_Handle *h,
369 struct GNUNET_CADET_ClientChannelNumber chid) 369 struct GNUNET_CADET_ClientChannelNumber ccn)
370{ 370{
371 struct GNUNET_CADET_Channel *ch; 371 struct GNUNET_CADET_Channel *ch;
372 372
373 for (ch = h->channels_head; NULL != ch; ch = ch->next) 373 for (ch = h->channels_head; NULL != ch; ch = ch->next)
374 if (ch->chid.channel_of_client == chid.channel_of_client) 374 if (ch->ccn.channel_of_client == ccn.channel_of_client)
375 return ch; 375 return ch;
376 return NULL; 376 return NULL;
377} 377}
@@ -381,13 +381,13 @@ retrieve_channel (struct GNUNET_CADET_Handle *h,
381 * Create a new channel and insert it in the channel list of the cadet handle 381 * Create a new channel and insert it in the channel list of the cadet handle
382 * 382 *
383 * @param h Cadet handle 383 * @param h Cadet handle
384 * @param chid Desired chid of the channel, 0 to assign one automatically. 384 * @param ccn Desired ccn of the channel, 0 to assign one automatically.
385 * 385 *
386 * @return Handle to the created channel. 386 * @return Handle to the created channel.
387 */ 387 */
388static struct GNUNET_CADET_Channel * 388static struct GNUNET_CADET_Channel *
389create_channel (struct GNUNET_CADET_Handle *h, 389create_channel (struct GNUNET_CADET_Handle *h,
390 struct GNUNET_CADET_ClientChannelNumber chid) 390 struct GNUNET_CADET_ClientChannelNumber ccn)
391{ 391{
392 struct GNUNET_CADET_Channel *ch; 392 struct GNUNET_CADET_Channel *ch;
393 393
@@ -396,22 +396,22 @@ create_channel (struct GNUNET_CADET_Handle *h,
396 h->channels_tail, 396 h->channels_tail,
397 ch); 397 ch);
398 ch->cadet = h; 398 ch->cadet = h;
399 if (0 == chid.channel_of_client) 399 if (0 == ccn.channel_of_client)
400 { 400 {
401 ch->chid = h->next_chid; 401 ch->ccn = h->next_ccn;
402 while (NULL != retrieve_channel (h, 402 while (NULL != retrieve_channel (h,
403 h->next_chid)) 403 h->next_ccn))
404 { 404 {
405 h->next_chid.channel_of_client 405 h->next_ccn.channel_of_client
406 = htonl (1 + ntohl (h->next_chid.channel_of_client)); 406 = htonl (1 + ntohl (h->next_ccn.channel_of_client));
407 if (0 == ntohl (h->next_chid.channel_of_client)) 407 if (0 == ntohl (h->next_ccn.channel_of_client))
408 h->next_chid.channel_of_client 408 h->next_ccn.channel_of_client
409 = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 409 = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
410 } 410 }
411 } 411 }
412 else 412 else
413 { 413 {
414 ch->chid = chid; 414 ch->ccn = ccn;
415 } 415 }
416 ch->allow_send = GNUNET_NO; 416 ch->allow_send = GNUNET_NO;
417 return ch; 417 return ch;
@@ -438,7 +438,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner)
438 struct GNUNET_CADET_TransmitHandle *th; 438 struct GNUNET_CADET_TransmitHandle *th;
439 struct GNUNET_CADET_TransmitHandle *next; 439 struct GNUNET_CADET_TransmitHandle *next;
440 440
441 LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy_channel %X\n", ch->chid); 441 LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy_channel %X\n", ch->ccn);
442 442
443 if (NULL == ch) 443 if (NULL == ch)
444 { 444 {
@@ -530,8 +530,8 @@ send_ack (struct GNUNET_CADET_Channel *ch)
530 530
531 LOG (GNUNET_ERROR_TYPE_DEBUG, 531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "Sending ACK on channel %X\n", 532 "Sending ACK on channel %X\n",
533 ch->chid.channel_of_client); 533 ch->ccn.channel_of_client);
534 msg->channel_id = ch->chid; 534 msg->ccn = ch->ccn;
535 GNUNET_MQ_send (ch->cadet->mq, 535 GNUNET_MQ_send (ch->cadet->mq,
536 env); 536 env);
537} 537}
@@ -569,7 +569,7 @@ request_data (void *cls)
569 env = GNUNET_MQ_msg_extra (msg, 569 env = GNUNET_MQ_msg_extra (msg,
570 th->size, 570 th->size,
571 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 571 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
572 msg->channel_id = th->channel->chid; 572 msg->ccn = th->channel->ccn;
573 osize = th->notify (th->notify_cls, 573 osize = th->notify (th->notify_cls,
574 th->size, 574 th->size,
575 &msg[1]); 575 &msg[1]);
@@ -594,15 +594,15 @@ handle_channel_created (void *cls,
594 struct GNUNET_CADET_Channel *ch; 594 struct GNUNET_CADET_Channel *ch;
595 struct GNUNET_CADET_Port *port; 595 struct GNUNET_CADET_Port *port;
596 const struct GNUNET_HashCode *port_number; 596 const struct GNUNET_HashCode *port_number;
597 struct GNUNET_CADET_ClientChannelNumber chid; 597 struct GNUNET_CADET_ClientChannelNumber ccn;
598 598
599 chid = msg->channel_id; 599 ccn = msg->ccn;
600 port_number = &msg->port; 600 port_number = &msg->port;
601 LOG (GNUNET_ERROR_TYPE_DEBUG, 601 LOG (GNUNET_ERROR_TYPE_DEBUG,
602 "Creating incoming channel %X [%s]\n", 602 "Creating incoming channel %X [%s]\n",
603 ntohl (chid.channel_of_client), 603 ntohl (ccn.channel_of_client),
604 GNUNET_h2s (port_number)); 604 GNUNET_h2s (port_number));
605 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 605 if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
606 { 606 {
607 GNUNET_break (0); 607 GNUNET_break (0);
608 return; 608 return;
@@ -612,11 +612,11 @@ handle_channel_created (void *cls,
612 { 612 {
613 void *ctx; 613 void *ctx;
614 614
615 ch = create_channel (h, chid); 615 ch = create_channel (h, ccn);
616 ch->allow_send = GNUNET_NO; 616 ch->allow_send = GNUNET_NO;
617 ch->peer = GNUNET_PEER_intern (&msg->peer); 617 ch->peer = GNUNET_PEER_intern (&msg->peer);
618 ch->cadet = h; 618 ch->cadet = h;
619 ch->chid = chid; 619 ch->ccn = ccn;
620 ch->port = port; 620 ch->port = port;
621 ch->options = ntohl (msg->opt); 621 ch->options = ntohl (msg->opt);
622 622
@@ -634,7 +634,7 @@ handle_channel_created (void *cls,
634 LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n"); 634 LOG (GNUNET_ERROR_TYPE_DEBUG, "No handler for incoming channels\n");
635 env = GNUNET_MQ_msg (d_msg, 635 env = GNUNET_MQ_msg (d_msg,
636 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 636 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
637 d_msg->channel_id = msg->channel_id; 637 d_msg->ccn = msg->ccn;
638 GNUNET_MQ_send (h->mq, env); 638 GNUNET_MQ_send (h->mq, env);
639 } 639 }
640 return; 640 return;
@@ -653,20 +653,20 @@ handle_channel_destroy (void *cls,
653{ 653{
654 struct GNUNET_CADET_Handle *h = cls; 654 struct GNUNET_CADET_Handle *h = cls;
655 struct GNUNET_CADET_Channel *ch; 655 struct GNUNET_CADET_Channel *ch;
656 struct GNUNET_CADET_ClientChannelNumber chid; 656 struct GNUNET_CADET_ClientChannelNumber ccn;
657 657
658 chid = msg->channel_id; 658 ccn = msg->ccn;
659 LOG (GNUNET_ERROR_TYPE_DEBUG, 659 LOG (GNUNET_ERROR_TYPE_DEBUG,
660 "Channel %X Destroy from service\n", 660 "Channel %X Destroy from service\n",
661 ntohl (chid.channel_of_client)); 661 ntohl (ccn.channel_of_client));
662 ch = retrieve_channel (h, 662 ch = retrieve_channel (h,
663 chid); 663 ccn);
664 664
665 if (NULL == ch) 665 if (NULL == ch)
666 { 666 {
667 LOG (GNUNET_ERROR_TYPE_DEBUG, 667 LOG (GNUNET_ERROR_TYPE_DEBUG,
668 "channel %X unknown\n", 668 "channel %X unknown\n",
669 ntohl (chid.channel_of_client)); 669 ntohl (ccn.channel_of_client));
670 return; 670 return;
671 } 671 }
672 destroy_channel (ch, 672 destroy_channel (ch,
@@ -698,7 +698,7 @@ check_local_data (void *cls,
698 } 698 }
699 699
700 ch = retrieve_channel (h, 700 ch = retrieve_channel (h,
701 message->channel_id); 701 message->ccn);
702 if (NULL == ch) 702 if (NULL == ch)
703 { 703 {
704 GNUNET_break_op (0); 704 GNUNET_break_op (0);
@@ -728,15 +728,16 @@ handle_local_data (void *cls,
728 728
729 LOG (GNUNET_ERROR_TYPE_DEBUG, 729 LOG (GNUNET_ERROR_TYPE_DEBUG,
730 "Got a data message!\n"); 730 "Got a data message!\n");
731 ch = retrieve_channel (h, message->channel_id); 731 ch = retrieve_channel (h,
732 message->ccn);
732 GNUNET_assert (NULL != ch); 733 GNUNET_assert (NULL != ch);
733 734
734 payload = (struct GNUNET_MessageHeader *) &message[1]; 735 payload = (struct GNUNET_MessageHeader *) &message[1];
735 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", 736 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
736 GC_f2s (ntohl (ch->chid.channel_of_client) >= 737 GC_f2s (ntohl (ch->ccn.channel_of_client) >=
737 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI), 738 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI),
738 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), 739 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)),
739 ntohl (message->channel_id.channel_of_client)); 740 ntohl (message->ccn.channel_of_client));
740 741
741 type = ntohs (payload->type); 742 type = ntohs (payload->type);
742 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type)); 743 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type));
@@ -778,21 +779,21 @@ handle_local_ack (void *cls,
778{ 779{
779 struct GNUNET_CADET_Handle *h = cls; 780 struct GNUNET_CADET_Handle *h = cls;
780 struct GNUNET_CADET_Channel *ch; 781 struct GNUNET_CADET_Channel *ch;
781 struct GNUNET_CADET_ClientChannelNumber chid; 782 struct GNUNET_CADET_ClientChannelNumber ccn;
782 783
783 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); 784 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
784 chid = message->channel_id; 785 ccn = message->ccn;
785 ch = retrieve_channel (h, chid); 786 ch = retrieve_channel (h, ccn);
786 if (NULL == ch) 787 if (NULL == ch)
787 { 788 {
788 LOG (GNUNET_ERROR_TYPE_DEBUG, 789 LOG (GNUNET_ERROR_TYPE_DEBUG,
789 "ACK on unknown channel %X\n", 790 "ACK on unknown channel %X\n",
790 ntohl (chid.channel_of_client)); 791 ntohl (ccn.channel_of_client));
791 return; 792 return;
792 } 793 }
793 LOG (GNUNET_ERROR_TYPE_DEBUG, 794 LOG (GNUNET_ERROR_TYPE_DEBUG,
794 " on channel %X!\n", 795 " on channel %X!\n",
795 ntohl (ch->chid.channel_of_client)); 796 ntohl (ch->ccn.channel_of_client));
796 ch->allow_send = GNUNET_YES; 797 ch->allow_send = GNUNET_YES;
797 if (0 < ch->packet_size) 798 if (0 < ch->packet_size)
798 { 799 {
@@ -1406,7 +1407,7 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1406 } 1407 }
1407 h->cls = cls; 1408 h->cls = cls;
1408 h->message_handlers = handlers; 1409 h->message_handlers = handlers;
1409 h->next_chid.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 1410 h->next_ccn.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1410 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 1411 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1411 h->reconnect_task = NULL; 1412 h->reconnect_task = NULL;
1412 1413
@@ -1432,12 +1433,12 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1432 while (NULL != ch) 1433 while (NULL != ch)
1433 { 1434 {
1434 aux = ch->next; 1435 aux = ch->next;
1435 if (ntohl (ch->chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1436 if (ntohl (ch->ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1436 { 1437 {
1437 GNUNET_break (0); 1438 GNUNET_break (0);
1438 LOG (GNUNET_ERROR_TYPE_DEBUG, 1439 LOG (GNUNET_ERROR_TYPE_DEBUG,
1439 "channel %X not destroyed\n", 1440 "channel %X not destroyed\n",
1440 ntohl (ch->chid.channel_of_client)); 1441 ntohl (ch->ccn.channel_of_client));
1441 } 1442 }
1442 destroy_channel (ch, 1443 destroy_channel (ch,
1443 GNUNET_YES); 1444 GNUNET_YES);
@@ -1566,7 +1567,6 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
1566 * @param peer peer identity the channel should go to 1567 * @param peer peer identity the channel should go to
1567 * @param port Port hash (port number). 1568 * @param port Port hash (port number).
1568 * @param options CadetOption flag field, with all desired option bits set to 1. 1569 * @param options CadetOption flag field, with all desired option bits set to 1.
1569 *
1570 * @return handle to the channel 1570 * @return handle to the channel
1571 */ 1571 */
1572struct GNUNET_CADET_Channel * 1572struct GNUNET_CADET_Channel *
@@ -1579,21 +1579,21 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1579 struct GNUNET_CADET_LocalChannelCreateMessage *msg; 1579 struct GNUNET_CADET_LocalChannelCreateMessage *msg;
1580 struct GNUNET_MQ_Envelope *env; 1580 struct GNUNET_MQ_Envelope *env;
1581 struct GNUNET_CADET_Channel *ch; 1581 struct GNUNET_CADET_Channel *ch;
1582 struct GNUNET_CADET_ClientChannelNumber chid; 1582 struct GNUNET_CADET_ClientChannelNumber ccn;
1583 1583
1584 LOG (GNUNET_ERROR_TYPE_DEBUG, 1584 LOG (GNUNET_ERROR_TYPE_DEBUG,
1585 "Creating new channel to %s:%u\n", 1585 "Creating new channel to %s:%u\n",
1586 GNUNET_i2s (peer), port); 1586 GNUNET_i2s (peer), port);
1587 chid.channel_of_client = htonl (0); 1587 ccn.channel_of_client = htonl (0);
1588 ch = create_channel (h, chid); 1588 ch = create_channel (h, ccn);
1589 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); 1589 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch);
1590 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", 1590 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n",
1591 ntohl (ch->chid.channel_of_client)); 1591 ntohl (ch->ccn.channel_of_client));
1592 ch->ctx = channel_ctx; 1592 ch->ctx = channel_ctx;
1593 ch->peer = GNUNET_PEER_intern (peer); 1593 ch->peer = GNUNET_PEER_intern (peer);
1594 1594
1595 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 1595 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
1596 msg->channel_id = ch->chid; 1596 msg->ccn = ch->ccn;
1597 msg->port = *port; 1597 msg->port = *port;
1598 msg->peer = *peer; 1598 msg->peer = *peer;
1599 msg->opt = htonl (options); 1599 msg->opt = htonl (options);
@@ -1639,8 +1639,9 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1639 1639
1640 env = GNUNET_MQ_msg (msg, 1640 env = GNUNET_MQ_msg (msg,
1641 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1641 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
1642 msg->channel_id = channel->chid; 1642 msg->ccn = channel->ccn;
1643 GNUNET_MQ_send (h->mq, env); 1643 GNUNET_MQ_send (h->mq,
1644 env);
1644 1645
1645 destroy_channel (channel, GNUNET_YES); 1646 destroy_channel (channel, GNUNET_YES);
1646} 1647}
@@ -1698,9 +1699,9 @@ GNUNET_CADET_notify_transmit_ready (struct GNUNET_CADET_Channel *channel,
1698 GNUNET_assert (NULL != channel); 1699 GNUNET_assert (NULL != channel);
1699 GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= notify_size); 1700 GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= notify_size);
1700 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n"); 1701 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n");
1701 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); 1702 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->ccn);
1702 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); 1703 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send);
1703 if (ntohl (channel->chid.channel_of_client) >= 1704 if (ntohl (channel->ccn.channel_of_client) >=
1704 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1705 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1705 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); 1706 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n");
1706 else 1707 else
@@ -1996,7 +1997,7 @@ GNUNET_CADET_show_channel (struct GNUNET_CADET_Handle *h,
1996 1997
1997 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL); 1998 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL);
1998 msg->peer = *initiator; 1999 msg->peer = *initiator;
1999 msg->channel_id.channel_of_client = htonl (channel_number); 2000 msg->ccn.channel_of_client = htonl (channel_number);
2000 GNUNET_MQ_send (h->mq, env); 2001 GNUNET_MQ_send (h->mq, env);
2001 2002
2002 h->info_cb.channel_cb = callback; 2003 h->info_cb.channel_cb = callback;
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 0c325fc5a..3a70758d9 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -385,7 +385,7 @@ struct GNUNET_CADET_ChannelOpenMessage
385 /** 385 /**
386 * ID of the channel within the tunnel. 386 * ID of the channel within the tunnel.
387 */ 387 */
388 struct GNUNET_CADET_ChannelTunnelNumber chid; 388 struct GNUNET_CADET_ChannelTunnelNumber ctn;
389}; 389};
390 390
391 391
@@ -410,7 +410,7 @@ struct GNUNET_CADET_ChannelManageMessage
410 /** 410 /**
411 * ID of the channel 411 * ID of the channel
412 */ 412 */
413 struct GNUNET_CADET_ChannelTunnelNumber chid; 413 struct GNUNET_CADET_ChannelTunnelNumber ctn;
414}; 414};
415 415
416 416
@@ -436,7 +436,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
436 /** 436 /**
437 * ID of the channel 437 * ID of the channel
438 */ 438 */
439 struct GNUNET_CADET_ChannelTunnelNumber chid; 439 struct GNUNET_CADET_ChannelTunnelNumber ctn;
440 440
441 /** 441 /**
442 * Payload follows 442 * Payload follows
@@ -457,7 +457,7 @@ struct GNUNET_CADET_ChannelDataAckMessage
457 /** 457 /**
458 * ID of the channel 458 * ID of the channel
459 */ 459 */
460 struct GNUNET_CADET_ChannelTunnelNumber chid; 460 struct GNUNET_CADET_ChannelTunnelNumber ctn;
461 461
462 /** 462 /**
463 * Bitfield of already-received newer messages 463 * Bitfield of already-received newer messages
@@ -506,7 +506,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
506 /** 506 /**
507 * ID of the channel 507 * ID of the channel
508 */ 508 */
509 struct GNUNET_CADET_ChannelTunnelNumber chid; 509 struct GNUNET_CADET_ChannelTunnelNumber ctn;
510 510
511 /** 511 /**
512 * Payload follows 512 * Payload follows
@@ -527,7 +527,7 @@ struct GNUNET_CADET_ChannelDataAckMessage
527 /** 527 /**
528 * ID of the channel 528 * ID of the channel
529 */ 529 */
530 struct GNUNET_CADET_ChannelTunnelNumber chid; 530 struct GNUNET_CADET_ChannelTunnelNumber ctn;
531 531
532 /** 532 /**
533 * Bitfield of already-received messages past @e mid. 533 * Bitfield of already-received messages past @e mid.
diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c
index a60ef647a..6ba0df69e 100644
--- a/src/cadet/gnunet-service-cadet-new.c
+++ b/src/cadet/gnunet-service-cadet-new.c
@@ -66,19 +66,10 @@ struct CadetClient
66 struct CadetClient *prev; 66 struct CadetClient *prev;
67 67
68 /** 68 /**
69 * Tunnels that belong to this client, indexed by local id 69 * Tunnels that belong to this client, indexed by local id,
70 * value is a `struct CadetChannel`.
70 */ 71 */
71 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels; 72 struct GNUNET_CONTAINER_MultiHashMap32 *channels;
72
73 /**
74 * Tunnels this client has accepted, indexed by incoming local id
75 */
76 struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels;
77
78 /**
79 * Channel ID for the next incoming channel.
80 */
81 struct GNUNET_CADET_ClientChannelNumber next_chid;
82 73
83 /** 74 /**
84 * Handle to communicate with the client 75 * Handle to communicate with the client
@@ -97,13 +88,13 @@ struct CadetClient
97 struct GNUNET_CONTAINER_MultiHashMap *ports; 88 struct GNUNET_CONTAINER_MultiHashMap *ports;
98 89
99 /** 90 /**
100 * Whether the client is active or shutting down (don't send confirmations 91 * Channel ID to use for the next incoming channel for this client.
101 * to a client that is shutting down). 92 * Wraps around (in theory).
102 */ 93 */
103 int shutting_down; 94 struct GNUNET_CADET_ClientChannelNumber next_ccn;
104 95
105 /** 96 /**
106 * ID of the client, mainly for debug messages 97 * ID of the client, mainly for debug messages. Purely internal to this file.
107 */ 98 */
108 unsigned int id; 99 unsigned int id;
109}; 100};
@@ -193,7 +184,6 @@ unsigned long long ratchet_messages;
193struct GNUNET_TIME_Relative ratchet_time; 184struct GNUNET_TIME_Relative ratchet_time;
194 185
195 186
196
197/** 187/**
198 * Send a message to a client. 188 * Send a message to a client.
199 * 189 *
@@ -220,8 +210,6 @@ GSC_2s (struct CadetClient *c)
220{ 210{
221 static char buf[32]; 211 static char buf[32];
222 212
223 if (NULL == c)
224 return "Client(NULL)";
225 GNUNET_snprintf (buf, 213 GNUNET_snprintf (buf,
226 sizeof (buf), 214 sizeof (buf),
227 "Client(%u)", 215 "Client(%u)",
@@ -231,20 +219,36 @@ GSC_2s (struct CadetClient *c)
231 219
232 220
233/** 221/**
222 * Lookup channel of client @a c by @a ccn.
223 *
224 * @param c client to look in
225 * @param ccn channel ID to look up
226 * @return NULL if no such channel exists
227 */
228static struct CadetChannel *
229lookup_channel (struct CadetClient *c,
230 struct GNUNET_CADET_ClientChannelNumber ccn)
231{
232 return GNUNET_CONTAINER_multihashmap32_get (c->channels,
233 ntohl (ccn.channel_of_client));
234}
235
236
237/**
234 * Obtain the next LID to use for incoming connections to 238 * Obtain the next LID to use for incoming connections to
235 * the given client. 239 * the given client.
236 * 240 *
237 * @param c client handle 241 * @param c client handle
238 */ 242 */
239static struct GNUNET_CADET_ClientChannelNumber 243static struct GNUNET_CADET_ClientChannelNumber
240client_get_next_lid (struct CadetClient *c) 244client_get_next_ccn (struct CadetClient *c)
241{ 245{
242 struct GNUNET_CADET_ClientChannelNumber ccn = c->next_chid; 246 struct GNUNET_CADET_ClientChannelNumber ccn = c->next_ccn;
243 247
244 /* increment until we have a free one... */ 248 /* increment until we have a free one... */
245 while (NULL != 249 while (NULL !=
246 GNUNET_CONTAINER_multihashmap32_get (c->incoming_channels, 250 lookup_channel (c,
247 ntohl (ccn.channel_of_client))) 251 ccn))
248 { 252 {
249 ccn.channel_of_client 253 ccn.channel_of_client
250 = htonl (1 + (ntohl (ccn.channel_of_client))); 254 = htonl (1 + (ntohl (ccn.channel_of_client)));
@@ -252,15 +256,16 @@ client_get_next_lid (struct CadetClient *c)
252 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 256 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
253 ccn.channel_of_client = htonl (0); 257 ccn.channel_of_client = htonl (0);
254 } 258 }
255 c->next_chid.channel_of_client 259 c->next_ccn.channel_of_client
256 = htonl (1 + (ntohl (ccn.channel_of_client))); 260 = htonl (1 + (ntohl (ccn.channel_of_client)));
257 return ccn; 261 return ccn;
258} 262}
259 263
260 264
261/** 265/**
262 * Bind incoming channel to this client, and notify client 266 * Bind incoming channel to this client, and notify client about
263 * about incoming connection. 267 * incoming connection. Caller is responsible for notifying the other
268 * peer about our acceptance of the channel.
264 * 269 *
265 * @param c client to bind to 270 * @param c client to bind to
266 * @param ch channel to be bound 271 * @param ch channel to be bound
@@ -278,32 +283,33 @@ GSC_bind (struct CadetClient *c,
278{ 283{
279 struct GNUNET_MQ_Envelope *env; 284 struct GNUNET_MQ_Envelope *env;
280 struct GNUNET_CADET_LocalChannelCreateMessage *msg; 285 struct GNUNET_CADET_LocalChannelCreateMessage *msg;
281 struct GNUNET_CADET_ClientChannelNumber lid; 286 struct GNUNET_CADET_ClientChannelNumber ccn;
282 287
283 lid = client_get_next_lid (c); 288 ccn = client_get_next_ccn (c);
284 GNUNET_assert (GNUNET_YES == 289 GNUNET_assert (GNUNET_YES ==
285 GNUNET_CONTAINER_multihashmap32_put (c->incoming_channels, 290 GNUNET_CONTAINER_multihashmap32_put (c->channels,
286 ntohl (lid.channel_of_client), 291 ntohl (ccn.channel_of_client),
287 ch, 292 ch,
288 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 293 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
289 294 LOG (GNUNET_ERROR_TYPE_DEBUG,
295 "Accepting incoming channel %s from %s on open port %s (%u)\n",
296 GCCH_2s (ch),
297 GCP_2s (dest),
298 GNUNET_h2s (port),
299 ntohl (options));
290 /* notify local client about incoming connection! */ 300 /* notify local client about incoming connection! */
291 env = GNUNET_MQ_msg (msg, 301 env = GNUNET_MQ_msg (msg,
292 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 302 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
293 msg->channel_id = lid; 303 msg->ccn = ccn;
294 msg->port = *port; 304 msg->port = *port;
295 msg->opt = htonl (options); 305 msg->opt = htonl (options);
296 msg->peer = *GCP_get_id (dest); 306 msg->peer = *GCP_get_id (dest);
297 GSC_send_to_client (c, 307 GSC_send_to_client (c,
298 env); 308 env);
299 return lid; 309 return ccn;
300} 310}
301 311
302 312
303/******************************************************************************/
304/************************ MAIN FUNCTIONS ****************************/
305/******************************************************************************/
306
307/** 313/**
308 * Task run during shutdown. 314 * Task run during shutdown.
309 * 315 *
@@ -313,7 +319,7 @@ static void
313shutdown_task (void *cls) 319shutdown_task (void *cls)
314{ 320{
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 "shutting down\n"); 322 "Shutting down\n");
317 shutting_down = GNUNET_YES; 323 shutting_down = GNUNET_YES;
318 GCO_shutdown (); 324 GCO_shutdown ();
319 if (NULL != stats) 325 if (NULL != stats)
@@ -384,7 +390,10 @@ bind_loose_channel (void *cls,
384 390
385 391
386/** 392/**
387 * Handler for port open requests. 393 * Handle port open request. Creates a mapping from the
394 * port to the respective client and checks whether we have
395 * loose channels trying to bind to the port. If so, those
396 * are bound.
388 * 397 *
389 * @param cls Identification of the client. 398 * @param cls Identification of the client.
390 * @param pmsg The actual message. 399 * @param pmsg The actual message.
@@ -396,9 +405,9 @@ handle_port_open (void *cls,
396 struct CadetClient *c = cls; 405 struct CadetClient *c = cls;
397 406
398 LOG (GNUNET_ERROR_TYPE_DEBUG, 407 LOG (GNUNET_ERROR_TYPE_DEBUG,
399 "Open port %s requested by client %u\n", 408 "Open port %s requested by client %s\n",
400 GNUNET_h2s (&pmsg->port), 409 GNUNET_h2s (&pmsg->port),
401 c->id); 410 GSC_2s (c));
402 if (NULL == c->ports) 411 if (NULL == c->ports)
403 c->ports = GNUNET_CONTAINER_multihashmap_create (4, 412 c->ports = GNUNET_CONTAINER_multihashmap_create (4,
404 GNUNET_NO); 413 GNUNET_NO);
@@ -412,13 +421,10 @@ handle_port_open (void *cls,
412 GNUNET_SERVICE_client_drop (c->client); 421 GNUNET_SERVICE_client_drop (c->client);
413 return; 422 return;
414 } 423 }
415 /* store in global hashmap */ 424 (void) GNUNET_CONTAINER_multihashmap_put (open_ports,
416 /* FIXME only allow one client to have the port open, 425 &pmsg->port,
417 * have a backup hashmap with waiting clients */ 426 c,
418 GNUNET_CONTAINER_multihashmap_put (open_ports, 427 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
419 &pmsg->port,
420 c,
421 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
422 GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels, 428 GNUNET_CONTAINER_multihashmap_get_multiple (loose_channels,
423 &pmsg->port, 429 &pmsg->port,
424 &bind_loose_channel, 430 &bind_loose_channel,
@@ -428,7 +434,10 @@ handle_port_open (void *cls,
428 434
429 435
430/** 436/**
431 * Handler for port close requests. 437 * Handler for port close requests. Marks this port as closed
438 * (unless of course we have another client with the same port
439 * open). Note that existing channels accepted on the port are
440 * not affected.
432 * 441 *
433 * @param cls Identification of the client. 442 * @param cls Identification of the client.
434 * @param pmsg The actual message. 443 * @param pmsg The actual message.
@@ -440,9 +449,9 @@ handle_port_close (void *cls,
440 struct CadetClient *c = cls; 449 struct CadetClient *c = cls;
441 450
442 LOG (GNUNET_ERROR_TYPE_DEBUG, 451 LOG (GNUNET_ERROR_TYPE_DEBUG,
443 "Open port %s requested by client %u\n", 452 "Closing port %s as requested by client %s\n",
444 GNUNET_h2s (&pmsg->port), 453 GNUNET_h2s (&pmsg->port),
445 c->id); 454 GSC_2s (c));
446 if (GNUNET_YES != 455 if (GNUNET_YES !=
447 GNUNET_CONTAINER_multihashmap_remove (c->ports, 456 GNUNET_CONTAINER_multihashmap_remove (c->ports,
448 &pmsg->port, 457 &pmsg->port,
@@ -456,36 +465,32 @@ handle_port_close (void *cls,
456 GNUNET_CONTAINER_multihashmap_remove (open_ports, 465 GNUNET_CONTAINER_multihashmap_remove (open_ports,
457 &pmsg->port, 466 &pmsg->port,
458 c)); 467 c));
459
460 GNUNET_SERVICE_client_continue (c->client); 468 GNUNET_SERVICE_client_continue (c->client);
461} 469}
462 470
463 471
464/** 472/**
465 * Handler for requests of new channels. 473 * Handler for requests for us creating a new channel to another peer and port.
466 * 474 *
467 * @param cls Identification of the client. 475 * @param cls Identification of the client.
468 * @param tcm The actual message. 476 * @param tcm The actual message.
469 */ 477 */
470static void 478static void
471handle_tunnel_create (void *cls, 479handle_channel_create (void *cls,
472 const struct GNUNET_CADET_LocalChannelCreateMessage *tcm) 480 const struct GNUNET_CADET_LocalChannelCreateMessage *tcm)
473{ 481{
474 struct CadetClient *c = cls; 482 struct CadetClient *c = cls;
475 struct CadetChannel *ch; 483 struct CadetChannel *ch;
476 struct GNUNET_CADET_ClientChannelNumber chid;
477 struct CadetPeer *dst;
478 484
479 chid = tcm->channel_id; 485 if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
480 if (ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
481 { 486 {
482 /* Channel ID not in allowed range. */ 487 /* Channel ID not in allowed range. */
483 GNUNET_break (0); 488 GNUNET_break (0);
484 GNUNET_SERVICE_client_drop (c->client); 489 GNUNET_SERVICE_client_drop (c->client);
485 return; 490 return;
486 } 491 }
487 ch = GNUNET_CONTAINER_multihashmap32_get (c->own_channels, 492 ch = lookup_channel (c,
488 ntohl (chid.channel_of_client)); 493 tcm->ccn);
489 if (NULL != ch) 494 if (NULL != ch)
490 { 495 {
491 /* Channel ID already in use. Not allowed. */ 496 /* Channel ID already in use. Not allowed. */
@@ -494,13 +499,11 @@ handle_tunnel_create (void *cls,
494 return; 499 return;
495 } 500 }
496 501
497 dst = GCP_get (&tcm->peer,
498 GNUNET_YES);
499
500 /* Create channel */ 502 /* Create channel */
501 ch = GCCH_channel_local_new (c, 503 ch = GCCH_channel_local_new (c,
502 chid, 504 tcm->ccn,
503 dst, 505 GCP_get (&tcm->peer,
506 GNUNET_YES),
504 &tcm->port, 507 &tcm->port,
505 ntohl (tcm->opt)); 508 ntohl (tcm->opt));
506 if (NULL == ch) 509 if (NULL == ch)
@@ -510,59 +513,36 @@ handle_tunnel_create (void *cls,
510 return; 513 return;
511 } 514 }
512 GNUNET_assert (GNUNET_YES == 515 GNUNET_assert (GNUNET_YES ==
513 GNUNET_CONTAINER_multihashmap32_put (c->own_channels, 516 GNUNET_CONTAINER_multihashmap32_put (c->channels,
514 ntohl (chid.channel_of_client), 517 ntohl (tcm->ccn.channel_of_client),
515 ch, 518 ch,
516 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 519 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
517 520
518 LOG (GNUNET_ERROR_TYPE_DEBUG, 521 LOG (GNUNET_ERROR_TYPE_DEBUG,
519 "New channel %s to %s at port %s requested by client %u\n", 522 "New channel %s to %s at port %s requested by client %s\n",
520 GCCH_2s (ch), 523 GCCH_2s (ch),
521 GNUNET_i2s (&tcm->peer), 524 GNUNET_i2s (&tcm->peer),
522 GNUNET_h2s (&tcm->port), 525 GNUNET_h2s (&tcm->port),
523 c->id); 526 GSC_2s (c));
524 GNUNET_SERVICE_client_continue (c->client); 527 GNUNET_SERVICE_client_continue (c->client);
525} 528}
526 529
527 530
528/** 531/**
529 * Return the map which we use for client @a c for a channel ID of @a chid 532 * Handler for requests of destroying an existing channel.
530 *
531 * @param c client to find map for
532 * @param chid chid to find map for
533 * @return applicable map we use
534 */
535static struct GNUNET_CONTAINER_MultiHashMap32 *
536get_map_by_chid (struct CadetClient *c,
537 struct GNUNET_CADET_ClientChannelNumber chid)
538{
539 return (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
540 ? c->own_channels
541 : c->incoming_channels;
542}
543
544
545/**
546 * Handler for requests of deleting tunnels
547 * 533 *
548 * @param cls client identification of the client 534 * @param cls client identification of the client
549 * @param msg the actual message 535 * @param msg the actual message
550 */ 536 */
551static void 537static void
552handle_tunnel_destroy (void *cls, 538handle_channel_destroy (void *cls,
553 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) 539 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg)
554{ 540{
555 struct CadetClient *c = cls; 541 struct CadetClient *c = cls;
556 struct GNUNET_CADET_ClientChannelNumber chid;
557 struct GNUNET_CONTAINER_MultiHashMap32 *map;
558 struct CadetChannel *ch; 542 struct CadetChannel *ch;
559 543
560 /* Retrieve tunnel */ 544 ch = lookup_channel (c,
561 chid = msg->channel_id; 545 msg->ccn);
562 map = get_map_by_chid (c,
563 chid);
564 ch = GNUNET_CONTAINER_multihashmap32_get (map,
565 ntohl (chid.channel_of_client));
566 if (NULL == ch) 546 if (NULL == ch)
567 { 547 {
568 /* Client attempted to destroy unknown channel */ 548 /* Client attempted to destroy unknown channel */
@@ -571,12 +551,12 @@ handle_tunnel_destroy (void *cls,
571 return; 551 return;
572 } 552 }
573 LOG (GNUNET_ERROR_TYPE_INFO, 553 LOG (GNUNET_ERROR_TYPE_INFO,
574 "Client %u is destroying channel %s\n", 554 "Client %s is destroying channel %s\n",
575 c->id, 555 GSC_2s(c),
576 GCCH_2s (ch)); 556 GCCH_2s (ch));
577 GNUNET_assert (GNUNET_YES == 557 GNUNET_assert (GNUNET_YES ==
578 GNUNET_CONTAINER_multihashmap32_remove (map, 558 GNUNET_CONTAINER_multihashmap32_remove (c->channels,
579 ntohl (chid.channel_of_client), 559 ntohl (msg->ccn.channel_of_client),
580 ch)); 560 ch));
581 GCCH_channel_local_destroy (ch); 561 GCCH_channel_local_destroy (ch);
582 GNUNET_SERVICE_client_continue (c->client); 562 GNUNET_SERVICE_client_continue (c->client);
@@ -584,7 +564,7 @@ handle_tunnel_destroy (void *cls,
584 564
585 565
586/** 566/**
587 * Check for client traffic data message is well-formed 567 * Check for client traffic data message is well-formed.
588 * 568 *
589 * @param cls identification of the client 569 * @param cls identification of the client
590 * @param msg the actual message 570 * @param msg the actual message
@@ -618,7 +598,8 @@ check_data (void *cls,
618 598
619 599
620/** 600/**
621 * Handler for client traffic 601 * Handler for client payload traffic to be send on a channel to
602 * another peer.
622 * 603 *
623 * @param cls identification of the client 604 * @param cls identification of the client
624 * @param msg the actual message 605 * @param msg the actual message
@@ -628,16 +609,11 @@ handle_data (void *cls,
628 const struct GNUNET_CADET_LocalData *msg) 609 const struct GNUNET_CADET_LocalData *msg)
629{ 610{
630 struct CadetClient *c = cls; 611 struct CadetClient *c = cls;
631 struct GNUNET_CONTAINER_MultiHashMap32 *map;
632 struct GNUNET_CADET_ClientChannelNumber chid;
633 struct CadetChannel *ch; 612 struct CadetChannel *ch;
634 const struct GNUNET_MessageHeader *payload; 613 const struct GNUNET_MessageHeader *payload;
635 614
636 chid = msg->channel_id; 615 ch = lookup_channel (c,
637 map = get_map_by_chid (c, 616 msg->ccn);
638 chid);
639 ch = GNUNET_CONTAINER_multihashmap32_get (map,
640 ntohl (chid.channel_of_client));
641 if (NULL == ch) 617 if (NULL == ch)
642 { 618 {
643 /* Channel does not exist! */ 619 /* Channel does not exist! */
@@ -648,9 +624,9 @@ handle_data (void *cls,
648 624
649 payload = (const struct GNUNET_MessageHeader *) &msg[1]; 625 payload = (const struct GNUNET_MessageHeader *) &msg[1];
650 LOG (GNUNET_ERROR_TYPE_DEBUG, 626 LOG (GNUNET_ERROR_TYPE_DEBUG,
651 "Received %u bytes payload from client %u for channel %s\n", 627 "Received %u bytes payload from client %s for channel %s\n",
652 ntohs (payload->size), 628 ntohs (payload->size),
653 c->id, 629 GSC_2s (c),
654 GCCH_2s (ch)); 630 GCCH_2s (ch));
655 if (GNUNET_OK != 631 if (GNUNET_OK !=
656 GCCH_handle_local_data (ch, 632 GCCH_handle_local_data (ch,
@@ -674,15 +650,10 @@ handle_ack (void *cls,
674 const struct GNUNET_CADET_LocalAck *msg) 650 const struct GNUNET_CADET_LocalAck *msg)
675{ 651{
676 struct CadetClient *c = cls; 652 struct CadetClient *c = cls;
677 struct GNUNET_CONTAINER_MultiHashMap32 *map;
678 struct GNUNET_CADET_ClientChannelNumber chid;
679 struct CadetChannel *ch; 653 struct CadetChannel *ch;
680 654
681 chid = msg->channel_id; 655 ch = lookup_channel (c,
682 map = get_map_by_chid (c, 656 msg->ccn);
683 chid);
684 ch = GNUNET_CONTAINER_multihashmap32_get (map,
685 ntohl (chid.channel_of_client));
686 if (NULL == ch) 657 if (NULL == ch)
687 { 658 {
688 /* Channel does not exist! */ 659 /* Channel does not exist! */
@@ -691,8 +662,8 @@ handle_ack (void *cls,
691 return; 662 return;
692 } 663 }
693 LOG (GNUNET_ERROR_TYPE_DEBUG, 664 LOG (GNUNET_ERROR_TYPE_DEBUG,
694 "Got a local ACK from client %u for channel %s\n", 665 "Got a local ACK from client %s for channel %s\n",
695 c->id, 666 GSC_2s(c),
696 GCCH_2s (ch)); 667 GCCH_2s (ch));
697 GCCH_handle_local_ack (ch); 668 GCCH_handle_local_ack (ch);
698 GNUNET_SERVICE_client_continue (c->client); 669 GNUNET_SERVICE_client_continue (c->client);
@@ -869,14 +840,14 @@ get_all_tunnels_iterator (void *cls,
869 840
870 841
871/** 842/**
872 * Handler for client's INFO TUNNELS request. 843 * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS request.
873 * 844 *
874 * @param cls client Identification of the client. 845 * @param cls client Identification of the client.
875 * @param message The actual message. 846 * @param message The actual message.
876 */ 847 */
877static void 848static void
878handle_get_tunnels (void *cls, 849handle_info_tunnels (void *cls,
879 const struct GNUNET_MessageHeader *message) 850 const struct GNUNET_MessageHeader *message)
880{ 851{
881 struct CadetClient *c = cls; 852 struct CadetClient *c = cls;
882 struct GNUNET_MQ_Envelope *env; 853 struct GNUNET_MQ_Envelope *env;
@@ -893,7 +864,10 @@ handle_get_tunnels (void *cls,
893 864
894 865
895/** 866/**
896 * FIXME. 867 * Update the message with information about the connection.
868 *
869 * @param cls a `struct GNUNET_CADET_LocalInfoTunnel` message to update
870 * @param c a connection about which we should store information in @a cls
897 */ 871 */
898static void 872static void
899iter_connection (void *cls, 873iter_connection (void *cls,
@@ -908,7 +882,10 @@ iter_connection (void *cls,
908 882
909 883
910/** 884/**
911 * FIXME. 885 * Update the message with information about the channel.
886 *
887 * @param cls a `struct GNUNET_CADET_LocalInfoTunnel` message to update
888 * @param ch a channel about which we should store information in @a cls
912 */ 889 */
913static void 890static void
914iter_channel (void *cls, 891iter_channel (void *cls,
@@ -924,13 +901,13 @@ iter_channel (void *cls,
924 901
925 902
926/** 903/**
927 * Handler for client's SHOW_TUNNEL request. 904 * Handler for client's #GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL request.
928 * 905 *
929 * @param cls Identification of the client. 906 * @param cls Identification of the client.
930 * @param msg The actual message. 907 * @param msg The actual message.
931 */ 908 */
932static void 909static void
933handle_show_tunnel (void *cls, 910handle_info_tunnel (void *cls,
934 const struct GNUNET_CADET_LocalInfo *msg) 911 const struct GNUNET_CADET_LocalInfo *msg)
935{ 912{
936 struct CadetClient *c = cls; 913 struct CadetClient *c = cls;
@@ -1033,18 +1010,19 @@ handle_info_dump (void *cls,
1033 1010
1034 LOG (GNUNET_ERROR_TYPE_ERROR, 1011 LOG (GNUNET_ERROR_TYPE_ERROR,
1035 "*************************** DUMP START ***************************\n"); 1012 "*************************** DUMP START ***************************\n");
1036 for (struct CadetClient *ci = clients_head; NULL != ci; ci = ci->next) 1013 for (struct CadetClient *ci = clients_head;
1014 NULL != ci;
1015 ci = ci->next)
1037 { 1016 {
1038 LOG (GNUNET_ERROR_TYPE_ERROR, 1017 LOG (GNUNET_ERROR_TYPE_ERROR,
1039 "Client %u (%p), handle: %p, ports: %u, own channels: %u, incoming channels: %u\n", 1018 "Client %u (%p), handle: %p, ports: %u, channels: %u\n",
1040 ci->id, 1019 ci->id,
1041 ci, 1020 ci,
1042 ci->client, 1021 ci->client,
1043 (NULL != c->ports) 1022 (NULL != c->ports)
1044 ? GNUNET_CONTAINER_multihashmap_size (ci->ports) 1023 ? GNUNET_CONTAINER_multihashmap_size (ci->ports)
1045 : 0, 1024 : 0,
1046 GNUNET_CONTAINER_multihashmap32_size (ci->own_channels), 1025 GNUNET_CONTAINER_multihashmap32_size (ci->channels));
1047 GNUNET_CONTAINER_multihashmap32_size (ci->incoming_channels));
1048 } 1026 }
1049 LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n"); 1027 LOG (GNUNET_ERROR_TYPE_ERROR, "***************************\n");
1050 GCP_iterate_all (&show_peer_iterator, 1028 GCP_iterate_all (&show_peer_iterator,
@@ -1077,9 +1055,7 @@ client_connect_cb (void *cls,
1077 c->client = client; 1055 c->client = client;
1078 c->mq = mq; 1056 c->mq = mq;
1079 c->id = next_client_id++; /* overflow not important: just for debug */ 1057 c->id = next_client_id++; /* overflow not important: just for debug */
1080 c->own_channels 1058 c->channels
1081 = GNUNET_CONTAINER_multihashmap32_create (32);
1082 c->incoming_channels
1083 = GNUNET_CONTAINER_multihashmap32_create (32); 1059 = GNUNET_CONTAINER_multihashmap32_create (32);
1084 GNUNET_CONTAINER_DLL_insert (clients_head, 1060 GNUNET_CONTAINER_DLL_insert (clients_head,
1085 clients_tail, 1061 clients_tail,
@@ -1088,6 +1064,9 @@ client_connect_cb (void *cls,
1088 "# clients", 1064 "# clients",
1089 +1, 1065 +1,
1090 GNUNET_NO); 1066 GNUNET_NO);
1067 LOG (GNUNET_ERROR_TYPE_DEBUG,
1068 "Client %s connected\n",
1069 GSC_2s (c));
1091 return c; 1070 return c;
1092} 1071}
1093 1072
@@ -1096,57 +1075,30 @@ client_connect_cb (void *cls,
1096 * Iterator for deleting each channel whose client endpoint disconnected. 1075 * Iterator for deleting each channel whose client endpoint disconnected.
1097 * 1076 *
1098 * @param cls Closure (client that has disconnected). 1077 * @param cls Closure (client that has disconnected).
1099 * @param key The local channel id (used to access the hashmap). 1078 * @param key The local channel id in host byte order
1100 * @param value The value stored at the key (channel to destroy). 1079 * @param value The value stored at the key (channel to destroy).
1101 * @return #GNUNET_OK, keep iterating. 1080 * @return #GNUNET_OK, keep iterating.
1102 */ 1081 */
1103static int 1082static int
1104own_channel_destroy_iterator (void *cls, 1083channel_destroy_iterator (void *cls,
1105 uint32_t key, 1084 uint32_t key,
1106 void *value) 1085 void *value)
1107{ 1086{
1108 struct CadetClient *c = cls; 1087 struct CadetClient *c = cls;
1109 struct CadetChannel *ch = value; 1088 struct CadetChannel *ch = value;
1110 1089
1111 GNUNET_assert (GNUNET_YES == 1090 GNUNET_assert (GNUNET_YES ==
1112 GNUNET_CONTAINER_multihashmap32_remove (c->own_channels, 1091 GNUNET_CONTAINER_multihashmap32_remove (c->channels,
1113 key,
1114 ch));
1115 LOG (GNUNET_ERROR_TYPE_DEBUG,
1116 "Destroying own channel %s, due to client %u shutdown.\n",
1117 GCCH_2s (ch),
1118 c->id);
1119 GCCH_channel_local_destroy (ch);
1120 return GNUNET_OK;
1121}
1122
1123
1124/**
1125 * Iterator for deleting each channel whose client endpoint disconnected.
1126 *
1127 * @param cls Closure (client that has disconnected).
1128 * @param key The local channel id (used to access the hashmap).
1129 * @param value The value stored at the key (channel to destroy).
1130 * @return #GNUNET_OK, keep iterating.
1131 */
1132static int
1133incoming_channel_destroy_iterator (void *cls,
1134 uint32_t key,
1135 void *value)
1136{
1137 struct CadetChannel *ch = value;
1138 struct CadetClient *c = cls;
1139
1140 GNUNET_assert (GNUNET_YES ==
1141 GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels,
1142 key, 1092 key,
1143 ch)); 1093 ch));
1144
1145 LOG (GNUNET_ERROR_TYPE_DEBUG, 1094 LOG (GNUNET_ERROR_TYPE_DEBUG,
1146 "Destroying incoming channel %s due to client %u shutdown.\n", 1095 "Destroying channel %s, due to client %s disconnecting.\n",
1147 GCCH_2s (ch), 1096 GCCH_2s (ch),
1148 c->id); 1097 GSC_2s (c));
1149 GCCH_channel_incoming_destroy (ch); 1098 if (key < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1099 GCCH_channel_local_destroy (ch);
1100 else
1101 GCCH_channel_incoming_destroy (ch);
1150 return GNUNET_OK; 1102 return GNUNET_OK;
1151} 1103}
1152 1104
@@ -1155,7 +1107,7 @@ incoming_channel_destroy_iterator (void *cls,
1155 * Remove client's ports from the global hashmap on disconnect. 1107 * Remove client's ports from the global hashmap on disconnect.
1156 * 1108 *
1157 * @param cls Closure (unused). 1109 * @param cls Closure (unused).
1158 * @param key Port. 1110 * @param key the port.
1159 * @param value the `struct CadetClient` to remove 1111 * @param value the `struct CadetClient` to remove
1160 * @return #GNUNET_OK, keep iterating. 1112 * @return #GNUNET_OK, keep iterating.
1161 */ 1113 */
@@ -1166,6 +1118,10 @@ client_release_ports (void *cls,
1166{ 1118{
1167 struct CadetClient *c = value; 1119 struct CadetClient *c = value;
1168 1120
1121 LOG (GNUNET_ERROR_TYPE_DEBUG,
1122 "Closing port %s due to client %s disconnect.\n",
1123 GNUNET_h2s (key),
1124 GSC_2s (c));
1169 GNUNET_assert (GNUNET_YES == 1125 GNUNET_assert (GNUNET_YES ==
1170 GNUNET_CONTAINER_multihashmap_remove (open_ports, 1126 GNUNET_CONTAINER_multihashmap_remove (open_ports,
1171 key, 1127 key,
@@ -1193,20 +1149,15 @@ client_disconnect_cb (void *cls,
1193 struct CadetClient *c = internal_cls; 1149 struct CadetClient *c = internal_cls;
1194 1150
1195 GNUNET_assert (c->client == client); 1151 GNUNET_assert (c->client == client);
1196 c->shutting_down = GNUNET_YES; 1152 LOG (GNUNET_ERROR_TYPE_DEBUG,
1197 if (NULL != c->own_channels) 1153 "Client %s is disconnecting.\n",
1198 { 1154 GSC_2s (c));
1199 GNUNET_CONTAINER_multihashmap32_iterate (c->own_channels, 1155 if (NULL != c->channels)
1200 &own_channel_destroy_iterator,
1201 c);
1202 GNUNET_CONTAINER_multihashmap32_destroy (c->own_channels);
1203 }
1204 if (NULL != c->incoming_channels)
1205 { 1156 {
1206 GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_channels, 1157 GNUNET_CONTAINER_multihashmap32_iterate (c->channels,
1207 &incoming_channel_destroy_iterator, 1158 &channel_destroy_iterator,
1208 c); 1159 c);
1209 GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_channels); 1160 GNUNET_CONTAINER_multihashmap32_destroy (c->channels);
1210 } 1161 }
1211 if (NULL != c->ports) 1162 if (NULL != c->ports)
1212 { 1163 {
@@ -1291,7 +1242,7 @@ run (void *cls,
1291 GCD_init (c); 1242 GCD_init (c);
1292 GCO_init (c); 1243 GCO_init (c);
1293 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1244 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1294 "CADET starting at peer %s\n", 1245 "CADET started for peer %s\n",
1295 GNUNET_i2s (&my_full_id)); 1246 GNUNET_i2s (&my_full_id));
1296 1247
1297} 1248}
@@ -1315,11 +1266,11 @@ GNUNET_SERVICE_MAIN
1315 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE, 1266 GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE,
1316 struct GNUNET_CADET_PortMessage, 1267 struct GNUNET_CADET_PortMessage,
1317 NULL), 1268 NULL),
1318 GNUNET_MQ_hd_fixed_size (tunnel_create, 1269 GNUNET_MQ_hd_fixed_size (channel_create,
1319 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, 1270 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE,
1320 struct GNUNET_CADET_LocalChannelCreateMessage, 1271 struct GNUNET_CADET_LocalChannelCreateMessage,
1321 NULL), 1272 NULL),
1322 GNUNET_MQ_hd_fixed_size (tunnel_destroy, 1273 GNUNET_MQ_hd_fixed_size (channel_destroy,
1323 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, 1274 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY,
1324 struct GNUNET_CADET_LocalChannelDestroyMessage, 1275 struct GNUNET_CADET_LocalChannelDestroyMessage,
1325 NULL), 1276 NULL),
@@ -1339,11 +1290,11 @@ GNUNET_SERVICE_MAIN
1339 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER, 1290 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
1340 struct GNUNET_CADET_LocalInfo, 1291 struct GNUNET_CADET_LocalInfo,
1341 NULL), 1292 NULL),
1342 GNUNET_MQ_hd_fixed_size (get_tunnels, 1293 GNUNET_MQ_hd_fixed_size (info_tunnels,
1343 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS, 1294 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
1344 struct GNUNET_MessageHeader, 1295 struct GNUNET_MessageHeader,
1345 NULL), 1296 NULL),
1346 GNUNET_MQ_hd_fixed_size (show_tunnel, 1297 GNUNET_MQ_hd_fixed_size (info_tunnel,
1347 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL, 1298 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
1348 struct GNUNET_CADET_LocalInfo, 1299 struct GNUNET_CADET_LocalInfo,
1349 NULL), 1300 NULL),
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index d7981656c..e64e66dfa 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -44,7 +44,7 @@
44#include "gnunet-service-cadet-new_peer.h" 44#include "gnunet-service-cadet-new_peer.h"
45#include "gnunet-service-cadet-new_paths.h" 45#include "gnunet-service-cadet-new_paths.h"
46 46
47#define LOG(level, ...) GNUNET_log (level,__VA_ARGS__) 47#define LOG(level,...) GNUNET_log_from (level,"cadet-channel",__VA_ARGS__)
48 48
49/** 49/**
50 * How long do we initially wait before retransmitting? 50 * How long do we initially wait before retransmitting?
@@ -263,13 +263,13 @@ struct CadetChannel
263 /** 263 /**
264 * Number identifying this channel in its tunnel. 264 * Number identifying this channel in its tunnel.
265 */ 265 */
266 struct GNUNET_CADET_ChannelTunnelNumber chid; 266 struct GNUNET_CADET_ChannelTunnelNumber ctn;
267 267
268 /** 268 /**
269 * Local tunnel number for local client owning the channel. 269 * Local tunnel number for local client owning the channel.
270 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) 270 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 )
271 */ 271 */
272 struct GNUNET_CADET_ClientChannelNumber lid; 272 struct GNUNET_CADET_ClientChannelNumber ccn;
273 273
274 /** 274 /**
275 * Channel state. 275 * Channel state.
@@ -327,11 +327,11 @@ GCCH_2s (const struct CadetChannel *ch)
327 return "(NULL Channel)"; 327 return "(NULL Channel)";
328 GNUNET_snprintf (buf, 328 GNUNET_snprintf (buf,
329 sizeof (buf), 329 sizeof (buf),
330 "%s:%s chid:%X (%X)", 330 "%s:%s ctn:%X (%X)",
331 GCT_2s (ch->t), 331 GCT_2s (ch->t),
332 GNUNET_h2s (&ch->port), 332 GNUNET_h2s (&ch->port),
333 ch->chid, 333 ch->ctn,
334 ntohl (ch->lid.channel_of_client)); 334 ntohl (ch->ccn.channel_of_client));
335 return buf; 335 return buf;
336} 336}
337 337
@@ -346,7 +346,7 @@ GCCH_2s (const struct CadetChannel *ch)
346struct GNUNET_CADET_ChannelTunnelNumber 346struct GNUNET_CADET_ChannelTunnelNumber
347GCCH_get_id (const struct CadetChannel *ch) 347GCCH_get_id (const struct CadetChannel *ch)
348{ 348{
349 return ch->chid; 349 return ch->ctn;
350} 350}
351 351
352 352
@@ -394,7 +394,7 @@ channel_destroy (struct CadetChannel *ch)
394 } 394 }
395 GCT_remove_channel (ch->t, 395 GCT_remove_channel (ch->t,
396 ch, 396 ch,
397 ch->chid); 397 ch->ctn);
398 GNUNET_free (ch); 398 GNUNET_free (ch);
399} 399}
400 400
@@ -450,7 +450,7 @@ send_create (void *cls)
450 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 450 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
451 msgcc.opt = htonl (options); 451 msgcc.opt = htonl (options);
452 msgcc.port = ch->port; 452 msgcc.port = ch->port;
453 msgcc.chid = ch->chid; 453 msgcc.ctn = ch->ctn;
454 ch->state = CADET_CHANNEL_CREATE_SENT; 454 ch->state = CADET_CHANNEL_CREATE_SENT;
455 ch->last_control_qe = GCT_send (ch->t, 455 ch->last_control_qe = GCT_send (ch->t,
456 &msgcc.header, 456 &msgcc.header,
@@ -463,7 +463,7 @@ send_create (void *cls)
463 * Create a new channel. 463 * Create a new channel.
464 * 464 *
465 * @param owner local client owning the channel 465 * @param owner local client owning the channel
466 * @param owner_id local chid of this channel at the @a owner 466 * @param ccn local number of this channel at the @a owner
467 * @param destination peer to which we should build the channel 467 * @param destination peer to which we should build the channel
468 * @param port desired port at @a destination 468 * @param port desired port at @a destination
469 * @param options options for the channel 469 * @param options options for the channel
@@ -471,7 +471,7 @@ send_create (void *cls)
471 */ 471 */
472struct CadetChannel * 472struct CadetChannel *
473GCCH_channel_local_new (struct CadetClient *owner, 473GCCH_channel_local_new (struct CadetClient *owner,
474 struct GNUNET_CADET_ClientChannelNumber owner_id, 474 struct GNUNET_CADET_ClientChannelNumber ccn,
475 struct CadetPeer *destination, 475 struct CadetPeer *destination,
476 const struct GNUNET_HashCode *port, 476 const struct GNUNET_HashCode *port,
477 uint32_t options) 477 uint32_t options)
@@ -484,11 +484,11 @@ GCCH_channel_local_new (struct CadetClient *owner,
484 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 484 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER));
485 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */ 485 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */
486 ch->owner = owner; 486 ch->owner = owner;
487 ch->lid = owner_id; 487 ch->ccn = ccn;
488 ch->port = *port; 488 ch->port = *port;
489 ch->t = GCP_get_tunnel (destination, 489 ch->t = GCP_get_tunnel (destination,
490 GNUNET_YES); 490 GNUNET_YES);
491 ch->chid = GCT_add_channel (ch->t, 491 ch->ctn = GCT_add_channel (ch->t,
492 ch); 492 ch);
493 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 493 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
494 ch->retry_task = GNUNET_SCHEDULER_add_now (&send_create, 494 ch->retry_task = GNUNET_SCHEDULER_add_now (&send_create,
@@ -497,6 +497,12 @@ GCCH_channel_local_new (struct CadetClient *owner,
497 "# channels", 497 "# channels",
498 1, 498 1,
499 GNUNET_NO); 499 GNUNET_NO);
500 LOG (GNUNET_ERROR_TYPE_DEBUG,
501 "Created channel to port %s at peer %s for client %s using tunnel %s\n",
502 GNUNET_h2s (port),
503 GCP_2s (destination),
504 GSC_2s (owner),
505 GCT_2s (ch->t));
500 return ch; 506 return ch;
501} 507}
502 508
@@ -513,6 +519,10 @@ timeout_closed_cb (void *cls)
513 struct CadetChannel *ch = cls; 519 struct CadetChannel *ch = cls;
514 520
515 ch->retry_task = NULL; 521 ch->retry_task = NULL;
522 LOG (GNUNET_ERROR_TYPE_DEBUG,
523 "Closing incoming channel to port %s from peer %s due to timeout\n",
524 GNUNET_h2s (&ch->port),
525 GCP_2s (GCT_get_destination (ch->t)));
516 channel_destroy (ch); 526 channel_destroy (ch);
517} 527}
518 528
@@ -521,14 +531,14 @@ timeout_closed_cb (void *cls)
521 * Create a new channel based on a request coming in over the network. 531 * Create a new channel based on a request coming in over the network.
522 * 532 *
523 * @param t tunnel to the remote peer 533 * @param t tunnel to the remote peer
524 * @param chid identifier of this channel in the tunnel 534 * @param ctn identifier of this channel in the tunnel
525 * @param port desired local port 535 * @param port desired local port
526 * @param options options for the channel 536 * @param options options for the channel
527 * @return handle to the new channel 537 * @return handle to the new channel
528 */ 538 */
529struct CadetChannel * 539struct CadetChannel *
530GCCH_channel_incoming_new (struct CadetTunnel *t, 540GCCH_channel_incoming_new (struct CadetTunnel *t,
531 struct GNUNET_CADET_ChannelTunnelNumber chid, 541 struct GNUNET_CADET_ChannelTunnelNumber ctn,
532 const struct GNUNET_HashCode *port, 542 const struct GNUNET_HashCode *port,
533 uint32_t options) 543 uint32_t options)
534{ 544{
@@ -538,7 +548,7 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
538 ch = GNUNET_new (struct CadetChannel); 548 ch = GNUNET_new (struct CadetChannel);
539 ch->port = *port; 549 ch->port = *port;
540 ch->t = t; 550 ch->t = t;
541 ch->chid = chid; 551 ch->ctn = ctn;
542 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 552 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
543 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 553 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
544 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 554 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
@@ -561,6 +571,10 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
561 ch->retry_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, 571 ch->retry_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT,
562 &timeout_closed_cb, 572 &timeout_closed_cb,
563 ch); 573 ch);
574 LOG (GNUNET_ERROR_TYPE_DEBUG,
575 "Created loose incoming channel to port %s from peer %s\n",
576 GNUNET_h2s (&ch->port),
577 GCP_2s (GCT_get_destination (ch->t)));
564 } 578 }
565 else 579 else
566 { 580 {
@@ -603,7 +617,7 @@ send_channel_ack (struct CadetChannel *ch)
603 617
604 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); 618 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
605 msg.header.size = htons (sizeof (msg)); 619 msg.header.size = htons (sizeof (msg));
606 msg.chid = ch->chid; 620 msg.ctn = ch->ctn;
607 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1); 621 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1);
608 msg.futures = GNUNET_htonll (ch->mid_futures); 622 msg.futures = GNUNET_htonll (ch->mid_futures);
609 if (NULL != ch->last_control_qe) 623 if (NULL != ch->last_control_qe)
@@ -646,7 +660,7 @@ send_ack_to_client (struct CadetChannel *ch,
646 660
647 env = GNUNET_MQ_msg (ack, 661 env = GNUNET_MQ_msg (ack,
648 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 662 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
649 ack->channel_id = ch->lid; 663 ack->ccn = ch->ccn;
650 GSC_send_to_client (c, 664 GSC_send_to_client (c,
651 env); 665 env);
652} 666}
@@ -668,6 +682,12 @@ GCCH_bind (struct CadetChannel *ch,
668 struct GNUNET_CADET_LocalChannelCreateMessage *tcm; 682 struct GNUNET_CADET_LocalChannelCreateMessage *tcm;
669 uint32_t options; 683 uint32_t options;
670 684
685 LOG (GNUNET_ERROR_TYPE_DEBUG,
686 "Binding channel %s from tunnel %s to port %s of client %s\n",
687 GCCH_2s (ch),
688 GCT_2s (ch->t),
689 GNUNET_h2s (&ch->port),
690 GSC_2s (c));
671 if (NULL != ch->retry_task) 691 if (NULL != ch->retry_task)
672 { 692 {
673 /* there might be a timeout task here */ 693 /* there might be a timeout task here */
@@ -682,7 +702,7 @@ GCCH_bind (struct CadetChannel *ch,
682 if (ch->out_of_order) 702 if (ch->out_of_order)
683 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER; 703 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
684 ch->dest = c; 704 ch->dest = c;
685 ch->lid = GSC_bind (c, 705 ch->ccn = GSC_bind (c,
686 ch, 706 ch,
687 GCT_get_destination (ch->t), 707 GCT_get_destination (ch->t),
688 &ch->port, 708 &ch->port,
@@ -695,7 +715,7 @@ GCCH_bind (struct CadetChannel *ch,
695 /* give client it's initial supply of ACKs */ 715 /* give client it's initial supply of ACKs */
696 env = GNUNET_MQ_msg (tcm, 716 env = GNUNET_MQ_msg (tcm,
697 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 717 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
698 tcm->channel_id = ch->lid; 718 tcm->ccn = ch->ccn;
699 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t)); 719 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t));
700 tcm->port = ch->port; 720 tcm->port = ch->port;
701 tcm->opt = htonl (options); 721 tcm->opt = htonl (options);
@@ -731,7 +751,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch)
731 } 751 }
732 /* Nothing left to do, just finish destruction */ 752 /* Nothing left to do, just finish destruction */
733 GCT_send_channel_destroy (ch->t, 753 GCT_send_channel_destroy (ch->t,
734 ch->chid); 754 ch->ctn);
735 channel_destroy (ch); 755 channel_destroy (ch);
736} 756}
737 757
@@ -760,7 +780,7 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch)
760 } 780 }
761 /* Nothing left to do, just finish destruction */ 781 /* Nothing left to do, just finish destruction */
762 GCT_send_channel_destroy (ch->t, 782 GCT_send_channel_destroy (ch->t,
763 ch->chid); 783 ch->ctn);
764 channel_destroy (ch); 784 channel_destroy (ch);
765} 785}
766 786
@@ -859,7 +879,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
859 env = GNUNET_MQ_msg_extra (ld, 879 env = GNUNET_MQ_msg_extra (ld,
860 payload_size, 880 payload_size,
861 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 881 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
862 ld->channel_id = ch->lid; 882 ld->ccn = ch->ccn;
863 GNUNET_memcpy (&ld[1], 883 GNUNET_memcpy (&ld[1],
864 &msg[1], 884 &msg[1],
865 payload_size); 885 payload_size);
@@ -978,7 +998,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch)
978 ch->destroy = GNUNET_YES; 998 ch->destroy = GNUNET_YES;
979 env = GNUNET_MQ_msg (tdm, 999 env = GNUNET_MQ_msg (tdm,
980 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1000 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
981 tdm->channel_id = ch->lid; 1001 tdm->ccn = ch->ccn;
982 GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest, 1002 GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest,
983 env); 1003 env);
984 channel_destroy (ch); 1004 channel_destroy (ch);
@@ -1063,7 +1083,7 @@ GCCH_check_allow_client (struct CadetChannel *ch)
1063 GCCH_2s (ch)); 1083 GCCH_2s (ch));
1064 env = GNUNET_MQ_msg (msg, 1084 env = GNUNET_MQ_msg (msg,
1065 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 1085 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
1066 msg->channel_id = ch->lid; 1086 msg->ccn = ch->ccn;
1067 GSC_send_to_client (ch->owner ? ch->owner : ch->dest, 1087 GSC_send_to_client (ch->owner ? ch->owner : ch->dest,
1068 env); 1088 env);
1069} 1089}
@@ -1169,7 +1189,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1169 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 1189 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
1170 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); 1190 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
1171 crm->data_message.mid = ch->mid_send; 1191 crm->data_message.mid = ch->mid_send;
1172 crm->data_message.chid = ch->chid; 1192 crm->data_message.ctn = ch->ctn;
1173 GNUNET_memcpy (&crm[1], 1193 GNUNET_memcpy (&crm[1],
1174 message, 1194 message,
1175 payload_size); 1195 payload_size);
@@ -1243,7 +1263,7 @@ send_client_buffered_data (struct CadetChannel *ch)
1243 if (GNUNET_NO == ch->destroy) 1263 if (GNUNET_NO == ch->destroy)
1244 return; 1264 return;
1245 GCT_send_channel_destroy (ch->t, 1265 GCT_send_channel_destroy (ch->t,
1246 ch->chid); 1266 ch->ctn);
1247 channel_destroy (ch); 1267 channel_destroy (ch);
1248} 1268}
1249 1269
@@ -1290,7 +1310,7 @@ GCCH_debug (struct CadetChannel *ch,
1290 LOG2 (level, 1310 LOG2 (level,
1291 "CHN Channel %s:%X (%p)\n", 1311 "CHN Channel %s:%X (%p)\n",
1292 GCT_2s (ch->t), 1312 GCT_2s (ch->t),
1293 ch->chid, 1313 ch->ctn,
1294 ch); 1314 ch);
1295 if (NULL != ch->owner) 1315 if (NULL != ch->owner)
1296 { 1316 {
@@ -1298,7 +1318,7 @@ GCCH_debug (struct CadetChannel *ch,
1298 "CHN origin %s ready %s local-id: %u\n", 1318 "CHN origin %s ready %s local-id: %u\n",
1299 GSC_2s (ch->owner), 1319 GSC_2s (ch->owner),
1300 ch->client_ready ? "YES" : "NO", 1320 ch->client_ready ? "YES" : "NO",
1301 ntohl (ch->lid.channel_of_client)); 1321 ntohl (ch->ccn.channel_of_client));
1302 } 1322 }
1303 if (NULL != ch->dest) 1323 if (NULL != ch->dest)
1304 { 1324 {
@@ -1306,7 +1326,7 @@ GCCH_debug (struct CadetChannel *ch,
1306 "CHN destination %s ready %s local-id: %u\n", 1326 "CHN destination %s ready %s local-id: %u\n",
1307 GSC_2s (ch->dest), 1327 GSC_2s (ch->dest),
1308 ch->client_ready ? "YES" : "NO", 1328 ch->client_ready ? "YES" : "NO",
1309 ntohl (ch->lid.channel_of_client)); 1329 ntohl (ch->ccn.channel_of_client));
1310 } 1330 }
1311 LOG2 (level, 1331 LOG2 (level,
1312 "CHN Message IDs recv: %d (%LLX), send: %d\n", 1332 "CHN Message IDs recv: %d (%LLX), send: %d\n",
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index a6502de01..cfdc4270a 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -342,7 +342,7 @@ struct CadetTunnel
342 /** 342 /**
343 * Channel ID for the next created channel in this tunnel. 343 * Channel ID for the next created channel in this tunnel.
344 */ 344 */
345 struct GNUNET_CADET_ChannelTunnelNumber next_chid; 345 struct GNUNET_CADET_ChannelTunnelNumber next_ctn;
346 346
347 /** 347 /**
348 * Queued messages, to transmit once tunnel gets connected. 348 * Queued messages, to transmit once tunnel gets connected.
@@ -444,18 +444,18 @@ GCT_count_channels (struct CadetTunnel *t)
444 444
445 445
446/** 446/**
447 * Lookup a channel by its @a chid. 447 * Lookup a channel by its @a ctn.
448 * 448 *
449 * @param t tunnel to look in 449 * @param t tunnel to look in
450 * @param chid number of channel to find 450 * @param ctn number of channel to find
451 * @return NULL if channel does not exist 451 * @return NULL if channel does not exist
452 */ 452 */
453struct CadetChannel * 453struct CadetChannel *
454lookup_channel (struct CadetTunnel *t, 454lookup_channel (struct CadetTunnel *t,
455 struct GNUNET_CADET_ChannelTunnelNumber chid) 455 struct GNUNET_CADET_ChannelTunnelNumber ctn)
456{ 456{
457 return GNUNET_CONTAINER_multihashmap32_get (t->channels, 457 return GNUNET_CONTAINER_multihashmap32_get (t->channels,
458 ntohl (chid.cn)); 458 ntohl (ctn.cn));
459} 459}
460 460
461 461
@@ -1389,22 +1389,22 @@ GCT_handle_kx (struct CadetTConnection *ct,
1389 * @return unused number that can uniquely identify a channel in the tunnel 1389 * @return unused number that can uniquely identify a channel in the tunnel
1390 */ 1390 */
1391static struct GNUNET_CADET_ChannelTunnelNumber 1391static struct GNUNET_CADET_ChannelTunnelNumber
1392get_next_free_chid (struct CadetTunnel *t) 1392get_next_free_ctn (struct CadetTunnel *t)
1393{ 1393{
1394 struct GNUNET_CADET_ChannelTunnelNumber ret; 1394 struct GNUNET_CADET_ChannelTunnelNumber ret;
1395 uint32_t chid; 1395 uint32_t ctn;
1396 1396
1397 /* FIXME: this logic does NOT prevent both ends of the 1397 /* FIXME: this logic does NOT prevent both ends of the
1398 channel from picking the same CHID! 1398 channel from picking the same CTN!
1399 Need to reserve one bit of the CHID for the 1399 Need to reserve one bit of the CTN for the
1400 direction, i.e. which side established the connection! */ 1400 direction, i.e. which side established the connection! */
1401 chid = ntohl (t->next_chid.cn); 1401 ctn = ntohl (t->next_ctn.cn);
1402 while (NULL != 1402 while (NULL !=
1403 GNUNET_CONTAINER_multihashmap32_get (t->channels, 1403 GNUNET_CONTAINER_multihashmap32_get (t->channels,
1404 chid)) 1404 ctn))
1405 chid++; 1405 ctn++;
1406 t->next_chid.cn = htonl (chid + 1); 1406 t->next_ctn.cn = htonl (ctn + 1);
1407 ret.cn = ntohl (chid); 1407 ret.cn = ntohl (ctn);
1408 return ret; 1408 return ret;
1409} 1409}
1410 1410
@@ -1420,15 +1420,15 @@ struct GNUNET_CADET_ChannelTunnelNumber
1420GCT_add_channel (struct CadetTunnel *t, 1420GCT_add_channel (struct CadetTunnel *t,
1421 struct CadetChannel *ch) 1421 struct CadetChannel *ch)
1422{ 1422{
1423 struct GNUNET_CADET_ChannelTunnelNumber chid; 1423 struct GNUNET_CADET_ChannelTunnelNumber ctn;
1424 1424
1425 chid = get_next_free_chid (t); 1425 ctn = get_next_free_ctn (t);
1426 GNUNET_assert (GNUNET_YES == 1426 GNUNET_assert (GNUNET_YES ==
1427 GNUNET_CONTAINER_multihashmap32_put (t->channels, 1427 GNUNET_CONTAINER_multihashmap32_put (t->channels,
1428 ntohl (chid.cn), 1428 ntohl (ctn.cn),
1429 ch, 1429 ch,
1430 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1430 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1431 return chid; 1431 return ctn;
1432} 1432}
1433 1433
1434 1434
@@ -1759,13 +1759,13 @@ handle_plaintext_data (void *cls,
1759 struct CadetChannel *ch; 1759 struct CadetChannel *ch;
1760 1760
1761 ch = lookup_channel (t, 1761 ch = lookup_channel (t,
1762 msg->chid); 1762 msg->ctn);
1763 if (NULL == ch) 1763 if (NULL == ch)
1764 { 1764 {
1765 /* We don't know about such a channel, might have been destroyed on our 1765 /* We don't know about such a channel, might have been destroyed on our
1766 end in the meantime, or never existed. Send back a DESTROY. */ 1766 end in the meantime, or never existed. Send back a DESTROY. */
1767 GCT_send_channel_destroy (t, 1767 GCT_send_channel_destroy (t,
1768 msg->chid); 1768 msg->ctn);
1769 return; 1769 return;
1770 } 1770 }
1771 GCCH_handle_channel_plaintext_data (ch, 1771 GCCH_handle_channel_plaintext_data (ch,
@@ -1789,13 +1789,13 @@ handle_plaintext_data_ack (void *cls,
1789 struct CadetChannel *ch; 1789 struct CadetChannel *ch;
1790 1790
1791 ch = lookup_channel (t, 1791 ch = lookup_channel (t,
1792 ack->chid); 1792 ack->ctn);
1793 if (NULL == ch) 1793 if (NULL == ch)
1794 { 1794 {
1795 /* We don't know about such a channel, might have been destroyed on our 1795 /* We don't know about such a channel, might have been destroyed on our
1796 end in the meantime, or never existed. Send back a DESTROY. */ 1796 end in the meantime, or never existed. Send back a DESTROY. */
1797 GCT_send_channel_destroy (t, 1797 GCT_send_channel_destroy (t,
1798 ack->chid); 1798 ack->ctn);
1799 return; 1799 return;
1800 } 1800 }
1801 GCCH_handle_channel_plaintext_data_ack (ch, 1801 GCCH_handle_channel_plaintext_data_ack (ch,
@@ -1816,16 +1816,16 @@ handle_plaintext_channel_create (void *cls,
1816{ 1816{
1817 struct CadetTunnel *t = cls; 1817 struct CadetTunnel *t = cls;
1818 struct CadetChannel *ch; 1818 struct CadetChannel *ch;
1819 struct GNUNET_CADET_ChannelTunnelNumber chid; 1819 struct GNUNET_CADET_ChannelTunnelNumber ctn;
1820 1820
1821 chid = get_next_free_chid (t); 1821 ctn = get_next_free_ctn (t);
1822 ch = GCCH_channel_incoming_new (t, 1822 ch = GCCH_channel_incoming_new (t,
1823 chid, 1823 ctn,
1824 &cc->port, 1824 &cc->port,
1825 ntohl (cc->opt)); 1825 ntohl (cc->opt));
1826 GNUNET_assert (GNUNET_OK == 1826 GNUNET_assert (GNUNET_OK ==
1827 GNUNET_CONTAINER_multihashmap32_put (t->channels, 1827 GNUNET_CONTAINER_multihashmap32_put (t->channels,
1828 ntohl (chid.cn), 1828 ntohl (ctn.cn),
1829 ch, 1829 ch,
1830 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1830 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1831} 1831}
@@ -1835,18 +1835,18 @@ handle_plaintext_channel_create (void *cls,
1835 * Send a DESTROY message via the tunnel. 1835 * Send a DESTROY message via the tunnel.
1836 * 1836 *
1837 * @param t the tunnel to transmit over 1837 * @param t the tunnel to transmit over
1838 * @param chid ID of the channel to destroy 1838 * @param ctn ID of the channel to destroy
1839 */ 1839 */
1840void 1840void
1841GCT_send_channel_destroy (struct CadetTunnel *t, 1841GCT_send_channel_destroy (struct CadetTunnel *t,
1842 struct GNUNET_CADET_ChannelTunnelNumber chid) 1842 struct GNUNET_CADET_ChannelTunnelNumber ctn)
1843{ 1843{
1844 struct GNUNET_CADET_ChannelManageMessage msg; 1844 struct GNUNET_CADET_ChannelManageMessage msg;
1845 1845
1846 msg.header.size = htons (sizeof (msg)); 1846 msg.header.size = htons (sizeof (msg));
1847 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1847 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1848 msg.reserved = htonl (0); 1848 msg.reserved = htonl (0);
1849 msg.chid = chid; 1849 msg.ctn = ctn;
1850 GCT_send (t, 1850 GCT_send (t,
1851 &msg.header, 1851 &msg.header,
1852 NULL, 1852 NULL,
@@ -1870,13 +1870,13 @@ handle_plaintext_channel_ack (void *cls,
1870 struct CadetChannel *ch; 1870 struct CadetChannel *ch;
1871 1871
1872 ch = lookup_channel (t, 1872 ch = lookup_channel (t,
1873 cm->chid); 1873 cm->ctn);
1874 if (NULL == ch) 1874 if (NULL == ch)
1875 { 1875 {
1876 /* We don't know about such a channel, might have been destroyed on our 1876 /* We don't know about such a channel, might have been destroyed on our
1877 end in the meantime, or never existed. Send back a DESTROY. */ 1877 end in the meantime, or never existed. Send back a DESTROY. */
1878 GCT_send_channel_destroy (t, 1878 GCT_send_channel_destroy (t,
1879 cm->chid); 1879 cm->ctn);
1880 return; 1880 return;
1881 } 1881 }
1882 GCCH_handle_channel_create_ack (ch); 1882 GCCH_handle_channel_create_ack (ch);
@@ -1896,7 +1896,7 @@ handle_plaintext_channel_destroy (void *cls,
1896{ 1896{
1897 struct CadetTunnel *t = cls; 1897 struct CadetTunnel *t = cls;
1898 struct CadetChannel *cc = lookup_channel (t, 1898 struct CadetChannel *cc = lookup_channel (t,
1899 cm->chid); 1899 cm->ctn);
1900 1900
1901 GCCH_handle_remote_destroy (cc); 1901 GCCH_handle_remote_destroy (cc);
1902} 1902}
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index 1de6ea865..7b7c6e57c 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -451,7 +451,7 @@ add_destination (struct CadetChannel *ch, struct CadetClient *c)
451 } 451 }
452 452
453 /* Assign local id as destination */ 453 /* Assign local id as destination */
454 ch->lid_dest = GML_get_next_chid (c); 454 ch->lid_dest = GML_get_next_ccn (c);
455 455
456 /* Store in client's hashmap */ 456 /* Store in client's hashmap */
457 GML_channel_add (c, ch->lid_dest, ch); 457 GML_channel_add (c, ch->lid_dest, ch);
@@ -517,7 +517,7 @@ send_destroy (struct CadetChannel *ch, int local_only)
517 517
518 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 518 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
519 msg.header.size = htons (sizeof (msg)); 519 msg.header.size = htons (sizeof (msg));
520 msg.chid = ch->gid; 520 msg.ctn = ch->gid;
521 521
522 /* If root is not NULL, notify. 522 /* If root is not NULL, notify.
523 * If it's NULL, check lid_root. When a local destroy comes in, root 523 * If it's NULL, check lid_root. When a local destroy comes in, root
@@ -886,7 +886,7 @@ send_create (struct CadetChannel *ch)
886 886
887 msgcc.header.size = htons (sizeof (msgcc)); 887 msgcc.header.size = htons (sizeof (msgcc));
888 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 888 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
889 msgcc.chid = ch->gid; 889 msgcc.ctn = ch->gid;
890 msgcc.port = ch->port; 890 msgcc.port = ch->port;
891 msgcc.opt = htonl (channel_get_options (ch)); 891 msgcc.opt = htonl (channel_get_options (ch));
892 892
@@ -911,7 +911,7 @@ send_ack (struct CadetChannel *ch, int fwd)
911 " sending channel %s ack for channel %s\n", 911 " sending channel %s ack for channel %s\n",
912 GC_f2s (fwd), GCCH_2s (ch)); 912 GC_f2s (fwd), GCCH_2s (ch));
913 913
914 msg.chid =ch->gid; 914 msg.ctn =ch->gid;
915 GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL); 915 GCCH_send_prebuilt_message (&msg.header, ch, !fwd, NULL);
916} 916}
917 917
@@ -951,7 +951,7 @@ send_nack (struct CadetChannel *ch)
951 " sending channel NACK for channel %s\n", 951 " sending channel NACK for channel %s\n",
952 GCCH_2s (ch)); 952 GCCH_2s (ch));
953 953
954 msg.chid = ch->gid; 954 msg.ctn = ch->gid;
955 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL); 955 GCCH_send_prebuilt_message (&msg.header, ch, GNUNET_NO, NULL);
956} 956}
957 957
@@ -1270,7 +1270,7 @@ channel_new (struct CadetTunnel *t,
1270 1270
1271 if (NULL != owner) 1271 if (NULL != owner)
1272 { 1272 {
1273 ch->gid = GCT_get_next_chid (t); 1273 ch->gid = GCT_get_next_ctn (t);
1274 GML_channel_add (owner, lid_root, ch); 1274 GML_channel_add (owner, lid_root, ch);
1275 } 1275 }
1276 GCT_add_channel (t, ch); 1276 GCT_add_channel (t, ch);
@@ -1539,7 +1539,7 @@ GCCH_send_data_ack (struct CadetChannel *ch, int fwd)
1539 1539
1540 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); 1540 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
1541 msg.header.size = htons (sizeof (msg)); 1541 msg.header.size = htons (sizeof (msg));
1542 msg.chid = ch->gid; 1542 msg.ctn = ch->gid;
1543 msg.mid = htonl (ack); 1543 msg.mid = htonl (ack);
1544 1544
1545 msg.futures = 0LL; 1545 msg.futures = 0LL;
@@ -1782,7 +1782,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1782 GNUNET_memcpy (&payload[1], message, size); 1782 GNUNET_memcpy (&payload[1], message, size);
1783 payload->header.size = htons (p2p_size); 1783 payload->header.size = htons (p2p_size);
1784 payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 1784 payload->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
1785 payload->chid = ch->gid; 1785 payload->ctn = ch->gid;
1786 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n"); 1786 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
1787 GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL); 1787 GCCH_send_prebuilt_message (&payload->header, ch, fwd, NULL);
1788 1788
@@ -1852,14 +1852,14 @@ GCCH_handle_local_create (struct CadetClient *c,
1852 struct CadetChannel *ch; 1852 struct CadetChannel *ch;
1853 struct CadetTunnel *t; 1853 struct CadetTunnel *t;
1854 struct CadetPeer *peer; 1854 struct CadetPeer *peer;
1855 struct GNUNET_CADET_ClientChannelNumber chid; 1855 struct GNUNET_CADET_ClientChannelNumber ccn;
1856 1856
1857 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n", 1857 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s:%u\n",
1858 GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port)); 1858 GNUNET_i2s (&msg->peer), GNUNET_h2s (&msg->port));
1859 chid = msg->channel_id; 1859 ccn = msg->ccn;
1860 1860
1861 /* Sanity check for duplicate channel IDs */ 1861 /* Sanity check for duplicate channel IDs */
1862 if (NULL != GML_channel_get (c, chid)) 1862 if (NULL != GML_channel_get (c, ccn))
1863 { 1863 {
1864 GNUNET_break (0); 1864 GNUNET_break (0);
1865 return GNUNET_SYSERR; 1865 return GNUNET_SYSERR;
@@ -1880,7 +1880,7 @@ GCCH_handle_local_create (struct CadetClient *c,
1880 } 1880 }
1881 1881
1882 /* Create channel */ 1882 /* Create channel */
1883 ch = channel_new (t, c, chid); 1883 ch = channel_new (t, c, ccn);
1884 if (NULL == ch) 1884 if (NULL == ch)
1885 { 1885 {
1886 GNUNET_break (0); 1886 GNUNET_break (0);
@@ -2154,20 +2154,20 @@ struct CadetChannel *
2154GCCH_handle_create (struct CadetTunnel *t, 2154GCCH_handle_create (struct CadetTunnel *t,
2155 const struct GNUNET_CADET_ChannelOpenMessage *msg) 2155 const struct GNUNET_CADET_ChannelOpenMessage *msg)
2156{ 2156{
2157 struct GNUNET_CADET_ClientChannelNumber chid; 2157 struct GNUNET_CADET_ClientChannelNumber ccn;
2158 struct GNUNET_CADET_ChannelTunnelNumber gid; 2158 struct GNUNET_CADET_ChannelTunnelNumber gid;
2159 struct CadetChannel *ch; 2159 struct CadetChannel *ch;
2160 struct CadetClient *c; 2160 struct CadetClient *c;
2161 int new_channel; 2161 int new_channel;
2162 const struct GNUNET_HashCode *port; 2162 const struct GNUNET_HashCode *port;
2163 2163
2164 gid = msg->chid; 2164 gid = msg->ctn;
2165 ch = GCT_get_channel (t, gid); 2165 ch = GCT_get_channel (t, gid);
2166 if (NULL == ch) 2166 if (NULL == ch)
2167 { 2167 {
2168 /* Create channel */ 2168 /* Create channel */
2169 chid.channel_of_client = htonl (0); 2169 ccn.channel_of_client = htonl (0);
2170 ch = channel_new (t, NULL, chid); 2170 ch = channel_new (t, NULL, ccn);
2171 ch->gid = gid; 2171 ch->gid = gid;
2172 channel_set_options (ch, ntohl (msg->opt)); 2172 channel_set_options (ch, ntohl (msg->opt));
2173 new_channel = GNUNET_YES; 2173 new_channel = GNUNET_YES;
@@ -2180,7 +2180,7 @@ GCCH_handle_create (struct CadetTunnel *t,
2180 2180
2181 LOG (GNUNET_ERROR_TYPE_INFO, 2181 LOG (GNUNET_ERROR_TYPE_INFO,
2182 "<== %s ( 0x%08X %4u) on chan %s (%p) %s [%5u]\n", 2182 "<== %s ( 0x%08X %4u) on chan %s (%p) %s [%5u]\n",
2183 GC_m2s (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN), chid, port, 2183 GC_m2s (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN), ccn, port,
2184 GCCH_2s (ch), ch, GC_f2s (GNUNET_YES), ntohs (msg->header.size)); 2184 GCCH_2s (ch), ch, GC_f2s (GNUNET_YES), ntohs (msg->header.size));
2185 2185
2186 if (GNUNET_YES == new_channel || GCT_is_loopback (t)) 2186 if (GNUNET_YES == new_channel || GCT_is_loopback (t))
@@ -2411,7 +2411,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2411 { 2411 {
2412 struct GNUNET_CADET_ChannelOpenMessage *cc_msg; 2412 struct GNUNET_CADET_ChannelOpenMessage *cc_msg;
2413 cc_msg = (struct GNUNET_CADET_ChannelOpenMessage *) message; 2413 cc_msg = (struct GNUNET_CADET_ChannelOpenMessage *) message;
2414 SPRINTF (info, " 0x%08X", ntohl (cc_msg->chid.cn)); 2414 SPRINTF (info, " 0x%08X", ntohl (cc_msg->ctn.cn));
2415 break; 2415 break;
2416 } 2416 }
2417 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK: 2417 case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK:
@@ -2420,7 +2420,7 @@ GCCH_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2420 { 2420 {
2421 struct GNUNET_CADET_ChannelManageMessage *m_msg; 2421 struct GNUNET_CADET_ChannelManageMessage *m_msg;
2422 m_msg = (struct GNUNET_CADET_ChannelManageMessage *) message; 2422 m_msg = (struct GNUNET_CADET_ChannelManageMessage *) message;
2423 SPRINTF (info, " 0x%08X", ntohl (m_msg->chid.cn)); 2423 SPRINTF (info, " 0x%08X", ntohl (m_msg->ctn.cn));
2424 break; 2424 break;
2425 } 2425 }
2426 default: 2426 default:
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c
index a993f5758..dea6681df 100644
--- a/src/cadet/gnunet-service-cadet_local.c
+++ b/src/cadet/gnunet-service-cadet_local.c
@@ -70,7 +70,7 @@ struct CadetClient
70 /** 70 /**
71 * Channel ID for the next incoming channel. 71 * Channel ID for the next incoming channel.
72 */ 72 */
73 struct GNUNET_CADET_ClientChannelNumber next_chid; 73 struct GNUNET_CADET_ClientChannelNumber next_ccn;
74 74
75 /** 75 /**
76 * Handle to communicate with the client 76 * Handle to communicate with the client
@@ -475,7 +475,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
475 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg; 475 const struct GNUNET_CADET_LocalChannelDestroyMessage *msg;
476 struct CadetClient *c; 476 struct CadetClient *c;
477 struct CadetChannel *ch; 477 struct CadetChannel *ch;
478 struct GNUNET_CADET_ClientChannelNumber chid; 478 struct GNUNET_CADET_ClientChannelNumber ccn;
479 479
480 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n"); 480 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a DESTROY CHANNEL from client!\n");
481 481
@@ -500,15 +500,15 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
500 msg = (const struct GNUNET_CADET_LocalChannelDestroyMessage *) message; 500 msg = (const struct GNUNET_CADET_LocalChannelDestroyMessage *) message;
501 501
502 /* Retrieve tunnel */ 502 /* Retrieve tunnel */
503 chid = msg->channel_id; 503 ccn = msg->ccn;
504 ch = GML_channel_get (c, chid); 504 ch = GML_channel_get (c, ccn);
505 505
506 LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n", 506 LOG (GNUNET_ERROR_TYPE_INFO, "Client %u is destroying channel %X\n",
507 c->id, chid); 507 c->id, ccn);
508 508
509 if (NULL == ch) 509 if (NULL == ch)
510 { 510 {
511 LOG (GNUNET_ERROR_TYPE_WARNING, " channel %X not found\n", chid); 511 LOG (GNUNET_ERROR_TYPE_WARNING, " channel %X not found\n", ccn);
512 GNUNET_STATISTICS_update (stats, 512 GNUNET_STATISTICS_update (stats,
513 "# client destroy messages on unknown channel", 513 "# client destroy messages on unknown channel",
514 1, GNUNET_NO); 514 1, GNUNET_NO);
@@ -518,7 +518,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
518 518
519 GCCH_handle_local_destroy (ch, 519 GCCH_handle_local_destroy (ch,
520 c, 520 c,
521 ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 521 ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
522 522
523 GNUNET_SERVER_receive_done (client, GNUNET_OK); 523 GNUNET_SERVER_receive_done (client, GNUNET_OK);
524} 524}
@@ -539,7 +539,7 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
539 struct GNUNET_CADET_LocalData *msg; 539 struct GNUNET_CADET_LocalData *msg;
540 struct CadetClient *c; 540 struct CadetClient *c;
541 struct CadetChannel *ch; 541 struct CadetChannel *ch;
542 struct GNUNET_CADET_ClientChannelNumber chid; 542 struct GNUNET_CADET_ClientChannelNumber ccn;
543 size_t message_size; 543 size_t message_size;
544 size_t payload_size; 544 size_t payload_size;
545 size_t payload_claimed_size; 545 size_t payload_claimed_size;
@@ -585,13 +585,13 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
585 return; 585 return;
586 } 586 }
587 587
588 chid = msg->channel_id; 588 ccn = msg->ccn;
589 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n", 589 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes (%u payload) by client %u\n",
590 payload_size, payload_claimed_size, c->id); 590 payload_size, payload_claimed_size, c->id);
591 591
592 /* Channel exists? */ 592 /* Channel exists? */
593 fwd = ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 593 fwd = ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
594 ch = GML_channel_get (c, chid); 594 ch = GML_channel_get (c, ccn);
595 if (NULL == ch) 595 if (NULL == ch)
596 { 596 {
597 GNUNET_STATISTICS_update (stats, 597 GNUNET_STATISTICS_update (stats,
@@ -628,7 +628,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
628 struct GNUNET_CADET_LocalAck *msg; 628 struct GNUNET_CADET_LocalAck *msg;
629 struct CadetChannel *ch; 629 struct CadetChannel *ch;
630 struct CadetClient *c; 630 struct CadetClient *c;
631 struct GNUNET_CADET_ClientChannelNumber chid; 631 struct GNUNET_CADET_ClientChannelNumber ccn;
632 int fwd; 632 int fwd;
633 633
634 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); 634 LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
@@ -646,16 +646,16 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
646 msg = (struct GNUNET_CADET_LocalAck *) message; 646 msg = (struct GNUNET_CADET_LocalAck *) message;
647 647
648 /* Channel exists? */ 648 /* Channel exists? */
649 chid = msg->channel_id; 649 ccn = msg->ccn;
650 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", 650 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n",
651 ntohl (chid.channel_of_client)); 651 ntohl (ccn.channel_of_client));
652 ch = GML_channel_get (c, chid); 652 ch = GML_channel_get (c, ccn);
653 LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch); 653 LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch);
654 if (NULL == ch) 654 if (NULL == ch)
655 { 655 {
656 LOG (GNUNET_ERROR_TYPE_DEBUG, 656 LOG (GNUNET_ERROR_TYPE_DEBUG,
657 "Channel %X unknown.\n", 657 "Channel %X unknown.\n",
658 ntohl (chid.channel_of_client)); 658 ntohl (ccn.channel_of_client));
659 LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id); 659 LOG (GNUNET_ERROR_TYPE_DEBUG, " for client %u.\n", c->id);
660 GNUNET_STATISTICS_update (stats, 660 GNUNET_STATISTICS_update (stats,
661 "# client ack messages on unknown channel", 661 "# client ack messages on unknown channel",
@@ -666,7 +666,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
666 666
667 /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */ 667 /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */
668 /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */ 668 /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */
669 fwd = ntohl (chid.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 669 fwd = ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
670 670
671 GCCH_handle_local_ack (ch, fwd); 671 GCCH_handle_local_ack (ch, fwd);
672 GNUNET_SERVER_receive_done (client, GNUNET_OK); 672 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1213,17 +1213,17 @@ GML_shutdown (void)
1213 * Get a channel from a client. 1213 * Get a channel from a client.
1214 * 1214 *
1215 * @param c Client to check. 1215 * @param c Client to check.
1216 * @param chid Channel ID, must be local (> 0x800...). 1216 * @param ccn Channel ID, must be local (> 0x800...).
1217 * 1217 *
1218 * @return non-NULL if channel exists in the clients lists 1218 * @return non-NULL if channel exists in the clients lists
1219 */ 1219 */
1220struct CadetChannel * 1220struct CadetChannel *
1221GML_channel_get (struct CadetClient *c, 1221GML_channel_get (struct CadetClient *c,
1222 struct GNUNET_CADET_ClientChannelNumber chid) 1222 struct GNUNET_CADET_ClientChannelNumber ccn)
1223{ 1223{
1224 struct GNUNET_CONTAINER_MultiHashMap32 *map; 1224 struct GNUNET_CONTAINER_MultiHashMap32 *map;
1225 1225
1226 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1226 if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1227 map = c->own_channels; 1227 map = c->own_channels;
1228 else 1228 else
1229 map = c->incoming_channels; 1229 map = c->incoming_channels;
@@ -1232,12 +1232,12 @@ GML_channel_get (struct CadetClient *c,
1232 { 1232 {
1233 GNUNET_break (0); 1233 GNUNET_break (0);
1234 LOG (GNUNET_ERROR_TYPE_DEBUG, 1234 LOG (GNUNET_ERROR_TYPE_DEBUG,
1235 "Client %s does no t have a valid map for CHID %X\n", 1235 "Client %s does no t have a valid map for CCN %X\n",
1236 GML_2s (c), chid); 1236 GML_2s (c), ccn);
1237 return NULL; 1237 return NULL;
1238 } 1238 }
1239 return GNUNET_CONTAINER_multihashmap32_get (map, 1239 return GNUNET_CONTAINER_multihashmap32_get (map,
1240 chid.channel_of_client); 1240 ccn.channel_of_client);
1241} 1241}
1242 1242
1243 1243
@@ -1245,22 +1245,22 @@ GML_channel_get (struct CadetClient *c,
1245 * Add a channel to a client 1245 * Add a channel to a client
1246 * 1246 *
1247 * @param client Client. 1247 * @param client Client.
1248 * @param chid Channel ID. 1248 * @param ccn Channel ID.
1249 * @param ch Channel. 1249 * @param ch Channel.
1250 */ 1250 */
1251void 1251void
1252GML_channel_add (struct CadetClient *client, 1252GML_channel_add (struct CadetClient *client,
1253 struct GNUNET_CADET_ClientChannelNumber chid, 1253 struct GNUNET_CADET_ClientChannelNumber ccn,
1254 struct CadetChannel *ch) 1254 struct CadetChannel *ch)
1255{ 1255{
1256 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1256 if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1257 GNUNET_CONTAINER_multihashmap32_put (client->own_channels, 1257 GNUNET_CONTAINER_multihashmap32_put (client->own_channels,
1258 chid.channel_of_client, 1258 ccn.channel_of_client,
1259 ch, 1259 ch,
1260 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1260 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1261 else 1261 else
1262 GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, 1262 GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels,
1263 chid.channel_of_client, 1263 ccn.channel_of_client,
1264 ch, 1264 ch,
1265 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1265 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1266} 1266}
@@ -1270,21 +1270,21 @@ GML_channel_add (struct CadetClient *client,
1270 * Remove a channel from a client. 1270 * Remove a channel from a client.
1271 * 1271 *
1272 * @param client Client. 1272 * @param client Client.
1273 * @param chid Channel ID. 1273 * @param ccn Channel ID.
1274 * @param ch Channel. 1274 * @param ch Channel.
1275 */ 1275 */
1276void 1276void
1277GML_channel_remove (struct CadetClient *client, 1277GML_channel_remove (struct CadetClient *client,
1278 struct GNUNET_CADET_ClientChannelNumber chid, 1278 struct GNUNET_CADET_ClientChannelNumber ccn,
1279 struct CadetChannel *ch) 1279 struct CadetChannel *ch)
1280{ 1280{
1281 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1281 if (ntohl (ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1282 GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, 1282 GNUNET_CONTAINER_multihashmap32_remove (client->own_channels,
1283 chid.channel_of_client, 1283 ccn.channel_of_client,
1284 ch); 1284 ch);
1285 else 1285 else
1286 GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, 1286 GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels,
1287 chid.channel_of_client, 1287 ccn.channel_of_client,
1288 ch); 1288 ch);
1289} 1289}
1290 1290
@@ -1297,27 +1297,27 @@ GML_channel_remove (struct CadetClient *client,
1297 * @return LID of a channel free to use. 1297 * @return LID of a channel free to use.
1298 */ 1298 */
1299struct GNUNET_CADET_ClientChannelNumber 1299struct GNUNET_CADET_ClientChannelNumber
1300GML_get_next_chid (struct CadetClient *c) 1300GML_get_next_ccn (struct CadetClient *c)
1301{ 1301{
1302 struct GNUNET_CADET_ClientChannelNumber chid; 1302 struct GNUNET_CADET_ClientChannelNumber ccn;
1303 1303
1304 while (NULL != GML_channel_get (c, 1304 while (NULL != GML_channel_get (c,
1305 c->next_chid)) 1305 c->next_ccn))
1306 { 1306 {
1307 LOG (GNUNET_ERROR_TYPE_DEBUG, 1307 LOG (GNUNET_ERROR_TYPE_DEBUG,
1308 "Channel %u exists...\n", 1308 "Channel %u exists...\n",
1309 c->next_chid); 1309 c->next_ccn);
1310 c->next_chid.channel_of_client 1310 c->next_ccn.channel_of_client
1311 = htonl (1 + (ntohl (c->next_chid.channel_of_client))); 1311 = htonl (1 + (ntohl (c->next_ccn.channel_of_client)));
1312 if (ntohl (c->next_chid.channel_of_client) >= 1312 if (ntohl (c->next_ccn.channel_of_client) >=
1313 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 1313 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1314 c->next_chid.channel_of_client = htonl (0); 1314 c->next_ccn.channel_of_client = htonl (0);
1315 } 1315 }
1316 chid = c->next_chid; 1316 ccn = c->next_ccn;
1317 c->next_chid.channel_of_client 1317 c->next_ccn.channel_of_client
1318 = htonl (1 + (ntohl (c->next_chid.channel_of_client))); 1318 = htonl (1 + (ntohl (c->next_ccn.channel_of_client)));
1319 1319
1320 return chid; 1320 return ccn;
1321} 1321}
1322 1322
1323 1323
@@ -1390,24 +1390,24 @@ GML_client_delete_channel (struct CadetClient *c,
1390 * If the client was already allowed to send data, do nothing. 1390 * If the client was already allowed to send data, do nothing.
1391 * 1391 *
1392 * @param c Client to whom send the ACK. 1392 * @param c Client to whom send the ACK.
1393 * @param id Channel ID to use 1393 * @param ccn Channel ID to use
1394 */ 1394 */
1395void 1395void
1396GML_send_ack (struct CadetClient *c, 1396GML_send_ack (struct CadetClient *c,
1397 struct GNUNET_CADET_ClientChannelNumber id) 1397 struct GNUNET_CADET_ClientChannelNumber ccn)
1398{ 1398{
1399 struct GNUNET_CADET_LocalAck msg; 1399 struct GNUNET_CADET_LocalAck msg;
1400 1400
1401 LOG (GNUNET_ERROR_TYPE_DEBUG, 1401 LOG (GNUNET_ERROR_TYPE_DEBUG,
1402 "send local %s ack on %X towards %p\n", 1402 "send local %s ack on %X towards %p\n",
1403 ntohl (id.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI 1403 ntohl (ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
1404 ? "FWD" : "BCK", 1404 ? "FWD" : "BCK",
1405 ntohl (id.channel_of_client), 1405 ntohl (ccn.channel_of_client),
1406 c); 1406 c);
1407 1407
1408 msg.header.size = htons (sizeof (msg)); 1408 msg.header.size = htons (sizeof (msg));
1409 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 1409 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
1410 msg.channel_id = id; 1410 msg.ccn = ccn;
1411 GNUNET_SERVER_notification_context_unicast (nc, 1411 GNUNET_SERVER_notification_context_unicast (nc,
1412 c->handle, 1412 c->handle,
1413 &msg.header, 1413 &msg.header,
@@ -1421,14 +1421,14 @@ GML_send_ack (struct CadetClient *c,
1421 * Notify the client that a new incoming channel was created. 1421 * Notify the client that a new incoming channel was created.
1422 * 1422 *
1423 * @param c Client to notify. 1423 * @param c Client to notify.
1424 * @param id Channel ID. 1424 * @param ccn Channel ID.
1425 * @param port Channel's destination port. 1425 * @param port Channel's destination port.
1426 * @param opt Options (bit array). 1426 * @param opt Options (bit array).
1427 * @param peer Origin peer. 1427 * @param peer Origin peer.
1428 */ 1428 */
1429void 1429void
1430GML_send_channel_create (struct CadetClient *c, 1430GML_send_channel_create (struct CadetClient *c,
1431 struct GNUNET_CADET_ClientChannelNumber id, 1431 struct GNUNET_CADET_ClientChannelNumber ccn,
1432 const struct GNUNET_HashCode *port, 1432 const struct GNUNET_HashCode *port,
1433 uint32_t opt, 1433 uint32_t opt,
1434 const struct GNUNET_PeerIdentity *peer) 1434 const struct GNUNET_PeerIdentity *peer)
@@ -1437,7 +1437,7 @@ GML_send_channel_create (struct CadetClient *c,
1437 1437
1438 msg.header.size = htons (sizeof (msg)); 1438 msg.header.size = htons (sizeof (msg));
1439 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 1439 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
1440 msg.channel_id = id; 1440 msg.ccn = ccn;
1441 msg.port = *port; 1441 msg.port = *port;
1442 msg.opt = htonl (opt); 1442 msg.opt = htonl (opt);
1443 msg.peer = *peer; 1443 msg.peer = *peer;
@@ -1450,22 +1450,22 @@ GML_send_channel_create (struct CadetClient *c,
1450 * Build a local channel NACK message and send it to a local client. 1450 * Build a local channel NACK message and send it to a local client.
1451 * 1451 *
1452 * @param c Client to whom send the NACK. 1452 * @param c Client to whom send the NACK.
1453 * @param id Channel ID to use 1453 * @param ccn Channel ID to use
1454 */ 1454 */
1455void 1455void
1456GML_send_channel_nack (struct CadetClient *c, 1456GML_send_channel_nack (struct CadetClient *c,
1457 struct GNUNET_CADET_ClientChannelNumber id) 1457 struct GNUNET_CADET_ClientChannelNumber ccn)
1458{ 1458{
1459 struct GNUNET_CADET_LocalAck msg; 1459 struct GNUNET_CADET_LocalAck msg;
1460 1460
1461 LOG (GNUNET_ERROR_TYPE_DEBUG, 1461 LOG (GNUNET_ERROR_TYPE_DEBUG,
1462 "send local nack on %X towards %p\n", 1462 "send local nack on %X towards %p\n",
1463 ntohl (id.channel_of_client), 1463 ntohl (ccn.channel_of_client),
1464 c); 1464 c);
1465 1465
1466 msg.header.size = htons (sizeof (msg)); 1466 msg.header.size = htons (sizeof (msg));
1467 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED); 1467 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED);
1468 msg.channel_id = id; 1468 msg.ccn = ccn;
1469 GNUNET_SERVER_notification_context_unicast (nc, 1469 GNUNET_SERVER_notification_context_unicast (nc,
1470 c->handle, 1470 c->handle,
1471 &msg.header, 1471 &msg.header,
@@ -1477,11 +1477,11 @@ GML_send_channel_nack (struct CadetClient *c,
1477 * Notify a client that a channel is no longer valid. 1477 * Notify a client that a channel is no longer valid.
1478 * 1478 *
1479 * @param c Client. 1479 * @param c Client.
1480 * @param id ID of the channel that is destroyed. 1480 * @param ccn ID of the channel that is destroyed.
1481 */ 1481 */
1482void 1482void
1483GML_send_channel_destroy (struct CadetClient *c, 1483GML_send_channel_destroy (struct CadetClient *c,
1484 struct GNUNET_CADET_ClientChannelNumber id) 1484 struct GNUNET_CADET_ClientChannelNumber ccn)
1485{ 1485{
1486 struct GNUNET_CADET_LocalChannelDestroyMessage msg; 1486 struct GNUNET_CADET_LocalChannelDestroyMessage msg;
1487 1487
@@ -1494,7 +1494,7 @@ GML_send_channel_destroy (struct CadetClient *c,
1494 return; 1494 return;
1495 msg.header.size = htons (sizeof (msg)); 1495 msg.header.size = htons (sizeof (msg));
1496 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1496 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
1497 msg.channel_id = id; 1497 msg.ccn = ccn;
1498 GNUNET_SERVER_notification_context_unicast (nc, c->handle, 1498 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
1499 &msg.header, GNUNET_NO); 1499 &msg.header, GNUNET_NO);
1500} 1500}
@@ -1505,12 +1505,12 @@ GML_send_channel_destroy (struct CadetClient *c,
1505 * 1505 *
1506 * @param c Client to send to. 1506 * @param c Client to send to.
1507 * @param msg Message to modify and send. 1507 * @param msg Message to modify and send.
1508 * @param id Channel ID to use (c can be both owner and client). 1508 * @param ccn Channel ID to use (c can be both owner and client).
1509 */ 1509 */
1510void 1510void
1511GML_send_data (struct CadetClient *c, 1511GML_send_data (struct CadetClient *c,
1512 const struct GNUNET_CADET_ChannelAppDataMessage *msg, 1512 const struct GNUNET_CADET_ChannelAppDataMessage *msg,
1513 struct GNUNET_CADET_ClientChannelNumber id) 1513 struct GNUNET_CADET_ClientChannelNumber ccn)
1514{ 1514{
1515 struct GNUNET_CADET_LocalData *copy; 1515 struct GNUNET_CADET_LocalData *copy;
1516 uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_ChannelAppDataMessage); 1516 uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_CADET_ChannelAppDataMessage);
@@ -1530,7 +1530,7 @@ GML_send_data (struct CadetClient *c,
1530 GNUNET_memcpy (&copy[1], &msg[1], size); 1530 GNUNET_memcpy (&copy[1], &msg[1], size);
1531 copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size); 1531 copy->header.size = htons (sizeof (struct GNUNET_CADET_LocalData) + size);
1532 copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1532 copy->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1533 copy->channel_id = id; 1533 copy->ccn = ccn;
1534 GNUNET_SERVER_notification_context_unicast (nc, c->handle, 1534 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
1535 &copy->header, GNUNET_NO); 1535 &copy->header, GNUNET_NO);
1536} 1536}
diff --git a/src/cadet/gnunet-service-cadet_local.h b/src/cadet/gnunet-service-cadet_local.h
index bf691f9c3..113c2f489 100644
--- a/src/cadet/gnunet-service-cadet_local.h
+++ b/src/cadet/gnunet-service-cadet_local.h
@@ -75,36 +75,36 @@ GML_shutdown (void);
75 * Get a channel from a client. 75 * Get a channel from a client.
76 * 76 *
77 * @param c Client to check. 77 * @param c Client to check.
78 * @param chid Channel ID, must be local (> 0x800...). 78 * @param ccn Channel ID, must be local (> 0x800...).
79 * 79 *
80 * @return non-NULL if channel exists in the clients lists 80 * @return non-NULL if channel exists in the clients lists
81 */ 81 */
82struct CadetChannel * 82struct CadetChannel *
83GML_channel_get (struct CadetClient *c, 83GML_channel_get (struct CadetClient *c,
84 struct GNUNET_CADET_ClientChannelNumber chid); 84 struct GNUNET_CADET_ClientChannelNumber ccn);
85 85
86/** 86/**
87 * Add a channel to a client 87 * Add a channel to a client
88 * 88 *
89 * @param client Client. 89 * @param client Client.
90 * @param chid Channel ID. 90 * @param ccn Channel ID.
91 * @param ch Channel. 91 * @param ch Channel.
92 */ 92 */
93void 93void
94GML_channel_add (struct CadetClient *client, 94GML_channel_add (struct CadetClient *client,
95 struct GNUNET_CADET_ClientChannelNumber chid, 95 struct GNUNET_CADET_ClientChannelNumber ccn,
96 struct CadetChannel *ch); 96 struct CadetChannel *ch);
97 97
98/** 98/**
99 * Remove a channel from a client 99 * Remove a channel from a client
100 * 100 *
101 * @param client Client. 101 * @param client Client.
102 * @param chid Channel ID. 102 * @param ccn Channel ID.
103 * @param ch Channel. 103 * @param ch Channel.
104 */ 104 */
105void 105void
106GML_channel_remove (struct CadetClient *client, 106GML_channel_remove (struct CadetClient *client,
107 struct GNUNET_CADET_ClientChannelNumber chid, 107 struct GNUNET_CADET_ClientChannelNumber ccn,
108 struct CadetChannel *ch); 108 struct CadetChannel *ch);
109 109
110/** 110/**
@@ -115,7 +115,7 @@ GML_channel_remove (struct CadetClient *client,
115 * @return LID of a channel free to use. 115 * @return LID of a channel free to use.
116 */ 116 */
117struct GNUNET_CADET_ClientChannelNumber 117struct GNUNET_CADET_ClientChannelNumber
118GML_get_next_chid (struct CadetClient *c); 118GML_get_next_ccn (struct CadetClient *c);
119 119
120/** 120/**
121 * Check if client has registered with the service and has not disconnected 121 * Check if client has registered with the service and has not disconnected
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 31c9b9e1c..3b21f4107 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -311,7 +311,7 @@ struct CadetTunnel
311 /** 311 /**
312 * Channel ID for the next created channel. 312 * Channel ID for the next created channel.
313 */ 313 */
314 struct GNUNET_CADET_ChannelTunnelNumber next_chid; 314 struct GNUNET_CADET_ChannelTunnelNumber next_ctn;
315 315
316 /** 316 /**
317 * Destroy flag: if true, destroy on last message. 317 * Destroy flag: if true, destroy on last message.
@@ -1563,7 +1563,7 @@ send_channel_destroy (struct CadetTunnel *t,
1563 1563
1564 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1564 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1565 msg.header.size = htons (sizeof (msg)); 1565 msg.header.size = htons (sizeof (msg));
1566 msg.chid = gid; 1566 msg.ctn = gid;
1567 1567
1568 LOG (GNUNET_ERROR_TYPE_DEBUG, 1568 LOG (GNUNET_ERROR_TYPE_DEBUG,
1569 "WARNING destroying unknown channel %u on tunnel %s\n", 1569 "WARNING destroying unknown channel %u on tunnel %s\n",
@@ -1609,7 +1609,7 @@ handle_data (struct CadetTunnel *t,
1609 1609
1610 1610
1611 /* Check channel */ 1611 /* Check channel */
1612 ch = GCT_get_channel (t, msg->chid); 1612 ch = GCT_get_channel (t, msg->ctn);
1613 if (NULL == ch) 1613 if (NULL == ch)
1614 { 1614 {
1615 GNUNET_STATISTICS_update (stats, 1615 GNUNET_STATISTICS_update (stats,
@@ -1618,8 +1618,8 @@ handle_data (struct CadetTunnel *t,
1618 GNUNET_NO); 1618 GNUNET_NO);
1619 LOG (GNUNET_ERROR_TYPE_DEBUG, 1619 LOG (GNUNET_ERROR_TYPE_DEBUG,
1620 "channel 0x%X unknown\n", 1620 "channel 0x%X unknown\n",
1621 ntohl (msg->chid.cn)); 1621 ntohl (msg->ctn.cn));
1622 send_channel_destroy (t, msg->chid); 1622 send_channel_destroy (t, msg->ctn);
1623 return; 1623 return;
1624 } 1624 }
1625 1625
@@ -1654,13 +1654,13 @@ handle_data_ack (struct CadetTunnel *t,
1654 } 1654 }
1655 1655
1656 /* Check channel */ 1656 /* Check channel */
1657 ch = GCT_get_channel (t, msg->chid); 1657 ch = GCT_get_channel (t, msg->ctn);
1658 if (NULL == ch) 1658 if (NULL == ch)
1659 { 1659 {
1660 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel", 1660 GNUNET_STATISTICS_update (stats, "# data ack on unknown channel",
1661 1, GNUNET_NO); 1661 1, GNUNET_NO);
1662 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n", 1662 LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING channel %u unknown\n",
1663 ntohl (msg->chid.cn)); 1663 ntohl (msg->ctn.cn));
1664 return; 1664 return;
1665 } 1665 }
1666 1666
@@ -1690,7 +1690,7 @@ handle_ch_create (struct CadetTunnel *t,
1690 } 1690 }
1691 1691
1692 /* Check channel */ 1692 /* Check channel */
1693 ch = GCT_get_channel (t, msg->chid); 1693 ch = GCT_get_channel (t, msg->ctn);
1694 if (NULL != ch && ! GCT_is_loopback (t)) 1694 if (NULL != ch && ! GCT_is_loopback (t))
1695 { 1695 {
1696 /* Probably a retransmission, safe to ignore */ 1696 /* Probably a retransmission, safe to ignore */
@@ -1725,14 +1725,14 @@ handle_ch_nack (struct CadetTunnel *t,
1725 } 1725 }
1726 1726
1727 /* Check channel */ 1727 /* Check channel */
1728 ch = GCT_get_channel (t, msg->chid); 1728 ch = GCT_get_channel (t, msg->ctn);
1729 if (NULL == ch) 1729 if (NULL == ch)
1730 { 1730 {
1731 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel", 1731 GNUNET_STATISTICS_update (stats, "# channel NACK on unknown channel",
1732 1, GNUNET_NO); 1732 1, GNUNET_NO);
1733 LOG (GNUNET_ERROR_TYPE_DEBUG, 1733 LOG (GNUNET_ERROR_TYPE_DEBUG,
1734 "WARNING channel %u unknown\n", 1734 "WARNING channel %u unknown\n",
1735 ntohl (msg->chid.cn)); 1735 ntohl (msg->ctn.cn));
1736 return; 1736 return;
1737 } 1737 }
1738 1738
@@ -1767,7 +1767,7 @@ handle_ch_ack (struct CadetTunnel *t,
1767 } 1767 }
1768 1768
1769 /* Check channel */ 1769 /* Check channel */
1770 ch = GCT_get_channel (t, msg->chid); 1770 ch = GCT_get_channel (t, msg->ctn);
1771 if (NULL == ch) 1771 if (NULL == ch)
1772 { 1772 {
1773 GNUNET_STATISTICS_update (stats, 1773 GNUNET_STATISTICS_update (stats,
@@ -1776,7 +1776,7 @@ handle_ch_ack (struct CadetTunnel *t,
1776 GNUNET_NO); 1776 GNUNET_NO);
1777 LOG (GNUNET_ERROR_TYPE_DEBUG, 1777 LOG (GNUNET_ERROR_TYPE_DEBUG,
1778 "WARNING channel %u unknown\n", 1778 "WARNING channel %u unknown\n",
1779 ntohl (msg->chid.cn)); 1779 ntohl (msg->ctn.cn));
1780 return; 1780 return;
1781 } 1781 }
1782 1782
@@ -1811,7 +1811,7 @@ handle_ch_destroy (struct CadetTunnel *t,
1811 } 1811 }
1812 1812
1813 /* Check channel */ 1813 /* Check channel */
1814 ch = GCT_get_channel (t, msg->chid); 1814 ch = GCT_get_channel (t, msg->ctn);
1815 if (NULL == ch) 1815 if (NULL == ch)
1816 { 1816 {
1817 /* Probably a retransmission, safe to ignore */ 1817 /* Probably a retransmission, safe to ignore */
@@ -2204,7 +2204,7 @@ GCT_new (struct CadetPeer *destination)
2204 struct CadetTunnel *t; 2204 struct CadetTunnel *t;
2205 2205
2206 t = GNUNET_new (struct CadetTunnel); 2206 t = GNUNET_new (struct CadetTunnel);
2207 t->next_chid.cn = 0; 2207 t->next_ctn.cn = 0;
2208 t->peer = destination; 2208 t->peer = destination;
2209 2209
2210 if (GNUNET_OK != 2210 if (GNUNET_OK !=
@@ -2510,13 +2510,13 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
2510 * Search for a channel by global ID. 2510 * Search for a channel by global ID.
2511 * 2511 *
2512 * @param t Tunnel containing the channel. 2512 * @param t Tunnel containing the channel.
2513 * @param chid Public channel number. 2513 * @param ctn Public channel number.
2514 * 2514 *
2515 * @return channel handler, NULL if doesn't exist 2515 * @return channel handler, NULL if doesn't exist
2516 */ 2516 */
2517struct CadetChannel * 2517struct CadetChannel *
2518GCT_get_channel (struct CadetTunnel *t, 2518GCT_get_channel (struct CadetTunnel *t,
2519 struct GNUNET_CADET_ChannelTunnelNumber chid) 2519 struct GNUNET_CADET_ChannelTunnelNumber ctn)
2520{ 2520{
2521 struct CadetTChannel *iter; 2521 struct CadetTChannel *iter;
2522 2522
@@ -2525,7 +2525,7 @@ GCT_get_channel (struct CadetTunnel *t,
2525 2525
2526 for (iter = t->channel_head; NULL != iter; iter = iter->next) 2526 for (iter = t->channel_head; NULL != iter; iter = iter->next)
2527 { 2527 {
2528 if (GCCH_get_id (iter->ch).cn == chid.cn) 2528 if (GCCH_get_id (iter->ch).cn == ctn.cn)
2529 break; 2529 break;
2530 } 2530 }
2531 2531
@@ -2973,9 +2973,9 @@ GCT_get_destination (struct CadetTunnel *t)
2973 * @return GID of a channel free to use. 2973 * @return GID of a channel free to use.
2974 */ 2974 */
2975struct GNUNET_CADET_ChannelTunnelNumber 2975struct GNUNET_CADET_ChannelTunnelNumber
2976GCT_get_next_chid (struct CadetTunnel *t) 2976GCT_get_next_ctn (struct CadetTunnel *t)
2977{ 2977{
2978 struct GNUNET_CADET_ChannelTunnelNumber chid; 2978 struct GNUNET_CADET_ChannelTunnelNumber ctn;
2979 struct GNUNET_CADET_ChannelTunnelNumber mask; 2979 struct GNUNET_CADET_ChannelTunnelNumber mask;
2980 int result; 2980 int result;
2981 2981
@@ -2988,21 +2988,21 @@ GCT_get_next_chid (struct CadetTunnel *t)
2988 mask.cn = htonl (0x40000000); 2988 mask.cn = htonl (0x40000000);
2989 else 2989 else
2990 mask.cn = 0x0; 2990 mask.cn = 0x0;
2991 t->next_chid.cn |= mask.cn; 2991 t->next_ctn.cn |= mask.cn;
2992 2992
2993 while (NULL != GCT_get_channel (t, t->next_chid)) 2993 while (NULL != GCT_get_channel (t, t->next_ctn))
2994 { 2994 {
2995 LOG (GNUNET_ERROR_TYPE_DEBUG, 2995 LOG (GNUNET_ERROR_TYPE_DEBUG,
2996 "Channel %u exists...\n", 2996 "Channel %u exists...\n",
2997 t->next_chid.cn); 2997 t->next_ctn.cn);
2998 t->next_chid.cn = htonl ((ntohl (t->next_chid.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 2998 t->next_ctn.cn = htonl ((ntohl (t->next_ctn.cn) + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
2999 t->next_chid.cn |= mask.cn; 2999 t->next_ctn.cn |= mask.cn;
3000 } 3000 }
3001 chid = t->next_chid; 3001 ctn = t->next_ctn;
3002 t->next_chid.cn = (t->next_chid.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 3002 t->next_ctn.cn = (t->next_ctn.cn + 1) & ~GNUNET_CADET_LOCAL_CHANNEL_ID_CLI;
3003 t->next_chid.cn |= mask.cn; 3003 t->next_ctn.cn |= mask.cn;
3004 3004
3005 return chid; 3005 return ctn;
3006} 3006}
3007 3007
3008 3008
diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h
index c10815a3b..0abdc02ce 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.h
+++ b/src/cadet/gnunet-service-cadet_tunnel.h
@@ -286,12 +286,12 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch);
286 * Search for a channel by global ID. 286 * Search for a channel by global ID.
287 * 287 *
288 * @param t Tunnel containing the channel. 288 * @param t Tunnel containing the channel.
289 * @param chid Public channel number. 289 * @param ctn Public channel number.
290 * 290 *
291 * @return channel handler, NULL if doesn't exist 291 * @return channel handler, NULL if doesn't exist
292 */ 292 */
293struct CadetChannel * 293struct CadetChannel *
294GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber chid); 294GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber ctn);
295 295
296 296
297/** 297/**
@@ -428,7 +428,7 @@ GCT_get_destination (struct CadetTunnel *t);
428 * @return ID of a channel free to use. 428 * @return ID of a channel free to use.
429 */ 429 */
430struct GNUNET_CADET_ChannelTunnelNumber 430struct GNUNET_CADET_ChannelTunnelNumber
431GCT_get_next_chid (struct CadetTunnel *t); 431GCT_get_next_ctn (struct CadetTunnel *t);
432 432
433 433
434/** 434/**