From ee7f26b7ed883027f0a81ece1c2aacd41053ce1e Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 10 Apr 2020 23:29:49 +0200 Subject: [PATCH] Some updates --- src/protocol/AcknowledgeManager.cpp | 4 ++-- src/protocol/PacketLossCalculator.cpp | 32 +++++++++++++++++++++++---- src/protocol/PacketLossCalculator.h | 5 ++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/protocol/AcknowledgeManager.cpp b/src/protocol/AcknowledgeManager.cpp index 0edb8a6..67f29f1 100644 --- a/src/protocol/AcknowledgeManager.cpp +++ b/src/protocol/AcknowledgeManager.cpp @@ -109,6 +109,8 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now , if(entry->next_resend <= now) { entry->next_resend = now + std::chrono::milliseconds{(int64_t) min(ceil(this->rto), 1500.f)}; need_resend.push_back(entry); + entry->resend_count++; + entry->send_count++; } if(next_resend > entry->next_resend) next_resend = entry->next_resend; @@ -128,8 +130,6 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now , } resend_count++; - packet->resend_count++; - packet->send_count++; buffers.push_back(packet); } diff --git a/src/protocol/PacketLossCalculator.cpp b/src/protocol/PacketLossCalculator.cpp index f0a5bc6..45e2bca 100644 --- a/src/protocol/PacketLossCalculator.cpp +++ b/src/protocol/PacketLossCalculator.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "PacketLossCalculator.h" using namespace ts::protocol; @@ -64,6 +65,19 @@ void UnorderedPacketLossCalculator::short_stats() { this->last_history_offset = this->packet_history_offset; } +void UnorderedPacketLossCalculator::reset() { + this->received_packets_ = 0; + this->received_packets_total_ = 0; + this->lost_packets_ = 0; + this->lost_packets_total_ = 0; + this->reset_offsets(); +} +void UnorderedPacketLossCalculator::reset_offsets() { + this->packet_history_offset = 0; + this->last_history_offset = 0; + this->packet_history.clear(); +} + void CommandPacketLossCalculator::packet_send(uint32_t packet_id) { if(packet_id > this->packet_history_offset) { assert(packet_id - 1 == this->packet_history_offset); /* the method will only be called with an incrementing packet id */ @@ -71,8 +85,6 @@ void CommandPacketLossCalculator::packet_send(uint32_t packet_id) { auto lost = std::exchange(this->packet_ack_counts[packet_id % CommandPacketLossCalculator::packet_ack_counts_length], 1); this->lost_packets_ += lost; this->lost_packets_total_ += lost; - if(lost > 0) - __asm__("nop"); this->packet_history_offset = packet_id; } else { /* We're not really interested if the packet id matches the resend packet. If not we may accidentally increase the loss count. */ @@ -85,8 +97,6 @@ void CommandPacketLossCalculator::ack_received(uint32_t packet_id) { auto& count = this->packet_ack_counts[packet_id % CommandPacketLossCalculator::packet_ack_counts_length]; if(count > 0) /* could happen if receive an acknowledge for an packet which is older than out buffer size or the client send the ack twice... */ count--; - else - __asm__("nop"); this->received_packets_++; this->received_packets_total_++; @@ -102,4 +112,18 @@ void CommandPacketLossCalculator::short_stats() { const auto factor = target_interval / packets_passed; this->received_packets_ *= factor; this->lost_packets_ *= factor; +} + +void CommandPacketLossCalculator::reset() { + this->received_packets_ = 0; + this->received_packets_total_ = 0; + this->lost_packets_ = 0; + this->lost_packets_total_ = 0; + this->reset_offsets(); +} + +void CommandPacketLossCalculator::reset_offsets() { + this->packet_history_offset = 0; + this->packets_send_unshorten = 0; + memset(packet_ack_counts, 0, packet_ack_counts_length); } \ No newline at end of file diff --git a/src/protocol/PacketLossCalculator.h b/src/protocol/PacketLossCalculator.h index b0c7e73..74366d2 100644 --- a/src/protocol/PacketLossCalculator.h +++ b/src/protocol/PacketLossCalculator.h @@ -48,6 +48,8 @@ namespace ts::protocol { void packet_received(uint32_t /* packet id */); void short_stats(); + void reset(); + void reset_offsets(); [[nodiscard]] inline auto last_packet_id() const { return this->packet_history_offset; } [[nodiscard]] inline bool valid_data() const { return this->packet_history_offset >= 32; } @@ -61,7 +63,6 @@ namespace ts::protocol { [[nodiscard]] inline uint32_t unconfirmed_received_packets() const { return this->packet_history.count(); }; [[nodiscard]] inline uint32_t unconfirmed_lost_packets() const { return this->packet_history.max_bits() - this->packet_history.count(); }; - inline void reset() { this->received_packets_ = 0; this->lost_packets_ = 0; } private: uint32_t received_packets_{0}, received_packets_total_{0}, lost_packets_{0}, lost_packets_total_{0}; @@ -78,6 +79,8 @@ namespace ts::protocol { void ack_received(uint32_t /* packet id */); //Attention: This is a full ID! void short_stats(); + void reset(); + void reset_offsets(); [[nodiscard]] inline bool valid_data() const { return true; }