Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
con::Connection Class Referencefinal

#include <impl.h>

+ Inheritance diagram for con::Connection:
+ Collaboration diagram for con::Connection:

Public Member Functions

 Connection (u32 max_packet_size, float timeout, bool ipv6, PeerHandler *peerhandler)
 
 ~Connection ()
 
ConnectionEventPtr waitEvent (u32 timeout_ms)
 
void putCommand (ConnectionCommandPtr c)
 
void Serve (Address bind_addr)
 
void Connect (Address address)
 
bool Connected ()
 
void Disconnect ()
 
bool ReceiveTimeoutMs (NetworkPacket *pkt, u32 timeout_ms)
 
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)
 
u32 GetProtocolID () const
 
const std::string getDesc ()
 
void DisconnectPeer (session_t peer_id)
 
- Public Member Functions inherited from con::IConnection
virtual ~IConnection ()=default
 
bool TryReceive (NetworkPacket *pkt)
 

Protected Member Functions

PeerHelper getPeerNoEx (session_t peer_id)
 
session_t lookupPeer (const Address &sender)
 
session_t createPeer (const Address &sender, int fd)
 
UDPPeercreateServerPeer (const Address &sender)
 
bool deletePeer (session_t peer_id, bool timeout)
 
void SetPeerID (session_t id)
 
void doResendOne (session_t peer_id)
 
void sendAck (session_t peer_id, u8 channelnum, u16 seqnum)
 
std::vector< session_tgetPeerIDs ()
 
u32 getActiveCount ()
 
void putEvent (ConnectionEventPtr e)
 
void TriggerSend ()
 
bool ConnectedToServer ()
 

Protected Attributes

UDPSocket m_udpSocket
 
MutexedQueue< ConnectionCommandPtrm_command_queue
 

Private Attributes

MutexedQueue< ConnectionEventPtrm_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
 
bool m_shutting_down = false
 

Friends

class ConnectionSendThread
 
class ConnectionReceiveThread
 

Constructor & Destructor Documentation

◆ Connection()

con::Connection::Connection ( 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)
virtual

Implements con::IConnection.

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

+ Here is the call graph for this function:

◆ Connected()

bool con::Connection::Connected ( )
virtual

◆ 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()

session_t con::Connection::createPeer ( const Address & sender,
int fd )
protected

References CONTROLTYPE_SET_PEER_ID, con::ConnectionCommand::createPeer(), dout_con, errorstream, getDesc(), con::IPeer::id, LOG, m_peer_ids, m_peers, m_peers_mutex, MAX_UDP_PEERS, myrand_range(), 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 ( const Address & sender)
protected

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

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::IPeer::getAddress(), m_peer_ids, m_peers, m_peers_mutex, 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 ( )
virtual

Implements con::IConnection.

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

+ Here is the call graph for this function:

◆ DisconnectPeer()

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

Implements con::IConnection.

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

+ Here is the call graph for this function:

◆ doResendOne()

void con::Connection::doResendOne ( session_t peer_id)
protected

References PEER_ID_INEXISTENT, putCommand(), and con::ConnectionCommand::resend_one().

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

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

◆ getActiveCount()

u32 con::Connection::getActiveCount ( )
protected

References con::Peer::isHalfOpen(), con::Peer::isPendingDeletion(), m_peers, and m_peers_mutex.

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

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

◆ getDesc()

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

References _, UDPSocket::GetHandle(), itos(), m_info_mutex, 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(), con::ConnectionSendThread::processNonReliableCommand(), con::ConnectionReceiveThread::processPacket(), con::ConnectionSendThread::processReliableCommand(), con::UDPPeer::processReliableSendCommand(), con::UDPPeer::PutReliableSendCommand(), con::ConnectionSendThread::rawSend(), con::ConnectionSendThread::rawSendAsPacket(), con::ConnectionReceiveThread::receive(), ReceiveTimeoutMs(), con::UDPPeer::reportRTT(), con::ConnectionSendThread::resendReliable(), con::ConnectionReceiveThread::run(), con::ConnectionSendThread::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)
virtual

Implements con::IConnection.

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)
virtual

Implements con::IConnection.

References con::IPeer::getAddress(), and getPeerNoEx().

+ Here is the call graph for this function:

◆ GetPeerID()

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

Implements con::IConnection.

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 )
virtual

Implements con::IConnection.

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

+ Here is the call graph for this function:

◆ GetProtocolID()

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()

session_t con::Connection::lookupPeer ( const Address & sender)
protected

References con::IPeer::getAddress(), con::IPeer::id, con::Peer::isPendingDeletion(), m_peers, m_peers_mutex, 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:

◆ putCommand()

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

References m_command_queue, m_sendThread, m_shutting_down, and MutexedQueue< T >::push_back().

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

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

◆ putEvent()

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

References con::CONNEVENT_NONE, m_event_queue, and MutexedQueue< T >::push_back().

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

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

◆ ReceiveTimeoutMs()

◆ Send()

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

Implements con::IConnection.

References CHANNEL_COUNT, FATAL_ERROR, NetworkPacket::getCommand(), NetworkPacket::getSize(), MAX_RELIABLE_WINDOW_SIZE, 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)
virtual

Implements con::IConnection.

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:

◆ TriggerSend()

void con::Connection::TriggerSend ( )
protected

References m_sendThread.

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

+ Here is the caller graph for this function:

◆ waitEvent()

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

References con::CONNEVENT_NONE, con::ConnectionEvent::create(), m_event_queue, and MutexedQueue< T >::pop_front().

Referenced by ReceiveTimeoutMs().

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

Friends And Related Symbol 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 ReceiveTimeoutMs().

◆ m_command_queue

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

◆ m_event_queue

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

Referenced by putEvent(), and waitEvent().

◆ m_info_mutex

std::mutex con::Connection::m_info_mutex
mutableprivate

Referenced by getDesc().

◆ 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

std::map<session_t, Peer *> con::Connection::m_peers
private

◆ 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: