R-Type 0.1
Loading...
Searching...
No Matches
Connection Class Reference

State the server keeps for one connected client. More...

#include <connection/Connection.hpp>

Public Member Functions

 Connection (std::uint32_t id, const asio::ip::udp::endpoint &endpoint)
 Creates a connection bound to a client address.
 
std::uint32_t getId () const
 Returns the connection id.
 
const asio::ip::udp::endpoint & getEndpoint () const
 Returns the client address.
 
PacketHeader makeHeader ()
 Builds the header of the next outgoing packet.
 
PacketReceiveRes onPacketReceived (const PacketHeader &header)
 Records an incoming packet in the acknowledgement state.
 

Detailed Description

State the server keeps for one connected client.

Constructor & Destructor Documentation

◆ Connection()

Connection::Connection ( std::uint32_t id,
const asio::ip::udp::endpoint & endpoint )

Creates a connection bound to a client address.

Parameters
idConnection id given to the client.
endpointClient address and port.

Member Function Documentation

◆ getId()

std::uint32_t Connection::getId ( ) const

Returns the connection id.

Returns
The id sent to the client in Welcome.

◆ getEndpoint()

const asio::ip::udp::endpoint & Connection::getEndpoint ( ) const

Returns the client address.

Returns
The endpoint the connection is bound to.

◆ makeHeader()

PacketHeader Connection::makeHeader ( )

Builds the header of the next outgoing packet.

Returns
A header with a fresh sequence number and the current acks.

◆ onPacketReceived()

PacketReceiveRes Connection::onPacketReceived ( const PacketHeader & header)

Records an incoming packet in the acknowledgement state.

Parameters
headerHeader of the received packet.
Returns
Whether the packet is new, duplicated, out of order or too old.