OpenTTD Source: ClientNetworkStunSocketHandler Class Reference

OpenTTD Source 14.1

Public Member Functions | Static Public Member Functions | Data Fields | Private Attributes
ClientNetworkStunSocketHandler Class Reference

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

`#include <network_stun.h>`

Inheritance diagram for ClientNetworkStunSocketHandler:

## Public Member Functions
NetworkRecvStatus | CloseConnection (bool error=true) override
| This will put this socket handler in a close state. More...
void | SendReceive ()
| Check whether we received/can send some data from/to the STUN server and when that's the case handle it appropriately.
void | Connect (const std::string &token, uint8_t family)
| Connect to the STUN server over either IPv4 or IPv6. More...
Public Member Functions inherited from NetworkStunSocketHandler
| NetworkStunSocketHandler (SOCKET s=INVALID_SOCKET)
| Create a new cs socket handler for a given cs. More...
Public Member Functions inherited from NetworkTCPSocketHandler
bool | IsConnected () const
| Whether this socket is currently bound to a socket. 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< Packet > | ReceivePacket ()
| 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.

## Static Public Member Functions
static std::unique_ptr< ClientNetworkStunSocketHandler > | Stun (const std::string &token, uint8_t family)
| Send a STUN packet to the STUN server. More...

## Data Fields
std::shared_ptr< TCPConnecter > | connecter {}
| Connecter instance.
NetworkAddress | local_addr
| Local addresses of the socket.
Data Fields inherited from NetworkTCPSocketHandler
SOCKET | sock
| The socket currently connected to.
bool | writable
| Can we write to this socket?

## Private Attributes
std::string | token
| Token of this STUN handler.
uint8_t | family = AF_UNSPEC
| Family of this STUN handler.
bool | sent_result = false
| Did we sent the result of the STUN connection?

## Additional Inherited Members
Protected Member Functions inherited from NetworkStunSocketHandler
bool | ReceiveInvalidPacket (PacketStunType type)
| Helper for logging receiving invalid packets. More...
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. More...

## Detailed Description

Class for handling the client side of the STUN connection.

Definition at line 16 of file network_stun.h.

## Member Function Documentation

## ◆ CloseConnection()

NetworkRecvStatus ClientNetworkStunSocketHandler::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

  error | Whether we quit under an error condition or not.

Returns
  new status of the connection.

Reimplemented from NetworkTCPSocketHandler.

Definition at line 105 of file network_stun.cpp.

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

## ◆ Connect()

void ClientNetworkStunSocketHandler::Connect | ( | const std::string & | token,
|  | uint8_t | family
| ) |  |

Connect to the STUN server over either IPv4 or IPv6.

Parameters

  token | The token as received from the Game Coordinator.
  family | What IP family to use.

Definition at line 73 of file network_stun.cpp.

References connecter, Debug, family, NetworkStunConnectionString(), and token.

## ◆ Stun()

std::unique_ptr< ClientNetworkStunSocketHandler > ClientNetworkStunSocketHandler::Stun | ( | const std::string & | token,
|  | uint8_t | family
| ) |  |
| static

Send a STUN packet to the STUN server.

Parameters

  token | The token as received from the Game Coordinator.
  family | What IP family this STUN request is for.

Returns
  The handler for this STUN request.

Definition at line 89 of file network_stun.cpp.

References family, NETWORK_COORDINATOR_VERSION, PACKET_STUN_SERCLI_STUN, and token.

Referenced by ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_REQUEST().

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

- src/network/network_stun.h
- src/network/network_stun.cpp