1 #ifndef BLANK_NET_CONGESTIONCONTROL_HPP_
2 #define BLANK_NET_CONGESTIONCONTROL_HPP_
10 class CongestionControl {
22 /// get recommended mode of operation
23 Mode GetMode() const noexcept { return mode; }
24 /// according to current mode, drop this many unimportant packets
25 unsigned int SuggestedPacketSkip() const noexcept { return (1 << mode) - 1; }
26 /// according to current mode, pause between large uncritical packets for this many ticks
27 unsigned int SuggestedPacketHold() const noexcept { return (1 << (mode + 1)) - 1; }
29 /// packet loss as factor
30 float PacketLoss() const noexcept { return packet_loss; }
31 /// smooth average round trip time in milliseconds
32 float RoundTripTime() const noexcept { return rtt; }
33 /// estimated kilobytes transferred per second
34 float Upstream() const noexcept { return tx_kbps; }
35 /// estimated kilobytes received per second
36 float Downstream() const noexcept { return rx_kbps; }
38 void PacketSent(std::uint16_t) noexcept;
39 void PacketLost(std::uint16_t) noexcept;
40 void PacketReceived(std::uint16_t) noexcept;
42 void PacketIn(const UDPpacket &) noexcept;
43 void PacketOut(const UDPpacket &) noexcept;
46 void UpdatePacketLoss() noexcept;
48 void UpdateRTT(std::uint16_t) noexcept;
49 bool SamplePacket(std::uint16_t) const noexcept;
50 std::size_t SampleIndex(std::uint16_t) const noexcept;
52 void UpdateStats() noexcept;
54 void UpdateMode() noexcept;
55 void CheckUpgrade(Mode) noexcept;
56 void ChangeMode(Mode) noexcept;
57 void KeepMode() noexcept;
59 Mode Conditions() const noexcept;
62 const unsigned int packet_overhead;
63 const unsigned int sample_skip;
65 unsigned int packets_lost;
66 unsigned int packets_received;
70 std::uint16_t stamp_last;
86 Uint32 mode_keep_time;