group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
net::UdpSessionTransport Class Reference

#include <UdpSessionTransport.hpp>

Collaboration diagram for net::UdpSessionTransport:
[legend]

Classes

struct  Event
struct  Stats
struct  RelayConfig
struct  PunchAssist
 Direct UDP hole-punch assist for global joins. More...
struct  PendingReliable
struct  ChannelState
struct  Peer

Public Types

enum class  Mode { Client , Server }
enum class  EventType { Connected , Payload , Disconnected , DirectoryControl }

Public Member Functions

 UdpSessionTransport ()
 UdpSessionTransport (const UdpSessionTransport &)=delete
UdpSessionTransportoperator= (const UdpSessionTransport &)=delete
 ~UdpSessionTransport ()
bool openServer (const char *bindAddr, Uint16 port)
bool connectClient (const char *host, Uint16 port, int timeoutMs)
void close ()
void setRelayConfig (const RelayConfig &cfg)
void setPunchAssist (PunchAssist assist)
void preferRelay (bool enabled)
bool pollEvent (Event &out)
void pump ()
bool send (std::uint64_t connectionId, ChannelId channel, const void *payload, int payloadLen, int redundancy=1)
bool disconnect (std::uint64_t connectionId)
bool isOpen () const noexcept
bool isClientConnected () const noexcept
std::uint64_t clientConnectionId () const noexcept
std::uint32_t clientNonce () const noexcept
Uint16 localPort () const noexcept
 Get the local UDP port used by this session transport.
const Statsstats () const noexcept
bool sendDirectoryControl (const UdpEndpointAddr &dest, const void *payload, int payloadLen)
 Send a directory-control payload from the same UDP socket.

Private Member Functions

bool resolveAddress (const char *host, Uint16 port, UdpEndpointAddr &out, int timeoutMs)
void queueEvent (Event &&event)
PeerfindPeer (std::uint64_t connectionId)
PeercreateServerPeer (const UdpEndpointAddr &from, std::uint32_t clientNonce, bool viaRelay)
void sendConnectionRequest (bool viaRelay)
void sendConnectionAccepted (Peer &peer)
bool sendPacket (Peer &peer, PacketHeader hdr, const void *payload, int payloadLen, int redundancy)
bool sendViaRelay (Peer &peer, PacketHeader hdr, const void *payload, int payloadLen)
bool sendDirect (const UdpEndpointAddr &dest, PacketHeader hdr, const void *payload, int payloadLen, int redundancy)
void processDatagram (UdpReceivedMessage &msg, bool viaRelay)
void processRelayPayload (UdpReceivedMessage &msg)
void processPayload (Peer &peer, PacketHeader hdr, std::vector< std::uint8_t > &&payload, bool viaRelay)
void processAcks (Peer &peer, const PacketHeader &hdr)
void rememberReceived (ChannelState &state, std::uint32_t sequence)
bool acceptUnreliableSequenced (ChannelState &state, std::uint32_t sequence)
void deliverReliable (Peer &peer, ChannelId channel, std::uint32_t sequence, std::vector< std::uint8_t > &&payload, bool viaRelay)
void retransmitReliable (Uint64 nowMs)
void sendKeepAlives (Uint64 nowMs)
void dropTimedOutPeers (Uint64 nowMs)

Static Private Member Functions

static std::size_t channelIndex (ChannelId channel) noexcept
static bool isKnownChannel (std::uint8_t channel) noexcept
static bool isReliable (ChannelId channel) noexcept
static bool seqMoreRecent (std::uint32_t s1, std::uint32_t s2) noexcept
static bool seqAcked (std::uint32_t seq, std::uint32_t ack, std::uint32_t ackBits) noexcept

Private Attributes

Mode mode_ = Mode::Client
UdpEndpoint endpoint_
UdpEndpointAddr serverAddr_
UdpEndpointAddr relayAddr_
RelayConfig relayConfig_
PunchAssist punchAssist_
UdpEndpointAddr punchDirectoryAddr_
bool preferRelay_ = false
std::uint32_t clientNonce_ = 0
std::uint64_t clientConnectionId_ = 0
Uint64 lastConnectAttemptMs_ = 0
std::mt19937_64 rng_
std::unordered_map< std::uint64_t, Peerpeers_
std::unordered_map< std::uint32_t, std::uint64_t > connectionByClientNonce_
std::deque< Eventevents_
Stats stats_

Static Private Attributes

static constexpr Uint64 k_keepAliveMs = 1000
static constexpr Uint64 k_routeUnhealthyMs = 3000
static constexpr Uint64 k_timeoutMs = 5000
static constexpr Uint64 k_retransmitFloorMs = 80
static constexpr std::size_t k_maxPeers = 128
static constexpr std::size_t k_maxQueuedEvents = 1024
static constexpr std::size_t k_maxReliablePending = 256
static constexpr std::size_t k_maxReliableOrderedBuffer = 256

Member Enumeration Documentation

