Minetest  5.4.0
con::Connection Class Reference

#include <connection.h>

+ Collaboration diagram for con::Connection:

Public Member Functions

 Connection (u32 protocol_id, u32 max_packet_size, float timeout, bool ipv6, PeerHandler *peerhandler)
 
 ~Connection ()
 
ConnectionEvent waitEvent (u32 timeout_ms)
 
void putCommand (ConnectionCommand &c)
 
void SetTimeoutMs (u32 timeout)
 
void Serve (Address bind_addr)
 
void Connect (Address address)
 
bool Connected ()
 
void Disconnect ()
 
void Receive (NetworkPacket *pkt)
 
bool TryReceive (NetworkPacket *pkt)
 
void Send (session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable)
 
session_t GetPeerID () const
 
Address GetPeerAddress (session_t peer_id)
 
float getPeerStat (session_t peer_id, rtt_stat_type type)
 
float getLocalStat (rate_stat_type type)
 
const u32 GetProtocolID () const
 
const std::string getDesc ()
 
void DisconnectPeer (session_t peer_id)
 

Protected Member Functions

PeerHelper getPeerNoEx (session_t peer_id)
 
u16 lookupPeer (Address &sender)
 
u16 createPeer (Address &sender, MTProtocols protocol, int fd)
 
UDPPeercreateServerPeer (Address &sender)
 
bool deletePeer (session_t peer_id, bool timeout)
 
void SetPeerID (session_t id)
 
void sendAck (session_t peer_id, u8 channelnum, u16 seqnum)
 
void PrintInfo (std::ostream &out)
 
std::vector< session_tgetPeerIDs ()
 
bool Receive (NetworkPacket *pkt, u32 timeout)
 
void putEvent (ConnectionEvent &e)
 
void TriggerSend ()
 
bool ConnectedToServer ()
 

Protected Attributes

UDPSocket m_udpSocket
 
MutexedQueue< ConnectionCommandm_command_queue
 

Private Attributes

MutexedQueue< ConnectionEventm_event_queue
 
session_t m_peer_id = 0
 
u32 m_protocol_id
 
std::map< session_t, Peer * > m_peers
 
std::vector< session_tm_peer_ids
 
std::mutex m_peers_mutex
 
std::unique_ptr< ConnectionSendThreadm_sendThread
 
std::unique_ptr< ConnectionReceiveThreadm_receiveThread
 
std::mutex m_info_mutex
 
PeerHandlerm_bc_peerhandler
 
u32 m_bc_receive_timeout = 0
 
bool m_shutting_down = false
 
session_t m_next_remote_peer_id = 2
 

Friends

class ConnectionSendThread
 
class ConnectionReceiveThread
 

Constructor & Destructor Documentation

◆ Connection()

con::Connection::Connection ( u32  protocol_id,
u32  max_packet_size,
float  timeout,
bool  ipv6,
PeerHandler peerhandler 
)

References m_receiveThread, m_sendThread, m_udpSocket, and UDPSocket::setTimeoutMs().

+ Here is the call graph for this function:

◆ ~Connection()

con::Connection::~Connection ( )

Member Function Documentation

◆ Connect()

void con::Connection::Connect ( Address  address)

References con::ConnectionCommand::connect(), and putCommand().

+ Here is the call graph for this function:

◆ Connected()

bool con::Connection::Connected ( )

◆ ConnectedToServer()

bool con::Connection::ConnectedToServer ( )
inlineprotected

References getPeerNoEx(), and PEER_ID_SERVER.

Referenced by createServerPeer(), and con::ConnectionReceiveThread::receive().

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

◆ createPeer()

u16 con::Connection::createPeer ( Address sender,
MTProtocols  protocol,
int  fd 
)
protected

References CONTROLTYPE_SET_PEER_ID, con::ConnectionCommand::createPeer(), dout_con, errorstream, getDesc(), con::Peer::id, LOG, m_next_remote_peer_id, m_peer_ids, m_peers, m_peers_mutex, MAX_UDP_PEERS, con::PACKET_TYPE_CONTROL, PEER_ID_INEXISTENT, con::ConnectionEvent::peerAdded(), putCommand(), putEvent(), writeU16(), and writeU8().

Referenced by con::ConnectionReceiveThread::receive().

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

◆ createServerPeer()

UDPPeer * con::Connection::createServerPeer ( Address sender)
protected

References ConnectedToServer(), con::Peer::id, m_peer_ids, m_peers, m_peers_mutex, and PEER_ID_SERVER.

Referenced by con::ConnectionSendThread::connect().

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

◆ deletePeer()

bool con::Connection::deletePeer ( session_t  peer_id,
bool  timeout 
)
protected

