aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-20 10:08:07 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-20 10:08:07 +0100
commit7d96a8234bbd9d9a4dc431c52d92ebb604084c70 (patch)
treed2162b1006202ed154bf128293b9ec54fc38ac5e /src/cadet
parentaedd5919e802370061850486c96da72b25df7f22 (diff)
downloadgnunet-7d96a8234bbd9d9a4dc431c52d92ebb604084c70.tar.gz
gnunet-7d96a8234bbd9d9a4dc431c52d92ebb604084c70.zip
more work on channel/tunnel logic
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_protocol.h7
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c44
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.h7
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.c4
-rw-r--r--src/cadet/gnunet-service-cadet-new_connection.h11
-rw-r--r--src/cadet/gnunet-service-cadet-new_core.c79
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.c100
-rw-r--r--src/cadet/gnunet-service-cadet-new_tunnels.h11
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c4
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c11
10 files changed, 136 insertions, 142 deletions
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index cf32e0d6d..f85ef17ae 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -337,7 +337,7 @@ struct GNUNET_CADET_ConnectionEncryptedAckMessage
337 /** 337 /**
338 * Maximum packet ID authorized. 338 * Maximum packet ID authorized.
339 */ 339 */
340 struct CadetEncryptedMessageIdentifier cemi; 340 struct CadetEncryptedMessageIdentifier cemi_max;
341 341
342 /** 342 /**
343 * ID of the connection. 343 * ID of the connection.
@@ -379,12 +379,13 @@ struct GNUNET_CADET_ChannelOpenMessage
379 379
380 380
381/** 381/**
382 * Message to manage a Channel (ACK, NACK, Destroy). 382 * Message to manage a Channel (CHANNEL_CREATE_ACK, CHANNEL_DESTROY).
383 */ 383 */
384struct GNUNET_CADET_ChannelManageMessage 384struct GNUNET_CADET_ChannelManageMessage
385{ 385{
386 /** 386 /**
387 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY} 387 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_ACK or
388 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
388 */ 389 */
389 struct GNUNET_MessageHeader header; 390 struct GNUNET_MessageHeader header;
390 391
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index 5acd098b6..70f16dbe6 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -18,7 +18,6 @@
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. 19 Boston, MA 02110-1301, USA.
20*/ 20*/
21
22/** 21/**
23 * @file cadet/gnunet-service-cadet-new_channel.c 22 * @file cadet/gnunet-service-cadet-new_channel.c
24 * @brief logical links between CADET clients 23 * @brief logical links between CADET clients
@@ -26,10 +25,11 @@
26 * @author Christian Grothoff 25 * @author Christian Grothoff
27 * 26 *
28 * TODO: 27 * TODO:
29 * - estimate max bandwidth using bursts and use to optimize 28 * - estimate max bandwidth using bursts and use to for CONGESTION CONTROL!
30 * transmission rate(s) 29 * - check that '0xFFULL' really is sufficient for flow control!
30 * - what about the 'no buffer' option?
31 * - what about the 'out-of-order' option?
31 */ 32 */
32
33#include "platform.h" 33#include "platform.h"
34#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
35#include "cadet.h" 35#include "cadet.h"
@@ -259,7 +259,7 @@ struct CadetChannel
259 /** 259 /**
260 * Number identifying this channel in its tunnel. 260 * Number identifying this channel in its tunnel.
261 */ 261 */
262 struct GNUNET_CADET_ChannelTunnelNumber gid; 262 struct GNUNET_CADET_ChannelTunnelNumber chid;
263 263
264 /** 264 /**
265 * Local tunnel number for local client owning the channel. 265 * Local tunnel number for local client owning the channel.
@@ -324,10 +324,10 @@ GCCH_2s (const struct CadetChannel *ch)
324 return "(NULL Channel)"; 324 return "(NULL Channel)";
325 GNUNET_snprintf (buf, 325 GNUNET_snprintf (buf,
326 sizeof (buf), 326 sizeof (buf),
327 "%s:%s gid:%X (%X)", 327 "%s:%s chid:%X (%X)",
328 GCT_2s (ch->t), 328 GCT_2s (ch->t),
329 GNUNET_h2s (&ch->port), 329 GNUNET_h2s (&ch->port),
330 ch->gid, 330 ch->chid,
331 ntohl (ch->lid.channel_of_client)); 331 ntohl (ch->lid.channel_of_client));
332 return buf; 332 return buf;
333} 333}
@@ -343,7 +343,7 @@ GCCH_2s (const struct CadetChannel *ch)
343struct GNUNET_CADET_ChannelTunnelNumber 343struct GNUNET_CADET_ChannelTunnelNumber
344GCCH_get_id (const struct CadetChannel *ch) 344GCCH_get_id (const struct CadetChannel *ch)
345{ 345{
346 return ch->gid; 346 return ch->chid;
347} 347}
348 348
349 349
@@ -391,7 +391,7 @@ channel_destroy (struct CadetChannel *ch)
391 } 391 }
392 GCT_remove_channel (ch->t, 392 GCT_remove_channel (ch->t,
393 ch, 393 ch,
394 ch->gid); 394 ch->chid);
395 GNUNET_free (ch); 395 GNUNET_free (ch);
396} 396}
397 397
@@ -447,7 +447,7 @@ send_create (void *cls)
447 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 447 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
448 msgcc.opt = htonl (options); 448 msgcc.opt = htonl (options);
449 msgcc.port = ch->port; 449 msgcc.port = ch->port;
450 msgcc.chid = ch->gid; 450 msgcc.chid = ch->chid;
451 ch->state = CADET_CHANNEL_CREATE_SENT; 451 ch->state = CADET_CHANNEL_CREATE_SENT;
452 ch->last_control_qe = GCT_send (ch->t, 452 ch->last_control_qe = GCT_send (ch->t,
453 &msgcc.header, 453 &msgcc.header,
@@ -483,8 +483,8 @@ GCCH_channel_local_new (struct CadetClient *owner,
483 ch->port = *port; 483 ch->port = *port;
484 ch->t = GCP_get_tunnel (destination, 484 ch->t = GCP_get_tunnel (destination,
485 GNUNET_YES); 485 GNUNET_YES);
486 ch->gid = GCT_add_channel (ch->t, 486 ch->chid = GCT_add_channel (ch->t,
487 ch); 487 ch);
488 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 488 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
489 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 489 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
490 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 490 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
@@ -516,17 +516,17 @@ timeout_closed_cb (void *cls)
516 516
517 517
518/** 518/**
519 * Create a new channel. 519 * Create a new channel based on a request coming in over the network.
520 * 520 *
521 * @param t tunnel to the remote peer 521 * @param t tunnel to the remote peer
522 * @param gid identifier of this channel in the tunnel 522 * @param chid identifier of this channel in the tunnel
523 * @param port desired local port 523 * @param port desired local port
524 * @param options options for the channel 524 * @param options options for the channel
525 * @return handle to the new channel 525 * @return handle to the new channel
526 */ 526 */
527struct CadetChannel * 527struct CadetChannel *
528GCCH_channel_incoming_new (struct CadetTunnel *t, 528GCCH_channel_incoming_new (struct CadetTunnel *t,
529 struct GNUNET_CADET_ChannelTunnelNumber gid, 529 struct GNUNET_CADET_ChannelTunnelNumber chid,
530 const struct GNUNET_HashCode *port, 530 const struct GNUNET_HashCode *port,
531 uint32_t options) 531 uint32_t options)
532{ 532{
@@ -538,7 +538,7 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
538 or adjust dynamically... */ 538 or adjust dynamically... */
539 ch->port = *port; 539 ch->port = *port;
540 ch->t = t; 540 ch->t = t;
541 ch->gid = gid; 541 ch->chid = chid;
542 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 542 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
543 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 543 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
544 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 544 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
@@ -602,7 +602,7 @@ send_channel_ack (struct CadetChannel *ch)
602 602
603 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); 603 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
604 msg.header.size = htons (sizeof (msg)); 604 msg.header.size = htons (sizeof (msg));
605 msg.gid = ch->gid; 605 msg.gid = ch->chid;
606 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1); 606 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1);
607 msg.futures = GNUNET_htonll (ch->mid_futures); 607 msg.futures = GNUNET_htonll (ch->mid_futures);
608 if (NULL != ch->last_control_qe) 608 if (NULL != ch->last_control_qe)
@@ -694,6 +694,8 @@ GCCH_channel_local_destroy (struct CadetChannel *ch)
694 return; 694 return;
695 } 695 }
696 /* Nothing left to do, just finish destruction */ 696 /* Nothing left to do, just finish destruction */
697 GCT_send_channel_destroy (ch->t,
698 ch->chid);
697 channel_destroy (ch); 699 channel_destroy (ch);
698} 700}
699 701
@@ -721,6 +723,8 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch)
721 return; 723 return;
722 } 724 }
723 /* Nothing left to do, just finish destruction */ 725 /* Nothing left to do, just finish destruction */
726 GCT_send_channel_destroy (ch->t,
727 ch->chid);
724 channel_destroy (ch); 728 channel_destroy (ch);
725} 729}
726 730
@@ -930,7 +934,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
930 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 934 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
931 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); 935 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
932 crm->data_message.mid = ch->mid_send; 936 crm->data_message.mid = ch->mid_send;
933 crm->data_message.gid = ch->gid; 937 crm->data_message.gid = ch->chid;
934 GNUNET_memcpy (&crm[1], 938 GNUNET_memcpy (&crm[1],
935 message, 939 message,
936 payload_size); 940 payload_size);
@@ -1001,6 +1005,8 @@ send_client_buffered_data (struct CadetChannel *ch)
1001 return; 1005 return;
1002 if (GNUNET_NO == ch->destroy) 1006 if (GNUNET_NO == ch->destroy)
1003 return; 1007 return;
1008 GCT_send_channel_destroy (ch->t,
1009 ch->chid);
1004 channel_destroy (ch); 1010 channel_destroy (ch);
1005} 1011}
1006 1012
@@ -1047,7 +1053,7 @@ GCCH_debug (struct CadetChannel *ch,
1047 LOG2 (level, 1053 LOG2 (level,
1048 "CHN Channel %s:%X (%p)\n", 1054 "CHN Channel %s:%X (%p)\n",
1049 GCT_2s (ch->t), 1055 GCT_2s (ch->t),
1050 ch->gid, 1056 ch->chid,
1051 ch); 1057 ch);
1052 if (NULL != ch->owner) 1058 if (NULL != ch->owner)
1053 { 1059 {
diff --git a/src/cadet/gnunet-service-cadet-new_channel.h b/src/cadet/gnunet-service-cadet-new_channel.h
index 8caa254d1..0d56d8ae0 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.h
+++ b/src/cadet/gnunet-service-cadet-new_channel.h
@@ -107,7 +107,6 @@ GCCH_bind (struct CadetChannel *ch,
107 struct CadetClient *c); 107 struct CadetClient *c);
108 108
109 109
110
111/** 110/**
112 * Destroy locally created channel. Called by the 111 * Destroy locally created channel. Called by the
113 * local client, so no need to tell the client. 112 * local client, so no need to tell the client.
@@ -119,10 +118,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch);
119 118
120 119
121/** 120/**
122 * Create a new channel. 121 * Create a new channel based on a request coming in over the network.
123 * 122 *
124 * @param t tunnel to the remote peer 123 * @param t tunnel to the remote peer
125 * @param gid identifier of this channel in the tunnel 124 * @param chid identifier of this channel in the tunnel
126 * @param origin peer to who initiated the channel 125 * @param origin peer to who initiated the channel
127 * @param port desired local port 126 * @param port desired local port
128 * @param options options for the channel 127 * @param options options for the channel
@@ -130,7 +129,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch);
130 */ 129 */
131struct CadetChannel * 130struct CadetChannel *
132GCCH_channel_incoming_new (struct CadetTunnel *t, 131GCCH_channel_incoming_new (struct CadetTunnel *t,
133 struct GNUNET_CADET_ChannelTunnelNumber gid, 132 struct GNUNET_CADET_ChannelTunnelNumber chid,
134 const struct GNUNET_HashCode *port, 133 const struct GNUNET_HashCode *port,
135 uint32_t options); 134 uint32_t options);
136 135
diff --git a/src/cadet/gnunet-service-cadet-new_connection.c b/src/cadet/gnunet-service-cadet-new_connection.c
index bf88d78e1..5eb6335a2 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.c
+++ b/src/cadet/gnunet-service-cadet-new_connection.c
@@ -27,8 +27,8 @@
27 * @author Christian Grothoff 27 * @author Christian Grothoff
28 * 28 *
29 * TODO: 29 * TODO:
30 * - keepalive messages 30 * - Optimization: keepalive messages / timeout (timeout to be done @ peer level!)
31 * - keep performance metrics (?) 31 * - Optimization: keep performance metrics (?)
32 */ 32 */
33#include "platform.h" 33#include "platform.h"
34#include "gnunet-service-cadet-new_channel.h" 34#include "gnunet-service-cadet-new_channel.h"
diff --git a/src/cadet/gnunet-service-cadet-new_connection.h b/src/cadet/gnunet-service-cadet-new_connection.h
index 99426776d..31a2e80bb 100644
--- a/src/cadet/gnunet-service-cadet-new_connection.h
+++ b/src/cadet/gnunet-service-cadet-new_connection.h
@@ -122,6 +122,17 @@ GCC_handle_connection_ack (struct CadetConnection *cc);
122 122
123 123
124/** 124/**
125 * We got a #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE for a
126 * connection that we already have. Either our ACK got lost
127 * or something is fishy. Consider retransmitting the ACK.
128 *
129 * @param cc connection that got the duplicate CREATE
130 */
131void
132GCC_handle_duplicate_create (struct CadetConnection *cc);
133
134
135/**
125 * Handle KX message. 136 * Handle KX message.
126 * 137 *
127 * @param cc connection that received encrypted message 138 * @param cc connection that received encrypted message
diff --git a/src/cadet/gnunet-service-cadet-new_core.c b/src/cadet/gnunet-service-cadet-new_core.c
index 9ce4418de..a5d114b34 100644
--- a/src/cadet/gnunet-service-cadet-new_core.c
+++ b/src/cadet/gnunet-service-cadet-new_core.c
@@ -27,10 +27,7 @@
27 * All functions in this file should use the prefix GCO (Gnunet Cadet cOre (bottom)) 27 * All functions in this file should use the prefix GCO (Gnunet Cadet cOre (bottom))
28 * 28 *
29 * TODO: 29 * TODO:
30 * - pass encrypted ACK to connection (!) 30 * - Optimization: given BROKEN messages, destroy paths (?)
31 * - given BROKEN messages, destroy paths (?)
32 * -
33 * - handle POLL (if needed)
34 */ 31 */
35#include "platform.h" 32#include "platform.h"
36#include "gnunet-service-cadet-new_core.h" 33#include "gnunet-service-cadet-new_core.h"
@@ -422,8 +419,7 @@ handle_connection_create (void *cls,
422 &msg->cid.connection_of_tunnel); 419 &msg->cid.connection_of_tunnel);
423 if (NULL != cc) 420 if (NULL != cc)
424 { 421 {
425 /* Duplicate CREATE, likely our ACK got lost, retransmit the ACK! */ 422 GCC_handle_duplicate_create (cc);
426 GNUNET_break (0); // FIXME: not implemented!
427 return; 423 return;
428 } 424 }
429 425
@@ -604,68 +600,6 @@ handle_connection_destroy (void *cls,
604 600
605 601
606/** 602/**
607 * Handle for #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_HOP_BY_HOP_ENCRYPTED_ACK.
608 *
609 * @param cls Closure (CadetPeer for neighbor that sent the message).
610 * @param msg Message itself.
611 */
612static void
613handle_hop_by_hop_encrypted_ack (void *cls,
614 const struct GNUNET_CADET_ConnectionEncryptedAckMessage *msg)
615{
616 struct CadetPeer *peer = cls;
617 struct CadetConnection *cc;
618
619 /* First, check if message belongs to a connection that ends here. */
620 cc = GNUNET_CONTAINER_multishortmap_get (connections,
621 &msg->cid.connection_of_tunnel);
622 if (NULL != cc)
623 {
624 /* verify message came from the right direction */
625 struct CadetPeerPath *path = GCC_get_path (cc);
626
627 if (peer !=
628 GCPP_get_peer_at_offset (path,
629 0))
630 {
631 /* received message from unexpected direction, ignore! */
632 GNUNET_break_op (0);
633 return;
634 }
635#if FIXME
636 GCC_handle_ack (peer,
637 msg);
638#endif
639 return;
640 }
641
642 /* We're just an intermediary peer, route the message along its path */
643 route_message (peer,
644 &msg->cid,
645 &msg->header);
646}
647
648
649/**
650 * Handle for #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL
651 *
652 * @param cls Closure (CadetPeer for neighbor that sent the message).
653 * @param msg Message itself.
654 */
655static void
656handle_poll (void *cls,
657 const struct GNUNET_CADET_ConnectionHopByHopPollMessage *msg)
658{
659 struct CadetPeer *peer = cls;
660
661#if FIXME
662 GCC_handle_poll (peer,
663 msg);
664#endif
665}
666
667
668/**
669 * Handle for #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX 603 * Handle for #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX
670 * 604 *
671 * @param cls Closure (CadetPeer for neighbor that sent the message). 605 * @param cls Closure (CadetPeer for neighbor that sent the message).
@@ -755,7 +689,6 @@ handle_tunnel_encrypted (void *cls,
755 msg); 689 msg);
756 return; 690 return;
757 } 691 }
758
759 /* We're just an intermediary peer, route the message along its path */ 692 /* We're just an intermediary peer, route the message along its path */
760 route_message (peer, 693 route_message (peer,
761 &msg->cid, 694 &msg->cid,
@@ -855,14 +788,6 @@ GCO_init (const struct GNUNET_CONFIGURATION_Handle *c)
855 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, 788 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
856 struct GNUNET_CADET_ConnectionDestroyMessage, 789 struct GNUNET_CADET_ConnectionDestroyMessage,
857 NULL), 790 NULL),
858 GNUNET_MQ_hd_fixed_size (hop_by_hop_encrypted_ack,
859 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK,
860 struct GNUNET_CADET_ConnectionEncryptedAckMessage,
861 NULL),
862 GNUNET_MQ_hd_fixed_size (poll,
863 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL,
864 struct GNUNET_CADET_ConnectionHopByHopPollMessage,
865 NULL),
866 GNUNET_MQ_hd_fixed_size (tunnel_kx, 791 GNUNET_MQ_hd_fixed_size (tunnel_kx,
867 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX, 792 GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX,
868 struct GNUNET_CADET_TunnelKeyExchangeMessage, 793 struct GNUNET_CADET_TunnelKeyExchangeMessage,
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c
index 23b270b82..6873fb396 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.c
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.c
@@ -1,4 +1,3 @@
1
2/* 1/*
3 This file is part of GNUnet. 2 This file is part of GNUnet.
4 Copyright (C) 2013, 2017 GNUnet e.V. 3 Copyright (C) 2013, 2017 GNUnet e.V.
@@ -18,7 +17,6 @@
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
20*/ 19*/
21
22/** 20/**
23 * @file cadet/gnunet-service-cadet-new_tunnels.c 21 * @file cadet/gnunet-service-cadet-new_tunnels.c
24 * @brief Information we track per tunnel. 22 * @brief Information we track per tunnel.
@@ -26,12 +24,12 @@
26 * @author Christian Grothoff 24 * @author Christian Grothoff
27 * 25 *
28 * FIXME: 26 * FIXME:
27 * - clean up KX logic!
28 * - implement sending and receiving KX messages
29 * - implement processing of incoming decrypted plaintext messages
29 * - when managing connections, distinguish those that 30 * - when managing connections, distinguish those that
30 * have (recently) had traffic from those that were 31 * have (recently) had traffic from those that were
31 * never ready (or not recently) 32 * never ready (or not recently)
32 * - implement sending and receiving KX messages
33 * - implement processing of incoming decrypted plaintext messages
34 * - clean up KX logic!
35 */ 33 */
36#include "platform.h" 34#include "platform.h"
37#include "gnunet_util_lib.h" 35#include "gnunet_util_lib.h"
@@ -1306,32 +1304,52 @@ GCT_handle_kx (struct CadetTConnection *ct,
1306 1304
1307 1305
1308/** 1306/**
1309 * Add a channel to a tunnel. 1307 * Compute the next free channel tunnel number for this tunnel.
1310 * 1308 *
1311 * @param t Tunnel. 1309 * @param t the tunnel
1312 * @param ch Channel 1310 * @return unused number that can uniquely identify a channel in the tunnel
1313 * @return unique number identifying @a ch within @a t
1314 */ 1311 */
1315struct GNUNET_CADET_ChannelTunnelNumber 1312static struct GNUNET_CADET_ChannelTunnelNumber
1316GCT_add_channel (struct CadetTunnel *t, 1313get_next_free_chid (struct CadetTunnel *t)
1317 struct CadetChannel *ch)
1318{ 1314{
1319 struct GNUNET_CADET_ChannelTunnelNumber ret; 1315 struct GNUNET_CADET_ChannelTunnelNumber ret;
1320 uint32_t chid; 1316 uint32_t chid;
1321 1317
1318 /* FIXME: this logic does NOT prevent both ends of the
1319 channel from picking the same CHID!
1320 Need to reserve one bit of the CHID for the
1321 direction, i.e. which side established the connection! */
1322 chid = ntohl (t->next_chid.cn); 1322 chid = ntohl (t->next_chid.cn);
1323 while (NULL != 1323 while (NULL !=
1324 GNUNET_CONTAINER_multihashmap32_get (t->channels, 1324 GNUNET_CONTAINER_multihashmap32_get (t->channels,
1325 chid)) 1325 chid))
1326 chid++; 1326 chid++;
1327 t->next_chid.cn = htonl (chid + 1);
1328 ret.cn = ntohl (chid);
1329 return ret;
1330}
1331
1332
1333/**
1334 * Add a channel to a tunnel.
1335 *
1336 * @param t Tunnel.
1337 * @param ch Channel
1338 * @return unique number identifying @a ch within @a t
1339 */
1340struct GNUNET_CADET_ChannelTunnelNumber
1341GCT_add_channel (struct CadetTunnel *t,
1342 struct CadetChannel *ch)
1343{
1344 struct GNUNET_CADET_ChannelTunnelNumber chid;
1345
1346 chid = get_next_free_chid (t);
1327 GNUNET_assert (GNUNET_YES == 1347 GNUNET_assert (GNUNET_YES ==
1328 GNUNET_CONTAINER_multihashmap32_put (t->channels, 1348 GNUNET_CONTAINER_multihashmap32_put (t->channels,
1329 chid, 1349 ntohl (chid.cn),
1330 ch, 1350 ch,
1331 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 1351 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1332 t->next_chid.cn = htonl (chid + 1); 1352 return chid;
1333 ret.cn = htonl (chid);
1334 return ret;
1335} 1353}
1336 1354
1337 1355
@@ -1638,7 +1656,8 @@ handle_plaintext_data_ack (void *cls,
1638 1656
1639 1657
1640/** 1658/**
1641 * 1659 * We have received a request to open a channel to a port from
1660 * another peer. Creates the incoming channel.
1642 * 1661 *
1643 * @param cls the `struct CadetTunnel` for which we decrypted the message 1662 * @param cls the `struct CadetTunnel` for which we decrypted the message
1644 * @param cc the message we received on the tunnel 1663 * @param cc the message we received on the tunnel
@@ -1648,27 +1667,40 @@ handle_plaintext_channel_create (void *cls,
1648 const struct GNUNET_CADET_ChannelOpenMessage *cc) 1667 const struct GNUNET_CADET_ChannelOpenMessage *cc)
1649{ 1668{
1650 struct CadetTunnel *t = cls; 1669 struct CadetTunnel *t = cls;
1651 GNUNET_break (0); // FIXME! 1670 struct CadetChannel *ch;
1671 struct GNUNET_CADET_ChannelTunnelNumber chid;
1672
1673 chid = get_next_free_chid (t);
1674 ch = GCCH_channel_incoming_new (t,
1675 chid,
1676 &cc->port,
1677 ntohl (cc->opt));
1678 GNUNET_assert (GNUNET_OK ==
1679 GNUNET_CONTAINER_multihashmap32_put (t->channels,
1680 ntohl (chid.cn),
1681 ch,
1682 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1652} 1683}
1653 1684
1654 1685
1655/** 1686/**
1687 * Send a DESTROY message via the tunnel.
1656 * 1688 *
1657 * 1689 * @param t the tunnel to transmit over
1658 * @param cls the `struct CadetTunnel` for which we decrypted the message 1690 * @param chid ID of the channel to destroy
1659 * @param cm the message we received on the tunnel
1660 */ 1691 */
1661static void 1692void
1662handle_plaintext_channel_nack (void *cls, 1693GCT_send_channel_destroy (struct CadetTunnel *t,
1663 const struct GNUNET_CADET_ChannelManageMessage *cm) 1694 struct GNUNET_CADET_ChannelTunnelNumber chid)
1664{ 1695{
1665 struct CadetTunnel *t = cls;
1666 GNUNET_break (0); // FIXME! 1696 GNUNET_break (0); // FIXME!
1667} 1697}
1668 1698
1669 1699
1670/** 1700/**
1671 * 1701 * We have received confirmation from the target peer that the
1702 * given channel could be established (the port is open).
1703 * Tell the client.
1672 * 1704 *
1673 * @param cls the `struct CadetTunnel` for which we decrypted the message 1705 * @param cls the `struct CadetTunnel` for which we decrypted the message
1674 * @param cm the message we received on the tunnel 1706 * @param cm the message we received on the tunnel
@@ -1678,6 +1710,18 @@ handle_plaintext_channel_ack (void *cls,
1678 const struct GNUNET_CADET_ChannelManageMessage *cm) 1710 const struct GNUNET_CADET_ChannelManageMessage *cm)
1679{ 1711{
1680 struct CadetTunnel *t = cls; 1712 struct CadetTunnel *t = cls;
1713 struct CadetChannel *ch;
1714
1715 ch = lookup_channel (t,
1716 cm->chid);
1717 if (NULL == ch)
1718 {
1719 /* We don't know about such a channel, might have been destroyed on our
1720 end in the meantime, or never existed. Send back a DESTROY. */
1721 GCT_send_channel_destroy (t,
1722 cm->chid);
1723 return;
1724 }
1681 GNUNET_break (0); // FIXME! 1725 GNUNET_break (0); // FIXME!
1682} 1726}
1683 1727
@@ -1763,10 +1807,6 @@ GCT_create_tunnel (struct CadetPeer *destination)
1763 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN, 1807 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN,
1764 struct GNUNET_CADET_ChannelOpenMessage, 1808 struct GNUNET_CADET_ChannelOpenMessage,
1765 NULL), 1809 NULL),
1766 GNUNET_MQ_hd_fixed_size (plaintext_channel_nack,
1767 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_NACK_DEPRECATED,
1768 struct GNUNET_CADET_ChannelManageMessage,
1769 NULL),
1770 GNUNET_MQ_hd_fixed_size (plaintext_channel_ack, 1810 GNUNET_MQ_hd_fixed_size (plaintext_channel_ack,
1771 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK, 1811 GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK,
1772 struct GNUNET_CADET_ChannelManageMessage, 1812 struct GNUNET_CADET_ChannelManageMessage,
diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.h b/src/cadet/gnunet-service-cadet-new_tunnels.h
index 82e4b0da6..cd96a50bc 100644
--- a/src/cadet/gnunet-service-cadet-new_tunnels.h
+++ b/src/cadet/gnunet-service-cadet-new_tunnels.h
@@ -202,6 +202,17 @@ GCT_remove_channel (struct CadetTunnel *t,
202 202
203 203
204/** 204/**
205 * Send a DESTROY message via the tunnel.
206 *
207 * @param t the tunnel to transmit over
208 * @param chid ID of the channel to destroy
209 */
210void
211GCT_send_channel_destroy (struct CadetTunnel *t,
212 struct GNUNET_CADET_ChannelTunnelNumber chid);
213
214
215/**
205 * Sends an already built message on a tunnel, encrypting it and 216 * Sends an already built message on a tunnel, encrypting it and
206 * choosing the best connection if not provided. 217 * choosing the best connection if not provided.
207 * 218 *
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 931b32b95..c4802abde 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -617,7 +617,7 @@ send_ack (struct CadetConnection *c,
617 /* Build ACK message and send on conn */ 617 /* Build ACK message and send on conn */
618 msg.header.size = htons (sizeof (msg)); 618 msg.header.size = htons (sizeof (msg));
619 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK); 619 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK);
620 msg.cemi = ack_cemi; 620 msg.cemi_max = ack_cemi;
621 msg.cid = c->id; 621 msg.cid = c->id;
622 622
623 prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, 623 prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header,
@@ -2373,7 +2373,7 @@ GCC_handle_ack (struct CadetPeer *peer,
2373 return; 2373 return;
2374 } 2374 }
2375 2375
2376 ack = msg->cemi; 2376 ack = msg->cemi_max;
2377 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", 2377 LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n",
2378 GC_f2s (fwd), 2378 GC_f2s (fwd),
2379 ntohl (ack.pid), 2379 ntohl (ack.pid),
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 65775ce66..31c9b9e1c 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013, 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
@@ -17,16 +17,17 @@
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. 18 Boston, MA 02110-1301, USA.
19*/ 19*/
20 20/**
21 * @file cadet/gnunet-service-cadet_tunnel.c
22 * @brief logical links between CADET clients
23 * @author Bartlomiej Polot
24 */
21#include "platform.h" 25#include "platform.h"
22#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
23
24#include "gnunet_signatures.h" 27#include "gnunet_signatures.h"
25#include "gnunet_statistics_service.h" 28#include "gnunet_statistics_service.h"
26
27#include "cadet_protocol.h" 29#include "cadet_protocol.h"
28#include "cadet_path.h" 30#include "cadet_path.h"
29
30#include "gnunet-service-cadet_tunnel.h" 31#include "gnunet-service-cadet_tunnel.h"
31#include "gnunet-service-cadet_connection.h" 32#include "gnunet-service-cadet_connection.h"
32#include "gnunet-service-cadet_channel.h" 33#include "gnunet-service-cadet_channel.h"