OpenTTD Source
20241121-master-g67a0fccfad
|
Class for handling the client side of the STUN connection. More...
#include <network_stun.h>
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... | |
Protected Attributes inherited from NetworkSocketHandler | |
std::unique_ptr< class NetworkEncryptionHandler > | receive_encryption_handler |
The handler for decrypting received packets. | |
std::unique_ptr< class NetworkEncryptionHandler > | send_encryption_handler |
The handler for encrypting sent packets. | |
Class for handling the client side of the STUN connection.
Definition at line 16 of file network_stun.h.
|
overridevirtual |
This will put this socket handler in a close state.
It will not actually close the OS socket; use CloseSocket for this.
error | Whether we quit under an error condition or not. |
Reimplemented from NetworkTCPSocketHandler.
Definition at line 105 of file network_stun.cpp.
References NetworkTCPSocketHandler::CloseConnection(), connecter, and NETWORK_RECV_STATUS_OKAY.
void ClientNetworkStunSocketHandler::Connect | ( | const std::string & | token, |
uint8_t | family | ||
) |
Connect to the STUN server over either IPv4 or IPv6.
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.
|
static |
Send a STUN packet to the STUN server.
token | The token as received from the Game Coordinator. |
family | What IP family this STUN request is for. |
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().