From 79a3ad17904641b9ff6593f9af0e3f41c67eed76 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Tue, 11 May 2021 14:30:53 +0200 Subject: [PATCH] Switching from pnet to if-addrs for Windows support --- Cargo.toml | 2 +- src/discovery.rs | 5 +++-- src/main.rs | 9 +++++---- src/session_manager/mod.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f8ebcc5..4a38c8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ uuid = {version = "0.8", features = ["v4"]} webbrowser = "0.5.5" libmdns = "0.6" #mDNS advertiser multicast_dns = "0.5" #mDNS browser -pnet_datalink = "0.27.2" +if-addrs = "0.6" base64 = "0.13.0" scrypt = "0.7.0" zeroize = "1.2.0" diff --git a/src/discovery.rs b/src/discovery.rs index 3625b6a..398401b 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -1,12 +1,13 @@ use std::{net::IpAddr, io}; +use tokio::runtime::Handle; use libmdns::{Responder, Service}; use multicast_dns::discovery::{DiscoveryManager, DiscoveryListeners, ResolveListeners}; use crate::{constants, print_error}; const SERVICE_TYPE: &str = "_aira._tcp"; -pub fn advertise_me() -> io::Result { - Ok(Responder::new()?.register( +pub async fn advertise_me() -> io::Result { + Ok(Responder::spawn(&Handle::current())?.register( SERVICE_TYPE.to_string(), "AIRA Node".to_string(), constants::PORT, diff --git a/src/main.rs b/src/main.rs index 2b187f5..52d07c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,12 +117,13 @@ async fn websocket_worker(mut ui_connection: UiConnection, global_vars: Arc for iface in ifaces { + if !iface.is_loopback() { + ips.push(iface.ip()); } } + Err(e) => print_error!(e) } ui_connection.set_local_ips(ips); discover_peers(session_manager.clone()); diff --git a/src/session_manager/mod.rs b/src/session_manager/mod.rs index 449bcb3..186c6cc 100644 --- a/src/session_manager/mod.rs +++ b/src/session_manager/mod.rs @@ -528,7 +528,7 @@ impl SessionManager { let server_v4 = TcpListener::bind(SocketAddr::new("0.0.0.0".parse().unwrap(), constants::PORT)).await?; let (sender, mut receiver) = mpsc::channel(1); *session_manager.listener_stop_signal.lock().unwrap() = Some(sender); - match discovery::advertise_me() { + match discovery::advertise_me().await { Ok(service) => *session_manager.mdns_service.lock().unwrap() = Some(service), Err(e) => { print_error!("{}: you won't be discoverable by other peers.", e);