OpenTTD Source 20241224-master-gf74b0cf984
ClientNetworkTurnSocketHandler Class Reference

Class for handling the client side of the TURN connection. More...

#include <network_turn.h>

Inheritance diagram for ClientNetworkTurnSocketHandler:
NetworkTurnSocketHandler NetworkTCPSocketHandler NetworkSocketHandler

Public Member Functions

 ClientNetworkTurnSocketHandler (const std::string &token, uint8_t tracking_number, const std::string &connection_string)
 
NetworkRecvStatus CloseConnection (bool error=true) override
 This will put this socket handler in a close state.
 
void SendReceive ()
 Check whether we received/can send some data from/to the TURN server and when that's the case handle it appropriately.
 
void Connect ()
 Connect to the TURN server.
 
void ConnectFailure ()
 
- Public Member Functions inherited from NetworkTurnSocketHandler
 NetworkTurnSocketHandler (SOCKET s=INVALID_SOCKET)
 Create a new cs socket handler for a given cs.
 
bool ReceivePackets ()
 Receive a packet at TCP level.
 
- Public Member Functions inherited from NetworkTCPSocketHandler
bool IsConnected () const
 Whether this socket is currently bound to a socket.
 
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.
 

Static Public Member Functions

static std::unique_ptr< ClientNetworkTurnSocketHandlerTurn (const std::string &token, uint8_t tracking_number, const std::string &ticket, const std::string &connection_string)
 Prepare a TURN connection.
 

Data Fields

std::shared_ptr< TCPConnecterconnecter {}
 Connecter instance.
 
bool connect_started = false
 Whether we started the connection.
 
- Data Fields inherited from NetworkTCPSocketHandler
SOCKET sock
 The socket currently connected to.
 
bool writable
 Can we write to this socket?
 

Protected Member Functions

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

Private Attributes

std::string token
 Token of this connection.
 
uint8_t tracking_number
 Tracking number of this connection.
 
std::string connection_string
 The connection string of the TURN server we are connecting to.
 

Additional Inherited Members

- 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

Class for handling the client side of the TURN connection.

Definition at line 16 of file network_turn.h.

Constructor & Destructor Documentation

◆ ClientNetworkTurnSocketHandler()

ClientNetworkTurnSocketHandler::ClientNetworkTurnSocketHandler ( const std::string &  token,
uint8_t  tracking_number,
const std::string &  connection_string 
)
inline

Definition at line 30 of file network_turn.h.

◆ ~ClientNetworkTurnSocketHandler()

ClientNetworkTurnSocketHandler::~ClientNetworkTurnSocketHandler ( )
override

Definition at line 130 of file network_turn.cpp.

Member Function Documentation

◆ CloseConnection()

NetworkRecvStatus ClientNetworkTurnSocketHandler::CloseConnection ( bool  error = true)
overridevirtual

This will put this socket handler in a close state.

It will not actually close the OS socket; use CloseSocket for this.

Parameters
errorWhether we quit under an error condition or not.
Returns
new status of the connection.

Reimplemented from NetworkTCPSocketHandler.

Definition at line 117 of file network_turn.cpp.

References NetworkTCPSocketHandler::CloseConnection(), connecter, and NETWORK_RECV_STATUS_OKAY.

◆ Connect()

void ClientNetworkTurnSocketHandler::Connect ( )

Connect to the TURN server.

Definition at line 81 of file network_turn.cpp.

References connect_started, connecter, connection_string, and Debug.

◆ ConnectFailure()

void ClientNetworkTurnSocketHandler::ConnectFailure ( )

Definition at line 112 of file network_turn.cpp.

◆ Receive_TURN_CONNECTED()

bool ClientNetworkTurnSocketHandler::Receive_TURN_CONNECTED ( Packet p)
overrideprotectedvirtual

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 from NetworkTurnSocketHandler.

Definition at line 61 of file network_turn.cpp.

References _network_coordinator_client, ClientNetworkCoordinatorSocketHandler::ConnectSuccess(), Debug, NETWORK_DEFAULT_PORT, NETWORK_HOSTNAME_LENGTH, Packet::Recv_string(), NetworkTCPSocketHandler::sock, and token.

◆ Receive_TURN_ERROR()

bool ClientNetworkTurnSocketHandler::Receive_TURN_ERROR ( Packet p)
overrideprotectedvirtual

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 from NetworkTurnSocketHandler.

Definition at line 52 of file network_turn.cpp.

References Debug.

◆ SendReceive()

void ClientNetworkTurnSocketHandler::SendReceive ( )

Check whether we received/can send some data from/to the TURN server and when that's the case handle it appropriately.

Definition at line 142 of file network_turn.cpp.

References NetworkTCPSocketHandler::CanSendReceive(), NetworkTurnSocketHandler::ReceivePackets(), NetworkTCPSocketHandler::SendPackets(), and NetworkTCPSocketHandler::sock.

◆ Turn()

std::unique_ptr< ClientNetworkTurnSocketHandler > ClientNetworkTurnSocketHandler::Turn ( const std::string &  token,
uint8_t  tracking_number,
const std::string &  ticket,
const std::string &  connection_string 
)
static

Prepare a TURN connection.

Not until you run Connect() on the resulting instance will it start setting up the TURN connection.

Parameters
tokenThe token as received from the Game Coordinator.
tracking_numberThe tracking number as recieved from the Game Coordinator.
ticketThe ticket as received from the Game Coordinator.
connection_stringConnection string of the TURN server.
Returns
The handler for this TURN connection.

Definition at line 99 of file network_turn.cpp.

References connection_string, NETWORK_COORDINATOR_VERSION, PACKET_TURN_SERCLI_CONNECT, token, and tracking_number.

Referenced by ClientNetworkCoordinatorSocketHandler::Receive_GC_TURN_CONNECT().

Field Documentation

◆ connect_started

bool ClientNetworkTurnSocketHandler::connect_started = false

Whether we started the connection.

Definition at line 28 of file network_turn.h.

Referenced by Connect().

◆ connecter

std::shared_ptr<TCPConnecter> ClientNetworkTurnSocketHandler::connecter {}

Connecter instance.

Definition at line 27 of file network_turn.h.

Referenced by CloseConnection(), Connect(), NetworkTurnConnecter::OnConnect(), and NetworkTurnConnecter::OnFailure().

◆ connection_string

std::string ClientNetworkTurnSocketHandler::connection_string
private

The connection string of the TURN server we are connecting to.

Definition at line 20 of file network_turn.h.

Referenced by Connect(), and Turn().

◆ token

std::string ClientNetworkTurnSocketHandler::token
private

Token of this connection.

Definition at line 18 of file network_turn.h.

Referenced by Receive_TURN_CONNECTED(), and Turn().

◆ tracking_number

uint8_t ClientNetworkTurnSocketHandler::tracking_number
private

Tracking number of this connection.

Definition at line 19 of file network_turn.h.

Referenced by Turn().


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