diff options
Diffstat (limited to 'src/cadet/gnunet-service-cadet_connection.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 518 |
1 files changed, 314 insertions, 204 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 1c500f716..931b32b95 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c | |||
@@ -112,17 +112,17 @@ struct CadetFlowControl | |||
112 | /** | 112 | /** |
113 | * ID of the next packet to send. | 113 | * ID of the next packet to send. |
114 | */ | 114 | */ |
115 | uint32_t next_pid; | 115 | struct CadetEncryptedMessageIdentifier next_pid; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * ID of the last packet sent towards the peer. | 118 | * ID of the last packet sent towards the peer. |
119 | */ | 119 | */ |
120 | uint32_t last_pid_sent; | 120 | struct CadetEncryptedMessageIdentifier last_pid_sent; |
121 | 121 | ||
122 | /** | 122 | /** |
123 | * ID of the last packet received from the peer. | 123 | * ID of the last packet received from the peer. |
124 | */ | 124 | */ |
125 | uint32_t last_pid_recv; | 125 | struct CadetEncryptedMessageIdentifier last_pid_recv; |
126 | 126 | ||
127 | /** | 127 | /** |
128 | * Bitmap of past 32 messages received: | 128 | * Bitmap of past 32 messages received: |
@@ -132,14 +132,15 @@ struct CadetFlowControl | |||
132 | uint32_t recv_bitmap; | 132 | uint32_t recv_bitmap; |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Last ACK sent to the peer (peer can't send more than this PID). | 135 | * Last ACK sent to the peer (peer is not allowed to send |
136 | * messages with PIDs higher than this value). | ||
136 | */ | 137 | */ |
137 | uint32_t last_ack_sent; | 138 | struct CadetEncryptedMessageIdentifier last_ack_sent; |
138 | 139 | ||
139 | /** | 140 | /** |
140 | * Last ACK sent towards the origin (for traffic towards leaf node). | 141 | * Last ACK sent towards the origin (for traffic towards leaf node). |
141 | */ | 142 | */ |
142 | uint32_t last_ack_recv; | 143 | struct CadetEncryptedMessageIdentifier last_ack_recv; |
143 | 144 | ||
144 | /** | 145 | /** |
145 | * Task to poll the peer in case of a lost ACK causes stall. | 146 | * Task to poll the peer in case of a lost ACK causes stall. |
@@ -217,7 +218,7 @@ struct CadetConnection | |||
217 | /** | 218 | /** |
218 | * ID of the connection. | 219 | * ID of the connection. |
219 | */ | 220 | */ |
220 | struct GNUNET_CADET_Hash id; | 221 | struct GNUNET_CADET_ConnectionTunnelIdentifier id; |
221 | 222 | ||
222 | /** | 223 | /** |
223 | * Path being used for the tunnel. At the origin of the connection | 224 | * Path being used for the tunnel. At the origin of the connection |
@@ -321,7 +322,7 @@ extern struct GNUNET_PeerIdentity my_full_id; | |||
321 | /** | 322 | /** |
322 | * Connections known, indexed by cid (CadetConnection). | 323 | * Connections known, indexed by cid (CadetConnection). |
323 | */ | 324 | */ |
324 | static struct GNUNET_CONTAINER_MultiHashMap *connections; | 325 | static struct GNUNET_CONTAINER_MultiShortmap *connections; |
325 | 326 | ||
326 | /** | 327 | /** |
327 | * How many connections are we willing to maintain. | 328 | * How many connections are we willing to maintain. |
@@ -358,7 +359,8 @@ static void | |||
358 | fc_debug (struct CadetFlowControl *fc) | 359 | fc_debug (struct CadetFlowControl *fc) |
359 | { | 360 | { |
360 | LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n", | 361 | LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n", |
361 | fc->last_pid_recv, fc->last_ack_sent); | 362 | ntohl (fc->last_pid_recv.pid), |
363 | ntohl (fc->last_ack_sent.pid)); | ||
362 | LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n", | 364 | LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n", |
363 | fc->last_pid_sent, fc->last_ack_recv); | 365 | fc->last_pid_sent, fc->last_ack_recv); |
364 | LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n", | 366 | LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n", |
@@ -452,11 +454,11 @@ GCC_state2s (enum CadetConnectionState s) | |||
452 | static void | 454 | static void |
453 | fc_init (struct CadetFlowControl *fc) | 455 | fc_init (struct CadetFlowControl *fc) |
454 | { | 456 | { |
455 | fc->next_pid = (uint32_t) 0; | 457 | fc->next_pid.pid = 0; |
456 | fc->last_pid_sent = (uint32_t) -1; | 458 | fc->last_pid_sent.pid = htonl (UINT32_MAX); |
457 | fc->last_pid_recv = (uint32_t) -1; | 459 | fc->last_pid_recv.pid = htonl (UINT32_MAX); |
458 | fc->last_ack_sent = (uint32_t) 0; | 460 | fc->last_ack_sent.pid = (uint32_t) 0; |
459 | fc->last_ack_recv = (uint32_t) 0; | 461 | fc->last_ack_recv.pid = (uint32_t) 0; |
460 | fc->poll_task = NULL; | 462 | fc->poll_task = NULL; |
461 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | 463 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; |
462 | fc->queue_n = 0; | 464 | fc->queue_n = 0; |
@@ -472,9 +474,10 @@ fc_init (struct CadetFlowControl *fc) | |||
472 | * @return conntection with the given ID @cid or NULL if not found. | 474 | * @return conntection with the given ID @cid or NULL if not found. |
473 | */ | 475 | */ |
474 | static struct CadetConnection * | 476 | static struct CadetConnection * |
475 | connection_get (const struct GNUNET_CADET_Hash *cid) | 477 | connection_get (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid) |
476 | { | 478 | { |
477 | return GNUNET_CONTAINER_multihashmap_get (connections, GC_h2hc (cid)); | 479 | return GNUNET_CONTAINER_multishortmap_get (connections, |
480 | &cid->connection_of_tunnel); | ||
478 | } | 481 | } |
479 | 482 | ||
480 | 483 | ||
@@ -540,12 +543,16 @@ send_poll (void *cls); | |||
540 | * @param force Don't optimize out. | 543 | * @param force Don't optimize out. |
541 | */ | 544 | */ |
542 | static void | 545 | static void |
543 | send_ack (struct CadetConnection *c, unsigned int buffer, int fwd, int force) | 546 | send_ack (struct CadetConnection *c, |
547 | unsigned int buffer, | ||
548 | int fwd, | ||
549 | int force) | ||
544 | { | 550 | { |
551 | static struct CadetEncryptedMessageIdentifier zero; | ||
545 | struct CadetFlowControl *next_fc; | 552 | struct CadetFlowControl *next_fc; |
546 | struct CadetFlowControl *prev_fc; | 553 | struct CadetFlowControl *prev_fc; |
547 | struct GNUNET_CADET_ACK msg; | 554 | struct GNUNET_CADET_ConnectionEncryptedAckMessage msg; |
548 | uint32_t ack; | 555 | struct CadetEncryptedMessageIdentifier ack_cemi; |
549 | int delta; | 556 | int delta; |
550 | 557 | ||
551 | GCC_check_connections (); | 558 | GCC_check_connections (); |
@@ -558,24 +565,28 @@ send_ack (struct CadetConnection *c, unsigned int buffer, int fwd, int force) | |||
558 | GC_f2s (fwd), GCC_2s (c)); | 565 | GC_f2s (fwd), GCC_2s (c)); |
559 | 566 | ||
560 | /* Check if we need to transmit the ACK. */ | 567 | /* Check if we need to transmit the ACK. */ |
561 | delta = prev_fc->last_ack_sent - prev_fc->last_pid_recv; | 568 | delta = ntohl (prev_fc->last_ack_sent.pid) - ntohl (prev_fc->last_pid_recv.pid); |
562 | if (3 < delta && buffer < delta && GNUNET_NO == force) | 569 | if (3 < delta && buffer < delta && GNUNET_NO == force) |
563 | { | 570 | { |
564 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, delta > 3\n"); | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, delta > 3\n"); |
565 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 572 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
566 | " last pid recv: %u, last ack sent: %u\n", | 573 | " last pid recv: %u, last ack sent: %u\n", |
567 | prev_fc->last_pid_recv, prev_fc->last_ack_sent); | 574 | ntohl (prev_fc->last_pid_recv.pid), |
575 | ntohl (prev_fc->last_ack_sent.pid)); | ||
568 | GCC_check_connections (); | 576 | GCC_check_connections (); |
569 | return; | 577 | return; |
570 | } | 578 | } |
571 | 579 | ||
572 | /* Ok, ACK might be necessary, what PID to ACK? */ | 580 | /* Ok, ACK might be necessary, what PID to ACK? */ |
573 | ack = prev_fc->last_pid_recv + buffer; | 581 | ack_cemi.pid = htonl (ntohl (prev_fc->last_pid_recv.pid) + buffer); |
574 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 582 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
575 | " ACK %u, last PID %u, last ACK %u, qmax %u, q %u\n", | 583 | " ACK %u, last PID %u, last ACK %u, qmax %u, q %u\n", |
576 | ack, prev_fc->last_pid_recv, prev_fc->last_ack_sent, | 584 | ntohl (ack_cemi.pid), |
585 | ntohl (prev_fc->last_pid_recv.pid), | ||
586 | ntohl (prev_fc->last_ack_sent.pid), | ||
577 | next_fc->queue_max, next_fc->queue_n); | 587 | next_fc->queue_max, next_fc->queue_n); |
578 | if (ack == prev_fc->last_ack_sent && GNUNET_NO == force) | 588 | if ( (ack_cemi.pid == prev_fc->last_ack_sent.pid) && |
589 | (GNUNET_NO == force) ) | ||
579 | { | 590 | { |
580 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); | 591 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); |
581 | GCC_check_connections (); | 592 | GCC_check_connections (); |
@@ -585,7 +596,8 @@ send_ack (struct CadetConnection *c, unsigned int buffer, int fwd, int force) | |||
585 | /* Check if message is already in queue */ | 596 | /* Check if message is already in queue */ |
586 | if (NULL != prev_fc->ack_msg) | 597 | if (NULL != prev_fc->ack_msg) |
587 | { | 598 | { |
588 | if (GC_is_pid_bigger (ack, prev_fc->last_ack_sent)) | 599 | if (GC_is_pid_bigger (ntohl (ack_cemi.pid), |
600 | ntohl (prev_fc->last_ack_sent.pid))) | ||
589 | { | 601 | { |
590 | LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); | 602 | LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); |
591 | GCC_cancel (prev_fc->ack_msg); | 603 | GCC_cancel (prev_fc->ack_msg); |
@@ -598,17 +610,22 @@ send_ack (struct CadetConnection *c, unsigned int buffer, int fwd, int force) | |||
598 | return; | 610 | return; |
599 | } | 611 | } |
600 | } | 612 | } |
601 | 613 | GNUNET_break (GC_is_pid_bigger (ntohl (ack_cemi.pid), | |
602 | prev_fc->last_ack_sent = ack; | 614 | ntohl (prev_fc->last_ack_sent.pid))); |
615 | prev_fc->last_ack_sent = ack_cemi; | ||
603 | 616 | ||
604 | /* Build ACK message and send on conn */ | 617 | /* Build ACK message and send on conn */ |
605 | msg.header.size = htons (sizeof (msg)); | 618 | msg.header.size = htons (sizeof (msg)); |
606 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_ACK); | 619 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK); |
607 | msg.ack = htonl (ack); | 620 | msg.cemi = ack_cemi; |
608 | msg.cid = c->id; | 621 | msg.cid = c->id; |
609 | 622 | ||
610 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, ack, | 623 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, |
611 | c, !fwd, GNUNET_YES, | 624 | UINT16_MAX, |
625 | zero, | ||
626 | c, | ||
627 | !fwd, | ||
628 | GNUNET_YES, | ||
612 | NULL, NULL); | 629 | NULL, NULL); |
613 | GNUNET_assert (NULL != prev_fc->ack_msg); | 630 | GNUNET_assert (NULL != prev_fc->ack_msg); |
614 | GCC_check_connections (); | 631 | GCC_check_connections (); |
@@ -672,8 +689,12 @@ update_perf (struct CadetConnection *c, | |||
672 | */ | 689 | */ |
673 | static void | 690 | static void |
674 | conn_message_sent (void *cls, | 691 | conn_message_sent (void *cls, |
675 | struct CadetConnection *c, int fwd, int sent, | 692 | struct CadetConnection *c, |
676 | uint16_t type, uint16_t payload_type, uint32_t pid, | 693 | int fwd, |
694 | int sent, | ||
695 | uint16_t type, | ||
696 | uint16_t payload_type, | ||
697 | struct CadetEncryptedMessageIdentifier pid, | ||
677 | size_t size, | 698 | size_t size, |
678 | struct GNUNET_TIME_Relative wait) | 699 | struct GNUNET_TIME_Relative wait) |
679 | { | 700 | { |
@@ -684,8 +705,11 @@ conn_message_sent (void *cls, | |||
684 | GCC_check_connections (); | 705 | GCC_check_connections (); |
685 | LOG (GNUNET_ERROR_TYPE_INFO, | 706 | LOG (GNUNET_ERROR_TYPE_INFO, |
686 | ">>> %s (%s %4u) on conn %s (%p) %s [%5u] in queue %s\n", | 707 | ">>> %s (%s %4u) on conn %s (%p) %s [%5u] in queue %s\n", |
687 | GC_m2s (type), GC_m2s (payload_type), pid, GCC_2s (c), c, | 708 | GC_m2s (type), GC_m2s (payload_type), |
688 | GC_f2s(fwd), size, | 709 | ntohl (pid.pid), |
710 | GCC_2s (c), | ||
711 | c, | ||
712 | GC_f2s (fwd), size, | ||
689 | GNUNET_STRINGS_relative_time_to_string (wait, GNUNET_YES)); | 713 | GNUNET_STRINGS_relative_time_to_string (wait, GNUNET_YES)); |
690 | 714 | ||
691 | /* If c is NULL, nothing to update. */ | 715 | /* If c is NULL, nothing to update. */ |
@@ -703,7 +727,8 @@ conn_message_sent (void *cls, | |||
703 | 727 | ||
704 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s pid %u\n", | 728 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s pid %u\n", |
705 | sent ? "" : "not ", GC_f2s (fwd), | 729 | sent ? "" : "not ", GC_f2s (fwd), |
706 | GC_m2s (type), GC_m2s (payload_type), pid); | 730 | GC_m2s (type), GC_m2s (payload_type), |
731 | ntohl (pid.pid)); | ||
707 | GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); | 732 | GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); |
708 | 733 | ||
709 | /* Update flow control info. */ | 734 | /* Update flow control info. */ |
@@ -722,7 +747,7 @@ conn_message_sent (void *cls, | |||
722 | } | 747 | } |
723 | else /* CONN_CREATE or CONN_ACK */ | 748 | else /* CONN_CREATE or CONN_ACK */ |
724 | { | 749 | { |
725 | GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED != type); | 750 | GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED != type); |
726 | forced = GNUNET_YES; | 751 | forced = GNUNET_YES; |
727 | } | 752 | } |
728 | 753 | ||
@@ -742,18 +767,19 @@ conn_message_sent (void *cls, | |||
742 | switch (type) | 767 | switch (type) |
743 | { | 768 | { |
744 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: | 769 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: |
745 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK: | 770 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK: |
746 | c->maintenance_q = NULL; | 771 | c->maintenance_q = NULL; |
747 | /* Don't trigger a keepalive for sent ACKs, only SYN and SYNACKs */ | 772 | /* Don't trigger a keepalive for sent ACKs, only SYN and SYNACKs */ |
748 | if (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE == type || !fwd) | 773 | if (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE == type || !fwd) |
749 | schedule_next_keepalive (c, fwd); | 774 | schedule_next_keepalive (c, fwd); |
750 | break; | 775 | break; |
751 | 776 | ||
752 | case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED: | 777 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED: |
753 | if (GNUNET_YES == sent) | 778 | if (GNUNET_YES == sent) |
754 | { | 779 | { |
755 | fc->last_pid_sent = pid; | 780 | fc->last_pid_sent = pid; |
756 | if (GC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv)) | 781 | if (GC_is_pid_bigger (ntohl (fc->last_pid_sent.pid) + 1, |
782 | ntohl (fc->last_ack_recv.pid)) ) | ||
757 | GCC_start_poll (c, fwd); | 783 | GCC_start_poll (c, fwd); |
758 | GCC_send_ack (c, fwd, GNUNET_NO); | 784 | GCC_send_ack (c, fwd, GNUNET_NO); |
759 | connection_reset_timeout (c, fwd); | 785 | connection_reset_timeout (c, fwd); |
@@ -764,23 +790,23 @@ conn_message_sent (void *cls, | |||
764 | { | 790 | { |
765 | fc->queue_n--; | 791 | fc->queue_n--; |
766 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 792 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
767 | "! accounting pid %u\n", | 793 | "! accounting pid %u\n", |
768 | fc->last_pid_sent); | 794 | ntohl (fc->last_pid_sent.pid)); |
769 | } | 795 | } |
770 | else | 796 | else |
771 | { | 797 | { |
772 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 798 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
773 | "! forced, Q_N not accounting pid %u\n", | 799 | "! forced, Q_N not accounting pid %u\n", |
774 | fc->last_pid_sent); | 800 | ntohl (fc->last_pid_sent.pid)); |
775 | } | 801 | } |
776 | break; | 802 | break; |
777 | 803 | ||
778 | case GNUNET_MESSAGE_TYPE_CADET_KX: | 804 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: |
779 | if (GNUNET_YES == sent) | 805 | if (GNUNET_YES == sent) |
780 | connection_reset_timeout (c, fwd); | 806 | connection_reset_timeout (c, fwd); |
781 | break; | 807 | break; |
782 | 808 | ||
783 | case GNUNET_MESSAGE_TYPE_CADET_POLL: | 809 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL: |
784 | fc->poll_msg = NULL; | 810 | fc->poll_msg = NULL; |
785 | if (2 == c->destroy) | 811 | if (2 == c->destroy) |
786 | { | 812 | { |
@@ -801,7 +827,7 @@ conn_message_sent (void *cls, | |||
801 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); | 827 | LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task); |
802 | break; | 828 | break; |
803 | 829 | ||
804 | case GNUNET_MESSAGE_TYPE_CADET_ACK: | 830 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK: |
805 | fc->ack_msg = NULL; | 831 | fc->ack_msg = NULL; |
806 | break; | 832 | break; |
807 | 833 | ||
@@ -905,7 +931,7 @@ check_neighbours (const struct CadetConnection *c) | |||
905 | */ | 931 | */ |
906 | static int | 932 | static int |
907 | check_connection (void *cls, | 933 | check_connection (void *cls, |
908 | const struct GNUNET_HashCode *key, | 934 | const struct GNUNET_ShortHashCode *key, |
909 | void *value) | 935 | void *value) |
910 | { | 936 | { |
911 | struct CadetConnection *c = value; | 937 | struct CadetConnection *c = value; |
@@ -925,9 +951,9 @@ GCC_check_connections () | |||
925 | return; | 951 | return; |
926 | if (NULL == connections) | 952 | if (NULL == connections) |
927 | return; | 953 | return; |
928 | GNUNET_CONTAINER_multihashmap_iterate (connections, | 954 | GNUNET_CONTAINER_multishortmap_iterate (connections, |
929 | &check_connection, | 955 | &check_connection, |
930 | NULL); | 956 | NULL); |
931 | } | 957 | } |
932 | 958 | ||
933 | 959 | ||
@@ -953,9 +979,11 @@ get_hop (struct CadetConnection *c, int fwd) | |||
953 | * @param ooo_pid PID of the out-of-order message. | 979 | * @param ooo_pid PID of the out-of-order message. |
954 | */ | 980 | */ |
955 | static uint32_t | 981 | static uint32_t |
956 | get_recv_bitmask (uint32_t last_pid_recv, uint32_t ooo_pid) | 982 | get_recv_bitmask (struct CadetEncryptedMessageIdentifier last_pid_recv, |
983 | struct CadetEncryptedMessageIdentifier ooo_pid) | ||
957 | { | 984 | { |
958 | return 1 << (last_pid_recv - ooo_pid); | 985 | // FIXME: should assert that the delta is in range... |
986 | return 1 << (ntohl (last_pid_recv.pid) - ntohl (ooo_pid.pid)); | ||
959 | } | 987 | } |
960 | 988 | ||
961 | 989 | ||
@@ -967,14 +995,18 @@ get_recv_bitmask (uint32_t last_pid_recv, uint32_t ooo_pid) | |||
967 | * @param last_pid_recv Last in-order PID received. | 995 | * @param last_pid_recv Last in-order PID received. |
968 | */ | 996 | */ |
969 | static int | 997 | static int |
970 | is_ooo_ok (uint32_t last_pid_recv, uint32_t ooo_pid, uint32_t ooo_bitmap) | 998 | is_ooo_ok (struct CadetEncryptedMessageIdentifier last_pid_recv, |
999 | struct CadetEncryptedMessageIdentifier ooo_pid, | ||
1000 | uint32_t ooo_bitmap) | ||
971 | { | 1001 | { |
972 | uint32_t mask; | 1002 | uint32_t mask; |
973 | 1003 | ||
974 | if (GC_is_pid_bigger (last_pid_recv - 31, ooo_pid)) | 1004 | if (GC_is_pid_bigger (ntohl (last_pid_recv.pid) - 31, |
1005 | ntohl (ooo_pid.pid))) | ||
975 | return GNUNET_NO; | 1006 | return GNUNET_NO; |
976 | 1007 | ||
977 | mask = get_recv_bitmask (last_pid_recv, ooo_pid); | 1008 | mask = get_recv_bitmask (last_pid_recv, |
1009 | ooo_pid); | ||
978 | if (0 != (ooo_bitmap & mask)) | 1010 | if (0 != (ooo_bitmap & mask)) |
979 | return GNUNET_NO; | 1011 | return GNUNET_NO; |
980 | 1012 | ||
@@ -1021,10 +1053,11 @@ is_fwd (const struct CadetConnection *c, | |||
1021 | static void | 1053 | static void |
1022 | send_connection_ack (struct CadetConnection *c, int fwd) | 1054 | send_connection_ack (struct CadetConnection *c, int fwd) |
1023 | { | 1055 | { |
1024 | struct GNUNET_CADET_ConnectionACK msg; | 1056 | static struct CadetEncryptedMessageIdentifier zero; |
1057 | struct GNUNET_CADET_ConnectionCreateMessageAckMessage msg; | ||
1025 | struct CadetTunnel *t; | 1058 | struct CadetTunnel *t; |
1026 | const uint16_t size = sizeof (struct GNUNET_CADET_ConnectionACK); | 1059 | const uint16_t size = sizeof (struct GNUNET_CADET_ConnectionCreateMessageAckMessage); |
1027 | const uint16_t type = GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK; | 1060 | const uint16_t type = GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK; |
1028 | 1061 | ||
1029 | GCC_check_connections (); | 1062 | GCC_check_connections (); |
1030 | t = c->t; | 1063 | t = c->t; |
@@ -1038,9 +1071,12 @@ send_connection_ack (struct CadetConnection *c, int fwd) | |||
1038 | msg.cid = c->id; | 1071 | msg.cid = c->id; |
1039 | 1072 | ||
1040 | GNUNET_assert (NULL == c->maintenance_q); | 1073 | GNUNET_assert (NULL == c->maintenance_q); |
1041 | c->maintenance_q = GCP_send (get_hop (c, fwd), &msg.header, | 1074 | c->maintenance_q = GCP_send (get_hop (c, fwd), |
1042 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK, 0, | 1075 | &msg.header, |
1043 | c, fwd, | 1076 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, |
1077 | zero, | ||
1078 | c, | ||
1079 | fwd, | ||
1044 | &conn_message_sent, NULL); | 1080 | &conn_message_sent, NULL); |
1045 | LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u (conn`ACK)\n", | 1081 | LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u (conn`ACK)\n", |
1046 | c, c->pending_messages); | 1082 | c, c->pending_messages); |
@@ -1068,17 +1104,23 @@ send_broken (struct CadetConnection *c, | |||
1068 | const struct GNUNET_PeerIdentity *id2, | 1104 | const struct GNUNET_PeerIdentity *id2, |
1069 | int fwd) | 1105 | int fwd) |
1070 | { | 1106 | { |
1071 | struct GNUNET_CADET_ConnectionBroken msg; | 1107 | static struct CadetEncryptedMessageIdentifier zero; |
1108 | struct GNUNET_CADET_ConnectionBrokenMessage msg; | ||
1072 | 1109 | ||
1073 | GCC_check_connections (); | 1110 | GCC_check_connections (); |
1074 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); | 1111 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBrokenMessage)); |
1075 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 1112 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
1076 | msg.cid = c->id; | 1113 | msg.cid = c->id; |
1077 | msg.reserved = htonl (0); | 1114 | msg.reserved = htonl (0); |
1078 | msg.peer1 = *id1; | 1115 | msg.peer1 = *id1; |
1079 | msg.peer2 = *id2; | 1116 | msg.peer2 = *id2; |
1080 | (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, fwd, | 1117 | (void) GCC_send_prebuilt_message (&msg.header, |
1081 | GNUNET_YES, NULL, NULL); | 1118 | UINT16_MAX, |
1119 | zero, | ||
1120 | c, | ||
1121 | fwd, | ||
1122 | GNUNET_YES, | ||
1123 | NULL, NULL); | ||
1082 | GCC_check_connections (); | 1124 | GCC_check_connections (); |
1083 | } | 1125 | } |
1084 | 1126 | ||
@@ -1093,18 +1135,19 @@ send_broken (struct CadetConnection *c, | |||
1093 | * @param neighbor Peer to notify (neighbor who sent the connection). | 1135 | * @param neighbor Peer to notify (neighbor who sent the connection). |
1094 | */ | 1136 | */ |
1095 | static void | 1137 | static void |
1096 | send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id, | 1138 | send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *connection_id, |
1097 | const struct GNUNET_PeerIdentity *id1, | 1139 | const struct GNUNET_PeerIdentity *id1, |
1098 | const struct GNUNET_PeerIdentity *id2, | 1140 | const struct GNUNET_PeerIdentity *id2, |
1099 | struct CadetPeer *neighbor) | 1141 | struct CadetPeer *neighbor) |
1100 | { | 1142 | { |
1101 | struct GNUNET_CADET_ConnectionBroken msg; | 1143 | static struct CadetEncryptedMessageIdentifier zero; |
1144 | struct GNUNET_CADET_ConnectionBrokenMessage msg; | ||
1102 | 1145 | ||
1103 | GCC_check_connections (); | 1146 | GCC_check_connections (); |
1104 | LOG (GNUNET_ERROR_TYPE_INFO, "--> BROKEN on unknown connection %s\n", | 1147 | LOG (GNUNET_ERROR_TYPE_INFO, "--> BROKEN on unknown connection %s\n", |
1105 | GNUNET_h2s (GC_h2hc (connection_id))); | 1148 | GNUNET_sh2s (&connection_id->connection_of_tunnel)); |
1106 | 1149 | ||
1107 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBroken)); | 1150 | msg.header.size = htons (sizeof (struct GNUNET_CADET_ConnectionBrokenMessage)); |
1108 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); | 1151 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN); |
1109 | msg.cid = *connection_id; | 1152 | msg.cid = *connection_id; |
1110 | msg.reserved = htonl (0); | 1153 | msg.reserved = htonl (0); |
@@ -1113,9 +1156,12 @@ send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id, | |||
1113 | msg.peer2 = *id2; | 1156 | msg.peer2 = *id2; |
1114 | else | 1157 | else |
1115 | memset (&msg.peer2, 0, sizeof (msg.peer2)); | 1158 | memset (&msg.peer2, 0, sizeof (msg.peer2)); |
1116 | GNUNET_assert (NULL != GCP_send (neighbor, &msg.header, | 1159 | GNUNET_assert (NULL != GCP_send (neighbor, |
1117 | UINT16_MAX, 2, | 1160 | &msg.header, |
1118 | NULL, GNUNET_SYSERR, /* connection, fwd */ | 1161 | UINT16_MAX, |
1162 | zero, | ||
1163 | NULL, | ||
1164 | GNUNET_SYSERR, /* connection, fwd */ | ||
1119 | NULL, NULL)); /* continuation */ | 1165 | NULL, NULL)); /* continuation */ |
1120 | GCC_check_connections (); | 1166 | GCC_check_connections (); |
1121 | } | 1167 | } |
@@ -1153,7 +1199,7 @@ send_connection_keepalive (struct CadetConnection *c, int fwd) | |||
1153 | 1199 | ||
1154 | GNUNET_assert (NULL != c->t); | 1200 | GNUNET_assert (NULL != c->t); |
1155 | msg.size = htons (sizeof (msg)); | 1201 | msg.size = htons (sizeof (msg)); |
1156 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_KEEPALIVE); | 1202 | msg.type = htons (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE); |
1157 | 1203 | ||
1158 | GNUNET_assert (NULL == | 1204 | GNUNET_assert (NULL == |
1159 | GCT_send_prebuilt_message (&msg, c->t, c, | 1205 | GCT_send_prebuilt_message (&msg, c->t, c, |
@@ -1410,8 +1456,9 @@ connection_cancel_queues (struct CadetConnection *c, | |||
1410 | static void | 1456 | static void |
1411 | send_poll (void *cls) | 1457 | send_poll (void *cls) |
1412 | { | 1458 | { |
1459 | static struct CadetEncryptedMessageIdentifier zero; | ||
1413 | struct CadetFlowControl *fc = cls; | 1460 | struct CadetFlowControl *fc = cls; |
1414 | struct GNUNET_CADET_Poll msg; | 1461 | struct GNUNET_CADET_ConnectionHopByHopPollMessage msg; |
1415 | struct CadetConnection *c; | 1462 | struct CadetConnection *c; |
1416 | int fwd; | 1463 | int fwd; |
1417 | 1464 | ||
@@ -1422,14 +1469,20 @@ send_poll (void *cls) | |||
1422 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n", | 1469 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n", |
1423 | GCC_2s (c), GC_f2s (fwd)); | 1470 | GCC_2s (c), GC_f2s (fwd)); |
1424 | 1471 | ||
1425 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_POLL); | 1472 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL); |
1426 | msg.header.size = htons (sizeof (msg)); | 1473 | msg.header.size = htons (sizeof (msg)); |
1427 | msg.cid = c->id; | 1474 | msg.cid = c->id; |
1428 | msg.pid = htonl (fc->last_pid_sent); | 1475 | msg.cemi = fc->last_pid_sent; |
1429 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); | 1476 | LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", ntohl (fc->last_pid_sent.pid)); |
1430 | fc->poll_msg = | 1477 | fc->poll_msg |
1431 | GCC_send_prebuilt_message (&msg.header, UINT16_MAX, fc->last_pid_sent, c, | 1478 | = GCC_send_prebuilt_message (&msg.header, |
1432 | fc == &c->fwd_fc, GNUNET_YES, NULL, NULL); | 1479 | UINT16_MAX, |
1480 | zero, | ||
1481 | c, | ||
1482 | fc == &c->fwd_fc, | ||
1483 | GNUNET_YES, | ||
1484 | NULL, | ||
1485 | NULL); | ||
1433 | GNUNET_assert (NULL != fc->poll_msg); | 1486 | GNUNET_assert (NULL != fc->poll_msg); |
1434 | GCC_check_connections (); | 1487 | GCC_check_connections (); |
1435 | } | 1488 | } |
@@ -1829,7 +1882,7 @@ add_to_peer (struct CadetConnection *c, | |||
1829 | static void | 1882 | static void |
1830 | log_message (const struct GNUNET_MessageHeader *message, | 1883 | log_message (const struct GNUNET_MessageHeader *message, |
1831 | const struct CadetPeer *peer, | 1884 | const struct CadetPeer *peer, |
1832 | const struct GNUNET_CADET_Hash *conn_id) | 1885 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *conn_id) |
1833 | { | 1886 | { |
1834 | uint16_t size; | 1887 | uint16_t size; |
1835 | uint16_t type; | 1888 | uint16_t type; |
@@ -1840,7 +1893,7 @@ log_message (const struct GNUNET_MessageHeader *message, | |||
1840 | switch (type) | 1893 | switch (type) |
1841 | { | 1894 | { |
1842 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: | 1895 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: |
1843 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK: | 1896 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK: |
1844 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: | 1897 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: |
1845 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: | 1898 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: |
1846 | arrow = "=="; | 1899 | arrow = "=="; |
@@ -1848,9 +1901,13 @@ log_message (const struct GNUNET_MessageHeader *message, | |||
1848 | default: | 1901 | default: |
1849 | arrow = "--"; | 1902 | arrow = "--"; |
1850 | } | 1903 | } |
1851 | LOG (GNUNET_ERROR_TYPE_INFO, "<%s %s on conn %s from %s, %6u bytes\n", | 1904 | LOG (GNUNET_ERROR_TYPE_INFO, |
1852 | arrow, GC_m2s (type), GNUNET_h2s (GC_h2hc (conn_id)), | 1905 | "<%s %s on conn %s from %s, %6u bytes\n", |
1853 | GCP_2s(peer), (unsigned int) size); | 1906 | arrow, |
1907 | GC_m2s (type), | ||
1908 | GNUNET_sh2s (&conn_id->connection_of_tunnel), | ||
1909 | GCP_2s(peer), | ||
1910 | (unsigned int) size); | ||
1854 | } | 1911 | } |
1855 | 1912 | ||
1856 | /******************************************************************************/ | 1913 | /******************************************************************************/ |
@@ -1865,9 +1922,10 @@ log_message (const struct GNUNET_MessageHeader *message, | |||
1865 | */ | 1922 | */ |
1866 | void | 1923 | void |
1867 | GCC_handle_create (struct CadetPeer *peer, | 1924 | GCC_handle_create (struct CadetPeer *peer, |
1868 | const struct GNUNET_CADET_ConnectionCreate *msg) | 1925 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) |
1869 | { | 1926 | { |
1870 | const struct GNUNET_CADET_Hash *cid; | 1927 | static struct CadetEncryptedMessageIdentifier zero; |
1928 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid; | ||
1871 | struct GNUNET_PeerIdentity *id; | 1929 | struct GNUNET_PeerIdentity *id; |
1872 | struct CadetPeerPath *path; | 1930 | struct CadetPeerPath *path; |
1873 | struct CadetPeer *dest_peer; | 1931 | struct CadetPeer *dest_peer; |
@@ -1880,7 +1938,7 @@ GCC_handle_create (struct CadetPeer *peer, | |||
1880 | size = ntohs (msg->header.size); | 1938 | size = ntohs (msg->header.size); |
1881 | 1939 | ||
1882 | /* Calculate hops */ | 1940 | /* Calculate hops */ |
1883 | size -= sizeof (struct GNUNET_CADET_ConnectionCreate); | 1941 | size -= sizeof (struct GNUNET_CADET_ConnectionCreateMessage); |
1884 | if (0 != size % sizeof (struct GNUNET_PeerIdentity)) | 1942 | if (0 != size % sizeof (struct GNUNET_PeerIdentity)) |
1885 | { | 1943 | { |
1886 | GNUNET_break_op (0); | 1944 | GNUNET_break_op (0); |
@@ -1989,8 +2047,12 @@ GCC_handle_create (struct CadetPeer *peer, | |||
1989 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2047 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
1990 | GCP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); | 2048 | GCP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); |
1991 | GCP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_NO); | 2049 | GCP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_NO); |
1992 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, | 2050 | (void) GCC_send_prebuilt_message (&msg->header, |
1993 | GNUNET_YES, GNUNET_YES, NULL, NULL); | 2051 | 0, |
2052 | zero, | ||
2053 | c, | ||
2054 | GNUNET_YES, GNUNET_YES, | ||
2055 | NULL, NULL); | ||
1994 | } | 2056 | } |
1995 | path_destroy (path); | 2057 | path_destroy (path); |
1996 | GCC_check_connections (); | 2058 | GCC_check_connections (); |
@@ -2005,8 +2067,9 @@ GCC_handle_create (struct CadetPeer *peer, | |||
2005 | */ | 2067 | */ |
2006 | void | 2068 | void |
2007 | GCC_handle_confirm (struct CadetPeer *peer, | 2069 | GCC_handle_confirm (struct CadetPeer *peer, |
2008 | const struct GNUNET_CADET_ConnectionACK *msg) | 2070 | const struct GNUNET_CADET_ConnectionCreateMessageAckMessage *msg) |
2009 | { | 2071 | { |
2072 | static struct CadetEncryptedMessageIdentifier zero; | ||
2010 | struct CadetConnection *c; | 2073 | struct CadetConnection *c; |
2011 | enum CadetConnectionState oldstate; | 2074 | enum CadetConnectionState oldstate; |
2012 | int fwd; | 2075 | int fwd; |
@@ -2114,7 +2177,10 @@ GCC_handle_confirm (struct CadetPeer *peer, | |||
2114 | else | 2177 | else |
2115 | { | 2178 | { |
2116 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2179 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2117 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2180 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2181 | zero, | ||
2182 | c, | ||
2183 | fwd, | ||
2118 | GNUNET_YES, NULL, NULL); | 2184 | GNUNET_YES, NULL, NULL); |
2119 | } | 2185 | } |
2120 | GCC_check_connections (); | 2186 | GCC_check_connections (); |
@@ -2129,8 +2195,9 @@ GCC_handle_confirm (struct CadetPeer *peer, | |||
2129 | */ | 2195 | */ |
2130 | void | 2196 | void |
2131 | GCC_handle_broken (struct CadetPeer *peer, | 2197 | GCC_handle_broken (struct CadetPeer *peer, |
2132 | const struct GNUNET_CADET_ConnectionBroken *msg) | 2198 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) |
2133 | { | 2199 | { |
2200 | static struct CadetEncryptedMessageIdentifier zero; | ||
2134 | struct CadetConnection *c; | 2201 | struct CadetConnection *c; |
2135 | struct CadetTunnel *t; | 2202 | struct CadetTunnel *t; |
2136 | int fwd; | 2203 | int fwd; |
@@ -2183,7 +2250,8 @@ GCC_handle_broken (struct CadetPeer *peer, | |||
2183 | } | 2250 | } |
2184 | else | 2251 | else |
2185 | { | 2252 | { |
2186 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2253 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2254 | zero, c, fwd, | ||
2187 | GNUNET_YES, NULL, NULL); | 2255 | GNUNET_YES, NULL, NULL); |
2188 | connection_cancel_queues (c, !fwd); | 2256 | connection_cancel_queues (c, !fwd); |
2189 | } | 2257 | } |
@@ -2200,8 +2268,9 @@ GCC_handle_broken (struct CadetPeer *peer, | |||
2200 | */ | 2268 | */ |
2201 | void | 2269 | void |
2202 | GCC_handle_destroy (struct CadetPeer *peer, | 2270 | GCC_handle_destroy (struct CadetPeer *peer, |
2203 | const struct GNUNET_CADET_ConnectionDestroy *msg) | 2271 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) |
2204 | { | 2272 | { |
2273 | static struct CadetEncryptedMessageIdentifier zero; | ||
2205 | struct CadetConnection *c; | 2274 | struct CadetConnection *c; |
2206 | int fwd; | 2275 | int fwd; |
2207 | 2276 | ||
@@ -2233,7 +2302,8 @@ GCC_handle_destroy (struct CadetPeer *peer, | |||
2233 | 2302 | ||
2234 | if (GNUNET_NO == GCC_is_terminal (c, fwd)) | 2303 | if (GNUNET_NO == GCC_is_terminal (c, fwd)) |
2235 | { | 2304 | { |
2236 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2305 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2306 | zero, c, fwd, | ||
2237 | GNUNET_YES, NULL, NULL); | 2307 | GNUNET_YES, NULL, NULL); |
2238 | } | 2308 | } |
2239 | else if (0 == c->pending_messages) | 2309 | else if (0 == c->pending_messages) |
@@ -2262,11 +2332,11 @@ GCC_handle_destroy (struct CadetPeer *peer, | |||
2262 | */ | 2332 | */ |
2263 | void | 2333 | void |
2264 | GCC_handle_ack (struct CadetPeer *peer, | 2334 | GCC_handle_ack (struct CadetPeer *peer, |
2265 | const struct GNUNET_CADET_ACK *msg) | 2335 | const struct GNUNET_CADET_ConnectionEncryptedAckMessage *msg) |
2266 | { | 2336 | { |
2267 | struct CadetConnection *c; | 2337 | struct CadetConnection *c; |
2268 | struct CadetFlowControl *fc; | 2338 | struct CadetFlowControl *fc; |
2269 | uint32_t ack; | 2339 | struct CadetEncryptedMessageIdentifier ack; |
2270 | int fwd; | 2340 | int fwd; |
2271 | 2341 | ||
2272 | GCC_check_connections (); | 2342 | GCC_check_connections (); |
@@ -2303,15 +2373,19 @@ GCC_handle_ack (struct CadetPeer *peer, | |||
2303 | return; | 2373 | return; |
2304 | } | 2374 | } |
2305 | 2375 | ||
2306 | ack = ntohl (msg->ack); | 2376 | ack = msg->cemi; |
2307 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", | 2377 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", |
2308 | GC_f2s (fwd), ack, fc->last_ack_recv); | 2378 | GC_f2s (fwd), |
2309 | if (GC_is_pid_bigger (ack, fc->last_ack_recv)) | 2379 | ntohl (ack.pid), |
2380 | ntohl (fc->last_ack_recv.pid)); | ||
2381 | if (GC_is_pid_bigger (ntohl (ack.pid), | ||
2382 | ntohl (fc->last_ack_recv.pid))) | ||
2310 | fc->last_ack_recv = ack; | 2383 | fc->last_ack_recv = ack; |
2311 | 2384 | ||
2312 | /* Cancel polling if the ACK is big enough. */ | 2385 | /* Cancel polling if the ACK is big enough. */ |
2313 | if (NULL != fc->poll_task && | 2386 | if ( (NULL != fc->poll_task) & |
2314 | GC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) | 2387 | GC_is_pid_bigger (ntohl (fc->last_ack_recv.pid), |
2388 | ntohl (fc->last_pid_sent.pid))) | ||
2315 | { | 2389 | { |
2316 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); | 2390 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); |
2317 | GNUNET_SCHEDULER_cancel (fc->poll_task); | 2391 | GNUNET_SCHEDULER_cancel (fc->poll_task); |
@@ -2331,11 +2405,11 @@ GCC_handle_ack (struct CadetPeer *peer, | |||
2331 | */ | 2405 | */ |
2332 | void | 2406 | void |
2333 | GCC_handle_poll (struct CadetPeer *peer, | 2407 | GCC_handle_poll (struct CadetPeer *peer, |
2334 | const struct GNUNET_CADET_Poll *msg) | 2408 | const struct GNUNET_CADET_ConnectionHopByHopPollMessage *msg) |
2335 | { | 2409 | { |
2336 | struct CadetConnection *c; | 2410 | struct CadetConnection *c; |
2337 | struct CadetFlowControl *fc; | 2411 | struct CadetFlowControl *fc; |
2338 | uint32_t pid; | 2412 | struct CadetEncryptedMessageIdentifier pid; |
2339 | int fwd; | 2413 | int fwd; |
2340 | 2414 | ||
2341 | GCC_check_connections (); | 2415 | GCC_check_connections (); |
@@ -2347,7 +2421,7 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2347 | GNUNET_NO); | 2421 | GNUNET_NO); |
2348 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2422 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2349 | "POLL message on unknown connection %s!\n", | 2423 | "POLL message on unknown connection %s!\n", |
2350 | GNUNET_h2s (GC_h2hc (&msg->cid))); | 2424 | GNUNET_sh2s (&msg->cid.connection_of_tunnel)); |
2351 | send_broken_unknown (&msg->cid, | 2425 | send_broken_unknown (&msg->cid, |
2352 | &my_full_id, | 2426 | &my_full_id, |
2353 | NULL, | 2427 | NULL, |
@@ -2377,8 +2451,11 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2377 | return; | 2451 | return; |
2378 | } | 2452 | } |
2379 | 2453 | ||
2380 | pid = ntohl (msg->pid); | 2454 | pid = msg->cemi; |
2381 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u, OLD %u\n", pid, fc->last_pid_recv); | 2455 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2456 | " PID %u, OLD %u\n", | ||
2457 | ntohl (pid.pid), | ||
2458 | ntohl (fc->last_pid_recv.pid)); | ||
2382 | fc->last_pid_recv = pid; | 2459 | fc->last_pid_recv = pid; |
2383 | fwd = fc == &c->bck_fc; | 2460 | fwd = fc == &c->bck_fc; |
2384 | GCC_send_ack (c, fwd, GNUNET_YES); | 2461 | GCC_send_ack (c, fwd, GNUNET_YES); |
@@ -2402,10 +2479,10 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2402 | */ | 2479 | */ |
2403 | static int | 2480 | static int |
2404 | check_message (const struct GNUNET_MessageHeader *message, | 2481 | check_message (const struct GNUNET_MessageHeader *message, |
2405 | const struct GNUNET_CADET_Hash* cid, | 2482 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid, |
2406 | struct CadetConnection *c, | 2483 | struct CadetConnection *c, |
2407 | struct CadetPeer *sender, | 2484 | struct CadetPeer *sender, |
2408 | uint32_t pid) | 2485 | struct CadetEncryptedMessageIdentifier pid) |
2409 | { | 2486 | { |
2410 | struct CadetFlowControl *fc; | 2487 | struct CadetFlowControl *fc; |
2411 | struct CadetPeer *hop; | 2488 | struct CadetPeer *hop; |
@@ -2421,7 +2498,8 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2421 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2422 | "%s on unknown connection %s\n", | 2499 | "%s on unknown connection %s\n", |
2423 | GC_m2s (ntohs (message->type)), | 2500 | GC_m2s (ntohs (message->type)), |
2424 | GNUNET_h2s (GC_h2hc (cid))); | 2501 | GNUNET_sh2s (&cid->connection_of_tunnel)); |
2502 | GNUNET_break_op (0); | ||
2425 | send_broken_unknown (cid, | 2503 | send_broken_unknown (cid, |
2426 | &my_full_id, | 2504 | &my_full_id, |
2427 | NULL, | 2505 | NULL, |
@@ -2453,43 +2531,59 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2453 | 2531 | ||
2454 | /* Check PID for payload messages */ | 2532 | /* Check PID for payload messages */ |
2455 | type = ntohs (message->type); | 2533 | type = ntohs (message->type); |
2456 | if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type) | 2534 | if (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED == type) |
2457 | { | 2535 | { |
2458 | fc = fwd ? &c->bck_fc : &c->fwd_fc; | 2536 | fc = fwd ? &c->bck_fc : &c->fwd_fc; |
2459 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected %u - %u)\n", | 2537 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected in interval [%u,%u])\n", |
2460 | pid, fc->last_pid_recv + 1, fc->last_ack_sent); | 2538 | ntohl (pid.pid), |
2461 | if (GC_is_pid_bigger (pid, fc->last_ack_sent)) | 2539 | ntohl (fc->last_pid_recv.pid) + 1, |
2540 | ntohl (fc->last_ack_sent.pid)); | ||
2541 | if (GC_is_pid_bigger (ntohl (pid.pid), | ||
2542 | ntohl (fc->last_ack_sent.pid))) | ||
2462 | { | 2543 | { |
2463 | GNUNET_break_op (0); | 2544 | GNUNET_STATISTICS_update (stats, |
2464 | GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO); | 2545 | "# unsolicited message", |
2465 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received PID %u, (prev %u), ACK %u\n", | 2546 | 1, |
2466 | pid, fc->last_pid_recv, fc->last_ack_sent); | 2547 | GNUNET_NO); |
2548 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2549 | "Received PID %u, (prev %u), ACK %u\n", | ||
2550 | pid, fc->last_pid_recv, fc->last_ack_sent); | ||
2467 | return GNUNET_SYSERR; | 2551 | return GNUNET_SYSERR; |
2468 | } | 2552 | } |
2469 | if (GC_is_pid_bigger (pid, fc->last_pid_recv)) | 2553 | if (GC_is_pid_bigger (ntohl (pid.pid), |
2554 | ntohl (fc->last_pid_recv.pid))) | ||
2470 | { | 2555 | { |
2471 | unsigned int delta; | 2556 | unsigned int delta; |
2472 | 2557 | ||
2473 | delta = pid - fc->last_pid_recv; | 2558 | delta = ntohl (pid.pid) - ntohl (fc->last_pid_recv.pid); |
2474 | fc->last_pid_recv = pid; | 2559 | fc->last_pid_recv = pid; |
2475 | fc->recv_bitmap <<= delta; | 2560 | fc->recv_bitmap <<= delta; |
2476 | fc->recv_bitmap |= 1; | 2561 | fc->recv_bitmap |= 1; |
2477 | } | 2562 | } |
2478 | else | 2563 | else |
2479 | { | 2564 | { |
2480 | GNUNET_STATISTICS_update (stats, "# out of order PID", 1, GNUNET_NO); | 2565 | GNUNET_STATISTICS_update (stats, |
2481 | if (GNUNET_NO == is_ooo_ok (fc->last_pid_recv, pid, fc->recv_bitmap)) | 2566 | "# out of order PID", |
2567 | 1, | ||
2568 | GNUNET_NO); | ||
2569 | if (GNUNET_NO == is_ooo_ok (fc->last_pid_recv, | ||
2570 | pid, | ||
2571 | fc->recv_bitmap)) | ||
2482 | { | 2572 | { |
2483 | LOG (GNUNET_ERROR_TYPE_WARNING, "PID %u unexpected (%u+), dropping!\n", | 2573 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2484 | pid, fc->last_pid_recv - 31); | 2574 | "PID %u unexpected (%u+), dropping!\n", |
2575 | ntohl (pid.pid), | ||
2576 | ntohl (fc->last_pid_recv.pid) - 31); | ||
2485 | return GNUNET_SYSERR; | 2577 | return GNUNET_SYSERR; |
2486 | } | 2578 | } |
2487 | fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, pid); | 2579 | fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, |
2580 | pid); | ||
2488 | } | 2581 | } |
2489 | } | 2582 | } |
2490 | 2583 | ||
2491 | /* Count as connection confirmation. */ | 2584 | /* Count as connection confirmation. */ |
2492 | if (CADET_CONNECTION_SENT == c->state || CADET_CONNECTION_ACK == c->state) | 2585 | if ( (CADET_CONNECTION_SENT == c->state) || |
2586 | (CADET_CONNECTION_ACK == c->state) ) | ||
2493 | { | 2587 | { |
2494 | connection_change_state (c, CADET_CONNECTION_READY); | 2588 | connection_change_state (c, CADET_CONNECTION_READY); |
2495 | if (NULL != c->t) | 2589 | if (NULL != c->t) |
@@ -2512,9 +2606,10 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2512 | */ | 2606 | */ |
2513 | void | 2607 | void |
2514 | GCC_handle_kx (struct CadetPeer *peer, | 2608 | GCC_handle_kx (struct CadetPeer *peer, |
2515 | const struct GNUNET_CADET_KX *msg) | 2609 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) |
2516 | { | 2610 | { |
2517 | const struct GNUNET_CADET_Hash* cid; | 2611 | static struct CadetEncryptedMessageIdentifier zero; |
2612 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; | ||
2518 | struct CadetConnection *c; | 2613 | struct CadetConnection *c; |
2519 | int fwd; | 2614 | int fwd; |
2520 | 2615 | ||
@@ -2527,7 +2622,7 @@ GCC_handle_kx (struct CadetPeer *peer, | |||
2527 | cid, | 2622 | cid, |
2528 | c, | 2623 | c, |
2529 | peer, | 2624 | peer, |
2530 | 0); | 2625 | zero); |
2531 | 2626 | ||
2532 | /* If something went wrong, discard message. */ | 2627 | /* If something went wrong, discard message. */ |
2533 | if (GNUNET_SYSERR == fwd) | 2628 | if (GNUNET_SYSERR == fwd) |
@@ -2555,7 +2650,8 @@ GCC_handle_kx (struct CadetPeer *peer, | |||
2555 | /* Message not for us: forward to next hop */ | 2650 | /* Message not for us: forward to next hop */ |
2556 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2651 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2557 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); | 2652 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); |
2558 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2653 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2654 | zero, c, fwd, | ||
2559 | GNUNET_NO, NULL, NULL); | 2655 | GNUNET_NO, NULL, NULL); |
2560 | GCC_check_connections (); | 2656 | GCC_check_connections (); |
2561 | } | 2657 | } |
@@ -2569,16 +2665,17 @@ GCC_handle_kx (struct CadetPeer *peer, | |||
2569 | */ | 2665 | */ |
2570 | void | 2666 | void |
2571 | GCC_handle_encrypted (struct CadetPeer *peer, | 2667 | GCC_handle_encrypted (struct CadetPeer *peer, |
2572 | const struct GNUNET_CADET_Encrypted *msg) | 2668 | const struct GNUNET_CADET_TunnelEncryptedMessage *msg) |
2573 | { | 2669 | { |
2574 | const struct GNUNET_CADET_Hash* cid; | 2670 | static struct CadetEncryptedMessageIdentifier zero; |
2671 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; | ||
2575 | struct CadetConnection *c; | 2672 | struct CadetConnection *c; |
2576 | uint32_t pid; | 2673 | struct CadetEncryptedMessageIdentifier pid; |
2577 | int fwd; | 2674 | int fwd; |
2578 | 2675 | ||
2579 | GCC_check_connections (); | 2676 | GCC_check_connections (); |
2580 | cid = &msg->cid; | 2677 | cid = &msg->cid; |
2581 | pid = ntohl (msg->pid); | 2678 | pid = msg->cemi; |
2582 | log_message (&msg->header, peer, cid); | 2679 | log_message (&msg->header, peer, cid); |
2583 | 2680 | ||
2584 | c = connection_get (cid); | 2681 | c = connection_get (cid); |
@@ -2591,7 +2688,6 @@ GCC_handle_encrypted (struct CadetPeer *peer, | |||
2591 | /* If something went wrong, discard message. */ | 2688 | /* If something went wrong, discard message. */ |
2592 | if (GNUNET_SYSERR == fwd) | 2689 | if (GNUNET_SYSERR == fwd) |
2593 | { | 2690 | { |
2594 | GNUNET_break_op (0); | ||
2595 | GCC_check_connections (); | 2691 | GCC_check_connections (); |
2596 | return; | 2692 | return; |
2597 | } | 2693 | } |
@@ -2615,7 +2711,8 @@ GCC_handle_encrypted (struct CadetPeer *peer, | |||
2615 | /* Message not for us: forward to next hop */ | 2711 | /* Message not for us: forward to next hop */ |
2616 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2712 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2617 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); | 2713 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); |
2618 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2714 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2715 | zero, c, fwd, | ||
2619 | GNUNET_NO, NULL, NULL); | 2716 | GNUNET_NO, NULL, NULL); |
2620 | GCC_check_connections (); | 2717 | GCC_check_connections (); |
2621 | } | 2718 | } |
@@ -2661,7 +2758,8 @@ GCC_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
2661 | } | 2758 | } |
2662 | create_connection_time = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, | 2759 | create_connection_time = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, |
2663 | refresh_connection_time); | 2760 | refresh_connection_time); |
2664 | connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); | 2761 | connections = GNUNET_CONTAINER_multishortmap_create (1024, |
2762 | GNUNET_YES); | ||
2665 | } | 2763 | } |
2666 | 2764 | ||
2667 | 2765 | ||
@@ -2676,7 +2774,7 @@ GCC_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
2676 | */ | 2774 | */ |
2677 | static int | 2775 | static int |
2678 | shutdown_iterator (void *cls, | 2776 | shutdown_iterator (void *cls, |
2679 | const struct GNUNET_HashCode *key, | 2777 | const struct GNUNET_ShortHashCode *key, |
2680 | void *value) | 2778 | void *value) |
2681 | { | 2779 | { |
2682 | struct CadetConnection *c = value; | 2780 | struct CadetConnection *c = value; |
@@ -2695,10 +2793,10 @@ GCC_shutdown (void) | |||
2695 | { | 2793 | { |
2696 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connections\n"); | 2794 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connections\n"); |
2697 | GCC_check_connections (); | 2795 | GCC_check_connections (); |
2698 | GNUNET_CONTAINER_multihashmap_iterate (connections, | 2796 | GNUNET_CONTAINER_multishortmap_iterate (connections, |
2699 | &shutdown_iterator, | 2797 | &shutdown_iterator, |
2700 | NULL); | 2798 | NULL); |
2701 | GNUNET_CONTAINER_multihashmap_destroy (connections); | 2799 | GNUNET_CONTAINER_multishortmap_destroy (connections); |
2702 | connections = NULL; | 2800 | connections = NULL; |
2703 | } | 2801 | } |
2704 | 2802 | ||
@@ -2715,7 +2813,7 @@ GCC_shutdown (void) | |||
2715 | * NULL in case of error: own id not in path, wrong neighbors, ... | 2813 | * NULL in case of error: own id not in path, wrong neighbors, ... |
2716 | */ | 2814 | */ |
2717 | struct CadetConnection * | 2815 | struct CadetConnection * |
2718 | GCC_new (const struct GNUNET_CADET_Hash *cid, | 2816 | GCC_new (const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid, |
2719 | struct CadetTunnel *t, | 2817 | struct CadetTunnel *t, |
2720 | struct CadetPeerPath *path, | 2818 | struct CadetPeerPath *path, |
2721 | unsigned int own_pos) | 2819 | unsigned int own_pos) |
@@ -2729,9 +2827,10 @@ GCC_new (const struct GNUNET_CADET_Hash *cid, | |||
2729 | c = GNUNET_new (struct CadetConnection); | 2827 | c = GNUNET_new (struct CadetConnection); |
2730 | c->id = *cid; | 2828 | c->id = *cid; |
2731 | GNUNET_assert (GNUNET_OK == | 2829 | GNUNET_assert (GNUNET_OK == |
2732 | GNUNET_CONTAINER_multihashmap_put (connections, | 2830 | GNUNET_CONTAINER_multishortmap_put (connections, |
2733 | GCC_get_h (c), c, | 2831 | &c->id.connection_of_tunnel, |
2734 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2832 | c, |
2833 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2735 | fc_init (&c->fwd_fc); | 2834 | fc_init (&c->fwd_fc); |
2736 | fc_init (&c->bck_fc); | 2835 | fc_init (&c->bck_fc); |
2737 | c->fwd_fc.c = c; | 2836 | c->fwd_fc.c = c; |
@@ -2832,9 +2931,9 @@ GCC_destroy (struct CadetConnection *c) | |||
2832 | if (GNUNET_NO == c->was_removed) | 2931 | if (GNUNET_NO == c->was_removed) |
2833 | { | 2932 | { |
2834 | GNUNET_break (GNUNET_YES == | 2933 | GNUNET_break (GNUNET_YES == |
2835 | GNUNET_CONTAINER_multihashmap_remove (connections, | 2934 | GNUNET_CONTAINER_multishortmap_remove (connections, |
2836 | GCC_get_h (c), | 2935 | &c->id.connection_of_tunnel, |
2837 | c)); | 2936 | c)); |
2838 | } | 2937 | } |
2839 | GNUNET_STATISTICS_update (stats, | 2938 | GNUNET_STATISTICS_update (stats, |
2840 | "# connections", | 2939 | "# connections", |
@@ -2852,7 +2951,7 @@ GCC_destroy (struct CadetConnection *c) | |||
2852 | * | 2951 | * |
2853 | * @return ID of the connection. | 2952 | * @return ID of the connection. |
2854 | */ | 2953 | */ |
2855 | const struct GNUNET_CADET_Hash * | 2954 | const struct GNUNET_CADET_ConnectionTunnelIdentifier * |
2856 | GCC_get_id (const struct CadetConnection *c) | 2955 | GCC_get_id (const struct CadetConnection *c) |
2857 | { | 2956 | { |
2858 | return &c->id; | 2957 | return &c->id; |
@@ -2860,20 +2959,6 @@ GCC_get_id (const struct CadetConnection *c) | |||
2860 | 2959 | ||
2861 | 2960 | ||
2862 | /** | 2961 | /** |
2863 | * Get the connection ID. | ||
2864 | * | ||
2865 | * @param c Connection to get the ID from. | ||
2866 | * | ||
2867 | * @return ID of the connection. | ||
2868 | */ | ||
2869 | const struct GNUNET_HashCode * | ||
2870 | GCC_get_h (const struct CadetConnection *c) | ||
2871 | { | ||
2872 | return GC_h2hc (&c->id); | ||
2873 | } | ||
2874 | |||
2875 | |||
2876 | /** | ||
2877 | * Get the connection path. | 2962 | * Get the connection path. |
2878 | * | 2963 | * |
2879 | * @param c Connection to get the path from. | 2964 | * @param c Connection to get the path from. |
@@ -2953,12 +3038,13 @@ GCC_get_allowed (struct CadetConnection *c, int fwd) | |||
2953 | struct CadetFlowControl *fc; | 3038 | struct CadetFlowControl *fc; |
2954 | 3039 | ||
2955 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3040 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
2956 | if (CADET_CONNECTION_READY != c->state | 3041 | if ( (CADET_CONNECTION_READY != c->state) || |
2957 | || GC_is_pid_bigger (fc->last_pid_recv, fc->last_ack_sent)) | 3042 | GC_is_pid_bigger (ntohl (fc->last_pid_recv.pid), |
3043 | ntohl (fc->last_ack_sent.pid)) ) | ||
2958 | { | 3044 | { |
2959 | return 0; | 3045 | return 0; |
2960 | } | 3046 | } |
2961 | return (fc->last_ack_sent - fc->last_pid_recv); | 3047 | return (ntohl (fc->last_ack_sent.pid) - ntohl (fc->last_pid_recv.pid)); |
2962 | } | 3048 | } |
2963 | 3049 | ||
2964 | 3050 | ||
@@ -2986,18 +3072,17 @@ GCC_get_qn (struct CadetConnection *c, int fwd) | |||
2986 | * | 3072 | * |
2987 | * @param c Connection. | 3073 | * @param c Connection. |
2988 | * @param fwd Is query about FWD traffic? | 3074 | * @param fwd Is query about FWD traffic? |
2989 | * | ||
2990 | * @return Next PID to use. | 3075 | * @return Next PID to use. |
2991 | */ | 3076 | */ |
2992 | uint32_t | 3077 | struct CadetEncryptedMessageIdentifier |
2993 | GCC_get_pid (struct CadetConnection *c, int fwd) | 3078 | GCC_get_pid (struct CadetConnection *c, int fwd) |
2994 | { | 3079 | { |
2995 | struct CadetFlowControl *fc; | 3080 | struct CadetFlowControl *fc; |
2996 | uint32_t pid; | 3081 | struct CadetEncryptedMessageIdentifier pid; |
2997 | 3082 | ||
2998 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3083 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
2999 | pid = fc->next_pid; | 3084 | pid = fc->next_pid; |
3000 | fc->next_pid++; | 3085 | fc->next_pid.pid = htonl (1 + ntohl (pid.pid)); |
3001 | return pid; | 3086 | return pid; |
3002 | } | 3087 | } |
3003 | 3088 | ||
@@ -3072,9 +3157,9 @@ GCC_neighbor_disconnected (struct CadetConnection *c, struct CadetPeer *peer) | |||
3072 | GNUNET_assert (GNUNET_NO == c->was_removed); | 3157 | GNUNET_assert (GNUNET_NO == c->was_removed); |
3073 | c->was_removed = GNUNET_YES; | 3158 | c->was_removed = GNUNET_YES; |
3074 | GNUNET_break (GNUNET_YES == | 3159 | GNUNET_break (GNUNET_YES == |
3075 | GNUNET_CONTAINER_multihashmap_remove (connections, | 3160 | GNUNET_CONTAINER_multishortmap_remove (connections, |
3076 | GCC_get_h (c), | 3161 | &c->id.connection_of_tunnel, |
3077 | c)); | 3162 | c)); |
3078 | /* Cancel queue in the direction that just died. */ | 3163 | /* Cancel queue in the direction that just died. */ |
3079 | connection_cancel_queues (c, ! fwd); | 3164 | connection_cancel_queues (c, ! fwd); |
3080 | GCC_stop_poll (c, ! fwd); | 3165 | GCC_stop_poll (c, ! fwd); |
@@ -3142,8 +3227,10 @@ GCC_is_sendable (struct CadetConnection *c, int fwd) | |||
3142 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3227 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3143 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3228 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3144 | " last ack recv: %u, last pid sent: %u\n", | 3229 | " last ack recv: %u, last pid sent: %u\n", |
3145 | fc->last_ack_recv, fc->last_pid_sent); | 3230 | ntohl (fc->last_ack_recv.pid), |
3146 | if (GC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) | 3231 | ntohl (fc->last_pid_sent.pid)); |
3232 | if (GC_is_pid_bigger (ntohl (fc->last_ack_recv.pid), | ||
3233 | ntohl (fc->last_pid_sent.pid))) | ||
3147 | { | 3234 | { |
3148 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); | 3235 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); |
3149 | return GNUNET_YES; | 3236 | return GNUNET_YES; |
@@ -3188,7 +3275,8 @@ GCC_is_direct (struct CadetConnection *c) | |||
3188 | */ | 3275 | */ |
3189 | struct CadetConnectionQueue * | 3276 | struct CadetConnectionQueue * |
3190 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | 3277 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, |
3191 | uint16_t payload_type, uint32_t payload_id, | 3278 | uint16_t payload_type, |
3279 | struct CadetEncryptedMessageIdentifier payload_id, | ||
3192 | struct CadetConnection *c, int fwd, int force, | 3280 | struct CadetConnection *c, int fwd, int force, |
3193 | GCC_sent cont, void *cont_cls) | 3281 | GCC_sent cont, void *cont_cls) |
3194 | { | 3282 | { |
@@ -3214,27 +3302,30 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3214 | GC_f2s(fwd), size); | 3302 | GC_f2s(fwd), size); |
3215 | switch (type) | 3303 | switch (type) |
3216 | { | 3304 | { |
3217 | case GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED: | 3305 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED: |
3218 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u, PIDsnt: %u, ACKrcv: %u\n", | 3306 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u, PIDsnt: %u, ACKrcv: %u\n", |
3219 | fc, fc->queue_n, fc->last_pid_sent, fc->last_ack_recv); | 3307 | fc, |
3308 | fc->queue_n, | ||
3309 | ntohl (fc->last_pid_sent.pid), | ||
3310 | ntohl (fc->last_ack_recv.pid)); | ||
3220 | if (GNUNET_NO == force) | 3311 | if (GNUNET_NO == force) |
3221 | { | 3312 | { |
3222 | fc->queue_n++; | 3313 | fc->queue_n++; |
3223 | } | 3314 | } |
3224 | break; | 3315 | break; |
3225 | 3316 | ||
3226 | case GNUNET_MESSAGE_TYPE_CADET_KX: | 3317 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX: |
3227 | /* nothing to do here */ | 3318 | /* nothing to do here */ |
3228 | break; | 3319 | break; |
3229 | 3320 | ||
3230 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: | 3321 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: |
3231 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK: | 3322 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK: |
3232 | /* Should've only be used for restransmissions. */ | 3323 | /* Should've only be used for restransmissions. */ |
3233 | GNUNET_break (0 == payload_type); | 3324 | GNUNET_break (0 == payload_type); |
3234 | break; | 3325 | break; |
3235 | 3326 | ||
3236 | case GNUNET_MESSAGE_TYPE_CADET_ACK: | 3327 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK: |
3237 | case GNUNET_MESSAGE_TYPE_CADET_POLL: | 3328 | case GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL: |
3238 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: | 3329 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY: |
3239 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: | 3330 | case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN: |
3240 | GNUNET_assert (GNUNET_YES == force); | 3331 | GNUNET_assert (GNUNET_YES == force); |
@@ -3252,7 +3343,7 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3252 | GNUNET_break (0); | 3343 | GNUNET_break (0); |
3253 | LOG (GNUNET_ERROR_TYPE_DEBUG, "queue full: %u/%u\n", | 3344 | LOG (GNUNET_ERROR_TYPE_DEBUG, "queue full: %u/%u\n", |
3254 | fc->queue_n, fc->queue_max); | 3345 | fc->queue_n, fc->queue_max); |
3255 | if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == type) | 3346 | if (GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED == type) |
3256 | { | 3347 | { |
3257 | fc->queue_n--; | 3348 | fc->queue_n--; |
3258 | } | 3349 | } |
@@ -3264,21 +3355,25 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3264 | c->pending_messages++; | 3355 | c->pending_messages++; |
3265 | 3356 | ||
3266 | q = GNUNET_new (struct CadetConnectionQueue); | 3357 | q = GNUNET_new (struct CadetConnectionQueue); |
3358 | q->cont = cont; | ||
3359 | q->cont_cls = cont_cls; | ||
3267 | q->forced = force; | 3360 | q->forced = force; |
3268 | q->peer_q = GCP_send (get_hop (c, fwd), message, | 3361 | GNUNET_CONTAINER_DLL_insert (fc->q_head, fc->q_tail, q); |
3269 | payload_type, payload_id, | 3362 | q->peer_q = GCP_send (get_hop (c, fwd), |
3270 | c, fwd, | 3363 | message, |
3364 | payload_type, | ||
3365 | payload_id, | ||
3366 | c, | ||
3367 | fwd, | ||
3271 | &conn_message_sent, q); | 3368 | &conn_message_sent, q); |
3272 | if (NULL == q->peer_q) | 3369 | if (NULL == q->peer_q) |
3273 | { | 3370 | { |
3274 | LOG (GNUNET_ERROR_TYPE_DEBUG, "dropping msg on %s, NULL q\n", GCC_2s (c)); | 3371 | LOG (GNUNET_ERROR_TYPE_DEBUG, "dropping msg on %s, NULL q\n", GCC_2s (c)); |
3372 | GNUNET_CONTAINER_DLL_remove (fc->q_head, fc->q_tail, q); | ||
3275 | GNUNET_free (q); | 3373 | GNUNET_free (q); |
3276 | GCC_check_connections (); | 3374 | GCC_check_connections (); |
3277 | return NULL; | 3375 | return NULL; |
3278 | } | 3376 | } |
3279 | q->cont = cont; | ||
3280 | q->cont_cls = cont_cls; | ||
3281 | GNUNET_CONTAINER_DLL_insert (fc->q_head, fc->q_tail, q); | ||
3282 | GCC_check_connections (); | 3377 | GCC_check_connections (); |
3283 | return q; | 3378 | return q; |
3284 | } | 3379 | } |
@@ -3313,19 +3408,21 @@ GCC_cancel (struct CadetConnectionQueue *q) | |||
3313 | void | 3408 | void |
3314 | GCC_send_create (struct CadetConnection *c) | 3409 | GCC_send_create (struct CadetConnection *c) |
3315 | { | 3410 | { |
3411 | static struct CadetEncryptedMessageIdentifier zero; | ||
3316 | enum CadetTunnelCState state; | 3412 | enum CadetTunnelCState state; |
3317 | size_t size; | 3413 | size_t size; |
3318 | 3414 | ||
3319 | GCC_check_connections (); | 3415 | GCC_check_connections (); |
3320 | size = sizeof (struct GNUNET_CADET_ConnectionCreate); | 3416 | size = sizeof (struct GNUNET_CADET_ConnectionCreateMessage); |
3321 | size += c->path->length * sizeof (struct GNUNET_PeerIdentity); | 3417 | size += c->path->length * sizeof (struct GNUNET_PeerIdentity); |
3322 | { | 3418 | { |
3323 | /* Allocate message on the stack */ | 3419 | /* Allocate message on the stack */ |
3324 | unsigned char cbuf[size]; | 3420 | unsigned char cbuf[size]; |
3325 | struct GNUNET_CADET_ConnectionCreate *msg; | 3421 | struct GNUNET_CADET_ConnectionCreateMessage *msg; |
3326 | struct GNUNET_PeerIdentity *peers; | 3422 | struct GNUNET_PeerIdentity *peers; |
3327 | 3423 | ||
3328 | msg = (struct GNUNET_CADET_ConnectionCreate *) cbuf; | 3424 | |
3425 | msg = (struct GNUNET_CADET_ConnectionCreateMessage *) cbuf; | ||
3329 | msg->header.size = htons (size); | 3426 | msg->header.size = htons (size); |
3330 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 3427 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
3331 | msg->reserved = htonl (0); | 3428 | msg->reserved = htonl (0); |
@@ -3338,7 +3435,8 @@ GCC_send_create (struct CadetConnection *c) | |||
3338 | GNUNET_assert (NULL == c->maintenance_q); | 3435 | GNUNET_assert (NULL == c->maintenance_q); |
3339 | c->maintenance_q = GCP_send (get_next_hop (c), | 3436 | c->maintenance_q = GCP_send (get_next_hop (c), |
3340 | &msg->header, | 3437 | &msg->header, |
3341 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 0, | 3438 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, |
3439 | zero, | ||
3342 | c, GNUNET_YES, | 3440 | c, GNUNET_YES, |
3343 | &conn_message_sent, NULL); | 3441 | &conn_message_sent, NULL); |
3344 | } | 3442 | } |
@@ -3435,7 +3533,8 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force) | |||
3435 | void | 3533 | void |
3436 | GCC_send_destroy (struct CadetConnection *c) | 3534 | GCC_send_destroy (struct CadetConnection *c) |
3437 | { | 3535 | { |
3438 | struct GNUNET_CADET_ConnectionDestroy msg; | 3536 | static struct CadetEncryptedMessageIdentifier zero; |
3537 | struct GNUNET_CADET_ConnectionDestroyMessage msg; | ||
3439 | 3538 | ||
3440 | if (GNUNET_YES == c->destroy) | 3539 | if (GNUNET_YES == c->destroy) |
3441 | return; | 3540 | return; |
@@ -3449,10 +3548,16 @@ GCC_send_destroy (struct CadetConnection *c) | |||
3449 | GCC_2s (c)); | 3548 | GCC_2s (c)); |
3450 | 3549 | ||
3451 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_YES)) | 3550 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_YES)) |
3452 | (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, | 3551 | (void) GCC_send_prebuilt_message (&msg.header, |
3552 | UINT16_MAX, | ||
3553 | zero, | ||
3554 | c, | ||
3453 | GNUNET_YES, GNUNET_YES, NULL, NULL); | 3555 | GNUNET_YES, GNUNET_YES, NULL, NULL); |
3454 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_NO)) | 3556 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_NO)) |
3455 | (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, | 3557 | (void) GCC_send_prebuilt_message (&msg.header, |
3558 | UINT16_MAX, | ||
3559 | zero, | ||
3560 | c, | ||
3456 | GNUNET_NO, GNUNET_YES, NULL, NULL); | 3561 | GNUNET_NO, GNUNET_YES, NULL, NULL); |
3457 | mark_destroyed (c); | 3562 | mark_destroyed (c); |
3458 | GCC_check_connections (); | 3563 | GCC_check_connections (); |
@@ -3538,10 +3643,11 @@ GCC_2s (const struct CadetConnection *c) | |||
3538 | static char buf[128]; | 3643 | static char buf[128]; |
3539 | 3644 | ||
3540 | SPRINTF (buf, "%s (->%s)", | 3645 | SPRINTF (buf, "%s (->%s)", |
3541 | GNUNET_h2s (GC_h2hc (GCC_get_id (c))), GCT_2s (c->t)); | 3646 | GNUNET_sh2s (&GCC_get_id (c)->connection_of_tunnel), |
3647 | GCT_2s (c->t)); | ||
3542 | return buf; | 3648 | return buf; |
3543 | } | 3649 | } |
3544 | return GNUNET_h2s (GC_h2hc (&c->id)); | 3650 | return GNUNET_sh2s (&c->id.connection_of_tunnel); |
3545 | } | 3651 | } |
3546 | 3652 | ||
3547 | 3653 | ||
@@ -3582,9 +3688,11 @@ GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level) | |||
3582 | LOG2 (level, "CCC FWD flow control:\n"); | 3688 | LOG2 (level, "CCC FWD flow control:\n"); |
3583 | LOG2 (level, "CCC queue: %u/%u\n", c->fwd_fc.queue_n, c->fwd_fc.queue_max); | 3689 | LOG2 (level, "CCC queue: %u/%u\n", c->fwd_fc.queue_n, c->fwd_fc.queue_max); |
3584 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", | 3690 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", |
3585 | c->fwd_fc.last_pid_sent, c->fwd_fc.last_pid_recv); | 3691 | ntohl (c->fwd_fc.last_pid_sent.pid), |
3692 | ntohl (c->fwd_fc.last_pid_recv.pid)); | ||
3586 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", | 3693 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", |
3587 | c->fwd_fc.last_ack_sent, c->fwd_fc.last_ack_recv); | 3694 | ntohl (c->fwd_fc.last_ack_sent.pid), |
3695 | ntohl (c->fwd_fc.last_ack_recv.pid)); | ||
3588 | LOG2 (level, "CCC recv PID bitmap: %X\n", c->fwd_fc.recv_bitmap); | 3696 | LOG2 (level, "CCC recv PID bitmap: %X\n", c->fwd_fc.recv_bitmap); |
3589 | LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", | 3697 | LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", |
3590 | c->fwd_fc.poll_task, c->fwd_fc.poll_msg, c->fwd_fc.ack_msg); | 3698 | c->fwd_fc.poll_task, c->fwd_fc.poll_msg, c->fwd_fc.ack_msg); |
@@ -3592,9 +3700,11 @@ GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level) | |||
3592 | LOG2 (level, "CCC BCK flow control:\n"); | 3700 | LOG2 (level, "CCC BCK flow control:\n"); |
3593 | LOG2 (level, "CCC queue: %u/%u\n", c->bck_fc.queue_n, c->bck_fc.queue_max); | 3701 | LOG2 (level, "CCC queue: %u/%u\n", c->bck_fc.queue_n, c->bck_fc.queue_max); |
3594 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", | 3702 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", |
3595 | c->bck_fc.last_pid_sent, c->bck_fc.last_pid_recv); | 3703 | ntohl (c->bck_fc.last_pid_sent.pid), |
3704 | ntohl (c->bck_fc.last_pid_recv.pid)); | ||
3596 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", | 3705 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", |
3597 | c->bck_fc.last_ack_sent, c->bck_fc.last_ack_recv); | 3706 | ntohl (c->bck_fc.last_ack_sent.pid), |
3707 | ntohl (c->bck_fc.last_ack_recv.pid)); | ||
3598 | LOG2 (level, "CCC recv PID bitmap: %X\n", c->bck_fc.recv_bitmap); | 3708 | LOG2 (level, "CCC recv PID bitmap: %X\n", c->bck_fc.recv_bitmap); |
3599 | LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", | 3709 | LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", |
3600 | c->bck_fc.poll_task, c->bck_fc.poll_msg, c->bck_fc.ack_msg); | 3710 | c->bck_fc.poll_task, c->bck_fc.poll_msg, c->bck_fc.ack_msg); |