OpenTTD Source  20241108-master-g80f628063a
network_turn.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_TURN_H
11 #define NETWORK_TURN_H
12 
13 #include "core/tcp_turn.h"
14 
17 private:
18  std::string token;
19  uint8_t tracking_number;
20  std::string connection_string;
21 
22 protected:
23  bool Receive_TURN_ERROR(Packet &p) override;
24  bool Receive_TURN_CONNECTED(Packet &p) override;
25 
26 public:
27  std::shared_ptr<TCPConnecter> connecter{};
28  bool connect_started = false;
29 
31 
32  NetworkRecvStatus CloseConnection(bool error = true) override;
34  void SendReceive();
35 
36  void Connect();
37  void ConnectFailure();
38 
39  static std::unique_ptr<ClientNetworkTurnSocketHandler> Turn(const std::string &token, uint8_t tracking_number, const std::string &ticket, const std::string &connection_string);
40 };
41 
42 #endif /* NETWORK_TURN_H */
Class for handling the client side of the TURN connection.
Definition: network_turn.h:16
bool Receive_TURN_ERROR(Packet &p) override
TURN server was unable to connect the client or server based on the token.
bool connect_started
Whether we started the connection.
Definition: network_turn.h:28
uint8_t tracking_number
Tracking number of this connection.
Definition: network_turn.h:19
std::string token
Token of this connection.
Definition: network_turn.h:18
void Connect()
Connect to the TURN server.
bool Receive_TURN_CONNECTED(Packet &p) override
TURN server has connected client and server together and will now relay all packets to each other.
static std::unique_ptr< ClientNetworkTurnSocketHandler > Turn(const std::string &token, uint8_t tracking_number, const std::string &ticket, const std::string &connection_string)
Prepare a TURN connection.
void SendReceive()
Check whether we received/can send some data from/to the TURN server and when that's the case handle ...
std::string connection_string
The connection string of the TURN server we are connecting to.
Definition: network_turn.h:20
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
Definition: network_turn.h:27
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Base socket handler for all TURN TCP sockets.
Definition: tcp_turn.h:29
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:23
Internal entity of a packet.
Definition: packet.h:42
Basic functions to receive and send TCP packets to/from the TURN server.