aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_channel.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_channel.c')
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c574
1 files changed, 211 insertions, 363 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c
index a1f6e37c2..664b8a7c1 100644
--- a/src/cadet/gnunet-service-cadet_channel.c
+++ b/src/cadet/gnunet-service-cadet_channel.c
@@ -41,23 +41,26 @@
41#include "gnunet-service-cadet_tunnels.h" 41#include "gnunet-service-cadet_tunnels.h"
42#include "gnunet-service-cadet_paths.h" 42#include "gnunet-service-cadet_paths.h"
43 43
44#define LOG(level,...) GNUNET_log_from (level,"cadet-chn",__VA_ARGS__) 44#define LOG(level, ...) GNUNET_log_from (level, "cadet-chn", __VA_ARGS__)
45 45
46/** 46/**
47 * How long do we initially wait before retransmitting? 47 * How long do we initially wait before retransmitting?
48 */ 48 */
49#define CADET_INITIAL_RETRANSMIT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250) 49#define CADET_INITIAL_RETRANSMIT_TIME \
50 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
50 51
51/** 52/**
52 * How long do we wait before dropping state about incoming 53 * How long do we wait before dropping state about incoming
53 * connection to closed port? 54 * connection to closed port?
54 */ 55 */
55#define TIMEOUT_CLOSED_PORT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) 56#define TIMEOUT_CLOSED_PORT \
57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
56 58
57/** 59/**
58 * How long do we wait at least before retransmitting ever? 60 * How long do we wait at least before retransmitting ever?
59 */ 61 */
60#define MIN_RTT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 75) 62#define MIN_RTT_DELAY \
63 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 75)
61 64
62/** 65/**
63 * Maximum message ID into the future we accept for out-of-order messages. 66 * Maximum message ID into the future we accept for out-of-order messages.
@@ -164,7 +167,6 @@ struct CadetReliableMessage
164 * yet transmitted ever, otherwise the number of (re) transmissions. 167 * yet transmitted ever, otherwise the number of (re) transmissions.
165 */ 168 */
166 int num_transmissions; 169 int num_transmissions;
167
168}; 170};
169 171
170 172
@@ -193,7 +195,6 @@ struct CadetOutOfOrderMessage
193 * The envelope with the payload of the out-of-order message 195 * The envelope with the payload of the out-of-order message
194 */ 196 */
195 struct GNUNET_MQ_Envelope *env; 197 struct GNUNET_MQ_Envelope *env;
196
197}; 198};
198 199
199 200
@@ -238,7 +239,6 @@ struct CadetChannelClient
238 * Can we send data to the client? 239 * Can we send data to the client?
239 */ 240 */
240 int client_ready; 241 int client_ready;
241
242}; 242};
243 243
244 244
@@ -380,7 +380,6 @@ struct CadetChannel
380 * empty. 380 * empty.
381 */ 381 */
382 int destroy; 382 int destroy;
383
384}; 383};
385 384
386 385
@@ -400,12 +399,16 @@ GCCH_2s (const struct CadetChannel *ch)
400 sizeof (buf), 399 sizeof (buf),
401 "Channel %s:%s ctn:%X(%X/%X)", 400 "Channel %s:%s ctn:%X(%X/%X)",
402 (GNUNET_YES == ch->is_loopback) 401 (GNUNET_YES == ch->is_loopback)
403 ? "loopback" 402 ? "loopback"
404 : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))), 403 : GNUNET_i2s (GCP_get_id (GCT_get_destination (ch->t))),
405 GNUNET_h2s (&ch->port), 404 GNUNET_h2s (&ch->port),
406 ch->ctn, 405 ch->ctn,
407 (NULL == ch->owner) ? 0 : ntohl (ch->owner->ccn.channel_of_client), 406 (NULL == ch->owner)
408 (NULL == ch->dest) ? 0 : ntohl (ch->dest->ccn.channel_of_client)); 407 ? 0
408 : ntohl (ch->owner->ccn.channel_of_client),
409 (NULL == ch->dest)
410 ? 0
411 : ntohl (ch->dest->ccn.channel_of_client));
409 return buf; 412 return buf;
410} 413}
411 414
@@ -421,20 +424,15 @@ GCCH_2s (const struct CadetChannel *ch)
421 */ 424 */
422void 425void
423GCCH_hash_port (struct GNUNET_HashCode *h_port, 426GCCH_hash_port (struct GNUNET_HashCode *h_port,
424 const struct GNUNET_HashCode *port, 427 const struct GNUNET_HashCode *port,
425 const struct GNUNET_PeerIdentity *listener) 428 const struct GNUNET_PeerIdentity *listener)
426{ 429{
427 struct GNUNET_HashContext *hc; 430 struct GNUNET_HashContext *hc;
428 431
429 hc = GNUNET_CRYPTO_hash_context_start (); 432 hc = GNUNET_CRYPTO_hash_context_start ();
430 GNUNET_CRYPTO_hash_context_read (hc, 433 GNUNET_CRYPTO_hash_context_read (hc, port, sizeof (*port));
431 port, 434 GNUNET_CRYPTO_hash_context_read (hc, listener, sizeof (*listener));
432 sizeof (*port)); 435 GNUNET_CRYPTO_hash_context_finish (hc, h_port);
433 GNUNET_CRYPTO_hash_context_read (hc,
434 listener,
435 sizeof (*listener));
436 GNUNET_CRYPTO_hash_context_finish (hc,
437 h_port);
438 LOG (GNUNET_ERROR_TYPE_DEBUG, 436 LOG (GNUNET_ERROR_TYPE_DEBUG,
439 "Calculated port hash %s\n", 437 "Calculated port hash %s\n",
440 GNUNET_h2s (h_port)); 438 GNUNET_h2s (h_port));
@@ -467,9 +465,7 @@ free_channel_client (struct CadetChannelClient *ccc)
467 465
468 while (NULL != (com = ccc->head_recv)) 466 while (NULL != (com = ccc->head_recv))
469 { 467 {
470 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 468 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
471 ccc->tail_recv,
472 com);
473 ccc->num_recv--; 469 ccc->num_recv--;
474 GNUNET_MQ_discard (com->env); 470 GNUNET_MQ_discard (com->env);
475 GNUNET_free (com); 471 GNUNET_free (com);
@@ -496,16 +492,13 @@ channel_destroy (struct CadetChannel *ch)
496 GCT_send_cancel (crm->qe); 492 GCT_send_cancel (crm->qe);
497 crm->qe = NULL; 493 crm->qe = NULL;
498 } 494 }
499 GNUNET_CONTAINER_DLL_remove (ch->head_sent, 495 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
500 ch->tail_sent,
501 crm);
502 GNUNET_free (crm->data_message); 496 GNUNET_free (crm->data_message);
503 GNUNET_free (crm); 497 GNUNET_free (crm);
504 } 498 }
505 if (CADET_CHANNEL_LOOSE == ch->state) 499 if (CADET_CHANNEL_LOOSE == ch->state)
506 { 500 {
507 GSC_drop_loose_channel (&ch->h_port, 501 GSC_drop_loose_channel (&ch->h_port, ch);
508 ch);
509 } 502 }
510 if (NULL != ch->owner) 503 if (NULL != ch->owner)
511 { 504 {
@@ -534,9 +527,7 @@ channel_destroy (struct CadetChannel *ch)
534 } 527 }
535 if (GNUNET_NO == ch->is_loopback) 528 if (GNUNET_NO == ch->is_loopback)
536 { 529 {
537 GCT_remove_channel (ch->t, 530 GCT_remove_channel (ch->t, ch, ch->ctn);
538 ch,
539 ch->ctn);
540 ch->t = NULL; 531 ch->t = NULL;
541 } 532 }
542 GNUNET_free (ch); 533 GNUNET_free (ch);
@@ -572,12 +563,9 @@ channel_open_sent_cb (void *cls,
572 LOG (GNUNET_ERROR_TYPE_DEBUG, 563 LOG (GNUNET_ERROR_TYPE_DEBUG,
573 "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n", 564 "Sent CADET_CHANNEL_OPEN on %s, retrying in %s\n",
574 GCCH_2s (ch), 565 GCCH_2s (ch),
575 GNUNET_STRINGS_relative_time_to_string (ch->retry_time, 566 GNUNET_STRINGS_relative_time_to_string (ch->retry_time, GNUNET_YES));
576 GNUNET_YES)); 567 ch->retry_control_task =
577 ch->retry_control_task 568 GNUNET_SCHEDULER_add_delayed (ch->retry_time, &send_channel_open, ch);
578 = GNUNET_SCHEDULER_add_delayed (ch->retry_time,
579 &send_channel_open,
580 ch);
581} 569}
582 570
583 571
@@ -591,31 +579,22 @@ send_channel_open (void *cls)
591{ 579{
592 struct CadetChannel *ch = cls; 580 struct CadetChannel *ch = cls;
593 struct GNUNET_CADET_ChannelOpenMessage msgcc; 581 struct GNUNET_CADET_ChannelOpenMessage msgcc;
594 uint32_t options;
595 582
596 ch->retry_control_task = NULL; 583 ch->retry_control_task = NULL;
597 LOG (GNUNET_ERROR_TYPE_DEBUG, 584 LOG (GNUNET_ERROR_TYPE_DEBUG,
598 "Sending CHANNEL_OPEN message for %s\n", 585 "Sending CHANNEL_OPEN message for %s\n",
599 GCCH_2s (ch)); 586 GCCH_2s (ch));
600 options = 0;
601 if (ch->nobuffer)
602 options |= GNUNET_CADET_OPTION_NOBUFFER;
603 if (ch->reliable)
604 options |= GNUNET_CADET_OPTION_RELIABLE;
605 if (ch->out_of_order)
606 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
607 msgcc.header.size = htons (sizeof (msgcc)); 587 msgcc.header.size = htons (sizeof (msgcc));
608 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); 588 msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN);
609 msgcc.opt = htonl (options); 589 //TODO This will be removed in a major release, because this will be a protocol breaking change. We set the deprecated "reliable" bit here that was removed.
590 msgcc.opt = 2;
610 msgcc.h_port = ch->h_port; 591 msgcc.h_port = ch->h_port;
611 msgcc.ctn = ch->ctn; 592 msgcc.ctn = ch->ctn;
612 ch->state = CADET_CHANNEL_OPEN_SENT; 593 ch->state = CADET_CHANNEL_OPEN_SENT;
613 if (NULL != ch->last_control_qe) 594 if (NULL != ch->last_control_qe)
614 GCT_send_cancel (ch->last_control_qe); 595 GCT_send_cancel (ch->last_control_qe);
615 ch->last_control_qe = GCT_send (ch->t, 596 ch->last_control_qe =
616 &msgcc.header, 597 GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch);
617 &channel_open_sent_cb,
618 ch);
619 GNUNET_assert (NULL == ch->retry_control_task); 598 GNUNET_assert (NULL == ch->retry_control_task);
620} 599}
621 600
@@ -637,9 +616,7 @@ GCCH_tunnel_up (struct CadetChannel *ch)
637 LOG (GNUNET_ERROR_TYPE_DEBUG, 616 LOG (GNUNET_ERROR_TYPE_DEBUG,
638 "Tunnel up, sending CHANNEL_OPEN on %s now\n", 617 "Tunnel up, sending CHANNEL_OPEN on %s now\n",
639 GCCH_2s (ch)); 618 GCCH_2s (ch));
640 ch->retry_control_task 619 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch);
641 = GNUNET_SCHEDULER_add_now (&send_channel_open,
642 ch);
643} 620}
644 621
645 622
@@ -670,54 +647,45 @@ GCCH_channel_local_new (struct CadetClient *owner,
670 647
671 ch = GNUNET_new (struct CadetChannel); 648 ch = GNUNET_new (struct CadetChannel);
672 ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */ 649 ch->mid_recv.mid = htonl (1); /* The OPEN_ACK counts as message 0! */
673 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 650 ch->nobuffer = GNUNET_NO;
674 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 651 ch->reliable = GNUNET_YES;
675 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 652 ch->out_of_order = GNUNET_NO;
676 ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ 653 ch->max_pending_messages =
654 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
677 ch->owner = ccco; 655 ch->owner = ccco;
678 ch->port = *port; 656 ch->port = *port;
679 GCCH_hash_port (&ch->h_port, 657 GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination));
680 port, 658 if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination)))
681 GCP_get_id (destination));
682 if (0 == GNUNET_memcmp (&my_full_id,
683 GCP_get_id (destination)))
684 { 659 {
685 struct OpenPort *op; 660 struct OpenPort *op;
686 661
687 ch->is_loopback = GNUNET_YES; 662 ch->is_loopback = GNUNET_YES;
688 op = GNUNET_CONTAINER_multihashmap_get (open_ports, 663 op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port);
689 &ch->h_port);
690 if (NULL == op) 664 if (NULL == op)
691 { 665 {
692 /* port closed, wait for it to possibly open */ 666 /* port closed, wait for it to possibly open */
693 ch->state = CADET_CHANNEL_LOOSE; 667 ch->state = CADET_CHANNEL_LOOSE;
694 (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, 668 (void) GNUNET_CONTAINER_multihashmap_put (
695 &ch->h_port, 669 loose_channels,
696 ch, 670 &ch->h_port,
697 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 671 ch,
672 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
698 LOG (GNUNET_ERROR_TYPE_DEBUG, 673 LOG (GNUNET_ERROR_TYPE_DEBUG,
699 "Created loose incoming loopback channel to port %s\n", 674 "Created loose incoming loopback channel to port %s\n",
700 GNUNET_h2s (&ch->port)); 675 GNUNET_h2s (&ch->port));
701 } 676 }
702 else 677 else
703 { 678 {
704 GCCH_bind (ch, 679 GCCH_bind (ch, op->c, &op->port);
705 op->c,
706 &op->port);
707 } 680 }
708 } 681 }
709 else 682 else
710 { 683 {
711 ch->t = GCP_get_tunnel (destination, 684 ch->t = GCP_get_tunnel (destination, GNUNET_YES);
712 GNUNET_YES);
713 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 685 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
714 ch->ctn = GCT_add_channel (ch->t, 686 ch->ctn = GCT_add_channel (ch->t, ch);
715 ch);
716 } 687 }
717 GNUNET_STATISTICS_update (stats, 688 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
718 "# channels",
719 1,
720 GNUNET_NO);
721 LOG (GNUNET_ERROR_TYPE_DEBUG, 689 LOG (GNUNET_ERROR_TYPE_DEBUG,
722 "Created channel to port %s at peer %s for %s using %s\n", 690 "Created channel to port %s at peer %s for %s using %s\n",
723 GNUNET_h2s (port), 691 GNUNET_h2s (port),
@@ -771,30 +739,27 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
771 ch->t = t; 739 ch->t = t;
772 ch->ctn = ctn; 740 ch->ctn = ctn;
773 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; 741 ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME;
774 ch->nobuffer = (0 != (options & GNUNET_CADET_OPTION_NOBUFFER)); 742 ch->nobuffer = GNUNET_NO;
775 ch->reliable = (0 != (options & GNUNET_CADET_OPTION_RELIABLE)); 743 ch->reliable = GNUNET_YES;
776 ch->out_of_order = (0 != (options & GNUNET_CADET_OPTION_OUT_OF_ORDER)); 744 ch->out_of_order = GNUNET_NO;
777 ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ 745 ch->max_pending_messages =
778 GNUNET_STATISTICS_update (stats, 746 (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */
779 "# channels", 747 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
780 1, 748
781 GNUNET_NO); 749 op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port);
782
783 op = GNUNET_CONTAINER_multihashmap_get (open_ports,
784 h_port);
785 if (NULL == op) 750 if (NULL == op)
786 { 751 {
787 /* port closed, wait for it to possibly open */ 752 /* port closed, wait for it to possibly open */
788 ch->state = CADET_CHANNEL_LOOSE; 753 ch->state = CADET_CHANNEL_LOOSE;
789 (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, 754 (void) GNUNET_CONTAINER_multihashmap_put (
790 &ch->h_port, 755 loose_channels,
791 ch, 756 &ch->h_port,
792 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 757 ch,
758 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
793 GNUNET_assert (NULL == ch->retry_control_task); 759 GNUNET_assert (NULL == ch->retry_control_task);
794 ch->retry_control_task 760 ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT,
795 = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, 761 &timeout_closed_cb,
796 &timeout_closed_cb, 762 ch);
797 ch);
798 LOG (GNUNET_ERROR_TYPE_DEBUG, 763 LOG (GNUNET_ERROR_TYPE_DEBUG,
799 "Created loose incoming channel to port %s from peer %s\n", 764 "Created loose incoming channel to port %s from peer %s\n",
800 GNUNET_h2s (&ch->port), 765 GNUNET_h2s (&ch->port),
@@ -802,14 +767,9 @@ GCCH_channel_incoming_new (struct CadetTunnel *t,
802 } 767 }
803 else 768 else
804 { 769 {
805 GCCH_bind (ch, 770 GCCH_bind (ch, op->c, &op->port);
806 op->c,
807 &op->port);
808 } 771 }
809 GNUNET_STATISTICS_update (stats, 772 GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO);
810 "# channels",
811 1,
812 GNUNET_NO);
813 return ch; 773 return ch;
814} 774}
815 775
@@ -858,10 +818,7 @@ send_channel_data_ack (struct CadetChannel *ch)
858 GCCH_2s (ch)); 818 GCCH_2s (ch));
859 if (NULL != ch->last_control_qe) 819 if (NULL != ch->last_control_qe)
860 GCT_send_cancel (ch->last_control_qe); 820 GCT_send_cancel (ch->last_control_qe);
861 ch->last_control_qe = GCT_send (ch->t, 821 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
862 &msg.header,
863 &send_ack_cb,
864 ch);
865} 822}
866 823
867 824
@@ -888,10 +845,7 @@ send_open_ack (void *cls)
888 msg.port = ch->port; 845 msg.port = ch->port;
889 if (NULL != ch->last_control_qe) 846 if (NULL != ch->last_control_qe)
890 GCT_send_cancel (ch->last_control_qe); 847 GCT_send_cancel (ch->last_control_qe);
891 ch->last_control_qe = GCT_send (ch->t, 848 ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch);
892 &msg.header,
893 &send_ack_cb,
894 ch);
895} 849}
896 850
897 851
@@ -904,8 +858,9 @@ send_open_ack (void *cls)
904 * @param cti identifier of the connection that delivered the message 858 * @param cti identifier of the connection that delivered the message
905 */ 859 */
906void 860void
907GCCH_handle_duplicate_open (struct CadetChannel *ch, 861GCCH_handle_duplicate_open (
908 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 862 struct CadetChannel *ch,
863 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
909{ 864{
910 if (NULL == ch->dest) 865 if (NULL == ch->dest)
911 { 866 {
@@ -924,9 +879,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch,
924 LOG (GNUNET_ERROR_TYPE_DEBUG, 879 LOG (GNUNET_ERROR_TYPE_DEBUG,
925 "Retransmitting CHANNEL_OPEN_ACK on %s\n", 880 "Retransmitting CHANNEL_OPEN_ACK on %s\n",
926 GCCH_2s (ch)); 881 GCCH_2s (ch));
927 ch->retry_control_task 882 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
928 = GNUNET_SCHEDULER_add_now (&send_open_ack,
929 ch);
930} 883}
931 884
932 885
@@ -938,8 +891,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch,
938 * #GNUNET_NO to send to dest 891 * #GNUNET_NO to send to dest
939 */ 892 */
940static void 893static void
941send_ack_to_client (struct CadetChannel *ch, 894send_ack_to_client (struct CadetChannel *ch, int to_owner)
942 int to_owner)
943{ 895{
944 struct GNUNET_MQ_Envelope *env; 896 struct GNUNET_MQ_Envelope *env;
945 struct GNUNET_CADET_LocalAck *ack; 897 struct GNUNET_CADET_LocalAck *ack;
@@ -953,8 +905,7 @@ send_ack_to_client (struct CadetChannel *ch,
953 GNUNET_assert (GNUNET_YES == ch->destroy); 905 GNUNET_assert (GNUNET_YES == ch->destroy);
954 return; 906 return;
955 } 907 }
956 env = GNUNET_MQ_msg (ack, 908 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
957 GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK);
958 ack->ccn = ccc->ccn; 909 ack->ccn = ccc->ccn;
959 LOG (GNUNET_ERROR_TYPE_DEBUG, 910 LOG (GNUNET_ERROR_TYPE_DEBUG,
960 "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n", 911 "Sending CADET_LOCAL_ACK to %s (%s) at ccn %X (%u/%u pending)\n",
@@ -963,8 +914,7 @@ send_ack_to_client (struct CadetChannel *ch,
963 ntohl (ack->ccn.channel_of_client), 914 ntohl (ack->ccn.channel_of_client),
964 ch->pending_messages, 915 ch->pending_messages,
965 ch->max_pending_messages); 916 ch->max_pending_messages);
966 GSC_send_to_client (ccc->c, 917 GSC_send_to_client (ccc->c, env);
967 env);
968} 918}
969 919
970 920
@@ -980,7 +930,7 @@ send_ack_to_client (struct CadetChannel *ch,
980void 930void
981GCCH_bind (struct CadetChannel *ch, 931GCCH_bind (struct CadetChannel *ch,
982 struct CadetClient *c, 932 struct CadetClient *c,
983 const struct GNUNET_HashCode *port) 933 const struct GNUNET_HashCode *port)
984{ 934{
985 uint32_t options; 935 uint32_t options;
986 struct CadetChannelClient *cccd; 936 struct CadetChannelClient *cccd;
@@ -998,12 +948,6 @@ GCCH_bind (struct CadetChannel *ch,
998 ch->retry_control_task = NULL; 948 ch->retry_control_task = NULL;
999 } 949 }
1000 options = 0; 950 options = 0;
1001 if (ch->nobuffer)
1002 options |= GNUNET_CADET_OPTION_NOBUFFER;
1003 if (ch->reliable)
1004 options |= GNUNET_CADET_OPTION_RELIABLE;
1005 if (ch->out_of_order)
1006 options |= GNUNET_CADET_OPTION_OUT_OF_ORDER;
1007 cccd = GNUNET_new (struct CadetChannelClient); 951 cccd = GNUNET_new (struct CadetChannelClient);
1008 GNUNET_assert (NULL == ch->dest); 952 GNUNET_assert (NULL == ch->dest);
1009 ch->dest = cccd; 953 ch->dest = cccd;
@@ -1013,9 +957,8 @@ GCCH_bind (struct CadetChannel *ch,
1013 cccd->ccn = GSC_bind (c, 957 cccd->ccn = GSC_bind (c,
1014 ch, 958 ch,
1015 (GNUNET_YES == ch->is_loopback) 959 (GNUNET_YES == ch->is_loopback)
1016 ? GCP_get (&my_full_id, 960 ? GCP_get (&my_full_id, GNUNET_YES)
1017 GNUNET_YES) 961 : GCT_get_destination (ch->t),
1018 : GCT_get_destination (ch->t),
1019 port, 962 port,
1020 options); 963 options);
1021 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < 964 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
@@ -1024,24 +967,19 @@ GCCH_bind (struct CadetChannel *ch,
1024 if (GNUNET_YES == ch->is_loopback) 967 if (GNUNET_YES == ch->is_loopback)
1025 { 968 {
1026 ch->state = CADET_CHANNEL_OPEN_SENT; 969 ch->state = CADET_CHANNEL_OPEN_SENT;
1027 GCCH_handle_channel_open_ack (ch, 970 GCCH_handle_channel_open_ack (ch, NULL, port);
1028 NULL,
1029 port);
1030 } 971 }
1031 else 972 else
1032 { 973 {
1033 /* notify other peer that we accepted the connection */ 974 /* notify other peer that we accepted the connection */
1034 ch->state = CADET_CHANNEL_READY; 975 ch->state = CADET_CHANNEL_READY;
1035 ch->retry_control_task 976 ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch);
1036 = GNUNET_SCHEDULER_add_now (&send_open_ack,
1037 ch);
1038 } 977 }
1039 /* give client it's initial supply of ACKs */ 978 /* give client it's initial supply of ACKs */
1040 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < 979 GNUNET_assert (ntohl (cccd->ccn.channel_of_client) <
1041 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); 980 GNUNET_CADET_LOCAL_CHANNEL_ID_CLI);
1042 for (unsigned int i=0;i<ch->max_pending_messages;i++) 981 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1043 send_ack_to_client (ch, 982 send_ack_to_client (ch, GNUNET_NO);
1044 GNUNET_NO);
1045} 983}
1046 984
1047 985
@@ -1061,9 +999,7 @@ signal_remote_destroy_cb (void *cls)
1061 /* Find which end is left... */ 999 /* Find which end is left... */
1062 ch->retry_control_task = NULL; 1000 ch->retry_control_task = NULL;
1063 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1001 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1064 GSC_handle_remote_channel_destroy (ccc->c, 1002 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
1065 ccc->ccn,
1066 ch);
1067 channel_destroy (ch); 1003 channel_destroy (ch);
1068} 1004}
1069 1005
@@ -1086,16 +1022,14 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1086 GSC_2s (c), 1022 GSC_2s (c),
1087 GCCH_2s (ch)); 1023 GCCH_2s (ch));
1088 GNUNET_assert (NULL != c); 1024 GNUNET_assert (NULL != c);
1089 if ( (NULL != ch->owner) && 1025 if ((NULL != ch->owner) && (c == ch->owner->c) &&
1090 (c == ch->owner->c) && 1026 (ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1091 (ccn.channel_of_client == ch->owner->ccn.channel_of_client) )
1092 { 1027 {
1093 free_channel_client (ch->owner); 1028 free_channel_client (ch->owner);
1094 ch->owner = NULL; 1029 ch->owner = NULL;
1095 } 1030 }
1096 else if ( (NULL != ch->dest) && 1031 else if ((NULL != ch->dest) && (c == ch->dest->c) &&
1097 (c == ch->dest->c) && 1032 (ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1098 (ccn.channel_of_client == ch->dest->ccn.channel_of_client) )
1099 { 1033 {
1100 free_channel_client (ch->dest); 1034 free_channel_client (ch->dest);
1101 ch->dest = NULL; 1035 ch->dest = NULL;
@@ -1112,24 +1046,20 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1112 channel_destroy (ch); 1046 channel_destroy (ch);
1113 return; 1047 return;
1114 } 1048 }
1115 if ( (NULL != ch->head_sent) && 1049 if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest)))
1116 ( (NULL != ch->owner) ||
1117 (NULL != ch->dest) ) )
1118 { 1050 {
1119 /* Wait for other end to destroy us as well, 1051 /* Wait for other end to destroy us as well,
1120 and otherwise allow send queue to be transmitted first */ 1052 and otherwise allow send queue to be transmitted first */
1121 ch->destroy = GNUNET_YES; 1053 ch->destroy = GNUNET_YES;
1122 return; 1054 return;
1123 } 1055 }
1124 if ( (GNUNET_YES == ch->is_loopback) && 1056 if ((GNUNET_YES == ch->is_loopback) &&
1125 ( (NULL != ch->owner) || 1057 ((NULL != ch->owner) || (NULL != ch->dest)))
1126 (NULL != ch->dest) ) )
1127 { 1058 {
1128 if (NULL != ch->retry_control_task) 1059 if (NULL != ch->retry_control_task)
1129 GNUNET_SCHEDULER_cancel (ch->retry_control_task); 1060 GNUNET_SCHEDULER_cancel (ch->retry_control_task);
1130 ch->retry_control_task 1061 ch->retry_control_task =
1131 = GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, 1062 GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch);
1132 ch);
1133 return; 1063 return;
1134 } 1064 }
1135 if (GNUNET_NO == ch->is_loopback) 1065 if (GNUNET_NO == ch->is_loopback)
@@ -1144,8 +1074,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1144 case CADET_CHANNEL_LOOSE: 1074 case CADET_CHANNEL_LOOSE:
1145 break; 1075 break;
1146 default: 1076 default:
1147 GCT_send_channel_destroy (ch->t, 1077 GCT_send_channel_destroy (ch->t, ch->ctn);
1148 ch->ctn);
1149 } 1078 }
1150 } 1079 }
1151 /* Nothing left to do, just finish destruction */ 1080 /* Nothing left to do, just finish destruction */
@@ -1163,9 +1092,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch,
1163 * @param port port number (needed to verify receiver knows the port) 1092 * @param port port number (needed to verify receiver knows the port)
1164 */ 1093 */
1165void 1094void
1166GCCH_handle_channel_open_ack (struct CadetChannel *ch, 1095GCCH_handle_channel_open_ack (
1167 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1096 struct CadetChannel *ch,
1168 const struct GNUNET_HashCode *port) 1097 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1098 const struct GNUNET_HashCode *port)
1169{ 1099{
1170 switch (ch->state) 1100 switch (ch->state)
1171 { 1101 {
@@ -1184,8 +1114,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch,
1184 GNUNET_break_op (0); 1114 GNUNET_break_op (0);
1185 return; 1115 return;
1186 } 1116 }
1187 if (0 != GNUNET_memcmp (&ch->port, 1117 if (0 != GNUNET_memcmp (&ch->port, port))
1188 port))
1189 { 1118 {
1190 /* Other peer failed to provide the right port, 1119 /* Other peer failed to provide the right port,
1191 refuse connection. */ 1120 refuse connection. */
@@ -1203,19 +1132,15 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch,
1203 ch->state = CADET_CHANNEL_READY; 1132 ch->state = CADET_CHANNEL_READY;
1204 /* On first connect, send client as many ACKs as we allow messages 1133 /* On first connect, send client as many ACKs as we allow messages
1205 to be buffered! */ 1134 to be buffered! */
1206 for (unsigned int i=0;i<ch->max_pending_messages;i++) 1135 for (unsigned int i = 0; i < ch->max_pending_messages; i++)
1207 send_ack_to_client (ch, 1136 send_ack_to_client (ch, GNUNET_YES);
1208 GNUNET_YES);
1209 break; 1137 break;
1210 case CADET_CHANNEL_READY: 1138 case CADET_CHANNEL_READY:
1211 /* duplicate ACK, maybe we retried the CREATE. Ignore. */ 1139 /* duplicate ACK, maybe we retried the CREATE. Ignore. */
1212 LOG (GNUNET_ERROR_TYPE_DEBUG, 1140 LOG (GNUNET_ERROR_TYPE_DEBUG,
1213 "Received duplicate channel OPEN_ACK for %s\n", 1141 "Received duplicate channel OPEN_ACK for %s\n",
1214 GCCH_2s (ch)); 1142 GCCH_2s (ch));
1215 GNUNET_STATISTICS_update (stats, 1143 GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO);
1216 "# duplicate CREATE_ACKs",
1217 1,
1218 GNUNET_NO);
1219 break; 1144 break;
1220 } 1145 }
1221} 1146}
@@ -1264,9 +1189,10 @@ is_before (void *cls,
1264 * @param msg message that was received 1189 * @param msg message that was received
1265 */ 1190 */
1266void 1191void
1267GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, 1192GCCH_handle_channel_plaintext_data (
1268 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1193 struct CadetChannel *ch,
1269 const struct GNUNET_CADET_ChannelAppDataMessage *msg) 1194 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1195 const struct GNUNET_CADET_ChannelAppDataMessage *msg)
1270{ 1196{
1271 struct GNUNET_MQ_Envelope *env; 1197 struct GNUNET_MQ_Envelope *env;
1272 struct GNUNET_CADET_LocalData *ld; 1198 struct GNUNET_CADET_LocalData *ld;
@@ -1280,8 +1206,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1280 uint32_t delta; 1206 uint32_t delta;
1281 1207
1282 GNUNET_assert (GNUNET_NO == ch->is_loopback); 1208 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1283 if ( (NULL == ch->owner) && 1209 if ((NULL == ch->owner) && (NULL == ch->dest))
1284 (NULL == ch->dest) )
1285 { 1210 {
1286 /* This client is gone, but we still have messages to send to 1211 /* This client is gone, but we still have messages to send to
1287 the other end (which is why @a ch is not yet dead). However, 1212 the other end (which is why @a ch is not yet dead). However,
@@ -1291,8 +1216,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1291 GCCH_2s (ch)); 1216 GCCH_2s (ch));
1292 /* send back DESTROY notification to stop further retransmissions! */ 1217 /* send back DESTROY notification to stop further retransmissions! */
1293 if (GNUNET_YES == ch->destroy) 1218 if (GNUNET_YES == ch->destroy)
1294 GCT_send_channel_destroy (ch->t, 1219 GCT_send_channel_destroy (ch->t, ch->ctn);
1295 ch->ctn);
1296 return; 1220 return;
1297 } 1221 }
1298 payload_size = ntohs (msg->header.size) - sizeof (*msg); 1222 payload_size = ntohs (msg->header.size) - sizeof (*msg);
@@ -1300,9 +1224,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1300 payload_size, 1224 payload_size,
1301 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1225 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1302 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; 1226 ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn;
1303 GNUNET_memcpy (&ld[1], 1227 GNUNET_memcpy (&ld[1], &msg[1], payload_size);
1304 &msg[1],
1305 payload_size);
1306 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1228 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1307 if (GNUNET_YES == ccc->client_ready) 1229 if (GNUNET_YES == ccc->client_ready)
1308 { 1230 {
@@ -1312,13 +1234,12 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1312 * - The channel is reliable and MID matches next expected MID 1234 * - The channel is reliable and MID matches next expected MID
1313 * - The channel is unreliable and MID is before lowest seen MID 1235 * - The channel is unreliable and MID is before lowest seen MID
1314 */ 1236 */
1315 if ( (GNUNET_YES == ch->out_of_order) || 1237 if ((GNUNET_YES == ch->out_of_order) ||
1316 ((msg->mid.mid == ch->mid_recv.mid) && 1238 ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) ||
1317 (GNUNET_YES == ch->reliable)) || 1239 ((GNUNET_NO == ch->reliable) &&
1318 ((GNUNET_NO == ch->reliable) && 1240 (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) &&
1319 (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && 1241 ((NULL == ccc->head_recv) ||
1320 ((NULL == ccc->head_recv) || 1242 (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))))
1321 (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))) )
1322 { 1243 {
1323 LOG (GNUNET_ERROR_TYPE_DEBUG, 1244 LOG (GNUNET_ERROR_TYPE_DEBUG,
1324 "Giving %u bytes of payload with MID %u from %s to client %s\n", 1245 "Giving %u bytes of payload with MID %u from %s to client %s\n",
@@ -1327,24 +1248,22 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1327 GCCH_2s (ch), 1248 GCCH_2s (ch),
1328 GSC_2s (ccc->c)); 1249 GSC_2s (ccc->c));
1329 ccc->client_ready = GNUNET_NO; 1250 ccc->client_ready = GNUNET_NO;
1330 GSC_send_to_client (ccc->c, 1251 GSC_send_to_client (ccc->c, env);
1331 env);
1332 if (GNUNET_NO == ch->out_of_order) 1252 if (GNUNET_NO == ch->out_of_order)
1333 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); 1253 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1334 else 1254 else
1335 ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); 1255 ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid));
1336 ch->mid_futures >>= 1; 1256 ch->mid_futures >>= 1;
1337 if ( (GNUNET_YES == ch->out_of_order) && 1257 if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable))
1338 (GNUNET_NO == ch->reliable) )
1339 { 1258 {
1340 /* possibly shift by more if we skipped messages */ 1259 /* possibly shift by more if we skipped messages */
1341 uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid); 1260 uint64_t delta = htonl (msg->mid.mid) - 1 - ntohl (ch->mid_recv.mid);
1342 1261
1343 if (delta > 63) 1262 if (delta > 63)
1344 ch->mid_futures = 0; 1263 ch->mid_futures = 0;
1345 else 1264 else
1346 ch->mid_futures >>= delta; 1265 ch->mid_futures >>= delta;
1347 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); 1266 ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid));
1348 } 1267 }
1349 send_channel_data_ack (ch); 1268 send_channel_data_ack (ch);
1350 return; 1269 return;
@@ -1357,8 +1276,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1357 mid_min = ntohl (ch->mid_recv.mid); 1276 mid_min = ntohl (ch->mid_recv.mid);
1358 mid_max = mid_min + ch->max_pending_messages; 1277 mid_max = mid_min + ch->max_pending_messages;
1359 mid_msg = ntohl (msg->mid.mid); 1278 mid_msg = ntohl (msg->mid.mid);
1360 if ( ( (uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || 1279 if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) ||
1361 ( (uint32_t) (mid_max - mid_msg) > ch->max_pending_messages) ) 1280 ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages))
1362 { 1281 {
1363 LOG (GNUNET_ERROR_TYPE_DEBUG, 1282 LOG (GNUNET_ERROR_TYPE_DEBUG,
1364 "%s at %u drops ancient or far-future message %u\n", 1283 "%s at %u drops ancient or far-future message %u\n",
@@ -1386,10 +1305,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1386 (unsigned int) payload_size, 1305 (unsigned int) payload_size,
1387 GCCH_2s (ch), 1306 GCCH_2s (ch),
1388 ntohl (msg->mid.mid)); 1307 ntohl (msg->mid.mid));
1389 GNUNET_STATISTICS_update (stats, 1308 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1390 "# duplicate DATA",
1391 1,
1392 GNUNET_NO);
1393 GNUNET_MQ_discard (env); 1309 GNUNET_MQ_discard (env);
1394 send_channel_data_ack (ch); 1310 send_channel_data_ack (ch);
1395 return; 1311 return;
@@ -1411,8 +1327,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1411 * We always send if possible in this case. 1327 * We always send if possible in this case.
1412 * It is guaranteed that the queued MID < received MID 1328 * It is guaranteed that the queued MID < received MID
1413 **/ 1329 **/
1414 if ((NULL != ccc->head_recv) && 1330 if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready))
1415 (GNUNET_YES == ccc->client_ready))
1416 { 1331 {
1417 next_msg = ccc->head_recv; 1332 next_msg = ccc->head_recv;
1418 LOG (GNUNET_ERROR_TYPE_DEBUG, 1333 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1421,14 +1336,11 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1421 GCCH_2s (ch), 1336 GCCH_2s (ch),
1422 GSC_2s (ccc->c)); 1337 GSC_2s (ccc->c));
1423 ccc->client_ready = GNUNET_NO; 1338 ccc->client_ready = GNUNET_NO;
1424 GSC_send_to_client (ccc->c, 1339 GSC_send_to_client (ccc->c, next_msg->env);
1425 next_msg->env);
1426 ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); 1340 ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid));
1427 ch->mid_futures >>= 1; 1341 ch->mid_futures >>= 1;
1428 send_channel_data_ack (ch); 1342 send_channel_data_ack (ch);
1429 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1343 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg);
1430 ccc->tail_recv,
1431 next_msg);
1432 ccc->num_recv--; 1344 ccc->num_recv--;
1433 /* Do not process duplicate MID */ 1345 /* Do not process duplicate MID */
1434 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ 1346 if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */
@@ -1473,9 +1385,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1473 GNUNET_NO); 1385 GNUNET_NO);
1474 drop = ccc->head_recv; 1386 drop = ccc->head_recv;
1475 GNUNET_assert (NULL != drop); 1387 GNUNET_assert (NULL != drop);
1476 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1388 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop);
1477 ccc->tail_recv,
1478 drop);
1479 ccc->num_recv--; 1389 ccc->num_recv--;
1480 GNUNET_MQ_discard (drop->env); 1390 GNUNET_MQ_discard (drop->env);
1481 GNUNET_free (drop); 1391 GNUNET_free (drop);
@@ -1506,13 +1416,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1506 (unsigned int) payload_size, 1416 (unsigned int) payload_size,
1507 GCCH_2s (ch), 1417 GCCH_2s (ch),
1508 ntohl (msg->mid.mid)); 1418 ntohl (msg->mid.mid));
1509 GNUNET_STATISTICS_update (stats, 1419 GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO);
1510 "# duplicate DATA", 1420 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
1511 1,
1512 GNUNET_NO);
1513 GNUNET_CONTAINER_DLL_remove (ccc->head_recv,
1514 ccc->tail_recv,
1515 com);
1516 ccc->num_recv--; 1421 ccc->num_recv--;
1517 GNUNET_MQ_discard (com->env); 1422 GNUNET_MQ_discard (com->env);
1518 GNUNET_free (com); 1423 GNUNET_free (com);
@@ -1521,9 +1426,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch,
1521 } 1426 }
1522 LOG (GNUNET_ERROR_TYPE_DEBUG, 1427 LOG (GNUNET_ERROR_TYPE_DEBUG,
1523 "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n", 1428 "Queued %s payload of %u bytes on %s-%X(%p) (mid %u, need %u first)\n",
1524 (GNUNET_YES == ccc->client_ready) 1429 (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready",
1525 ? "out-of-order"
1526 : "client-not-ready",
1527 (unsigned int) payload_size, 1430 (unsigned int) payload_size,
1528 GCCH_2s (ch), 1431 GCCH_2s (ch),
1529 ntohl (ccc->ccn.channel_of_client), 1432 ntohl (ccc->ccn.channel_of_client),
@@ -1571,10 +1474,7 @@ retry_transmission (void *cls)
1571 "Retrying transmission on %s of message %u\n", 1474 "Retrying transmission on %s of message %u\n",
1572 GCCH_2s (ch), 1475 GCCH_2s (ch),
1573 (unsigned int) ntohl (crm->data_message->mid.mid)); 1476 (unsigned int) ntohl (crm->data_message->mid.mid));
1574 crm->qe = GCT_send (ch->t, 1477 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
1575 &crm->data_message->header,
1576 &data_sent_cb,
1577 crm);
1578 GNUNET_assert (NULL == ch->retry_data_task); 1478 GNUNET_assert (NULL == ch->retry_data_task);
1579} 1479}
1580 1480
@@ -1592,9 +1492,7 @@ handle_matching_ack (struct CadetChannel *ch,
1592 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1492 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1593 struct CadetReliableMessage *crm) 1493 struct CadetReliableMessage *crm)
1594{ 1494{
1595 GNUNET_CONTAINER_DLL_remove (ch->head_sent, 1495 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1596 ch->tail_sent,
1597 crm);
1598 ch->pending_messages--; 1496 ch->pending_messages--;
1599 GNUNET_assert (ch->pending_messages < ch->max_pending_messages); 1497 GNUNET_assert (ch->pending_messages < ch->max_pending_messages);
1600 LOG (GNUNET_ERROR_TYPE_DEBUG, 1498 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1607,23 +1505,19 @@ handle_matching_ack (struct CadetChannel *ch,
1607 GCT_send_cancel (crm->qe); 1505 GCT_send_cancel (crm->qe);
1608 crm->qe = NULL; 1506 crm->qe = NULL;
1609 } 1507 }
1610 if ( (1 == crm->num_transmissions) && 1508 if ((1 == crm->num_transmissions) && (NULL != cti))
1611 (NULL != cti) )
1612 { 1509 {
1613 GCC_ack_observed (cti); 1510 GCC_ack_observed (cti);
1614 if (0 == GNUNET_memcmp (cti, 1511 if (0 == GNUNET_memcmp (cti, &crm->connection_taken))
1615 &crm->connection_taken))
1616 { 1512 {
1617 GCC_latency_observed (cti, 1513 GCC_latency_observed (cti,
1618 GNUNET_TIME_absolute_get_duration (crm->first_transmission_time)); 1514 GNUNET_TIME_absolute_get_duration (
1515 crm->first_transmission_time));
1619 } 1516 }
1620 } 1517 }
1621 GNUNET_free (crm->data_message); 1518 GNUNET_free (crm->data_message);
1622 GNUNET_free (crm); 1519 GNUNET_free (crm);
1623 send_ack_to_client (ch, 1520 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1624 (NULL == ch->owner)
1625 ? GNUNET_NO
1626 : GNUNET_YES);
1627} 1521}
1628 1522
1629 1523
@@ -1636,9 +1530,10 @@ handle_matching_ack (struct CadetChannel *ch,
1636 * @param ack details about what was received 1530 * @param ack details about what was received
1637 */ 1531 */
1638void 1532void
1639GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, 1533GCCH_handle_channel_plaintext_data_ack (
1640 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, 1534 struct CadetChannel *ch,
1641 const struct GNUNET_CADET_ChannelDataAckMessage *ack) 1535 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti,
1536 const struct GNUNET_CADET_ChannelDataAckMessage *ack)
1642{ 1537{
1643 struct CadetReliableMessage *crm; 1538 struct CadetReliableMessage *crm;
1644 struct CadetReliableMessage *crmn; 1539 struct CadetReliableMessage *crmn;
@@ -1660,9 +1555,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1660 mid_base = ntohl (ack->mid.mid); 1555 mid_base = ntohl (ack->mid.mid);
1661 mid_mask = GNUNET_htonll (ack->futures); 1556 mid_mask = GNUNET_htonll (ack->futures);
1662 found = GNUNET_NO; 1557 found = GNUNET_NO;
1663 for (crm = ch->head_sent; 1558 for (crm = ch->head_sent; NULL != crm; crm = crmn)
1664 NULL != crm;
1665 crm = crmn)
1666 { 1559 {
1667 crmn = crm->next; 1560 crmn = crm->next;
1668 delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); 1561 delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base);
@@ -1674,9 +1567,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1674 (unsigned int) mid_base, 1567 (unsigned int) mid_base,
1675 ntohl (crm->data_message->mid.mid), 1568 ntohl (crm->data_message->mid.mid),
1676 GCCH_2s (ch)); 1569 GCCH_2s (ch));
1677 handle_matching_ack (ch, 1570 handle_matching_ack (ch, cti, crm);
1678 cti,
1679 crm);
1680 found = GNUNET_YES; 1571 found = GNUNET_YES;
1681 continue; 1572 continue;
1682 } 1573 }
@@ -1694,9 +1585,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1694 "Got DATA_ACK with mask for %u on %s\n", 1585 "Got DATA_ACK with mask for %u on %s\n",
1695 ntohl (crm->data_message->mid.mid), 1586 ntohl (crm->data_message->mid.mid),
1696 GCCH_2s (ch)); 1587 GCCH_2s (ch));
1697 handle_matching_ack (ch, 1588 handle_matching_ack (ch, cti, crm);
1698 cti,
1699 crm);
1700 found = GNUNET_YES; 1589 found = GNUNET_YES;
1701 } 1590 }
1702 } 1591 }
@@ -1707,10 +1596,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1707 LOG (GNUNET_ERROR_TYPE_DEBUG, 1596 LOG (GNUNET_ERROR_TYPE_DEBUG,
1708 "Duplicate DATA_ACK on %s, ignoring\n", 1597 "Duplicate DATA_ACK on %s, ignoring\n",
1709 GCCH_2s (ch)); 1598 GCCH_2s (ch));
1710 GNUNET_STATISTICS_update (stats, 1599 GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO);
1711 "# duplicate DATA_ACKs",
1712 1,
1713 GNUNET_NO);
1714 return; 1600 return;
1715 } 1601 }
1716 if (NULL != ch->retry_data_task) 1602 if (NULL != ch->retry_data_task)
@@ -1718,12 +1604,10 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1718 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1604 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1719 ch->retry_data_task = NULL; 1605 ch->retry_data_task = NULL;
1720 } 1606 }
1721 if ( (NULL != ch->head_sent) && 1607 if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe))
1722 (NULL == ch->head_sent->qe) ) 1608 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1723 ch->retry_data_task 1609 &retry_transmission,
1724 = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, 1610 ch);
1725 &retry_transmission,
1726 ch);
1727} 1611}
1728 1612
1729 1613
@@ -1737,8 +1621,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch,
1737 * NULL if we are simulating receiving a destroy due to shutdown 1621 * NULL if we are simulating receiving a destroy due to shutdown
1738 */ 1622 */
1739void 1623void
1740GCCH_handle_remote_destroy (struct CadetChannel *ch, 1624GCCH_handle_remote_destroy (
1741 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) 1625 struct CadetChannel *ch,
1626 const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti)
1742{ 1627{
1743 struct CadetChannelClient *ccc; 1628 struct CadetChannelClient *ccc;
1744 1629
@@ -1753,8 +1638,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch,
1753 return; 1638 return;
1754 } 1639 }
1755 ccc = (NULL != ch->owner) ? ch->owner : ch->dest; 1640 ccc = (NULL != ch->owner) ? ch->owner : ch->dest;
1756 if ( (NULL != ccc) && 1641 if ((NULL != ccc) && (NULL != ccc->head_recv))
1757 (NULL != ccc->head_recv) )
1758 { 1642 {
1759 LOG (GNUNET_ERROR_TYPE_WARNING, 1643 LOG (GNUNET_ERROR_TYPE_WARNING,
1760 "Lost end of transmission due to remote shutdown on %s\n", 1644 "Lost end of transmission due to remote shutdown on %s\n",
@@ -1763,9 +1647,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch,
1763 } 1647 }
1764 ch->destroy = GNUNET_YES; 1648 ch->destroy = GNUNET_YES;
1765 if (NULL != ccc) 1649 if (NULL != ccc)
1766 GSC_handle_remote_channel_destroy (ccc->c, 1650 GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch);
1767 ccc->ccn,
1768 ch);
1769 channel_destroy (ch); 1651 channel_destroy (ch);
1770} 1652}
1771 1653
@@ -1783,8 +1665,7 @@ cmp_crm_by_next_retry (void *cls,
1783 struct CadetReliableMessage *crm1, 1665 struct CadetReliableMessage *crm1,
1784 struct CadetReliableMessage *crm2) 1666 struct CadetReliableMessage *crm2)
1785{ 1667{
1786 if (crm1->next_retry.abs_value_us < 1668 if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us)
1787 crm2->next_retry.abs_value_us)
1788 return GNUNET_YES; 1669 return GNUNET_YES;
1789 return GNUNET_NO; 1670 return GNUNET_NO;
1790} 1671}
@@ -1810,18 +1691,13 @@ data_sent_cb (void *cls,
1810 GNUNET_assert (GNUNET_NO == ch->is_loopback); 1691 GNUNET_assert (GNUNET_NO == ch->is_loopback);
1811 GNUNET_assert (NULL != crm->qe); 1692 GNUNET_assert (NULL != crm->qe);
1812 crm->qe = NULL; 1693 crm->qe = NULL;
1813 GNUNET_CONTAINER_DLL_remove (ch->head_sent, 1694 GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm);
1814 ch->tail_sent,
1815 crm);
1816 if (GNUNET_NO == ch->reliable) 1695 if (GNUNET_NO == ch->reliable)
1817 { 1696 {
1818 GNUNET_free (crm->data_message); 1697 GNUNET_free (crm->data_message);
1819 GNUNET_free (crm); 1698 GNUNET_free (crm);
1820 ch->pending_messages--; 1699 ch->pending_messages--;
1821 send_ack_to_client (ch, 1700 send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES);
1822 (NULL == ch->owner)
1823 ? GNUNET_NO
1824 : GNUNET_YES);
1825 return; 1701 return;
1826 } 1702 }
1827 if (NULL == cid) 1703 if (NULL == cid)
@@ -1841,8 +1717,7 @@ data_sent_cb (void *cls,
1841 GCC_ack_expected (cid); 1717 GCC_ack_expected (cid);
1842 } 1718 }
1843 } 1719 }
1844 if ( (0 == crm->retry_delay.rel_value_us) && 1720 if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid))
1845 (NULL != cid) )
1846 { 1721 {
1847 struct CadetConnection *cc = GCC_lookup (cid); 1722 struct CadetConnection *cc = GCC_lookup (cid);
1848 1723
@@ -1852,8 +1727,7 @@ data_sent_cb (void *cls,
1852 crm->retry_delay = ch->retry_time; 1727 crm->retry_delay = ch->retry_time;
1853 } 1728 }
1854 crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); 1729 crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay);
1855 crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, 1730 crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY);
1856 MIN_RTT_DELAY);
1857 crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); 1731 crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay);
1858 1732
1859 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, 1733 GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage,
@@ -1866,16 +1740,16 @@ data_sent_cb (void *cls,
1866 "Message %u sent, next transmission on %s in %s\n", 1740 "Message %u sent, next transmission on %s in %s\n",
1867 (unsigned int) ntohl (crm->data_message->mid.mid), 1741 (unsigned int) ntohl (crm->data_message->mid.mid),
1868 GCCH_2s (ch), 1742 GCCH_2s (ch),
1869 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (ch->head_sent->next_retry), 1743 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
1744 ch->head_sent->next_retry),
1870 GNUNET_YES)); 1745 GNUNET_YES));
1871 if (NULL == ch->head_sent->qe) 1746 if (NULL == ch->head_sent->qe)
1872 { 1747 {
1873 if (NULL != ch->retry_data_task) 1748 if (NULL != ch->retry_data_task)
1874 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1749 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1875 ch->retry_data_task 1750 ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry,
1876 = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, 1751 &retry_transmission,
1877 &retry_transmission, 1752 ch);
1878 ch);
1879 } 1753 }
1880} 1754}
1881 1755
@@ -1921,19 +1795,16 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1921 struct GNUNET_CADET_LocalData *ld; 1795 struct GNUNET_CADET_LocalData *ld;
1922 int ack_to_owner; 1796 int ack_to_owner;
1923 1797
1924 env = GNUNET_MQ_msg_extra (ld, 1798 env =
1925 buf_len, 1799 GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
1926 GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1800 if ((NULL != ch->owner) &&
1927 if ( (NULL != ch->owner) && 1801 (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client))
1928 (sender_ccn.channel_of_client ==
1929 ch->owner->ccn.channel_of_client) )
1930 { 1802 {
1931 receiver = ch->dest; 1803 receiver = ch->dest;
1932 ack_to_owner = GNUNET_YES; 1804 ack_to_owner = GNUNET_YES;
1933 } 1805 }
1934 else if ( (NULL != ch->dest) && 1806 else if ((NULL != ch->dest) &&
1935 (sender_ccn.channel_of_client == 1807 (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client))
1936 ch->dest->ccn.channel_of_client) )
1937 { 1808 {
1938 receiver = ch->owner; 1809 receiver = ch->owner;
1939 ack_to_owner = GNUNET_NO; 1810 ack_to_owner = GNUNET_NO;
@@ -1945,16 +1816,12 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1945 } 1816 }
1946 GNUNET_assert (NULL != receiver); 1817 GNUNET_assert (NULL != receiver);
1947 ld->ccn = receiver->ccn; 1818 ld->ccn = receiver->ccn;
1948 GNUNET_memcpy (&ld[1], 1819 GNUNET_memcpy (&ld[1], buf, buf_len);
1949 buf,
1950 buf_len);
1951 if (GNUNET_YES == receiver->client_ready) 1820 if (GNUNET_YES == receiver->client_ready)
1952 { 1821 {
1953 ch->pending_messages--; 1822 ch->pending_messages--;
1954 GSC_send_to_client (receiver->c, 1823 GSC_send_to_client (receiver->c, env);
1955 env); 1824 send_ack_to_client (ch, ack_to_owner);
1956 send_ack_to_client (ch,
1957 ack_to_owner);
1958 } 1825 }
1959 else 1826 else
1960 { 1827 {
@@ -1973,19 +1840,17 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1973 /* Everything is correct, send the message. */ 1840 /* Everything is correct, send the message. */
1974 crm = GNUNET_malloc (sizeof (*crm)); 1841 crm = GNUNET_malloc (sizeof (*crm));
1975 crm->ch = ch; 1842 crm->ch = ch;
1976 crm->data_message = GNUNET_malloc (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) 1843 crm->data_message = GNUNET_malloc (
1977 + buf_len); 1844 sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len);
1978 crm->data_message->header.size = htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); 1845 crm->data_message->header.size =
1979 crm->data_message->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA); 1846 htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len);
1847 crm->data_message->header.type =
1848 htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA);
1980 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); 1849 ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1);
1981 crm->data_message->mid = ch->mid_send; 1850 crm->data_message->mid = ch->mid_send;
1982 crm->data_message->ctn = ch->ctn; 1851 crm->data_message->ctn = ch->ctn;
1983 GNUNET_memcpy (&crm->data_message[1], 1852 GNUNET_memcpy (&crm->data_message[1], buf, buf_len);
1984 buf, 1853 GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm);
1985 buf_len);
1986 GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent,
1987 ch->tail_sent,
1988 crm);
1989 LOG (GNUNET_ERROR_TYPE_DEBUG, 1854 LOG (GNUNET_ERROR_TYPE_DEBUG,
1990 "Sending message %u from local client to %s with %u bytes\n", 1855 "Sending message %u from local client to %s with %u bytes\n",
1991 ntohl (crm->data_message->mid.mid), 1856 ntohl (crm->data_message->mid.mid),
@@ -1996,10 +1861,7 @@ GCCH_handle_local_data (struct CadetChannel *ch,
1996 GNUNET_SCHEDULER_cancel (ch->retry_data_task); 1861 GNUNET_SCHEDULER_cancel (ch->retry_data_task);
1997 ch->retry_data_task = NULL; 1862 ch->retry_data_task = NULL;
1998 } 1863 }
1999 crm->qe = GCT_send (ch->t, 1864 crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm);
2000 &crm->data_message->header,
2001 &data_sent_cb,
2002 crm);
2003 GNUNET_assert (NULL == ch->retry_data_task); 1865 GNUNET_assert (NULL == ch->retry_data_task);
2004 return GNUNET_OK; 1866 return GNUNET_OK;
2005} 1867}
@@ -2019,11 +1881,11 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2019 struct CadetChannelClient *ccc; 1881 struct CadetChannelClient *ccc;
2020 struct CadetOutOfOrderMessage *com; 1882 struct CadetOutOfOrderMessage *com;
2021 1883
2022 if ( (NULL != ch->owner) && 1884 if ((NULL != ch->owner) &&
2023 (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client) ) 1885 (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client))
2024 ccc = ch->owner; 1886 ccc = ch->owner;
2025 else if ( (NULL != ch->dest) && 1887 else if ((NULL != ch->dest) &&
2026 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client) ) 1888 (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client))
2027 ccc = ch->dest; 1889 ccc = ch->dest;
2028 else 1890 else
2029 GNUNET_assert (0); 1891 GNUNET_assert (0);
@@ -2045,35 +1907,28 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2045 int to_owner; 1907 int to_owner;
2046 1908
2047 /* Messages are always in-order, just send */ 1909 /* Messages are always in-order, just send */
2048 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1910 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
2049 ccc->tail_recv,
2050 com);
2051 ccc->num_recv--; 1911 ccc->num_recv--;
2052 GSC_send_to_client (ccc->c, 1912 GSC_send_to_client (ccc->c, com->env);
2053 com->env);
2054 /* Notify sender that we can receive more */ 1913 /* Notify sender that we can receive more */
2055 if ( (NULL != ch->owner) && 1914 if ((NULL != ch->owner) &&
2056 (ccc->ccn.channel_of_client == 1915 (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client))
2057 ch->owner->ccn.channel_of_client) )
2058 { 1916 {
2059 to_owner = GNUNET_NO; 1917 to_owner = GNUNET_NO;
2060 } 1918 }
2061 else 1919 else
2062 { 1920 {
2063 GNUNET_assert ( (NULL != ch->dest) && 1921 GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client ==
2064 (ccc->ccn.channel_of_client == 1922 ch->dest->ccn.channel_of_client));
2065 ch->dest->ccn.channel_of_client) );
2066 to_owner = GNUNET_YES; 1923 to_owner = GNUNET_YES;
2067 } 1924 }
2068 send_ack_to_client (ch, 1925 send_ack_to_client (ch, to_owner);
2069 to_owner);
2070 GNUNET_free (com); 1926 GNUNET_free (com);
2071 return; 1927 return;
2072 } 1928 }
2073 1929
2074 if ( (com->mid.mid != ch->mid_recv.mid) && 1930 if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) &&
2075 (GNUNET_NO == ch->out_of_order) && 1931 (GNUNET_YES == ch->reliable))
2076 (GNUNET_YES == ch->reliable) )
2077 { 1932 {
2078 LOG (GNUNET_ERROR_TYPE_DEBUG, 1933 LOG (GNUNET_ERROR_TYPE_DEBUG,
2079 "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n", 1934 "Got LOCAL_ACK, %s-%X ready to receive more data (but next one is out-of-order %u vs. %u)!\n",
@@ -2092,9 +1947,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2092 GCCH_2s (ch)); 1947 GCCH_2s (ch));
2093 1948
2094 /* all good, pass next message to client */ 1949 /* all good, pass next message to client */
2095 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, 1950 GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com);
2096 ccc->tail_recv,
2097 com);
2098 ccc->num_recv--; 1951 ccc->num_recv--;
2099 /* FIXME: if unreliable, this is not aggressive 1952 /* FIXME: if unreliable, this is not aggressive
2100 enough, as it would be OK to have lost some! */ 1953 enough, as it would be OK to have lost some! */
@@ -2102,21 +1955,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2102 ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); 1955 ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid));
2103 ch->mid_futures >>= 1; /* equivalent to division by 2 */ 1956 ch->mid_futures >>= 1; /* equivalent to division by 2 */
2104 ccc->client_ready = GNUNET_NO; 1957 ccc->client_ready = GNUNET_NO;
2105 GSC_send_to_client (ccc->c, 1958 GSC_send_to_client (ccc->c, com->env);
2106 com->env);
2107 GNUNET_free (com); 1959 GNUNET_free (com);
2108 send_channel_data_ack (ch); 1960 send_channel_data_ack (ch);
2109 if (NULL != ccc->head_recv) 1961 if (NULL != ccc->head_recv)
2110 return; 1962 return;
2111 if (GNUNET_NO == ch->destroy) 1963 if (GNUNET_NO == ch->destroy)
2112 return; 1964 return;
2113 GCT_send_channel_destroy (ch->t, 1965 GCT_send_channel_destroy (ch->t, ch->ctn);
2114 ch->ctn);
2115 channel_destroy (ch); 1966 channel_destroy (ch);
2116} 1967}
2117 1968
2118 1969
2119#define LOG2(level, ...) GNUNET_log_from_nocheck(level,"cadet-chn",__VA_ARGS__) 1970#define LOG2(level, ...) \
1971 GNUNET_log_from_nocheck (level, "cadet-chn", __VA_ARGS__)
2120 1972
2121 1973
2122/** 1974/**
@@ -2126,15 +1978,16 @@ GCCH_handle_local_ack (struct CadetChannel *ch,
2126 * @param level Debug level to use. 1978 * @param level Debug level to use.
2127 */ 1979 */
2128void 1980void
2129GCCH_debug (struct CadetChannel *ch, 1981GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level)
2130 enum GNUNET_ErrorType level)
2131{ 1982{
2132#if !defined(GNUNET_CULL_LOGGING) 1983#if ! defined(GNUNET_CULL_LOGGING)
2133 int do_log; 1984 int do_log;
2134 1985
2135 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK), 1986 do_log = GNUNET_get_log_call_status (level & (~GNUNET_ERROR_TYPE_BULK),
2136 "cadet-chn", 1987 "cadet-chn",
2137 __FILE__, __FUNCTION__, __LINE__); 1988 __FILE__,
1989 __FUNCTION__,
1990 __LINE__);
2138 if (0 == do_log) 1991 if (0 == do_log)
2139 return; 1992 return;
2140 1993
@@ -2143,11 +1996,7 @@ GCCH_debug (struct CadetChannel *ch,
2143 LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); 1996 LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n");
2144 return; 1997 return;
2145 } 1998 }
2146 LOG2 (level, 1999 LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch);
2147 "CHN %s:%X (%p)\n",
2148 GCT_2s (ch->t),
2149 ch->ctn,
2150 ch);
2151 if (NULL != ch->owner) 2000 if (NULL != ch->owner)
2152 { 2001 {
2153 LOG2 (level, 2002 LOG2 (level,
@@ -2173,5 +2022,4 @@ GCCH_debug (struct CadetChannel *ch,
2173} 2022}
2174 2023
2175 2024
2176
2177/* end of gnunet-service-cadet-new_channel.c */ 2025/* end of gnunet-service-cadet-new_channel.c */