OpenTTD Source  20240919-master-gdf0233f4c2
network_stun.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef NETWORK_STUN_H
11 #define NETWORK_STUN_H
12 
13 #include "core/tcp_stun.h"
14 
17 private:
18  std::string token;
19  uint8_t family = AF_UNSPEC;
20  bool sent_result = false;
21 
22 public:
23  std::shared_ptr<TCPConnecter> connecter{};
25 
26  NetworkRecvStatus CloseConnection(bool error = true) override;
28  void SendReceive();
29 
30  void Connect(const std::string &token, uint8_t family);
31 
32  static std::unique_ptr<ClientNetworkStunSocketHandler> Stun(const std::string &token, uint8_t family);
33 };
34 
35 #endif /* NETWORK_STUN_H */
tcp_stun.h
ClientNetworkStunSocketHandler::Connect
void Connect(const std::string &token, uint8_t family)
Connect to the STUN server over either IPv4 or IPv6.
Definition: network_stun.cpp:73
ClientNetworkStunSocketHandler::local_addr
NetworkAddress local_addr
Local addresses of the socket.
Definition: network_stun.h:24
ClientNetworkStunSocketHandler::family
uint8_t family
Family of this STUN handler.
Definition: network_stun.h:19
ClientNetworkStunSocketHandler::connecter
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
Definition: network_stun.h:23
ClientNetworkStunSocketHandler::token
std::string token
Token of this STUN handler.
Definition: network_stun.h:18
ClientNetworkStunSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition: network_stun.cpp:105
NetworkAddress
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Definition: address.h:28
ClientNetworkStunSocketHandler::SendReceive
void SendReceive()
Check whether we received/can send some data from/to the STUN server and when that's the case handle ...
Definition: network_stun.cpp:130
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:23
ClientNetworkStunSocketHandler::Stun
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(const std::string &token, uint8_t family)
Send a STUN packet to the STUN server.
Definition: network_stun.cpp:89
ClientNetworkStunSocketHandler::sent_result
bool sent_result
Did we sent the result of the STUN connection?
Definition: network_stun.h:20
NetworkStunSocketHandler
Base socket handler for all STUN TCP sockets.
Definition: tcp_stun.h:26
ClientNetworkStunSocketHandler
Class for handling the client side of the STUN connection.
Definition: network_stun.h:16