diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_channel.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_channel.c | 555 |
1 files changed, 208 insertions, 347 deletions
diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index 847a217c7..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 | ||
@@ -368,7 +368,7 @@ struct CadetChannel | |||
368 | * Is the tunnel out-of-order? | 368 | * Is the tunnel out-of-order? |
369 | */ | 369 | */ |
370 | int out_of_order; | 370 | int out_of_order; |
371 | 371 | ||
372 | /** | 372 | /** |
373 | * Is this channel a loopback channel, where the destination is us again? | 373 | * Is this channel a loopback channel, where the destination is us again? |
374 | */ | 374 | */ |
@@ -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 | */ |
422 | void | 425 | void |
423 | GCCH_hash_port (struct GNUNET_HashCode *h_port, | 426 | GCCH_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 | ||
@@ -598,17 +586,15 @@ send_channel_open (void *cls) | |||
598 | GCCH_2s (ch)); | 586 | GCCH_2s (ch)); |
599 | msgcc.header.size = htons (sizeof (msgcc)); | 587 | msgcc.header.size = htons (sizeof (msgcc)); |
600 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); | 588 | msgcc.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN); |
601 | //TODO This will be removed in a major release, because this will be a protocol breaking change. We shift here to be compatible with GNUNET_CADET_OPTION_RELIABLE that was removed, and to already use the newly introduced 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. |
602 | msgcc.opt = GNUNET_MQ_PREF_RELIABLE >> 10; | 590 | msgcc.opt = 2; |
603 | msgcc.h_port = ch->h_port; | 591 | msgcc.h_port = ch->h_port; |
604 | msgcc.ctn = ch->ctn; | 592 | msgcc.ctn = ch->ctn; |
605 | ch->state = CADET_CHANNEL_OPEN_SENT; | 593 | ch->state = CADET_CHANNEL_OPEN_SENT; |
606 | if (NULL != ch->last_control_qe) | 594 | if (NULL != ch->last_control_qe) |
607 | GCT_send_cancel (ch->last_control_qe); | 595 | GCT_send_cancel (ch->last_control_qe); |
608 | ch->last_control_qe = GCT_send (ch->t, | 596 | ch->last_control_qe = |
609 | &msgcc.header, | 597 | GCT_send (ch->t, &msgcc.header, &channel_open_sent_cb, ch); |
610 | &channel_open_sent_cb, | ||
611 | ch); | ||
612 | GNUNET_assert (NULL == ch->retry_control_task); | 598 | GNUNET_assert (NULL == ch->retry_control_task); |
613 | } | 599 | } |
614 | 600 | ||
@@ -630,9 +616,7 @@ GCCH_tunnel_up (struct CadetChannel *ch) | |||
630 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 616 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
631 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", | 617 | "Tunnel up, sending CHANNEL_OPEN on %s now\n", |
632 | GCCH_2s (ch)); | 618 | GCCH_2s (ch)); |
633 | ch->retry_control_task | 619 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_channel_open, ch); |
634 | = GNUNET_SCHEDULER_add_now (&send_channel_open, | ||
635 | ch); | ||
636 | } | 620 | } |
637 | 621 | ||
638 | 622 | ||
@@ -663,54 +647,45 @@ GCCH_channel_local_new (struct CadetClient *owner, | |||
663 | 647 | ||
664 | ch = GNUNET_new (struct CadetChannel); | 648 | ch = GNUNET_new (struct CadetChannel); |
665 | 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! */ |
666 | ch->nobuffer = GNUNET_NO ; | 650 | ch->nobuffer = GNUNET_NO; |
667 | ch->reliable = GNUNET_YES; | 651 | ch->reliable = GNUNET_YES; |
668 | ch->out_of_order = GNUNET_NO ; | 652 | ch->out_of_order = GNUNET_NO; |
669 | 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! */ | ||
670 | ch->owner = ccco; | 655 | ch->owner = ccco; |
671 | ch->port = *port; | 656 | ch->port = *port; |
672 | GCCH_hash_port (&ch->h_port, | 657 | GCCH_hash_port (&ch->h_port, port, GCP_get_id (destination)); |
673 | port, | 658 | if (0 == GNUNET_memcmp (&my_full_id, GCP_get_id (destination))) |
674 | GCP_get_id (destination)); | ||
675 | if (0 == GNUNET_memcmp (&my_full_id, | ||
676 | GCP_get_id (destination))) | ||
677 | { | 659 | { |
678 | struct OpenPort *op; | 660 | struct OpenPort *op; |
679 | 661 | ||
680 | ch->is_loopback = GNUNET_YES; | 662 | ch->is_loopback = GNUNET_YES; |
681 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, | 663 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, &ch->h_port); |
682 | &ch->h_port); | ||
683 | if (NULL == op) | 664 | if (NULL == op) |
684 | { | 665 | { |
685 | /* port closed, wait for it to possibly open */ | 666 | /* port closed, wait for it to possibly open */ |
686 | ch->state = CADET_CHANNEL_LOOSE; | 667 | ch->state = CADET_CHANNEL_LOOSE; |
687 | (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, | 668 | (void) GNUNET_CONTAINER_multihashmap_put ( |
688 | &ch->h_port, | 669 | loose_channels, |
689 | ch, | 670 | &ch->h_port, |
690 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 671 | ch, |
672 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
691 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 673 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
692 | "Created loose incoming loopback channel to port %s\n", | 674 | "Created loose incoming loopback channel to port %s\n", |
693 | GNUNET_h2s (&ch->port)); | 675 | GNUNET_h2s (&ch->port)); |
694 | } | 676 | } |
695 | else | 677 | else |
696 | { | 678 | { |
697 | GCCH_bind (ch, | 679 | GCCH_bind (ch, op->c, &op->port); |
698 | op->c, | ||
699 | &op->port); | ||
700 | } | 680 | } |
701 | } | 681 | } |
702 | else | 682 | else |
703 | { | 683 | { |
704 | ch->t = GCP_get_tunnel (destination, | 684 | ch->t = GCP_get_tunnel (destination, GNUNET_YES); |
705 | GNUNET_YES); | ||
706 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; | 685 | ch->retry_time = CADET_INITIAL_RETRANSMIT_TIME; |
707 | ch->ctn = GCT_add_channel (ch->t, | 686 | ch->ctn = GCT_add_channel (ch->t, ch); |
708 | ch); | ||
709 | } | 687 | } |
710 | GNUNET_STATISTICS_update (stats, | 688 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
711 | "# channels", | ||
712 | 1, | ||
713 | GNUNET_NO); | ||
714 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 689 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
715 | "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", |
716 | GNUNET_h2s (port), | 691 | GNUNET_h2s (port), |
@@ -767,27 +742,24 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
767 | ch->nobuffer = GNUNET_NO; | 742 | ch->nobuffer = GNUNET_NO; |
768 | ch->reliable = GNUNET_YES; | 743 | ch->reliable = GNUNET_YES; |
769 | ch->out_of_order = GNUNET_NO; | 744 | ch->out_of_order = GNUNET_NO; |
770 | ch->max_pending_messages = (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ | 745 | ch->max_pending_messages = |
771 | GNUNET_STATISTICS_update (stats, | 746 | (ch->nobuffer) ? 1 : 4; /* FIXME: 4!? Do not hardcode! */ |
772 | "# channels", | 747 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
773 | 1, | 748 | |
774 | GNUNET_NO); | 749 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, h_port); |
775 | |||
776 | op = GNUNET_CONTAINER_multihashmap_get (open_ports, | ||
777 | h_port); | ||
778 | if (NULL == op) | 750 | if (NULL == op) |
779 | { | 751 | { |
780 | /* port closed, wait for it to possibly open */ | 752 | /* port closed, wait for it to possibly open */ |
781 | ch->state = CADET_CHANNEL_LOOSE; | 753 | ch->state = CADET_CHANNEL_LOOSE; |
782 | (void) GNUNET_CONTAINER_multihashmap_put (loose_channels, | 754 | (void) GNUNET_CONTAINER_multihashmap_put ( |
783 | &ch->h_port, | 755 | loose_channels, |
784 | ch, | 756 | &ch->h_port, |
785 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 757 | ch, |
758 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
786 | GNUNET_assert (NULL == ch->retry_control_task); | 759 | GNUNET_assert (NULL == ch->retry_control_task); |
787 | ch->retry_control_task | 760 | ch->retry_control_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, |
788 | = GNUNET_SCHEDULER_add_delayed (TIMEOUT_CLOSED_PORT, | 761 | &timeout_closed_cb, |
789 | &timeout_closed_cb, | 762 | ch); |
790 | ch); | ||
791 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 763 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
792 | "Created loose incoming channel to port %s from peer %s\n", | 764 | "Created loose incoming channel to port %s from peer %s\n", |
793 | GNUNET_h2s (&ch->port), | 765 | GNUNET_h2s (&ch->port), |
@@ -795,14 +767,9 @@ GCCH_channel_incoming_new (struct CadetTunnel *t, | |||
795 | } | 767 | } |
796 | else | 768 | else |
797 | { | 769 | { |
798 | GCCH_bind (ch, | 770 | GCCH_bind (ch, op->c, &op->port); |
799 | op->c, | ||
800 | &op->port); | ||
801 | } | 771 | } |
802 | GNUNET_STATISTICS_update (stats, | 772 | GNUNET_STATISTICS_update (stats, "# channels", 1, GNUNET_NO); |
803 | "# channels", | ||
804 | 1, | ||
805 | GNUNET_NO); | ||
806 | return ch; | 773 | return ch; |
807 | } | 774 | } |
808 | 775 | ||
@@ -851,10 +818,7 @@ send_channel_data_ack (struct CadetChannel *ch) | |||
851 | GCCH_2s (ch)); | 818 | GCCH_2s (ch)); |
852 | if (NULL != ch->last_control_qe) | 819 | if (NULL != ch->last_control_qe) |
853 | GCT_send_cancel (ch->last_control_qe); | 820 | GCT_send_cancel (ch->last_control_qe); |
854 | ch->last_control_qe = GCT_send (ch->t, | 821 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
855 | &msg.header, | ||
856 | &send_ack_cb, | ||
857 | ch); | ||
858 | } | 822 | } |
859 | 823 | ||
860 | 824 | ||
@@ -881,10 +845,7 @@ send_open_ack (void *cls) | |||
881 | msg.port = ch->port; | 845 | msg.port = ch->port; |
882 | if (NULL != ch->last_control_qe) | 846 | if (NULL != ch->last_control_qe) |
883 | GCT_send_cancel (ch->last_control_qe); | 847 | GCT_send_cancel (ch->last_control_qe); |
884 | ch->last_control_qe = GCT_send (ch->t, | 848 | ch->last_control_qe = GCT_send (ch->t, &msg.header, &send_ack_cb, ch); |
885 | &msg.header, | ||
886 | &send_ack_cb, | ||
887 | ch); | ||
888 | } | 849 | } |
889 | 850 | ||
890 | 851 | ||
@@ -897,8 +858,9 @@ send_open_ack (void *cls) | |||
897 | * @param cti identifier of the connection that delivered the message | 858 | * @param cti identifier of the connection that delivered the message |
898 | */ | 859 | */ |
899 | void | 860 | void |
900 | GCCH_handle_duplicate_open (struct CadetChannel *ch, | 861 | GCCH_handle_duplicate_open ( |
901 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 862 | struct CadetChannel *ch, |
863 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | ||
902 | { | 864 | { |
903 | if (NULL == ch->dest) | 865 | if (NULL == ch->dest) |
904 | { | 866 | { |
@@ -917,9 +879,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, | |||
917 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 879 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
918 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", | 880 | "Retransmitting CHANNEL_OPEN_ACK on %s\n", |
919 | GCCH_2s (ch)); | 881 | GCCH_2s (ch)); |
920 | ch->retry_control_task | 882 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
921 | = GNUNET_SCHEDULER_add_now (&send_open_ack, | ||
922 | ch); | ||
923 | } | 883 | } |
924 | 884 | ||
925 | 885 | ||
@@ -931,8 +891,7 @@ GCCH_handle_duplicate_open (struct CadetChannel *ch, | |||
931 | * #GNUNET_NO to send to dest | 891 | * #GNUNET_NO to send to dest |
932 | */ | 892 | */ |
933 | static void | 893 | static void |
934 | send_ack_to_client (struct CadetChannel *ch, | 894 | send_ack_to_client (struct CadetChannel *ch, int to_owner) |
935 | int to_owner) | ||
936 | { | 895 | { |
937 | struct GNUNET_MQ_Envelope *env; | 896 | struct GNUNET_MQ_Envelope *env; |
938 | struct GNUNET_CADET_LocalAck *ack; | 897 | struct GNUNET_CADET_LocalAck *ack; |
@@ -946,8 +905,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
946 | GNUNET_assert (GNUNET_YES == ch->destroy); | 905 | GNUNET_assert (GNUNET_YES == ch->destroy); |
947 | return; | 906 | return; |
948 | } | 907 | } |
949 | env = GNUNET_MQ_msg (ack, | 908 | env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); |
950 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK); | ||
951 | ack->ccn = ccc->ccn; | 909 | ack->ccn = ccc->ccn; |
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 910 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
953 | "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", |
@@ -956,8 +914,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
956 | ntohl (ack->ccn.channel_of_client), | 914 | ntohl (ack->ccn.channel_of_client), |
957 | ch->pending_messages, | 915 | ch->pending_messages, |
958 | ch->max_pending_messages); | 916 | ch->max_pending_messages); |
959 | GSC_send_to_client (ccc->c, | 917 | GSC_send_to_client (ccc->c, env); |
960 | env); | ||
961 | } | 918 | } |
962 | 919 | ||
963 | 920 | ||
@@ -973,7 +930,7 @@ send_ack_to_client (struct CadetChannel *ch, | |||
973 | void | 930 | void |
974 | GCCH_bind (struct CadetChannel *ch, | 931 | GCCH_bind (struct CadetChannel *ch, |
975 | struct CadetClient *c, | 932 | struct CadetClient *c, |
976 | const struct GNUNET_HashCode *port) | 933 | const struct GNUNET_HashCode *port) |
977 | { | 934 | { |
978 | uint32_t options; | 935 | uint32_t options; |
979 | struct CadetChannelClient *cccd; | 936 | struct CadetChannelClient *cccd; |
@@ -1000,9 +957,8 @@ GCCH_bind (struct CadetChannel *ch, | |||
1000 | cccd->ccn = GSC_bind (c, | 957 | cccd->ccn = GSC_bind (c, |
1001 | ch, | 958 | ch, |
1002 | (GNUNET_YES == ch->is_loopback) | 959 | (GNUNET_YES == ch->is_loopback) |
1003 | ? GCP_get (&my_full_id, | 960 | ? GCP_get (&my_full_id, GNUNET_YES) |
1004 | GNUNET_YES) | 961 | : GCT_get_destination (ch->t), |
1005 | : GCT_get_destination (ch->t), | ||
1006 | port, | 962 | port, |
1007 | options); | 963 | options); |
1008 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 964 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
@@ -1011,24 +967,19 @@ GCCH_bind (struct CadetChannel *ch, | |||
1011 | if (GNUNET_YES == ch->is_loopback) | 967 | if (GNUNET_YES == ch->is_loopback) |
1012 | { | 968 | { |
1013 | ch->state = CADET_CHANNEL_OPEN_SENT; | 969 | ch->state = CADET_CHANNEL_OPEN_SENT; |
1014 | GCCH_handle_channel_open_ack (ch, | 970 | GCCH_handle_channel_open_ack (ch, NULL, port); |
1015 | NULL, | ||
1016 | port); | ||
1017 | } | 971 | } |
1018 | else | 972 | else |
1019 | { | 973 | { |
1020 | /* notify other peer that we accepted the connection */ | 974 | /* notify other peer that we accepted the connection */ |
1021 | ch->state = CADET_CHANNEL_READY; | 975 | ch->state = CADET_CHANNEL_READY; |
1022 | ch->retry_control_task | 976 | ch->retry_control_task = GNUNET_SCHEDULER_add_now (&send_open_ack, ch); |
1023 | = GNUNET_SCHEDULER_add_now (&send_open_ack, | ||
1024 | ch); | ||
1025 | } | 977 | } |
1026 | /* give client it's initial supply of ACKs */ | 978 | /* give client it's initial supply of ACKs */ |
1027 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < | 979 | GNUNET_assert (ntohl (cccd->ccn.channel_of_client) < |
1028 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); | 980 | GNUNET_CADET_LOCAL_CHANNEL_ID_CLI); |
1029 | for (unsigned int i=0;i<ch->max_pending_messages;i++) | 981 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
1030 | send_ack_to_client (ch, | 982 | send_ack_to_client (ch, GNUNET_NO); |
1031 | GNUNET_NO); | ||
1032 | } | 983 | } |
1033 | 984 | ||
1034 | 985 | ||
@@ -1048,9 +999,7 @@ signal_remote_destroy_cb (void *cls) | |||
1048 | /* Find which end is left... */ | 999 | /* Find which end is left... */ |
1049 | ch->retry_control_task = NULL; | 1000 | ch->retry_control_task = NULL; |
1050 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1001 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1051 | GSC_handle_remote_channel_destroy (ccc->c, | 1002 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
1052 | ccc->ccn, | ||
1053 | ch); | ||
1054 | channel_destroy (ch); | 1003 | channel_destroy (ch); |
1055 | } | 1004 | } |
1056 | 1005 | ||
@@ -1073,16 +1022,14 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1073 | GSC_2s (c), | 1022 | GSC_2s (c), |
1074 | GCCH_2s (ch)); | 1023 | GCCH_2s (ch)); |
1075 | GNUNET_assert (NULL != c); | 1024 | GNUNET_assert (NULL != c); |
1076 | if ( (NULL != ch->owner) && | 1025 | if ((NULL != ch->owner) && (c == ch->owner->c) && |
1077 | (c == ch->owner->c) && | 1026 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1078 | (ccn.channel_of_client == ch->owner->ccn.channel_of_client) ) | ||
1079 | { | 1027 | { |
1080 | free_channel_client (ch->owner); | 1028 | free_channel_client (ch->owner); |
1081 | ch->owner = NULL; | 1029 | ch->owner = NULL; |
1082 | } | 1030 | } |
1083 | else if ( (NULL != ch->dest) && | 1031 | else if ((NULL != ch->dest) && (c == ch->dest->c) && |
1084 | (c == ch->dest->c) && | 1032 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1085 | (ccn.channel_of_client == ch->dest->ccn.channel_of_client) ) | ||
1086 | { | 1033 | { |
1087 | free_channel_client (ch->dest); | 1034 | free_channel_client (ch->dest); |
1088 | ch->dest = NULL; | 1035 | ch->dest = NULL; |
@@ -1099,24 +1046,20 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1099 | channel_destroy (ch); | 1046 | channel_destroy (ch); |
1100 | return; | 1047 | return; |
1101 | } | 1048 | } |
1102 | if ( (NULL != ch->head_sent) && | 1049 | if ((NULL != ch->head_sent) && ((NULL != ch->owner) || (NULL != ch->dest))) |
1103 | ( (NULL != ch->owner) || | ||
1104 | (NULL != ch->dest) ) ) | ||
1105 | { | 1050 | { |
1106 | /* Wait for other end to destroy us as well, | 1051 | /* Wait for other end to destroy us as well, |
1107 | and otherwise allow send queue to be transmitted first */ | 1052 | and otherwise allow send queue to be transmitted first */ |
1108 | ch->destroy = GNUNET_YES; | 1053 | ch->destroy = GNUNET_YES; |
1109 | return; | 1054 | return; |
1110 | } | 1055 | } |
1111 | if ( (GNUNET_YES == ch->is_loopback) && | 1056 | if ((GNUNET_YES == ch->is_loopback) && |
1112 | ( (NULL != ch->owner) || | 1057 | ((NULL != ch->owner) || (NULL != ch->dest))) |
1113 | (NULL != ch->dest) ) ) | ||
1114 | { | 1058 | { |
1115 | if (NULL != ch->retry_control_task) | 1059 | if (NULL != ch->retry_control_task) |
1116 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); | 1060 | GNUNET_SCHEDULER_cancel (ch->retry_control_task); |
1117 | ch->retry_control_task | 1061 | ch->retry_control_task = |
1118 | = GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, | 1062 | GNUNET_SCHEDULER_add_now (&signal_remote_destroy_cb, ch); |
1119 | ch); | ||
1120 | return; | 1063 | return; |
1121 | } | 1064 | } |
1122 | if (GNUNET_NO == ch->is_loopback) | 1065 | if (GNUNET_NO == ch->is_loopback) |
@@ -1131,8 +1074,7 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1131 | case CADET_CHANNEL_LOOSE: | 1074 | case CADET_CHANNEL_LOOSE: |
1132 | break; | 1075 | break; |
1133 | default: | 1076 | default: |
1134 | GCT_send_channel_destroy (ch->t, | 1077 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1135 | ch->ctn); | ||
1136 | } | 1078 | } |
1137 | } | 1079 | } |
1138 | /* Nothing left to do, just finish destruction */ | 1080 | /* Nothing left to do, just finish destruction */ |
@@ -1150,9 +1092,10 @@ GCCH_channel_local_destroy (struct CadetChannel *ch, | |||
1150 | * @param port port number (needed to verify receiver knows the port) | 1092 | * @param port port number (needed to verify receiver knows the port) |
1151 | */ | 1093 | */ |
1152 | void | 1094 | void |
1153 | GCCH_handle_channel_open_ack (struct CadetChannel *ch, | 1095 | GCCH_handle_channel_open_ack ( |
1154 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1096 | struct CadetChannel *ch, |
1155 | const struct GNUNET_HashCode *port) | 1097 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1098 | const struct GNUNET_HashCode *port) | ||
1156 | { | 1099 | { |
1157 | switch (ch->state) | 1100 | switch (ch->state) |
1158 | { | 1101 | { |
@@ -1171,8 +1114,7 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, | |||
1171 | GNUNET_break_op (0); | 1114 | GNUNET_break_op (0); |
1172 | return; | 1115 | return; |
1173 | } | 1116 | } |
1174 | if (0 != GNUNET_memcmp (&ch->port, | 1117 | if (0 != GNUNET_memcmp (&ch->port, port)) |
1175 | port)) | ||
1176 | { | 1118 | { |
1177 | /* Other peer failed to provide the right port, | 1119 | /* Other peer failed to provide the right port, |
1178 | refuse connection. */ | 1120 | refuse connection. */ |
@@ -1190,19 +1132,15 @@ GCCH_handle_channel_open_ack (struct CadetChannel *ch, | |||
1190 | ch->state = CADET_CHANNEL_READY; | 1132 | ch->state = CADET_CHANNEL_READY; |
1191 | /* 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 |
1192 | to be buffered! */ | 1134 | to be buffered! */ |
1193 | for (unsigned int i=0;i<ch->max_pending_messages;i++) | 1135 | for (unsigned int i = 0; i < ch->max_pending_messages; i++) |
1194 | send_ack_to_client (ch, | 1136 | send_ack_to_client (ch, GNUNET_YES); |
1195 | GNUNET_YES); | ||
1196 | break; | 1137 | break; |
1197 | case CADET_CHANNEL_READY: | 1138 | case CADET_CHANNEL_READY: |
1198 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ | 1139 | /* duplicate ACK, maybe we retried the CREATE. Ignore. */ |
1199 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1140 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1200 | "Received duplicate channel OPEN_ACK for %s\n", | 1141 | "Received duplicate channel OPEN_ACK for %s\n", |
1201 | GCCH_2s (ch)); | 1142 | GCCH_2s (ch)); |
1202 | GNUNET_STATISTICS_update (stats, | 1143 | GNUNET_STATISTICS_update (stats, "# duplicate CREATE_ACKs", 1, GNUNET_NO); |
1203 | "# duplicate CREATE_ACKs", | ||
1204 | 1, | ||
1205 | GNUNET_NO); | ||
1206 | break; | 1144 | break; |
1207 | } | 1145 | } |
1208 | } | 1146 | } |
@@ -1251,9 +1189,10 @@ is_before (void *cls, | |||
1251 | * @param msg message that was received | 1189 | * @param msg message that was received |
1252 | */ | 1190 | */ |
1253 | void | 1191 | void |
1254 | GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | 1192 | GCCH_handle_channel_plaintext_data ( |
1255 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1193 | struct CadetChannel *ch, |
1256 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | 1194 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1195 | const struct GNUNET_CADET_ChannelAppDataMessage *msg) | ||
1257 | { | 1196 | { |
1258 | struct GNUNET_MQ_Envelope *env; | 1197 | struct GNUNET_MQ_Envelope *env; |
1259 | struct GNUNET_CADET_LocalData *ld; | 1198 | struct GNUNET_CADET_LocalData *ld; |
@@ -1267,8 +1206,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1267 | uint32_t delta; | 1206 | uint32_t delta; |
1268 | 1207 | ||
1269 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1208 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1270 | if ( (NULL == ch->owner) && | 1209 | if ((NULL == ch->owner) && (NULL == ch->dest)) |
1271 | (NULL == ch->dest) ) | ||
1272 | { | 1210 | { |
1273 | /* 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 |
1274 | 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, |
@@ -1278,8 +1216,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1278 | GCCH_2s (ch)); | 1216 | GCCH_2s (ch)); |
1279 | /* send back DESTROY notification to stop further retransmissions! */ | 1217 | /* send back DESTROY notification to stop further retransmissions! */ |
1280 | if (GNUNET_YES == ch->destroy) | 1218 | if (GNUNET_YES == ch->destroy) |
1281 | GCT_send_channel_destroy (ch->t, | 1219 | GCT_send_channel_destroy (ch->t, ch->ctn); |
1282 | ch->ctn); | ||
1283 | return; | 1220 | return; |
1284 | } | 1221 | } |
1285 | payload_size = ntohs (msg->header.size) - sizeof (*msg); | 1222 | payload_size = ntohs (msg->header.size) - sizeof (*msg); |
@@ -1287,9 +1224,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1287 | payload_size, | 1224 | payload_size, |
1288 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1225 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1289 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; | 1226 | ld->ccn = (NULL == ch->dest) ? ch->owner->ccn : ch->dest->ccn; |
1290 | GNUNET_memcpy (&ld[1], | 1227 | GNUNET_memcpy (&ld[1], &msg[1], payload_size); |
1291 | &msg[1], | ||
1292 | payload_size); | ||
1293 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1228 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1294 | if (GNUNET_YES == ccc->client_ready) | 1229 | if (GNUNET_YES == ccc->client_ready) |
1295 | { | 1230 | { |
@@ -1299,13 +1234,12 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1299 | * - The channel is reliable and MID matches next expected MID | 1234 | * - The channel is reliable and MID matches next expected MID |
1300 | * - The channel is unreliable and MID is before lowest seen MID | 1235 | * - The channel is unreliable and MID is before lowest seen MID |
1301 | */ | 1236 | */ |
1302 | if ( (GNUNET_YES == ch->out_of_order) || | 1237 | if ((GNUNET_YES == ch->out_of_order) || |
1303 | ((msg->mid.mid == ch->mid_recv.mid) && | 1238 | ((msg->mid.mid == ch->mid_recv.mid) && (GNUNET_YES == ch->reliable)) || |
1304 | (GNUNET_YES == ch->reliable)) || | 1239 | ((GNUNET_NO == ch->reliable) && |
1305 | ((GNUNET_NO == ch->reliable) && | 1240 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && |
1306 | (ntohl (msg->mid.mid) >= ntohl (ch->mid_recv.mid)) && | 1241 | ((NULL == ccc->head_recv) || |
1307 | ((NULL == ccc->head_recv) || | 1242 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid))))) |
1308 | (ntohl (msg->mid.mid) < ntohl (ccc->head_recv->mid.mid)))) ) | ||
1309 | { | 1243 | { |
1310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1244 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "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", |
@@ -1314,24 +1248,22 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1314 | GCCH_2s (ch), | 1248 | GCCH_2s (ch), |
1315 | GSC_2s (ccc->c)); | 1249 | GSC_2s (ccc->c)); |
1316 | ccc->client_ready = GNUNET_NO; | 1250 | ccc->client_ready = GNUNET_NO; |
1317 | GSC_send_to_client (ccc->c, | 1251 | GSC_send_to_client (ccc->c, env); |
1318 | env); | ||
1319 | if (GNUNET_NO == ch->out_of_order) | 1252 | if (GNUNET_NO == ch->out_of_order) |
1320 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1253 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1321 | else | 1254 | else |
1322 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); | 1255 | ch->mid_recv.mid = htonl (1 + ntohl (ch->mid_recv.mid)); |
1323 | ch->mid_futures >>= 1; | 1256 | ch->mid_futures >>= 1; |
1324 | if ( (GNUNET_YES == ch->out_of_order) && | 1257 | if ((GNUNET_YES == ch->out_of_order) && (GNUNET_NO == ch->reliable)) |
1325 | (GNUNET_NO == ch->reliable) ) | ||
1326 | { | 1258 | { |
1327 | /* possibly shift by more if we skipped messages */ | 1259 | /* possibly shift by more if we skipped messages */ |
1328 | 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); |
1329 | 1261 | ||
1330 | if (delta > 63) | 1262 | if (delta > 63) |
1331 | ch->mid_futures = 0; | 1263 | ch->mid_futures = 0; |
1332 | else | 1264 | else |
1333 | ch->mid_futures >>= delta; | 1265 | ch->mid_futures >>= delta; |
1334 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); | 1266 | ch->mid_recv.mid = htonl (1 + ntohl (msg->mid.mid)); |
1335 | } | 1267 | } |
1336 | send_channel_data_ack (ch); | 1268 | send_channel_data_ack (ch); |
1337 | return; | 1269 | return; |
@@ -1344,8 +1276,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1344 | mid_min = ntohl (ch->mid_recv.mid); | 1276 | mid_min = ntohl (ch->mid_recv.mid); |
1345 | mid_max = mid_min + ch->max_pending_messages; | 1277 | mid_max = mid_min + ch->max_pending_messages; |
1346 | mid_msg = ntohl (msg->mid.mid); | 1278 | mid_msg = ntohl (msg->mid.mid); |
1347 | if ( ( (uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || | 1279 | if (((uint32_t) (mid_msg - mid_min) > ch->max_pending_messages) || |
1348 | ( (uint32_t) (mid_max - mid_msg) > ch->max_pending_messages) ) | 1280 | ((uint32_t) (mid_max - mid_msg) > ch->max_pending_messages)) |
1349 | { | 1281 | { |
1350 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1282 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1351 | "%s at %u drops ancient or far-future message %u\n", | 1283 | "%s at %u drops ancient or far-future message %u\n", |
@@ -1373,10 +1305,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1373 | (unsigned int) payload_size, | 1305 | (unsigned int) payload_size, |
1374 | GCCH_2s (ch), | 1306 | GCCH_2s (ch), |
1375 | ntohl (msg->mid.mid)); | 1307 | ntohl (msg->mid.mid)); |
1376 | GNUNET_STATISTICS_update (stats, | 1308 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1377 | "# duplicate DATA", | ||
1378 | 1, | ||
1379 | GNUNET_NO); | ||
1380 | GNUNET_MQ_discard (env); | 1309 | GNUNET_MQ_discard (env); |
1381 | send_channel_data_ack (ch); | 1310 | send_channel_data_ack (ch); |
1382 | return; | 1311 | return; |
@@ -1398,8 +1327,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1398 | * We always send if possible in this case. | 1327 | * We always send if possible in this case. |
1399 | * It is guaranteed that the queued MID < received MID | 1328 | * It is guaranteed that the queued MID < received MID |
1400 | **/ | 1329 | **/ |
1401 | if ((NULL != ccc->head_recv) && | 1330 | if ((NULL != ccc->head_recv) && (GNUNET_YES == ccc->client_ready)) |
1402 | (GNUNET_YES == ccc->client_ready)) | ||
1403 | { | 1331 | { |
1404 | next_msg = ccc->head_recv; | 1332 | next_msg = ccc->head_recv; |
1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1333 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1408,14 +1336,11 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1408 | GCCH_2s (ch), | 1336 | GCCH_2s (ch), |
1409 | GSC_2s (ccc->c)); | 1337 | GSC_2s (ccc->c)); |
1410 | ccc->client_ready = GNUNET_NO; | 1338 | ccc->client_ready = GNUNET_NO; |
1411 | GSC_send_to_client (ccc->c, | 1339 | GSC_send_to_client (ccc->c, next_msg->env); |
1412 | next_msg->env); | ||
1413 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); | 1340 | ch->mid_recv.mid = htonl (1 + ntohl (next_msg->mid.mid)); |
1414 | ch->mid_futures >>= 1; | 1341 | ch->mid_futures >>= 1; |
1415 | send_channel_data_ack (ch); | 1342 | send_channel_data_ack (ch); |
1416 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1343 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, next_msg); |
1417 | ccc->tail_recv, | ||
1418 | next_msg); | ||
1419 | ccc->num_recv--; | 1344 | ccc->num_recv--; |
1420 | /* Do not process duplicate MID */ | 1345 | /* Do not process duplicate MID */ |
1421 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ | 1346 | if (msg->mid.mid == next_msg->mid.mid) /* Duplicate */ |
@@ -1460,9 +1385,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1460 | GNUNET_NO); | 1385 | GNUNET_NO); |
1461 | drop = ccc->head_recv; | 1386 | drop = ccc->head_recv; |
1462 | GNUNET_assert (NULL != drop); | 1387 | GNUNET_assert (NULL != drop); |
1463 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1388 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, drop); |
1464 | ccc->tail_recv, | ||
1465 | drop); | ||
1466 | ccc->num_recv--; | 1389 | ccc->num_recv--; |
1467 | GNUNET_MQ_discard (drop->env); | 1390 | GNUNET_MQ_discard (drop->env); |
1468 | GNUNET_free (drop); | 1391 | GNUNET_free (drop); |
@@ -1493,13 +1416,8 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1493 | (unsigned int) payload_size, | 1416 | (unsigned int) payload_size, |
1494 | GCCH_2s (ch), | 1417 | GCCH_2s (ch), |
1495 | ntohl (msg->mid.mid)); | 1418 | ntohl (msg->mid.mid)); |
1496 | GNUNET_STATISTICS_update (stats, | 1419 | GNUNET_STATISTICS_update (stats, "# duplicate DATA", 1, GNUNET_NO); |
1497 | "# duplicate DATA", | 1420 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
1498 | 1, | ||
1499 | GNUNET_NO); | ||
1500 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | ||
1501 | ccc->tail_recv, | ||
1502 | com); | ||
1503 | ccc->num_recv--; | 1421 | ccc->num_recv--; |
1504 | GNUNET_MQ_discard (com->env); | 1422 | GNUNET_MQ_discard (com->env); |
1505 | GNUNET_free (com); | 1423 | GNUNET_free (com); |
@@ -1508,9 +1426,7 @@ GCCH_handle_channel_plaintext_data (struct CadetChannel *ch, | |||
1508 | } | 1426 | } |
1509 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1427 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1510 | "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", |
1511 | (GNUNET_YES == ccc->client_ready) | 1429 | (GNUNET_YES == ccc->client_ready) ? "out-of-order" : "client-not-ready", |
1512 | ? "out-of-order" | ||
1513 | : "client-not-ready", | ||
1514 | (unsigned int) payload_size, | 1430 | (unsigned int) payload_size, |
1515 | GCCH_2s (ch), | 1431 | GCCH_2s (ch), |
1516 | ntohl (ccc->ccn.channel_of_client), | 1432 | ntohl (ccc->ccn.channel_of_client), |
@@ -1558,10 +1474,7 @@ retry_transmission (void *cls) | |||
1558 | "Retrying transmission on %s of message %u\n", | 1474 | "Retrying transmission on %s of message %u\n", |
1559 | GCCH_2s (ch), | 1475 | GCCH_2s (ch), |
1560 | (unsigned int) ntohl (crm->data_message->mid.mid)); | 1476 | (unsigned int) ntohl (crm->data_message->mid.mid)); |
1561 | crm->qe = GCT_send (ch->t, | 1477 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1562 | &crm->data_message->header, | ||
1563 | &data_sent_cb, | ||
1564 | crm); | ||
1565 | GNUNET_assert (NULL == ch->retry_data_task); | 1478 | GNUNET_assert (NULL == ch->retry_data_task); |
1566 | } | 1479 | } |
1567 | 1480 | ||
@@ -1579,9 +1492,7 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1579 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1492 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1580 | struct CadetReliableMessage *crm) | 1493 | struct CadetReliableMessage *crm) |
1581 | { | 1494 | { |
1582 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, | 1495 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1583 | ch->tail_sent, | ||
1584 | crm); | ||
1585 | ch->pending_messages--; | 1496 | ch->pending_messages--; |
1586 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); | 1497 | GNUNET_assert (ch->pending_messages < ch->max_pending_messages); |
1587 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1594,23 +1505,19 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1594 | GCT_send_cancel (crm->qe); | 1505 | GCT_send_cancel (crm->qe); |
1595 | crm->qe = NULL; | 1506 | crm->qe = NULL; |
1596 | } | 1507 | } |
1597 | if ( (1 == crm->num_transmissions) && | 1508 | if ((1 == crm->num_transmissions) && (NULL != cti)) |
1598 | (NULL != cti) ) | ||
1599 | { | 1509 | { |
1600 | GCC_ack_observed (cti); | 1510 | GCC_ack_observed (cti); |
1601 | if (0 == GNUNET_memcmp (cti, | 1511 | if (0 == GNUNET_memcmp (cti, &crm->connection_taken)) |
1602 | &crm->connection_taken)) | ||
1603 | { | 1512 | { |
1604 | GCC_latency_observed (cti, | 1513 | GCC_latency_observed (cti, |
1605 | GNUNET_TIME_absolute_get_duration (crm->first_transmission_time)); | 1514 | GNUNET_TIME_absolute_get_duration ( |
1515 | crm->first_transmission_time)); | ||
1606 | } | 1516 | } |
1607 | } | 1517 | } |
1608 | GNUNET_free (crm->data_message); | 1518 | GNUNET_free (crm->data_message); |
1609 | GNUNET_free (crm); | 1519 | GNUNET_free (crm); |
1610 | send_ack_to_client (ch, | 1520 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1611 | (NULL == ch->owner) | ||
1612 | ? GNUNET_NO | ||
1613 | : GNUNET_YES); | ||
1614 | } | 1521 | } |
1615 | 1522 | ||
1616 | 1523 | ||
@@ -1623,9 +1530,10 @@ handle_matching_ack (struct CadetChannel *ch, | |||
1623 | * @param ack details about what was received | 1530 | * @param ack details about what was received |
1624 | */ | 1531 | */ |
1625 | void | 1532 | void |
1626 | GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | 1533 | GCCH_handle_channel_plaintext_data_ack ( |
1627 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, | 1534 | struct CadetChannel *ch, |
1628 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | 1535 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti, |
1536 | const struct GNUNET_CADET_ChannelDataAckMessage *ack) | ||
1629 | { | 1537 | { |
1630 | struct CadetReliableMessage *crm; | 1538 | struct CadetReliableMessage *crm; |
1631 | struct CadetReliableMessage *crmn; | 1539 | struct CadetReliableMessage *crmn; |
@@ -1647,9 +1555,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1647 | mid_base = ntohl (ack->mid.mid); | 1555 | mid_base = ntohl (ack->mid.mid); |
1648 | mid_mask = GNUNET_htonll (ack->futures); | 1556 | mid_mask = GNUNET_htonll (ack->futures); |
1649 | found = GNUNET_NO; | 1557 | found = GNUNET_NO; |
1650 | for (crm = ch->head_sent; | 1558 | for (crm = ch->head_sent; NULL != crm; crm = crmn) |
1651 | NULL != crm; | ||
1652 | crm = crmn) | ||
1653 | { | 1559 | { |
1654 | crmn = crm->next; | 1560 | crmn = crm->next; |
1655 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); | 1561 | delta = (unsigned int) (ntohl (crm->data_message->mid.mid) - mid_base); |
@@ -1661,9 +1567,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1661 | (unsigned int) mid_base, | 1567 | (unsigned int) mid_base, |
1662 | ntohl (crm->data_message->mid.mid), | 1568 | ntohl (crm->data_message->mid.mid), |
1663 | GCCH_2s (ch)); | 1569 | GCCH_2s (ch)); |
1664 | handle_matching_ack (ch, | 1570 | handle_matching_ack (ch, cti, crm); |
1665 | cti, | ||
1666 | crm); | ||
1667 | found = GNUNET_YES; | 1571 | found = GNUNET_YES; |
1668 | continue; | 1572 | continue; |
1669 | } | 1573 | } |
@@ -1681,9 +1585,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1681 | "Got DATA_ACK with mask for %u on %s\n", | 1585 | "Got DATA_ACK with mask for %u on %s\n", |
1682 | ntohl (crm->data_message->mid.mid), | 1586 | ntohl (crm->data_message->mid.mid), |
1683 | GCCH_2s (ch)); | 1587 | GCCH_2s (ch)); |
1684 | handle_matching_ack (ch, | 1588 | handle_matching_ack (ch, cti, crm); |
1685 | cti, | ||
1686 | crm); | ||
1687 | found = GNUNET_YES; | 1589 | found = GNUNET_YES; |
1688 | } | 1590 | } |
1689 | } | 1591 | } |
@@ -1694,10 +1596,7 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1694 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1596 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1695 | "Duplicate DATA_ACK on %s, ignoring\n", | 1597 | "Duplicate DATA_ACK on %s, ignoring\n", |
1696 | GCCH_2s (ch)); | 1598 | GCCH_2s (ch)); |
1697 | GNUNET_STATISTICS_update (stats, | 1599 | GNUNET_STATISTICS_update (stats, "# duplicate DATA_ACKs", 1, GNUNET_NO); |
1698 | "# duplicate DATA_ACKs", | ||
1699 | 1, | ||
1700 | GNUNET_NO); | ||
1701 | return; | 1600 | return; |
1702 | } | 1601 | } |
1703 | if (NULL != ch->retry_data_task) | 1602 | if (NULL != ch->retry_data_task) |
@@ -1705,12 +1604,10 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1705 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1604 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1706 | ch->retry_data_task = NULL; | 1605 | ch->retry_data_task = NULL; |
1707 | } | 1606 | } |
1708 | if ( (NULL != ch->head_sent) && | 1607 | if ((NULL != ch->head_sent) && (NULL == ch->head_sent->qe)) |
1709 | (NULL == ch->head_sent->qe) ) | 1608 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1710 | ch->retry_data_task | 1609 | &retry_transmission, |
1711 | = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1610 | ch); |
1712 | &retry_transmission, | ||
1713 | ch); | ||
1714 | } | 1611 | } |
1715 | 1612 | ||
1716 | 1613 | ||
@@ -1724,8 +1621,9 @@ GCCH_handle_channel_plaintext_data_ack (struct CadetChannel *ch, | |||
1724 | * NULL if we are simulating receiving a destroy due to shutdown | 1621 | * NULL if we are simulating receiving a destroy due to shutdown |
1725 | */ | 1622 | */ |
1726 | void | 1623 | void |
1727 | GCCH_handle_remote_destroy (struct CadetChannel *ch, | 1624 | GCCH_handle_remote_destroy ( |
1728 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | 1625 | struct CadetChannel *ch, |
1626 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cti) | ||
1729 | { | 1627 | { |
1730 | struct CadetChannelClient *ccc; | 1628 | struct CadetChannelClient *ccc; |
1731 | 1629 | ||
@@ -1740,8 +1638,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, | |||
1740 | return; | 1638 | return; |
1741 | } | 1639 | } |
1742 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; | 1640 | ccc = (NULL != ch->owner) ? ch->owner : ch->dest; |
1743 | if ( (NULL != ccc) && | 1641 | if ((NULL != ccc) && (NULL != ccc->head_recv)) |
1744 | (NULL != ccc->head_recv) ) | ||
1745 | { | 1642 | { |
1746 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1643 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1747 | "Lost end of transmission due to remote shutdown on %s\n", | 1644 | "Lost end of transmission due to remote shutdown on %s\n", |
@@ -1750,9 +1647,7 @@ GCCH_handle_remote_destroy (struct CadetChannel *ch, | |||
1750 | } | 1647 | } |
1751 | ch->destroy = GNUNET_YES; | 1648 | ch->destroy = GNUNET_YES; |
1752 | if (NULL != ccc) | 1649 | if (NULL != ccc) |
1753 | GSC_handle_remote_channel_destroy (ccc->c, | 1650 | GSC_handle_remote_channel_destroy (ccc->c, ccc->ccn, ch); |
1754 | ccc->ccn, | ||
1755 | ch); | ||
1756 | channel_destroy (ch); | 1651 | channel_destroy (ch); |
1757 | } | 1652 | } |
1758 | 1653 | ||
@@ -1770,8 +1665,7 @@ cmp_crm_by_next_retry (void *cls, | |||
1770 | struct CadetReliableMessage *crm1, | 1665 | struct CadetReliableMessage *crm1, |
1771 | struct CadetReliableMessage *crm2) | 1666 | struct CadetReliableMessage *crm2) |
1772 | { | 1667 | { |
1773 | if (crm1->next_retry.abs_value_us < | 1668 | if (crm1->next_retry.abs_value_us < crm2->next_retry.abs_value_us) |
1774 | crm2->next_retry.abs_value_us) | ||
1775 | return GNUNET_YES; | 1669 | return GNUNET_YES; |
1776 | return GNUNET_NO; | 1670 | return GNUNET_NO; |
1777 | } | 1671 | } |
@@ -1797,18 +1691,13 @@ data_sent_cb (void *cls, | |||
1797 | GNUNET_assert (GNUNET_NO == ch->is_loopback); | 1691 | GNUNET_assert (GNUNET_NO == ch->is_loopback); |
1798 | GNUNET_assert (NULL != crm->qe); | 1692 | GNUNET_assert (NULL != crm->qe); |
1799 | crm->qe = NULL; | 1693 | crm->qe = NULL; |
1800 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, | 1694 | GNUNET_CONTAINER_DLL_remove (ch->head_sent, ch->tail_sent, crm); |
1801 | ch->tail_sent, | ||
1802 | crm); | ||
1803 | if (GNUNET_NO == ch->reliable) | 1695 | if (GNUNET_NO == ch->reliable) |
1804 | { | 1696 | { |
1805 | GNUNET_free (crm->data_message); | 1697 | GNUNET_free (crm->data_message); |
1806 | GNUNET_free (crm); | 1698 | GNUNET_free (crm); |
1807 | ch->pending_messages--; | 1699 | ch->pending_messages--; |
1808 | send_ack_to_client (ch, | 1700 | send_ack_to_client (ch, (NULL == ch->owner) ? GNUNET_NO : GNUNET_YES); |
1809 | (NULL == ch->owner) | ||
1810 | ? GNUNET_NO | ||
1811 | : GNUNET_YES); | ||
1812 | return; | 1701 | return; |
1813 | } | 1702 | } |
1814 | if (NULL == cid) | 1703 | if (NULL == cid) |
@@ -1828,8 +1717,7 @@ data_sent_cb (void *cls, | |||
1828 | GCC_ack_expected (cid); | 1717 | GCC_ack_expected (cid); |
1829 | } | 1718 | } |
1830 | } | 1719 | } |
1831 | if ( (0 == crm->retry_delay.rel_value_us) && | 1720 | if ((0 == crm->retry_delay.rel_value_us) && (NULL != cid)) |
1832 | (NULL != cid) ) | ||
1833 | { | 1721 | { |
1834 | struct CadetConnection *cc = GCC_lookup (cid); | 1722 | struct CadetConnection *cc = GCC_lookup (cid); |
1835 | 1723 | ||
@@ -1839,8 +1727,7 @@ data_sent_cb (void *cls, | |||
1839 | crm->retry_delay = ch->retry_time; | 1727 | crm->retry_delay = ch->retry_time; |
1840 | } | 1728 | } |
1841 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); | 1729 | crm->retry_delay = GNUNET_TIME_STD_BACKOFF (crm->retry_delay); |
1842 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, | 1730 | crm->retry_delay = GNUNET_TIME_relative_max (crm->retry_delay, MIN_RTT_DELAY); |
1843 | MIN_RTT_DELAY); | ||
1844 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); | 1731 | crm->next_retry = GNUNET_TIME_relative_to_absolute (crm->retry_delay); |
1845 | 1732 | ||
1846 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, | 1733 | GNUNET_CONTAINER_DLL_insert_sorted (struct CadetReliableMessage, |
@@ -1853,16 +1740,16 @@ data_sent_cb (void *cls, | |||
1853 | "Message %u sent, next transmission on %s in %s\n", | 1740 | "Message %u sent, next transmission on %s in %s\n", |
1854 | (unsigned int) ntohl (crm->data_message->mid.mid), | 1741 | (unsigned int) ntohl (crm->data_message->mid.mid), |
1855 | GCCH_2s (ch), | 1742 | GCCH_2s (ch), |
1856 | 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), | ||
1857 | GNUNET_YES)); | 1745 | GNUNET_YES)); |
1858 | if (NULL == ch->head_sent->qe) | 1746 | if (NULL == ch->head_sent->qe) |
1859 | { | 1747 | { |
1860 | if (NULL != ch->retry_data_task) | 1748 | if (NULL != ch->retry_data_task) |
1861 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1749 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1862 | ch->retry_data_task | 1750 | ch->retry_data_task = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, |
1863 | = GNUNET_SCHEDULER_add_at (ch->head_sent->next_retry, | 1751 | &retry_transmission, |
1864 | &retry_transmission, | 1752 | ch); |
1865 | ch); | ||
1866 | } | 1753 | } |
1867 | } | 1754 | } |
1868 | 1755 | ||
@@ -1908,19 +1795,16 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1908 | struct GNUNET_CADET_LocalData *ld; | 1795 | struct GNUNET_CADET_LocalData *ld; |
1909 | int ack_to_owner; | 1796 | int ack_to_owner; |
1910 | 1797 | ||
1911 | env = GNUNET_MQ_msg_extra (ld, | 1798 | env = |
1912 | buf_len, | 1799 | GNUNET_MQ_msg_extra (ld, buf_len, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); |
1913 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); | 1800 | if ((NULL != ch->owner) && |
1914 | if ( (NULL != ch->owner) && | 1801 | (sender_ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
1915 | (sender_ccn.channel_of_client == | ||
1916 | ch->owner->ccn.channel_of_client) ) | ||
1917 | { | 1802 | { |
1918 | receiver = ch->dest; | 1803 | receiver = ch->dest; |
1919 | ack_to_owner = GNUNET_YES; | 1804 | ack_to_owner = GNUNET_YES; |
1920 | } | 1805 | } |
1921 | else if ( (NULL != ch->dest) && | 1806 | else if ((NULL != ch->dest) && |
1922 | (sender_ccn.channel_of_client == | 1807 | (sender_ccn.channel_of_client == ch->dest->ccn.channel_of_client)) |
1923 | ch->dest->ccn.channel_of_client) ) | ||
1924 | { | 1808 | { |
1925 | receiver = ch->owner; | 1809 | receiver = ch->owner; |
1926 | ack_to_owner = GNUNET_NO; | 1810 | ack_to_owner = GNUNET_NO; |
@@ -1932,16 +1816,12 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1932 | } | 1816 | } |
1933 | GNUNET_assert (NULL != receiver); | 1817 | GNUNET_assert (NULL != receiver); |
1934 | ld->ccn = receiver->ccn; | 1818 | ld->ccn = receiver->ccn; |
1935 | GNUNET_memcpy (&ld[1], | 1819 | GNUNET_memcpy (&ld[1], buf, buf_len); |
1936 | buf, | ||
1937 | buf_len); | ||
1938 | if (GNUNET_YES == receiver->client_ready) | 1820 | if (GNUNET_YES == receiver->client_ready) |
1939 | { | 1821 | { |
1940 | ch->pending_messages--; | 1822 | ch->pending_messages--; |
1941 | GSC_send_to_client (receiver->c, | 1823 | GSC_send_to_client (receiver->c, env); |
1942 | env); | 1824 | send_ack_to_client (ch, ack_to_owner); |
1943 | send_ack_to_client (ch, | ||
1944 | ack_to_owner); | ||
1945 | } | 1825 | } |
1946 | else | 1826 | else |
1947 | { | 1827 | { |
@@ -1960,19 +1840,17 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1960 | /* Everything is correct, send the message. */ | 1840 | /* Everything is correct, send the message. */ |
1961 | crm = GNUNET_malloc (sizeof (*crm)); | 1841 | crm = GNUNET_malloc (sizeof (*crm)); |
1962 | crm->ch = ch; | 1842 | crm->ch = ch; |
1963 | crm->data_message = GNUNET_malloc (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) | 1843 | crm->data_message = GNUNET_malloc ( |
1964 | + buf_len); | 1844 | sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); |
1965 | crm->data_message->header.size = htons (sizeof (struct GNUNET_CADET_ChannelAppDataMessage) + buf_len); | 1845 | crm->data_message->header.size = |
1966 | 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); | ||
1967 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); | 1849 | ch->mid_send.mid = htonl (ntohl (ch->mid_send.mid) + 1); |
1968 | crm->data_message->mid = ch->mid_send; | 1850 | crm->data_message->mid = ch->mid_send; |
1969 | crm->data_message->ctn = ch->ctn; | 1851 | crm->data_message->ctn = ch->ctn; |
1970 | GNUNET_memcpy (&crm->data_message[1], | 1852 | GNUNET_memcpy (&crm->data_message[1], buf, buf_len); |
1971 | buf, | 1853 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, ch->tail_sent, crm); |
1972 | buf_len); | ||
1973 | GNUNET_CONTAINER_DLL_insert_tail (ch->head_sent, | ||
1974 | ch->tail_sent, | ||
1975 | crm); | ||
1976 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1854 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1977 | "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", |
1978 | ntohl (crm->data_message->mid.mid), | 1856 | ntohl (crm->data_message->mid.mid), |
@@ -1983,10 +1861,7 @@ GCCH_handle_local_data (struct CadetChannel *ch, | |||
1983 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); | 1861 | GNUNET_SCHEDULER_cancel (ch->retry_data_task); |
1984 | ch->retry_data_task = NULL; | 1862 | ch->retry_data_task = NULL; |
1985 | } | 1863 | } |
1986 | crm->qe = GCT_send (ch->t, | 1864 | crm->qe = GCT_send (ch->t, &crm->data_message->header, &data_sent_cb, crm); |
1987 | &crm->data_message->header, | ||
1988 | &data_sent_cb, | ||
1989 | crm); | ||
1990 | GNUNET_assert (NULL == ch->retry_data_task); | 1865 | GNUNET_assert (NULL == ch->retry_data_task); |
1991 | return GNUNET_OK; | 1866 | return GNUNET_OK; |
1992 | } | 1867 | } |
@@ -2006,11 +1881,11 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2006 | struct CadetChannelClient *ccc; | 1881 | struct CadetChannelClient *ccc; |
2007 | struct CadetOutOfOrderMessage *com; | 1882 | struct CadetOutOfOrderMessage *com; |
2008 | 1883 | ||
2009 | if ( (NULL != ch->owner) && | 1884 | if ((NULL != ch->owner) && |
2010 | (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client) ) | 1885 | (ch->owner->ccn.channel_of_client == client_ccn.channel_of_client)) |
2011 | ccc = ch->owner; | 1886 | ccc = ch->owner; |
2012 | else if ( (NULL != ch->dest) && | 1887 | else if ((NULL != ch->dest) && |
2013 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client) ) | 1888 | (ch->dest->ccn.channel_of_client == client_ccn.channel_of_client)) |
2014 | ccc = ch->dest; | 1889 | ccc = ch->dest; |
2015 | else | 1890 | else |
2016 | GNUNET_assert (0); | 1891 | GNUNET_assert (0); |
@@ -2032,35 +1907,28 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2032 | int to_owner; | 1907 | int to_owner; |
2033 | 1908 | ||
2034 | /* Messages are always in-order, just send */ | 1909 | /* Messages are always in-order, just send */ |
2035 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1910 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
2036 | ccc->tail_recv, | ||
2037 | com); | ||
2038 | ccc->num_recv--; | 1911 | ccc->num_recv--; |
2039 | GSC_send_to_client (ccc->c, | 1912 | GSC_send_to_client (ccc->c, com->env); |
2040 | com->env); | ||
2041 | /* Notify sender that we can receive more */ | 1913 | /* Notify sender that we can receive more */ |
2042 | if ( (NULL != ch->owner) && | 1914 | if ((NULL != ch->owner) && |
2043 | (ccc->ccn.channel_of_client == | 1915 | (ccc->ccn.channel_of_client == ch->owner->ccn.channel_of_client)) |
2044 | ch->owner->ccn.channel_of_client) ) | ||
2045 | { | 1916 | { |
2046 | to_owner = GNUNET_NO; | 1917 | to_owner = GNUNET_NO; |
2047 | } | 1918 | } |
2048 | else | 1919 | else |
2049 | { | 1920 | { |
2050 | GNUNET_assert ( (NULL != ch->dest) && | 1921 | GNUNET_assert ((NULL != ch->dest) && (ccc->ccn.channel_of_client == |
2051 | (ccc->ccn.channel_of_client == | 1922 | ch->dest->ccn.channel_of_client)); |
2052 | ch->dest->ccn.channel_of_client) ); | ||
2053 | to_owner = GNUNET_YES; | 1923 | to_owner = GNUNET_YES; |
2054 | } | 1924 | } |
2055 | send_ack_to_client (ch, | 1925 | send_ack_to_client (ch, to_owner); |
2056 | to_owner); | ||
2057 | GNUNET_free (com); | 1926 | GNUNET_free (com); |
2058 | return; | 1927 | return; |
2059 | } | 1928 | } |
2060 | 1929 | ||
2061 | if ( (com->mid.mid != ch->mid_recv.mid) && | 1930 | if ((com->mid.mid != ch->mid_recv.mid) && (GNUNET_NO == ch->out_of_order) && |
2062 | (GNUNET_NO == ch->out_of_order) && | 1931 | (GNUNET_YES == ch->reliable)) |
2063 | (GNUNET_YES == ch->reliable) ) | ||
2064 | { | 1932 | { |
2065 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1933 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2066 | "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", |
@@ -2079,9 +1947,7 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2079 | GCCH_2s (ch)); | 1947 | GCCH_2s (ch)); |
2080 | 1948 | ||
2081 | /* all good, pass next message to client */ | 1949 | /* all good, pass next message to client */ |
2082 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, | 1950 | GNUNET_CONTAINER_DLL_remove (ccc->head_recv, ccc->tail_recv, com); |
2083 | ccc->tail_recv, | ||
2084 | com); | ||
2085 | ccc->num_recv--; | 1951 | ccc->num_recv--; |
2086 | /* FIXME: if unreliable, this is not aggressive | 1952 | /* FIXME: if unreliable, this is not aggressive |
2087 | enough, as it would be OK to have lost some! */ | 1953 | enough, as it would be OK to have lost some! */ |
@@ -2089,21 +1955,20 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2089 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); | 1955 | ch->mid_recv.mid = htonl (1 + ntohl (com->mid.mid)); |
2090 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ | 1956 | ch->mid_futures >>= 1; /* equivalent to division by 2 */ |
2091 | ccc->client_ready = GNUNET_NO; | 1957 | ccc->client_ready = GNUNET_NO; |
2092 | GSC_send_to_client (ccc->c, | 1958 | GSC_send_to_client (ccc->c, com->env); |
2093 | com->env); | ||
2094 | GNUNET_free (com); | 1959 | GNUNET_free (com); |
2095 | send_channel_data_ack (ch); | 1960 | send_channel_data_ack (ch); |
2096 | if (NULL != ccc->head_recv) | 1961 | if (NULL != ccc->head_recv) |
2097 | return; | 1962 | return; |
2098 | if (GNUNET_NO == ch->destroy) | 1963 | if (GNUNET_NO == ch->destroy) |
2099 | return; | 1964 | return; |
2100 | GCT_send_channel_destroy (ch->t, | 1965 | GCT_send_channel_destroy (ch->t, ch->ctn); |
2101 | ch->ctn); | ||
2102 | channel_destroy (ch); | 1966 | channel_destroy (ch); |
2103 | } | 1967 | } |
2104 | 1968 | ||
2105 | 1969 | ||
2106 | #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__) | ||
2107 | 1972 | ||
2108 | 1973 | ||
2109 | /** | 1974 | /** |
@@ -2113,15 +1978,16 @@ GCCH_handle_local_ack (struct CadetChannel *ch, | |||
2113 | * @param level Debug level to use. | 1978 | * @param level Debug level to use. |
2114 | */ | 1979 | */ |
2115 | void | 1980 | void |
2116 | GCCH_debug (struct CadetChannel *ch, | 1981 | GCCH_debug (struct CadetChannel *ch, enum GNUNET_ErrorType level) |
2117 | enum GNUNET_ErrorType level) | ||
2118 | { | 1982 | { |
2119 | #if !defined(GNUNET_CULL_LOGGING) | 1983 | #if ! defined(GNUNET_CULL_LOGGING) |
2120 | int do_log; | 1984 | int do_log; |
2121 | 1985 | ||
2122 | 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), |
2123 | "cadet-chn", | 1987 | "cadet-chn", |
2124 | __FILE__, __FUNCTION__, __LINE__); | 1988 | __FILE__, |
1989 | __FUNCTION__, | ||
1990 | __LINE__); | ||
2125 | if (0 == do_log) | 1991 | if (0 == do_log) |
2126 | return; | 1992 | return; |
2127 | 1993 | ||
@@ -2130,11 +1996,7 @@ GCCH_debug (struct CadetChannel *ch, | |||
2130 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); | 1996 | LOG2 (level, "CHN *** DEBUG NULL CHANNEL ***\n"); |
2131 | return; | 1997 | return; |
2132 | } | 1998 | } |
2133 | LOG2 (level, | 1999 | LOG2 (level, "CHN %s:%X (%p)\n", GCT_2s (ch->t), ch->ctn, ch); |
2134 | "CHN %s:%X (%p)\n", | ||
2135 | GCT_2s (ch->t), | ||
2136 | ch->ctn, | ||
2137 | ch); | ||
2138 | if (NULL != ch->owner) | 2000 | if (NULL != ch->owner) |
2139 | { | 2001 | { |
2140 | LOG2 (level, | 2002 | LOG2 (level, |
@@ -2160,5 +2022,4 @@ GCCH_debug (struct CadetChannel *ch, | |||
2160 | } | 2022 | } |
2161 | 2023 | ||
2162 | 2024 | ||
2163 | |||
2164 | /* end of gnunet-service-cadet-new_channel.c */ | 2025 | /* end of gnunet-service-cadet-new_channel.c */ |