From 8914ac5f0bf6a0940051dda2fa7a46fe08f37a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 30 Jul 2019 22:43:38 +0200 Subject: [PATCH] Fix some issues with DATA ACK --- lib/src/streamconnection.c | 2 +- lib/src/takion.c | 18 ++++++++---------- lib/src/takionsendbuffer.c | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index 78cb887..91e0aa5 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -773,6 +773,6 @@ CHIAKI_EXPORT ChiakiErrorCode stream_connection_send_corrupt_frame(ChiakiStreamC return CHIAKI_ERR_UNKNOWN; } - CHIAKI_LOGD(stream_connection->log, "StreamConnection reporting corrupt frame(s) from %u to %u\n", (unsigned int)start, (unsigned int)end); + CHIAKI_LOGD(stream_connection->log, "StreamConnection reporting corrupt frame(s) from %u to %u", (unsigned int)start, (unsigned int)end); return chiaki_takion_send_message_data(&stream_connection->takion, 1, 2, buf, stream.bytes_written); } diff --git a/lib/src/takion.c b/lib/src/takion.c index 51a1f91..158ab78 100644 --- a/lib/src/takion.c +++ b/lib/src/takion.c @@ -914,24 +914,22 @@ static void takion_handle_packet_message_data_ack(ChiakiTakion *takion, uint8_t return; } - uint32_t seq_num = ntohl(*((uint32_t *)(buf + 0))); + uint32_t cumulative_seq_num = ntohl(*((uint32_t *)(buf + 0))); uint32_t a_rwnd = ntohl(*((uint32_t *)(buf + 4))); - uint16_t size_internal = ntohs(*((uint16_t *)(buf + 8))); - uint16_t zero = ntohs(*((uint16_t *)(buf + 0xa))); + uint16_t gap_ack_blocks_count = ntohs(*((uint16_t *)(buf + 8))); + uint16_t dup_tsns_count = ntohs(*((uint16_t *)(buf + 0xa))); - // this check is basically size_or_something != 0, but it is done like that in the original code, - // so I assume size_or_something may be the size of additional data coming after the data ack header. - if(buf_size != size_internal * 4 + 0xc) + if(buf_size != gap_ack_blocks_count * 4 + 0xc) { - CHIAKI_LOGW(takion->log, "Takion received data ack with invalid size_internal = %#x", size_internal); + CHIAKI_LOGW(takion->log, "Takion received data ack with invalid gap_ack_blocks_count"); return; } - if(zero != 0) - CHIAKI_LOGW(takion->log, "Takion received data ack with nonzero %#x at buf+0xa", zero); + if(dup_tsns_count != 0) + CHIAKI_LOGW(takion->log, "Takion received data ack with nonzero dup_tsns_count %#x", dup_tsns_count); //CHIAKI_LOGD(takion->log, "Takion received data ack with seq_num = %#x, something = %#x, size_or_something = %#x, zero = %#x", seq_num, something, size_internal, zero); - chiaki_takion_send_buffer_ack(&takion->send_buffer, seq_num); + chiaki_takion_send_buffer_ack(&takion->send_buffer, cumulative_seq_num); } /** diff --git a/lib/src/takionsendbuffer.c b/lib/src/takionsendbuffer.c index c6d5642..89e9888 100644 --- a/lib/src/takionsendbuffer.c +++ b/lib/src/takionsendbuffer.c @@ -145,7 +145,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_ack(ChiakiTakionSendBuff size_t i; for(i=0; ipackets_count; i++) { - if(send_buffer->packets[i].seq_num == seq_num) + if(send_buffer->packets[i].seq_num == seq_num) // TODO: should be <= (with seqnum arithmetic) break; } @@ -158,7 +158,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_buffer_ack(ChiakiTakionSendBuff free(send_buffer->packets[i].buf); if(i < send_buffer->packets_count - 1) - memmove(send_buffer->packets + i, send_buffer->packets + i + 1, send_buffer->packets_count - i - 1); + memmove(send_buffer->packets + i, send_buffer->packets + i + 1, (send_buffer->packets_count - i - 1) * sizeof(ChiakiTakionSendBufferPacket)); send_buffer->packets_count--;