From: Christian Grothoff Date: Wed, 18 Jan 2017 10:43:09 +0000 (+0100) Subject: introduce CadetEncryptedMessageIdentifier instead of over-using uint32_t X-Git-Tag: taler-0.2.1~416 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=965d792189fa54bc9423f643cd8dccb681632b41;p=oweals%2Fgnunet.git introduce CadetEncryptedMessageIdentifier instead of over-using uint32_t --- diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h index c45c4c684..2a0de2a8f 100644 --- a/src/cadet/cadet_protocol.h +++ b/src/cadet/cadet_protocol.h @@ -161,6 +161,23 @@ struct GNUNET_CADET_ConnectionDestroyMessage }; +/** + * Unique identifier (counter) for an encrypted message in a channel. + * Used to match #GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED_HOP_BY_HOP_ACK + * and #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_POLL messages + * against the respective #GNUNET_MESSAGE_TYPE_CONNECTION_ENCRYPTED + * messages. + */ +struct CadetEncryptedMessageIdentifier +{ + /** + * This number is incremented by one per message. It may wrap around. + * In network byte order. + */ + uint32_t pid GNUNET_PACKED; +}; + + /** * Message to acknowledge cadet encrypted traffic. */ @@ -174,7 +191,7 @@ struct GNUNET_CADET_ConnectionEncryptedAckMessage /** * Maximum packet ID authorized. */ - uint32_t ack GNUNET_PACKED; + struct CadetEncryptedMessageIdentifier cemi; /** * ID of the connection. @@ -196,7 +213,7 @@ struct GNUNET_CADET_ConnectionHopByHopPollMessage /** * Last packet sent. */ - uint32_t pid GNUNET_PACKED; + struct CadetEncryptedMessageIdentifier cemi; /** * ID of the connection. @@ -278,7 +295,7 @@ struct GNUNET_CADET_ConnectionEncryptedMessage /** * ID of the packet (hop by hop). */ - uint32_t pid GNUNET_PACKED; + struct CadetEncryptedMessageIdentifier cemi; /** * ID of the connection. @@ -404,7 +421,7 @@ struct GNUNET_CADET_ChannelDataMessage struct GNUNET_CADET_ChannelDataAckMessage { /** - * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DATA_ACK + * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DATA_ACK */ struct GNUNET_MessageHeader header; 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 /** * ID of the next packet to send. */ - uint32_t next_pid; + struct CadetEncryptedMessageIdentifier next_pid; /** * ID of the last packet sent towards the peer. */ - uint32_t last_pid_sent; + struct CadetEncryptedMessageIdentifier last_pid_sent; /** * ID of the last packet received from the peer. */ - uint32_t last_pid_recv; + struct CadetEncryptedMessageIdentifier last_pid_recv; /** * Bitmap of past 32 messages received: @@ -135,12 +135,12 @@ struct CadetFlowControl * Last ACK sent to the peer (peer is not allowed to send * messages with PIDs higher than this value). */ - uint32_t last_ack_sent; + struct CadetEncryptedMessageIdentifier last_ack_sent; /** * Last ACK sent towards the origin (for traffic towards leaf node). */ - uint32_t last_ack_recv; + struct CadetEncryptedMessageIdentifier last_ack_recv; /** * Task to poll the peer in case of a lost ACK causes stall. @@ -359,7 +359,8 @@ static void fc_debug (struct CadetFlowControl *fc) { LOG (GNUNET_ERROR_TYPE_DEBUG, " IN: %u/%u\n", - fc->last_pid_recv, fc->last_ack_sent); + ntohl (fc->last_pid_recv.pid), + ntohl (fc->last_ack_sent.pid)); LOG (GNUNET_ERROR_TYPE_DEBUG, " OUT: %u/%u\n", fc->last_pid_sent, fc->last_ack_recv); LOG (GNUNET_ERROR_TYPE_DEBUG, " QUEUE: %u/%u\n", @@ -453,11 +454,11 @@ GCC_state2s (enum CadetConnectionState s) static void fc_init (struct CadetFlowControl *fc) { - fc->next_pid = (uint32_t) 0; - fc->last_pid_sent = (uint32_t) -1; - fc->last_pid_recv = (uint32_t) -1; - fc->last_ack_sent = (uint32_t) 0; - fc->last_ack_recv = (uint32_t) 0; + fc->next_pid.pid = 0; + fc->last_pid_sent.pid = htonl (UINT32_MAX); + fc->last_pid_recv.pid = htonl (UINT32_MAX); + fc->last_ack_sent.pid = (uint32_t) 0; + fc->last_ack_recv.pid = (uint32_t) 0; fc->poll_task = NULL; fc->poll_time = GNUNET_TIME_UNIT_SECONDS; fc->queue_n = 0; @@ -547,10 +548,11 @@ send_ack (struct CadetConnection *c, int fwd, int force) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetFlowControl *next_fc; struct CadetFlowControl *prev_fc; struct GNUNET_CADET_ConnectionEncryptedAckMessage msg; - uint32_t ack; + struct CadetEncryptedMessageIdentifier ack_cemi; int delta; GCC_check_connections (); @@ -563,24 +565,28 @@ send_ack (struct CadetConnection *c, GC_f2s (fwd), GCC_2s (c)); /* Check if we need to transmit the ACK. */ - delta = prev_fc->last_ack_sent - prev_fc->last_pid_recv; + delta = ntohl (prev_fc->last_ack_sent.pid) - ntohl (prev_fc->last_pid_recv.pid); if (3 < delta && buffer < delta && GNUNET_NO == force) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, delta > 3\n"); LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid recv: %u, last ack sent: %u\n", - prev_fc->last_pid_recv, prev_fc->last_ack_sent); + ntohl (prev_fc->last_pid_recv.pid), + ntohl (prev_fc->last_ack_sent.pid)); GCC_check_connections (); return; } /* Ok, ACK might be necessary, what PID to ACK? */ - ack = prev_fc->last_pid_recv + buffer; + ack_cemi.pid = htonl (ntohl (prev_fc->last_pid_recv.pid) + buffer); LOG (GNUNET_ERROR_TYPE_DEBUG, " ACK %u, last PID %u, last ACK %u, qmax %u, q %u\n", - ack, prev_fc->last_pid_recv, prev_fc->last_ack_sent, + ntohl (ack_cemi.pid), + ntohl (prev_fc->last_pid_recv.pid), + ntohl (prev_fc->last_ack_sent.pid), next_fc->queue_max, next_fc->queue_n); - if (ack == prev_fc->last_ack_sent && GNUNET_NO == force) + if ( (ack_cemi.pid == prev_fc->last_ack_sent.pid) && + (GNUNET_NO == force) ) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, not needed\n"); GCC_check_connections (); @@ -590,7 +596,8 @@ send_ack (struct CadetConnection *c, /* Check if message is already in queue */ if (NULL != prev_fc->ack_msg) { - if (GC_is_pid_bigger (ack, prev_fc->last_ack_sent)) + if (GC_is_pid_bigger (ntohl (ack_cemi.pid), + ntohl (prev_fc->last_ack_sent.pid))) { LOG (GNUNET_ERROR_TYPE_DEBUG, " canceling old ACK\n"); GCC_cancel (prev_fc->ack_msg); @@ -603,20 +610,22 @@ send_ack (struct CadetConnection *c, return; } } - GNUNET_break (GC_is_pid_bigger (ack, - prev_fc->last_ack_sent)); - prev_fc->last_ack_sent = ack; + GNUNET_break (GC_is_pid_bigger (ntohl (ack_cemi.pid), + ntohl (prev_fc->last_ack_sent.pid))); + prev_fc->last_ack_sent = ack_cemi; /* Build ACK message and send on conn */ msg.header.size = htons (sizeof (msg)); msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED_HOP_BY_HOP_ACK); - msg.ack = htonl (ack); + msg.cemi = ack_cemi; msg.cid = c->id; prev_fc->ack_msg = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, - ack, - c, !fwd, GNUNET_YES, + zero, + c, + !fwd, + GNUNET_YES, NULL, NULL); GNUNET_assert (NULL != prev_fc->ack_msg); GCC_check_connections (); @@ -680,8 +689,12 @@ update_perf (struct CadetConnection *c, */ static void conn_message_sent (void *cls, - struct CadetConnection *c, int fwd, int sent, - uint16_t type, uint16_t payload_type, uint32_t pid, + struct CadetConnection *c, + int fwd, + int sent, + uint16_t type, + uint16_t payload_type, + struct CadetEncryptedMessageIdentifier pid, size_t size, struct GNUNET_TIME_Relative wait) { @@ -692,7 +705,10 @@ conn_message_sent (void *cls, GCC_check_connections (); LOG (GNUNET_ERROR_TYPE_INFO, ">>> %s (%s %4u) on conn %s (%p) %s [%5u] in queue %s\n", - GC_m2s (type), GC_m2s (payload_type), pid, GCC_2s (c), c, + GC_m2s (type), GC_m2s (payload_type), + ntohl (pid.pid), + GCC_2s (c), + c, GC_f2s (fwd), size, GNUNET_STRINGS_relative_time_to_string (wait, GNUNET_YES)); @@ -711,7 +727,8 @@ conn_message_sent (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, " %ssent %s %s pid %u\n", sent ? "" : "not ", GC_f2s (fwd), - GC_m2s (type), GC_m2s (payload_type), pid); + GC_m2s (type), GC_m2s (payload_type), + ntohl (pid.pid)); GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG); /* Update flow control info. */ @@ -761,7 +778,8 @@ conn_message_sent (void *cls, if (GNUNET_YES == sent) { fc->last_pid_sent = pid; - if (GC_is_pid_bigger (fc->last_pid_sent + 1, fc->last_ack_recv)) + if (GC_is_pid_bigger (ntohl (fc->last_pid_sent.pid) + 1, + ntohl (fc->last_ack_recv.pid)) ) GCC_start_poll (c, fwd); GCC_send_ack (c, fwd, GNUNET_NO); connection_reset_timeout (c, fwd); @@ -772,14 +790,14 @@ conn_message_sent (void *cls, { fc->queue_n--; LOG (GNUNET_ERROR_TYPE_DEBUG, - "! accounting pid %u\n", - fc->last_pid_sent); + "! accounting pid %u\n", + ntohl (fc->last_pid_sent.pid)); } else { LOG (GNUNET_ERROR_TYPE_DEBUG, "! forced, Q_N not accounting pid %u\n", - fc->last_pid_sent); + ntohl (fc->last_pid_sent.pid)); } break; @@ -961,9 +979,11 @@ get_hop (struct CadetConnection *c, int fwd) * @param ooo_pid PID of the out-of-order message. */ static uint32_t -get_recv_bitmask (uint32_t last_pid_recv, uint32_t ooo_pid) +get_recv_bitmask (struct CadetEncryptedMessageIdentifier last_pid_recv, + struct CadetEncryptedMessageIdentifier ooo_pid) { - return 1 << (last_pid_recv - ooo_pid); + // FIXME: should assert that the delta is in range... + return 1 << (ntohl (last_pid_recv.pid) - ntohl (ooo_pid.pid)); } @@ -975,14 +995,18 @@ get_recv_bitmask (uint32_t last_pid_recv, uint32_t ooo_pid) * @param last_pid_recv Last in-order PID received. */ static int -is_ooo_ok (uint32_t last_pid_recv, uint32_t ooo_pid, uint32_t ooo_bitmap) +is_ooo_ok (struct CadetEncryptedMessageIdentifier last_pid_recv, + struct CadetEncryptedMessageIdentifier ooo_pid, + uint32_t ooo_bitmap) { uint32_t mask; - if (GC_is_pid_bigger (last_pid_recv - 31, ooo_pid)) + if (GC_is_pid_bigger (ntohl (last_pid_recv.pid) - 31, + ntohl (ooo_pid.pid))) return GNUNET_NO; - mask = get_recv_bitmask (last_pid_recv, ooo_pid); + mask = get_recv_bitmask (last_pid_recv, + ooo_pid); if (0 != (ooo_bitmap & mask)) return GNUNET_NO; @@ -1029,6 +1053,7 @@ is_fwd (const struct CadetConnection *c, static void send_connection_ack (struct CadetConnection *c, int fwd) { + static struct CadetEncryptedMessageIdentifier zero; struct GNUNET_CADET_ConnectionCreateMessageAckMessage msg; struct CadetTunnel *t; const uint16_t size = sizeof (struct GNUNET_CADET_ConnectionCreateMessageAckMessage); @@ -1046,9 +1071,12 @@ send_connection_ack (struct CadetConnection *c, int fwd) msg.cid = c->id; GNUNET_assert (NULL == c->maintenance_q); - c->maintenance_q = GCP_send (get_hop (c, fwd), &msg.header, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, 0, - c, fwd, + c->maintenance_q = GCP_send (get_hop (c, fwd), + &msg.header, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK, + zero, + c, + fwd, &conn_message_sent, NULL); LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u (conn`ACK)\n", c, c->pending_messages); @@ -1076,6 +1104,7 @@ send_broken (struct CadetConnection *c, const struct GNUNET_PeerIdentity *id2, int fwd) { + static struct CadetEncryptedMessageIdentifier zero; struct GNUNET_CADET_ConnectionBrokenMessage msg; GCC_check_connections (); @@ -1085,8 +1114,13 @@ send_broken (struct CadetConnection *c, msg.reserved = htonl (0); msg.peer1 = *id1; msg.peer2 = *id2; - (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, fwd, - GNUNET_YES, NULL, NULL); + (void) GCC_send_prebuilt_message (&msg.header, + UINT16_MAX, + zero, + c, + fwd, + GNUNET_YES, + NULL, NULL); GCC_check_connections (); } @@ -1106,6 +1140,7 @@ send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *conne const struct GNUNET_PeerIdentity *id2, struct CadetPeer *neighbor) { + static struct CadetEncryptedMessageIdentifier zero; struct GNUNET_CADET_ConnectionBrokenMessage msg; GCC_check_connections (); @@ -1121,9 +1156,12 @@ send_broken_unknown (const struct GNUNET_CADET_ConnectionTunnelIdentifier *conne msg.peer2 = *id2; else memset (&msg.peer2, 0, sizeof (msg.peer2)); - GNUNET_assert (NULL != GCP_send (neighbor, &msg.header, - UINT16_MAX, 2, - NULL, GNUNET_SYSERR, /* connection, fwd */ + GNUNET_assert (NULL != GCP_send (neighbor, + &msg.header, + UINT16_MAX, + zero, + NULL, + GNUNET_SYSERR, /* connection, fwd */ NULL, NULL)); /* continuation */ GCC_check_connections (); } @@ -1418,6 +1456,7 @@ connection_cancel_queues (struct CadetConnection *c, static void send_poll (void *cls) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetFlowControl *fc = cls; struct GNUNET_CADET_ConnectionHopByHopPollMessage msg; struct CadetConnection *c; @@ -1433,11 +1472,17 @@ send_poll (void *cls) msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_POLL); msg.header.size = htons (sizeof (msg)); msg.cid = c->id; - msg.pid = htonl (fc->last_pid_sent); - LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", fc->last_pid_sent); - fc->poll_msg = - GCC_send_prebuilt_message (&msg.header, UINT16_MAX, fc->last_pid_sent, c, - fc == &c->fwd_fc, GNUNET_YES, NULL, NULL); + msg.cemi = fc->last_pid_sent; + LOG (GNUNET_ERROR_TYPE_DEBUG, " last pid sent: %u\n", ntohl (fc->last_pid_sent.pid)); + fc->poll_msg + = GCC_send_prebuilt_message (&msg.header, + UINT16_MAX, + zero, + c, + fc == &c->fwd_fc, + GNUNET_YES, + NULL, + NULL); GNUNET_assert (NULL != fc->poll_msg); GCC_check_connections (); } @@ -1879,6 +1924,7 @@ void GCC_handle_create (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionCreateMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; const struct GNUNET_CADET_ConnectionTunnelIdentifier *cid; struct GNUNET_PeerIdentity *id; struct CadetPeerPath *path; @@ -2001,8 +2047,12 @@ GCC_handle_create (struct CadetPeer *peer, LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); GCP_add_path (dest_peer, path_duplicate (path), GNUNET_NO); GCP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_NO); - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, - GNUNET_YES, GNUNET_YES, NULL, NULL); + (void) GCC_send_prebuilt_message (&msg->header, + 0, + zero, + c, + GNUNET_YES, GNUNET_YES, + NULL, NULL); } path_destroy (path); GCC_check_connections (); @@ -2019,6 +2069,7 @@ void GCC_handle_confirm (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionCreateMessageAckMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetConnection *c; enum CadetConnectionState oldstate; int fwd; @@ -2126,7 +2177,10 @@ GCC_handle_confirm (struct CadetPeer *peer, else { LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, + (void) GCC_send_prebuilt_message (&msg->header, 0, + zero, + c, + fwd, GNUNET_YES, NULL, NULL); } GCC_check_connections (); @@ -2143,6 +2197,7 @@ void GCC_handle_broken (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionBrokenMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetConnection *c; struct CadetTunnel *t; int fwd; @@ -2195,7 +2250,8 @@ GCC_handle_broken (struct CadetPeer *peer, } else { - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, + (void) GCC_send_prebuilt_message (&msg->header, 0, + zero, c, fwd, GNUNET_YES, NULL, NULL); connection_cancel_queues (c, !fwd); } @@ -2214,6 +2270,7 @@ void GCC_handle_destroy (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionDestroyMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetConnection *c; int fwd; @@ -2245,7 +2302,8 @@ GCC_handle_destroy (struct CadetPeer *peer, if (GNUNET_NO == GCC_is_terminal (c, fwd)) { - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, + (void) GCC_send_prebuilt_message (&msg->header, 0, + zero, c, fwd, GNUNET_YES, NULL, NULL); } else if (0 == c->pending_messages) @@ -2278,7 +2336,7 @@ GCC_handle_ack (struct CadetPeer *peer, { struct CadetConnection *c; struct CadetFlowControl *fc; - uint32_t ack; + struct CadetEncryptedMessageIdentifier ack; int fwd; GCC_check_connections (); @@ -2315,15 +2373,19 @@ GCC_handle_ack (struct CadetPeer *peer, return; } - ack = ntohl (msg->ack); + ack = msg->cemi; LOG (GNUNET_ERROR_TYPE_DEBUG, " %s ACK %u (was %u)\n", - GC_f2s (fwd), ack, fc->last_ack_recv); - if (GC_is_pid_bigger (ack, fc->last_ack_recv)) + GC_f2s (fwd), + ntohl (ack.pid), + ntohl (fc->last_ack_recv.pid)); + if (GC_is_pid_bigger (ntohl (ack.pid), + ntohl (fc->last_ack_recv.pid))) fc->last_ack_recv = ack; /* Cancel polling if the ACK is big enough. */ if ( (NULL != fc->poll_task) & - GC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) + GC_is_pid_bigger (ntohl (fc->last_ack_recv.pid), + ntohl (fc->last_pid_sent.pid))) { LOG (GNUNET_ERROR_TYPE_DEBUG, " Cancel poll\n"); GNUNET_SCHEDULER_cancel (fc->poll_task); @@ -2347,7 +2409,7 @@ GCC_handle_poll (struct CadetPeer *peer, { struct CadetConnection *c; struct CadetFlowControl *fc; - uint32_t pid; + struct CadetEncryptedMessageIdentifier pid; int fwd; GCC_check_connections (); @@ -2389,8 +2451,11 @@ GCC_handle_poll (struct CadetPeer *peer, return; } - pid = ntohl (msg->pid); - LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u, OLD %u\n", pid, fc->last_pid_recv); + pid = msg->cemi; + LOG (GNUNET_ERROR_TYPE_DEBUG, + " PID %u, OLD %u\n", + ntohl (pid.pid), + ntohl (fc->last_pid_recv.pid)); fc->last_pid_recv = pid; fwd = fc == &c->bck_fc; GCC_send_ack (c, fwd, GNUNET_YES); @@ -2417,7 +2482,7 @@ check_message (const struct GNUNET_MessageHeader *message, const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid, struct CadetConnection *c, struct CadetPeer *sender, - uint32_t pid) + struct CadetEncryptedMessageIdentifier pid) { struct CadetFlowControl *fc; struct CadetPeer *hop; @@ -2470,10 +2535,11 @@ check_message (const struct GNUNET_MessageHeader *message, { fc = fwd ? &c->bck_fc : &c->fwd_fc; LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected in interval [%u,%u])\n", - pid, - fc->last_pid_recv + 1, - fc->last_ack_sent); - if (GC_is_pid_bigger (pid, fc->last_ack_sent)) + ntohl (pid.pid), + ntohl (fc->last_pid_recv.pid) + 1, + ntohl (fc->last_ack_sent.pid)); + if (GC_is_pid_bigger (ntohl (pid.pid), + ntohl (fc->last_ack_sent.pid))) { GNUNET_STATISTICS_update (stats, "# unsolicited message", @@ -2484,11 +2550,12 @@ check_message (const struct GNUNET_MessageHeader *message, pid, fc->last_pid_recv, fc->last_ack_sent); return GNUNET_SYSERR; } - if (GC_is_pid_bigger (pid, fc->last_pid_recv)) + if (GC_is_pid_bigger (ntohl (pid.pid), + ntohl (fc->last_pid_recv.pid))) { unsigned int delta; - delta = pid - fc->last_pid_recv; + delta = ntohl (pid.pid) - ntohl (fc->last_pid_recv.pid); fc->last_pid_recv = pid; fc->recv_bitmap <<= delta; fc->recv_bitmap |= 1; @@ -2505,10 +2572,12 @@ check_message (const struct GNUNET_MessageHeader *message, { LOG (GNUNET_ERROR_TYPE_WARNING, "PID %u unexpected (%u+), dropping!\n", - pid, fc->last_pid_recv - 31); + ntohl (pid.pid), + ntohl (fc->last_pid_recv.pid) - 31); return GNUNET_SYSERR; } - fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, pid); + fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, + pid); } } @@ -2539,6 +2608,7 @@ void GCC_handle_kx (struct CadetPeer *peer, const struct GNUNET_CADET_TunnelKeyExchangeMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; struct CadetConnection *c; int fwd; @@ -2552,7 +2622,7 @@ GCC_handle_kx (struct CadetPeer *peer, cid, c, peer, - 0); + zero); /* If something went wrong, discard message. */ if (GNUNET_SYSERR == fwd) @@ -2580,7 +2650,8 @@ GCC_handle_kx (struct CadetPeer *peer, /* Message not for us: forward to next hop */ LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, + (void) GCC_send_prebuilt_message (&msg->header, 0, + zero, c, fwd, GNUNET_NO, NULL, NULL); GCC_check_connections (); } @@ -2596,14 +2667,15 @@ void GCC_handle_encrypted (struct CadetPeer *peer, const struct GNUNET_CADET_ConnectionEncryptedMessage *msg) { + static struct CadetEncryptedMessageIdentifier zero; const struct GNUNET_CADET_ConnectionTunnelIdentifier* cid; struct CadetConnection *c; - uint32_t pid; + struct CadetEncryptedMessageIdentifier pid; int fwd; GCC_check_connections (); cid = &msg->cid; - pid = ntohl (msg->pid); + pid = msg->cemi; log_message (&msg->header, peer, cid); c = connection_get (cid); @@ -2639,7 +2711,8 @@ GCC_handle_encrypted (struct CadetPeer *peer, /* Message not for us: forward to next hop */ LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); - (void) GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd, + (void) GCC_send_prebuilt_message (&msg->header, 0, + zero, c, fwd, GNUNET_NO, NULL, NULL); GCC_check_connections (); } @@ -2966,12 +3039,12 @@ GCC_get_allowed (struct CadetConnection *c, int fwd) fc = fwd ? &c->fwd_fc : &c->bck_fc; if ( (CADET_CONNECTION_READY != c->state) || - GC_is_pid_bigger (fc->last_pid_recv, - fc->last_ack_sent) ) + GC_is_pid_bigger (ntohl (fc->last_pid_recv.pid), + ntohl (fc->last_ack_sent.pid)) ) { return 0; } - return (fc->last_ack_sent - fc->last_pid_recv); + return (ntohl (fc->last_ack_sent.pid) - ntohl (fc->last_pid_recv.pid)); } @@ -2999,18 +3072,17 @@ GCC_get_qn (struct CadetConnection *c, int fwd) * * @param c Connection. * @param fwd Is query about FWD traffic? - * * @return Next PID to use. */ -uint32_t +struct CadetEncryptedMessageIdentifier GCC_get_pid (struct CadetConnection *c, int fwd) { struct CadetFlowControl *fc; - uint32_t pid; + struct CadetEncryptedMessageIdentifier pid; fc = fwd ? &c->fwd_fc : &c->bck_fc; pid = fc->next_pid; - fc->next_pid++; + fc->next_pid.pid = htonl (1 + ntohl (pid.pid)); return pid; } @@ -3155,8 +3227,10 @@ GCC_is_sendable (struct CadetConnection *c, int fwd) fc = fwd ? &c->fwd_fc : &c->bck_fc; LOG (GNUNET_ERROR_TYPE_DEBUG, " last ack recv: %u, last pid sent: %u\n", - fc->last_ack_recv, fc->last_pid_sent); - if (GC_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent)) + ntohl (fc->last_ack_recv.pid), + ntohl (fc->last_pid_sent.pid)); + if (GC_is_pid_bigger (ntohl (fc->last_ack_recv.pid), + ntohl (fc->last_pid_sent.pid))) { LOG (GNUNET_ERROR_TYPE_DEBUG, " sendable\n"); return GNUNET_YES; @@ -3201,7 +3275,8 @@ GCC_is_direct (struct CadetConnection *c) */ struct CadetConnectionQueue * GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, - uint16_t payload_type, uint32_t payload_id, + uint16_t payload_type, + struct CadetEncryptedMessageIdentifier payload_id, struct CadetConnection *c, int fwd, int force, GCC_sent cont, void *cont_cls) { @@ -3229,7 +3304,10 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, { case GNUNET_MESSAGE_TYPE_CONNECTION_ENCRYPTED: LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u, PIDsnt: %u, ACKrcv: %u\n", - fc, fc->queue_n, fc->last_pid_sent, fc->last_ack_recv); + fc, + fc->queue_n, + ntohl (fc->last_pid_sent.pid), + ntohl (fc->last_ack_recv.pid)); if (GNUNET_NO == force) { fc->queue_n++; @@ -3281,9 +3359,12 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, q->cont_cls = cont_cls; q->forced = force; GNUNET_CONTAINER_DLL_insert (fc->q_head, fc->q_tail, q); - q->peer_q = GCP_send (get_hop (c, fwd), message, - payload_type, payload_id, - c, fwd, + q->peer_q = GCP_send (get_hop (c, fwd), + message, + payload_type, + payload_id, + c, + fwd, &conn_message_sent, q); if (NULL == q->peer_q) { @@ -3327,6 +3408,7 @@ GCC_cancel (struct CadetConnectionQueue *q) void GCC_send_create (struct CadetConnection *c) { + static struct CadetEncryptedMessageIdentifier zero; enum CadetTunnelCState state; size_t size; @@ -3339,6 +3421,7 @@ GCC_send_create (struct CadetConnection *c) struct GNUNET_CADET_ConnectionCreateMessage *msg; struct GNUNET_PeerIdentity *peers; + msg = (struct GNUNET_CADET_ConnectionCreateMessage *) cbuf; msg->header.size = htons (size); msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE); @@ -3352,7 +3435,8 @@ GCC_send_create (struct CadetConnection *c) GNUNET_assert (NULL == c->maintenance_q); c->maintenance_q = GCP_send (get_next_hop (c), &msg->header, - GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 0, + GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, + zero, c, GNUNET_YES, &conn_message_sent, NULL); } @@ -3449,6 +3533,7 @@ GCC_send_ack (struct CadetConnection *c, int fwd, int force) void GCC_send_destroy (struct CadetConnection *c) { + static struct CadetEncryptedMessageIdentifier zero; struct GNUNET_CADET_ConnectionDestroyMessage msg; if (GNUNET_YES == c->destroy) @@ -3463,10 +3548,16 @@ GCC_send_destroy (struct CadetConnection *c) GCC_2s (c)); if (GNUNET_NO == GCC_is_terminal (c, GNUNET_YES)) - (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, + (void) GCC_send_prebuilt_message (&msg.header, + UINT16_MAX, + zero, + c, GNUNET_YES, GNUNET_YES, NULL, NULL); if (GNUNET_NO == GCC_is_terminal (c, GNUNET_NO)) - (void) GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, c, + (void) GCC_send_prebuilt_message (&msg.header, + UINT16_MAX, + zero, + c, GNUNET_NO, GNUNET_YES, NULL, NULL); mark_destroyed (c); GCC_check_connections (); @@ -3597,9 +3688,11 @@ GCC_debug (const struct CadetConnection *c, enum GNUNET_ErrorType level) LOG2 (level, "CCC FWD flow control:\n"); LOG2 (level, "CCC queue: %u/%u\n", c->fwd_fc.queue_n, c->fwd_fc.queue_max); LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", - c->fwd_fc.last_pid_sent, c->fwd_fc.last_pid_recv); + ntohl (c->fwd_fc.last_pid_sent.pid), + ntohl (c->fwd_fc.last_pid_recv.pid)); LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", - c->fwd_fc.last_ack_sent, c->fwd_fc.last_ack_recv); + ntohl (c->fwd_fc.last_ack_sent.pid), + ntohl (c->fwd_fc.last_ack_recv.pid)); LOG2 (level, "CCC recv PID bitmap: %X\n", c->fwd_fc.recv_bitmap); LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", 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) LOG2 (level, "CCC BCK flow control:\n"); LOG2 (level, "CCC queue: %u/%u\n", c->bck_fc.queue_n, c->bck_fc.queue_max); LOG2 (level, "CCC last PID sent: %5u, recv: %5u\n", - c->bck_fc.last_pid_sent, c->bck_fc.last_pid_recv); + ntohl (c->bck_fc.last_pid_sent.pid), + ntohl (c->bck_fc.last_pid_recv.pid)); LOG2 (level, "CCC last ACK sent: %5u, recv: %5u\n", - c->bck_fc.last_ack_sent, c->bck_fc.last_ack_recv); + ntohl (c->bck_fc.last_ack_sent.pid), + ntohl (c->bck_fc.last_ack_recv.pid)); LOG2 (level, "CCC recv PID bitmap: %X\n", c->bck_fc.recv_bitmap); LOG2 (level, "CCC poll: task %d, msg %p, msg_ack %p)\n", c->bck_fc.poll_task, c->bck_fc.poll_msg, c->bck_fc.ack_msg); diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h index 6df307dd1..ab2920ba3 100644 --- a/src/cadet/gnunet-service-cadet_connection.h +++ b/src/cadet/gnunet-service-cadet_connection.h @@ -372,10 +372,9 @@ GCC_get_qn (struct CadetConnection *c, int fwd); * * @param c Connection. * @param fwd Is query about FWD traffic? - * * @return Next PID to use. */ -uint32_t +struct CadetEncryptedMessageIdentifier GCC_get_pid (struct CadetConnection *c, int fwd); /** @@ -497,7 +496,8 @@ GCC_cancel (struct CadetConnectionQueue *q); */ struct CadetConnectionQueue * GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, - uint16_t payload_type, uint32_t payload_id, + uint16_t payload_type, + struct CadetEncryptedMessageIdentifier payload_id, struct CadetConnection *c, int fwd, int force, GCC_sent cont, void *cont_cls); diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 2c2c552c6..2b11040a5 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c @@ -103,9 +103,9 @@ struct CadetPeerQueue { uint16_t payload_type; /** - *ID of the payload (PID, ACK #, ...). + * ID of the payload (PID, ACK #, ...). */ - uint16_t payload_id; + struct CadetEncryptedMessageIdentifier payload_id; /** * Connection this message was sent on. @@ -1110,7 +1110,9 @@ call_peer_cont (struct CadetPeerQueue *q, int sent) GNUNET_STRINGS_relative_time_to_string (wait_time, GNUNET_NO)); q->cont (q->cont_cls, q->c, q->c_fwd, sent, - q->type, q->payload_type, q->payload_id, + q->type, + q->payload_type, + q->payload_id, q->size, wait_time); q->cont = NULL; } @@ -1173,7 +1175,7 @@ struct CadetPeerQueue * GCP_send (struct CadetPeer *peer, const struct GNUNET_MessageHeader *message, uint16_t payload_type, - uint32_t payload_id, + struct CadetEncryptedMessageIdentifier payload_id, struct CadetConnection *c, int fwd, GCP_sent cont, @@ -1188,7 +1190,8 @@ GCP_send (struct CadetPeer *peer, size = ntohs (message->size); LOG (GNUNET_ERROR_TYPE_DEBUG, "que %s (%s %4u) on conn %s (%p) %s towards %s (size %u)\n", - GC_m2s (type), GC_m2s (payload_type), payload_id, + GC_m2s (type), GC_m2s (payload_type), + ntohl (payload_id.pid), GCC_2s (c), c, GC_f2s (fwd), GCP_2s (peer), size); if (NULL == peer->connections) @@ -1227,8 +1230,11 @@ GCP_send (struct CadetPeer *peer, { LOG (GNUNET_ERROR_TYPE_WARNING, "DD %s (%s %u) on conn %s %s (random drop for testing)\n", - GC_m2s (q->type), GC_m2s (q->payload_type), - q->payload_id, GCC_2s (c), GC_f2s (q->c_fwd)); + GC_m2s (q->type), + GC_m2s (q->payload_type), + ntohl (q->payload_id.pid), + GCC_2s (c), + GC_f2s (q->c_fwd)); q->drop_task = GNUNET_SCHEDULER_add_now (&drop_cb, q); return q; diff --git a/src/cadet/gnunet-service-cadet_peer.h b/src/cadet/gnunet-service-cadet_peer.h index 37d735bf5..1e206e10f 100644 --- a/src/cadet/gnunet-service-cadet_peer.h +++ b/src/cadet/gnunet-service-cadet_peer.h @@ -69,8 +69,12 @@ struct CadetPeerQueue; */ typedef void (*GCP_sent) (void *cls, - struct CadetConnection *c, int fwd, int sent, - uint16_t type, uint16_t payload_type, uint32_t pid, + struct CadetConnection *c, + int fwd, + int sent, + uint16_t type, + uint16_t payload_type, + struct CadetEncryptedMessageIdentifier pid, size_t size, struct GNUNET_TIME_Relative wait); @@ -166,7 +170,7 @@ struct CadetPeerQueue * GCP_send (struct CadetPeer *peer, const struct GNUNET_MessageHeader *message, uint16_t payload_type, - uint32_t payload_id, + struct CadetEncryptedMessageIdentifier payload_id, struct CadetConnection *c, int fwd, GCP_sent cont, diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index df1cfa16e..5e0f5bf4f 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.c +++ b/src/cadet/gnunet-service-cadet_tunnel.c @@ -1327,7 +1327,6 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, size_t size = ntohs (message->size); char cbuf[sizeof (struct GNUNET_CADET_ConnectionEncryptedMessage) + size] GNUNET_ALIGN; size_t esize; - uint32_t mid; uint16_t type; int fwd; @@ -1379,38 +1378,22 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, } fwd = GCC_is_origin (c, GNUNET_YES); ax_msg->cid = *GCC_get_id (c); - ax_msg->pid = htonl (GCC_get_pid (c, fwd)); + ax_msg->cemi = GCC_get_pid (c, fwd); - mid = 0; - type = ntohs (message->type); - switch (type) - { - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DATA: - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DATA_ACK: - if (GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DATA == type) - mid = ntohl (((struct GNUNET_CADET_ChannelDataMessage *) message)->mid); - else - mid = ntohl (((struct GNUNET_CADET_ChannelDataAckMessage *) message)->mid); - /* Fall thru */ - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_KEEPALIVE: - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE: - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY: - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_ACK: - case GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE_NACK_DEPRECATED: - break; - default: - GNUNET_break (0); - LOG (GNUNET_ERROR_TYPE_ERROR, "type %s not valid\n", GC_m2s (type)); - } + type = htons (message->type); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Sending message of type %s with PID %u and CID %s\n", + "Sending message of type %s with CEMI %u and CID %s\n", GC_m2s (type), - htonl (ax_msg->pid), + htonl (ax_msg->cemi.pid), GNUNET_sh2s (&ax_msg->cid.connection_of_tunnel)); if (NULL == cont) { - (void) GCC_send_prebuilt_message (msg, type, mid, c, fwd, + (void) GCC_send_prebuilt_message (msg, + type, + ax_msg->cemi, + c, + fwd, force, NULL, NULL); return NULL; } @@ -1425,7 +1408,12 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, } tq->cont = cont; tq->cont_cls = cont_cls; - tq->cq = GCC_send_prebuilt_message (msg, type, mid, c, fwd, force, + tq->cq = GCC_send_prebuilt_message (msg, + type, + ax_msg->cemi, + c, + fwd, + force, &tun_message_sent, tq); GNUNET_assert (NULL != tq->cq); @@ -3204,7 +3192,8 @@ GCT_has_queued_traffic (struct CadetTunnel *t) */ struct CadetTunnelQueue * GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, - struct CadetTunnel *t, struct CadetConnection *c, + struct CadetTunnel *t, + struct CadetConnection *c, int force, GCT_sent cont, void *cont_cls) { return send_prebuilt_message (message, t, c, force, cont, cont_cls, NULL); @@ -3220,6 +3209,7 @@ GCT_send_prebuilt_message (const struct GNUNET_MessageHeader *message, void GCT_send_kx (struct CadetTunnel *t, int force_reply) { + static struct CadetEncryptedMessageIdentifier zero; struct CadetConnection *c; struct GNUNET_CADET_TunnelKeyExchangeMessage msg; enum GNUNET_CADET_KX_Flags flags; @@ -3253,8 +3243,11 @@ GCT_send_kx (struct CadetTunnel *t, int force_reply) GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->kx_0, &msg.ephemeral_key); GNUNET_CRYPTO_ecdhe_key_get_public (t->ax->DHRs, &msg.ratchet_key); - t->ephm_h = GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 0, - c, GCC_is_origin (c, GNUNET_YES), + t->ephm_h = GCC_send_prebuilt_message (&msg.header, + UINT16_MAX, + zero, + c, + GCC_is_origin (c, GNUNET_YES), GNUNET_YES, &ephm_sent, t); if (CADET_TUNNEL_KEY_UNINITIALIZED == t->estate) GCT_change_estate (t, CADET_TUNNEL_KEY_SENT);