pub struct MeshRouter<R: SignalingTransport, F: PeerLinkFactory> { /* private fields */ }Expand description
Mesh router handles peer discovery and negotiated link establishment.
This is the shared routing logic between production transports and simulation. It uses traits for signaling transport and negotiated link factories so the same router can drive Nostr websockets, LAN buses, BLE, WebRTC, or mocks.
Uses the standard concurrent-offer “perfect negotiation” pattern:
- Both peers can send offers when they discover each other
- On collision (both sent offers), “polite” peer backs off and accepts incoming
- This ensures connections form even when one peer is satisfied but can accept
Implementations§
Source§impl<R: SignalingTransport + 'static, F: PeerLinkFactory + 'static> MeshRouter<R, F>
impl<R: SignalingTransport + 'static, F: PeerLinkFactory + 'static> MeshRouter<R, F>
Sourcepub fn new(
peer_id: String,
transport: Arc<R>,
conn_factory: Arc<F>,
pools: PoolSettings,
debug: bool,
) -> Self
pub fn new( peer_id: String, transport: Arc<R>, conn_factory: Arc<F>, pools: PoolSettings, debug: bool, ) -> Self
Create a new mesh router.
Sourcepub fn set_classifier(&mut self, tx: Sender<ClassifyRequest>)
pub fn set_classifier(&mut self, tx: Sender<ClassifyRequest>)
Set classifier for peer pool assignment
Sourcepub async fn send_hello(&self, roots: Vec<String>) -> Result<(), TransportError>
pub async fn send_hello(&self, roots: Vec<String>) -> Result<(), TransportError>
Send hello broadcast
Sourcepub async fn handle_message(
&self,
msg: SignalingMessage,
) -> Result<(), TransportError>
pub async fn handle_message( &self, msg: SignalingMessage, ) -> Result<(), TransportError>
Handle incoming signaling message
This is the core signaling logic shared between production and simulation.
Sourcepub async fn peer_count(&self) -> usize
pub async fn peer_count(&self) -> usize
Get connected peer count
Sourcepub async fn get_channel(&self, peer_id: &str) -> Option<Arc<dyn PeerLink>>
pub async fn get_channel(&self, peer_id: &str) -> Option<Arc<dyn PeerLink>>
Get a peer’s channel
Sourcepub async fn remove_peer(&self, peer_id: &str) -> Option<Arc<dyn PeerLink>>
pub async fn remove_peer(&self, peer_id: &str) -> Option<Arc<dyn PeerLink>>
Remove a peer and any pending offer state.
Sourcepub async fn needs_peers(&self) -> bool
pub async fn needs_peers(&self) -> bool
Check if we need more peers (below satisfied in any pool)
Sourcepub async fn can_accept(&self) -> bool
pub async fn can_accept(&self) -> bool
Check if we can accept more peers (below max in any pool)
Auto Trait Implementations§
impl<R, F> !Freeze for MeshRouter<R, F>
impl<R, F> !RefUnwindSafe for MeshRouter<R, F>
impl<R, F> Send for MeshRouter<R, F>
impl<R, F> Sync for MeshRouter<R, F>
impl<R, F> Unpin for MeshRouter<R, F>
impl<R, F> UnsafeUnpin for MeshRouter<R, F>
impl<R, F> !UnwindSafe for MeshRouter<R, F>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more