pub struct Node { /* private fields */ }
Expand description
Implementation of a network node on Subspace Network.
Implementations§
source§impl Node
impl Node
sourcepub async fn get_value(
&self,
key: Multihash,
) -> Result<impl Stream<Item = PeerRecord>, GetValueError>
pub async fn get_value( &self, key: Multihash, ) -> Result<impl Stream<Item = PeerRecord>, GetValueError>
Return a value from the Kademlia network of the DSN.
sourcepub async fn put_value(
&self,
key: Multihash,
value: Vec<u8>,
) -> Result<impl Stream<Item = ()>, PutValueError>
pub async fn put_value( &self, key: Multihash, value: Vec<u8>, ) -> Result<impl Stream<Item = ()>, PutValueError>
Puts a value into the Kademlia network of the DSN.
sourcepub async fn subscribe(
&self,
topic: Sha256Topic,
) -> Result<TopicSubscription, SubscribeError>
pub async fn subscribe( &self, topic: Sha256Topic, ) -> Result<TopicSubscription, SubscribeError>
Subcribe to some topic on the DSN.
sourcepub async fn publish(
&self,
topic: Sha256Topic,
message: Vec<u8>,
) -> Result<(), PublishError>
pub async fn publish( &self, topic: Sha256Topic, message: Vec<u8>, ) -> Result<(), PublishError>
Subcribe a messgo to some topic on the DSN.
sourcepub async fn send_generic_request<Request>(
&self,
peer_id: PeerId,
addresses: Vec<Multiaddr>,
request: Request,
) -> Result<Request::Response, SendRequestError>where
Request: GenericRequest,
pub async fn send_generic_request<Request>(
&self,
peer_id: PeerId,
addresses: Vec<Multiaddr>,
request: Request,
) -> Result<Request::Response, SendRequestError>where
Request: GenericRequest,
Sends the generic request to the peer and awaits the result.
Optional addresses will be used for dialing if connection to peer isn’t established yet.
sourcepub async fn get_closest_peers(
&self,
key: Multihash,
) -> Result<impl Stream<Item = PeerId>, GetClosestPeersError>
pub async fn get_closest_peers( &self, key: Multihash, ) -> Result<impl Stream<Item = PeerId>, GetClosestPeersError>
Get closest peers by multihash key using Kademlia DHT.
sourcepub async fn get_closest_local_peers(
&self,
key: Multihash,
source: Option<PeerId>,
) -> Result<Vec<(PeerId, Vec<Multiaddr>)>, GetClosestLocalPeersError>
pub async fn get_closest_local_peers( &self, key: Multihash, source: Option<PeerId>, ) -> Result<Vec<(PeerId, Vec<Multiaddr>)>, GetClosestLocalPeersError>
Get closest peers by multihash key using Kademlia DHT’s local view without any network requests.
Optional source
is peer for which results will be sent as a response. Defaults to local
peer ID.
sourcepub async fn get_providers(
&self,
key: RecordKey,
) -> Result<impl Stream<Item = PeerId>, GetProvidersError>
pub async fn get_providers( &self, key: RecordKey, ) -> Result<impl Stream<Item = PeerId>, GetProvidersError>
Get item providers by its key. Initiate ‘providers’ Kademlia operation.
sourcepub async fn ban_peer(&self, peer_id: PeerId) -> Result<(), SendError>
pub async fn ban_peer(&self, peer_id: PeerId) -> Result<(), SendError>
Ban peer with specified peer ID.
sourcepub fn listeners(&self) -> Vec<Multiaddr>
pub fn listeners(&self) -> Vec<Multiaddr>
Node’s own addresses where it listens for incoming requests.
sourcepub fn external_addresses(&self) -> Vec<Multiaddr>
pub fn external_addresses(&self) -> Vec<Multiaddr>
Node’s own addresses observed remotely.
sourcepub fn on_new_listener(
&self,
callback: Arc<dyn Fn(&Multiaddr) + Send + Sync + 'static>,
) -> HandlerId
pub fn on_new_listener( &self, callback: Arc<dyn Fn(&Multiaddr) + Send + Sync + 'static>, ) -> HandlerId
Callback is called when node starts listening on new address.
sourcepub fn on_num_established_peer_connections_change(
&self,
callback: Arc<dyn Fn(&usize) + Send + Sync + 'static>,
) -> HandlerId
pub fn on_num_established_peer_connections_change( &self, callback: Arc<dyn Fn(&usize) + Send + Sync + 'static>, ) -> HandlerId
Callback is called when number of established peer connections changes.
sourcepub async fn connected_peers(&self) -> Result<Vec<PeerId>, ConnectedPeersError>
pub async fn connected_peers(&self) -> Result<Vec<PeerId>, ConnectedPeersError>
Returns a collection of currently connected peers.
sourcepub fn on_connected_peer(
&self,
callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>,
) -> HandlerId
pub fn on_connected_peer( &self, callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>, ) -> HandlerId
Callback is called when a peer is connected.
sourcepub fn on_disconnected_peer(
&self,
callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>,
) -> HandlerId
pub fn on_disconnected_peer( &self, callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>, ) -> HandlerId
Callback is called when a peer is disconnected.
sourcepub fn on_discovered_peer(
&self,
callback: Arc<dyn Fn(&PeerDiscovered) + Send + Sync + 'static>,
) -> HandlerId
pub fn on_discovered_peer( &self, callback: Arc<dyn Fn(&PeerDiscovered) + Send + Sync + 'static>, ) -> HandlerId
Callback is called when a routable or unraoutable peer is discovered.
sourcepub async fn get_requests_batch_handle(&self) -> NodeRequestsBatchHandle
pub async fn get_requests_batch_handle(&self) -> NodeRequestsBatchHandle
Returns the request batch handle with common “connection permit” slot from the shared pool.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Node
impl !RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl !UnwindSafe for Node
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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