2929#include < cstdint>
3030#include < cstring>
3131#include < mutex>
32+ #include < utility>
3233#include < vector>
3334
35+ #include " RTTEstimator.hpp"
3436#include " wire_protocol.hpp"
3537
3638namespace NUClear {
@@ -55,7 +57,7 @@ namespace network {
5557 tp.acked .resize (packet_count, false );
5658 tp.last_send = now;
5759
58- TrackingKey key{target, packet_id};
60+ const TrackingKey key{target, packet_id};
5961
6062 const std::lock_guard<std::mutex> lock (tracking_mutex);
6163 tracked_packets[key] = std::move (tp);
@@ -67,7 +69,7 @@ namespace network {
6769 const uint8_t * ack_bitset,
6870 std::size_t bitset_size,
6971 std::chrono::steady_clock::time_point now) {
70- TrackingKey key{source, packet_id};
72+ const TrackingKey key{source, packet_id};
7173
7274 const std::lock_guard<std::mutex> lock (tracking_mutex);
7375 auto it = tracked_packets.find (key);
@@ -95,8 +97,8 @@ namespace network {
9597 // Update acked bitset
9698 bool all_acked = true ;
9799 for (uint16_t i = 0 ; i < packet_count && i < tp.acked .size (); ++i) {
98- std::size_t byte_idx = i / 8 ;
99- uint8_t bit_idx = i % 8 ;
100+ const std::size_t byte_idx = i / 8 ;
101+ const uint8_t bit_idx = static_cast < uint8_t >( i % 8 ) ;
100102 if (byte_idx < bitset_size && (ack_bitset[byte_idx] & (1u << bit_idx)) != 0 ) {
101103 tp.acked [i] = true ;
102104 }
@@ -115,8 +117,8 @@ namespace network {
115117 uint16_t packet_count,
116118 const std::vector<bool >& received) {
117119 // Calculate bitset size: ceil(packet_count / 8)
118- std::size_t bitset_bytes = (packet_count + 7 ) / 8 ;
119- std::size_t total_size = sizeof (ACKPacket) - 1 + bitset_bytes; // -1 for the placeholder uint8_t
120+ const std::size_t bitset_bytes = (packet_count + 7 ) / 8 ;
121+ const std::size_t total_size = sizeof (ACKPacket) - 1 + bitset_bytes; // -1 for the placeholder uint8_t
120122
121123 std::vector<uint8_t > packet (total_size, 0 );
122124
@@ -171,9 +173,9 @@ namespace network {
171173 req.hash = tp.hash ;
172174
173175 // Extract the fragment data
174- std::size_t offset = static_cast <std::size_t >(i) * packet_mtu;
175- std::size_t length = std::min (static_cast <std::size_t >(packet_mtu), tp.payload .size () - offset);
176- req.data .assign (tp.payload .begin () + offset, tp.payload .begin () + offset + length);
176+ const std::size_t offset = static_cast <std::size_t >(i) * packet_mtu;
177+ const std::size_t length = std::min (static_cast <std::size_t >(packet_mtu), tp.payload .size () - offset);
178+ req.data .assign (tp.payload .data () + offset, tp.payload .data () + offset + length);
177179
178180 retransmissions.push_back (std::move (req));
179181 }
0 commit comments