Struct subspace_networking::Node

source ·
pub struct Node { /* private fields */ }
Expand description

Implementation of a network node on Subspace Network.

Implementations§

source§

impl Node

source

pub fn id(&self) -> PeerId

Node’s own local ID.

source

pub async fn get_value( &self, key: Multihash, ) -> Result<impl Stream<Item = PeerRecord>, GetValueError>

Return a value from the Kademlia network of the DSN.

source

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.

source

pub async fn subscribe( &self, topic: Sha256Topic, ) -> Result<TopicSubscription, SubscribeError>

Subcribe to some topic on the DSN.

source

pub async fn publish( &self, topic: Sha256Topic, message: Vec<u8>, ) -> Result<(), PublishError>

Subcribe a messgo to some topic on the DSN.

source

pub async fn send_generic_request<Request>( &self, peer_id: PeerId, request: Request, ) -> Result<Request::Response, SendRequestError>
where Request: GenericRequest,

Sends the generic request to the peer and awaits the result.

source

pub async fn get_closest_peers( &self, key: Multihash, ) -> Result<impl Stream<Item = PeerId>, GetClosestPeersError>

Get closest peers by multihash key using Kademlia DHT.

source

pub async fn get_providers( &self, key: RecordKey, ) -> Result<impl Stream<Item = PeerId>, GetProvidersError>

Get item providers by its key. Initiate ‘providers’ Kademlia operation.

source

pub async fn ban_peer(&self, peer_id: PeerId) -> Result<(), SendError>

Ban peer with specified peer ID.

source

pub fn listeners(&self) -> Vec<Multiaddr>

Node’s own addresses where it listens for incoming requests.

source

pub fn external_addresses(&self) -> Vec<Multiaddr>

Node’s own addresses observed remotely.

source

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.

source

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.

source

pub async fn connected_peers(&self) -> Result<Vec<PeerId>, ConnectedPeersError>

Returns a collection of currently connected peers.

source

pub async fn bootstrap(&self) -> Result<(), BootstrapError>

Bootstraps Kademlia network

source

pub fn on_connected_peer( &self, callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>, ) -> HandlerId

Callback is called when a peer is connected.

source

pub fn on_disconnected_peer( &self, callback: Arc<dyn Fn(&PeerId) + Send + Sync + 'static>, ) -> HandlerId

Callback is called when a peer is disconnected.

source

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.

source

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§

source§

impl Clone for Node

source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> JsonSchemaMaybe for T