X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fnet%2FCongestionControl.hpp;h=7d4bacacb39a55d1e34dd5aae73367f0af678c06;hb=b4e5dad2ed5c7e77573de413f3bf5be88577856d;hp=73d1d859ec0aaed8cafdcd8ba448786a7b047e0f;hpb=a957788426ff011acf662e29ec5fc0525c1a578f;p=blank.git diff --git a/src/net/CongestionControl.hpp b/src/net/CongestionControl.hpp index 73d1d85..7d4baca 100644 --- a/src/net/CongestionControl.hpp +++ b/src/net/CongestionControl.hpp @@ -9,9 +9,21 @@ 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; } + /// packet loss as factor float PacketLoss() const noexcept { return packet_loss; } /// smooth average round trip time in milliseconds @@ -30,11 +42,19 @@ 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; + 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; @@ -54,6 +74,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; + }; }