Skip to content

Commit

Permalink
Fixed connection pipeline assuming broadcast works in tcp
Browse files Browse the repository at this point in the history
  • Loading branch information
Meister1593 committed Feb 3, 2024
1 parent d5f4503 commit 904a453
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
30 changes: 15 additions & 15 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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(());
}
}
};

Expand Down
7 changes: 0 additions & 7 deletions alvr/client_core/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
Expand Down

0 comments on commit 904a453

Please sign in to comment.