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

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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 {
17private:
18 std::string token;
19 uint8_t tracking_number;
20 std::string connection_string;
21
22protected:
23 bool Receive_TURN_ERROR(Packet &p) override;
24 bool Receive_TURN_CONNECTED(Packet &p) override;
25
26public:
27 std::shared_ptr<TCPConnecter> connecter{};
28 bool connect_started = false;
29
30 ClientNetworkTurnSocketHandler(std::string_view token, uint8_t tracking_number, std::string_view 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(std::string_view token, uint8_t tracking_number, std::string_view ticket, std::string_view connection_string);
40};
41
42#endif /* NETWORK_TURN_H */
ClientNetworkTurnSocketHandler
Class for handling the client side of the TURN connection.
Definition network_turn.h:16
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:49
ClientNetworkTurnSocketHandler::connect_started
bool connect_started
Whether we started the connection.
Definition network_turn.h:28
ClientNetworkTurnSocketHandler::tracking_number
uint8_t tracking_number
Tracking number of this connection.
Definition network_turn.h:19
ClientNetworkTurnSocketHandler::token
std::string token
Token of this connection.
Definition network_turn.h:18
ClientNetworkTurnSocketHandler::Connect
void Connect()
Connect to the TURN server.
Definition network_turn.cpp:78
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:58
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:139
ClientNetworkTurnSocketHandler::connection_string
std::string connection_string
The connection string of the TURN server we are connecting to.
Definition network_turn.h:20
ClientNetworkTurnSocketHandler::connecter
std::shared_ptr< TCPConnecter > connecter
Connecter instance.
Definition network_turn.h:27
ClientNetworkTurnSocketHandler::CloseConnection
NetworkRecvStatus CloseConnection(bool error=true) override
This will put this socket handler in a close state.
Definition network_turn.cpp:114
ClientNetworkTurnSocketHandler::Turn
static std::unique_ptr< ClientNetworkTurnSocketHandler > Turn(std::string_view token, uint8_t tracking_number, std::string_view ticket, std::string_view connection_string)
Prepare a TURN connection.
Definition network_turn.cpp:96
NetworkTurnSocketHandler
Base socket handler for all TURN TCP sockets.
Definition tcp_turn.h:29
NetworkRecvStatus
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
Definition core.h:23
Packet
Internal entity of a packet.
Definition packet.h:43
tcp_turn.h
Basic functions to receive and send TCP packets to/from the TURN server.