From 801bc5bd6593cc027eb7f263223b14a0db92370b Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:43:07 +0900 Subject: [PATCH] add wivrn+tcp scheme --- AndroidManifest.xml | 1 + client/application.cpp | 6 ++++++ client/application.h | 6 ++++++ client/configuration.cpp | 2 ++ client/main.cpp | 1 + client/scenes/lobby.cpp | 4 ++-- client/wivrn_client.cpp | 12 ++++++------ client/wivrn_client.h | 6 +++--- client/wivrn_discover.h | 1 + 9 files changed, 28 insertions(+), 11 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 17d8c678..84685912 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -106,6 +106,7 @@ + diff --git a/client/application.cpp b/client/application.cpp index 23a3b96c..f7621238 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -959,6 +959,12 @@ application::application(application_info info) : server_address = data_string.substr(strlen("wivrn://")); } + if (data_string.starts_with("wivrn+tcp://")) + { + server_address = data_string.substr(strlen("wivrn+tcp://")); + server_tcp_only = true; + } + auto files_dir = ctx.call>("getFilesDir"); if (auto files_dir_path = files_dir.call("getAbsolutePath")) { diff --git a/client/application.h b/client/application.h index 6a7efd05..79a27592 100644 --- a/client/application.h +++ b/client/application.h @@ -147,6 +147,7 @@ class application : public singleton std::shared_ptr wifi; std::string server_address; + bool server_tcp_only = false; std::mutex scene_stack_lock; std::vector> scene_stack; @@ -377,6 +378,11 @@ public: return server_address; } + const bool & get_server_tcp_only() const + { + return server_tcp_only; + } + static vk::raii::PhysicalDevice & get_physical_device() { return instance().vk_physical_device; diff --git a/client/configuration.cpp b/client/configuration.cpp index 5a9d926e..e1646628 100644 --- a/client/configuration.cpp +++ b/client/configuration.cpp @@ -103,6 +103,7 @@ configuration::configuration(const std::string & path) .name = (std::string)i["pretty_name"], .hostname = (std::string)i["hostname"], .port = (int)i["port"].get_int64(), + .tcp_only = i["tcp_only"].is_bool() && i["tcp_only"].get_bool(), .txt = {{"cookie", (std::string)i["cookie"]}} }}; @@ -143,6 +144,7 @@ void configuration::save() ss << "\"pretty_name\":" << json_string(server_data.service.name) << ","; ss << "\"hostname\":" << json_string(server_data.service.hostname) << ","; ss << "\"port\":" << server_data.service.port << ","; + ss << "\"tcp_only\":" << std::boolalpha << server_data.service.tcp_only << ","; ss << "\"cookie\":" << json_string(cookie); ss << "},"; } diff --git a/client/main.cpp b/client/main.cpp index 030e2433..996572e9 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -71,6 +71,7 @@ void real_main() .name = app.get_server_address(), .hostname = server_address, .port = port, + .tcp_only = app.get_server_tcp_only(), }, }; } diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 14eb95be..45247662 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -224,8 +224,8 @@ std::unique_ptr connect_to_session(wivrn_discover::service servic { spdlog::debug("Trying address {}", address_string); - return std::visit([port = service.port](auto & address) { - return std::make_unique(address, port); + return std::visit([port = service.port, tcp_only = service.tcp_only](auto & address) { + return std::make_unique(address, port, tcp_only); }, address); } diff --git a/client/wivrn_client.cpp b/client/wivrn_client.cpp index ca0f54a9..7a36f291 100644 --- a/client/wivrn_client.cpp +++ b/client/wivrn_client.cpp @@ -49,7 +49,7 @@ void init_stream(T & stream) } // namespace template -void wivrn_session::handshake(T address) +void wivrn_session::handshake(T address, bool tcp_only) { // Wait for handshake on control socket, // then send ours on stream or control socket, @@ -75,7 +75,7 @@ void wivrn_session::handshake(T address) try { auto h = std::get(*packet); - if (h.stream_port > 0) + if (h.stream_port > 0 && !tcp_only) { stream = decltype(stream)(); stream.connect(address, h.stream_port); @@ -113,18 +113,18 @@ void wivrn_session::handshake(T address) } } -wivrn_session::wivrn_session(in6_addr address, int port) : +wivrn_session::wivrn_session(in6_addr address, int port, bool tcp_only) : control(address, port), stream(-1), address(address) { char buffer[100]; spdlog::info("Connection to {}:{}", inet_ntop(AF_INET6, &address, buffer, sizeof(buffer)), port); - handshake(address); + handshake(address, tcp_only); } -wivrn_session::wivrn_session(in_addr address, int port) : +wivrn_session::wivrn_session(in_addr address, int port, bool tcp_only) : control(address, port), stream(-1), address(address) { char buffer[100]; spdlog::info("Connection to {}:{}", inet_ntop(AF_INET, &address, buffer, sizeof(buffer)), port); - handshake(address); + handshake(address, tcp_only); } diff --git a/client/wivrn_client.h b/client/wivrn_client.h index fb6ee91d..ff8b9ca1 100644 --- a/client/wivrn_client.h +++ b/client/wivrn_client.h @@ -31,13 +31,13 @@ class wivrn_session typed_socket stream; template - void handshake(T address); + void handshake(T address, bool tcp_only); public: std::variant address; - wivrn_session(in6_addr address, int port); - wivrn_session(in_addr address, int port); + wivrn_session(in6_addr address, int port, bool tcp_only); + wivrn_session(in_addr address, int port, bool tcp_only); wivrn_session(const wivrn_session &) = delete; wivrn_session & operator=(const wivrn_session &) = delete; diff --git a/client/wivrn_discover.h b/client/wivrn_discover.h index 543de5b3..7b31b426 100644 --- a/client/wivrn_discover.h +++ b/client/wivrn_discover.h @@ -20,6 +20,7 @@ public: std::string name; std::string hostname; int port; + bool tcp_only = false; std::vector> addresses; std::map txt;