#include <connection.h>
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) |
UDPPeer * | createServerPeer (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_t > | getPeerIDs () |
bool | Receive (NetworkPacket *pkt, u32 timeout) |
void | putEvent (ConnectionEvent &e) |
void | TriggerSend () |
bool | ConnectedToServer () |
Protected Attributes | |
UDPSocket | m_udpSocket |
MutexedQueue< ConnectionCommand > | m_command_queue |
Private Attributes | |
MutexedQueue< ConnectionEvent > | m_event_queue |
session_t | m_peer_id = 0 |
u32 | m_protocol_id |
std::map< session_t, Peer * > | m_peers |
std::vector< session_t > | m_peer_ids |
std::mutex | m_peers_mutex |
std::unique_ptr< ConnectionSendThread > | m_sendThread |
std::unique_ptr< ConnectionReceiveThread > | m_receiveThread |
std::mutex | m_info_mutex |
PeerHandler * | m_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 |
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().
con::Connection::~Connection | ( | ) |
References m_peers, m_receiveThread, m_sendThread, and m_shutting_down.
void con::Connection::Connect | ( | Address | address | ) |
References con::ConnectionCommand::connect(), and putCommand().
bool con::Connection::Connected | ( | ) |
References m_peer_id, m_peers, m_peers_mutex, PEER_ID_INEXISTENT, and PEER_ID_SERVER.
|
inlineprotected |
References getPeerNoEx(), and PEER_ID_SERVER.
Referenced by createServerPeer(), and con::ConnectionReceiveThread::receive().
|
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().
References ConnectedToServer(), con::Peer::id, m_peer_ids, m_peers, m_peers_mutex, and PEER_ID_SERVER.
Referenced by con::ConnectionSendThread::connect().
|
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().
void con::Connection::Disconnect | ( | ) |
References con::ConnectionCommand::disconnect(), and putCommand().
void con::Connection::DisconnectPeer | ( | session_t | peer_id | ) |
References con::ConnectionCommand::disconnect_peer(), and putCommand().
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().
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.
References con::Peer::getAddress(), getPeerNoEx(), and con::MTP_PRIMARY.
|
inline |
References m_peer_id.
Referenced by con::ConnectionReceiveThread::handlePacketType_Control(), con::UDPPeer::processReliableSendCommand(), and con::ConnectionSendThread::rawSendAsPacket().
|
inlineprotected |
References m_peer_ids, and m_peers_mutex.
Referenced by con::ConnectionSendThread::disconnect(), con::ConnectionReceiveThread::getFromBuffers(), con::ConnectionSendThread::packetsQueued(), con::ConnectionReceiveThread::run(), con::ConnectionSendThread::runTimeouts(), con::ConnectionSendThread::sendPackets(), con::ConnectionSendThread::sendToAll(), and con::ConnectionSendThread::sendToAllReliable().
|
protected |
References FATAL_ERROR_IF, m_peers, and m_peers_mutex.
Referenced by ConnectedToServer(), con::ConnectionSendThread::disconnect_peer(), con::ConnectionReceiveThread::getFromBuffers(), getLocalStat(), GetPeerAddress(), getPeerStat(), con::ConnectionSendThread::packetsQueued(), con::ConnectionReceiveThread::processPacket(), con::ConnectionSendThread::rawSendAsPacket(), con::ConnectionReceiveThread::receive(), con::ConnectionReceiveThread::run(), con::ConnectionSendThread::runTimeouts(), con::ConnectionSendThread::send(), con::ConnectionSendThread::sendPackets(), con::ConnectionSendThread::sendReliable(), and con::ConnectionSendThread::sendToAllReliable().
float con::Connection::getPeerStat | ( | session_t | peer_id, |
rtt_stat_type | type | ||
) |
|
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().
|
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().
|
protected |
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().
|
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().
void con::Connection::Receive | ( | NetworkPacket * | pkt | ) |
References m_bc_receive_timeout.
Referenced by TryReceive().
|
protected |
References con::ConnectionEvent::address, con::CONNEVENT_BIND_FAILED, con::CONNEVENT_DATA_RECEIVED, con::CONNEVENT_NONE, con::CONNEVENT_PEER_ADDED, con::CONNEVENT_PEER_REMOVED, con::ConnectionEvent::data, con::PeerHandler::deletingPeer(), con::ConnectionEvent::describe(), dout_con, getDesc(), Buffer< T >::getSize(), LOG, m_bc_peerhandler, con::ConnectionEvent::peer_id, con::PeerHandler::peerAdded(), NetworkPacket::putRawPacket(), con::ConnectionEvent::timeout, con::ConnectionEvent::type, and waitEvent().
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().
|
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().
void con::Connection::Serve | ( | Address | bind_addr | ) |
References putCommand(), and con::ConnectionCommand::serve().
|
inlineprotected |
References m_peer_id.
Referenced by con::ConnectionSendThread::connect(), con::ConnectionReceiveThread::handlePacketType_Control(), and con::ConnectionSendThread::serve().
|
inline |
References m_bc_receive_timeout.
|
protected |
References m_sendThread.
Referenced by con::ConnectionReceiveThread::handlePacketType_Control().
bool con::Connection::TryReceive | ( | NetworkPacket * | pkt | ) |
ConnectionEvent con::Connection::waitEvent | ( | u32 | timeout_ms | ) |
References con::CONNEVENT_NONE, m_event_queue, and con::ConnectionEvent::type.
Referenced by Receive().
|
friend |
|
friend |
|
private |
Referenced by Receive().
|
private |
Referenced by Receive(), and SetTimeoutMs().
|
protected |
Referenced by putCommand(), and con::ConnectionSendThread::run().
|
private |
Referenced by putEvent(), and waitEvent().
|
private |
Referenced by PrintInfo().
|
private |
Referenced by createPeer().
|
private |
Referenced by Connected(), getDesc(), GetPeerID(), and SetPeerID().
|
private |
Referenced by createPeer(), createServerPeer(), deletePeer(), and getPeerIDs().
Referenced by ~Connection(), Connected(), createPeer(), createServerPeer(), deletePeer(), getPeerNoEx(), lookupPeer(), and con::ConnectionSendThread::runTimeouts().
|
private |
Referenced by Connected(), createPeer(), createServerPeer(), deletePeer(), getPeerIDs(), getPeerNoEx(), and lookupPeer().
|
private |
Referenced by GetProtocolID().
|
private |
Referenced by Connection(), and ~Connection().
|
private |
Referenced by Connection(), ~Connection(), putCommand(), sendAck(), and TriggerSend().
|
private |
Referenced by ~Connection(), and putCommand().
|
protected |