Two root causes kept the wasm web client from syncing with native peers,
both fixed here:
1. Gossip island — a node that registered with the rendezvous first joined
its gossip topic alone and never pulled later-joining peers into its
active view (its single subscribe_and_join was done, so a browser that
appeared afterwards had a live magicsock path but no gossip neighbor).
The re-register loop now seeds peer relay addrs into the MemoryLookup and
calls GossipSender::join_peers each round, so neighbors form both ways.
2. Engine::send panicked on wasm — directly_covered() calls Instant::now(),
which traps ("time not implemented") on wasm32-unknown-unknown, so send
threw before ever reaching the gossip broadcast (0 Broadcast commands).
web-time backs Instant with Performance.now() on wasm; native keeps
std::time and is unaffected (web-time isn't linked there).
Supporting connectivity: the rendezvous now stores + returns each peer's
iroh relay URL (PeerInfo{id,relay}) so a browser — relay-only, can't resolve
id→addr via discovery — can dial natives via a seeded MemoryLookup; CORS
added so the browser's fetch to the rendezvous is allowed.
Verified live, cross-relay: text typed in a browser tab lands on the Mac
clipboard and vice-versa, with the wasm engine running as a relay-only iroh
peer. Browser-console tracing capped at INFO; demo send wrapped in try/catch.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
90 lines
3.7 KiB
TOML
90 lines
3.7 KiB
TOML
[package]
|
|
name = "tethercore"
|
|
version = "0.1.0"
|
|
edition = "2021"
|
|
description = "Shared tether sync engine: codec + SSE client + reconnect, FFI-exported via UniFFI."
|
|
|
|
[lib]
|
|
# lib → examples/tests can link it natively
|
|
# staticlib → iOS .a / desktop agent
|
|
# cdylib → Android .so / bindgen library mode
|
|
crate-type = ["lib", "staticlib", "cdylib"]
|
|
name = "tethercore"
|
|
|
|
[[bin]]
|
|
name = "uniffi-bindgen"
|
|
path = "src/bin/uniffi-bindgen.rs"
|
|
|
|
# Common, wasm-safe dependencies (no OS sockets / threads).
|
|
[dependencies]
|
|
serde = { version = "1", features = ["derive"] }
|
|
serde_json = "1"
|
|
futures-util = "0.3"
|
|
sha2 = "0.11.0"
|
|
bytes = "1.12.0"
|
|
chacha20poly1305 = "0.10.1"
|
|
base64 = "0.22.1"
|
|
|
|
# n0-future: iroh's cross-platform async (works native + wasm) — used for the
|
|
# IrohTransport's timers so it doesn't depend on tokio's time on wasm.
|
|
n0-future = { version = "0.3", optional = true }
|
|
|
|
[features]
|
|
default = []
|
|
iroh-transport = ["dep:iroh", "dep:iroh-gossip", "dep:iroh-blobs", "dep:n0-future"]
|
|
|
|
# ── Native (desktop/mobile): legacy transports + UniFFI + full tokio ──
|
|
# The hand-rolled SSE/RTC/LAN stack and its OS-socket deps live here; none of it
|
|
# compiles to wasm. iroh (behind the feature) takes full default features.
|
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
|
uniffi = { version = "0.28", features = ["cli"] }
|
|
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "stream", "json"] }
|
|
tokio = { version = "1", features = ["rt-multi-thread", "time", "sync", "macros", "net", "io-util"] }
|
|
webrtc = "0.17.1"
|
|
mdns-sd = "0.20.0"
|
|
getrandom = "0.4.3"
|
|
iroh = { version = "1", optional = true }
|
|
iroh-gossip = { version = "0.101", optional = true }
|
|
iroh-blobs = { version = "0.103", optional = true }
|
|
|
|
# ── wasm32 (browser): iroh-only, no OS sockets / UniFFI ──
|
|
# Browser iroh is relay-only; reqwest uses fetch; the runtime is the JS event
|
|
# loop (wasm-bindgen-futures) instead of a tokio runtime.
|
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
|
tokio = { version = "1", features = ["sync", "macros"] }
|
|
reqwest = { version = "0.12", default-features = false, features = ["json"] }
|
|
# wasm rng: getrandom 0.4 uses a build-cfg (--cfg getrandom_backend="wasm_js"),
|
|
# but a transitive getrandom 0.2 needs the `js` *feature* — enable it via the
|
|
# rename-alias trick (cargo unifies it with the transitive copy).
|
|
getrandom = "0.4.3"
|
|
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
|
|
wasm-bindgen-futures = "0.4"
|
|
wasm-bindgen = "0.2"
|
|
js-sys = "0.3"
|
|
# Drop-in Instant for the browser: std::time::Instant::now() panics ("time not
|
|
# implemented") on wasm32-unknown-unknown. web_time backs it with Performance.now()
|
|
# (and re-exports std on native, so native is unaffected — it isn't even linked there).
|
|
web-time = "1"
|
|
# Browser diagnostics: surface Rust panics + iroh's tracing logs in the console.
|
|
console_error_panic_hook = "0.1"
|
|
tracing-wasm = "0.2"
|
|
tracing = "0.1"
|
|
# Browser iroh: default-features off (drops native portmapper/apple-datapath),
|
|
# but keep tls-ring — ring works on wasm and presets::N0 needs it. (Matches n0's
|
|
# own browser-chat example.)
|
|
iroh = { version = "1", optional = true, default-features = false, features = ["tls-ring"] }
|
|
iroh-gossip = { version = "0.101", optional = true, default-features = false, features = ["net"] }
|
|
iroh-blobs = { version = "0.103", optional = true, default-features = false }
|
|
|
|
[dev-dependencies]
|
|
# Iroh spikes (examples/iroh_*.rs) link iroh directly regardless of the feature.
|
|
iroh = "1"
|
|
iroh-gossip = "0.101"
|
|
anyhow = "1"
|
|
|
|
# The M4 integration example drives the real Engine over IrohTransport, so it
|
|
# needs the feature (and Engine::iroh_id, which only exists under it).
|
|
[[example]]
|
|
name = "iroh_engine"
|
|
required-features = ["iroh-transport"]
|