References con::Peer::Drop(), con::Peer::getAddress(), m_peer_ids, m_peers, m_peers_mutex, con::MTP_PRIMARY, con::ConnectionEvent::peerRemoved(), and putEvent().

Referenced by con::ConnectionReceiveThread::handlePacketType_Control(), con::ConnectionSendThread::runTimeouts(), and con::ConnectionSendThread::sendPackets().

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

◆ Disconnect()

void con::Connection::Disconnect ( )

References con::ConnectionCommand::disconnect(), and putCommand().

+ Here is the call graph for this function:

◆ DisconnectPeer()

void con::Connection::DisconnectPeer ( session_t  peer_id)

References con::ConnectionCommand::disconnect_peer(), and putCommand().

+ Here is the call graph for this function:

◆ getDesc()

const std::string con::Connection::getDesc ( )

References UDPSocket::GetHandle(), itos(), m_peer_id, and m_udpSocket.

Referenced by con::ConnectionReceiveThread::checkIncomingBuffers(), con::ConnectionSendThread::connect(), createPeer(), con::ConnectionSendThread::disconnect(), con::ConnectionSendThread::disconnect_peer(), con::Peer::Drop(), con::ConnectionReceiveThread::handlePacketType_Control(), con::ConnectionReceiveThread::handlePacketType_Original(), con::ConnectionReceiveThread::handlePacketType_Reliable(), con::ConnectionReceiveThread::handlePacketType_Split(), PrintInfo(), con::ConnectionSendThread::processNonReliableCommand(), con::ConnectionReceiveThread::processPacket(), con::ConnectionSendThread::processReliableCommand(), con::UDPPeer::processReliableSendCommand(), con::UDPPeer::PutReliableSendCommand(), con::ConnectionSendThread::rawSend(), con::ConnectionSendThread::rawSendAsPacket(), Receive(), con::ConnectionReceiveThread::receive(), con::ConnectionSendThread::run(), con::ConnectionReceiveThread::run(), con::UDPPeer::RunCommandQueues(), con::ConnectionSendThread::runTimeouts(), con::ConnectionSendThread::send(), sendAck(), con::ConnectionSendThread::sendAsPacketReliable(), con::ConnectionSendThread::sendPackets(), and con::ConnectionSendThread::serve().

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

◆ getLocalStat()

float con::Connection::getLocalStat ( rate_stat_type  type)

References con::AVG_DL_RATE, con::AVG_INC_RATE, con::AVG_LOSS_RATE, con::CUR_DL_RATE, con::CUR_INC_RATE, con::CUR_LOSS_RATE, FATAL_ERROR, FATAL_ERROR_IF, getPeerNoEx(), and PEER_ID_SERVER.

+ Here is the call graph for this function:

◆ GetPeerAddress()

Address con::Connection::GetPeerAddress ( session_t  peer_id)

References con::Peer::getAddress(), getPeerNoEx(), and con::MTP_PRIMARY.

+ Here is the call graph for this function:

◆ GetPeerID()

session_t con::Connection::GetPeerID ( ) const
inline

References m_peer_id.

Referenced by con::ConnectionReceiveThread::handlePacketType_Control(), con::UDPPeer::processReliableSendCommand(), and con::ConnectionSendThread::rawSendAsPacket().

+ Here is the caller graph for this function:

◆ getPeerIDs()

std::vector<session_t> con::Connection::getPeerIDs ( )
inlineprotected

◆ getPeerNoEx()

◆ getPeerStat()

float con::Connection::getPeerStat ( session_t  peer_id,
rtt_stat_type  type 
)

References getPeerNoEx(), and con::Peer::getStat().

+ Here is the call graph for this function:

◆ GetProtocolID()

const u32 con::Connection::GetProtocolID ( ) const
inline

References m_protocol_id.

Referenced by con::ConnectionReceiveThread::handlePacketType_Reliable(), con::ConnectionReceiveThread::handlePacketType_Split(), con::UDPPeer::processReliableSendCommand(), con::ConnectionSendThread::rawSendAsPacket(), and con::ConnectionReceiveThread::receive().

+ Here is the caller graph for this function:

◆ lookupPeer()

u16 con::Connection::lookupPeer ( Address sender)
protected

References con::Peer::getAddress(), con::Peer::id, con::Peer::isPendingDeletion(), m_peers, m_peers_mutex, con::MTP_MINETEST_RELIABLE_UDP, con::MTP_UDP, and PEER_ID_INEXISTENT.

Referenced by con::ConnectionReceiveThread::receive().

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

◆ PrintInfo()

void con::Connection::PrintInfo ( std::ostream &  out)
protected

References getDesc(), and m_info_mutex.

+ Here is the call graph for this function:

◆ putCommand()

