better multicast

This commit is contained in:
Joe Ardent 2025-08-16 13:46:17 -07:00
parent bb6241ac97
commit 6feb6f8ab8
3 changed files with 8 additions and 9 deletions

View file

@ -26,7 +26,7 @@ impl App {
KeyCode::Char('l') => self.logs(),
KeyCode::Char('m') => self.main(),
KeyCode::Char('h') | KeyCode::Char('?') => self.help(),
KeyCode::Char('c') => self.service.refresh_peers().await,
KeyCode::Char('c') => self.service.clear_peers().await,
KeyCode::Esc => self.pop(),
_ => match mode {
CurrentScreen::Main | CurrentScreen::Help => {}

View file

@ -30,8 +30,6 @@ use transfer::Session;
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_micros(33333);
pub type Peers = Arc<Mutex<BTreeMap<String, (SocketAddr, Device)>>>;
@ -78,7 +76,7 @@ pub struct ReceiveRequest {
impl PartialEq for ReceiveRequest {
fn eq(&self, other: &Self) -> bool {
self.alias == other.alias
self.alias == other.alias && self.files == other.files
}
}
@ -113,10 +111,11 @@ impl JocalService {
config: Config,
) -> crate::error::Result<(Self, UnboundedReceiver<JocalEvent>)> {
let (tx, rx) = mpsc::unbounded_channel();
let socket = UdpSocket::bind(LISTENING_SOCKET_ADDR).await?;
let addr = SocketAddrV4::new(config.local_ip_addr, DEFAULT_PORT);
let socket = UdpSocket::bind(addr).await?;
socket.set_multicast_loop_v4(false)?;
socket.set_multicast_ttl_v4(1)?; // local subnet only
socket.join_multicast_v4(MULTICAST_IP, Ipv4Addr::from_bits(0))?;
socket.join_multicast_v4(MULTICAST_IP, config.local_ip_addr)?;
let client = reqwest::ClientBuilder::new()
// localsend certs are self-signed
@ -202,7 +201,7 @@ impl JocalService {
.graceful_shutdown(Some(Duration::from_secs(5)));
}
pub async fn refresh_peers(&self) {
pub async fn clear_peers(&self) {
let mut peers = self.peers.lock().await;
peers.clear();
}

View file

@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use crate::error::LocalSendError;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct FileMetadata {
pub id: String,
@ -21,7 +21,7 @@ pub struct FileMetadata {
pub metadata: Option<FileMetadataExt>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FileMetadataExt {
#[serde(skip_serializing_if = "Option::is_none")]
pub modified: Option<String>,