pub struct Swarm<B: Backhaul, C> { /* private fields */ }Expand description
Represents a node in an independent P2P swarm that implements a particular RPC protocol.
This is generic over a backhaul, so different transports can be plugged in easily, as well as a client-level handle (e.g. the FoobarClient that nanorpc’s macros generate from a FoobarProtocol trait). We are intentionally generic over the second one to statically prevent confusion between swarms that run incompatible RPC protocols; the combination of backhaul and client uniquely identifies a network compatible with a particular protocol.
Implementations
sourceimpl<B: Backhaul, C: 'static> Swarm<B, C>where
<B::RpcTransport as RpcTransport>::Error: Error + Send + Sync,
impl<B: Backhaul, C: 'static> Swarm<B, C>where
<B::RpcTransport as RpcTransport>::Error: Error + Send + Sync,
sourcepub fn new(
backhaul: B,
client_map_fn: impl Fn(B::RpcTransport) -> C + Sync + Send + 'static,
swarm_id: &str
) -> Self
pub fn new(
backhaul: B,
client_map_fn: impl Fn(B::RpcTransport) -> C + Sync + Send + 'static,
swarm_id: &str
) -> Self
Creates a new Swarm given a backhaul, and a function that maps a raw transport to a client-level handle.
sourcepub async fn connect(&self, addr: Address) -> Result<C, B::ConnectError>
pub async fn connect(&self, addr: Address) -> Result<C, B::ConnectError>
Obtains a connection to a peer.
sourcepub async fn start_listen(
&self,
listen_addr: Address,
advertise_addr: Option<Address>,
service: impl RpcService
) -> Result<(), B::ListenError>
pub async fn start_listen(
&self,
listen_addr: Address,
advertise_addr: Option<Address>,
service: impl RpcService
) -> Result<(), B::ListenError>
Starts a listener on the given address. If advertise_addr is present, then advertise this address to peers asking for routes.