25 Commits

Author SHA1 Message Date
Cthulhu-throwaway
690c802921
Netplay Stuff (#13375)
* Netplay Stuff

## PROTOCOL FALLBACK
In order to support older clients a protocol fallback system was introduced.
The host will no longer send its header automatically after a TCP connection is established, instead, it awaits for the client to send his before determining which protocol this connection is going to operate on.
Netplay has now two protocols, a low protocol and a high protocol; the low protocol is the minimum protocol it supports, while the high protocol is the highest protocol it can operate on.
To fully support older clients, a hack was necessary: sending the high protocol in the unused client's header salt field, while keeping the protocol field to the low protocol. Without this hack we would only be able to support older clients if a newer client was the host.
Any future system can make use of this system by checking connection->netplay_protocol, which is available for both the client and host.

## NETPLAY CHAT
Starting with protocol 6, netplay chat is available through the new NETPLAY_CMD_PLAYER_CHAT command.
Limitations of the command code, which causes a disconnection on unknown commands, makes this system not possible on protocol 5.
Protocol 5 connections can neither send nor receive chat, but other netplay operations are unaffected.
Clients send chat as a string to the server, and it's the server's sole responsability to relay chat messages.
As of now, sending chat uses RetroArch's input menu, while the display of on-screen chat uses a widget overlay and RetroArch's notifications as a fallback.
If a new overlay and/or input system is desired, no backwards compatibility changes need to be made.
Only clients in playing mode (as opposed to spectating mode) can send and receive chat.

## SETTINGS SHARING
Some settings are better used when both host and clients share the same configuration.
As of protocol 6, the following settings will be shared from host to clients (without altering a client's configuration file): input latency frames and allow pausing.

## NETPLAY TUNNEL/MITM
With the current MITM system being defunct (at least as of 1.9.X), a new system was in order to solve most if not all of the problems with the current system.
This new system uses a tunneling approach, which is similar to most VPN and tunneling services around.

Tunnel commands:
RATS[unique id] (RetroArch Tunnel Session) - 16 bytes -> When this command is sent with a zeroed unique id, the tunnel server interprets this as a netplay host wanting to create a new session, in this case, the same command is returned to the host, but now with its unique session id. When a client needs to connect to a host, this command is sent with the unique session id of the host, causing the tunnel server to send a RATL command to the host.
RATL[unique id] (RetroArch Tunnel Link) - 16 bytes -> The tunnel server sends this command to the host when a client wants to connect to the host. Once the host receives this command, it establishes a new connection to the tunnel server, sending this command together with the client's unique id through this new connection, causing the tunnel server to link this connection to the connection of the client.
RATP (RetroArch Tunnel Ping) - 4 bytes -> The tunnel server sends this command to verify that the host, whom the session belongs to, is still around. The host replies with the same command. A session is closed if the tunnel server can not verify that the host is alive.

Operations:
Host -> Instead of listening and accepting connections, it connects to the tunnel server, requests a new session and then monitor this connection for new linking requests. Once a request is received, it establishes a new connection to the tunnel server for linking with a client. The tunnel server's address and port are obtained by querying the lobby server. The host will publish its session id together with the rest of its info to the lobby server.
Client -> It connects to the tunnel server and then sends the session id of the host it wants to connect to. A host's session id is obtained from the json data sent by the lobby server.

Improvements (from current MITM system):
No longer a risk of TCP port exhaustion; we only use one port now at the tunnel server.
Very little cpu usage. About 95% net I/O bound now.
Future backwards compatible with any and all changes to netplay as it no longer runs any netplay logic at MITM servers.
No longer operates the host in client mode, which was a source of many of the current problems.
Cleaner and more maintainable system and code.

Notable functions:
netplay_mitm_query -> Grabs the tunnel's address and port from the lobby server.
init_tcp_socket -> Handles the creation and operation mode of the TCP socket based on whether it's host, host+MITM or client.
handle_mitm_connection -> Creates and completes linking connections and replies to ping commands (only 1 of each per call to not affect performance).

## MISC
Ping Limiter: If a client's estimated latency to the server is higher than this value, connection will be dropped just before finishing the netplay handshake.
Ping Counter: A ping counter (similar to the FPS one) can be shown in the bottom right corner of the screen, if you are connected to a host.
LAN Discovery: Refactored and moved to its own "Refresh Netplay LAN List" button.

## FIXES
Many minor fixes to the current netplay implementation are also included.

* Remove NETPLAY_TEST_BUILD
2021-12-19 16:58:01 +01:00
twinaphex
1f4123ba54 Don't include netplay.h header unless we have HAVE_NETWORKING
defined
2021-11-05 19:50:02 +01:00
twinaphex
67c010394d Remove netplay_discovery.h - hopefully fixes other build issues 2021-11-05 19:12:55 +01:00
twinaphex
d07e0da412 Improve HAVE_NETWORKING and HAVE_NETPLAYDISCOVERY ifdefs; remove
unused netplay lan scan rooms function
2021-08-12 16:44:07 +02:00
radius
d865c5e4a6 add some copyright on files I contributed considerably just in case 2019-06-20 05:45:17 +02:00
natinusala
c20ab3864d First version of menu widgets (gl only) 2019-02-06 20:48:24 +01:00
twinaphex
0083e10926 Some header include changes - create task_file_transfer.h 2019-01-20 02:17:43 +01:00
gblues
6904101c44 Clean up trailing whitespace
== DETAILS

Really simple code cleanup, because my editor flags trailing whitespaces
and it's pretty annoying.
2017-12-12 00:24:18 -08:00
radius
a98c2c38c0 update copyrights 2017-05-23 19:55:47 -05:00
twinaphex
8e76c4a131 Prevent title memory leak 2017-05-16 02:48:54 +02:00
twinaphex
56fb642119 Rewrite task_netplay_lan_scan.c - pass callback function to task 2017-05-15 02:09:26 +02:00
twinaphex
80d9d1f143 Rewrite task_queue 2017-05-14 20:43:48 +02:00
radius
e50ea80dfa integrate the rest of the lan scan parameters 2017-02-27 21:24:34 -05:00
radius
b719f30b8e add lan games 2017-02-27 19:00:43 -05:00
twinaphex
d1aff197b9 Cleanup netplay_lan_scan_callback 2017-02-18 22:12:41 +01:00
twinaphex
e3a1b1859d Fix ./configure --disable-rgui 2017-02-04 09:20:41 +01:00
twinaphex
4aac4aa2e6 Revert "Use task_set_title"
This reverts commit c867784898efa94f39911512ecd2202191efef38.
2017-01-23 14:15:26 +01:00
twinaphex
c867784898 Use task_set_title 2017-01-23 13:19:35 +01:00
twinaphex
96c8ca5a09 Header update #1 2017-01-22 13:40:32 +01:00
Brad Parker
41f40acfc4 guard task struct read/writes across threads with a mutex, fixes several data races found by ThreadSanitizer and helgrind 2016-12-29 00:54:12 -05:00
twinaphex
81096a27b9 Fix one Coverity issue 2016-12-05 07:06:32 +01:00
twinaphex
47274607f4 (tasks) * Respect 80-char limit - * Fix leaking of ssid_list in task_wifi.c 2016-12-04 19:08:24 +01:00
twinaphex
e2b27f6dc7 (tasks) Cleanups 2016-12-04 04:30:43 +01:00
Gregor Richards
0577749fae Netplay LAN scanning is go! (sort of) 2016-12-02 22:40:26 -05:00
Gregor Richards
addff325d0 Netplay discovery LAN scanning task (incomplete) 2016-12-02 18:56:29 -05:00