OpenTTD Source 20241224-master-gee860a5c8e
NetworkStunSocketHandler Class Reference

Base socket handler for all STUN TCP sockets. More...

#include <tcp_stun.h>

Inheritance diagram for NetworkStunSocketHandler:
NetworkTCPSocketHandler NetworkSocketHandler ClientNetworkStunSocketHandler

Public Member Functions

 NetworkStunSocketHandler (SOCKET s=INVALID_SOCKET)
 Create a new cs socket handler for a given cs.
 
- Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket.
 
virtual NetworkRecvStatus CloseConnection (bool error=true)
 This will put this socket handler in a close state.
 
void CloseSocket ()
 Close the actual socket of the connection.
 
virtual void SendPacket (std::unique_ptr< Packet > &&packet)
 This function puts the packet in the send-queue and it is send as soon as possible.
 
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this client.
 
virtual std::unique_ptr< PacketReceivePacket ()
 Receives a packet for the given client.
 
bool CanSendReceive ()
 Check whether this socket can send or receive something.
 
bool HasSendQueue ()
 Whether there is something pending in the send queue.
 
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
 Construct a socket handler for a TCP connection.
 
- Public Member Functions inherited from NetworkSocketHandler
 NetworkSocketHandler ()
 Create a new unbound socket.
 
virtual ~NetworkSocketHandler ()=default
 Close the socket when destructing the socket handler.
 
void MarkClosed ()
 Mark the connection as closed.
 
bool HasClientQuit () const
 Whether the current client connected to the socket has quit.
 
void Reopen ()
 Reopen the socket so we can send/receive stuff again.
 

Protected Member Functions

bool ReceiveInvalidPacket (PacketStunType type)
 Helper for logging receiving invalid packets.
 
virtual bool Receive_SERCLI_STUN (Packet &p)
 Send a STUN request to the STUN server letting the Game Coordinator know what our actually public IP:port is.
 

Additional Inherited Members

- Data Fields inherited from NetworkTCPSocketHandler
SOCKET sock
 The socket currently connected to.
 
bool writable
 Can we write to this socket?
 
- Protected Attributes inherited from NetworkSocketHandler
std::unique_ptr< class NetworkEncryptionHandlerreceive_encryption_handler
 The handler for decrypting received packets.
 
std::unique_ptr< class NetworkEncryptionHandlersend_encryption_handler
 The handler for encrypting sent packets.
 

Detailed Description

Base socket handler for all STUN TCP sockets.

Definition at line 26 of file tcp_stun.h.

Constructor & Destructor Documentation

◆ NetworkStunSocketHandler()

NetworkStunSocketHandler::NetworkStunSocketHandler ( SOCKET  s = INVALID_SOCKET)
inline

Create a new cs socket handler for a given cs.

Parameters
sthe socket we are connected with.
addressIP etc. of the client.

Definition at line 50 of file tcp_stun.h.

Member Function Documentation

◆ Receive_SERCLI_STUN()

bool NetworkStunSocketHandler::Receive_SERCLI_STUN ( Packet p)
protectedvirtual

Send a STUN request to the STUN server letting the Game Coordinator know what our actually public IP:port is.

uint8_t Game Coordinator protocol version. string Token to track the current STUN request. uint8_t Which interface number this is (for example, IPv4 or IPv6). The Game Coordinator relays this number back in later packets.

Parameters
pThe packet that was just received.
Returns
True upon success, otherwise false.

Definition at line 29 of file tcp_stun.cpp.

References PACKET_STUN_SERCLI_STUN, and ReceiveInvalidPacket().

◆ ReceiveInvalidPacket()

bool NetworkStunSocketHandler::ReceiveInvalidPacket ( PacketStunType  type)
protected

Helper for logging receiving invalid packets.

Parameters
typeThe received packet type.
Returns
Always false, as it's an error.

Definition at line 23 of file tcp_stun.cpp.

References Debug.

Referenced by Receive_SERCLI_STUN().


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