◆ EventType

Enumerator
Connected 
Payload 
Disconnected 
DirectoryControl 

◆ Mode

enum class net::UdpSessionTransport::Mode
strong
Enumerator
Client 
Server 

Constructor & Destructor Documentation

◆ UdpSessionTransport() [1/2]

net::UdpSessionTransport::UdpSessionTransport ( )
Here is the caller graph for this function:

◆ UdpSessionTransport() [2/2]

net::UdpSessionTransport::UdpSessionTransport ( const UdpSessionTransport & )
delete
Here is the call graph for this function:

◆ ~UdpSessionTransport()

net::UdpSessionTransport::~UdpSessionTransport ( )
inline
Here is the call graph for this function:

Member Function Documentation

◆ acceptUnreliableSequenced()

bool net::UdpSessionTransport::acceptUnreliableSequenced ( ChannelState & state,
std::uint32_t sequence )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ channelIndex()

std::size_t net::UdpSessionTransport::channelIndex ( ChannelId channel)
staticnodiscardprivatenoexcept
Here is the caller graph for this function:

◆ clientConnectionId()

std::uint64_t net::UdpSessionTransport::clientConnectionId ( ) const
inlinenodiscardnoexcept

◆ clientNonce()

std::uint32_t net::UdpSessionTransport::clientNonce ( ) const
inlinenodiscardnoexcept
Here is the caller graph for this function:

◆ close()

void net::UdpSessionTransport::close ( )
Here is the caller graph for this function:

◆ connectClient()

bool net::UdpSessionTransport::connectClient ( const char * host,
Uint16 port,
int timeoutMs )
Here is the call graph for this function:

◆ createServerPeer()

UdpSessionTransport::Peer * net::UdpSessionTransport::createServerPeer ( const UdpEndpointAddr & from,
std::uint32_t clientNonce,
bool viaRelay )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deliverReliable()

void net::UdpSessionTransport::deliverReliable ( Peer & peer,
ChannelId channel,
std::uint32_t sequence,
std::vector< std::uint8_t > && payload,
bool viaRelay )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

bool net::UdpSessionTransport::disconnect ( std::uint64_t connectionId)
Here is the call graph for this function:

◆ dropTimedOutPeers()

void net::UdpSessionTransport::dropTimedOutPeers ( Uint64 nowMs)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findPeer()

UdpSessionTransport::Peer * net::UdpSessionTransport::findPeer ( std::uint64_t connectionId)
private
Here is the caller graph for this function:

◆ isClientConnected()

bool net::UdpSessionTransport::isClientConnected ( ) const
inlinenodiscardnoexcept

◆ isKnownChannel()

bool net::UdpSessionTransport::isKnownChannel ( std::uint8_t channel)
staticnodiscardprivatenoexcept
Here is the caller graph for this function:

◆ isOpen()

bool net::UdpSessionTransport::isOpen ( ) const
inlinenodiscardnoexcept

◆ isReliable()

bool net::UdpSessionTransport::isReliable ( ChannelId channel)
staticnodiscardprivatenoexcept
Here is the caller graph for this function:

◆ localPort()

Uint16 net::UdpSessionTransport::localPort ( ) const
inlinenodiscardnoexcept

Get the local UDP port used by this session transport.

◆ openServer()

bool net::UdpSessionTransport::openServer ( const char * bindAddr,
Uint16 port )
Here is the call graph for this function:

◆ operator=()

UdpSessionTransport & net::UdpSessionTransport::operator= ( const UdpSessionTransport & )
delete
Here is the call graph for this function:

◆ pollEvent()

bool net::UdpSessionTransport::pollEvent ( Event & out)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ preferRelay()

void net::UdpSessionTransport::preferRelay ( bool enabled)
inline

◆ processAcks()

void net::UdpSessionTransport::processAcks ( Peer & peer,
const PacketHeader & hdr )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processDatagram()

void net::UdpSessionTransport::processDatagram ( UdpReceivedMessage & msg,
bool viaRelay )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processPayload()

void net::UdpSessionTransport::processPayload ( Peer & peer,
PacketHeader hdr,
std::vector< std::uint8_t > && payload,
bool viaRelay )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processRelayPayload()

void net::UdpSessionTransport::processRelayPayload ( UdpReceivedMessage & msg)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pump()

void net::UdpSessionTransport::pump ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ queueEvent()

void net::UdpSessionTransport::queueEvent ( Event && event)
private
Here is the caller graph for this function:

◆ rememberReceived()

void net::UdpSessionTransport::rememberReceived ( ChannelState & state,
std::uint32_t sequence )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resolveAddress()

bool net::UdpSessionTransport::resolveAddress ( const char * host,
Uint16 port,
UdpEndpointAddr & out,
int timeoutMs )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ retransmitReliable()

void net::UdpSessionTransport::retransmitReliable ( Uint64 nowMs)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

