summaryrefslogtreecommitdiff
path: root/src/network/network_turn.h
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-05-05 10:47:01 +0200
committerPatric Stout <github@truebrain.nl>2021-07-20 19:57:23 +0200
commitfa1e27994dd1284f6fefbe08c47a5c4145ccf00d (patch)
treebbe8fab946192e5667ef176673590d2fae60e969 /src/network/network_turn.h
parent8a361340037d6908c9a4df10aefdb58860a22b80 (diff)
downloadopenttd-fa1e27994dd1284f6fefbe08c47a5c4145ccf00d.tar.xz
Feature: allow the use of TURN to connect client and server together
TURN is a last resort, used only if all other methods failed. TURN is a relay approach to connect client and server together, where openttd.org (by default) is the middleman. It is very unlikely either the client or server cannot connect to the STUN server, as they are both already connected to the Game Coordinator. But in the odd case it does fail, estabilishing the connection fails without any further possibility to recover.
Diffstat (limited to 'src/network/network_turn.h')
-rw-r--r--src/network/network_turn.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/network/network_turn.h b/src/network/network_turn.h
new file mode 100644
index 000000000..cc569a977
--- /dev/null
+++ b/src/network/network_turn.h
@@ -0,0 +1,41 @@
+/*
+ * This file is part of OpenTTD.
+ * 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.
+ * 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.
+ * 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/>.
+ */
+
+/** @file network_turn.h Part of the network protocol handling TURN requests. */
+
+#ifndef NETWORK_TURN_H
+#define NETWORK_TURN_H
+
+#include "core/tcp_turn.h"
+
+/** Class for handling the client side of the TURN connection. */
+class ClientNetworkTurnSocketHandler : public NetworkTurnSocketHandler {
+private:
+ std::string token; ///< Token of this connection.
+ uint8 tracking_number; ///< Tracking number of this connection.
+ std::string connection_string; ///< The connection string of the TURN server we are connecting to.
+
+protected:
+ bool Receive_TURN_ERROR(Packet *p) override;
+ bool Receive_TURN_CONNECTED(Packet *p) override;
+
+public:
+ TCPConnecter *connecter = nullptr; ///< Connecter instance.
+ bool connect_started = false; ///< Whether we started the connection.
+
+ ClientNetworkTurnSocketHandler(const std::string &token, uint8 tracking_number, const std::string &connection_string) : token(token), tracking_number(tracking_number), connection_string(connection_string) {}
+
+ NetworkRecvStatus CloseConnection(bool error = true) override;
+ void SendReceive();
+
+ void Connect();
+ void ConnectFailure();
+
+ static std::unique_ptr<ClientNetworkTurnSocketHandler> Turn(const std::string &token, uint8 tracking_number, const std::string &ticket, const std::string &connection_string);
+};
+
+#endif /* NETWORK_TURN_H */