aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-18 19:24:33 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-18 19:24:33 +0100
commitdfde8ea01a08a32340a47df29ffc2571c031488b (patch)
tree81abde784965de4a4d3f32f882a39353cc96a88d /src
parent3edc21c27d208e45dc1af76131a480a3ebf1e8d3 (diff)
downloadgnunet-dfde8ea01a08a32340a47df29ffc2571c031488b.tar.gz
gnunet-dfde8ea01a08a32340a47df29ffc2571c031488b.zip
create matching connection objects for inbound connections
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_api.c6
-rw-r--r--src/cadet/cadet_protocol.h85
-rw-r--r--src/cadet/gnunet-cadet.c2
-rw-r--r--src/cadet/gnunet-service-cadet-new.c6
-rw-r--r--src/cadet/gnunet-service-cadet-new.h11
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c110
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.h4
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.c92
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.h23
-rw-r--r--src/cadet/gnunet-service-cadet-new_core.c174
-rw-r--r--src/cadet/gnunet-service-cadet-new_paths.c18
-rw-r--r--src/cadet/gnunet-service-cadet-new_paths.h14
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.c13
-rw-r--r--src/cadet/gnunet-service-cadet-new_peer.h10
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c53
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.h26
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c6
-rw-r--r--src/cadet/gnunet-service-cadet_channel.h2
-rw-r--r--src/cadet/gnunet-service-cadet_local.c4
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c12
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.h4
-rw-r--r--src/include/gnunet_cadet_service.h20
22 files changed, 499 insertions, 196 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 4a662487c..8f1274d63 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -1209,7 +1209,7 @@ check_get_tunnel (void *cls,
1209 } 1209 }
1210 ch_n = ntohl (msg->channels); 1210 ch_n = ntohl (msg->channels);
1211 c_n = ntohl (msg->connections); 1211 c_n = ntohl (msg->connections);
1212 esize += ch_n * sizeof (struct GNUNET_CADET_ChannelNumber); 1212 esize += ch_n * sizeof (struct GNUNET_CADET_ChannelTunnelNumber);
1213 esize += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier); 1213 esize += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier);
1214 if (msize != esize) 1214 if (msize != esize)
1215 { 1215 {
@@ -1248,14 +1248,14 @@ handle_get_tunnel (void *cls,
1248 unsigned int ch_n; 1248 unsigned int ch_n;
1249 unsigned int c_n; 1249 unsigned int c_n;
1250 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns; 1250 const struct GNUNET_CADET_ConnectionTunnelIdentifier *conns;
1251 const struct GNUNET_CADET_ChannelNumber *chns; 1251 const struct GNUNET_CADET_ChannelTunnelNumber *chns;
1252 1252
1253 ch_n = ntohl (msg->channels); 1253 ch_n = ntohl (msg->channels);
1254 c_n = ntohl (msg->connections); 1254 c_n = ntohl (msg->connections);
1255 1255
1256 /* Call Callback with tunnel info. */ 1256 /* Call Callback with tunnel info. */
1257 conns = (const struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1]; 1257 conns = (const struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
1258 chns = (const struct GNUNET_CADET_ChannelNumber *) &conns[c_n]; 1258 chns = (const struct GNUNET_CADET_ChannelTunnelNumber *) &conns[c_n];
1259 h->info_cb.tunnel_cb (h->info_cls, 1259 h->info_cb.tunnel_cb (h->info_cls,
1260 &msg->destination, 1260 &msg->destination,
1261 ch_n, 1261 ch_n,
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 7e4a6ae16..cf32e0d6d 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -113,7 +113,7 @@ struct GNUNET_CADET_ConnectionCreateMessageAckMessage
113struct GNUNET_CADET_ConnectionBrokenMessage 113struct GNUNET_CADET_ConnectionBrokenMessage
114{ 114{
115 /** 115 /**
116 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN 116 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
117 */ 117 */
118 struct GNUNET_MessageHeader header; 118 struct GNUNET_MessageHeader header;
119 119
@@ -350,7 +350,6 @@ struct GNUNET_CADET_ConnectionEncryptedAckMessage
350/******************************* CHANNEL ***********************************/ 350/******************************* CHANNEL ***********************************/
351/******************************************************************************/ 351/******************************************************************************/
352 352
353#ifndef NEW_CADET
354 353
355/** 354/**
356 * Message to create a Channel. 355 * Message to create a Channel.
@@ -373,12 +372,11 @@ struct GNUNET_CADET_ChannelOpenMessage
373 struct GNUNET_HashCode port; 372 struct GNUNET_HashCode port;
374 373
375 /** 374 /**
376 * ID of the channel 375 * ID of the channel within the tunnel.
377 */ 376 */
378 struct GNUNET_CADET_ChannelNumber chid; 377 struct GNUNET_CADET_ChannelTunnelNumber chid;
379}; 378};
380 379
381#endif
382 380
383/** 381/**
384 * Message to manage a Channel (ACK, NACK, Destroy). 382 * Message to manage a Channel (ACK, NACK, Destroy).
@@ -400,7 +398,7 @@ struct GNUNET_CADET_ChannelManageMessage
400 /** 398 /**
401 * ID of the channel 399 * ID of the channel
402 */ 400 */
403 struct GNUNET_CADET_ChannelNumber chid; 401 struct GNUNET_CADET_ChannelTunnelNumber chid;
404}; 402};
405 403
406 404
@@ -426,7 +424,7 @@ struct GNUNET_CADET_ChannelAppDataMessage
426 /** 424 /**
427 * ID of the channel 425 * ID of the channel
428 */ 426 */
429 struct GNUNET_CADET_ChannelNumber chid; 427 struct GNUNET_CADET_ChannelTunnelNumber chid;
430 428
431 /** 429 /**
432 * Payload follows 430 * Payload follows
@@ -447,7 +445,7 @@ struct GNUNET_CADET_ChannelDataAckMessage
447 /** 445 /**
448 * ID of the channel 446 * ID of the channel
449 */ 447 */
450 struct GNUNET_CADET_ChannelNumber chid; 448 struct GNUNET_CADET_ChannelTunnelNumber chid;
451 449
452 /** 450 /**
453 * Bitfield of already-received newer messages 451 * Bitfield of already-received newer messages
@@ -463,6 +461,77 @@ struct GNUNET_CADET_ChannelDataAckMessage
463 uint32_t mid GNUNET_PACKED; 461 uint32_t mid GNUNET_PACKED;
464}; 462};
465 463
464#else
465
466
467/**
468 * Number used to uniquely identify messages in a CADET Channel.
469 */
470struct ChannelMessageIdentifier
471{
472 /**
473 * Unique ID of the message, cycles around, in NBO.
474 */
475 uint32_t mid GNUNET_PACKED;
476};
477
478
479/**
480 * Message for cadet data traffic.
481 */
482struct GNUNET_CADET_ChannelAppDataMessage
483{
484 /**
485 * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
486 * #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
487 */
488 struct GNUNET_MessageHeader header;
489
490 /**
491 * Unique ID of the payload message.
492 */
493 struct ChannelMessageIdentifier mid;
494
495 /**
496 * ID of the channel
497 */
498 struct GNUNET_CADET_ChannelTunnelNumber gid;
499
500 /**
501 * Payload follows
502 */
503};
504
505
506/**
507 * Message to acknowledge end-to-end data.
508 */
509struct GNUNET_CADET_ChannelDataAckMessage
510{
511 /**
512 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
513 */
514 struct GNUNET_MessageHeader header;
515
516 /**
517 * ID of the channel
518 */
519 struct GNUNET_CADET_ChannelTunnelNumber gid;
520
521 /**
522 * Bitfield of already-received messages past @e mid.
523 * pid + 1 @ LSB
524 * pid + 64 @ MSB
525 */
526 uint64_t futures GNUNET_PACKED;
527
528 /**
529 * Last message ID received.
530 */
531 struct ChannelMessageIdentifier mid;
532};
533
534
466#endif 535#endif
467 536
468GNUNET_NETWORK_STRUCT_END 537GNUNET_NETWORK_STRUCT_END
diff --git a/src/cadet/gnunet-cadet.c b/src/cadet/gnunet-cadet.c
index 72d7bf8a9..80010ec54 100644
--- a/src/cadet/gnunet-cadet.c
+++ b/src/cadet/gnunet-cadet.c
@@ -727,7 +727,7 @@ tunnel_callback (void *cls,
727 const struct GNUNET_PeerIdentity *peer, 727 const struct GNUNET_PeerIdentity *peer,
728 unsigned int n_channels, 728 unsigned int n_channels,
729 unsigned int n_connections, 729 unsigned int n_connections,
730 const struct GNUNET_CADET_ChannelNumber *channels, 730 const struct GNUNET_CADET_ChannelTunnelNumber *channels,
731 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections, 731 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
732 unsigned int estate, 732 unsigned int estate,
733 unsigned int cstate) 733 unsigned int cstate)
diff --git a/src/cadet/gnunet-service-cadet-new.c b/src/cadet/gnunet-service-cadet-new.c
index 3e149e9bb..2f6cc7b11 100644
--- a/src/cadet/gnunet-service-cadet-new.c
+++ b/src/cadet/gnunet-service-cadet-new.c
@@ -911,8 +911,8 @@ iter_channel (void *cls,
911{ 911{
912 struct GNUNET_CADET_LocalInfoTunnel *msg = cls; 912 struct GNUNET_CADET_LocalInfoTunnel *msg = cls;
913 struct GNUNET_CADET_ConnectionTunnelIdentifier *h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1]; 913 struct GNUNET_CADET_ConnectionTunnelIdentifier *h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
914 struct GCT_ChannelTunnelNumber *chn 914 struct GNUNET_CADET_ChannelTunnelNumber *chn
915 = (struct GCT_ChannelTunnelNumber *) &h[msg->connections]; 915 = (struct GNUNET_CADET_ChannelTunnelNumber *) &h[msg->connections];
916 916
917 chn[msg->channels++] = GCCH_get_id (ch); 917 chn[msg->channels++] = GCCH_get_id (ch);
918} 918}
@@ -963,7 +963,7 @@ handle_show_tunnel (void *cls,
963 c_n = GCT_count_any_connections (t); 963 c_n = GCT_count_any_connections (t);
964 env = GNUNET_MQ_msg_extra (resp, 964 env = GNUNET_MQ_msg_extra (resp,
965 c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier) + 965 c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier) +
966 ch_n * sizeof (struct GCT_ChannelTunnelNumber), 966 ch_n * sizeof (struct GNUNET_CADET_ChannelTunnelNumber),
967 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL); 967 GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL);
968 resp->destination = msg->peer; 968 resp->destination = msg->peer;
969 /* Do not reorder! #iter_channel needs counters in HBO! */ 969 /* Do not reorder! #iter_channel needs counters in HBO! */
diff --git a/src/cadet/gnunet-service-cadet-new.h b/src/cadet/gnunet-service-cadet-new.h
index 3258a6666..862a0f088 100644
--- a/src/cadet/gnunet-service-cadet-new.h
+++ b/src/cadet/gnunet-service-cadet-new.h
@@ -29,6 +29,7 @@
29#define GNUNET_SERVICE_CADET_H 29#define GNUNET_SERVICE_CADET_H
30 30
31#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
32#define NEW_CADET 1
32 33
33/** 34/**
34 * A client to the CADET service. Each client gets a unique handle. 35 * A client to the CADET service. Each client gets a unique handle.
@@ -113,6 +114,16 @@ struct CadetTConnection;
113struct CadetConnection; 114struct CadetConnection;
114 115
115/** 116/**
117 * Description of a segment of a `struct CadetConnection` at the
118 * intermediate peers. Routes are basically entries in a peer's
119 * routing table for forwarding traffic. At both endpoints, the
120 * routes are terminated by a `struct CadetConnection`, which knows
121 * the complete `struct CadetPath` that is formed by the individual
122 * routes.
123 */
124struct CadetRoute;
125
126/**
116 * Logical end-to-end conenction between clients. There can be 127 * Logical end-to-end conenction between clients. There can be
117 * any number of channels between clients. 128 * any number of channels between clients.
118 */ 129 */
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index 32e4c6269..dcbc5614f 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -51,108 +51,6 @@
51#define TIMEOUT_CLOSED_PORT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 51#define TIMEOUT_CLOSED_PORT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
52 52
53 53
54GNUNET_NETWORK_STRUCT_BEGIN
55
56/**
57 * Number used to uniquely identify messages in a CADET Channel.
58 */
59struct ChannelMessageIdentifier
60{
61 /**
62 * Unique ID of the message, cycles around, in NBO.
63 */
64 uint32_t mid GNUNET_PACKED;
65};
66
67
68/**
69 * Message to create a Channel.
70 */
71struct GNUNET_CADET_ChannelOpenMessage
72{
73 /**
74 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
75 */
76 struct GNUNET_MessageHeader header;
77
78 /**
79 * Channel options.
80 */
81 uint32_t opt GNUNET_PACKED;
82
83 /**
84 * Destination port.
85 */
86 struct GNUNET_HashCode port;
87
88 /**
89 * ID of the channel
90 */
91 struct GCT_ChannelTunnelNumber gid;
92};
93
94
95
96/**
97 * Message for cadet data traffic.
98 */
99struct GNUNET_CADET_ChannelAppDataMessage
100{
101 /**
102 * Type: #GNUNET_MESSAGE_TYPE_CADET_UNICAST,
103 * #GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
104 */
105 struct GNUNET_MessageHeader header;
106
107 /**
108 * Unique ID of the payload message.
109 */
110 struct ChannelMessageIdentifier mid;
111
112 /**
113 * ID of the channel
114 */
115 struct GCT_ChannelTunnelNumber gid;
116
117 /**
118 * Payload follows
119 */
120};
121
122
123/**
124 * Message to acknowledge end-to-end data.
125 */
126struct GNUNET_CADET_ChannelDataAckMessage
127{
128 /**
129 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
130 */
131 struct GNUNET_MessageHeader header;
132
133 /**
134 * ID of the channel
135 */
136 struct GCT_ChannelTunnelNumber gid;
137
138 /**
139 * Bitfield of already-received messages past @e mid.
140 * pid + 1 @ LSB
141 * pid + 64 @ MSB
142 */
143 uint64_t futures GNUNET_PACKED;
144
145 /**
146 * Last message ID received.
147 */
148 struct ChannelMessageIdentifier mid;
149};
150
151
152
153GNUNET_NETWORK_STRUCT_END
154
155
156/** 54/**
157 * All the states a connection can be in. 55 * All the states a connection can be in.
158 */ 56 */
@@ -357,7 +255,7 @@ struct CadetChannel
357 /** 255 /**
358 * Number identifying this channel in its tunnel. 256 * Number identifying this channel in its tunnel.
359 */ 257 */
360 struct GCT_ChannelTunnelNumber gid; 258 struct GNUNET_CADET_ChannelTunnelNumber gid;
361 259
362 /** 260 /**
363 * Local tunnel number for local client owning the channel. 261 * Local tunnel number for local client owning the channel.
@@ -438,7 +336,7 @@ GCCH_2s (const struct CadetChannel *ch)
438 * 336 *
439 * @return ID used to identify the channel with the remote peer. 337 * @return ID used to identify the channel with the remote peer.
440 */ 338 */
441struct GCT_ChannelTunnelNumber 339struct GNUNET_CADET_ChannelTunnelNumber
442GCCH_get_id (const struct CadetChannel *ch) 340GCCH_get_id (const struct CadetChannel *ch)
443{ 341{
444 return ch->gid; 342 return ch->gid;
@@ -545,7 +443,7 @@ send_create (void *cls)
545 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 443 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
546 msgcc.opt = htonl (options); 444 msgcc.opt = htonl (options);
547 msgcc.port = ch->port; 445 msgcc.port = ch->port;
548 msgcc.gid = ch->gid; 446 msgcc.chid = ch->gid;
549 ch->state = CADET_CHANNEL_CREATE_SENT; 447 ch->state = CADET_CHANNEL_CREATE_SENT;
550 ch->last_control_qe = GCT_send (ch->t, 448 ch->last_control_qe = GCT_send (ch->t,
551 &msgcc.header, 449 &msgcc.header,
@@ -624,7 +522,7 @@ timeout_closed_cb (void *cls)
624 */ 522 */
625struct CadetChannel * 523struct CadetChannel *
626GCCH_channel_incoming_new (struct CadetTunnel *t, 524GCCH_channel_incoming_new (struct CadetTunnel *t,
627 struct GCT_ChannelTunnelNumber gid, 525 struct GNUNET_CADET_ChannelTunnelNumber gid,
628 const struct GNUNET_HashCode *port, 526 const struct GNUNET_HashCode *port,
629 uint32_t options) 527 uint32_t options)
630{ 528{
diff --git a/src/cadet/gnunet-service-cadet-new_channel.h b/src/cadet/gnunet-service-cadet-new_channel.h
index 5cf42a894..85302ea0a 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.h
+++ b/src/cadet/gnunet-service-cadet-new_channel.h
@@ -72,7 +72,7 @@ GCCH_debug (struct CadetChannel *ch,
72 * 72 *
73 * @return ID used to identify the channel with the remote peer. 73 * @return ID used to identify the channel with the remote peer.
74 */ 74 */
75struct GCT_ChannelTunnelNumber 75struct GNUNET_CADET_ChannelTunnelNumber
76GCCH_get_id (const struct CadetChannel *ch); 76GCCH_get_id (const struct CadetChannel *ch);
77 77
78 78
@@ -130,7 +130,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch);
130 */ 130 */
131struct CadetChannel * 131struct CadetChannel *
132GCCH_channel_incoming_new (struct CadetTunnel *t, 132GCCH_channel_incoming_new (struct CadetTunnel *t,
133 struct GCT_ChannelTunnelNumber gid, 133 struct GNUNET_CADET_ChannelTunnelNumber gid,
134 const struct GNUNET_HashCode *port, 134 const struct GNUNET_HashCode *port,
135 uint32_t options); 135 uint32_t options);
136 136
diff --git a/src/cadet/gnunet-service-cadet-new_connection.c b/src/cadet/gnunet-service-cadet-new_connection.c
index 440d64fb6..5123f9d45 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.c
+++ b/src/cadet/gnunet-service-cadet-new_connection.c
@@ -376,22 +376,24 @@ manage_first_hop_mq (void *cls,
376 376
377 377
378/** 378/**
379 * Create a connection to @a destination via @a path and 379 * Create a connection to @a destination via @a path and notify @a cb
380 * notify @a cb whenever we are ready for more data. 380 * whenever we are ready for more data. Shared logic independent of
381 * who is initiating the connection.
381 * 382 *
382 * @param destination where to go 383 * @param destination where to go
383 * @param path which path to take (may not be the full path) 384 * @param path which path to take (may not be the full path)
384 * @param ct tunnel that uses the connection 385 * @param ct which tunnel uses this connection
385 * @param ready_cb function to call when ready to transmit 386 * @param ready_cb function to call when ready to transmit
386 * @param ready_cb_cls closure for @a cb 387 * @param ready_cb_cls closure for @a cb
387 * @return handle to the connection 388 * @return handle to the connection
388 */ 389 */
389struct CadetConnection * 390static struct CadetConnection *
390GCC_create (struct CadetPeer *destination, 391connection_create (struct CadetPeer *destination,
391 struct CadetPeerPath *path, 392 struct CadetPeerPath *path,
392 struct CadetTConnection *ct, 393 struct CadetTConnection *ct,
393 GNUNET_SCHEDULER_TaskCallback ready_cb, 394 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
394 void *ready_cb_cls) 395 GNUNET_SCHEDULER_TaskCallback ready_cb,
396 void *ready_cb_cls)
395{ 397{
396 struct CadetConnection *cc; 398 struct CadetConnection *cc;
397 struct CadetPeer *first_hop; 399 struct CadetPeer *first_hop;
@@ -402,9 +404,7 @@ GCC_create (struct CadetPeer *destination,
402 GNUNET_assert (UINT_MAX > off); 404 GNUNET_assert (UINT_MAX > off);
403 cc = GNUNET_new (struct CadetConnection); 405 cc = GNUNET_new (struct CadetConnection);
404 cc->ct = ct; 406 cc->ct = ct;
405 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 407 cc->cid = *cid;
406 &cc->cid,
407 sizeof (cc->cid));
408 GNUNET_assert (GNUNET_OK == 408 GNUNET_assert (GNUNET_OK ==
409 GNUNET_CONTAINER_multishortmap_put (connections, 409 GNUNET_CONTAINER_multishortmap_put (connections,
410 &GCC_get_id (cc)->connection_of_tunnel, 410 &GCC_get_id (cc)->connection_of_tunnel,
@@ -432,6 +432,74 @@ GCC_create (struct CadetPeer *destination,
432 432
433 433
434/** 434/**
435 * Create a connection to @a destination via @a path and
436 * notify @a cb whenever we are ready for more data. This
437 * is an inbound tunnel, so we must use the existing @a cid
438 *
439 * @param destination where to go
440 * @param path which path to take (may not be the full path)
441 * @param ct which tunnel uses this connection
442 * @param ready_cb function to call when ready to transmit
443 * @param ready_cb_cls closure for @a cb
444 * @return handle to the connection
445 */
446struct CadetConnection *
447GCC_create_inbound (struct CadetPeer *destination,
448 struct CadetPeerPath *path,
449 struct CadetTConnection *ct,
450 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
451 GNUNET_SCHEDULER_TaskCallback ready_cb,
452 void *ready_cb_cls)
453{
454 struct CadetConnection *cc;
455
456 cc = connection_create (destination,
457 path,
458 ct,
459 cid,
460 ready_cb,
461 ready_cb_cls);
462 /* FIXME: send CREATE_ACK? */
463 return cc;
464}
465
466
467/**
468 * Create a connection to @a destination via @a path and
469 * notify @a cb whenever we are ready for more data.
470 *
471 * @param destination where to go
472 * @param path which path to take (may not be the full path)
473 * @param ct tunnel that uses the connection
474 * @param ready_cb function to call when ready to transmit
475 * @param ready_cb_cls closure for @a cb
476 * @return handle to the connection
477 */
478struct CadetConnection *
479GCC_create (struct CadetPeer *destination,
480 struct CadetPeerPath *path,
481 struct CadetTConnection *ct,
482 GNUNET_SCHEDULER_TaskCallback ready_cb,
483 void *ready_cb_cls)
484{
485 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
486 struct CadetConnection *cc;
487
488 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
489 &cid,
490 sizeof (cid));
491 cc = connection_create (destination,
492 path,
493 ct,
494 &cid,
495 ready_cb,
496 ready_cb_cls);
497 /* FIXME: send CREATE? */
498 return cc;
499}
500
501
502/**
435 * We finished transmission of a message, if we are still ready, tell 503 * We finished transmission of a message, if we are still ready, tell
436 * the tunnel! 504 * the tunnel!
437 * 505 *
diff --git a/src/cadet/gnunet-service-cadet-new_connection.h b/src/cadet/gnunet-service-cadet-new_connection.h
index 32452024c..f2364dea4 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.h
+++ b/src/cadet/gnunet-service-cadet-new_connection.h
@@ -28,8 +28,6 @@
28#ifndef GNUNET_SERVICE_CADET_CONNECTION_H 28#ifndef GNUNET_SERVICE_CADET_CONNECTION_H
29#define GNUNET_SERVICE_CADET_CONNECTION_H 29#define GNUNET_SERVICE_CADET_CONNECTION_H
30 30
31#define NEW_CADET
32
33#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
34#include "gnunet-service-cadet-new.h" 32#include "gnunet-service-cadet-new.h"
35#include "gnunet-service-cadet-new_peer.h" 33#include "gnunet-service-cadet-new_peer.h"
@@ -74,6 +72,27 @@ GCC_create (struct CadetPeer *destination,
74 72
75 73
76/** 74/**
75 * Create a connection to @a destination via @a path and
76 * notify @a cb whenever we are ready for more data. This
77 * is an inbound tunnel, so we must use the existing @a cid
78 *
79 * @param destination where to go
80 * @param path which path to take (may not be the full path)
81 * @param ct which tunnel uses this connection
82 * @param ready_cb function to call when ready to transmit
83 * @param ready_cb_cls closure for @a cb
84 * @return handle to the connection
85 */
86struct CadetConnection *
87GCC_create_inbound (struct CadetPeer *destination,
88 struct CadetPeerPath *path,
89 struct CadetTConnection *ct,
90 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
91 GNUNET_SCHEDULER_TaskCallback ready_cb,
92 void *ready_cb_cls);
93
94
95/**
77 * Transmit message @a msg via connection @a cc. Must only be called 96 * Transmit message @a msg via connection @a cc. Must only be called
78 * (once) after the connection has signalled that it is ready via the 97 * (once) after the connection has signalled that it is ready via the
79 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the 98 * `ready_cb`. Clients can also use #GCC_is_ready() to check if the
diff --git a/src/cadet/gnunet-service-cadet-new_core.c b/src/cadet/gnunet-service-cadet-new_core.c
index e9fc6bf05..3d8406dc9 100644
--- a/src/cadet/gnunet-service-cadet-new_core.c
+++ b/src/cadet/gnunet-service-cadet-new_core.c
@@ -31,6 +31,7 @@
31#include "gnunet-service-cadet-new_paths.h" 31#include "gnunet-service-cadet-new_paths.h"
32#include "gnunet-service-cadet-new_peer.h" 32#include "gnunet-service-cadet-new_peer.h"
33#include "gnunet-service-cadet-new_connection.h" 33#include "gnunet-service-cadet-new_connection.h"
34#include "gnunet-service-cadet-new_tunnels.h"
34#include "gnunet_core_service.h" 35#include "gnunet_core_service.h"
35#include "cadet_protocol.h" 36#include "cadet_protocol.h"
36 37
@@ -76,6 +77,12 @@ struct CadetRoute
76 */ 77 */
77 struct GNUNET_TIME_Absolute last_use; 78 struct GNUNET_TIME_Absolute last_use;
78 79
80 /**
81 * Counter, used to verify that both MQs are up when the route is
82 * initialized.
83 */
84 unsigned int up;
85
79}; 86};
80 87
81 88
@@ -177,6 +184,91 @@ destroy_route (struct CadetRoute *route)
177 184
178 185
179/** 186/**
187 * Send message that a route is broken between @a peer1 and @a peer2.
188 *
189 * @param target where to send the message
190 * @param cid connection identifier to use
191 * @param peer1 one of the peers where a link is broken
192 * @param peer2 another one of the peers where a link is broken
193 */
194static void
195send_broken (struct CadetPeer *target,
196 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
197 const struct GNUNET_PeerIdentity *peer1,
198 const struct GNUNET_PeerIdentity *peer2)
199{
200 struct GNUNET_MQ_Envelope *env;
201 struct GNUNET_CADET_ConnectionBrokenMessage *bm;
202
203 env = GNUNET_MQ_msg (bm,
204 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN);
205 bm->cid = *cid;
206 if (NULL != peer1)
207 bm->peer1 = *peer1;
208 if (NULL != peer2)
209 bm->peer2 = *peer2;
210 GCP_send (target,
211 env);
212}
213
214
215/**
216 * Function called when the message queue to the previous hop
217 * becomes available/unavailable. We expect this function to
218 * be called immediately when we register, and then again
219 * later if the connection ever goes down.
220 *
221 * @param cls the `struct CadetRoute`
222 * @param mq the message queue, NULL if connection went down
223 */
224static void
225mqm_cr_destroy_prev (void *cls,
226 struct GNUNET_MQ_Handle *mq)
227{
228 struct CadetRoute *route = cls;
229
230 if (NULL != mq)
231 {
232 route->up |= 1;
233 return;
234 }
235 send_broken (route->next_hop,
236 &route->cid,
237 GCP_get_id (route->prev_hop),
238 &my_full_id);
239 destroy_route (route);
240}
241
242
243/**
244 * Function called when the message queue to the previous hop
245 * becomes available/unavailable. We expect this function to
246 * be called immediately when we register, and then again
247 * later if the connection ever goes down.
248 *
249 * @param cls the `struct CadetRoute`
250 * @param mq the message queue, NULL if connection went down
251 */
252static void
253mqm_cr_destroy_next (void *cls,
254 struct GNUNET_MQ_Handle *mq)
255{
256 struct CadetRoute *route = cls;
257
258 if (NULL != mq)
259 {
260 route->up |= 2;
261 return;
262 }
263 send_broken (route->prev_hop,
264 &route->cid,
265 GCP_get_id (route->next_hop),
266 &my_full_id);
267 destroy_route (route);
268}
269
270
271/**
180 * Handle for #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE 272 * Handle for #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
181 * 273 *
182 * @param cls Closure (CadetPeer for neighbor that sent the message). 274 * @param cls Closure (CadetPeer for neighbor that sent the message).
@@ -215,29 +307,60 @@ handle_connection_create (void *cls,
215 GNUNET_break_op (0); 307 GNUNET_break_op (0);
216 return; 308 return;
217 } 309 }
310 if (NULL !=
311 get_route (&msg->cid))
312 {
313 /* CID not chosen at random, collides */
314 GNUNET_break_op (0);
315 return;
316 }
218 if (off == path_length - 1) 317 if (off == path_length - 1)
219 { 318 {
220 /* We are the destination, create connection */ 319 /* We are the destination, create connection */
320 struct CadetPeerPath *path;
321 struct CadetPeer *origin;
322
323 path = GCPP_get_path_from_route (path_length,
324 pids);
325 origin = GCP_get (&pids[0],
326 GNUNET_YES);
327 GCT_add_inbound_connection (GCT_create_tunnel (origin),
328 &msg->cid,
329 path);
330
221 return; 331 return;
222 } 332 }
223 /* We are merely a hop on the way, check if we can support the route */ 333 /* We are merely a hop on the way, check if we can support the route */
224 next = GCP_get (&pids[off + 1], 334 next = GCP_get (&pids[off + 1],
225 GNUNET_NO); 335 GNUNET_NO);
226 if (NULL == next) 336 if ( (NULL == next) ||
337 (NULL == GCP_get_mq (next)) )
227 { 338 {
228 /* unworkable, send back BROKEN */ 339 /* unworkable, send back BROKEN notification */
229 GNUNET_break (0); // FIXME... 340 send_broken (sender,
341 &msg->cid,
342 &pids[off + 1],
343 &my_full_id);
230 return; 344 return;
231 } 345 }
232 346
347 /* Workable route, create routing entry */
233 route = GNUNET_new (struct CadetRoute); 348 route = GNUNET_new (struct CadetRoute);
234 349 route->cid = msg->cid;
235#if FIXME 350 route->prev_mqm = GCP_request_mq (sender,
236 GCC_handle_create (peer, 351 &mqm_cr_destroy_prev,
237 &msg->cid, 352 route);
238 path_length, 353 route->next_mqm = GCP_request_mq (next,
239 route); 354 &mqm_cr_destroy_next,
240#endif 355 route);
356 route->prev_hop = sender;
357 route->next_hop = next;
358 GNUNET_assert ((1|2) == route->up);
359 GNUNET_assert (GNUNET_OK ==
360 GNUNET_CONTAINER_multishortmap_put (routes,
361 &route->cid.connection_of_tunnel,
362 route,
363 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
241} 364}
242 365
243 366
@@ -382,11 +505,35 @@ handle_hop_by_hop_encrypted_ack (void *cls,
382 const struct GNUNET_CADET_ConnectionEncryptedAckMessage *msg) 505 const struct GNUNET_CADET_ConnectionEncryptedAckMessage *msg)
383{ 506{
384 struct CadetPeer *peer = cls; 507 struct CadetPeer *peer = cls;
508 struct CadetConnection *cc;
509
510 /* First, check if message belongs to a connection that ends here. */
511 cc = GNUNET_CONTAINER_multishortmap_get (connections,
512 &msg->cid.connection_of_tunnel);
513 if (NULL != cc)
514 {
515 /* verify message came from the right direction */
516 struct CadetPeerPath *path = GCC_get_path (cc);
385 517
518 if (peer !=
519 GCPP_get_peer_at_offset (path,
520 0))
521 {
522 /* received message from unexpected direction, ignore! */
523 GNUNET_break_op (0);
524 return;
525 }
386#if FIXME 526#if FIXME
387 GCC_handle_poll (peer, 527 GCC_handle_ack (peer,
388 msg); 528 msg);
389#endif 529#endif
530 return;
531 }
532
533 /* We're just an intermediary peer, route the message along its path */
534 route_message (peer,
535 &msg->cid,
536 &msg->header);
390} 537}
391 538
392 539
@@ -569,9 +716,6 @@ core_disconnect_cb (void *cls,
569{ 716{
570 struct CadetPeer *cp = peer_cls; 717 struct CadetPeer *cp = peer_cls;
571 718
572 /* FIXME: also check all routes going via peer and
573 send broken messages to the other direction! */
574 GNUNET_break (0);
575 GCP_set_mq (cp, 719 GCP_set_mq (cp,
576 NULL); 720 NULL);
577} 721}
diff --git a/src/cadet/gnunet-service-cadet-new_paths.c b/src/cadet/gnunet-service-cadet-new_paths.c
index 96f32a87b..3f6edef39 100644
--- a/src/cadet/gnunet-service-cadet-new_paths.c
+++ b/src/cadet/gnunet-service-cadet-new_paths.c
@@ -100,7 +100,7 @@ GCPP_get_desirability (const struct CadetPeerPath *path)
100 * @param path path to traverse 100 * @param path path to traverse
101 * @param destination destination node to get to, must be on path 101 * @param destination destination node to get to, must be on path
102 * @param off offset of @a destination on @a path 102 * @param off offset of @a destination on @a path
103 * @return NULL if @a create is NO and we have no existing connection 103 * @return NULL if we have no existing connection
104 * otherwise connection from us to @a destination via @a path 104 * otherwise connection from us to @a destination via @a path
105 */ 105 */
106struct CadetConnection * 106struct CadetConnection *
@@ -460,6 +460,22 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
460 460
461 461
462/** 462/**
463 * We got an incoming connection, obtain the corresponding path.
464 *
465 * @param path_length number of segments on the @a path
466 * @param path through the network, in reverse order (we are at the end!)
467 * @return corresponding path object
468 */
469struct CadetPeerPath *
470GCPP_get_path_from_route (unsigned int path_length,
471 const struct GNUNET_PeerIdentity *pids)
472{
473 GNUNET_assert (0); // FIXME!
474 return NULL;
475}
476
477
478/**
463 * Return the length of the path. Excludes one end of the 479 * Return the length of the path. Excludes one end of the
464 * path, so the loopback path has length 0. 480 * path, so the loopback path has length 0.
465 * 481 *
diff --git a/src/cadet/gnunet-service-cadet-new_paths.h b/src/cadet/gnunet-service-cadet-new_paths.h
index f08d4a705..6a864e8ec 100644
--- a/src/cadet/gnunet-service-cadet-new_paths.h
+++ b/src/cadet/gnunet-service-cadet-new_paths.h
@@ -50,6 +50,18 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
50 50
51 51
52/** 52/**
53 * We got an incoming connection, obtain the corresponding path.
54 *
55 * @param path_length number of segments on the @a path
56 * @param path through the network, in reverse order (we are at the end!)
57 * @return corresponding path object
58 */
59struct CadetPeerPath *
60GCPP_get_path_from_route (unsigned int path_length,
61 const struct GNUNET_PeerIdentity *pids);
62
63
64/**
53 * Return the length of the path. Excludes one end of the 65 * Return the length of the path. Excludes one end of the
54 * path, so the loopback path has length 0. 66 * path, so the loopback path has length 0.
55 * 67 *
@@ -67,7 +79,7 @@ GCPP_get_length (struct CadetPeerPath *path);
67 * @param path path to traverse 79 * @param path path to traverse
68 * @param destination destination node to get to, must be on path 80 * @param destination destination node to get to, must be on path
69 * @param off offset of @a destination on @a path 81 * @param off offset of @a destination on @a path
70 * @return NULL if @a create is NO and we have no existing connection 82 * @return NULL if we have no existing connection
71 * otherwise connection from us to @a destination via @a path 83 * otherwise connection from us to @a destination via @a path
72 */ 84 */
73struct CadetConnection * 85struct CadetConnection *
diff --git a/src/cadet/gnunet-service-cadet-new_peer.c b/src/cadet/gnunet-service-cadet-new_peer.c
index 55a03a206..c57622181 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.c
+++ b/src/cadet/gnunet-service-cadet-new_peer.c
@@ -265,6 +265,19 @@ destroy_peer (void *cls)
265 265
266 266
267/** 267/**
268 * Get the message queue for peer @a cp.
269 *
270 * @param cp peer to modify
271 * @return message queue (can be NULL)
272 */
273struct GNUNET_MQ_Handle *
274GCP_get_mq (struct CadetPeer *cp)
275{
276 return cp->core_mq;
277}
278
279
280/**
268 * Set the message queue to @a mq for peer @a cp and notify watchers. 281 * Set the message queue to @a mq for peer @a cp and notify watchers.
269 * 282 *
270 * @param cp peer to modify 283 * @param cp peer to modify
diff --git a/src/cadet/gnunet-service-cadet-new_peer.h b/src/cadet/gnunet-service-cadet-new_peer.h
index 6b0812cc7..6b4ee1b56 100644
--- a/src/cadet/gnunet-service-cadet-new_peer.h
+++ b/src/cadet/gnunet-service-cadet-new_peer.h
@@ -313,6 +313,16 @@ GCP_set_mq (struct CadetPeer *cp,
313 313
314 314
315/** 315/**
316 * Get the message queue for peer @a cp.
317 *
318 * @param cp peer to modify
319 * @return message queue (can be NULL)
320 */
321struct GNUNET_MQ_Handle *
322GCP_get_mq (struct CadetPeer *cp);
323
324
325/**
316 * Send the message in @a env to @a cp. 326 * Send the message in @a env to @a cp.
317 * 327 *
318 * @param cp the peer 328 * @param cp the peer
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index d874011aa..67af76109 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -374,14 +374,14 @@ struct CadetTunnel
374 374
375 /** 375 /**
376 * Channels inside this tunnel. Maps 376 * Channels inside this tunnel. Maps
377 * `struct GCT_ChannelTunnelNumber` to a `struct CadetChannel`. 377 * `struct GNUNET_CADET_ChannelTunnelNumber` to a `struct CadetChannel`.
378 */ 378 */
379 struct GNUNET_CONTAINER_MultiHashMap32 *channels; 379 struct GNUNET_CONTAINER_MultiHashMap32 *channels;
380 380
381 /** 381 /**
382 * Channel ID for the next created channel in this tunnel. 382 * Channel ID for the next created channel in this tunnel.
383 */ 383 */
384 struct GCT_ChannelTunnelNumber next_chid; 384 struct GNUNET_CADET_ChannelTunnelNumber next_chid;
385 385
386 /** 386 /**
387 * Queued messages, to transmit once tunnel gets connected. 387 * Queued messages, to transmit once tunnel gets connected.
@@ -1137,14 +1137,14 @@ t_ax_decrypt_and_validate (struct CadetTunnel *t,
1137 * @param ch Channel 1137 * @param ch Channel
1138 * @return unique number identifying @a ch within @a t 1138 * @return unique number identifying @a ch within @a t
1139 */ 1139 */
1140struct GCT_ChannelTunnelNumber 1140struct GNUNET_CADET_ChannelTunnelNumber
1141GCT_add_channel (struct CadetTunnel *t, 1141GCT_add_channel (struct CadetTunnel *t,
1142 struct CadetChannel *ch) 1142 struct CadetChannel *ch)
1143{ 1143{
1144 struct GCT_ChannelTunnelNumber ret; 1144 struct GNUNET_CADET_ChannelTunnelNumber ret;
1145 uint32_t chid; 1145 uint32_t chid;
1146 1146
1147 chid = ntohl (t->next_chid.channel_in_tunnel); 1147 chid = ntohl (t->next_chid.cn);
1148 while (NULL != 1148 while (NULL !=
1149 GNUNET_CONTAINER_multihashmap32_get (t->channels, 1149 GNUNET_CONTAINER_multihashmap32_get (t->channels,
1150 chid)) 1150 chid))
@@ -1154,8 +1154,8 @@ GCT_add_channel (struct CadetTunnel *t,
1154 chid, 1154 chid,
1155 ch, 1155 ch,
1156 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1156 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1157 t->next_chid.channel_in_tunnel = htonl (chid + 1); 1157 t->next_chid.cn = htonl (chid + 1);
1158 ret.channel_in_tunnel = htonl (chid); 1158 ret.cn = htonl (chid);
1159 return ret; 1159 return ret;
1160} 1160}
1161 1161
@@ -1617,11 +1617,11 @@ GCT_create_tunnel (struct CadetPeer *destination)
1617void 1617void
1618GCT_remove_channel (struct CadetTunnel *t, 1618GCT_remove_channel (struct CadetTunnel *t,
1619 struct CadetChannel *ch, 1619 struct CadetChannel *ch,
1620 struct GCT_ChannelTunnelNumber gid) 1620 struct GNUNET_CADET_ChannelTunnelNumber gid)
1621{ 1621{
1622 GNUNET_assert (GNUNET_YES == 1622 GNUNET_assert (GNUNET_YES ==
1623 GNUNET_CONTAINER_multihashmap32_remove (t->channels, 1623 GNUNET_CONTAINER_multihashmap32_remove (t->channels,
1624 ntohl (gid.channel_in_tunnel), 1624 ntohl (gid.cn),
1625 ch)); 1625 ch));
1626 if (0 == 1626 if (0 ==
1627 GNUNET_CONTAINER_multihashmap32_size (t->channels)) 1627 GNUNET_CONTAINER_multihashmap32_size (t->channels))
@@ -1671,6 +1671,41 @@ GCT_change_estate (struct CadetTunnel *t,
1671 1671
1672 1672
1673/** 1673/**
1674 * Add a @a connection to the @a tunnel.
1675 *
1676 * @param t a tunnel
1677 * @param cid connection identifer to use for the connection
1678 * @param path path to use for the connection
1679 */
1680void
1681GCT_add_inbound_connection (struct CadetTunnel *t,
1682 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
1683 struct CadetPeerPath *path)
1684{
1685 struct CadetConnection *cc;
1686 struct CadetTConnection *ct;
1687
1688 ct = GNUNET_new (struct CadetTConnection);
1689 ct->created = GNUNET_TIME_absolute_get ();
1690 ct->t = t;
1691 ct->cc = GCC_create_inbound (t->destination,
1692 path,
1693 ct,
1694 cid,
1695 &connection_ready_cb,
1696 t);
1697 /* FIXME: schedule job to kill connection (and path?) if it takes
1698 too long to get ready! (And track performance data on how long
1699 other connections took with the tunnel!)
1700 => Note: to be done within 'connection'-logic! */
1701 GNUNET_CONTAINER_DLL_insert (t->connection_head,
1702 t->connection_tail,
1703 ct);
1704 t->num_connections++;
1705}
1706
1707
1708/**
1674 * Handle KX message. 1709 * Handle KX message.
1675 * 1710 *
1676 * @param ct connection/tunnel combo that received encrypted message 1711 * @param ct connection/tunnel combo that received encrypted message
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.h b/src/cadet/gnunet-service-cadet-new_tunnels.h
index 59a5a1958..82e4b0da6 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.h
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.h
@@ -118,15 +118,6 @@ enum CadetTunnelEState
118 118
119 119
120/** 120/**
121 * Number uniquely identifying a channel within a tunnel.
122 */
123struct GCT_ChannelTunnelNumber
124{
125 uint32_t channel_in_tunnel GNUNET_PACKED;
126};
127
128
129/**
130 * Get the static string for the peer this tunnel is directed. 121 * Get the static string for the peer this tunnel is directed.
131 * 122 *
132 * @param t Tunnel. 123 * @param t Tunnel.
@@ -149,6 +140,19 @@ GCT_create_tunnel (struct CadetPeer *destination);
149 140
150 141
151/** 142/**
143 * Add a @a connection to the @a tunnel.
144 *
145 * @param t a tunnel
146 * @param cid connection identifer to use for the connection
147 * @param path path to use for the connection
148 */
149void
150GCT_add_inbound_connection (struct CadetTunnel *t,
151 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid,
152 struct CadetPeerPath *path);
153
154
155/**
152 * Return the peer to which this tunnel goes. 156 * Return the peer to which this tunnel goes.
153 * 157 *
154 * @param t a tunnel 158 * @param t a tunnel
@@ -179,7 +183,7 @@ GCT_consider_path (struct CadetTunnel *t,
179 * @param ch Channel 183 * @param ch Channel
180 * @return unique number identifying @a ch within @a t 184 * @return unique number identifying @a ch within @a t
181 */ 185 */
182struct GCT_ChannelTunnelNumber 186struct GNUNET_CADET_ChannelTunnelNumber
183GCT_add_channel (struct CadetTunnel *t, 187GCT_add_channel (struct CadetTunnel *t,
184 struct CadetChannel *ch); 188 struct CadetChannel *ch);
185 189
@@ -194,7 +198,7 @@ GCT_add_channel (struct CadetTunnel *t,
194void 198void
195GCT_remove_channel (struct CadetTunnel *t, 199GCT_remove_channel (struct CadetTunnel *t,
196 struct CadetChannel *ch, 200 struct CadetChannel *ch,
197 struct GCT_ChannelTunnelNumber gid); 201 struct GNUNET_CADET_ChannelTunnelNumber gid);
198 202
199 203
200/** 204/**
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index 20ed582bd..dee0c37d7 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -216,7 +216,7 @@ struct CadetChannel
216 /** 216 /**
217 * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) 217 * Global channel number ( < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
218 */ 218 */
219 struct GNUNET_CADET_ChannelNumber gid; 219 struct GNUNET_CADET_ChannelTunnelNumber gid;
220 220
221 /** 221 /**
222 * Local tunnel number for root (owner) client. 222 * Local tunnel number for root (owner) client.
@@ -1398,7 +1398,7 @@ GCCH_destroy (struct CadetChannel *ch)
1398 * 1398 *
1399 * @return ID used to identify the channel with the remote peer. 1399 * @return ID used to identify the channel with the remote peer.
1400 */ 1400 */
1401struct GNUNET_CADET_ChannelNumber 1401struct GNUNET_CADET_ChannelTunnelNumber
1402GCCH_get_id (const struct CadetChannel *ch) 1402GCCH_get_id (const struct CadetChannel *ch)
1403{ 1403{
1404 return ch->gid; 1404 return ch->gid;
@@ -2154,7 +2154,7 @@ GCCH_handle_create (struct CadetTunnel *t,
2154 const struct GNUNET_CADET_ChannelOpenMessage *msg) 2154 const struct GNUNET_CADET_ChannelOpenMessage *msg)
2155{ 2155{
2156 struct GNUNET_CADET_ClientChannelNumber chid; 2156 struct GNUNET_CADET_ClientChannelNumber chid;
2157 struct GNUNET_CADET_ChannelNumber gid; 2157 struct GNUNET_CADET_ChannelTunnelNumber gid;
2158 struct CadetChannel *ch; 2158 struct CadetChannel *ch;
2159 struct CadetClient *c; 2159 struct CadetClient *c;
2160 int new_channel; 2160 int new_channel;
diff --git a/src/cadet/gnunet-service-cadet_channel.h b/src/cadet/gnunet-service-cadet_channel.h
index 9e887362b..1eeebf34b 100644
--- a/src/cadet/gnunet-service-cadet_channel.h
+++ b/src/cadet/gnunet-service-cadet_channel.h
@@ -69,7 +69,7 @@ GCCH_destroy (struct CadetChannel *ch);
69 * 69 *
70 * @return ID used to identify the channel with the remote peer. 70 * @return ID used to identify the channel with the remote peer.
71 */ 71 */
72struct GNUNET_CADET_ChannelNumber 72struct GNUNET_CADET_ChannelTunnelNumber
73GCCH_get_id (const struct CadetChannel *ch); 73GCCH_get_id (const struct CadetChannel *ch);
74 74
75/** 75/**
diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c
index 7ba7077aa..e1f6ac4c3 100644
--- a/src/cadet/gnunet-service-cadet_local.c
+++ b/src/cadet/gnunet-service-cadet_local.c
@@ -977,7 +977,7 @@ iter_channel (void *cls, struct CadetChannel *ch)
977{ 977{
978 struct GNUNET_CADET_LocalInfoTunnel *msg = cls; 978 struct GNUNET_CADET_LocalInfoTunnel *msg = cls;
979 struct GNUNET_CADET_ConnectionTunnelIdentifier *h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1]; 979 struct GNUNET_CADET_ConnectionTunnelIdentifier *h = (struct GNUNET_CADET_ConnectionTunnelIdentifier *) &msg[1];
980 struct GNUNET_CADET_ChannelNumber *chn = (struct GNUNET_CADET_ChannelNumber *) &h[msg->connections]; 980 struct GNUNET_CADET_ChannelTunnelNumber *chn = (struct GNUNET_CADET_ChannelTunnelNumber *) &h[msg->connections];
981 981
982 chn[msg->channels] = GCCH_get_id (ch); 982 chn[msg->channels] = GCCH_get_id (ch);
983 msg->channels++; 983 msg->channels++;
@@ -1045,7 +1045,7 @@ handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
1045 1045
1046 size = sizeof (struct GNUNET_CADET_LocalInfoTunnel); 1046 size = sizeof (struct GNUNET_CADET_LocalInfoTunnel);
1047 size += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier); 1047 size += c_n * sizeof (struct GNUNET_CADET_ConnectionTunnelIdentifier);
1048 size += ch_n * sizeof (struct GNUNET_CADET_ChannelNumber); 1048 size += ch_n * sizeof (struct GNUNET_CADET_ChannelTunnelNumber);
1049 1049
1050 resp = GNUNET_malloc (size); 1050 resp = GNUNET_malloc (size);
1051 resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL); 1051 resp->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL);
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index b2d91c995..65775ce66 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -310,7 +310,7 @@ struct CadetTunnel
310 /** 310 /**
311 * Channel ID for the next created channel. 311 * Channel ID for the next created channel.
312 */ 312 */
313 struct GNUNET_CADET_ChannelNumber next_chid; 313 struct GNUNET_CADET_ChannelTunnelNumber next_chid;
314 314
315 /** 315 /**
316 * Destroy flag: if true, destroy on last message. 316 * Destroy flag: if true, destroy on last message.
@@ -1556,7 +1556,7 @@ destroy_iterator (void *cls,
1556 */ 1556 */
1557static void 1557static void
1558send_channel_destroy (struct CadetTunnel *t, 1558send_channel_destroy (struct CadetTunnel *t,
1559 struct GNUNET_CADET_ChannelNumber gid) 1559 struct GNUNET_CADET_ChannelTunnelNumber gid)
1560{ 1560{
1561 struct GNUNET_CADET_ChannelManageMessage msg; 1561 struct GNUNET_CADET_ChannelManageMessage msg;
1562 1562
@@ -2515,7 +2515,7 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch)
2515 */ 2515 */
2516struct CadetChannel * 2516struct CadetChannel *
2517GCT_get_channel (struct CadetTunnel *t, 2517GCT_get_channel (struct CadetTunnel *t,
2518 struct GNUNET_CADET_ChannelNumber chid) 2518 struct GNUNET_CADET_ChannelTunnelNumber chid)
2519{ 2519{
2520 struct CadetTChannel *iter; 2520 struct CadetTChannel *iter;
2521 2521
@@ -2971,11 +2971,11 @@ GCT_get_destination (struct CadetTunnel *t)
2971 * 2971 *
2972 * @return GID of a channel free to use. 2972 * @return GID of a channel free to use.
2973 */ 2973 */
2974struct GNUNET_CADET_ChannelNumber 2974struct GNUNET_CADET_ChannelTunnelNumber
2975GCT_get_next_chid (struct CadetTunnel *t) 2975GCT_get_next_chid (struct CadetTunnel *t)
2976{ 2976{
2977 struct GNUNET_CADET_ChannelNumber chid; 2977 struct GNUNET_CADET_ChannelTunnelNumber chid;
2978 struct GNUNET_CADET_ChannelNumber mask; 2978 struct GNUNET_CADET_ChannelTunnelNumber mask;
2979 int result; 2979 int result;
2980 2980
2981 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID. 2981 /* Set bit 30 depending on the ID relationship. Bit 31 is always 0 for GID.
diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h
index 65f54e373..c10815a3b 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.h
+++ b/src/cadet/gnunet-service-cadet_tunnel.h
@@ -291,7 +291,7 @@ GCT_remove_channel (struct CadetTunnel *t, struct CadetChannel *ch);
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_ChannelNumber chid); 294GCT_get_channel (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber chid);
295 295
296 296
297/** 297/**
@@ -427,7 +427,7 @@ GCT_get_destination (struct CadetTunnel *t);
427 * 427 *
428 * @return ID of a channel free to use. 428 * @return ID of a channel free to use.
429 */ 429 */
430struct GNUNET_CADET_ChannelNumber 430struct GNUNET_CADET_ChannelTunnelNumber
431GCT_get_next_chid (struct CadetTunnel *t); 431GCT_get_next_chid (struct CadetTunnel *t);
432 432
433 433
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index c17cb983c..7090d4410 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -412,10 +412,10 @@ typedef void
412(*GNUNET_CADET_ChannelCB) (void *cls, 412(*GNUNET_CADET_ChannelCB) (void *cls,
413 const struct GNUNET_PeerIdentity *root, 413 const struct GNUNET_PeerIdentity *root,
414 const struct GNUNET_PeerIdentity *dest, 414 const struct GNUNET_PeerIdentity *dest,
415 uint32_t port, 415 uint32_t /* UGH */ port,
416 uint32_t root_channel_number, 416 uint32_t /* ugh */ root_channel_number,
417 uint32_t dest_channel_number, 417 uint32_t /* ugh */ dest_channel_number,
418 uint32_t public_channel_number); 418 uint32_t /* ugh */ public_channel_number);
419 419
420/** 420/**
421 * Method called to retrieve information about all peers in CADET, called 421 * Method called to retrieve information about all peers in CADET, called
@@ -491,10 +491,14 @@ struct GNUNET_CADET_ConnectionTunnelIdentifier
491 491
492 492
493/** 493/**
494 * Number identifying a CADET channel. 494 * Number identifying a CADET channel within a tunnel.
495 */ 495 */
496struct GNUNET_CADET_ChannelNumber 496struct GNUNET_CADET_ChannelTunnelNumber
497{ 497{
498 /**
499 * Which number does this channel have that uniquely identfies
500 * it within its tunnel?
501 */
498 uint32_t cn GNUNET_PACKED; 502 uint32_t cn GNUNET_PACKED;
499}; 503};
500 504
@@ -517,7 +521,7 @@ typedef void
517 const struct GNUNET_PeerIdentity *peer, 521 const struct GNUNET_PeerIdentity *peer,
518 unsigned int n_channels, 522 unsigned int n_channels,
519 unsigned int n_connections, 523 unsigned int n_connections,
520 const struct GNUNET_CADET_ChannelNumber *channels, 524 const struct GNUNET_CADET_ChannelTunnelNumber *channels,
521 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections, 525 const struct GNUNET_CADET_ConnectionTunnelIdentifier *connections,
522 unsigned int estate, 526 unsigned int estate,
523 unsigned int cstate); 527 unsigned int cstate);
@@ -537,7 +541,7 @@ typedef void
537void 541void
538GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h, 542GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h,
539 struct GNUNET_PeerIdentity *peer, 543 struct GNUNET_PeerIdentity *peer,
540 uint32_t channel_number, 544 uint32_t /* UGH */ channel_number,
541 GNUNET_CADET_ChannelCB callback, 545 GNUNET_CADET_ChannelCB callback,
542 void *callback_cls); 546 void *callback_cls);
543 547