add wivrn+tcp scheme

This commit is contained in:
galister
2024-09-18 18:18:00 +02:00
committed by xytovl
parent 9a39f24541
commit 801bc5bd65
9 changed files with 28 additions and 11 deletions
+1
View File
@@ -106,6 +106,7 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="wivrn" /> <data android:scheme="wivrn" />
<data android:scheme="wivrn+tcp" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
+6
View File
@@ -959,6 +959,12 @@ application::application(application_info info) :
server_address = data_string.substr(strlen("wivrn://")); 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<jni::object<"java/io/File">>("getFilesDir"); auto files_dir = ctx.call<jni::object<"java/io/File">>("getFilesDir");
if (auto files_dir_path = files_dir.call<jni::string>("getAbsolutePath")) if (auto files_dir_path = files_dir.call<jni::string>("getAbsolutePath"))
{ {
+6
View File
@@ -147,6 +147,7 @@ class application : public singleton<application>
std::shared_ptr<wifi_lock> wifi; std::shared_ptr<wifi_lock> wifi;
std::string server_address; std::string server_address;
bool server_tcp_only = false;
std::mutex scene_stack_lock; std::mutex scene_stack_lock;
std::vector<std::shared_ptr<scene>> scene_stack; std::vector<std::shared_ptr<scene>> scene_stack;
@@ -377,6 +378,11 @@ public:
return server_address; return server_address;
} }
const bool & get_server_tcp_only() const
{
return server_tcp_only;
}
static vk::raii::PhysicalDevice & get_physical_device() static vk::raii::PhysicalDevice & get_physical_device()
{ {
return instance().vk_physical_device; return instance().vk_physical_device;
+2
View File
@@ -103,6 +103,7 @@ configuration::configuration(const std::string & path)
.name = (std::string)i["pretty_name"], .name = (std::string)i["pretty_name"],
.hostname = (std::string)i["hostname"], .hostname = (std::string)i["hostname"],
.port = (int)i["port"].get_int64(), .port = (int)i["port"].get_int64(),
.tcp_only = i["tcp_only"].is_bool() && i["tcp_only"].get_bool(),
.txt = {{"cookie", (std::string)i["cookie"]}} .txt = {{"cookie", (std::string)i["cookie"]}}
}}; }};
@@ -143,6 +144,7 @@ void configuration::save()
ss << "\"pretty_name\":" << json_string(server_data.service.name) << ","; ss << "\"pretty_name\":" << json_string(server_data.service.name) << ",";
ss << "\"hostname\":" << json_string(server_data.service.hostname) << ","; ss << "\"hostname\":" << json_string(server_data.service.hostname) << ",";
ss << "\"port\":" << server_data.service.port << ","; ss << "\"port\":" << server_data.service.port << ",";
ss << "\"tcp_only\":" << std::boolalpha << server_data.service.tcp_only << ",";
ss << "\"cookie\":" << json_string(cookie); ss << "\"cookie\":" << json_string(cookie);
ss << "},"; ss << "},";
} }
+1
View File
@@ -71,6 +71,7 @@ void real_main()
.name = app.get_server_address(), .name = app.get_server_address(),
.hostname = server_address, .hostname = server_address,
.port = port, .port = port,
.tcp_only = app.get_server_tcp_only(),
}, },
}; };
} }
+2 -2
View File
@@ -224,8 +224,8 @@ std::unique_ptr<wivrn_session> connect_to_session(wivrn_discover::service servic
{ {
spdlog::debug("Trying address {}", address_string); spdlog::debug("Trying address {}", address_string);
return std::visit([port = service.port](auto & address) { return std::visit([port = service.port, tcp_only = service.tcp_only](auto & address) {
return std::make_unique<wivrn_session>(address, port); return std::make_unique<wivrn_session>(address, port, tcp_only);
}, },
address); address);
} }
+6 -6
View File
@@ -49,7 +49,7 @@ void init_stream(T & stream)
} // namespace } // namespace
template <typename T> template <typename T>
void wivrn_session::handshake(T address) void wivrn_session::handshake(T address, bool tcp_only)
{ {
// Wait for handshake on control socket, // Wait for handshake on control socket,
// then send ours on stream or control socket, // then send ours on stream or control socket,
@@ -75,7 +75,7 @@ void wivrn_session::handshake(T address)
try try
{ {
auto h = std::get<to_headset::handshake>(*packet); auto h = std::get<to_headset::handshake>(*packet);
if (h.stream_port > 0) if (h.stream_port > 0 && !tcp_only)
{ {
stream = decltype(stream)(); stream = decltype(stream)();
stream.connect(address, h.stream_port); 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) control(address, port), stream(-1), address(address)
{ {
char buffer[100]; char buffer[100];
spdlog::info("Connection to {}:{}", inet_ntop(AF_INET6, &address, buffer, sizeof(buffer)), port); 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) control(address, port), stream(-1), address(address)
{ {
char buffer[100]; char buffer[100];
spdlog::info("Connection to {}:{}", inet_ntop(AF_INET, &address, buffer, sizeof(buffer)), port); spdlog::info("Connection to {}:{}", inet_ntop(AF_INET, &address, buffer, sizeof(buffer)), port);
handshake(address); handshake(address, tcp_only);
} }
+3 -3
View File
@@ -31,13 +31,13 @@ class wivrn_session
typed_socket<UDP, to_headset::packets, from_headset::packets> stream; typed_socket<UDP, to_headset::packets, from_headset::packets> stream;
template <typename T> template <typename T>
void handshake(T address); void handshake(T address, bool tcp_only);
public: public:
std::variant<in_addr, in6_addr> address; std::variant<in_addr, in6_addr> address;
wivrn_session(in6_addr address, int port); wivrn_session(in6_addr address, int port, bool tcp_only);
wivrn_session(in_addr address, int port); wivrn_session(in_addr address, int port, bool tcp_only);
wivrn_session(const wivrn_session &) = delete; wivrn_session(const wivrn_session &) = delete;
wivrn_session & operator=(const wivrn_session &) = delete; wivrn_session & operator=(const wivrn_session &) = delete;
+1
View File
@@ -20,6 +20,7 @@ public:
std::string name; std::string name;
std::string hostname; std::string hostname;
int port; int port;
bool tcp_only = false;
std::vector<std::variant<in_addr, in6_addr>> addresses; std::vector<std::variant<in_addr, in6_addr>> addresses;
std::map<std::string, std::string> txt; std::map<std::string, std::string> txt;