Struct sn_networking::Network
source · pub struct Network {
pub swarm_cmd_sender: Sender<SwarmCmd>,
pub peer_id: PeerId,
pub root_dir_path: PathBuf,
}Expand description
API to interact with the underlying Swarm
Fields§
§swarm_cmd_sender: Sender<SwarmCmd>§peer_id: PeerId§root_dir_path: PathBufImplementations§
source§impl Network
impl Network
sourcepub async fn start_listening(&self, addr: Multiaddr) -> Result<(), Error>
pub async fn start_listening(&self, addr: Multiaddr) -> Result<(), Error>
Listen for incoming connections on the given address.
sourcepub async fn add_to_routing_table(
&self,
peer_id: PeerId,
peer_addr: Multiaddr
) -> Result<(), Error>
pub async fn add_to_routing_table( &self, peer_id: PeerId, peer_addr: Multiaddr ) -> Result<(), Error>
Dial the given peer at the given address.
sourcepub async fn dial(&self, addr: Multiaddr) -> Result<(), Error>
pub async fn dial(&self, addr: Multiaddr) -> Result<(), Error>
Dial the given peer at the given address.
sourcepub async fn client_get_closest_peers(
&self,
key: &NetworkAddress
) -> Result<Vec<PeerId>, Error>
pub async fn client_get_closest_peers( &self, key: &NetworkAddress ) -> Result<Vec<PeerId>, Error>
Returns the closest peers to the given XorName, sorted by their distance to the xor_name.
Excludes the client’s PeerId while calculating the closest peers.
sourcepub async fn node_get_closest_peers(
&self,
key: &NetworkAddress
) -> Result<Vec<PeerId>, Error>
pub async fn node_get_closest_peers( &self, key: &NetworkAddress ) -> Result<Vec<PeerId>, Error>
Returns the closest peers to the given NetworkAddress, sorted by their distance to the key.
Includes our node’s PeerId while calculating the closest peers.
sourcepub async fn get_closest_local_peers(
&self,
key: &NetworkAddress
) -> Result<Vec<PeerId>, Error>
pub async fn get_closest_local_peers( &self, key: &NetworkAddress ) -> Result<Vec<PeerId>, Error>
Returns the closest peers to the given NetworkAddress that is fetched from the local
Routing Table. It is ordered by increasing distance of the peers
Note self peer_id is not included in the result.
sourcepub async fn get_all_local_peers(&self) -> Result<Vec<PeerId>, Error>
pub async fn get_all_local_peers(&self) -> Result<Vec<PeerId>, Error>
Returns all the PeerId from all the KBuckets from our local Routing Table Also contains our own PeerId.
sourcepub async fn node_send_to_closest(
&self,
request: &Request
) -> Result<Vec<Result<Response, Error>>, Error>
pub async fn node_send_to_closest( &self, request: &Request ) -> Result<Vec<Result<Response, Error>>, Error>
Send Request to the closest peers. If self is among the closest_peers, the Request is
forwarded to itself and handled. Then a corresponding Response is created and is
forwarded to itself. Hence the flow remains the same and there is no branching at the upper
layers.
sourcepub async fn send_req_no_reply_to_closest(
&self,
request: &Request
) -> Result<(), Error>
pub async fn send_req_no_reply_to_closest( &self, request: &Request ) -> Result<(), Error>
Send Request to the closest peers and ignore reply
If self is among the closest_peers, the Request is
forwarded to itself and handled. Then a corresponding Response is created and is
forwarded to itself. Hence the flow remains the same and there is no branching at the upper
layers.
sourcepub async fn send_req_no_reply_to_self_closest(
&self,
request: &Request
) -> Result<(), Error>
pub async fn send_req_no_reply_to_self_closest( &self, request: &Request ) -> Result<(), Error>
Send Request to the closest peers to self
sourcepub async fn client_send_to_closest(
&self,
request: &Request,
expect_all_responses: bool
) -> Result<Vec<Result<Response, Error>>, Error>
pub async fn client_send_to_closest( &self, request: &Request, expect_all_responses: bool ) -> Result<Vec<Result<Response, Error>>, Error>
Send Request to the closest peers. Self is not present among the recipients.
sourcepub async fn get_record_keys_closest_to_target(
&self,
target: &NetworkAddress,
distance: Distance
) -> Result<Vec<RecordKey>, Error>
pub async fn get_record_keys_closest_to_target( &self, target: &NetworkAddress, distance: Distance ) -> Result<Vec<RecordKey>, Error>
Returns the list of keys that are within the provided distance to the target
sourcepub async fn get_record_from_network(
&self,
key: RecordKey
) -> Result<Record, Error>
pub async fn get_record_from_network( &self, key: RecordKey ) -> Result<Record, Error>
Get the Record from the network
sourcepub async fn get_local_record(
&self,
key: &RecordKey
) -> Result<Option<Record>, Error>
pub async fn get_local_record( &self, key: &RecordKey ) -> Result<Option<Record>, Error>
Get Record from the local RecordStore
sourcepub async fn put_local_record(&self, record: Record) -> Result<(), Error>
pub async fn put_local_record(&self, record: Record) -> Result<(), Error>
Put Record to the local RecordStore
Must be called after the validations are performed on the Record
sourcepub async fn get_all_local_record_addresses(
&self
) -> Result<HashSet<NetworkAddress>, Error>
pub async fn get_all_local_record_addresses( &self ) -> Result<HashSet<NetworkAddress>, Error>
Get the RecordAddress of all the Records stored locally
sourcepub async fn is_key_present_locally(
&self,
key: &RecordKey
) -> Result<bool, Error>
pub async fn is_key_present_locally( &self, key: &RecordKey ) -> Result<bool, Error>
Returns true if a RecordKey is present locally in the RecordStore
pub async fn add_keys_to_replication_fetcher( &self, peer: PeerId, keys: Vec<NetworkAddress> ) -> Result<Vec<(PeerId, NetworkAddress)>, Error>
pub async fn notify_fetch_result( &self, peer: PeerId, key: NetworkAddress, result: bool ) -> Result<Vec<(PeerId, NetworkAddress)>, Error>
sourcepub async fn set_record_distance_range(
&self,
distance: Distance
) -> Result<(), Error>
pub async fn set_record_distance_range( &self, distance: Distance ) -> Result<(), Error>
Set the acceptable range of record entry. A record is removed from the storage if the
distance between the record and the node is greater than the provided distance.
sourcepub async fn send_request(
&self,
req: Request,
peer: PeerId
) -> Result<Response, Error>
pub async fn send_request( &self, req: Request, peer: PeerId ) -> Result<Response, Error>
Send Request to the the given PeerId and await for the response. If self is the recipient,
then the Request is forwarded to itself and handled, and a corresponding Response is created
and returned to itself. Hence the flow remains the same and there is no branching at the upper
layers.
sourcepub async fn send_req_ignore_reply(
&self,
req: Request,
peer: PeerId
) -> Result<(), Error>
pub async fn send_req_ignore_reply( &self, req: Request, peer: PeerId ) -> Result<(), Error>
Send Request to the the given PeerId and do not await a response here.
Instead the Response will be handled by the common response_handler
sourcepub async fn send_response(
&self,
resp: Response,
channel: MsgResponder
) -> Result<(), Error>
pub async fn send_response( &self, resp: Response, channel: MsgResponder ) -> Result<(), Error>
Send a Response through the channel opened by the requester.
sourcepub async fn get_swarm_local_state(&self) -> Result<SwarmLocalState, Error>
pub async fn get_swarm_local_state(&self) -> Result<SwarmLocalState, Error>
Return a SwarmLocalState with some information obtained from swarm’s local state.
sourcepub async fn send_and_get_responses(
&self,
peers: Vec<PeerId>,
req: &Request,
get_all_responses: bool
) -> Vec<Result<Response, Error>>
pub async fn send_and_get_responses( &self, peers: Vec<PeerId>, req: &Request, get_all_responses: bool ) -> Vec<Result<Response, Error>>
Send a Request to the provided set of peers and wait for their responses concurrently.
If get_all_responses is true, we wait for the responses from all the peers.
NB TODO: Will return an error if the request timeouts.
If get_all_responses is false, we return the first successful response that we get
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Network
impl Send for Network
impl Sync for Network
impl Unpin for Network
impl !UnwindSafe for Network
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
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>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_mut() into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.