OpenTTD Source: src/network/network_turn.h Source File

OpenTTD Source 14.0-beta1

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
16 class ClientNetworkTurnSocketHandler : public NetworkTurnSocketHandler {
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
30 ClientNetworkTurnSocketHandler(const std::string &token, uint8_t tracking_number, const std::string &connection_string) : token(token), tracking_number(tracking_number), connection_string(connection_string) {}
31
32 NetworkRecvStatus CloseConnection(bool error = true) override;
33 ~ClientNetworkTurnSocketHandler() 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 */
ClientNetworkTurnSocketHandler::connection_string
std::string connection_string
The connection string of the TURN server we are connecting to.
Definition: network_turn.h:20
ClientNetworkTurnSocketHandler::Turn
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.
Definition: network_turn.cpp:99
ClientNetworkTurnSocketHandler::Receive_TURN_CONNECTED
bool Receive_TURN_CONNECTED(Packet *p) override
TURN server has connected client and server together and will now relay all packets to each other.
Definition: network_turn.cpp:61
ClientNetworkTurnSocketHandler::connecter
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
Definition: network_turn.h:27
tcp_turn.h
NetworkTurnSocketHandler
Base socket handler for all TURN TCP sockets.
Definition: tcp_turn.h:29
ClientNetworkTurnSocketHandler
Class for handling the client side of the TURN connection.
Definition: network_turn.h:16
ClientNetworkTurnSocketHandler::token
std::string token
Token of this connection.
Definition: network_turn.h:18
Packet
Internal entity of a packet.
Definition: packet.h:42
ClientNetworkTurnSocketHandler::Connect
void Connect()
Connect to the TURN server.
Definition: network_turn.cpp:81
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition: core.h:22
ClientNetworkTurnSocketHandler::connect_started
bool connect_started
Whether we started the connection.
Definition: network_turn.h:28
ClientNetworkTurnSocketHandler::Receive_TURN_ERROR
bool Receive_TURN_ERROR(Packet *p) override
TURN server was unable to connect the client or server based on the token.
Definition: network_turn.cpp:52
ClientNetworkTurnSocketHandler::tracking_number
uint8_t tracking_number
Tracking number of this connection.
Definition: network_turn.h:19
ClientNetworkTurnSocketHandler::SendReceive
void SendReceive()
Check whether we received/can send some data from/to the TURN server and when that's the case handle ...
Definition: network_turn.cpp:142
ClientNetworkTurnSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition: network_turn.cpp:117