7#include "net/wire/protocol.h"
8#include "platform/net/net_address.h"
9#include "platform/net/udp_socket.h"
11namespace Vkm::Engine {
22bool isNewerSequence(uint16_t a, uint16_t b);
60 NetConnection() =
default;
61 ~NetConnection() =
default;
63 NetConnection(
const NetConnection& other) =
delete;
64 NetConnection& operator=(
const NetConnection& other) =
delete;
66 NetConnection(NetConnection && other) =
delete;
67 NetConnection& operator=(NetConnection && other) =
delete;
82 void frame(
const uint8_t* payload,
size_t size, std::vector<uint8_t>& out);
97 std::vector<uint8_t>& payload,
98 std::vector<uint16_t>& acknowledged
140 const uint64_t seen = m_arrived + m_missed;
141 return seen == 0 ? 0.0f :
static_cast<float>(m_missed) /
static_cast<float>(seen);
147 const NetAddress& peer()
const {
return m_peer; }
154 uint16_t sequence = 0;
159 void recordTrip(uint16_t acknowledged, std::vector<uint16_t>& reported);
165 uint16_t m_newest = 0;
167 bool m_heard =
false;
169 uint16_t m_wasNewest = 0;
170 uint32_t m_wasSeen = 0;
171 bool m_wasHeard =
false;
173 float m_silent = 0.0f;
175 uint64_t m_arrived = 0;
176 uint64_t m_missed = 0;
178 float m_roundTrip = 0.0f;
179 float m_variation = 0.0f;
181 std::vector<Sent> m_sent;
static constexpr uint16_t NO_SEQUENCE
The sequence number nothing ever sends, so a header can say "nothing".
Definition connection.h:57
static constexpr size_t HEADER_BYTES
Bytes of header on every packet: sequence, acknowledgement, and the bitfield of the thirty-two before...
Definition connection.h:40
uint16_t nextSequence() const
What frame() will stamp on the next packet.
Definition connection.h:123
void frame(const uint8_t *payload, size_t size, std::vector< uint8_t > &out)
Wrap payload in a header and hand it back for sending.
bool accept(const uint8_t *bytes, size_t size, std::vector< uint8_t > &payload, std::vector< uint16_t > &acknowledged)
Take a datagram that arrived from this peer.
static constexpr float MAX_SILENCE_A_FRAME
Definition connection.h:50
float roundTrip() const
Round trip, smoothed.
Definition connection.h:130
void refuse()
Take back the acknowledgement for the packet just accepted.
float lossFraction() const
What fraction of the peer's packets never arrived, so far.
Definition connection.h:139
void advance(float seconds)
static constexpr float TIMEOUT_SECONDS
How long silence lasts before a peer is given up on.
Definition connection.h:46
static constexpr size_t MAX_PAYLOAD
The most one packet carries past its header: what a datagram leaves.
Definition connection.h:43
void open(const NetAddress &peer)
Point this at peer. Resets everything the last one left.
float roundTripVariation() const
How much that trip varies, smoothed the same way.
Definition connection.h:145
static constexpr size_t MAX_DATAGRAM
The largest datagram this will send.
Definition udp_socket.h:26
Where a datagram came from, or is going to: an IPv4 host and a port.
Definition net_address.h:13