aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet-new_channel.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-23 14:02:18 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-23 14:02:18 +0100
commit4b15b95280fd44d825a08b99ecbef0cda8393bc7 (patch)
tree688bc6217bd2b1d38d27a9b797447147b355d237 /src/cadet/gnunet-service-cadet-new_channel.c
parent990c75c9d7d1c8eb3d68c1eb9f49d131abb0deaa (diff)
downloadgnunet-4b15b95280fd44d825a08b99ecbef0cda8393bc7.tar.gz
gnunet-4b15b95280fd44d825a08b99ecbef0cda8393bc7.zip
more implementation of loopback handling
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_channel.c')
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index 870732192..fbd68e3e3 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -271,10 +271,16 @@ struct CadetChannel
271 struct GNUNET_CADET_ChannelTunnelNumber ctn; 271 struct GNUNET_CADET_ChannelTunnelNumber ctn;
272 272
273 /** 273 /**
274 * Local tunnel number for local client owning the channel. 274 * Local tunnel number for local client @e owner owning the channel.
275 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) 275 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
276 */ 276 */
277 struct GNUNET_CADET_ClientChannelNumber ccn; 277 struct GNUNET_CADET_ClientChannelNumber ccn_owner;
278
279 /**
280 * Local tunnel number for local client @e dest owning the channel.
281 * (< #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
282 */
283 struct GNUNET_CADET_ClientChannelNumber ccn_dest;
278 284
279 /** 285 /**
280 * Channel state. 286 * Channel state.
@@ -330,11 +336,12 @@ GCCH_2s (const struct CadetChannel *ch)
330 336
331 GNUNET_snprintf (buf, 337 GNUNET_snprintf (buf,
332 sizeof (buf), 338 sizeof (buf),
333 "Channel %s:%s ctn:%X(%X)", 339 "Channel %s:%s ctn:%X(%X/%X)",
334 GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), 340 GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))),
335 GNUNET_h2s (&ch->port), 341 GNUNET_h2s (&ch->port),
336 ch->ctn, 342 ch->ctn,
337 ntohl (ch->ccn.channel_of_client)); 343 ntohl (ch->ccn_owner.channel_of_client),
344 ntohl (ch->ccn_dest.channel_of_client));
338 return buf; 345 return buf;
339} 346}
340 347
@@ -526,7 +533,7 @@ GCCH_channel_local_new (struct CadetClient *owner,
526 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 533 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER));
527 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */ 534 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */
528 ch->owner = owner; 535 ch->owner = owner;
529 ch->ccn = ccn; 536 ch->ccn_owner = ccn;
530 ch->port = *port; 537 ch->port = *port;
531 if (0 == memcmp (&my_full_id, 538 if (0 == memcmp (&my_full_id,
532 GCP_get_id (destination), 539 GCP_get_id (destination),
@@ -675,9 +682,9 @@ send_ack_cb (void *cls)
675 682
676 683
677/** 684/**
678 * Compute and send the current ACK to the other peer. 685 * Compute and send the current #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK to the other peer.
679 * 686 *
680 * @param ch channel to send the ACK for 687 * @param ch channel to send the #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK for
681 */ 688 */
682static void 689static void
683send_channel_data_ack (struct CadetChannel *ch) 690send_channel_data_ack (struct CadetChannel *ch)
@@ -699,7 +706,7 @@ send_channel_data_ack (struct CadetChannel *ch)
699 706
700 707
701/** 708/**
702 * Send our initial ACK to the client confirming that the 709 * Send our initial #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK to the client confirming that the
703 * connection is up. 710 * connection is up.
704 * 711 *
705 * @param cls the `struct CadetChannel` 712 * @param cls the `struct CadetChannel`
@@ -761,7 +768,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch)
761 768
762 769
763/** 770/**
764 * Send a LOCAL ACK to the client to solicit more messages. 771 * Send a #GNUNET_MESSAGE_TYPE_CADET_LOCAL ACK to the client to solicit more messages.
765 * 772 *
766 * @param ch channel the ack is for 773 * @param ch channel the ack is for
767 * @param c client to send the ACK to 774 * @param c client to send the ACK to
@@ -775,7 +782,7 @@ send_ack_to_client (struct CadetChannel *ch,
775 782
776 env = GNUNET_MQ_msg (ack, 783 env = GNUNET_MQ_msg (ack,
777 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 784 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
778 ack->ccn = ch->ccn; 785 ack->ccn = (c == ch->owner) ? ch->ccn_owner : ch->ccn_dest;
779 GSC_send_to_client (c, 786 GSC_send_to_client (c,
780 env); 787 env);
781} 788}
@@ -817,11 +824,14 @@ GCCH_bind (struct CadetChannel *ch,
817 if (ch->out_of_order) 824 if (ch->out_of_order)
818 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER; 825 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
819 ch->dest = c; 826 ch->dest = c;
820 ch->ccn = GSC_bind (c, 827 ch->ccn_dest = GSC_bind (c,
821 ch, 828 ch,
822 GCT_get_destination (ch->t), 829 (GNUNET_YES == ch->is_loopback)
823 &ch->port, 830 ? GCP_get (&my_full_id,
824 options); 831 GNUNET_YES)
832 : GCT_get_destination (ch->t),
833 &ch->port,
834 options);
825 ch->mid_recv.mid = htonl (1); /* The CONNECT counts as message 0! */ 835 ch->mid_recv.mid = htonl (1); /* The CONNECT counts as message 0! */
826 if (GNUNET_YES == ch->is_loopback) 836 if (GNUNET_YES == ch->is_loopback)
827 { 837 {
@@ -838,8 +848,11 @@ GCCH_bind (struct CadetChannel *ch,
838 /* give client it's initial supply of ACKs */ 848 /* give client it's initial supply of ACKs */
839 env = GNUNET_MQ_msg (tcm, 849 env = GNUNET_MQ_msg (tcm,
840 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 850 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
841 tcm->ccn = ch->ccn; 851 tcm->ccn = ch->ccn_dest;
842 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t)); 852 if (GNUNET_YES == ch->is_loopback)
853 tcm->peer = my_full_id;
854 else
855 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t));
843 tcm->port = ch->port; 856 tcm->port = ch->port;
844 tcm->opt = htonl (options); 857 tcm->opt = htonl (options);
845 GSC_send_to_client (ch->dest, 858 GSC_send_to_client (ch->dest,
@@ -922,8 +935,11 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch)
922 LOG (GNUNET_ERROR_TYPE_DEBUG, 935 LOG (GNUNET_ERROR_TYPE_DEBUG,
923 "Received channel OPEN_ACK for waiting %s, entering READY state\n", 936 "Received channel OPEN_ACK for waiting %s, entering READY state\n",
924 GCCH_2s (ch)); 937 GCCH_2s (ch));
925 GNUNET_SCHEDULER_cancel (ch->retry_control_task); 938 if (NULL != ch->retry_control_task) /* can be NULL if ch->is_loopback */
926 ch->retry_control_task = NULL; 939 {
940 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
941 ch->retry_control_task = NULL;
942 }
927 ch->state = CADET_CHANNEL_READY; 943 ch->state = CADET_CHANNEL_READY;
928 /* On first connect, send client as many ACKs as we allow messages 944 /* On first connect, send client as many ACKs as we allow messages
929 to be buffered! */ 945 to be buffered! */
@@ -995,21 +1011,16 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
995 struct CadetOutOfOrderMessage *com; 1011 struct CadetOutOfOrderMessage *com;
996 size_t payload_size; 1012 size_t payload_size;
997 1013
1014 GNUNET_assert (GNUNET_NO == ch->is_loopback);
998 payload_size = ntohs (msg->header.size) - sizeof (*msg); 1015 payload_size = ntohs (msg->header.size) - sizeof (*msg);
999 LOG (GNUNET_ERROR_TYPE_DEBUG, 1016 LOG (GNUNET_ERROR_TYPE_DEBUG,
1000 "Receicved %u bytes of application data on %s\n", 1017 "Receicved %u bytes of application data on %s\n",
1001 (unsigned int) payload_size, 1018 (unsigned int) payload_size,
1002 GCCH_2s (ch)); 1019 GCCH_2s (ch));
1003 if (GNUNET_YES == ch->is_loopback)
1004 {
1005 GNUNET_break (0); // FIXME: not implemented
1006 return;
1007 }
1008
1009 env = GNUNET_MQ_msg_extra (ld, 1020 env = GNUNET_MQ_msg_extra (ld,
1010 payload_size, 1021 payload_size,
1011 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1022 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1012 ld->ccn = ch->ccn; 1023 ld->ccn = (NULL == ch->dest) ? ch->ccn_owner : ch->ccn_dest;
1013 GNUNET_memcpy (&ld[1], 1024 GNUNET_memcpy (&ld[1],
1014 &msg[1], 1025 &msg[1],
1015 payload_size); 1026 payload_size);
@@ -1131,7 +1142,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1131void 1142void
1132GCCH_handle_remote_destroy (struct CadetChannel *ch) 1143GCCH_handle_remote_destroy (struct CadetChannel *ch)
1133{ 1144{
1134 GNUNET_break (GNUNET_NO == ch->is_loopback); 1145 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1135 LOG (GNUNET_ERROR_TYPE_DEBUG, 1146 LOG (GNUNET_ERROR_TYPE_DEBUG,
1136 "Received remote channel DESTROY for %s\n", 1147 "Received remote channel DESTROY for %s\n",
1137 GCCH_2s (ch)); 1148 GCCH_2s (ch));
@@ -1150,7 +1161,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch)
1150 } 1161 }
1151 ch->destroy = GNUNET_YES; 1162 ch->destroy = GNUNET_YES;
1152 GSC_handle_remote_channel_destroy ((NULL != ch->owner) ? ch->owner : ch->dest, 1163 GSC_handle_remote_channel_destroy ((NULL != ch->owner) ? ch->owner : ch->dest,
1153 ch->ccn, 1164 (NULL != ch->owner) ? ch->ccn_owner : ch->ccn_dest,
1154 ch); 1165 ch);
1155 channel_destroy (ch); 1166 channel_destroy (ch);
1156} 1167}
@@ -1231,8 +1242,8 @@ GCCH_check_allow_client (struct CadetChannel *ch)
1231 GCCH_2s (ch)); 1242 GCCH_2s (ch));
1232 env = GNUNET_MQ_msg (msg, 1243 env = GNUNET_MQ_msg (msg,
1233 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 1244 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
1234 msg->ccn = ch->ccn; 1245 msg->ccn = (NULL != ch->owner) ? ch->ccn_owner : ch->ccn_dest;
1235 GSC_send_to_client (ch->owner ? ch->owner : ch->dest, 1246 GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest,
1236 env); 1247 env);
1237} 1248}
1238 1249
@@ -1473,7 +1484,7 @@ GCCH_debug (struct CadetChannel *ch,
1473 "CHN origin %s ready %s local-id: %u\n", 1484 "CHN origin %s ready %s local-id: %u\n",
1474 GSC_2s (ch->owner), 1485 GSC_2s (ch->owner),
1475 ch->client_ready ? "YES" : "NO", 1486 ch->client_ready ? "YES" : "NO",
1476 ntohl (ch->ccn.channel_of_client)); 1487 ntohl (ch->ccn_owner.channel_of_client));
1477 } 1488 }
1478 if (NULL != ch->dest) 1489 if (NULL != ch->dest)
1479 { 1490 {
@@ -1481,7 +1492,7 @@ GCCH_debug (struct CadetChannel *ch,
1481 "CHN destination %s ready %s local-id: %u\n", 1492 "CHN destination %s ready %s local-id: %u\n",
1482 GSC_2s (ch->dest), 1493 GSC_2s (ch->dest),
1483 ch->client_ready ? "YES" : "NO", 1494 ch->client_ready ? "YES" : "NO",
1484 ntohl (ch->ccn.channel_of_client)); 1495 ntohl (ch->ccn_dest.channel_of_client));
1485 } 1496 }
1486 LOG2 (level, 1497 LOG2 (level,
1487 "CHN Message IDs recv: %d (%LLX), send: %d\n", 1498 "CHN Message IDs recv: %d (%LLX), send: %d\n",