Skip to content

Commit

Permalink
Don't use/compile zeroconf-rs on Android and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Feb 4, 2025
1 parent 645a90e commit 4047b86
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ jobs:

- name: Install system dependencies
if: matrix.name == 'linux'
# NOTE: libfuse-dev is required only to build and run the ouisync
# application. It is not required for building and using the ouisync
# library.
run: sudo apt-get install libfuse-dev
run: sudo apt-get install libfuse-dev libavahi-client-dev libavahi-core-dev

- name: Install cross
if: matrix.cargo-command == 'cross'
Expand Down Expand Up @@ -106,7 +103,7 @@ jobs:
# NOTE: fuse isn't used by the bindings themselves but it's required for the unit tests
# because they use the linux version of the ouisync_ffi library, not the android one and
# the linux version does currently unconditionally depend on fuse.
run: sudo apt-get install libfuse-dev
run: sudo apt-get install libfuse-dev libavahi-client-dev libavahi-core-dev

# - name: Install NDK
# uses: nttld/setup-ndk@v1
Expand Down Expand Up @@ -181,7 +178,7 @@ jobs:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Install system dependencies
run: sudo apt-get install libfuse-dev
run: sudo apt-get install libfuse-dev libavahi-client-dev libavahi-core-dev

- name: Get dart dependencies
working-directory: bindings/dart
Expand Down
6 changes: 4 additions & 2 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ turmoil = { workspace = true, optional = true }
xxhash-rust = { version = "0.8.12", default-features = false, features = ["xxh3"] }
urlencoding = "2.1.0"
vint64 = "1.0.1"
# Our for with support for peer removal and non-string error types.
zeroize = "1.6.0"

[target.'cfg(not(any(target_os = "android", target_os = "windows")))'.dependencies]
# Our fork with support for peer removal and non-string error types.
# https://github.com/windy1/zeroconf-rs/issues/67
# https://github.com/windy1/zeroconf-rs/pull/73
zeroconf = { git = "https://github.com/inetic/zeroconf-rs", rev = "11ce6b47a7b7ffa8a50a2c20521db3dcdf559c86" }
zeroize = "1.6.0"

[dev-dependencies]
assert_matches = { workspace = true }
Expand Down
33 changes: 30 additions & 3 deletions lib/src/network/local_discovery/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
mod mdns_common;
mod mdns_direct;
#[cfg(not(any(target_os = "android", target_os = "windows")))]
mod mdns_zeroconf;
mod poor_man;

use crate::network::{peer_addr::PeerPort, seen_peers::SeenPeer};
use state_monitor::StateMonitor;
use tokio::select;

#[cfg(not(any(target_os = "android", target_os = "windows")))]
mod platform_zeroconf {
pub use super::mdns_zeroconf::LocalDiscovery;
use super::*;

pub fn new(listener_port: PeerPort) -> Option<LocalDiscovery> {
Some(LocalDiscovery::new(listener_port))
}
}

#[cfg(any(target_os = "android", target_os = "windows"))]
mod platform_zeroconf {
use super::*;
pub struct LocalDiscovery {}

impl LocalDiscovery {
pub async fn recv(&mut self) -> Option<SeenPeer> {
unreachable!();
}
}

pub fn new(_listener_port: super::PeerPort) -> Option<LocalDiscovery> {
None
}
}

pub struct LocalDiscovery {
poor_man: Option<poor_man::LocalDiscovery>,
mdns_direct: Option<mdns_direct::LocalDiscovery>,
mdns_zeroconf: Option<mdns_zeroconf::LocalDiscovery>,
mdns_zeroconf: Option<platform_zeroconf::LocalDiscovery>,
}

impl LocalDiscovery {
Expand All @@ -28,7 +55,7 @@ impl LocalDiscovery {
let mdns_direct = mdns_direct::LocalDiscovery::new(listener_port).ok();

let mdns_zeroconf = if mdns_direct.is_none() {
Some(mdns_zeroconf::LocalDiscovery::new(listener_port))
platform_zeroconf::new(listener_port)
} else {
None
};
Expand Down Expand Up @@ -64,7 +91,7 @@ impl LocalDiscovery {
Self {
poor_man: None,
mdns_direct: None,
mdns_zeroconf: Some(mdns_zeroconf::LocalDiscovery::new(listener_port)),
mdns_zeroconf: platform_zeroconf::new(listener_port),
}
}

Expand Down

0 comments on commit 4047b86

Please sign in to comment.