35 stun_handler(stun_handler),
43 Debug(net, 9,
"Stun::OnFailure(): family={}", this->family);
55 Debug(net, 9,
"Stun::OnConnect(): family={}", this->family);
59 assert(this->stun_handler->
sock == INVALID_SOCKET);
60 this->stun_handler->
sock = s;
80 Debug(net, 9,
"Stun::Connect(): family={}", this->family);
93 auto stun_handler = std::make_unique<ClientNetworkStunSocketHandler>();
99 p->Send_string(
token);
103 stun_handler->SendPacket(std::move(p));
121ClientNetworkStunSocketHandler::~ClientNetworkStunSocketHandler()
135 if (this->
sock == INVALID_SOCKET)
return;
Class for handling the client side of the STUN connection.
std::string token
Token of this STUN handler.
void SendReceive()
Check whether we received/can send some data from/to the STUN server and when that's the case handle ...
uint8_t family
Family of this STUN handler.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
NetworkAddress local_addr
Local addresses of the socket.
void Connect(std::string_view token, uint8_t family)
Connect to the STUN server over either IPv4 or IPv6.
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(std::string_view token, uint8_t family)
Send a STUN packet to the STUN server.
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
bool sent_result
Did we sent the result of the STUN connection?
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
NetworkStunConnecter(ClientNetworkStunSocketHandler *stun_handler, std::string_view connection_string, std::string_view token, uint8_t family)
Initiate the connecting.
void OnConnect(SOCKET s) override
Callback when the connection succeeded.
void OnFailure() override
Callback for when the connection attempt failed.
virtual NetworkRecvStatus CloseConnection(bool error=true)
This will put this socket handler in a close state.
SOCKET sock
The socket currently connected to.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
bool CanSendReceive()
Check whether this socket can send or receive something.
std::string connection_string
Current address we are connecting to (before resolving).
static std::shared_ptr< TCPConnecter > Create(Args &&... args)
Create the connecter, and initiate connecting by putting it in the collection of TCP connections to m...
std::string_view NetworkStunConnectionString()
Get the connection string for the STUN server from the environment variable OTTD_STUN_CS,...
static const uint16_t NETWORK_STUN_SERVER_PORT
The default port of the STUN server (TCP).
static const uint8_t NETWORK_COORDINATOR_VERSION
What version of game-coordinator-protocol do we use?
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
@ NETWORK_RECV_STATUS_OKAY
Everything is okay.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
ClientNetworkCoordinatorSocketHandler _network_coordinator_client
The connection to the Game Coordinator.
Part of the network protocol handling Game Coordinator requests.
Part of the network protocol handling STUN requests.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
@ SPS_ALL_SENT
All packets in the queue are sent.
@ PACKET_STUN_SERCLI_STUN
Send a STUN request to the STUN server.