OpenTTD Source  12.0-beta2
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;
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  TCPConnecter *connecter = nullptr;
28  bool connect_started = false;
29 
31 
32  NetworkRecvStatus CloseConnection(bool error = true) override;
33  void SendReceive();
34 
35  void Connect();
36  void ConnectFailure();
37 
38  static std::unique_ptr<ClientNetworkTurnSocketHandler> Turn(const std::string &token, uint8 tracking_number, const std::string &ticket, const std::string &connection_string);
39 };
40 
41 #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::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:55
TCPConnecter
"Helper" class for creating TCP connections in a non-blocking manner
Definition: tcp.h:71
tcp_turn.h
ClientNetworkTurnSocketHandler::connecter
TCPConnecter * connecter
Connecter instance.
Definition: network_turn.h:27
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:44
ClientNetworkTurnSocketHandler::Connect
void Connect()
Connect to the TURN server.
Definition: network_turn.cpp:73
ClientNetworkTurnSocketHandler::tracking_number
uint8 tracking_number
Tracking number of this connection.
Definition: network_turn.h:19
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:48
error
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
Definition: openttd.cpp:132
ClientNetworkTurnSocketHandler::Turn
static std::unique_ptr< ClientNetworkTurnSocketHandler > Turn(const std::string &token, uint8 tracking_number, const std::string &ticket, const std::string &connection_string)
Prepare a TURN connection.
Definition: network_turn.cpp:89
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:126
ClientNetworkTurnSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition: network_turn.cpp:107