Skip to content

Commit

Permalink
WIP: TURN
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain committed May 5, 2021
1 parent 24612b3 commit 628266f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/network/core/tcp_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bool NetworkCoordinatorSocketHandler::HandlePacket(Packet *p)
case PACKET_COORDINATOR_SERVER_STUN_REQUEST: return this->Receive_SERVER_STUN_REQUEST(p);
case PACKET_COORDINATOR_SERVER_STUN_CONNECT: return this->Receive_SERVER_STUN_CONNECT(p);
case PACKET_COORDINATOR_SERVER_STUN_ACCEPT: return this->Receive_SERVER_STUN_ACCEPT(p);
case PACKET_COORDINATOR_SERVER_TURN_CONNECT: return this->Receive_SERVER_TURN_CONNECT(p);

default:
DEBUG(net, 0, "[tcp/coordinator] received invalid packet type %d", type);
Expand Down Expand Up @@ -98,3 +99,4 @@ bool NetworkCoordinatorSocketHandler::Receive_SERVER_DIRECT_CONNECT(Packet *p) {
bool NetworkCoordinatorSocketHandler::Receive_SERVER_STUN_REQUEST(Packet *p) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_STUN_REQUEST); }
bool NetworkCoordinatorSocketHandler::Receive_SERVER_STUN_CONNECT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_STUN_CONNECT); }
bool NetworkCoordinatorSocketHandler::Receive_SERVER_STUN_ACCEPT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_STUN_ACCEPT); }
bool NetworkCoordinatorSocketHandler::Receive_SERVER_TURN_CONNECT(Packet *p) { return this->ReceiveInvalidPacket(PACKET_COORDINATOR_SERVER_TURN_CONNECT); }
15 changes: 15 additions & 0 deletions src/network/core/tcp_coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum PacketCoordinatorType {
PACKET_COORDINATOR_SERVER_STUN_REQUEST, ///< Game Coordinator tells client/server to initiate a STUN request.
PACKET_COORDINATOR_SERVER_STUN_CONNECT, ///< Game Coordinator tells client/server to connect() reusing the STUN local address.
PACKET_COORDINATOR_SERVER_STUN_ACCEPT, ///< Game Coordinator tells client/server to accept() reusing the STUN local address.
PACKET_COORDINATOR_SERVER_TURN_CONNECT, ///< Game Coordinator tells client/server to connect to TURN server.
PACKET_COORDINATOR_END, ///< Must ALWAYS be on the end of this list!! (period)
};

Expand All @@ -43,6 +44,7 @@ enum ConnectionType {
CONNECTION_TYPE_ISOLATED, ///< The Game Coordinator failed to find a way to connect to your server. Nobody will be able to join.
CONNECTION_TYPE_DIRECT, ///< The Game Coordinator can directly connect to your server.
CONNECTION_TYPE_STUN, ///< The Game Coordinator can connect to your server via a STUN request.
CONNECTION_TYPE_TURN, ///< The Game Coordinator needs you to connect to a relay.
};

/** Base socket handler for all Game Coordinator TCP sockets */
Expand Down Expand Up @@ -215,6 +217,19 @@ class NetworkCoordinatorSocketHandler : public NetworkTCPSocketHandler {
*/
virtual bool Receive_SERVER_STUN_ACCEPT(Packet *p);

/**
* Game Coordinator requests that we make a direct connection to the
* indicated peer, which is a TURN server.
*
* string Token to track the current connect request.
* string Host of the peer.
* uint16 Port of the peer.
*
* @param p The packet that was just received.
* @return True upon success, otherwise false.
*/
virtual bool Receive_SERVER_TURN_CONNECT(Packet *p);

bool HandlePacket(Packet *p);
public:
/**
Expand Down
7 changes: 7 additions & 0 deletions src/network/network_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ bool ClientNetworkCoordinatorSocketHandler::Receive_SERVER_STUN_ACCEPT(Packet *p
return true;
}

bool ClientNetworkCoordinatorSocketHandler::Receive_SERVER_TURN_CONNECT(Packet *p)
{
// TODO

return true;
}

void ClientNetworkCoordinatorSocketHandler::Connect()
{
/* We are either already connected or are trying to connect. */
Expand Down
5 changes: 5 additions & 0 deletions src/network/network_coordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
* - a) Server/client connect, client closes GC connection.
* - b) Server/client connect fails, connecting side sends CLIENT_CONNECT_FAILED to GC.
* - GC tries other combination if available.
* 3) TURN?
* - GC sends SERVER_TURN_CONNECT to server/client.
* - a) Server/client connect, client closes GC connection.
* - b) Server/client connect fails, both send CLIENT_CONNECT_FAILED to GC.
* - If all fails, GC sends SERVER_CONNECT_FAILED to indicate no connection was possible.
*/

Expand All @@ -61,6 +65,7 @@ class ClientNetworkCoordinatorSocketHandler : public NetworkCoordinatorSocketHan
bool Receive_SERVER_STUN_REQUEST(Packet *p) override;
bool Receive_SERVER_STUN_CONNECT(Packet *p) override;
bool Receive_SERVER_STUN_ACCEPT(Packet *p) override;
bool Receive_SERVER_TURN_CONNECT(Packet *p) override;

public:
bool connecting; ///< Are we connecting to the Game Coordinator?
Expand Down

0 comments on commit 628266f

Please sign in to comment.