OpenTTD Source 20241224-master-gee860a5c8e
|
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. | |
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. | |
Public Member Functions inherited from NetworkStunSocketHandler | |
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. | |
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< Packet > | ReceivePacket () |
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< ClientNetworkStunSocketHandler > | Stun (const std::string &token, uint8_t family) |
Send a STUN packet to the STUN server. | |
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. | |
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. | |
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.
|
override |
Definition at line 118 of file network_stun.cpp.
|
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.
void ClientNetworkStunSocketHandler::SendReceive | ( | ) |
Check whether we received/can send some data from/to the STUN server and when that's the case handle it appropriately.
Definition at line 130 of file network_stun.cpp.
References _network_coordinator_client, NetworkTCPSocketHandler::CanSendReceive(), family, NetworkTCPSocketHandler::SendPackets(), sent_result, NetworkTCPSocketHandler::sock, SPS_ALL_SENT, ClientNetworkCoordinatorSocketHandler::StunResult(), 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().
std::shared_ptr<TCPConnecter> ClientNetworkStunSocketHandler::connecter {} |
Connecter instance.
Definition at line 23 of file network_stun.h.
Referenced by CloseConnection(), Connect(), NetworkStunConnecter::OnConnect(), and NetworkStunConnecter::OnFailure().
|
private |
Family of this STUN handler.
Definition at line 19 of file network_stun.h.
Referenced by Connect(), SendReceive(), and Stun().
NetworkAddress ClientNetworkStunSocketHandler::local_addr |
Local addresses of the socket.
Definition at line 24 of file network_stun.h.
Referenced by NetworkStunConnecter::OnConnect().
|
private |
Did we sent the result of the STUN connection?
Definition at line 20 of file network_stun.h.
Referenced by SendReceive().
|
private |
Token of this STUN handler.
Definition at line 18 of file network_stun.h.
Referenced by Connect(), SendReceive(), and Stun().