From 8655d82e6ea415d3596b5da9ed588a1e5cb6a316 Mon Sep 17 00:00:00 2001 From: plyshka Date: Mon, 15 Jan 2024 20:20:13 +0500 Subject: [PATCH 1/3] =?UTF-8?q?fix(connection):=20=F0=9F=90=9B=20Try=20loc?= =?UTF-8?q?alhost=20if=20broadcast=20fails,=20fixes=20wifi=20being=20requi?= =?UTF-8?q?red=20for=20cabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alvr/client_core/src/connection.rs | 22 ++++++++++++++++------ alvr/client_core/src/sockets.rs | 5 ++--- wiki/Use-ALVR-through-a-USB-connection.md | 1 - 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/alvr/client_core/src/connection.rs b/alvr/client_core/src/connection.rs index c003a0b35f..3fcd885ec4 100644 --- a/alvr/client_core/src/connection.rs +++ b/alvr/client_core/src/connection.rs @@ -30,6 +30,7 @@ use alvr_sockets::{ KEEPALIVE_INTERVAL, KEEPALIVE_TIMEOUT, }; use serde_json as json; +use std::net::Ipv4Addr; use std::{ collections::HashMap, sync::{mpsc, Arc}, @@ -47,7 +48,9 @@ const INITIAL_MESSAGE: &str = concat!( "Open ALVR on your PC then click \"Trust\"\n", "next to the client entry", ); -const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the internet"; +const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the streamer.\nNetwork error."; +const SUCCESS_CONNECT_MESSAGE: &str = "Successful connection!\nPlease wait..."; +const LOCAL_TRY_MESSAGE: &str = "Trying to connect to local..."; // const INCOMPATIBLE_VERSIONS_MESSAGE: &str = concat!( // "Streamer and client have\n", // "incompatible types.\n", @@ -135,22 +138,29 @@ fn connection_pipeline( return Ok(()); } - if let Err(e) = announcer_socket.broadcast() { - warn!("Broadcast error: {e:?}"); + if let Err(e) = announcer_socket.announce_to(Ipv4Addr::BROADCAST) { + warn!("Global broadcast error. Is network available? {e:?}"); - set_hud_message(NETWORK_UNREACHABLE_MESSAGE); + set_hud_message(LOCAL_TRY_MESSAGE); thread::sleep(RETRY_CONNECT_MIN_INTERVAL); - set_hud_message(INITIAL_MESSAGE); + if let Err(e) = announcer_socket.announce_to(Ipv4Addr::LOCALHOST) { + warn!("Couldn't announce to neither network or localhost. {e:?}"); + set_hud_message(NETWORK_UNREACHABLE_MESSAGE); - return Ok(()); + thread::sleep(RETRY_CONNECT_MIN_INTERVAL); + + set_hud_message(INITIAL_MESSAGE); + return Ok(()); + } } if let Ok(pair) = ProtoControlSocket::connect_to( DISCOVERY_RETRY_PAUSE, PeerType::Server(&listener_socket), ) { + set_hud_message(SUCCESS_CONNECT_MESSAGE); break pair; } } diff --git a/alvr/client_core/src/sockets.rs b/alvr/client_core/src/sockets.rs index 1a0607596a..eb4967b16b 100644 --- a/alvr/client_core/src/sockets.rs +++ b/alvr/client_core/src/sockets.rs @@ -20,9 +20,8 @@ impl AnnouncerSocket { Ok(Self { socket, packet }) } - pub fn broadcast(&self) -> Result<()> { - self.socket - .send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?; + pub fn announce_to(&self, addr: Ipv4Addr) -> Result<()> { + self.socket.send_to(&self.packet, (addr, CONTROL_PORT))?; Ok(()) } diff --git a/wiki/Use-ALVR-through-a-USB-connection.md b/wiki/Use-ALVR-through-a-USB-connection.md index fc0fa5c248..8daff05ac4 100644 --- a/wiki/Use-ALVR-through-a-USB-connection.md +++ b/wiki/Use-ALVR-through-a-USB-connection.md @@ -10,7 +10,6 @@ * If your headset is detected, click "Trust." Click "Edit", "Add new" and change the IP address to `127.0.0.1`. * If your headset is not detected, click "Add client manually" and use the IP address `127.0.0.1`. Use the hostname displayed on your headset screen. -* Turn off client discovery in Settings > Connection. * Switch the connection streaming protocol to TCP in Settings > Connection. ## Letting your PC communicate with your HMD From d5f4503984920ddf3d1712e7100359754fe0a25f Mon Sep 17 00:00:00 2001 From: plyshka Date: Mon, 15 Jan 2024 20:41:09 +0500 Subject: [PATCH 2/3] =?UTF-8?q?fix(connection):=20=F0=9F=90=9B=20use=20sep?= =?UTF-8?q?arate=20functions=20for=20local=20and=20broadcast=20socket=20se?= =?UTF-8?q?nds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alvr/client_core/src/connection.rs | 4 ++-- alvr/client_core/src/sockets.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/alvr/client_core/src/connection.rs b/alvr/client_core/src/connection.rs index 3fcd885ec4..74654ecc47 100644 --- a/alvr/client_core/src/connection.rs +++ b/alvr/client_core/src/connection.rs @@ -138,14 +138,14 @@ fn connection_pipeline( return Ok(()); } - if let Err(e) = announcer_socket.announce_to(Ipv4Addr::BROADCAST) { + if let Err(e) = announcer_socket.announce_broadcast() { warn!("Global broadcast error. Is network available? {e:?}"); set_hud_message(LOCAL_TRY_MESSAGE); thread::sleep(RETRY_CONNECT_MIN_INTERVAL); - if let Err(e) = announcer_socket.announce_to(Ipv4Addr::LOCALHOST) { + if let Err(e) = announcer_socket.announce_local() { warn!("Couldn't announce to neither network or localhost. {e:?}"); set_hud_message(NETWORK_UNREACHABLE_MESSAGE); diff --git a/alvr/client_core/src/sockets.rs b/alvr/client_core/src/sockets.rs index eb4967b16b..8b984017aa 100644 --- a/alvr/client_core/src/sockets.rs +++ b/alvr/client_core/src/sockets.rs @@ -20,8 +20,16 @@ impl AnnouncerSocket { Ok(Self { socket, packet }) } - pub fn announce_to(&self, addr: Ipv4Addr) -> Result<()> { - self.socket.send_to(&self.packet, (addr, CONTROL_PORT))?; + pub fn announce_local(&self) -> Result<()> { + self.socket + .send_to(&self.packet, (Ipv4Addr::LOCALHOST, CONTROL_PORT))?; + + Ok(()) + } + + pub fn announce_broadcast(&self) -> Result<()> { + self.socket + .send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?; Ok(()) } From 904a453341d551e2cc1f403fa6d584faef505388 Mon Sep 17 00:00:00 2001 From: plyshka Date: Sat, 3 Feb 2024 15:58:46 +0500 Subject: [PATCH 3/3] Fixed connection pipeline assuming broadcast works in tcp --- alvr/client_core/src/connection.rs | 30 +++++++++++++++--------------- alvr/client_core/src/sockets.rs | 7 ------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/alvr/client_core/src/connection.rs b/alvr/client_core/src/connection.rs index 74654ecc47..cb7ad87ba4 100644 --- a/alvr/client_core/src/connection.rs +++ b/alvr/client_core/src/connection.rs @@ -30,7 +30,6 @@ use alvr_sockets::{ KEEPALIVE_INTERVAL, KEEPALIVE_TIMEOUT, }; use serde_json as json; -use std::net::Ipv4Addr; use std::{ collections::HashMap, sync::{mpsc, Arc}, @@ -50,7 +49,7 @@ const INITIAL_MESSAGE: &str = concat!( ); const NETWORK_UNREACHABLE_MESSAGE: &str = "Cannot connect to the streamer.\nNetwork error."; const SUCCESS_CONNECT_MESSAGE: &str = "Successful connection!\nPlease wait..."; -const LOCAL_TRY_MESSAGE: &str = "Trying to connect to local..."; +const LOCAL_TRY_MESSAGE: &str = "Trying to connect to localhost..."; // const INCOMPATIBLE_VERSIONS_MESSAGE: &str = concat!( // "Streamer and client have\n", // "incompatible types.\n", @@ -138,22 +137,13 @@ fn connection_pipeline( return Ok(()); } + let mut is_broadcast_ok = false; if let Err(e) = announcer_socket.announce_broadcast() { - warn!("Global broadcast error. Is network available? {e:?}"); + debug!("Couldn't announce to localhost, retrying on local... {e:}"); set_hud_message(LOCAL_TRY_MESSAGE); - - thread::sleep(RETRY_CONNECT_MIN_INTERVAL); - - if let Err(e) = announcer_socket.announce_local() { - warn!("Couldn't announce to neither network or localhost. {e:?}"); - set_hud_message(NETWORK_UNREACHABLE_MESSAGE); - - thread::sleep(RETRY_CONNECT_MIN_INTERVAL); - - set_hud_message(INITIAL_MESSAGE); - return Ok(()); - } + } else { + is_broadcast_ok = true; } if let Ok(pair) = ProtoControlSocket::connect_to( @@ -163,6 +153,16 @@ fn connection_pipeline( set_hud_message(SUCCESS_CONNECT_MESSAGE); break pair; } + + if !is_broadcast_ok { + warn!("Couldn't announce to network or connect to localhost."); + set_hud_message(NETWORK_UNREACHABLE_MESSAGE); + + thread::sleep(RETRY_CONNECT_MIN_INTERVAL); + + set_hud_message(INITIAL_MESSAGE); + return Ok(()); + } } }; diff --git a/alvr/client_core/src/sockets.rs b/alvr/client_core/src/sockets.rs index 8b984017aa..e3a46228bd 100644 --- a/alvr/client_core/src/sockets.rs +++ b/alvr/client_core/src/sockets.rs @@ -20,13 +20,6 @@ impl AnnouncerSocket { Ok(Self { socket, packet }) } - pub fn announce_local(&self) -> Result<()> { - self.socket - .send_to(&self.packet, (Ipv4Addr::LOCALHOST, CONTROL_PORT))?; - - Ok(()) - } - pub fn announce_broadcast(&self) -> Result<()> { self.socket .send_to(&self.packet, (Ipv4Addr::BROADCAST, CONTROL_PORT))?;