aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet-new_channel.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-21 17:51:51 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-21 17:51:51 +0100
commit308518cb6fbc4b635fccd87a770f66cc2e2816f3 (patch)
tree298ce9cf97c35e1447d119c270ceaa13d394275d /src/cadet/gnunet-service-cadet-new_channel.c
parent745cf54e655a9fb40a4ba3643de09a3471ca6ef6 (diff)
downloadgnunet-308518cb6fbc4b635fccd87a770f66cc2e2816f3.tar.gz
gnunet-308518cb6fbc4b635fccd87a770f66cc2e2816f3.zip
some renaming, some code general code cleanup, some logging
Diffstat (limited to 'src/cadet/gnunet-service-cadet-new_channel.c')
-rw-r--r--src/cadet/gnunet-service-cadet-new_channel.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/src/cadet/gnunet-service-cadet-new_channel.c b/src/cadet/gnunet-service-cadet-new_channel.c
index d7981656c..e64e66dfa 100644
--- a/src/cadet/gnunet-service-cadet-new_channel.c
+++ b/src/cadet/gnunet-service-cadet-new_channel.c
@@ -44,7 +44,7 @@
44#include "gnunet-service-cadet-new_peer.h" 44#include "gnunet-service-cadet-new_peer.h"
45#include "gnunet-service-cadet-new_paths.h" 45#include "gnunet-service-cadet-new_paths.h"
46 46
47#define LOG(level, ...) GNUNET_log (level,__VA_ARGS__) 47#define LOG(level,...) GNUNET_log_from (level,"cadet-channel",__VA_ARGS__)
48 48
49/** 49/**
50 * How long do we initially wait before retransmitting? 50 * How long do we initially wait before retransmitting?
@@ -263,13 +263,13 @@ struct CadetChannel
263 /** 263 /**
264 * Number identifying this channel in its tunnel. 264 * Number identifying this channel in its tunnel.
265 */ 265 */
266 struct GNUNET_CADET_ChannelTunnelNumber chid; 266 struct GNUNET_CADET_ChannelTunnelNumber ctn;
267 267
268 /** 268 /**
269 * Local tunnel number for local client owning the channel. 269 * Local tunnel number for local client owning the channel.
270 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 ) 270 * ( >= #GNUNET_CADET_LOCAL_CHANNEL_ID_CLI or 0 )
271 */ 271 */
272 struct GNUNET_CADET_ClientChannelNumber lid; 272 struct GNUNET_CADET_ClientChannelNumber ccn;
273 273
274 /** 274 /**
275 * Channel state. 275 * Channel state.
@@ -327,11 +327,11 @@ GCCH_2s (const struct CadetChannel *ch)
327 return "(NULL Channel)"; 327 return "(NULL Channel)";
328 GNUNET_snprintf (buf, 328 GNUNET_snprintf (buf,
329 sizeof (buf), 329 sizeof (buf),
330 "%s:%s chid:%X (%X)", 330 "%s:%s ctn:%X (%X)",
331 GCT_2s (ch->t), 331 GCT_2s (ch->t),
332 GNUNET_h2s (&ch->port), 332 GNUNET_h2s (&ch->port),
333 ch->chid, 333 ch->ctn,
334 ntohl (ch->lid.channel_of_client)); 334 ntohl (ch->ccn.channel_of_client));
335 return buf; 335 return buf;
336} 336}
337 337
@@ -346,7 +346,7 @@ GCCH_2s (const struct CadetChannel *ch)
346struct GNUNET_CADET_ChannelTunnelNumber 346struct GNUNET_CADET_ChannelTunnelNumber
347GCCH_get_id (const struct CadetChannel *ch) 347GCCH_get_id (const struct CadetChannel *ch)
348{ 348{
349 return ch->chid; 349 return ch->ctn;
350} 350}
351 351
352 352
@@ -394,7 +394,7 @@ channel_destroy (struct CadetChannel *ch)
394 } 394 }
395 GCT_remove_channel (ch->t, 395 GCT_remove_channel (ch->t,
396 ch, 396 ch,
397 ch->chid); 397 ch->ctn);
398 GNUNET_free (ch); 398 GNUNET_free (ch);
399} 399}
400 400
@@ -450,7 +450,7 @@ send_create (void *cls)
450 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 450 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
451 msgcc.opt = htonl (options); 451 msgcc.opt = htonl (options);
452 msgcc.port = ch->port; 452 msgcc.port = ch->port;
453 msgcc.chid = ch->chid; 453 msgcc.ctn = ch->ctn;
454 ch->state = CADET_CHANNEL_CREATE_SENT; 454 ch->state = CADET_CHANNEL_CREATE_SENT;
455 ch->last_control_qe = GCT_send (ch->t, 455 ch->last_control_qe = GCT_send (ch->t,
456 &msgcc.header, 456 &msgcc.header,
@@ -463,7 +463,7 @@ send_create (void *cls)
463 * Create a new channel. 463 * Create a new channel.
464 * 464 *
465 * @param owner local client owning the channel 465 * @param owner local client owning the channel
466 * @param owner_id local chid of this channel at the @a owner 466 * @param ccn local number of this channel at the @a owner
467 * @param destination peer to which we should build the channel 467 * @param destination peer to which we should build the channel
468 * @param port desired port at @a destination 468 * @param port desired port at @a destination
469 * @param options options for the channel 469 * @param options options for the channel
@@ -471,7 +471,7 @@ send_create (void *cls)
471 */ 471 */
472struct CadetChannel * 472struct CadetChannel *
473GCCH_channel_local_new (struct CadetClient *owner, 473GCCH_channel_local_new (struct CadetClient *owner,
474 struct GNUNET_CADET_ClientChannelNumber owner_id, 474 struct GNUNET_CADET_ClientChannelNumber ccn,
475 struct CadetPeer *destination, 475 struct CadetPeer *destination,
476 const struct GNUNET_HashCode *port, 476 const struct GNUNET_HashCode *port,
477 uint32_t options) 477 uint32_t options)
@@ -484,11 +484,11 @@ GCCH_channel_local_new (struct CadetClient *owner,
484 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 484 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER));
485 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */ 485 ch->max_pending_messages = (ch->nobuffer) ? 1 : 32; /* FIXME: 32!? Do not hardcode! */
486 ch->owner = owner; 486 ch->owner = owner;
487 ch->lid = owner_id; 487 ch->ccn = ccn;
488 ch->port = *port; 488 ch->port = *port;
489 ch->t = GCP_get_tunnel (destination, 489 ch->t = GCP_get_tunnel (destination,
490 GNUNET_YES); 490 GNUNET_YES);
491 ch->chid = GCT_add_channel (ch->t, 491 ch->ctn = GCT_add_channel (ch->t,
492 ch); 492 ch);
493 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 493 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
494 ch->retry_task = GNUNET_SCHEDULER_add_now (&send_create, 494 ch->retry_task = GNUNET_SCHEDULER_add_now (&send_create,
@@ -497,6 +497,12 @@ GCCH_channel_local_new (struct CadetClient *owner,
497 "# channels", 497 "# channels",
498 1, 498 1,
499 GNUNET_NO); 499 GNUNET_NO);
500 LOG (GNUNET_ERROR_TYPE_DEBUG,
501 "Created channel to port %s at peer %s for client %s using tunnel %s\n",
502 GNUNET_h2s (port),
503 GCP_2s (destination),
504 GSC_2s (owner),
505 GCT_2s (ch->t));
500 return ch; 506 return ch;
501} 507}
502 508
@@ -513,6 +519,10 @@ timeout_closed_cb (void *cls)
513 struct CadetChannel *ch = cls; 519 struct CadetChannel *ch = cls;
514 520
515 ch->retry_task = NULL; 521 ch->retry_task = NULL;
522 LOG (GNUNET_ERROR_TYPE_DEBUG,
523 "Closing incoming channel to port %s from peer %s due to timeout\n",
524 GNUNET_h2s (&ch->port),
525 GCP_2s (GCT_get_destination (ch->t)));
516 channel_destroy (ch); 526 channel_destroy (ch);
517} 527}
518 528
@@ -521,14 +531,14 @@ timeout_closed_cb (void *cls)
521 * Create a new channel based on a request coming in over the network. 531 * Create a new channel based on a request coming in over the network.
522 * 532 *
523 * @param t tunnel to the remote peer 533 * @param t tunnel to the remote peer
524 * @param chid identifier of this channel in the tunnel 534 * @param ctn identifier of this channel in the tunnel
525 * @param port desired local port 535 * @param port desired local port
526 * @param options options for the channel 536 * @param options options for the channel
527 * @return handle to the new channel 537 * @return handle to the new channel
528 */ 538 */
529struct CadetChannel * 539struct CadetChannel *
530GCCH_channel_incoming_new (struct CadetTunnel *t, 540GCCH_channel_incoming_new (struct CadetTunnel *t,
531 struct GNUNET_CADET_ChannelTunnelNumber chid, 541 struct GNUNET_CADET_ChannelTunnelNumber ctn,
532 const struct GNUNET_HashCode *port, 542 const struct GNUNET_HashCode *port,
533 uint32_t options) 543 uint32_t options)
534{ 544{
@@ -538,7 +548,7 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
538 ch = GNUNET_new (struct CadetChannel); 548 ch = GNUNET_new (struct CadetChannel);
539 ch->port = *port; 549 ch->port = *port;
540 ch->t = t; 550 ch->t = t;
541 ch->chid = chid; 551 ch->ctn = ctn;
542 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 552 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
543 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 553 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER));
544 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 554 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE));
@@ -561,6 +571,10 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
561 ch->retry_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, 571 ch->retry_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT,
562 &timeout_closed_cb, 572 &timeout_closed_cb,
563 ch); 573 ch);
574 LOG (GNUNET_ERROR_TYPE_DEBUG,
575 "Created loose incoming channel to port %s from peer %s\n",
576 GNUNET_h2s (&ch->port),
577 GCP_2s (GCT_get_destination (ch->t)));
564 } 578 }
565 else 579 else
566 { 580 {
@@ -603,7 +617,7 @@ send_channel_ack (struct CadetChannel *ch)
603 617
604 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK); 618 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK);
605 msg.header.size = htons (sizeof (msg)); 619 msg.header.size = htons (sizeof (msg));
606 msg.chid = ch->chid; 620 msg.ctn = ch->ctn;
607 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1); 621 msg.mid.mid = htonl (ntohl (ch->mid_recv.mid) - 1);
608 msg.futures = GNUNET_htonll (ch->mid_futures); 622 msg.futures = GNUNET_htonll (ch->mid_futures);
609 if (NULL != ch->last_control_qe) 623 if (NULL != ch->last_control_qe)
@@ -646,7 +660,7 @@ send_ack_to_client (struct CadetChannel *ch,
646 660
647 env = GNUNET_MQ_msg (ack, 661 env = GNUNET_MQ_msg (ack,
648 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 662 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
649 ack->channel_id = ch->lid; 663 ack->ccn = ch->ccn;
650 GSC_send_to_client (c, 664 GSC_send_to_client (c,
651 env); 665 env);
652} 666}
@@ -668,6 +682,12 @@ GCCH_bind (struct CadetChannel *ch,
668 struct GNUNET_CADET_LocalChannelCreateMessage *tcm; 682 struct GNUNET_CADET_LocalChannelCreateMessage *tcm;
669 uint32_t options; 683 uint32_t options;
670 684
685 LOG (GNUNET_ERROR_TYPE_DEBUG,
686 "Binding channel %s from tunnel %s to port %s of client %s\n",
687 GCCH_2s (ch),
688 GCT_2s (ch->t),
689 GNUNET_h2s (&ch->port),
690 GSC_2s (c));
671 if (NULL != ch->retry_task) 691 if (NULL != ch->retry_task)
672 { 692 {
673 /* there might be a timeout task here */ 693 /* there might be a timeout task here */
@@ -682,7 +702,7 @@ GCCH_bind (struct CadetChannel *ch,
682 if (ch->out_of_order) 702 if (ch->out_of_order)
683 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER; 703 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
684 ch->dest = c; 704 ch->dest = c;
685 ch->lid = GSC_bind (c, 705 ch->ccn = GSC_bind (c,
686 ch, 706 ch,
687 GCT_get_destination (ch->t), 707 GCT_get_destination (ch->t),
688 &ch->port, 708 &ch->port,
@@ -695,7 +715,7 @@ GCCH_bind (struct CadetChannel *ch,
695 /* give client it's initial supply of ACKs */ 715 /* give client it's initial supply of ACKs */
696 env = GNUNET_MQ_msg (tcm, 716 env = GNUNET_MQ_msg (tcm,
697 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE); 717 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE);
698 tcm->channel_id = ch->lid; 718 tcm->ccn = ch->ccn;
699 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t)); 719 tcm->peer = *GCP_get_id (GCT_get_destination (ch->t));
700 tcm->port = ch->port; 720 tcm->port = ch->port;
701 tcm->opt = htonl (options); 721 tcm->opt = htonl (options);
@@ -731,7 +751,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch)
731 } 751 }
732 /* Nothing left to do, just finish destruction */ 752 /* Nothing left to do, just finish destruction */
733 GCT_send_channel_destroy (ch->t, 753 GCT_send_channel_destroy (ch->t,
734 ch->chid); 754 ch->ctn);
735 channel_destroy (ch); 755 channel_destroy (ch);
736} 756}
737 757
@@ -760,7 +780,7 @@ GCCH_channel_incoming_destroy (struct CadetChannel *ch)
760 } 780 }
761 /* Nothing left to do, just finish destruction */ 781 /* Nothing left to do, just finish destruction */
762 GCT_send_channel_destroy (ch->t, 782 GCT_send_channel_destroy (ch->t,
763 ch->chid); 783 ch->ctn);
764 channel_destroy (ch); 784 channel_destroy (ch);
765} 785}
766 786
@@ -859,7 +879,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
859 env = GNUNET_MQ_msg_extra (ld, 879 env = GNUNET_MQ_msg_extra (ld,
860 payload_size, 880 payload_size,
861 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 881 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
862 ld->channel_id = ch->lid; 882 ld->ccn = ch->ccn;
863 GNUNET_memcpy (&ld[1], 883 GNUNET_memcpy (&ld[1],
864 &msg[1], 884 &msg[1],
865 payload_size); 885 payload_size);
@@ -978,7 +998,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch)
978 ch->destroy = GNUNET_YES; 998 ch->destroy = GNUNET_YES;
979 env = GNUNET_MQ_msg (tdm, 999 env = GNUNET_MQ_msg (tdm,
980 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY); 1000 GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY);
981 tdm->channel_id = ch->lid; 1001 tdm->ccn = ch->ccn;
982 GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest, 1002 GSC_send_to_client ((NULL != ch->owner) ? ch->owner : ch->dest,
983 env); 1003 env);
984 channel_destroy (ch); 1004 channel_destroy (ch);
@@ -1063,7 +1083,7 @@ GCCH_check_allow_client (struct CadetChannel *ch)
1063 GCCH_2s (ch)); 1083 GCCH_2s (ch));
1064 env = GNUNET_MQ_msg (msg, 1084 env = GNUNET_MQ_msg (msg,
1065 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); 1085 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
1066 msg->channel_id = ch->lid; 1086 msg->ccn = ch->ccn;
1067 GSC_send_to_client (ch->owner ? ch->owner : ch->dest, 1087 GSC_send_to_client (ch->owner ? ch->owner : ch->dest,
1068 env); 1088 env);
1069} 1089}
@@ -1169,7 +1189,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1169 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 1189 crm->data_message.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
1170 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); 1190 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
1171 crm->data_message.mid = ch->mid_send; 1191 crm->data_message.mid = ch->mid_send;
1172 crm->data_message.chid = ch->chid; 1192 crm->data_message.ctn = ch->ctn;
1173 GNUNET_memcpy (&crm[1], 1193 GNUNET_memcpy (&crm[1],
1174 message, 1194 message,
1175 payload_size); 1195 payload_size);
@@ -1243,7 +1263,7 @@ send_client_buffered_data (struct CadetChannel *ch)
1243 if (GNUNET_NO == ch->destroy) 1263 if (GNUNET_NO == ch->destroy)
1244 return; 1264 return;
1245 GCT_send_channel_destroy (ch->t, 1265 GCT_send_channel_destroy (ch->t,
1246 ch->chid); 1266 ch->ctn);
1247 channel_destroy (ch); 1267 channel_destroy (ch);
1248} 1268}
1249 1269
@@ -1290,7 +1310,7 @@ GCCH_debug (struct CadetChannel *ch,
1290 LOG2 (level, 1310 LOG2 (level,
1291 "CHN Channel %s:%X (%p)\n", 1311 "CHN Channel %s:%X (%p)\n",
1292 GCT_2s (ch->t), 1312 GCT_2s (ch->t),
1293 ch->chid, 1313 ch->ctn,
1294 ch); 1314 ch);
1295 if (NULL != ch->owner) 1315 if (NULL != ch->owner)
1296 { 1316 {
@@ -1298,7 +1318,7 @@ GCCH_debug (struct CadetChannel *ch,
1298 "CHN origin %s ready %s local-id: %u\n", 1318 "CHN origin %s ready %s local-id: %u\n",
1299 GSC_2s (ch->owner), 1319 GSC_2s (ch->owner),
1300 ch->client_ready ? "YES" : "NO", 1320 ch->client_ready ? "YES" : "NO",
1301 ntohl (ch->lid.channel_of_client)); 1321 ntohl (ch->ccn.channel_of_client));
1302 } 1322 }
1303 if (NULL != ch->dest) 1323 if (NULL != ch->dest)
1304 { 1324 {
@@ -1306,7 +1326,7 @@ GCCH_debug (struct CadetChannel *ch,
1306 "CHN destination %s ready %s local-id: %u\n", 1326 "CHN destination %s ready %s local-id: %u\n",
1307 GSC_2s (ch->dest), 1327 GSC_2s (ch->dest),
1308 ch->client_ready ? "YES" : "NO", 1328 ch->client_ready ? "YES" : "NO",
1309 ntohl (ch->lid.channel_of_client)); 1329 ntohl (ch->ccn.channel_of_client));
1310 } 1330 }
1311 LOG2 (level, 1331 LOG2 (level,
1312 "CHN Message IDs recv: %d (%LLX), send: %d\n", 1332 "CHN Message IDs recv: %d (%LLX), send: %d\n",