]> git.localhorst.tv Git - blank.git/commitdiff
also tell connection handlers about ack'd packets
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 7 Sep 2015 14:37:43 +0000 (16:37 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 7 Sep 2015 14:37:43 +0000 (16:37 +0200)
src/net/ConnectionHandler.hpp
src/net/Packet.hpp
src/net/net.cpp

index 29595e5061e01c9bac2a8671158191cd6e768d68..ab9761af3d30391abca9ae640740d63918ef1ff5 100644 (file)
@@ -13,6 +13,9 @@ class ConnectionHandler {
 public:
        void Handle(const UDPpacket &);
 
+       // called as soon as the remote end ack'd given packet
+       virtual void OnPacketReceived(std::uint16_t) { }
+       // called if the remote end probably didn't get given packet
        virtual void OnPacketLost(std::uint16_t) { }
 
        virtual void OnTimeout() { }
index 0dab9495fef9327e40ce7cd8e5283d4c4e8ab207..4ff45df53b6e5a136310b57991087b3249d35549 100644 (file)
@@ -21,6 +21,11 @@ struct Packet {
                std::uint16_t seq;
                std::uint16_t ack;
                std::uint32_t hist;
+
+               // true if this contains an ack for given (remote) seq
+               bool Acks(std::uint16_t) const noexcept;
+               std::uint16_t AckBegin() const noexcept { return ack; }
+               std::uint16_t AckEnd() const noexcept { return ack + std::uint16_t(33); }
        };
 
        struct Header {
index 837a7fb18125dccf52b7ea4e8eca491e5d27b566..18761572bd13364cb10cddd6a2ac410c5d6b4b2d 100644 (file)
@@ -271,10 +271,23 @@ void Connection::Received(const UDPpacket &udp_pack) {
                                }
                        }
                }
+               // check for newly ack'd packets
+               for (uint16_t s = ctrl_new.AckBegin(); s != ctrl_new.AckEnd(); ++s) {
+                       if (ctrl_new.Acks(s) && !ctrl_in.Acks(s)) {
+                               Handler().OnPacketReceived(s);
+                       }
+               }
                ctrl_in = ctrl_new;
        }
 }
 
+bool Packet::TControl::Acks(uint16_t s) const noexcept {
+       int16_t diff = int16_t(ack) - int16_t(s);
+       if (diff == 0) return true;
+       if (diff < 0 || diff > 32) return false;
+       return (hist & (1 << (diff - 1))) != 0;
+}
+
 uint16_t Connection::SendPing(UDPpacket &udp_pack, UDPsocket sock) {
        Packet::Make<Packet::Ping>(udp_pack);
        return Send(udp_pack, sock);