OpenTTD Source  20241121-master-g67a0fccfad
NetworkTurnSocketHandler Class Reference

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

#include <tcp_turn.h>

Inheritance diagram for NetworkTurnSocketHandler:
NetworkTCPSocketHandler NetworkSocketHandler ClientNetworkTurnSocketHandler

Public Member Functions

 NetworkTurnSocketHandler (SOCKET s=INVALID_SOCKET)
 Create a new cs socket handler for a given cs. More...
 
bool ReceivePackets ()
 Receive a packet at TCP level. More...
 
- Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket. More...
 
virtual NetworkRecvStatus CloseConnection (bool error=true)
 This will put this socket handler in a close state. More...
 
void CloseSocket ()
 Close the actual socket of the connection. More...
 
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. More...
 
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this client. More...
 
virtual std::unique_ptr< PacketReceivePacket ()
 Receives a packet for the given client. More...
 
bool CanSendReceive ()
 Check whether this socket can send or receive something. More...
 
bool HasSendQueue ()
 Whether there is something pending in the send queue. More...
 
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
 Construct a socket handler for a TCP connection. More...
 
- 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. More...
 
bool HasClientQuit () const
 Whether the current client connected to the socket has quit. More...
 
void Reopen ()
 Reopen the socket so we can send/receive stuff again.
 

Protected Member Functions

bool ReceiveInvalidPacket (PacketTurnType type)
 Helper for logging receiving invalid packets. More...
 
virtual bool Receive_TURN_ERROR (Packet &p)
 TURN server was unable to connect the client or server based on the token. More...
 
virtual bool Receive_SERCLI_CONNECT (Packet &p)
 Client or servers wants to connect to the TURN server (on request by the Game Coordinator). More...
 
virtual bool Receive_TURN_CONNECTED (Packet &p)
 TURN server has connected client and server together and will now relay all packets to each other. More...
 
bool HandlePacket (Packet &p)
 Handle the given packet, i.e. More...
 

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 TURN TCP sockets.

Definition at line 29 of file tcp_turn.h.

Constructor & Destructor Documentation

◆ NetworkTurnSocketHandler()

NetworkTurnSocketHandler::NetworkTurnSocketHandler ( 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 74 of file tcp_turn.h.

Member Function Documentation

◆ HandlePacket()

bool NetworkTurnSocketHandler::HandlePacket ( Packet p)
protected

Handle the given packet, i.e.

pass it to the right parser receive command.

Parameters
pthe packet to handle
Returns
true if we should immediately handle further packets, false otherwise

Definition at line 25 of file tcp_turn.cpp.

References Debug, PACKET_TURN_SERCLI_CONNECT, PACKET_TURN_TURN_CONNECTED, PACKET_TURN_TURN_ERROR, Receive_SERCLI_CONNECT(), Receive_TURN_CONNECTED(), Receive_TURN_ERROR(), and Packet::Recv_uint8().

Referenced by ReceivePackets().

◆ Receive_SERCLI_CONNECT()

bool NetworkTurnSocketHandler::Receive_SERCLI_CONNECT ( Packet p)
protectedvirtual

Client or servers wants to connect to the TURN server (on request by the Game Coordinator).

uint8_t Game Coordinator protocol version. string Token to track the current TURN request.

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

Definition at line 69 of file tcp_turn.cpp.

References PACKET_TURN_SERCLI_CONNECT, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_TURN_CONNECTED()

bool NetworkTurnSocketHandler::Receive_TURN_CONNECTED ( Packet p)
protectedvirtual

TURN server has connected client and server together and will now relay all packets to each other.

No further TURN packets should be send over this socket, and the socket should be handed over to the game protocol.

string Hostname of the peer. This can be used to check if a client is not banned etc.

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

Reimplemented in ClientNetworkTurnSocketHandler.

Definition at line 70 of file tcp_turn.cpp.

References PACKET_TURN_TURN_CONNECTED, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ Receive_TURN_ERROR()

bool NetworkTurnSocketHandler::Receive_TURN_ERROR ( Packet p)
protectedvirtual

TURN server was unable to connect the client or server based on the token.

Most likely cause is an invalid token or the other side that hasn't connected in a reasonable amount of time.

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

Reimplemented in ClientNetworkTurnSocketHandler.

Definition at line 68 of file tcp_turn.cpp.

References PACKET_TURN_TURN_ERROR, and ReceiveInvalidPacket().

Referenced by HandlePacket().

◆ ReceiveInvalidPacket()

bool NetworkTurnSocketHandler::ReceiveInvalidPacket ( PacketTurnType  type)
protected

Helper for logging receiving invalid packets.

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

Definition at line 62 of file tcp_turn.cpp.

References Debug.

Referenced by Receive_SERCLI_CONNECT(), Receive_TURN_CONNECTED(), and Receive_TURN_ERROR().

◆ ReceivePackets()

bool NetworkTurnSocketHandler::ReceivePackets ( )

Receive a packet at TCP level.

Returns
Whether at least one packet was received.

Definition at line 44 of file tcp_turn.cpp.

References HandlePacket(), and NetworkTCPSocketHandler::ReceivePacket().

Referenced by ClientNetworkTurnSocketHandler::SendReceive().


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