OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
16 #include "../safeguards.h"
33 stun_handler(stun_handler),
41 Debug(net, 9,
"Stun::OnFailure(): family={}", this->family);
51 void OnConnect(SOCKET s)
override
53 Debug(net, 9,
"Stun::OnConnect(): family={}", this->family);
57 assert(this->stun_handler->
sock == INVALID_SOCKET);
58 this->stun_handler->
sock = s;
78 Debug(net, 9,
"Stun::Connect(): family={}", this->family);
91 auto stun_handler = std::make_unique<ClientNetworkStunSocketHandler>();
97 p->Send_string(
token);
100 stun_handler->SendPacket(std::move(p));
118 ClientNetworkStunSocketHandler::~ClientNetworkStunSocketHandler()
132 if (this->
sock == INVALID_SOCKET)
return;
std::string connection_string
Current address we are connecting to (before resolving).
"Helper" class for creating TCP connections in a non-blocking manner
void Connect(const std::string &token, uint8_t family)
Connect to the STUN server over either IPv4 or IPv6.
static const uint8_t NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
SOCKET sock
The socket currently connected to.
void StunResult(const std::string &token, uint8_t family, bool result)
Callback from the STUN connecter to inform the Game Coordinator about the result of the STUN.
const char * NetworkStunConnectionString()
Get the connection string for the STUN server from the environment variable OTTD_STUN_CS,...
@ SPS_ALL_SENT
All packets in the queue are sent.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
NetworkAddress local_addr
Local addresses of the socket.
void OnFailure() override
Callback for when the connection attempt failed.
uint8_t family
Family of this STUN handler.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
virtual NetworkRecvStatus CloseConnection(bool error=true)
This will put this socket handler in a close state.
std::string token
Token of this STUN handler.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
NetworkStunConnecter(ClientNetworkStunSocketHandler *stun_handler, const std::string &connection_string, const std::string &token, uint8_t family)
Initiate the connecting.
bool CanSendReceive()
Check whether this socket can send or receive something.
void SendReceive()
Check whether we received/can send some data from/to the STUN server and when that's the case handle ...
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(const std::string &token, uint8_t family)
Send a STUN packet to the STUN server.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
bool sent_result
Did we sent the result of the STUN connection?
static const uint16_t NETWORK_STUN_SERVER_PORT
The default port of the STUN server (TCP)
Class for handling the client side of the STUN connection.
Connect to the STUN server.
@ PACKET_STUN_SERCLI_STUN
Send a STUN request to the STUN server.