From e7450df991be24c75bdc57649b4643b033c6caf2 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 9 Apr 2026 12:16:31 +0200 Subject: [PATCH] Reload interfaces if we don't have multicast or link --- client/scenes/lobby.cpp | 3 --- client/scenes/lobby.h | 2 -- client/wivrn_discover.cpp | 24 ++++++++++++++++++++---- client/wivrn_discover.h | 3 +++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 44430e7f..4d2ad1e9 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -1320,7 +1320,6 @@ void scenes::lobby::on_focused() std::ranges::sort(local_environments, std::less{}); setup_passthrough(); - multicast = application::get_wifi_lock().get_multicast_lock(); discover.emplace(); session.set_performance_level(XR_PERF_SETTINGS_DOMAIN_CPU_EXT, XR_PERF_SETTINGS_LEVEL_SUSTAINED_HIGH_EXT); @@ -1352,8 +1351,6 @@ void scenes::lobby::on_unfocused() left_hand.reset(); right_hand.reset(); face_tracker.emplace(); - - multicast.reset(); } void scenes::lobby::on_xr_event(const xr::event & event) diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index a8bd1a30..3b8aa535 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -27,7 +27,6 @@ #include "scenes/lobby_keyboard.h" #include "utils/mapped_file.h" #include "utils/thread_safe.h" -#include "wifi_lock.h" #include "wivrn_config.h" #include "wivrn_discover.h" #include "xr/face_tracker.h" @@ -51,7 +50,6 @@ class stream; class lobby : public scene_impl { std::optional discover; - wifi_lock::multicast multicast; std::string add_server_window_prettyname; std::string add_server_window_hostname; diff --git a/client/wivrn_discover.cpp b/client/wivrn_discover.cpp index e6dedf0d..dd2bb8ae 100644 --- a/client/wivrn_discover.cpp +++ b/client/wivrn_discover.cpp @@ -1,4 +1,6 @@ #include "wivrn_discover.h" + +#include "application.h" #include "mdns.h" #include "utils/named_thread.h" #include @@ -117,6 +119,7 @@ private: for (ifaddrs * i = addresses; i; i = i->ifa_next) { + spdlog::debug("address {} flags 0x{:x} required 0x{:x} forbidden 0x{:x}", uintptr_t(i->ifa_addr), i->ifa_flags, required_flags, forbidden_flags); if (i->ifa_addr == nullptr) continue; @@ -135,7 +138,7 @@ private: // Ignore link-local addresses if (saddr->sin6_scope_id) { - spdlog::trace("Ignoring link-local address {}", ip_address_to_string(i->ifa_addr)); + spdlog::debug("Ignoring link-local address {}", ip_address_to_string(i->ifa_addr)); continue; } static const unsigned char localhost[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; @@ -154,9 +157,11 @@ private: } else { - spdlog::info("Cannot open socket bound to {}: {}", ip_address_to_string(i->ifa_addr), strerror(errno)); + spdlog::warn("Cannot open socket bound to {}: {}", ip_address_to_string(i->ifa_addr), strerror(errno)); } } + else + spdlog::debug("ignore localhost (IPv6)"); } else if (i->ifa_addr->sa_family == AF_INET) { @@ -177,9 +182,15 @@ private: } else { - spdlog::info("Cannot open socket bound to {}: {}", ip_address_to_string(i->ifa_addr), strerror(errno)); + spdlog::warn("Cannot open socket bound to {}: {}", ip_address_to_string(i->ifa_addr), strerror(errno)); } } + else + spdlog::debug("ignore localhost (IPv4)"); + } + else + { + spdlog::warn("unknown family {}", i->ifa_addr->sa_family); } } @@ -391,6 +402,9 @@ public: } } + if (pollfds.size() < 2) + open_client_sockets(5353); + log_query(record, service_name); std::array buffer; for (size_t i = 1; i < pollfds.size(); i++) @@ -567,7 +581,9 @@ void wivrn_discover::discover(std::string service_name) } wivrn_discover::wivrn_discover(std::string service_name) : - cache(std::make_unique()), dnssd_thread(utils::named_thread("dnssd_thread", &wivrn_discover::discover, this, service_name)) + multicast{application::get_wifi_lock().get_multicast_lock()}, + cache(std::make_unique()), + dnssd_thread(utils::named_thread("dnssd_thread", &wivrn_discover::discover, this, service_name)) { } diff --git a/client/wivrn_discover.h b/client/wivrn_discover.h index 97ec77f3..4d17d275 100644 --- a/client/wivrn_discover.h +++ b/client/wivrn_discover.h @@ -1,5 +1,7 @@ #pragma once +#include "wifi_lock.h" + #include #include #include @@ -32,6 +34,7 @@ public: static inline const std::chrono::milliseconds discover_period{5000}; private: + wifi_lock::multicast multicast; std::unique_ptr cache; std::thread dnssd_thread;