aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/cadet_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/cadet_api.c')
-rw-r--r--src/cadet/cadet_api.c404
1 files changed, 226 insertions, 178 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 23305d8a9..57a14639d 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V. 3 Copyright (C) 2011, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -19,7 +19,7 @@
19*/ 19*/
20/** 20/**
21 * @file cadet/cadet_api.c 21 * @file cadet/cadet_api.c
22 * @brief cadet api: client implementation of new cadet service 22 * @brief cadet api: client implementation of cadet service
23 * @author Bartlomiej Polot 23 * @author Bartlomiej Polot
24 */ 24 */
25 25
@@ -41,46 +41,48 @@
41 */ 41 */
42struct GNUNET_CADET_TransmitHandle 42struct GNUNET_CADET_TransmitHandle
43{ 43{
44 /** 44 /**
45 * Double Linked list 45 * Double Linked list
46 */ 46 */
47 struct GNUNET_CADET_TransmitHandle *next; 47 struct GNUNET_CADET_TransmitHandle *next;
48 48
49 /** 49 /**
50 * Double Linked list 50 * Double Linked list
51 */ 51 */
52 struct GNUNET_CADET_TransmitHandle *prev; 52 struct GNUNET_CADET_TransmitHandle *prev;
53 53
54 /** 54 /**
55 * Channel this message is sent on / for (may be NULL for control messages). 55 * Channel this message is sent on / for (may be NULL for control messages).
56 */ 56 */
57 struct GNUNET_CADET_Channel *channel; 57 struct GNUNET_CADET_Channel *channel;
58 58
59 /** 59 /**
60 * Request data task. 60 * Request data task.
61 */ 61 */
62 struct GNUNET_SCHEDULER_Task *request_data_task; 62 struct GNUNET_SCHEDULER_Task *request_data_task;
63 63
64 /** 64 /**
65 * Callback to obtain the message to transmit, or NULL if we 65 * Callback to obtain the message to transmit, or NULL if we
66 * got the message in 'data'. Notice that messages built 66 * got the message in 'data'. Notice that messages built
67 * by 'notify' need to be encapsulated with information about 67 * by 'notify' need to be encapsulated with information about
68 * the 'target'. 68 * the 'target'.
69 */ 69 */
70 GNUNET_CONNECTION_TransmitReadyNotify notify; 70 GNUNET_CONNECTION_TransmitReadyNotify notify;
71 71
72 /** 72 /**
73 * Closure for 'notify' 73 * Closure for 'notify'
74 */ 74 */
75 void *notify_cls; 75 void *notify_cls;
76 76
77 /** 77 /**
78 * Size of the payload. 78 * Size of the payload.
79 */ 79 */
80 size_t size; 80 size_t size;
81}; 81};
82 82
83union CadetInfoCB { 83
84union CadetInfoCB
85{
84 86
85 /** 87 /**
86 * Channel callback. 88 * Channel callback.
@@ -114,14 +116,14 @@ union CadetInfoCB {
114 */ 116 */
115struct GNUNET_CADET_Handle 117struct GNUNET_CADET_Handle
116{ 118{
117 /** 119 /**
118 * Message queue (if available). 120 * Message queue (if available).
119 */ 121 */
120 struct GNUNET_MQ_Handle *mq; 122 struct GNUNET_MQ_Handle *mq;
121 123
122 /** 124 /**
123 * Set of handlers used for processing incoming messages in the channels 125 * Set of handlers used for processing incoming messages in the channels
124 */ 126 */
125 const struct GNUNET_CADET_MessageHandler *message_handlers; 127 const struct GNUNET_CADET_MessageHandler *message_handlers;
126 128
127 /** 129 /**
@@ -134,40 +136,40 @@ struct GNUNET_CADET_Handle
134 */ 136 */
135 struct GNUNET_CONTAINER_MultiHashMap *ports; 137 struct GNUNET_CONTAINER_MultiHashMap *ports;
136 138
137 /** 139 /**
138 * Double linked list of the channels this client is connected to, head. 140 * Double linked list of the channels this client is connected to, head.
139 */ 141 */
140 struct GNUNET_CADET_Channel *channels_head; 142 struct GNUNET_CADET_Channel *channels_head;
141 143
142 /** 144 /**
143 * Double linked list of the channels this client is connected to, tail. 145 * Double linked list of the channels this client is connected to, tail.
144 */ 146 */
145 struct GNUNET_CADET_Channel *channels_tail; 147 struct GNUNET_CADET_Channel *channels_tail;
146 148
147 /** 149 /**
148 * Callback for inbound channel disconnection 150 * Callback for inbound channel disconnection
149 */ 151 */
150 GNUNET_CADET_ChannelEndHandler *cleaner; 152 GNUNET_CADET_ChannelEndHandler *cleaner;
151 153
152 /** 154 /**
153 * Closure for all the handlers given by the client 155 * Closure for all the handlers given by the client
154 */ 156 */
155 void *cls; 157 void *cls;
156 158
157 /** 159 /**
158 * Messages to send to the service, head. 160 * Messages to send to the service, head.
159 */ 161 */
160 struct GNUNET_CADET_TransmitHandle *th_head; 162 struct GNUNET_CADET_TransmitHandle *th_head;
161 163
162 /** 164 /**
163 * Messages to send to the service, tail. 165 * Messages to send to the service, tail.
164 */ 166 */
165 struct GNUNET_CADET_TransmitHandle *th_tail; 167 struct GNUNET_CADET_TransmitHandle *th_tail;
166 168
167 /** 169 /**
168 * chid of the next channel to create (to avoid reusing IDs often) 170 * child of the next channel to create (to avoid reusing IDs often)
169 */ 171 */
170 CADET_ChannelNumber next_chid; 172 struct GNUNET_CADET_ClientChannelNumber next_chid;
171 173
172 /** 174 /**
173 * Configuration given by the client, in case of reconnection 175 * Configuration given by the client, in case of reconnection
@@ -201,9 +203,9 @@ struct GNUNET_CADET_Handle
201 */ 203 */
202struct GNUNET_CADET_Peer 204struct GNUNET_CADET_Peer
203{ 205{
204 /** 206 /**
205 * ID of the peer in short form 207 * ID of the peer in short form
206 */ 208 */
207 GNUNET_PEER_Id id; 209 GNUNET_PEER_Id id;
208 210
209 /** 211 /**
@@ -218,34 +220,34 @@ struct GNUNET_CADET_Peer
218 */ 220 */
219struct GNUNET_CADET_Channel 221struct GNUNET_CADET_Channel
220{ 222{
221 /** 223 /**
222 * DLL next 224 * DLL next
223 */ 225 */
224 struct GNUNET_CADET_Channel *next; 226 struct GNUNET_CADET_Channel *next;
225 227
226 /** 228 /**
227 * DLL prev 229 * DLL prev
228 */ 230 */
229 struct GNUNET_CADET_Channel *prev; 231 struct GNUNET_CADET_Channel *prev;
230 232
231 /** 233 /**
232 * Handle to the cadet this channel belongs to 234 * Handle to the cadet this channel belongs to
233 */ 235 */
234 struct GNUNET_CADET_Handle *cadet; 236 struct GNUNET_CADET_Handle *cadet;
235 237
236 /** 238 /**
237 * Local ID of the channel 239 * Local ID of the channel
238 */ 240 */
239 CADET_ChannelNumber chid; 241 struct GNUNET_CADET_ClientChannelNumber chid;
240 242
241 /** 243 /**
242 * Channel's port, if any. 244 * Channel's port, if any.
243 */ 245 */
244 struct GNUNET_CADET_Port *port; 246 struct GNUNET_CADET_Port *port;
245 247
246 /** 248 /**
247 * Other end of the channel. 249 * Other end of the channel.
248 */ 250 */
249 GNUNET_PEER_Id peer; 251 GNUNET_PEER_Id peer;
250 252
251 /** 253 /**
@@ -253,46 +255,47 @@ struct GNUNET_CADET_Channel
253 */ 255 */
254 void *ctx; 256 void *ctx;
255 257
256 /** 258 /**
257 * Size of packet queued in this channel 259 * Size of packet queued in this channel
258 */ 260 */
259 unsigned int packet_size; 261 unsigned int packet_size;
260 262
261 /** 263 /**
262 * Channel options: reliability, etc. 264 * Channel options: reliability, etc.
263 */ 265 */
264 enum GNUNET_CADET_ChannelOption options; 266 enum GNUNET_CADET_ChannelOption options;
265 267
266 /** 268 /**
267 * Are we allowed to send to the service? 269 * Are we allowed to send to the service?
268 */ 270 */
269 int allow_send; 271 int allow_send;
270 272
271}; 273};
272 274
275
273/** 276/**
274 * Opaque handle to a port. 277 * Opaque handle to a port.
275 */ 278 */
276struct GNUNET_CADET_Port 279struct GNUNET_CADET_Port
277{ 280{
278 /** 281 /**
279 * Handle to the CADET session this port belongs to. 282 * Handle to the CADET session this port belongs to.
280 */ 283 */
281 struct GNUNET_CADET_Handle *cadet; 284 struct GNUNET_CADET_Handle *cadet;
282 285
283 /** 286 /**
284 * Port ID. 287 * Port ID.
285 */ 288 */
286 struct GNUNET_HashCode *hash; 289 struct GNUNET_HashCode *hash;
287 290
288 /** 291 /**
289 * Callback handler for incoming channels on this port. 292 * Callback handler for incoming channels on this port.
290 */ 293 */
291 GNUNET_CADET_InboundChannelNotificationHandler *handler; 294 GNUNET_CADET_InboundChannelNotificationHandler *handler;
292 295
293 /** 296 /**
294 * Closure for @a handler. 297 * Closure for @a handler.
295 */ 298 */
296 void *cls; 299 void *cls;
297}; 300};
298 301
@@ -356,22 +359,20 @@ find_port (const struct GNUNET_CADET_Handle *h,
356 359
357/** 360/**
358 * 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 *
359 * @param h Cadet handle 363 * @param h Cadet handle
360 * @param chid ID of the wanted channel 364 * @param chid ID of the wanted channel
361 * @return handle to the required channel or NULL if not found 365 * @return handle to the required channel or NULL if not found
362 */ 366 */
363static struct GNUNET_CADET_Channel * 367static struct GNUNET_CADET_Channel *
364retrieve_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid) 368retrieve_channel (struct GNUNET_CADET_Handle *h,
369 struct GNUNET_CADET_ClientChannelNumber chid)
365{ 370{
366 struct GNUNET_CADET_Channel *ch; 371 struct GNUNET_CADET_Channel *ch;
367 372
368 ch = h->channels_head; 373 for (ch = h->channels_head; NULL != ch; ch = ch->next)
369 while (ch != NULL) 374 if (ch->chid.channel_of_client == chid.channel_of_client)
370 {
371 if (ch->chid == chid)
372 return ch; 375 return ch;
373 ch = ch->next;
374 }
375 return NULL; 376 return NULL;
376} 377}
377 378
@@ -385,21 +386,27 @@ retrieve_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid)
385 * @return Handle to the created channel. 386 * @return Handle to the created channel.
386 */ 387 */
387static struct GNUNET_CADET_Channel * 388static struct GNUNET_CADET_Channel *
388create_channel (struct GNUNET_CADET_Handle *h, CADET_ChannelNumber chid) 389create_channel (struct GNUNET_CADET_Handle *h,
390 struct GNUNET_CADET_ClientChannelNumber chid)
389{ 391{
390 struct GNUNET_CADET_Channel *ch; 392 struct GNUNET_CADET_Channel *ch;
391 393
392 ch = GNUNET_new (struct GNUNET_CADET_Channel); 394 ch = GNUNET_new (struct GNUNET_CADET_Channel);
393 GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch); 395 GNUNET_CONTAINER_DLL_insert (h->channels_head,
396 h->channels_tail,
397 ch);
394 ch->cadet = h; 398 ch->cadet = h;
395 if (0 == chid) 399 if (0 == chid.channel_of_client)
396 { 400 {
397 ch->chid = h->next_chid; 401 ch->chid = h->next_chid;
398 while (NULL != retrieve_channel (h, h->next_chid)) 402 while (NULL != retrieve_channel (h,
403 h->next_chid))
399 { 404 {
400 h->next_chid++; 405 h->next_chid.channel_of_client
401 h->next_chid &= ~GNUNET_CADET_LOCAL_CHANNEL_ID_SERV; 406 = htonl (1 + ntohl (h->next_chid.channel_of_client));
402 h->next_chid |= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 407 if (0 == ntohl (h->next_chid.channel_of_client))
408 h->next_chid.channel_of_client
409 = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
403 } 410 }
404 } 411 }
405 else 412 else
@@ -440,7 +447,9 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner)
440 } 447 }
441 h = ch->cadet; 448 h = ch->cadet;
442 449
443 GNUNET_CONTAINER_DLL_remove (h->channels_head, h->channels_tail, ch); 450 GNUNET_CONTAINER_DLL_remove (h->channels_head,
451 h->channels_tail,
452 ch);
444 453
445 /* signal channel destruction */ 454 /* signal channel destruction */
446 if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) ) 455 if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) )
@@ -466,7 +475,7 @@ destroy_channel (struct GNUNET_CADET_Channel *ch, int call_cleaner)
466 if (0 != ch->peer) 475 if (0 != ch->peer)
467 GNUNET_PEER_change_rc (ch->peer, -1); 476 GNUNET_PEER_change_rc (ch->peer, -1);
468 GNUNET_free (ch); 477 GNUNET_free (ch);
469 return; 478
470} 479}
471 480
472 481
@@ -516,13 +525,15 @@ send_ack (struct GNUNET_CADET_Channel *ch)
516 struct GNUNET_CADET_LocalAck *msg; 525 struct GNUNET_CADET_LocalAck *msg;
517 struct GNUNET_MQ_Envelope *env; 526 struct GNUNET_MQ_Envelope *env;
518 527
519 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 528 env = GNUNET_MQ_msg (msg,
520 529 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
521 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on channel %X\n", ch->chid);
522 msg->channel_id = htonl (ch->chid);
523 GNUNET_MQ_send (ch->cadet->mq, env);
524 530
525 return; 531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "Sending ACK on channel %X\n",
533 ch->chid.channel_of_client);
534 msg->channel_id = ch->chid;
535 GNUNET_MQ_send (ch->cadet->mq,
536 env);
526} 537}
527 538
528 539
@@ -555,13 +566,16 @@ request_data (void *cls)
555 th->channel->packet_size = 0; 566 th->channel->packet_size = 0;
556 remove_from_queue (th); 567 remove_from_queue (th);
557 568
558 env = GNUNET_MQ_msg_extra (msg, th->size, 569 env = GNUNET_MQ_msg_extra (msg,
570 th->size,
559 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 571 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
560 msg->id = htonl (th->channel->chid); 572 msg->id = th->channel->chid;
561 osize = th->notify (th->notify_cls, th->size, &msg[1]); 573 osize = th->notify (th->notify_cls,
574 th->size,
575 &msg[1]);
562 GNUNET_assert (osize == th->size); 576 GNUNET_assert (osize == th->size);
563 GNUNET_MQ_send (th->channel->cadet->mq, env); 577 GNUNET_MQ_send (th->channel->cadet->mq,
564 578 env);
565 GNUNET_free (th); 579 GNUNET_free (th);
566} 580}
567 581
@@ -580,13 +594,15 @@ handle_channel_created (void *cls,
580 struct GNUNET_CADET_Channel *ch; 594 struct GNUNET_CADET_Channel *ch;
581 struct GNUNET_CADET_Port *port; 595 struct GNUNET_CADET_Port *port;
582 const struct GNUNET_HashCode *port_number; 596 const struct GNUNET_HashCode *port_number;
583 CADET_ChannelNumber chid; 597 struct GNUNET_CADET_ClientChannelNumber chid;
584 598
585 chid = ntohl (msg->channel_id); 599 chid = msg->channel_id;
586 port_number = &msg->port; 600 port_number = &msg->port;
587 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming channel %X [%s]\n", 601 LOG (GNUNET_ERROR_TYPE_DEBUG,
588 chid, GNUNET_h2s (port_number)); 602 "Creating incoming channel %X [%s]\n",
589 if (chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 603 ntohl (chid.channel_of_client),
604 GNUNET_h2s (port_number));
605 if (ntohl (chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
590 { 606 {
591 GNUNET_break (0); 607 GNUNET_break (0);
592 return; 608 return;
@@ -636,18 +652,24 @@ handle_channel_destroy (void *cls,
636{ 652{
637 struct GNUNET_CADET_Handle *h = cls; 653 struct GNUNET_CADET_Handle *h = cls;
638 struct GNUNET_CADET_Channel *ch; 654 struct GNUNET_CADET_Channel *ch;
639 CADET_ChannelNumber chid; 655 struct GNUNET_CADET_ClientChannelNumber chid;
640 656
641 chid = ntohl (msg->channel_id); 657 chid = msg->channel_id;
642 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %X Destroy from service\n", chid); 658 LOG (GNUNET_ERROR_TYPE_DEBUG,
643 ch = retrieve_channel (h, chid); 659 "Channel %X Destroy from service\n",
660 ntohl (chid.channel_of_client));
661 ch = retrieve_channel (h,
662 chid);
644 663
645 if (NULL == ch) 664 if (NULL == ch)
646 { 665 {
647 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid); 666 LOG (GNUNET_ERROR_TYPE_DEBUG,
667 "channel %X unknown\n",
668 ntohl (chid.channel_of_client));
648 return; 669 return;
649 } 670 }
650 destroy_channel (ch, GNUNET_YES); 671 destroy_channel (ch,
672 GNUNET_YES);
651} 673}
652 674
653 675
@@ -674,7 +696,8 @@ check_local_data (void *cls,
674 return GNUNET_SYSERR; 696 return GNUNET_SYSERR;
675 } 697 }
676 698
677 ch = retrieve_channel (h, ntohl (message->id)); 699 ch = retrieve_channel (h,
700 message->id);
678 if (NULL == ch) 701 if (NULL == ch)
679 { 702 {
680 GNUNET_break_op (0); 703 GNUNET_break_op (0);
@@ -702,14 +725,17 @@ handle_local_data (void *cls,
702 unsigned int i; 725 unsigned int i;
703 uint16_t type; 726 uint16_t type;
704 727
705 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n"); 728 LOG (GNUNET_ERROR_TYPE_DEBUG,
706 ch = retrieve_channel (h, ntohl (message->id)); 729 "Got a data message!\n");
730 ch = retrieve_channel (h, message->id);
707 GNUNET_assert (NULL != ch); 731 GNUNET_assert (NULL != ch);
708 732
709 payload = (struct GNUNET_MessageHeader *) &message[1]; 733 payload = (struct GNUNET_MessageHeader *) &message[1];
710 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n", 734 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
711 GC_f2s (ch->chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV), 735 GC_f2s (ntohl (ch->chid.channel_of_client) >=
712 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (message->id)); 736 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI),
737 GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)),
738 ntohl (message->id.channel_of_client));
713 739
714 type = ntohs (payload->type); 740 type = ntohs (payload->type);
715 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type)); 741 LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GC_m2s (type));
@@ -751,17 +777,21 @@ handle_local_ack (void *cls,
751{ 777{
752 struct GNUNET_CADET_Handle *h = cls; 778 struct GNUNET_CADET_Handle *h = cls;
753 struct GNUNET_CADET_Channel *ch; 779 struct GNUNET_CADET_Channel *ch;
754 CADET_ChannelNumber chid; 780 struct GNUNET_CADET_ClientChannelNumber chid;
755 781
756 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n"); 782 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
757 chid = ntohl (message->channel_id); 783 chid = message->channel_id;
758 ch = retrieve_channel (h, chid); 784 ch = retrieve_channel (h, chid);
759 if (NULL == ch) 785 if (NULL == ch)
760 { 786 {
761 LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK on unknown channel %X\n", chid); 787 LOG (GNUNET_ERROR_TYPE_DEBUG,
788 "ACK on unknown channel %X\n",
789 ntohl (chid.channel_of_client));
762 return; 790 return;
763 } 791 }
764 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid); 792 LOG (GNUNET_ERROR_TYPE_DEBUG,
793 " on channel %X!\n",
794 ntohl (ch->chid.channel_of_client));
765 ch->allow_send = GNUNET_YES; 795 ch->allow_send = GNUNET_YES;
766 if (0 < ch->packet_size) 796 if (0 < ch->packet_size)
767 { 797 {
@@ -1132,9 +1162,12 @@ handle_get_tunnels (void *cls,
1132{ 1162{
1133 struct GNUNET_CADET_Handle *h = cls; 1163 struct GNUNET_CADET_Handle *h = cls;
1134 1164
1135 h->info_cb.tunnels_cb (h->info_cls, &msg->destination, 1165 h->info_cb.tunnels_cb (h->info_cls,
1136 ntohl (msg->channels), ntohl (msg->connections), 1166 &msg->destination,
1137 ntohs (msg->estate), ntohs (msg->cstate)); 1167 ntohl (msg->channels),
1168 ntohl (msg->connections),
1169 ntohs (msg->estate),
1170 ntohs (msg->cstate));
1138 1171
1139} 1172}
1140 1173
@@ -1170,13 +1203,14 @@ check_get_tunnel (void *cls,
1170 if (esize > msize) 1203 if (esize > msize)
1171 { 1204 {
1172 GNUNET_break_op (0); 1205 GNUNET_break_op (0);
1173 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1206 h->info_cb.tunnel_cb (h->info_cls,
1207 NULL, 0, 0, NULL, NULL, 0, 0);
1174 goto clean_cls; 1208 goto clean_cls;
1175 } 1209 }
1176 ch_n = ntohl (msg->channels); 1210 ch_n = ntohl (msg->channels);
1177 c_n = ntohl (msg->connections); 1211 c_n = ntohl (msg->connections);
1178 esize += ch_n * sizeof (CADET_ChannelNumber); 1212 esize += ch_n * sizeof (struct GNUNET_CADET_ChannelNumber);
1179 esize += c_n * sizeof (struct GNUNET_CADET_Hash); 1213 esize += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier);
1180 if (msize != esize) 1214 if (msize != esize)
1181 { 1215 {
1182 GNUNET_break_op (0); 1216 GNUNET_break_op (0);
@@ -1186,7 +1220,8 @@ check_get_tunnel (void *cls,
1186 (unsigned int) esize, 1220 (unsigned int) esize,
1187 ch_n, 1221 ch_n,
1188 c_n); 1222 c_n);
1189 h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0); 1223 h->info_cb.tunnel_cb (h->info_cls,
1224 NULL, 0, 0, NULL, NULL, 0, 0);
1190 goto clean_cls; 1225 goto clean_cls;
1191 } 1226 }
1192 1227
@@ -1212,18 +1247,23 @@ handle_get_tunnel (void *cls,
1212 struct GNUNET_CADET_Handle *h = cls; 1247 struct GNUNET_CADET_Handle *h = cls;
1213 unsigned int ch_n; 1248 unsigned int ch_n;
1214 unsigned int c_n; 1249 unsigned int c_n;
1215 struct GNUNET_CADET_Hash *conns; 1250 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns;
1216 CADET_ChannelNumber *chns; 1251 const struct GNUNET_CADET_ChannelNumber *chns;
1217 1252
1218 ch_n = ntohl (msg->channels); 1253 ch_n = ntohl (msg->channels);
1219 c_n = ntohl (msg->connections); 1254 c_n = ntohl (msg->connections);
1220 1255
1221 /* Call Callback with tunnel info. */ 1256 /* Call Callback with tunnel info. */
1222 conns = (struct GNUNET_CADET_Hash *) &msg[1]; 1257 conns = (const struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
1223 chns = (CADET_ChannelNumber *) &conns[c_n]; 1258 chns = (const struct GNUNET_CADET_ChannelNumber *) &conns[c_n];
1224 h->info_cb.tunnel_cb (h->info_cls, &msg->destination, 1259 h->info_cb.tunnel_cb (h->info_cls,
1225 ch_n, c_n, chns, conns, 1260 &msg->destination,
1226 ntohs (msg->estate), ntohs (msg->cstate)); 1261 ch_n,
1262 c_n,
1263 chns,
1264 conns,
1265 ntohs (msg->estate),
1266 ntohs (msg->cstate));
1227} 1267}
1228 1268
1229 1269
@@ -1343,9 +1383,10 @@ reconnect (struct GNUNET_CADET_Handle *h)
1343/******************************************************************************/ 1383/******************************************************************************/
1344 1384
1345struct GNUNET_CADET_Handle * 1385struct GNUNET_CADET_Handle *
1346GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, 1386GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1347 GNUNET_CADET_ChannelEndHandler cleaner, 1387 void *cls,
1348 const struct GNUNET_CADET_MessageHandler *handlers) 1388 GNUNET_CADET_ChannelEndHandler cleaner,
1389 const struct GNUNET_CADET_MessageHandler *handlers)
1349{ 1390{
1350 struct GNUNET_CADET_Handle *h; 1391 struct GNUNET_CADET_Handle *h;
1351 1392
@@ -1364,7 +1405,7 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls,
1364 } 1405 }
1365 h->cls = cls; 1406 h->cls = cls;
1366 h->message_handlers = handlers; 1407 h->message_handlers = handlers;
1367 h->next_chid = GNUNET_CADET_LOCAL_CHANNEL_ID_CLI; 1408 h->next_chid.channel_of_client = htonl (GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1368 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; 1409 h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS;
1369 h->reconnect_task = NULL; 1410 h->reconnect_task = NULL;
1370 1411
@@ -1384,21 +1425,24 @@ GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle)
1384 struct GNUNET_CADET_Channel *aux; 1425 struct GNUNET_CADET_Channel *aux;
1385 struct GNUNET_CADET_TransmitHandle *th; 1426 struct GNUNET_CADET_TransmitHandle *th;
1386 1427
1387 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET DISCONNECT\n"); 1428 LOG (GNUNET_ERROR_TYPE_DEBUG,
1388 1429 "CADET DISCONNECT\n");
1389 ch = handle->channels_head; 1430 ch = handle->channels_head;
1390 while (NULL != ch) 1431 while (NULL != ch)
1391 { 1432 {
1392 aux = ch->next; 1433 aux = ch->next;
1393 if (ch->chid < GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 1434 if (ntohl (ch->chid.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1394 { 1435 {
1395 GNUNET_break (0); 1436 GNUNET_break (0);
1396 LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X not destroyed\n", ch->chid); 1437 LOG (GNUNET_ERROR_TYPE_DEBUG,
1438 "channel %X not destroyed\n",
1439 ntohl (ch->chid.channel_of_client));
1397 } 1440 }
1398 destroy_channel (ch, GNUNET_YES); 1441 destroy_channel (ch,
1442 GNUNET_YES);
1399 ch = aux; 1443 ch = aux;
1400 } 1444 }
1401 while ( (th = handle->th_head) != NULL) 1445 while (NULL != (th = handle->th_head))
1402 { 1446 {
1403 struct GNUNET_MessageHeader *msg; 1447 struct GNUNET_MessageHeader *msg;
1404 1448
@@ -1534,24 +1578,27 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
1534 struct GNUNET_CADET_ChannelCreateMessage *msg; 1578 struct GNUNET_CADET_ChannelCreateMessage *msg;
1535 struct GNUNET_MQ_Envelope *env; 1579 struct GNUNET_MQ_Envelope *env;
1536 struct GNUNET_CADET_Channel *ch; 1580 struct GNUNET_CADET_Channel *ch;
1581 struct GNUNET_CADET_ClientChannelNumber chid;
1537 1582
1538 LOG (GNUNET_ERROR_TYPE_DEBUG, 1583 LOG (GNUNET_ERROR_TYPE_DEBUG,
1539 "Creating new channel to %s:%u\n", 1584 "Creating new channel to %s:%u\n",
1540 GNUNET_i2s (peer), port); 1585 GNUNET_i2s (peer), port);
1541 ch = create_channel (h, 0); 1586 chid.channel_of_client = htonl (0);
1587 ch = create_channel (h, chid);
1542 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch); 1588 LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", ch);
1543 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", ch->chid); 1589 LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n",
1590 ntohl (ch->chid.channel_of_client));
1544 ch->ctx = channel_ctx; 1591 ch->ctx = channel_ctx;
1545 ch->peer = GNUNET_PEER_intern (peer); 1592 ch->peer = GNUNET_PEER_intern (peer);
1546 1593
1547 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE); 1594 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE);
1548 msg->channel_id = htonl (ch->chid); 1595 msg->channel_id = ch->chid;
1549 msg->port = *port; 1596 msg->port = *port;
1550 msg->peer = *peer; 1597 msg->peer = *peer;
1551 msg->opt = htonl (options); 1598 msg->opt = htonl (options);
1552 ch->allow_send = GNUNET_NO; 1599 ch->allow_send = GNUNET_NO;
1553 GNUNET_MQ_send (h->mq, env); 1600 GNUNET_MQ_send (h->mq,
1554 1601 env);
1555 return ch; 1602 return ch;
1556} 1603}
1557 1604
@@ -1590,7 +1637,7 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1590 } 1637 }
1591 1638
1592 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); 1639 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY);
1593 msg->channel_id = htonl (channel->chid); 1640 msg->channel_id = channel->chid;
1594 GNUNET_MQ_send (h->mq, env); 1641 GNUNET_MQ_send (h->mq, env);
1595 1642
1596 destroy_channel (channel, GNUNET_YES); 1643 destroy_channel (channel, GNUNET_YES);
@@ -1617,7 +1664,7 @@ GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
1617 { 1664 {
1618 case GNUNET_CADET_OPTION_NOBUFFER: 1665 case GNUNET_CADET_OPTION_NOBUFFER:
1619 case GNUNET_CADET_OPTION_RELIABLE: 1666 case GNUNET_CADET_OPTION_RELIABLE:
1620 case GNUNET_CADET_OPTION_OOORDER: 1667 case GNUNET_CADET_OPTION_OUT_OF_ORDER:
1621 if (0 != (option & channel->options)) 1668 if (0 != (option & channel->options))
1622 bool_flag = GNUNET_YES; 1669 bool_flag = GNUNET_YES;
1623 else 1670 else
@@ -1651,7 +1698,8 @@ GNUNET_CADET_notify_transmit_ready (struct GNUNET_CADET_Channel *channel,
1651 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n"); 1698 LOG (GNUNET_ERROR_TYPE_DEBUG, "CADET NOTIFY TRANSMIT READY\n");
1652 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid); 1699 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", channel->chid);
1653 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send); 1700 LOG (GNUNET_ERROR_TYPE_DEBUG, " allow_send %d\n", channel->allow_send);
1654 if (channel->chid >= GNUNET_CADET_LOCAL_CHANNEL_ID_SERV) 1701 if (ntohl (channel->chid.channel_of_client) >=
1702 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
1655 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n"); 1703 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin\n");
1656 else 1704 else
1657 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n"); 1705 LOG (GNUNET_ERROR_TYPE_DEBUG, " to destination\n");
@@ -1946,7 +1994,7 @@ GNUNET_CADET_show_channel (struct GNUNET_CADET_Handle *h,
1946 1994
1947 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL); 1995 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_CHANNEL);
1948 msg->peer = *initiator; 1996 msg->peer = *initiator;
1949 msg->channel_id = htonl (channel_number); 1997 msg->channel_id.channel_of_client = htonl (channel_number);
1950 GNUNET_MQ_send (h->mq, env); 1998 GNUNET_MQ_send (h->mq, env);
1951 1999
1952 h->info_cb.channel_cb = callback; 2000 h->info_cb.channel_cb = callback;