]> git.sesse.net Git - greproxy/commitdiff
Support sequence restarts.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 15:36:09 +0000 (16:36 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 7 Feb 2015 15:36:09 +0000 (16:36 +0100)
reorderer.cpp
reorderer.h

index 7b19d1d3435ab9e5b1ba702b38c6e70d295e3408..3a6b6de0a8f32174508d0fcfb11856d8fbbe379d 100644 (file)
@@ -17,6 +17,7 @@ double tdiff(const timeval& a, const timeval& b)
 Reorderer::Reorderer(Sender* sender)
        : sender(sender), last_seq(-1)
 {
+       gettimeofday(&last_sent_packet, NULL);
 }
 
 void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
@@ -40,6 +41,14 @@ void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
                // in case there are more timeouts.
        }
 
+       // In case of restarts.
+       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);
+               last_seq = seq - 1;
+       }
+
        GREPacket packet;
        packet.seq = seq;
        packet.proto = proto;
@@ -66,6 +75,7 @@ void Reorderer::send_packet(uint16_t proto, const string& data, int seq)
                sender->send_packet(proto, data, seq);
                packet_buffer.pop();
                last_seq = front_seq;
+               last_sent_packet = now;
                if (!silence && !packet_buffer.empty()) {
                        printf("Reordering with packet buffer size %d: seq=%d new_front_seq=%d\n", int(packet_buffer.size()), front_seq, packet_buffer.top().seq);
                        silence = true;
index f58a9327673ac1850c67b8e5f4b91ae5d72eb1f4..0007a2bcd00314779818bff24a7b577ba4057781 100644 (file)
@@ -34,6 +34,7 @@ private:
 
        Sender* sender;
        int last_seq;
+       timeval last_sent_packet;
 
        std::priority_queue<GREPacket, std::vector<GREPacket>, std::greater<GREPacket>> packet_buffer;
        std::map<int, int> ccs;