From 5e40f292940122f9f0a91b11b6b425331bae1604 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 15 Aug 2025 15:54:03 -0700 Subject: [PATCH] don't loop multicast back --- src/discovery.rs | 30 ------------------------------ src/lib.rs | 13 +++++++------ 2 files changed, 7 insertions(+), 36 deletions(-) diff --git a/src/discovery.rs b/src/discovery.rs index 9d6872c..f89bfc7 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -138,33 +138,3 @@ async fn announce_multicast( socket.send_to(msg.as_bytes(), addr).await?; Ok(()) } - -/* -async fn announce_unicast( - device: &Device, - ip: Option, - client: reqwest::Client, -) -> crate::error::Result<()> { - // for enumerating subnet peers when multicast fails (https://github.com/localsend/protocol?tab=readme-ov-file#32-http-legacy-mode) - let std::net::IpAddr::V4(ip) = local_ip_address::local_ip()? else { - unreachable!() - }; - - let mut _network_ip = ip; - let nifs = NetworkInterface::show()?; - for addr in nifs.into_iter().flat_map(|i| i.addr) { - if let Addr::V4(V4IfAddr { - ip: ifip, - netmask: Some(netmask), - .. - }) = addr - && ip == ifip - { - _network_ip = ip & netmask; - break; - } - } - - todo!() -} -*/ diff --git a/src/lib.rs b/src/lib.rs index 1d5559a..fe746aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ pub const DEFAULT_PORT: u16 = 53317; pub const MULTICAST_IP: Ipv4Addr = Ipv4Addr::new(224, 0, 0, 167); pub const LISTENING_SOCKET_ADDR: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::from_bits(0), DEFAULT_PORT); -pub const DEFAULT_INTERVAL: Duration = Duration::from_millis(200); +pub const DEFAULT_INTERVAL: Duration = Duration::from_micros(33333); pub type Peers = Arc>>; pub type Sessions = Arc>>; // Session ID to Session @@ -114,7 +114,7 @@ impl JocalService { ) -> crate::error::Result<(Self, UnboundedReceiver)> { let (tx, rx) = mpsc::unbounded_channel(); let socket = UdpSocket::bind(LISTENING_SOCKET_ADDR).await?; - socket.set_multicast_loop_v4(true)?; + socket.set_multicast_loop_v4(false)?; socket.set_multicast_ttl_v4(8)?; // 8 hops out from localnet socket.join_multicast_v4(MULTICAST_IP, Ipv4Addr::from_bits(0))?; @@ -162,15 +162,16 @@ impl JocalService { let mut tick = tokio::time::interval(DEFAULT_INTERVAL); loop { - let rstate = service.running_state.lock().await; - if *rstate == RunningState::Stopping { - break; - } tick.tick().await; service .transfer_event_tx .send(JocalEvent::Tick) .unwrap_or_else(|e| log::warn!("could not send tick event: {e:?}")); + + let rstate = service.running_state.lock().await; + if *rstate == RunningState::Stopping { + break; + } } JocalTasks::Tick });