void con::Connection::putCommand ( ConnectionCommand c)

References m_command_queue, m_sendThread, and m_shutting_down.

Referenced by Connect(), createPeer(), Disconnect(), DisconnectPeer(), con::ConnectionReceiveThread::handlePacketType_Reliable(), Send(), sendAck(), and Serve().

+ Here is the caller graph for this function:

◆ putEvent()

void con::Connection::putEvent ( ConnectionEvent e)
protected

References con::CONNEVENT_NONE, m_event_queue, and con::ConnectionEvent::type.

Referenced by con::ConnectionSendThread::connect(), createPeer(), deletePeer(), con::ConnectionReceiveThread::receive(), and con::ConnectionSendThread::serve().

+ Here is the caller graph for this function:

◆ Receive() [1/2]

void con::Connection::Receive ( NetworkPacket pkt)

References m_bc_receive_timeout.

Referenced by TryReceive().

+ Here is the caller graph for this function:

◆ Receive() [2/2]

◆ Send()

void con::Connection::Send ( session_t  peer_id,
u8  channelnum,
NetworkPacket pkt,
bool  reliable 
)

References CHANNEL_COUNT, putCommand(), and con::ConnectionCommand::send().

Referenced by con::ConnectionSendThread::connect().

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

◆ sendAck()

void con::Connection::sendAck ( session_t  peer_id,
u8  channelnum,
u16  seqnum 
)
protected

References con::ConnectionCommand::ack(), CHANNEL_COUNT, CONTROLTYPE_ACK, dout_con, getDesc(), LOG, m_sendThread, con::PACKET_TYPE_CONTROL, putCommand(), writeU16(), and writeU8().

Referenced by con::ConnectionReceiveThread::handlePacketType_Reliable().

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

◆ Serve()

void con::Connection::Serve ( Address  bind_addr)

References putCommand(), and con::ConnectionCommand::serve().

+ Here is the call graph for this function:

◆ SetPeerID()

void con::Connection::SetPeerID ( session_t  id)
inlineprotected

References m_peer_id.

Referenced by con::ConnectionSendThread::connect(), con::ConnectionReceiveThread::handlePacketType_Control(), and con::ConnectionSendThread::serve().

+ Here is the caller graph for this function:

◆ SetTimeoutMs()

void con::Connection::SetTimeoutMs ( u32  timeout)
inline

References m_bc_receive_timeout.

◆ TriggerSend()

void con::Connection::TriggerSend ( )
protected

References m_sendThread.

Referenced by con::ConnectionReceiveThread::handlePacketType_Control().

+ Here is the caller graph for this function:

◆ TryReceive()

bool con::Connection::TryReceive ( NetworkPacket pkt)

References Receive().

+ Here is the call graph for this function:

◆ waitEvent()

ConnectionEvent con::Connection::waitEvent ( u32  timeout_ms)

References con::CONNEVENT_NONE, m_event_queue, and con::ConnectionEvent::type.

Referenced by Receive().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ ConnectionReceiveThread

friend class ConnectionReceiveThread
friend

◆ ConnectionSendThread

friend class ConnectionSendThread
friend

Member Data Documentation

◆ m_bc_peerhandler

PeerHandler* con::Connection::m_bc_peerhandler
private

Referenced by Receive().

◆ m_bc_receive_timeout

u32 con::Connection::m_bc_receive_timeout = 0
private

Referenced by Receive(), and SetTimeoutMs().

◆ m_command_queue

MutexedQueue<ConnectionCommand> con::Connection::m_command_queue
protected

◆ m_event_queue

MutexedQueue<ConnectionEvent> con::Connection::m_event_queue
private

Referenced by putEvent(), and waitEvent().

◆ m_info_mutex

std::mutex con::Connection::m_info_mutex
private

Referenced by PrintInfo().

◆ m_next_remote_peer_id

session_t con::Connection::m_next_remote_peer_id = 2
private

Referenced by createPeer().

◆ m_peer_id

session_t con::Connection::m_peer_id = 0
private

◆ m_peer_ids

std::vector<session_t> con::Connection::m_peer_ids
private

◆ m_peers

◆ m_peers_mutex

std::mutex con::Connection::m_peers_mutex
private

◆ m_protocol_id

u32 con::Connection::m_protocol_id
private

Referenced by GetProtocolID().

◆ m_receiveThread

std::unique_ptr<ConnectionReceiveThread> con::Connection::m_receiveThread
private

Referenced by Connection(), and ~Connection().

◆ m_sendThread

std::unique_ptr<ConnectionSendThread> con::Connection::m_sendThread
private

◆ m_shutting_down

bool con::Connection::m_shutting_down = false
private

Referenced by ~Connection(), and putCommand().

◆ m_udpSocket


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