SuperTuxKart
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
Network Class Reference

Public Member Functions

 Network (int peer_count, int channel_limit, uint32_t max_incoming_bandwidth, uint32_t max_outgoing_bandwidth, ENetAddress *address, bool change_port_if_bound=false)
 Constructor that just initialises this object (esp.
 
virtual ~Network ()
 Destructor.
 
ENetPeer * connectTo (const ENetAddress &address)
 
void sendRawPacket (const BareNetworkString &buffer, const SocketAddress &dst)
 Sends a packet whithout ENet adding its headers.
 
int receiveRawPacket (char *buffer, int buf_len, SocketAddress *sender, int max_tries=-1)
 Receives a packet directly from the network interface and filter its address.
 
void broadcastPacket (NetworkString *data, bool reliable=true)
 Broadcasts a packet to all peers.
 
uint16_t getPort () const
 
ENetHost * getENetHost ()
 Returns a pointer to the ENet host object.
 
bool isIPv6Socket ()
 

Static Public Member Functions

static void openLog ()
 
static void logPacket (const BareNetworkString &ns, bool incoming)
 Log packets into a file.
 
static void closeLog ()
 

Static Public Attributes

static bool m_connection_debug = false
 

Private Attributes

ENetHost * m_host
 ENet host interfacing sockets.
 
uint16_t m_port
 
bool m_ipv6_socket
 

Static Private Attributes

static Synchronised< FILE * > m_log_file
 Where to log packets.
 

Constructor & Destructor Documentation

◆ Network()

Network::Network ( int  peer_count,
int  channel_limit,
uint32_t  max_incoming_bandwidth,
uint32_t  max_outgoing_bandwidth,
ENetAddress *  address,
bool  change_port_if_bound = false 
)

Constructor that just initialises this object (esp.

opening the packet log file), but it does not start a listener thread.

Parameters
peer_count: The maximum number of peers.
channel_limit: The maximum number of channels per peer.
max_incoming_bandwidth: The maximum incoming bandwidth.
max_outgoing_bandwidth: The maximum outgoing bandwidth.
change_port_if_bound: Use another port if the prefered port is already bound to a socket.

◆ ~Network()

Network::~Network ( )
virtual

Destructor.

Stops the listening thread, closes the packet log file and destroys the enet host.

Member Function Documentation

◆ broadcastPacket()

void Network::broadcastPacket ( NetworkString data,
bool  reliable = true 
)

Broadcasts a packet to all peers.

Parameters
data: Data to send.

◆ logPacket()

void Network::logPacket ( const BareNetworkString ns,
bool  incoming 
)
static

Log packets into a file.

Parameters
ns: The data in the packet
incoming: True if the packet comes from a peer. False if it's sent to a peer.

◆ receiveRawPacket()

int Network::receiveRawPacket ( char *  buffer,
int  buf_len,
SocketAddress sender,
int  max_tries = -1 
)

Receives a packet directly from the network interface and filter its address.

Receive a packet whithout ENet processing it. Checks that the sender of the packet is the one that corresponds to the sender parameter. Does not check the port right now.

Parameters
bufferA buffer to receive the data in.
buf_lenLength of the buffer.
[out]sender: Transport address of the original sender of the wanted packet. If the ip address is 0, do not check the sender's ip address, otherwise wait till a message from the specified sender arrives. All other messages are discarded.
max_tries: Number of times we try to read data from the socket. This is aproximately the time we wait in milliseconds. -1 means eternal tries.
Returns
Length of the received data, or -1 if no data was received.

◆ sendRawPacket()

void Network::sendRawPacket ( const BareNetworkString buffer,
const SocketAddress dst 
)

Sends a packet whithout ENet adding its headers.

This function is used in particular to achieve the STUN protocol.

Parameters
data: Data to send.
dst: Destination of the packet.

Member Data Documentation

◆ m_log_file

Synchronised< FILE * > Network::m_log_file
staticprivate

Where to log packets.

If NULL for FILE* logging is disabled.


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