6#include <aegis2d/net/export.hpp>
57 using Clock = std::chrono::steady_clock;
65 Clock::time_point now)
noexcept;
71 void record(
Direction direction, std::size_t bytes, Clock::time_point now)
noexcept;
89 Clock::time_point now)
const noexcept;
97 Clock::time_point now)
const noexcept;
101 static constexpr std::size_t slots = 8;
102 using Table = std::array<std::array<TrafficCount, slots>, 2>;
104 void count(
Direction direction, std::size_t slot, std::size_t bytes,
105 Clock::time_point now)
noexcept;
107 Clock::time_point now)
const noexcept;
112 Clock::time_point window_start_{};
113 bool started_ =
false;
Counts the datagrams exchanged with one peer, by direction and packet type.
Definition traffic.hpp:54
void record(Direction direction, PacketType type, std::size_t bytes, Clock::time_point now) noexcept
Records a datagram whose header was read.
TrafficCount last_second(Direction direction, Clock::time_point now) const noexcept
Every datagram of a direction during the last whole second.
TrafficCount last_second(Direction direction, PacketType type, Clock::time_point now) const noexcept
The datagrams of one type and direction during the last whole second.
void record(Direction direction, std::size_t bytes, Clock::time_point now) noexcept
Records a datagram of unknown type, such as one too short for a header.
TrafficCount total(Direction direction) const noexcept
Every datagram of a direction since the counters were created.
TrafficCount total(Direction direction, PacketType type) const noexcept
The datagrams of one type and direction since the counters were created.
std::chrono::steady_clock Clock
Clock of the one-second windows.
Definition traffic.hpp:57
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
Direction
Way a datagram went.
Definition traffic.hpp:17
@ Received
Received from the peer.
PacketType
What a datagram carries; stored on one byte after the version.
Definition packet.hpp:22
Header carried by every UDP datagram, and the packet types.
A number of datagrams and the bytes they hold.
Definition traffic.hpp:25
std::uint64_t datagrams
Datagrams.
Definition traffic.hpp:27
std::uint64_t bytes
Bytes of the datagrams, the 18-byte header included; the IP and UDP headers (28 bytes in IPv4,...
Definition traffic.hpp:30
TrafficCount & operator+=(const TrafficCount &other) noexcept
Adds another count.
Definition traffic.hpp:35
bool operator==(const TrafficCount &) const =default
Field-by-field equality.