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.
This commit is contained in:

committed by
Patric Stout

parent
8a36134003
commit
fa1e27994d
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "core/tcp_coordinator.h"
|
||||
#include "network_stun.h"
|
||||
#include "network_turn.h"
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,10 @@
|
||||
* - a) Server/client connect, client sends CLIENT_CONNECTED to Game Coordinator.
|
||||
* - b) Server/client connect fails, both send SERCLI_CONNECT_FAILED to Game Coordinator.
|
||||
* - Game Coordinator tries other combination if available.
|
||||
* 3) TURN?
|
||||
* - Game Coordinator sends GC_TURN_CONNECT to server/client.
|
||||
* - a) Server/client connect, client sends CLIENT_CONNECTED to Game Coordinator.
|
||||
* - b) Server/client connect fails, both send SERCLI_CONNECT_FAILED to Game Coordinator.
|
||||
* - If all fails, Game Coordinator sends GC_CONNECT_FAILED to indicate no connection is possible.
|
||||
*/
|
||||
|
||||
@@ -52,6 +57,7 @@ private:
|
||||
std::map<std::string, TCPServerConnecter *> connecter; ///< Based on tokens, the current connecters that are pending.
|
||||
std::map<std::string, TCPServerConnecter *> connecter_pre; ///< Based on invite codes, the current connecters that are pending.
|
||||
std::map<std::string, std::map<int, std::unique_ptr<ClientNetworkStunSocketHandler>>> stun_handlers; ///< All pending STUN handlers, stored by token:family.
|
||||
std::map<std::string, std::unique_ptr<ClientNetworkTurnSocketHandler>> turn_handlers; ///< Pending TURN handler (if any), stored by token.
|
||||
TCPConnecter *game_connecter = nullptr; ///< Pending connecter to the game server.
|
||||
|
||||
uint32 newgrf_lookup_table_cursor = 0; ///< Last received cursor for the #GameInfoNewGRFLookupTable updates.
|
||||
@@ -67,6 +73,7 @@ protected:
|
||||
bool Receive_GC_STUN_REQUEST(Packet *p) override;
|
||||
bool Receive_GC_STUN_CONNECT(Packet *p) override;
|
||||
bool Receive_GC_NEWGRF_LOOKUP(Packet *p) override;
|
||||
bool Receive_GC_TURN_CONNECT(Packet *p) override;
|
||||
|
||||
public:
|
||||
/** The idle timeout; when to close the connection because it's idle. */
|
||||
@@ -88,12 +95,14 @@ public:
|
||||
void CloseToken(const std::string &token);
|
||||
void CloseAllConnections();
|
||||
void CloseStunHandler(const std::string &token, uint8 family = AF_UNSPEC);
|
||||
void CloseTurnHandler(const std::string &token);
|
||||
|
||||
void Register();
|
||||
void SendServerUpdate();
|
||||
void GetListing();
|
||||
|
||||
void ConnectToServer(const std::string &invite_code, TCPServerConnecter *connecter);
|
||||
void StartTurnConnection(std::string &token);
|
||||
};
|
||||
|
||||
extern ClientNetworkCoordinatorSocketHandler _network_coordinator_client;
|
||||
|
Reference in New Issue
Block a user