bool net::UdpSessionTransport::send ( std::uint64_t connectionId,
ChannelId channel,
const void * payload,
int payloadLen,
int redundancy = 1 )
Here is the call graph for this function:

◆ sendConnectionAccepted()

void net::UdpSessionTransport::sendConnectionAccepted ( Peer & peer)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendConnectionRequest()

void net::UdpSessionTransport::sendConnectionRequest ( bool viaRelay)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendDirect()

bool net::UdpSessionTransport::sendDirect ( const UdpEndpointAddr & dest,
PacketHeader hdr,
const void * payload,
int payloadLen,
int redundancy )
private
Here is the caller graph for this function:

◆ sendDirectoryControl()

bool net::UdpSessionTransport::sendDirectoryControl ( const UdpEndpointAddr & dest,
const void * payload,
int payloadLen )

Send a directory-control payload from the same UDP socket.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendKeepAlives()

void net::UdpSessionTransport::sendKeepAlives ( Uint64 nowMs)
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPacket()

bool net::UdpSessionTransport::sendPacket ( Peer & peer,
PacketHeader hdr,
const void * payload,
int payloadLen,
int redundancy )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendViaRelay()

bool net::UdpSessionTransport::sendViaRelay ( Peer & peer,
PacketHeader hdr,
const void * payload,
int payloadLen )
private
Here is the call graph for this function:
Here is the caller graph for this function:

◆ seqAcked()

bool net::UdpSessionTransport::seqAcked ( std::uint32_t seq,
std::uint32_t ack,
std::uint32_t ackBits )
staticnodiscardprivatenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ seqMoreRecent()

bool net::UdpSessionTransport::seqMoreRecent ( std::uint32_t s1,
std::uint32_t s2 )
staticnodiscardprivatenoexcept
Here is the caller graph for this function:

◆ setPunchAssist()

void net::UdpSessionTransport::setPunchAssist ( PunchAssist assist)

◆ setRelayConfig()

void net::UdpSessionTransport::setRelayConfig ( const RelayConfig & cfg)
Here is the call graph for this function:

◆ stats()

const Stats & net::UdpSessionTransport::stats ( ) const
inlinenodiscardnoexcept

Member Data Documentation

◆ clientConnectionId_

std::uint64_t net::UdpSessionTransport::clientConnectionId_ = 0
private

◆ clientNonce_

std::uint32_t net::UdpSessionTransport::clientNonce_ = 0
private

◆ connectionByClientNonce_

std::unordered_map<std::uint32_t, std::uint64_t> net::UdpSessionTransport::connectionByClientNonce_
private

◆ endpoint_

UdpEndpoint net::UdpSessionTransport::endpoint_
private

◆ events_

std::deque<Event> net::UdpSessionTransport::events_
private

◆ k_keepAliveMs

Uint64 net::UdpSessionTransport::k_keepAliveMs = 1000
staticconstexprprivate

◆ k_maxPeers

std::size_t net::UdpSessionTransport::k_maxPeers = 128
staticconstexprprivate

◆ k_maxQueuedEvents

std::size_t net::UdpSessionTransport::k_maxQueuedEvents = 1024
staticconstexprprivate

◆ k_maxReliableOrderedBuffer

std::size_t net::UdpSessionTransport::k_maxReliableOrderedBuffer = 256
staticconstexprprivate

◆ k_maxReliablePending

std::size_t net::UdpSessionTransport::k_maxReliablePending = 256
staticconstexprprivate

◆ k_retransmitFloorMs

Uint64 net::UdpSessionTransport::k_retransmitFloorMs = 80
staticconstexprprivate

◆ k_routeUnhealthyMs

Uint64 net::UdpSessionTransport::k_routeUnhealthyMs = 3000
staticconstexprprivate

◆ k_timeoutMs

Uint64 net::UdpSessionTransport::k_timeoutMs = 5000
staticconstexprprivate

◆ lastConnectAttemptMs_

Uint64 net::UdpSessionTransport::lastConnectAttemptMs_ = 0
private

◆ mode_

Mode net::UdpSessionTransport::mode_ = Mode::Client
private

◆ peers_

std::unordered_map<std::uint64_t, Peer> net::UdpSessionTransport::peers_
private

◆ preferRelay_

bool net::UdpSessionTransport::preferRelay_ = false
private

◆ punchAssist_

PunchAssist net::UdpSessionTransport::punchAssist_
private

◆ punchDirectoryAddr_

UdpEndpointAddr net::UdpSessionTransport::punchDirectoryAddr_
private

◆ relayAddr_

UdpEndpointAddr net::UdpSessionTransport::relayAddr_
private

◆ relayConfig_

RelayConfig net::UdpSessionTransport::relayConfig_
private

◆ rng_

std::mt19937_64 net::UdpSessionTransport::rng_
private

◆ serverAddr_

UdpEndpointAddr net::UdpSessionTransport::serverAddr_
private

◆ stats_

Stats net::UdpSessionTransport::stats_
private

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