diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-18 11:43:09 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-18 11:43:09 +0100 |
commit | 965d792189fa54bc9423f643cd8dccb681632b41 (patch) | |
tree | 7a7b72c753deaf7adc20951a046b4cde9c5e69d5 /src/cadet/gnunet-service-cadet_connection.c | |
parent | a1bd2dcc29c126023dbd1ddf83d7514859d1775b (diff) | |
download | gnunet-965d792189fa54bc9423f643cd8dccb681632b41.tar.gz gnunet-965d792189fa54bc9423f643cd8dccb681632b41.zip |
introduce CadetEncryptedMessageIdentifier instead of over-using uint32_t
Diffstat (limited to 'src/cadet/gnunet-service-cadet_connection.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 291 |
1 files changed, 193 insertions, 98 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index 351bf2d3c..4eed0ec1c 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: |
@@ -135,12 +135,12 @@ struct CadetFlowControl | |||
135 | * Last ACK sent to the peer (peer is not allowed to send | 135 | * Last ACK sent to the peer (peer is not allowed to send |
136 | * messages with PIDs higher than this value). | 136 | * messages with PIDs higher than this value). |
137 | */ | 137 | */ |
138 | uint32_t last_ack_sent; | 138 | struct CadetEncryptedMessageIdentifier last_ack_sent; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Last ACK sent towards the origin (for traffic towards leaf node). | 141 | * Last ACK sent towards the origin (for traffic towards leaf node). |
142 | */ | 142 | */ |
143 | uint32_t last_ack_recv; | 143 | struct CadetEncryptedMessageIdentifier last_ack_recv; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * 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. |
@@ -359,7 +359,8 @@ static void | |||
359 | fc_debug (struct CadetFlowControl *fc) | 359 | fc_debug (struct CadetFlowControl *fc) |
360 | { | 360 | { |
361 | LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n", | 361 | LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n", |
362 | fc->last_pid_recv, fc->last_ack_sent); | 362 | ntohl (fc->last_pid_recv.pid), |
363 | ntohl (fc->last_ack_sent.pid)); | ||
363 | LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n", | 364 | LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n", |
364 | fc->last_pid_sent, fc->last_ack_recv); | 365 | fc->last_pid_sent, fc->last_ack_recv); |
365 | LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n", | 366 | LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n", |
@@ -453,11 +454,11 @@ GCC_state2s (enum CadetConnectionState s) | |||
453 | static void | 454 | static void |
454 | fc_init (struct CadetFlowControl *fc) | 455 | fc_init (struct CadetFlowControl *fc) |
455 | { | 456 | { |
456 | fc->next_pid = (uint32_t) 0; | 457 | fc->next_pid.pid = 0; |
457 | fc->last_pid_sent = (uint32_t) -1; | 458 | fc->last_pid_sent.pid = htonl (UINT32_MAX); |
458 | fc->last_pid_recv = (uint32_t) -1; | 459 | fc->last_pid_recv.pid = htonl (UINT32_MAX); |
459 | fc->last_ack_sent = (uint32_t) 0; | 460 | fc->last_ack_sent.pid = (uint32_t) 0; |
460 | fc->last_ack_recv = (uint32_t) 0; | 461 | fc->last_ack_recv.pid = (uint32_t) 0; |
461 | fc->poll_task = NULL; | 462 | fc->poll_task = NULL; |
462 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; | 463 | fc->poll_time = GNUNET_TIME_UNIT_SECONDS; |
463 | fc->queue_n = 0; | 464 | fc->queue_n = 0; |
@@ -547,10 +548,11 @@ send_ack (struct CadetConnection *c, | |||
547 | int fwd, | 548 | int fwd, |
548 | int force) | 549 | int force) |
549 | { | 550 | { |
551 | static struct CadetEncryptedMessageIdentifier zero; | ||
550 | struct CadetFlowControl *next_fc; | 552 | struct CadetFlowControl *next_fc; |
551 | struct CadetFlowControl *prev_fc; | 553 | struct CadetFlowControl *prev_fc; |
552 | struct GNUNET_CADET_ConnectionEncryptedAckMessage msg; | 554 | struct GNUNET_CADET_ConnectionEncryptedAckMessage msg; |
553 | uint32_t ack; | 555 | struct CadetEncryptedMessageIdentifier ack_cemi; |
554 | int delta; | 556 | int delta; |
555 | 557 | ||
556 | GCC_check_connections (); | 558 | GCC_check_connections (); |
@@ -563,24 +565,28 @@ send_ack (struct CadetConnection *c, | |||
563 | GC_f2s (fwd), GCC_2s (c)); | 565 | GC_f2s (fwd), GCC_2s (c)); |
564 | 566 | ||
565 | /* Check if we need to transmit the ACK. */ | 567 | /* Check if we need to transmit the ACK. */ |
566 | 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); |
567 | if (3 < delta && buffer < delta && GNUNET_NO == force) | 569 | if (3 < delta && buffer < delta && GNUNET_NO == force) |
568 | { | 570 | { |
569 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, delta > 3\n"); | 571 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, delta > 3\n"); |
570 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 572 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
571 | " last pid recv: %u, last ack sent: %u\n", | 573 | " last pid recv: %u, last ack sent: %u\n", |
572 | 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)); | ||
573 | GCC_check_connections (); | 576 | GCC_check_connections (); |
574 | return; | 577 | return; |
575 | } | 578 | } |
576 | 579 | ||
577 | /* Ok, ACK might be necessary, what PID to ACK? */ | 580 | /* Ok, ACK might be necessary, what PID to ACK? */ |
578 | ack = prev_fc->last_pid_recv + buffer; | 581 | ack_cemi.pid = htonl (ntohl (prev_fc->last_pid_recv.pid) + buffer); |
579 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 582 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
580 | " 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", |
581 | 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), | ||
582 | next_fc->queue_max, next_fc->queue_n); | 587 | next_fc->queue_max, next_fc->queue_n); |
583 | 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) ) | ||
584 | { | 590 | { |
585 | 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"); |
586 | GCC_check_connections (); | 592 | GCC_check_connections (); |
@@ -590,7 +596,8 @@ send_ack (struct CadetConnection *c, | |||
590 | /* Check if message is already in queue */ | 596 | /* Check if message is already in queue */ |
591 | if (NULL != prev_fc->ack_msg) | 597 | if (NULL != prev_fc->ack_msg) |
592 | { | 598 | { |
593 | 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))) | ||
594 | { | 601 | { |
595 | LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); | 602 | LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); |
596 | GCC_cancel (prev_fc->ack_msg); | 603 | GCC_cancel (prev_fc->ack_msg); |
@@ -603,20 +610,22 @@ send_ack (struct CadetConnection *c, | |||
603 | return; | 610 | return; |
604 | } | 611 | } |
605 | } | 612 | } |
606 | GNUNET_break (GC_is_pid_bigger (ack, | 613 | GNUNET_break (GC_is_pid_bigger (ntohl (ack_cemi.pid), |
607 | prev_fc->last_ack_sent)); | 614 | ntohl (prev_fc->last_ack_sent.pid))); |
608 | prev_fc->last_ack_sent = ack; | 615 | prev_fc->last_ack_sent = ack_cemi; |
609 | 616 | ||
610 | /* Build ACK message and send on conn */ | 617 | /* Build ACK message and send on conn */ |
611 | msg.header.size = htons (sizeof (msg)); | 618 | msg.header.size = htons (sizeof (msg)); |
612 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED_HOP_BY_HOP_ACK); | 619 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED_HOP_BY_HOP_ACK); |
613 | msg.ack = htonl (ack); | 620 | msg.cemi = ack_cemi; |
614 | msg.cid = c->id; | 621 | msg.cid = c->id; |
615 | 622 | ||
616 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, | 623 | prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, |
617 | UINT16_MAX, | 624 | UINT16_MAX, |
618 | ack, | 625 | zero, |
619 | c, !fwd, GNUNET_YES, | 626 | c, |
627 | !fwd, | ||
628 | GNUNET_YES, | ||
620 | NULL, NULL); | 629 | NULL, NULL); |
621 | GNUNET_assert (NULL != prev_fc->ack_msg); | 630 | GNUNET_assert (NULL != prev_fc->ack_msg); |
622 | GCC_check_connections (); | 631 | GCC_check_connections (); |
@@ -680,8 +689,12 @@ update_perf (struct CadetConnection *c, | |||
680 | */ | 689 | */ |
681 | static void | 690 | static void |
682 | conn_message_sent (void *cls, | 691 | conn_message_sent (void *cls, |
683 | struct CadetConnection *c, int fwd, int sent, | 692 | struct CadetConnection *c, |
684 | 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, | ||
685 | size_t size, | 698 | size_t size, |
686 | struct GNUNET_TIME_Relative wait) | 699 | struct GNUNET_TIME_Relative wait) |
687 | { | 700 | { |
@@ -692,7 +705,10 @@ conn_message_sent (void *cls, | |||
692 | GCC_check_connections (); | 705 | GCC_check_connections (); |
693 | LOG (GNUNET_ERROR_TYPE_INFO, | 706 | LOG (GNUNET_ERROR_TYPE_INFO, |
694 | ">>> %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", |
695 | GC_m2s (type), GC_m2s (payload_type), pid, GCC_2s (c), c, | 708 | GC_m2s (type), GC_m2s (payload_type), |
709 | ntohl (pid.pid), | ||
710 | GCC_2s (c), | ||
711 | c, | ||
696 | GC_f2s (fwd), size, | 712 | GC_f2s (fwd), size, |
697 | GNUNET_STRINGS_relative_time_to_string (wait, GNUNET_YES)); | 713 | GNUNET_STRINGS_relative_time_to_string (wait, GNUNET_YES)); |
698 | 714 | ||
@@ -711,7 +727,8 @@ conn_message_sent (void *cls, | |||
711 | 727 | ||
712 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s pid %u\n", | 728 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s pid %u\n", |
713 | sent ? "" : "not ", GC_f2s (fwd), | 729 | sent ? "" : "not ", GC_f2s (fwd), |
714 | GC_m2s (type), GC_m2s (payload_type), pid); | 730 | GC_m2s (type), GC_m2s (payload_type), |
731 | ntohl (pid.pid)); | ||
715 | GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); | 732 | GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); |
716 | 733 | ||
717 | /* Update flow control info. */ | 734 | /* Update flow control info. */ |
@@ -761,7 +778,8 @@ conn_message_sent (void *cls, | |||
761 | if (GNUNET_YES == sent) | 778 | if (GNUNET_YES == sent) |
762 | { | 779 | { |
763 | fc->last_pid_sent = pid; | 780 | fc->last_pid_sent = pid; |
764 | 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)) ) | ||
765 | GCC_start_poll (c, fwd); | 783 | GCC_start_poll (c, fwd); |
766 | GCC_send_ack (c, fwd, GNUNET_NO); | 784 | GCC_send_ack (c, fwd, GNUNET_NO); |
767 | connection_reset_timeout (c, fwd); | 785 | connection_reset_timeout (c, fwd); |
@@ -772,14 +790,14 @@ conn_message_sent (void *cls, | |||
772 | { | 790 | { |
773 | fc->queue_n--; | 791 | fc->queue_n--; |
774 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 792 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
775 | "! accounting pid %u\n", | 793 | "! accounting pid %u\n", |
776 | fc->last_pid_sent); | 794 | ntohl (fc->last_pid_sent.pid)); |
777 | } | 795 | } |
778 | else | 796 | else |
779 | { | 797 | { |
780 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 798 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
781 | "! forced, Q_N not accounting pid %u\n", | 799 | "! forced, Q_N not accounting pid %u\n", |
782 | fc->last_pid_sent); | 800 | ntohl (fc->last_pid_sent.pid)); |
783 | } | 801 | } |
784 | break; | 802 | break; |
785 | 803 | ||
@@ -961,9 +979,11 @@ get_hop (struct CadetConnection *c, int fwd) | |||
961 | * @param ooo_pid PID of the out-of-order message. | 979 | * @param ooo_pid PID of the out-of-order message. |
962 | */ | 980 | */ |
963 | static uint32_t | 981 | static uint32_t |
964 | 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) | ||
965 | { | 984 | { |
966 | 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)); | ||
967 | } | 987 | } |
968 | 988 | ||
969 | 989 | ||
@@ -975,14 +995,18 @@ get_recv_bitmask (uint32_t last_pid_recv, uint32_t ooo_pid) | |||
975 | * @param last_pid_recv Last in-order PID received. | 995 | * @param last_pid_recv Last in-order PID received. |
976 | */ | 996 | */ |
977 | static int | 997 | static int |
978 | 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) | ||
979 | { | 1001 | { |
980 | uint32_t mask; | 1002 | uint32_t mask; |
981 | 1003 | ||
982 | 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))) | ||
983 | return GNUNET_NO; | 1006 | return GNUNET_NO; |
984 | 1007 | ||
985 | mask = get_recv_bitmask (last_pid_recv, ooo_pid); | 1008 | mask = get_recv_bitmask (last_pid_recv, |
1009 | ooo_pid); | ||
986 | if (0 != (ooo_bitmap & mask)) | 1010 | if (0 != (ooo_bitmap & mask)) |
987 | return GNUNET_NO; | 1011 | return GNUNET_NO; |
988 | 1012 | ||
@@ -1029,6 +1053,7 @@ is_fwd (const struct CadetConnection *c, | |||
1029 | static void | 1053 | static void |
1030 | send_connection_ack (struct CadetConnection *c, int fwd) | 1054 | send_connection_ack (struct CadetConnection *c, int fwd) |
1031 | { | 1055 | { |
1056 | static struct CadetEncryptedMessageIdentifier zero; | ||
1032 | struct GNUNET_CADET_ConnectionCreateMessageAckMessage msg; | 1057 | struct GNUNET_CADET_ConnectionCreateMessageAckMessage msg; |
1033 | struct CadetTunnel *t; | 1058 | struct CadetTunnel *t; |
1034 | const uint16_t size = sizeof (struct GNUNET_CADET_ConnectionCreateMessageAckMessage); | 1059 | const uint16_t size = sizeof (struct GNUNET_CADET_ConnectionCreateMessageAckMessage); |
@@ -1046,9 +1071,12 @@ send_connection_ack (struct CadetConnection *c, int fwd) | |||
1046 | msg.cid = c->id; | 1071 | msg.cid = c->id; |
1047 | 1072 | ||
1048 | GNUNET_assert (NULL == c->maintenance_q); | 1073 | GNUNET_assert (NULL == c->maintenance_q); |
1049 | c->maintenance_q = GCP_send (get_hop (c, fwd), &msg.header, | 1074 | c->maintenance_q = GCP_send (get_hop (c, fwd), |
1050 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, 0, | 1075 | &msg.header, |
1051 | c, fwd, | 1076 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, |
1077 | zero, | ||
1078 | c, | ||
1079 | fwd, | ||
1052 | &conn_message_sent, NULL); | 1080 | &conn_message_sent, NULL); |
1053 | 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", |
1054 | c, c->pending_messages); | 1082 | c, c->pending_messages); |
@@ -1076,6 +1104,7 @@ send_broken (struct CadetConnection *c, | |||
1076 | const struct GNUNET_PeerIdentity *id2, | 1104 | const struct GNUNET_PeerIdentity *id2, |
1077 | int fwd) | 1105 | int fwd) |
1078 | { | 1106 | { |
1107 | static struct CadetEncryptedMessageIdentifier zero; | ||
1079 | struct GNUNET_CADET_ConnectionBrokenMessage msg; | 1108 | struct GNUNET_CADET_ConnectionBrokenMessage msg; |
1080 | 1109 | ||
1081 | GCC_check_connections (); | 1110 | GCC_check_connections (); |
@@ -1085,8 +1114,13 @@ send_broken (struct CadetConnection *c, | |||
1085 | msg.reserved = htonl (0); | 1114 | msg.reserved = htonl (0); |
1086 | msg.peer1 = *id1; | 1115 | msg.peer1 = *id1; |
1087 | msg.peer2 = *id2; | 1116 | msg.peer2 = *id2; |
1088 | (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, fwd, | 1117 | (void) GCC_send_prebuilt_message (&msg.header, |
1089 | GNUNET_YES, NULL, NULL); | 1118 | UINT16_MAX, |
1119 | zero, | ||
1120 | c, | ||
1121 | fwd, | ||
1122 | GNUNET_YES, | ||
1123 | NULL, NULL); | ||
1090 | GCC_check_connections (); | 1124 | GCC_check_connections (); |
1091 | } | 1125 | } |
1092 | 1126 | ||
@@ -1106,6 +1140,7 @@ send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *conne | |||
1106 | const struct GNUNET_PeerIdentity *id2, | 1140 | const struct GNUNET_PeerIdentity *id2, |
1107 | struct CadetPeer *neighbor) | 1141 | struct CadetPeer *neighbor) |
1108 | { | 1142 | { |
1143 | static struct CadetEncryptedMessageIdentifier zero; | ||
1109 | struct GNUNET_CADET_ConnectionBrokenMessage msg; | 1144 | struct GNUNET_CADET_ConnectionBrokenMessage msg; |
1110 | 1145 | ||
1111 | GCC_check_connections (); | 1146 | GCC_check_connections (); |
@@ -1121,9 +1156,12 @@ send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *conne | |||
1121 | msg.peer2 = *id2; | 1156 | msg.peer2 = *id2; |
1122 | else | 1157 | else |
1123 | memset (&msg.peer2, 0, sizeof (msg.peer2)); | 1158 | memset (&msg.peer2, 0, sizeof (msg.peer2)); |
1124 | GNUNET_assert (NULL != GCP_send (neighbor, &msg.header, | 1159 | GNUNET_assert (NULL != GCP_send (neighbor, |
1125 | UINT16_MAX, 2, | 1160 | &msg.header, |
1126 | NULL, GNUNET_SYSERR, /* connection, fwd */ | 1161 | UINT16_MAX, |
1162 | zero, | ||
1163 | NULL, | ||
1164 | GNUNET_SYSERR, /* connection, fwd */ | ||
1127 | NULL, NULL)); /* continuation */ | 1165 | NULL, NULL)); /* continuation */ |
1128 | GCC_check_connections (); | 1166 | GCC_check_connections (); |
1129 | } | 1167 | } |
@@ -1418,6 +1456,7 @@ connection_cancel_queues (struct CadetConnection *c, | |||
1418 | static void | 1456 | static void |
1419 | send_poll (void *cls) | 1457 | send_poll (void *cls) |
1420 | { | 1458 | { |
1459 | static struct CadetEncryptedMessageIdentifier zero; | ||
1421 | struct CadetFlowControl *fc = cls; | 1460 | struct CadetFlowControl *fc = cls; |
1422 | struct GNUNET_CADET_ConnectionHopByHopPollMessage msg; | 1461 | struct GNUNET_CADET_ConnectionHopByHopPollMessage msg; |
1423 | struct CadetConnection *c; | 1462 | struct CadetConnection *c; |
@@ -1433,11 +1472,17 @@ send_poll (void *cls) | |||
1433 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_POLL); | 1472 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_POLL); |
1434 | msg.header.size = htons (sizeof (msg)); | 1473 | msg.header.size = htons (sizeof (msg)); |
1435 | msg.cid = c->id; | 1474 | msg.cid = c->id; |
1436 | msg.pid = htonl (fc->last_pid_sent); | 1475 | msg.cemi = fc->last_pid_sent; |
1437 | 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)); |
1438 | fc->poll_msg = | 1477 | fc->poll_msg |
1439 | GCC_send_prebuilt_message (&msg.header, UINT16_MAX, fc->last_pid_sent, c, | 1478 | = GCC_send_prebuilt_message (&msg.header, |
1440 | 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); | ||
1441 | GNUNET_assert (NULL != fc->poll_msg); | 1486 | GNUNET_assert (NULL != fc->poll_msg); |
1442 | GCC_check_connections (); | 1487 | GCC_check_connections (); |
1443 | } | 1488 | } |
@@ -1879,6 +1924,7 @@ void | |||
1879 | GCC_handle_create (struct CadetPeer *peer, | 1924 | GCC_handle_create (struct CadetPeer *peer, |
1880 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) | 1925 | const struct GNUNET_CADET_ConnectionCreateMessage *msg) |
1881 | { | 1926 | { |
1927 | static struct CadetEncryptedMessageIdentifier zero; | ||
1882 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid; | 1928 | const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid; |
1883 | struct GNUNET_PeerIdentity *id; | 1929 | struct GNUNET_PeerIdentity *id; |
1884 | struct CadetPeerPath *path; | 1930 | struct CadetPeerPath *path; |
@@ -2001,8 +2047,12 @@ GCC_handle_create (struct CadetPeer *peer, | |||
2001 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2047 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2002 | GCP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); | 2048 | GCP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); |
2003 | 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); |
2004 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, | 2050 | (void) GCC_send_prebuilt_message (&msg->header, |
2005 | GNUNET_YES, GNUNET_YES, NULL, NULL); | 2051 | 0, |
2052 | zero, | ||
2053 | c, | ||
2054 | GNUNET_YES, GNUNET_YES, | ||
2055 | NULL, NULL); | ||
2006 | } | 2056 | } |
2007 | path_destroy (path); | 2057 | path_destroy (path); |
2008 | GCC_check_connections (); | 2058 | GCC_check_connections (); |
@@ -2019,6 +2069,7 @@ void | |||
2019 | GCC_handle_confirm (struct CadetPeer *peer, | 2069 | GCC_handle_confirm (struct CadetPeer *peer, |
2020 | const struct GNUNET_CADET_ConnectionCreateMessageAckMessage *msg) | 2070 | const struct GNUNET_CADET_ConnectionCreateMessageAckMessage *msg) |
2021 | { | 2071 | { |
2072 | static struct CadetEncryptedMessageIdentifier zero; | ||
2022 | struct CadetConnection *c; | 2073 | struct CadetConnection *c; |
2023 | enum CadetConnectionState oldstate; | 2074 | enum CadetConnectionState oldstate; |
2024 | int fwd; | 2075 | int fwd; |
@@ -2126,7 +2177,10 @@ GCC_handle_confirm (struct CadetPeer *peer, | |||
2126 | else | 2177 | else |
2127 | { | 2178 | { |
2128 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2179 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2129 | (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, | ||
2130 | GNUNET_YES, NULL, NULL); | 2184 | GNUNET_YES, NULL, NULL); |
2131 | } | 2185 | } |
2132 | GCC_check_connections (); | 2186 | GCC_check_connections (); |
@@ -2143,6 +2197,7 @@ void | |||
2143 | GCC_handle_broken (struct CadetPeer *peer, | 2197 | GCC_handle_broken (struct CadetPeer *peer, |
2144 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) | 2198 | const struct GNUNET_CADET_ConnectionBrokenMessage *msg) |
2145 | { | 2199 | { |
2200 | static struct CadetEncryptedMessageIdentifier zero; | ||
2146 | struct CadetConnection *c; | 2201 | struct CadetConnection *c; |
2147 | struct CadetTunnel *t; | 2202 | struct CadetTunnel *t; |
2148 | int fwd; | 2203 | int fwd; |
@@ -2195,7 +2250,8 @@ GCC_handle_broken (struct CadetPeer *peer, | |||
2195 | } | 2250 | } |
2196 | else | 2251 | else |
2197 | { | 2252 | { |
2198 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2253 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2254 | zero, c, fwd, | ||
2199 | GNUNET_YES, NULL, NULL); | 2255 | GNUNET_YES, NULL, NULL); |
2200 | connection_cancel_queues (c, !fwd); | 2256 | connection_cancel_queues (c, !fwd); |
2201 | } | 2257 | } |
@@ -2214,6 +2270,7 @@ void | |||
2214 | GCC_handle_destroy (struct CadetPeer *peer, | 2270 | GCC_handle_destroy (struct CadetPeer *peer, |
2215 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) | 2271 | const struct GNUNET_CADET_ConnectionDestroyMessage *msg) |
2216 | { | 2272 | { |
2273 | static struct CadetEncryptedMessageIdentifier zero; | ||
2217 | struct CadetConnection *c; | 2274 | struct CadetConnection *c; |
2218 | int fwd; | 2275 | int fwd; |
2219 | 2276 | ||
@@ -2245,7 +2302,8 @@ GCC_handle_destroy (struct CadetPeer *peer, | |||
2245 | 2302 | ||
2246 | if (GNUNET_NO == GCC_is_terminal (c, fwd)) | 2303 | if (GNUNET_NO == GCC_is_terminal (c, fwd)) |
2247 | { | 2304 | { |
2248 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2305 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2306 | zero, c, fwd, | ||
2249 | GNUNET_YES, NULL, NULL); | 2307 | GNUNET_YES, NULL, NULL); |
2250 | } | 2308 | } |
2251 | else if (0 == c->pending_messages) | 2309 | else if (0 == c->pending_messages) |
@@ -2278,7 +2336,7 @@ GCC_handle_ack (struct CadetPeer *peer, | |||
2278 | { | 2336 | { |
2279 | struct CadetConnection *c; | 2337 | struct CadetConnection *c; |
2280 | struct CadetFlowControl *fc; | 2338 | struct CadetFlowControl *fc; |
2281 | uint32_t ack; | 2339 | struct CadetEncryptedMessageIdentifier ack; |
2282 | int fwd; | 2340 | int fwd; |
2283 | 2341 | ||
2284 | GCC_check_connections (); | 2342 | GCC_check_connections (); |
@@ -2315,15 +2373,19 @@ GCC_handle_ack (struct CadetPeer *peer, | |||
2315 | return; | 2373 | return; |
2316 | } | 2374 | } |
2317 | 2375 | ||
2318 | ack = ntohl (msg->ack); | 2376 | ack = msg->cemi; |
2319 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", | 2377 | LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", |
2320 | GC_f2s (fwd), ack, fc->last_ack_recv); | 2378 | GC_f2s (fwd), |
2321 | 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))) | ||
2322 | fc->last_ack_recv = ack; | 2383 | fc->last_ack_recv = ack; |
2323 | 2384 | ||
2324 | /* Cancel polling if the ACK is big enough. */ | 2385 | /* Cancel polling if the ACK is big enough. */ |
2325 | if ( (NULL != fc->poll_task) & | 2386 | if ( (NULL != fc->poll_task) & |
2326 | 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))) | ||
2327 | { | 2389 | { |
2328 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); | 2390 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); |
2329 | GNUNET_SCHEDULER_cancel (fc->poll_task); | 2391 | GNUNET_SCHEDULER_cancel (fc->poll_task); |
@@ -2347,7 +2409,7 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2347 | { | 2409 | { |
2348 | struct CadetConnection *c; | 2410 | struct CadetConnection *c; |
2349 | struct CadetFlowControl *fc; | 2411 | struct CadetFlowControl *fc; |
2350 | uint32_t pid; | 2412 | struct CadetEncryptedMessageIdentifier pid; |
2351 | int fwd; | 2413 | int fwd; |
2352 | 2414 | ||
2353 | GCC_check_connections (); | 2415 | GCC_check_connections (); |
@@ -2389,8 +2451,11 @@ GCC_handle_poll (struct CadetPeer *peer, | |||
2389 | return; | 2451 | return; |
2390 | } | 2452 | } |
2391 | 2453 | ||
2392 | pid = ntohl (msg->pid); | 2454 | pid = msg->cemi; |
2393 | 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)); | ||
2394 | fc->last_pid_recv = pid; | 2459 | fc->last_pid_recv = pid; |
2395 | fwd = fc == &c->bck_fc; | 2460 | fwd = fc == &c->bck_fc; |
2396 | GCC_send_ack (c, fwd, GNUNET_YES); | 2461 | GCC_send_ack (c, fwd, GNUNET_YES); |
@@ -2417,7 +2482,7 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2417 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid, | 2482 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid, |
2418 | struct CadetConnection *c, | 2483 | struct CadetConnection *c, |
2419 | struct CadetPeer *sender, | 2484 | struct CadetPeer *sender, |
2420 | uint32_t pid) | 2485 | struct CadetEncryptedMessageIdentifier pid) |
2421 | { | 2486 | { |
2422 | struct CadetFlowControl *fc; | 2487 | struct CadetFlowControl *fc; |
2423 | struct CadetPeer *hop; | 2488 | struct CadetPeer *hop; |
@@ -2470,10 +2535,11 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2470 | { | 2535 | { |
2471 | fc = fwd ? &c->bck_fc : &c->fwd_fc; | 2536 | fc = fwd ? &c->bck_fc : &c->fwd_fc; |
2472 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected in interval [%u,%u])\n", | 2537 | LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected in interval [%u,%u])\n", |
2473 | pid, | 2538 | ntohl (pid.pid), |
2474 | fc->last_pid_recv + 1, | 2539 | ntohl (fc->last_pid_recv.pid) + 1, |
2475 | fc->last_ack_sent); | 2540 | ntohl (fc->last_ack_sent.pid)); |
2476 | if (GC_is_pid_bigger (pid, fc->last_ack_sent)) | 2541 | if (GC_is_pid_bigger (ntohl (pid.pid), |
2542 | ntohl (fc->last_ack_sent.pid))) | ||
2477 | { | 2543 | { |
2478 | GNUNET_STATISTICS_update (stats, | 2544 | GNUNET_STATISTICS_update (stats, |
2479 | "# unsolicited message", | 2545 | "# unsolicited message", |
@@ -2484,11 +2550,12 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2484 | pid, fc->last_pid_recv, fc->last_ack_sent); | 2550 | pid, fc->last_pid_recv, fc->last_ack_sent); |
2485 | return GNUNET_SYSERR; | 2551 | return GNUNET_SYSERR; |
2486 | } | 2552 | } |
2487 | 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))) | ||
2488 | { | 2555 | { |
2489 | unsigned int delta; | 2556 | unsigned int delta; |
2490 | 2557 | ||
2491 | delta = pid - fc->last_pid_recv; | 2558 | delta = ntohl (pid.pid) - ntohl (fc->last_pid_recv.pid); |
2492 | fc->last_pid_recv = pid; | 2559 | fc->last_pid_recv = pid; |
2493 | fc->recv_bitmap <<= delta; | 2560 | fc->recv_bitmap <<= delta; |
2494 | fc->recv_bitmap |= 1; | 2561 | fc->recv_bitmap |= 1; |
@@ -2505,10 +2572,12 @@ check_message (const struct GNUNET_MessageHeader *message, | |||
2505 | { | 2572 | { |
2506 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2573 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2507 | "PID %u unexpected (%u+), dropping!\n", | 2574 | "PID %u unexpected (%u+), dropping!\n", |
2508 | pid, fc->last_pid_recv - 31); | 2575 | ntohl (pid.pid), |
2576 | ntohl (fc->last_pid_recv.pid) - 31); | ||
2509 | return GNUNET_SYSERR; | 2577 | return GNUNET_SYSERR; |
2510 | } | 2578 | } |
2511 | fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, pid); | 2579 | fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, |
2580 | pid); | ||
2512 | } | 2581 | } |
2513 | } | 2582 | } |
2514 | 2583 | ||
@@ -2539,6 +2608,7 @@ void | |||
2539 | GCC_handle_kx (struct CadetPeer *peer, | 2608 | GCC_handle_kx (struct CadetPeer *peer, |
2540 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) | 2609 | const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) |
2541 | { | 2610 | { |
2611 | static struct CadetEncryptedMessageIdentifier zero; | ||
2542 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; | 2612 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; |
2543 | struct CadetConnection *c; | 2613 | struct CadetConnection *c; |
2544 | int fwd; | 2614 | int fwd; |
@@ -2552,7 +2622,7 @@ GCC_handle_kx (struct CadetPeer *peer, | |||
2552 | cid, | 2622 | cid, |
2553 | c, | 2623 | c, |
2554 | peer, | 2624 | peer, |
2555 | 0); | 2625 | zero); |
2556 | 2626 | ||
2557 | /* If something went wrong, discard message. */ | 2627 | /* If something went wrong, discard message. */ |
2558 | if (GNUNET_SYSERR == fwd) | 2628 | if (GNUNET_SYSERR == fwd) |
@@ -2580,7 +2650,8 @@ GCC_handle_kx (struct CadetPeer *peer, | |||
2580 | /* Message not for us: forward to next hop */ | 2650 | /* Message not for us: forward to next hop */ |
2581 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2651 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2582 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); | 2652 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); |
2583 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2653 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2654 | zero, c, fwd, | ||
2584 | GNUNET_NO, NULL, NULL); | 2655 | GNUNET_NO, NULL, NULL); |
2585 | GCC_check_connections (); | 2656 | GCC_check_connections (); |
2586 | } | 2657 | } |
@@ -2596,14 +2667,15 @@ void | |||
2596 | GCC_handle_encrypted (struct CadetPeer *peer, | 2667 | GCC_handle_encrypted (struct CadetPeer *peer, |
2597 | const struct GNUNET_CADET_ConnectionEncryptedMessage *msg) | 2668 | const struct GNUNET_CADET_ConnectionEncryptedMessage *msg) |
2598 | { | 2669 | { |
2670 | static struct CadetEncryptedMessageIdentifier zero; | ||
2599 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; | 2671 | const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; |
2600 | struct CadetConnection *c; | 2672 | struct CadetConnection *c; |
2601 | uint32_t pid; | 2673 | struct CadetEncryptedMessageIdentifier pid; |
2602 | int fwd; | 2674 | int fwd; |
2603 | 2675 | ||
2604 | GCC_check_connections (); | 2676 | GCC_check_connections (); |
2605 | cid = &msg->cid; | 2677 | cid = &msg->cid; |
2606 | pid = ntohl (msg->pid); | 2678 | pid = msg->cemi; |
2607 | log_message (&msg->header, peer, cid); | 2679 | log_message (&msg->header, peer, cid); |
2608 | 2680 | ||
2609 | c = connection_get (cid); | 2681 | c = connection_get (cid); |
@@ -2639,7 +2711,8 @@ GCC_handle_encrypted (struct CadetPeer *peer, | |||
2639 | /* Message not for us: forward to next hop */ | 2711 | /* Message not for us: forward to next hop */ |
2640 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); | 2712 | LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); |
2641 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); | 2713 | GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); |
2642 | (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, | 2714 | (void) GCC_send_prebuilt_message (&msg->header, 0, |
2715 | zero, c, fwd, | ||
2643 | GNUNET_NO, NULL, NULL); | 2716 | GNUNET_NO, NULL, NULL); |
2644 | GCC_check_connections (); | 2717 | GCC_check_connections (); |
2645 | } | 2718 | } |
@@ -2966,12 +3039,12 @@ GCC_get_allowed (struct CadetConnection *c, int fwd) | |||
2966 | 3039 | ||
2967 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3040 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
2968 | if ( (CADET_CONNECTION_READY != c->state) || | 3041 | if ( (CADET_CONNECTION_READY != c->state) || |
2969 | GC_is_pid_bigger (fc->last_pid_recv, | 3042 | GC_is_pid_bigger (ntohl (fc->last_pid_recv.pid), |
2970 | fc->last_ack_sent) ) | 3043 | ntohl (fc->last_ack_sent.pid)) ) |
2971 | { | 3044 | { |
2972 | return 0; | 3045 | return 0; |
2973 | } | 3046 | } |
2974 | return (fc->last_ack_sent - fc->last_pid_recv); | 3047 | return (ntohl (fc->last_ack_sent.pid) - ntohl (fc->last_pid_recv.pid)); |
2975 | } | 3048 | } |
2976 | 3049 | ||
2977 | 3050 | ||
@@ -2999,18 +3072,17 @@ GCC_get_qn (struct CadetConnection *c, int fwd) | |||
2999 | * | 3072 | * |
3000 | * @param c Connection. | 3073 | * @param c Connection. |
3001 | * @param fwd Is query about FWD traffic? | 3074 | * @param fwd Is query about FWD traffic? |
3002 | * | ||
3003 | * @return Next PID to use. | 3075 | * @return Next PID to use. |
3004 | */ | 3076 | */ |
3005 | uint32_t | 3077 | struct CadetEncryptedMessageIdentifier |
3006 | GCC_get_pid (struct CadetConnection *c, int fwd) | 3078 | GCC_get_pid (struct CadetConnection *c, int fwd) |
3007 | { | 3079 | { |
3008 | struct CadetFlowControl *fc; | 3080 | struct CadetFlowControl *fc; |
3009 | uint32_t pid; | 3081 | struct CadetEncryptedMessageIdentifier pid; |
3010 | 3082 | ||
3011 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3083 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3012 | pid = fc->next_pid; | 3084 | pid = fc->next_pid; |
3013 | fc->next_pid++; | 3085 | fc->next_pid.pid = htonl (1 + ntohl (pid.pid)); |
3014 | return pid; | 3086 | return pid; |
3015 | } | 3087 | } |
3016 | 3088 | ||
@@ -3155,8 +3227,10 @@ GCC_is_sendable (struct CadetConnection *c, int fwd) | |||
3155 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3227 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3156 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3228 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3157 | " last ack recv: %u, last pid sent: %u\n", | 3229 | " last ack recv: %u, last pid sent: %u\n", |
3158 | fc->last_ack_recv, fc->last_pid_sent); | 3230 | ntohl (fc->last_ack_recv.pid), |
3159 | 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))) | ||
3160 | { | 3234 | { |
3161 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); | 3235 | LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); |
3162 | return GNUNET_YES; | 3236 | return GNUNET_YES; |
@@ -3201,7 +3275,8 @@ GCC_is_direct (struct CadetConnection *c) | |||
3201 | */ | 3275 | */ |
3202 | struct CadetConnectionQueue * | 3276 | struct CadetConnectionQueue * |
3203 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | 3277 | GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, |
3204 | uint16_t payload_type, uint32_t payload_id, | 3278 | uint16_t payload_type, |
3279 | struct CadetEncryptedMessageIdentifier payload_id, | ||
3205 | struct CadetConnection *c, int fwd, int force, | 3280 | struct CadetConnection *c, int fwd, int force, |
3206 | GCC_sent cont, void *cont_cls) | 3281 | GCC_sent cont, void *cont_cls) |
3207 | { | 3282 | { |
@@ -3229,7 +3304,10 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3229 | { | 3304 | { |
3230 | case GNUNET_MESSAGE_TYPE_CONNECTION_ENCRYPTED: | 3305 | case GNUNET_MESSAGE_TYPE_CONNECTION_ENCRYPTED: |
3231 | 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", |
3232 | 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)); | ||
3233 | if (GNUNET_NO == force) | 3311 | if (GNUNET_NO == force) |
3234 | { | 3312 | { |
3235 | fc->queue_n++; | 3313 | fc->queue_n++; |
@@ -3281,9 +3359,12 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3281 | q->cont_cls = cont_cls; | 3359 | q->cont_cls = cont_cls; |
3282 | q->forced = force; | 3360 | q->forced = force; |
3283 | GNUNET_CONTAINER_DLL_insert (fc->q_head, fc->q_tail, q); | 3361 | GNUNET_CONTAINER_DLL_insert (fc->q_head, fc->q_tail, q); |
3284 | q->peer_q = GCP_send (get_hop (c, fwd), message, | 3362 | q->peer_q = GCP_send (get_hop (c, fwd), |
3285 | payload_type, payload_id, | 3363 | message, |
3286 | c, fwd, | 3364 | payload_type, |
3365 | payload_id, | ||
3366 | c, | ||
3367 | fwd, | ||
3287 | &conn_message_sent, q); | 3368 | &conn_message_sent, q); |
3288 | if (NULL == q->peer_q) | 3369 | if (NULL == q->peer_q) |
3289 | { | 3370 | { |
@@ -3327,6 +3408,7 @@ GCC_cancel (struct CadetConnectionQueue *q) | |||
3327 | void | 3408 | void |
3328 | GCC_send_create (struct CadetConnection *c) | 3409 | GCC_send_create (struct CadetConnection *c) |
3329 | { | 3410 | { |
3411 | static struct CadetEncryptedMessageIdentifier zero; | ||
3330 | enum CadetTunnelCState state; | 3412 | enum CadetTunnelCState state; |
3331 | size_t size; | 3413 | size_t size; |
3332 | 3414 | ||
@@ -3339,6 +3421,7 @@ GCC_send_create (struct CadetConnection *c) | |||
3339 | struct GNUNET_CADET_ConnectionCreateMessage *msg; | 3421 | struct GNUNET_CADET_ConnectionCreateMessage *msg; |
3340 | struct GNUNET_PeerIdentity *peers; | 3422 | struct GNUNET_PeerIdentity *peers; |
3341 | 3423 | ||
3424 | |||
3342 | msg = (struct GNUNET_CADET_ConnectionCreateMessage *) cbuf; | 3425 | msg = (struct GNUNET_CADET_ConnectionCreateMessage *) cbuf; |
3343 | msg->header.size = htons (size); | 3426 | msg->header.size = htons (size); |
3344 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); | 3427 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); |
@@ -3352,7 +3435,8 @@ GCC_send_create (struct CadetConnection *c) | |||
3352 | GNUNET_assert (NULL == c->maintenance_q); | 3435 | GNUNET_assert (NULL == c->maintenance_q); |
3353 | c->maintenance_q = GCP_send (get_next_hop (c), | 3436 | c->maintenance_q = GCP_send (get_next_hop (c), |
3354 | &msg->header, | 3437 | &msg->header, |
3355 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 0, | 3438 | GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, |
3439 | zero, | ||
3356 | c, GNUNET_YES, | 3440 | c, GNUNET_YES, |
3357 | &conn_message_sent, NULL); | 3441 | &conn_message_sent, NULL); |
3358 | } | 3442 | } |
@@ -3449,6 +3533,7 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force) | |||
3449 | void | 3533 | void |
3450 | GCC_send_destroy (struct CadetConnection *c) | 3534 | GCC_send_destroy (struct CadetConnection *c) |
3451 | { | 3535 | { |
3536 | static struct CadetEncryptedMessageIdentifier zero; | ||
3452 | struct GNUNET_CADET_ConnectionDestroyMessage msg; | 3537 | struct GNUNET_CADET_ConnectionDestroyMessage msg; |
3453 | 3538 | ||
3454 | if (GNUNET_YES == c->destroy) | 3539 | if (GNUNET_YES == c->destroy) |
@@ -3463,10 +3548,16 @@ GCC_send_destroy (struct CadetConnection *c) | |||
3463 | GCC_2s (c)); | 3548 | GCC_2s (c)); |
3464 | 3549 | ||
3465 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_YES)) | 3550 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_YES)) |
3466 | (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, | ||
3467 | GNUNET_YES, GNUNET_YES, NULL, NULL); | 3555 | GNUNET_YES, GNUNET_YES, NULL, NULL); |
3468 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_NO)) | 3556 | if (GNUNET_NO == GCC_is_terminal (c, GNUNET_NO)) |
3469 | (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, | ||
3470 | GNUNET_NO, GNUNET_YES, NULL, NULL); | 3561 | GNUNET_NO, GNUNET_YES, NULL, NULL); |
3471 | mark_destroyed (c); | 3562 | mark_destroyed (c); |
3472 | GCC_check_connections (); | 3563 | GCC_check_connections (); |
@@ -3597,9 +3688,11 @@ GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level) | |||
3597 | LOG2 (level, "CCC FWD flow control:\n"); | 3688 | LOG2 (level, "CCC FWD flow control:\n"); |
3598 | 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); |
3599 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", | 3690 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", |
3600 | 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)); | ||
3601 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", | 3693 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", |
3602 | 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)); | ||
3603 | 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); |
3604 | 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", |
3605 | 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); |
@@ -3607,9 +3700,11 @@ GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level) | |||
3607 | LOG2 (level, "CCC BCK flow control:\n"); | 3700 | LOG2 (level, "CCC BCK flow control:\n"); |
3608 | 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); |
3609 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", | 3702 | LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", |
3610 | 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)); | ||
3611 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", | 3705 | LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", |
3612 | 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)); | ||
3613 | 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); |
3614 | 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", |
3615 | 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); |