X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FCongestionControl.hpp;h=76f98f61d08173189952b33274398068bfb0af35;hb=f506afdcb23fed22f2c7f345b94cb411487f89c9;hp=73d1d859ec0aaed8cafdcd8ba448786a7b047e0f;hpb=a957788426ff011acf662e29ec5fc0525c1a578f;p=blank.git diff --git a/src/net/CongestionControl.hpp b/src/net/CongestionControl.hpp index 73d1d85..76f98f6 100644 --- a/src/net/CongestionControl.hpp +++ b/src/net/CongestionControl.hpp @@ -9,9 +9,23 @@ namespace blank { class CongestionControl { +public: + enum Mode { + GOOD, + BAD, + UGLY, + }; + public: CongestionControl(); + /// get recommended mode of operation + Mode GetMode() const noexcept { return mode; } + /// according to current mode, drop this many unimportant packets + unsigned int SuggestedPacketSkip() const noexcept { return (1 << mode) - 1; } + /// according to current mode, pause between large uncritical packets for this many ticks + unsigned int SuggestedPacketHold() const noexcept { return (1 << (mode + 1)) - 1; } + /// packet loss as factor float PacketLoss() const noexcept { return packet_loss; } /// smooth average round trip time in milliseconds @@ -30,11 +44,20 @@ public: private: void UpdatePacketLoss() noexcept; + void UpdateRTT(std::uint16_t) noexcept; bool SamplePacket(std::uint16_t) const noexcept; - int HeadDiff(std::uint16_t) const noexcept; + std::size_t SampleIndex(std::uint16_t) const noexcept; + void UpdateStats() noexcept; + void UpdateMode() noexcept; + void CheckUpgrade(Mode) noexcept; + void ChangeMode(Mode) noexcept; + void KeepMode() noexcept; + + Mode Conditions() const noexcept; + private: const unsigned int packet_overhead; const unsigned int sample_skip; @@ -44,7 +67,6 @@ private: float packet_loss; Uint32 stamps[16]; - std::size_t stamp_cursor; std::uint16_t stamp_last; float rtt; @@ -54,6 +76,16 @@ private: float tx_kbps; float rx_kbps; + Mode mode; + float bad_rtt; + float bad_loss; + float ugly_rtt; + float ugly_loss; + Uint32 mode_entered; + Uint32 mode_reset; + Uint32 mode_keep_time; + Uint32 mode_step; + }; }