Skip to content

Commit

Permalink
fix(server): 🐛 Use device_id field for hostname instead of mDNS hostn…
Browse files Browse the repository at this point in the history
…ame (alvr-org#2077)
  • Loading branch information
zarik5 committed Apr 24, 2024
1 parent 868b28d commit 73af025
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
30 changes: 20 additions & 10 deletions alvr/server/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,32 @@ impl WelcomeSocket {
match self.mdns_receiver.try_recv() {
Ok(event) => {
if let ServiceEvent::ServiceResolved(info) = event {
let hostname = info.get_hostname();
let hostname = info
.get_property_val_str(alvr_sockets::MDNS_DEVICE_ID_KEY)
.unwrap_or_else(|| info.get_hostname());
let address = *info.get_addresses().iter().next().to_any()?;

let protocol = info
let client_protocol = info
.get_property_val_str(alvr_sockets::MDNS_PROTOCOL_KEY)
.to_any()?;
let server_protocol = alvr_common::protocol_id();
let client_is_dev = client_protocol.contains("-dev");
let server_is_dev = server_protocol.contains("-dev");

if protocol != alvr_common::protocol_id() {
let msg = format!(
r#"Expected protocol ID "{}", found "{}""#,
alvr_common::protocol_id(),
protocol
);
warn!(
"Found incompatible client {hostname}! Upgrade or downgrade\n{msg}"
if client_protocol != server_protocol {
let reason = if client_is_dev && server_is_dev {
"Please use matching nightly versions."
} else if client_is_dev {
"Please use nightly server or stable client."
} else if server_is_dev {
"Please use stable server or nightly client."
} else {
"Please use matching stable versions."
};
let protocols = format!(
"Protocols: server={server_protocol}, client={client_protocol}"
);
warn!("Found incompatible client {hostname}! {reason}\n{protocols}");
}

clients.insert(hostname.into(), address);
Expand Down
1 change: 1 addition & 0 deletions alvr/sockets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(2);

pub const MDNS_SERVICE_TYPE: &str = "_alvr._tcp.local.";
pub const MDNS_PROTOCOL_KEY: &str = "protocol";
pub const MDNS_DEVICE_ID_KEY: &str = "device_id";

fn set_socket_buffers(
socket: &socket2::Socket,
Expand Down

0 comments on commit 73af025

Please sign in to comment.