vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::NetConnection Class Reference

One end of one conversation: sequencing, acknowledgement and timing. More...

#include <connection.h>

Public Member Functions

void open (const NetAddress &peer)
 Point this at peer. Resets everything the last one left.
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.
void refuse ()
 Take back the acknowledgement for the packet just accepted.
void advance (float seconds)
 Age the silence timer and every unacknowledged packet by seconds of wall clock.
uint16_t nextSequence () const
 What frame() will stamp on the next packet.
float roundTrip () const
 Round trip, smoothed.
float lossFraction () const
 What fraction of the peer's packets never arrived, so far.
float roundTripVariation () const
 How much that trip varies, smoothed the same way.

Static Public Attributes

static constexpr size_t HEADER_BYTES = 8
 Bytes of header on every packet: sequence, acknowledgement, and the bitfield of the thirty-two before it.
static constexpr size_t MAX_PAYLOAD = UdpSocket::MAX_DATAGRAM - HEADER_BYTES
 The most one packet carries past its header: what a datagram leaves.
static constexpr float TIMEOUT_SECONDS = 5.0f
 How long silence lasts before a peer is given up on.
static constexpr uint16_t NO_SEQUENCE = 0
 The sequence number nothing ever sends, so a header can say "nothing".

Detailed Description

One end of one conversation: sequencing, acknowledgement and timing.

Every packet carries its sequence, the newest seen the other way, and a bitfield of the thirty-two before that.

Nothing is retransmitted: the next packet says it again, newer. Acknowledgement measures the trip and what a peer holds. A packet older than one already seen is refused, or the world would mix two moments.

Member Function Documentation

◆ frame()

void Vkm::Engine::NetConnection::frame ( const uint8_t * payload,
size_t size,
std::vector< uint8_t > & out )

Wrap payload in a header and hand it back for sending.

The caller owns the socket, which serves every peer of a server.

Parameters
payloadWhat to carry; may be empty, which is a keep-alive.
sizeIts length.
outFilled with header followed by payload.

◆ accept()

bool Vkm::Engine::NetConnection::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.

Parameters
bytesThe whole datagram, header included.
sizeIts length.
payloadFilled with what rode inside it.
acknowledgedAppended with the sequences this datagram confirms, each reported once only.
Returns
False when it is malformed, or older than one already seen.

◆ refuse()

void Vkm::Engine::NetConnection::refuse ( )

Take back the acknowledgement for the packet just accepted.

A sender reads an acknowledgement as the payload taken (see NetBaseline::confirm), so one that would not decode is un-seen here and described again.

◆ nextSequence()

uint16_t Vkm::Engine::NetConnection::nextSequence ( ) const
inline

What frame() will stamp on the next packet.

For a sender that must remember what that packet claimed.

Returns
The next outgoing sequence.

◆ roundTrip()

float Vkm::Engine::NetConnection::roundTrip ( ) const
inline

Round trip, smoothed.

Returns
Seconds; zero until an acknowledgement has been timed.

◆ lossFraction()

float Vkm::Engine::NetConnection::lossFraction ( ) const
inline

What fraction of the peer's packets never arrived, so far.

Counted from gaps in its sequence numbering; zero until something arrives.

Returns
Lost over sent, in [0, 1).

Member Data Documentation

◆ NO_SEQUENCE

uint16_t Vkm::Engine::NetConnection::NO_SEQUENCE = 0
staticconstexpr

The sequence number nothing ever sends, so a header can say "nothing".

A sender skips it, on the first packet and on every wrap.


The documentation for this class was generated from the following file: