From 7019fcdc8632b5740798e8345b48e23640e2de1b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 28 Feb 2016 19:27:38 +0100 Subject: [PATCH] Make sequence numbers unsigned, because they are. --- greprotocol.cpp | 4 ++-- greprotocol.h | 2 +- pacer.cpp | 2 +- pacer.h | 2 +- protocol.h | 2 +- reorderer.cpp | 8 ++++---- reorderer.h | 4 ++-- rsdecoder.cpp | 4 ++-- rsdecoder.h | 2 +- rsencoder.cpp | 6 +++--- rsencoder.h | 2 +- tunprotocol.cpp | 2 +- tunprotocol.h | 4 ++-- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/greprotocol.cpp b/greprotocol.cpp index d3daa9c..6f35130 100644 --- a/greprotocol.cpp +++ b/greprotocol.cpp @@ -51,7 +51,7 @@ GREProtocol::GREProtocol(const in6_addr &src, const in6_addr &dst) } } -void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq) +void GREProtocol::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq) { char buf[4096]; gre_header *gre = (gre_header *)buf; @@ -62,7 +62,7 @@ void GREProtocol::send_packet(uint16_t proto, const string &data, int incoming_s gre->protocol_type = htons(proto); char *ptr = buf + sizeof(*gre); - int seq_be = htonl(incoming_seq); + uint32_t seq_be = htonl(incoming_seq); memcpy(ptr, &seq_be, sizeof(seq_be)); ptr += sizeof(seq_be); diff --git a/greprotocol.h b/greprotocol.h index 738ec7b..c54efd6 100644 --- a/greprotocol.h +++ b/greprotocol.h @@ -11,7 +11,7 @@ class GREProtocol : public Sender, public Reader { public: GREProtocol(const in6_addr &myaddr, const in6_addr &dst); - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq); + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq); virtual int fd() const; virtual void read_packet(Sender* sender); diff --git a/pacer.cpp b/pacer.cpp index d049067..7de87a4 100644 --- a/pacer.cpp +++ b/pacer.cpp @@ -12,7 +12,7 @@ Pacer::Pacer(Sender *sender, int max_rate_kbit_per_sec, int burst_num_packets) seconds_per_byte = 1.0 / max_rate_byte_per_sec; } -void Pacer::send_packet(uint16_t proto, const string &data, int incoming_seq) +void Pacer::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq) { waiting_packets.push_back(GREPacket{incoming_seq, proto, data, {0, 0}}); possibly_flush_packets(); diff --git a/pacer.h b/pacer.h index 90d0c4f..b42d73f 100644 --- a/pacer.h +++ b/pacer.h @@ -12,7 +12,7 @@ struct Pacer : public Sender { public: Pacer(Sender *sender, int max_rate_kbit_per_sec, int burst_num_packets); - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq); + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq); void possibly_adjust_tv(timeval *tv); void possibly_flush_packets(); diff --git a/protocol.h b/protocol.h index 65c4d1d..acbaa3b 100644 --- a/protocol.h +++ b/protocol.h @@ -6,7 +6,7 @@ class Sender { public: - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq) = 0; + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq) = 0; }; class Reader { diff --git a/reorderer.cpp b/reorderer.cpp index c2823e5..71b90c5 100644 --- a/reorderer.cpp +++ b/reorderer.cpp @@ -30,7 +30,7 @@ void Reorderer::possibly_adjust_tv(timeval *tv) } } -void Reorderer::send_packet(uint16_t proto, const string& data, int seq) +void Reorderer::send_packet(uint16_t proto, const string& data, uint32_t seq) { timeval now; gettimeofday(&now, NULL); @@ -55,7 +55,7 @@ void Reorderer::send_packet(uint16_t proto, const string& data, int seq) if (packet_buffer.empty() && seq < last_seq && tdiff(last_sent_packet, now) > 5.0) { - printf("No good data for five seconds, resetting sequence to %d\n", seq); + printf("No good data for five seconds, resetting sequence to %u\n", seq); last_seq = seq - 1; } @@ -70,9 +70,9 @@ void Reorderer::send_packet(uint16_t proto, const string& data, int seq) while (!packet_buffer.empty() && (last_seq == -1 || packet_buffer.top().seq <= last_seq + 1)) { - int front_seq = packet_buffer.top().seq; + uint32_t front_seq = packet_buffer.top().seq; if (front_seq < last_seq + 1) { - printf("Duplicate packet or way out-of-order: seq=%d front_seq=%d\n", + printf("Duplicate packet or way out-of-order: seq=%u front_seq=%u\n", front_seq, last_seq + 1); packet_buffer.pop(); continue; diff --git a/reorderer.h b/reorderer.h index 77fda65..d7f585c 100644 --- a/reorderer.h +++ b/reorderer.h @@ -14,7 +14,7 @@ #include "protocol.h" struct GREPacket { - int seq; + uint32_t seq; uint16_t proto; std::string data; timeval ts; @@ -27,7 +27,7 @@ struct GREPacket { class Reorderer : public Sender { public: Reorderer(Sender* sender); - void send_packet(uint16_t proto, const std::string& data, int seq); + void send_packet(uint16_t proto, const std::string& data, uint32_t seq); void possibly_adjust_tv(timeval *tv); int get_reorders() const { return num_reorders; } diff --git a/rsdecoder.cpp b/rsdecoder.cpp index 58fa1ac..0a11541 100644 --- a/rsdecoder.cpp +++ b/rsdecoder.cpp @@ -17,7 +17,7 @@ RSDecoder::RSDecoder(Sender *sender) { } -void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incoming_seq) +void RSDecoder::send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq) { int rs_group; if (proto == 0xffff) { @@ -85,7 +85,7 @@ void RSDecoder::send_packet(uint16_t proto, const std::string &data, int incomin vector padded_packets; std::map shares; for (const auto &packet_pair : group.packets) { - int packet_seq = packet_pair.first; + uint32_t packet_seq = packet_pair.first; int share_num; string p; p.resize(max_length); diff --git a/rsdecoder.h b/rsdecoder.h index 3b1634d..db8c6e3 100644 --- a/rsdecoder.h +++ b/rsdecoder.h @@ -13,7 +13,7 @@ class Sender; class RSDecoder : public Sender { public: RSDecoder(Sender *sender); - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq); + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq); int get_recovered_packets() const { return num_recovered_packets; } diff --git a/rsencoder.cpp b/rsencoder.cpp index 4f63131..e4e9481 100644 --- a/rsencoder.cpp +++ b/rsencoder.cpp @@ -21,7 +21,7 @@ RSEncoder::RSEncoder(Sender *sender) { } -void RSEncoder::send_packet(uint16_t proto, const std::string &data, int incoming_seq) +void RSEncoder::send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq) { if (!packet_history.empty() && incoming_seq <= packet_history.back().seq) { @@ -40,7 +40,7 @@ void RSEncoder::send_packet(uint16_t proto, const std::string &data, int incomin } if (debug_drop_packet) { const unsigned char *ptr = reinterpret_cast(data.data()); - printf("DEBUG: Dropping packet seq=%d proto=0x%04x len=%d data=%02x %02x %02x %02x %02x %02x %02x %02x ...\n", + printf("DEBUG: Dropping packet seq=%u proto=0x%04x len=%d data=%02x %02x %02x %02x %02x %02x %02x %02x ...\n", incoming_seq, proto, data.size(), ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7]); } else { sender->send_packet(proto, data, incoming_seq); @@ -84,7 +84,7 @@ void RSEncoder::finish_group() } const char *sdata = reinterpret_cast(data); - int start_seq = packet_history[0].seq - 1; + uint32_t start_seq = packet_history[0].seq - 1; sender->send_packet(0xffff, string(sdata, size), start_seq - (packet_num - RS_PAYLOAD_SIZE)); }); diff --git a/rsencoder.h b/rsencoder.h index 6ab6e4b..538bcc8 100644 --- a/rsencoder.h +++ b/rsencoder.h @@ -14,7 +14,7 @@ class Sender; class RSEncoder : public Sender { public: RSEncoder(Sender* sender); - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq); + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq); private: void finish_group(); diff --git a/tunprotocol.cpp b/tunprotocol.cpp index 510decf..f455e20 100644 --- a/tunprotocol.cpp +++ b/tunprotocol.cpp @@ -42,7 +42,7 @@ TUNProtocol::TUNProtocol(const char *devname) : tunfd(tun_open(devname)), seq(0) { } -void TUNProtocol::send_packet(uint16_t proto, const string &data, int incoming_seq) +void TUNProtocol::send_packet(uint16_t proto, const string &data, uint32_t incoming_seq) { char buf[4096]; diff --git a/tunprotocol.h b/tunprotocol.h index 79e528f..81fd900 100644 --- a/tunprotocol.h +++ b/tunprotocol.h @@ -9,7 +9,7 @@ class TUNProtocol : public Sender, public Reader { public: TUNProtocol(const char *devname); - virtual void send_packet(uint16_t proto, const std::string &data, int incoming_seq); + virtual void send_packet(uint16_t proto, const std::string &data, uint32_t incoming_seq); virtual int fd() const; virtual void read_packet(Sender* sender); @@ -18,7 +18,7 @@ public: private: int tunfd; - int seq; + uint32_t seq; int received_packets = 0, sent_packets = 0; }; -- 2.39.2