From 6b25953f27639c7b87c98a6cb55fd173c9dc5016 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 20 Jan 2017 11:28:30 +0100 Subject: [PATCH] pass messages from tunnel to channel --- src/cadet/cadet_protocol.h | 4 +- src/cadet/gnunet-service-cadet-new_channel.c | 47 +++++++++++++++- src/cadet/gnunet-service-cadet-new_channel.h | 35 +++++++++++- src/cadet/gnunet-service-cadet-new_tunnels.c | 58 ++++++++++++++++---- 4 files changed, 128 insertions(+), 16 deletions(-) diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index f85ef17ae..070be3e28 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h @@ -496,7 +496,7 @@ struct GNUNET_CADET_ChannelAppDataMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber gid; + struct GNUNET_CADET_ChannelTunnelNumber chid; /** * Payload follows @@ -517,7 +517,7 @@ struct GNUNET_CADET_ChannelDataAckMessage /** * ID of the channel */ - struct GNUNET_CADET_ChannelTunnelNumber gid; + struct GNUNET_CADET_ChannelTunnelNumber chid; /** * Bitfield of already-received messages past @e mid. diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c index 70f16dbe6..c6adc351b 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.c +++ b/src/cadet/gnunet-service-cadet-new_channel.c @@ -602,7 +602,7 @@ send_channel_ack (struct CadetChannel *ch) msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); msg.header.size = htons (sizeof (msg)); - msg.gid = ch->chid; + msg.chid = ch->chid; msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1); msg.futures = GNUNET_htonll (ch->mid_futures); if (NULL != ch->last_control_qe) @@ -729,6 +729,47 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch) } +/** + * We got an acknowledgement for the creation of the channel + * (the port is open on the other side). Begin transmissions. + * + * @param ch channel to destroy + */ +void +GCCH_handle_channel_create_ack (struct CadetChannel *ch) +{ + GNUNET_break (0); // FIXME! +} + + +/** + * We got payload data for a channel. Pass it on to the client. + * + * @param ch channel that got data + */ +void +GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, + const struct GNUNET_CADET_ChannelAppDataMessage *msg) +{ + GNUNET_break (0); // FIXME! +} + + +/** + * We got an acknowledgement for payload data for a channel. + * Possibly resume transmissions. + * + * @param ch channel that got the ack + * @param ack details about what was received + */ +void +GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, + const struct GNUNET_CADET_ChannelDataAckMessage *ack) +{ + GNUNET_break (0); // FIXME! +} + + /** * Destroy channel, based on the other peer closing the * connection. Also needs to remove this channel from @@ -744,7 +785,7 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch) * @param ch channel to destroy */ void -GCCH_channel_remote_destroy (struct CadetChannel *ch) +GCCH_handle_remote_destroy (struct CadetChannel *ch) { GNUNET_break (0); // FIXME! } @@ -934,7 +975,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); crm->data_message.mid = ch->mid_send; - crm->data_message.gid = ch->chid; + crm->data_message.chid = ch->chid; GNUNET_memcpy (&crm[1], message, payload_size); diff --git a/src/cadet/gnunet-service-cadet-new_channel.h b/src/cadet/gnunet-service-cadet-new_channel.h index 0d56d8ae0..2e1eb4115 100644 --- a/src/cadet/gnunet-service-cadet-new_channel.h +++ b/src/cadet/gnunet-service-cadet-new_channel.h @@ -30,6 +30,7 @@ #include "gnunet-service-cadet-new.h" #include "gnunet-service-cadet-new_peer.h" +#include "cadet_protocol.h" /** @@ -144,6 +145,38 @@ void GCCH_channel_incoming_destroy (struct CadetChannel *ch); +/** + * We got payload data for a channel. Pass it on to the client. + * + * @param ch channel that got data + */ +void +GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, + const struct GNUNET_CADET_ChannelAppDataMessage *msg); + + +/** + * We got an acknowledgement for payload data for a channel. + * Possibly resume transmissions. + * + * @param ch channel that got the ack + * @param ack details about what was received + */ +void +GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, + const struct GNUNET_CADET_ChannelDataAckMessage *ack); + + +/** + * We got an acknowledgement for the creation of the channel + * (the port is open on the other side). Begin transmissions. + * + * @param ch channel to destroy + */ +void +GCCH_handle_channel_create_ack (struct CadetChannel *ch); + + /** * Destroy channel, based on the other peer closing the * connection. Also needs to remove this channel from @@ -159,7 +192,7 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch); * @param ch channel to destroy */ void -GCCH_channel_remote_destroy (struct CadetChannel *ch); +GCCH_handle_remote_destroy (struct CadetChannel *ch); /** diff --git a/src/cadet/gnunet-service-cadet-new_tunnels.c b/src/cadet/gnunet-service-cadet-new_tunnels.c index 6873fb396..9b359ed58 100644 --- a/src/cadet/gnunet-service-cadet-new_tunnels.c +++ b/src/cadet/gnunet-service-cadet-new_tunnels.c @@ -35,9 +35,8 @@ #include "gnunet_util_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_signatures.h" -#include "cadet_protocol.h" -#include "cadet_path.h" #include "gnunet-service-cadet-new.h" +#include "cadet_protocol.h" #include "gnunet-service-cadet-new_channel.h" #include "gnunet-service-cadet-new_connection.h" #include "gnunet-service-cadet-new_tunnels.h" @@ -1433,7 +1432,8 @@ connection_ready_cb (void *cls, ct->is_ready = GNUNET_NO; GCC_transmit (ct->cc, tq->env); - tq->cont (tq->cont_cls); + if (NULL != tq->cont) + tq->cont (tq->cont_cls); GNUNET_free (tq); } @@ -1626,7 +1626,8 @@ check_plaintext_data (void *cls, /** - * + * We received payload data for a channel. Locate the channel + * and process the data, or return an error if the channel is unknown. * * @param cls the `struct CadetTunnel` for which we decrypted the message * @param msg the message we received on the tunnel @@ -1636,12 +1637,27 @@ handle_plaintext_data (void *cls, const struct GNUNET_CADET_ChannelAppDataMessage *msg) { struct CadetTunnel *t = cls; - GNUNET_break (0); // FIXME! + struct CadetChannel *ch; + + ch = lookup_channel (t, + msg->chid); + if (NULL == ch) + { + /* We don't know about such a channel, might have been destroyed on our + end in the meantime, or never existed. Send back a DESTROY. */ + GCT_send_channel_destroy (t, + msg->chid); + return; + } + GCCH_handle_channel_plaintext_data (ch, + msg); } /** - * + * We received an acknowledgement for data we sent on a channel. + * Locate the channel and process it, or return an error if the + * channel is unknown. * * @param cls the `struct CadetTunnel` for which we decrypted the message * @param ack the message we received on the tunnel @@ -1651,7 +1667,20 @@ handle_plaintext_data_ack (void *cls, const struct GNUNET_CADET_ChannelDataAckMessage *ack) { struct CadetTunnel *t = cls; - GNUNET_break (0); // FIXME! + struct CadetChannel *ch; + + ch = lookup_channel (t, + ack->chid); + if (NULL == ch) + { + /* We don't know about such a channel, might have been destroyed on our + end in the meantime, or never existed. Send back a DESTROY. */ + GCT_send_channel_destroy (t, + ack->chid); + return; + } + GCCH_handle_channel_plaintext_data_ack (ch, + ack); } @@ -1693,7 +1722,16 @@ void GCT_send_channel_destroy (struct CadetTunnel *t, struct GNUNET_CADET_ChannelTunnelNumber chid) { - GNUNET_break (0); // FIXME! + struct GNUNET_CADET_ChannelManageMessage msg; + + msg.header.size = htons (sizeof (msg)); + msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY); + msg.reserved = htonl (0); + msg.chid = chid; + GCT_send (t, + &msg.header, + NULL, + NULL); } @@ -1722,7 +1760,7 @@ handle_plaintext_channel_ack (void *cls, cm->chid); return; } - GNUNET_break (0); // FIXME! + GCCH_handle_channel_create_ack (ch); } @@ -1741,7 +1779,7 @@ handle_plaintext_channel_destroy (void *cls, struct CadetChannel *cc = lookup_channel (t, cm->chid); - GCCH_channel_remote_destroy (cc); + GCCH_handle_remote_destroy (cc); } -- 2.25.1