Reload interfaces if we don't have multicast or link

This commit is contained in:
Patrick Nicolas
2026-04-09 12:16:31 +02:00
parent 6c6519fab5
commit e7450df991
4 changed files with 23 additions and 9 deletions
-3
View File
@@ -1320,7 +1320,6 @@ void scenes::lobby::on_focused()
std::ranges::sort(local_environments, std::less{}); std::ranges::sort(local_environments, std::less{});
setup_passthrough(); setup_passthrough();
multicast = application::get_wifi_lock().get_multicast_lock();
discover.emplace(); discover.emplace();
session.set_performance_level(XR_PERF_SETTINGS_DOMAIN_CPU_EXT, XR_PERF_SETTINGS_LEVEL_SUSTAINED_HIGH_EXT); 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(); left_hand.reset();
right_hand.reset(); right_hand.reset();
face_tracker.emplace<std::monostate>(); face_tracker.emplace<std::monostate>();
multicast.reset();
} }
void scenes::lobby::on_xr_event(const xr::event & event) void scenes::lobby::on_xr_event(const xr::event & event)
-2
View File
@@ -27,7 +27,6 @@
#include "scenes/lobby_keyboard.h" #include "scenes/lobby_keyboard.h"
#include "utils/mapped_file.h" #include "utils/mapped_file.h"
#include "utils/thread_safe.h" #include "utils/thread_safe.h"
#include "wifi_lock.h"
#include "wivrn_config.h" #include "wivrn_config.h"
#include "wivrn_discover.h" #include "wivrn_discover.h"
#include "xr/face_tracker.h" #include "xr/face_tracker.h"
@@ -51,7 +50,6 @@ class stream;
class lobby : public scene_impl<lobby> class lobby : public scene_impl<lobby>
{ {
std::optional<wivrn_discover> discover; std::optional<wivrn_discover> discover;
wifi_lock::multicast multicast;
std::string add_server_window_prettyname; std::string add_server_window_prettyname;
std::string add_server_window_hostname; std::string add_server_window_hostname;
+20 -4
View File
@@ -1,4 +1,6 @@
#include "wivrn_discover.h" #include "wivrn_discover.h"
#include "application.h"
#include "mdns.h" #include "mdns.h"
#include "utils/named_thread.h" #include "utils/named_thread.h"
#include <arpa/inet.h> #include <arpa/inet.h>
@@ -117,6 +119,7 @@ private:
for (ifaddrs * i = addresses; i; i = i->ifa_next) 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) if (i->ifa_addr == nullptr)
continue; continue;
@@ -135,7 +138,7 @@ private:
// Ignore link-local addresses // Ignore link-local addresses
if (saddr->sin6_scope_id) 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; continue;
} }
static const unsigned char localhost[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; 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 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) else if (i->ifa_addr->sa_family == AF_INET)
{ {
@@ -177,9 +182,15 @@ private:
} }
else 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); log_query(record, service_name);
std::array<uint8_t, 2048> buffer; std::array<uint8_t, 2048> buffer;
for (size_t i = 1; i < pollfds.size(); i++) 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) : wivrn_discover::wivrn_discover(std::string service_name) :
cache(std::make_unique<dnssd_cache>()), 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_cache>()),
dnssd_thread(utils::named_thread("dnssd_thread", &wivrn_discover::discover, this, service_name))
{ {
} }
+3
View File
@@ -1,5 +1,7 @@
#pragma once #pragma once
#include "wifi_lock.h"
#include <chrono> #include <chrono>
#include <map> #include <map>
#include <memory> #include <memory>
@@ -32,6 +34,7 @@ public:
static inline const std::chrono::milliseconds discover_period{5000}; static inline const std::chrono::milliseconds discover_period{5000};
private: private:
wifi_lock::multicast multicast;
std::unique_ptr<dnssd_cache> cache; std::unique_ptr<dnssd_cache> cache;
std::thread dnssd_thread; std::thread dnssd_thread;