OpenTTD Source  20241108-master-g80f628063a
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 */
Class for handling the client side of the STUN connection.
Definition: network_stun.h:16
void Connect(const std::string &token, uint8_t family)
Connect to the STUN server over either IPv4 or IPv6.
std::string token
Token of this STUN handler.
Definition: network_stun.h:18
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.
Definition: network_stun.h:19
static std::unique_ptr< ClientNetworkStunSocketHandler > Stun(const std::string &token, uint8_t family)
Send a STUN packet to the STUN server.
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
Definition: network_stun.h:23
NetworkAddress local_addr
Local addresses of the socket.
Definition: network_stun.h:24
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?
Definition: network_stun.h:20
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Definition: address.h:28
Base socket handler for all STUN TCP sockets.
Definition: tcp_stun.h:26
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:23
Basic functions to receive and send TCP packets to/from the STUN server.