Struct smoldot::libp2p::Network [−][src]
Data structure containing the list of all connections, pending or not, and their latest known state. See also the module-level documentation.
Implementations
impl<TNow, TPeer, TConn> Network<TNow, TPeer, TConn> where
TNow: Clone + Add<Duration, Output = TNow> + Sub<TNow, Output = Duration> + Ord,
[src]
TNow: Clone + Add<Duration, Output = TNow> + Sub<TNow, Output = Duration> + Ord,
pub fn new(config: Config<TPeer>) -> Self
[src]
Initializes a new network data structure.
pub async fn num_established_connections(&self) -> usize
[src]
Returns the number of established TCP connections, both incoming and outgoing.
pub fn noise_key(&self) -> &NoiseKey
[src]
Returns the Noise key originalled passed as Config::noise_key
.
pub fn overlay_networks(&self) -> impl ExactSizeIterator<Item = &OverlayNetwork>
[src]
Returns the list the overlay networks originally passed as Config::overlay_networks
.
pub fn request_response_protocols(
&self
) -> impl ExactSizeIterator<Item = &ConfigRequestResponse>
[src]
&self
) -> impl ExactSizeIterator<Item = &ConfigRequestResponse>
Returns the list the request-response protocols originally passed as
Config::request_response_protocols
.
pub async fn peers_list_lock(&self) -> impl Iterator<Item = PeerId>
[src]
Returns an iterator to the list of PeerId
s that we have an established connection
with.
pub async fn add_addresses(
&self,
or_insert: impl FnOnce() -> TPeer,
overlay_network_index: usize,
peer_id: PeerId,
addrs: impl IntoIterator<Item = Multiaddr>
)
[src]
&self,
or_insert: impl FnOnce() -> TPeer,
overlay_network_index: usize,
peer_id: PeerId,
addrs: impl IntoIterator<Item = Multiaddr>
)
pub fn add_incoming_connection(
&self,
local_listen_address: &Multiaddr,
remote_addr: Multiaddr,
user_data: TConn
) -> ConnectionId
[src]
&self,
local_listen_address: &Multiaddr,
remote_addr: Multiaddr,
user_data: TConn
) -> ConnectionId
pub async fn request(
&self,
now: TNow,
target: PeerId,
protocol_index: usize,
request_data: Vec<u8>
) -> Result<Vec<u8>, RequestError>
[src]
&self,
now: TNow,
target: PeerId,
protocol_index: usize,
request_data: Vec<u8>
) -> Result<Vec<u8>, RequestError>
Sends a request to the given peer, and waits for a response.
This consists in:
- Opening a substream on an established connection with the target.
- Negotiating the requested protocol (
protocol_index
) on this substream using the multistream-select protocol. - Sending the request (
request_data
parameter), prefixed with its length. - Waiting for the response (prefixed with its length), which is then returned.
An error happens if there is no suitable connection for that request, if the connection
closes while the request is in progress, if the request or response doesn’t respect
the protocol limits (see ConfigRequestResponse
), or if the remote takes too much time
to answer.
As the API of this module is inherently subject to race conditions, it is never possible
to guarantee that this function will succeed. RequestError::ConnectionClosed
should
be handled by retrying the same request again.
Note: This function doesn’t return before the remote has answered. It is strongly recommended to await the returned
Future
in the background, and not block any important task on this.
Panic
Panics if protocol_index
isn’t a valid index in Config::request_response_protocols
.
pub async fn queue_notification(
&self,
target: &PeerId,
protocol_index: usize,
notification: impl Into<Vec<u8>>
) -> Result<(), QueueNotificationError>
[src]
&self,
target: &PeerId,
protocol_index: usize,
notification: impl Into<Vec<u8>>
) -> Result<(), QueueNotificationError>
Adds a notification to the queue of notifications to send to the given peer.
Each substream maintains a queue of notifications to be sent to the remote. This method attempts to push a notification to this queue.
As the API of this module is inherently subject to race conditions, it is possible for connections and substreams to no longer exist with this peer. This is a normal situation, and this error should simply be ignored apart from diagnostic purposes.
An error is also returned if the queue exceeds a certain size in bytes, for two reasons:
-
Since the content of the queue is transferred at a limited rate, each notification pushed at the end of the queue will take more time than the previous one to reach the destination. Once the queue reaches a certain size, the time it would take for newly-pushed notifications to reach the destination would start being unreasonably large.
-
If the remote deliberately applies back-pressure on the substream, it is undesirable to increase the memory usage of the local node.
Similarly, the queue being full is a normal situations and notification protocols should be designed in such a way that discarding notifications shouldn’t have a too negative impact.
Regardless of the success of this function, no guarantee exists about the successful delivery of notifications.
pub async fn pending_outcome_ok(
&self,
id: PendingId,
user_data: TConn
) -> ConnectionId
[src]
&self,
id: PendingId,
user_data: TConn
) -> ConnectionId
After calling Network::fill_out_slots
, notifies the Network
of the success of the
dialing attempt.
See also Network::pending_outcome_err
.
Panic
Panics if the PendingId
is invalid.
pub async fn pending_outcome_err(&self, id: PendingId)
[src]
After calling Network::fill_out_slots
, notifies the Network
of the failure of the
dialing attempt.
See also Network::pending_outcome_ok
.
Panic
Panics if the PendingId
is invalid.
pub async fn accept_notifications_in(
&self,
id: ConnectionId,
overlay_network_index: usize,
handshake: Vec<u8>
)
[src]
&self,
id: ConnectionId,
overlay_network_index: usize,
handshake: Vec<u8>
)
pub async fn respond_in_request(
&self,
id: ConnectionId,
substream_id: SubstreamId,
response: Result<Vec<u8>, ()>
)
[src]
&self,
id: ConnectionId,
substream_id: SubstreamId,
response: Result<Vec<u8>, ()>
)
Responds to an incoming request. Must be called in response to a Event::RequestIn
.
Passing an Err
corresponds, on the other side, to a
established::RequestError::SubstreamClosed
.
Has no effect if the connection has been closed in the meanwhile.
pub async fn next_event(&self) -> Event<TConn>
[src]
Returns the next event produced by the service.
This function should be called at a high enough rate that Network::read_write
can
continue pushing events to the internal buffer of events. Failure to call this function
often enough will lead to connections being back-pressured.
See also Config::pending_api_events_buffer_size
.
It is technically possible to call this function multiple times simultaneously, in which
case the events will be distributed amongst the multiple calls in an unspecified way.
Keep in mind that some Event
s have logic attached to the order in which they are
produced, and calling this function multiple times is therefore discouraged.
pub async fn read_write<'a>(
&self,
connection_id: ConnectionId,
now: TNow,
incoming_buffer: Option<&[u8]>,
outgoing_buffer: (&'a mut [u8], &'a mut [u8])
) -> Result<ReadWrite<TNow>, ConnectionError>
[src]
&self,
connection_id: ConnectionId,
now: TNow,
incoming_buffer: Option<&[u8]>,
outgoing_buffer: (&'a mut [u8], &'a mut [u8])
) -> Result<ReadWrite<TNow>, ConnectionError>
Panic
Panics if connection_id
isn’t a valid connection.
pub async fn open_next_substream(
&self
) -> Option<SubstreamOpen<'_, TNow, TPeer, TConn>>
[src]
&self
) -> Option<SubstreamOpen<'_, TNow, TPeer, TConn>>
pub async fn fill_out_slots<'a>(
&self,
overlay_network_index: usize
) -> Option<StartConnect>
[src]
&self,
overlay_network_index: usize
) -> Option<StartConnect>
Spawns new outgoing connections in order to fill empty outgoing slots.
Auto Trait Implementations
impl<TNow, TPeer, TConn> !RefUnwindSafe for Network<TNow, TPeer, TConn>
impl<TNow, TPeer, TConn> Send for Network<TNow, TPeer, TConn> where
TConn: Send,
TNow: Send,
TPeer: Send,
TConn: Send,
TNow: Send,
TPeer: Send,
impl<TNow, TPeer, TConn> Sync for Network<TNow, TPeer, TConn> where
TConn: Send,
TNow: Send,
TPeer: Send,
TConn: Send,
TNow: Send,
TPeer: Send,
impl<TNow, TPeer, TConn> Unpin for Network<TNow, TPeer, TConn> where
TPeer: Unpin,
TPeer: Unpin,
impl<TNow, TPeer, TConn> !UnwindSafe for Network<TNow, TPeer, TConn>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Conv for T
impl<T> Conv for T
impl<T> Downcast for T where
T: Any,
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> DowncastSync for T where
T: Send + Sync + Any,
T: Send + Sync + Any,
impl<T> FmtForward for T
pub fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Self: Binary,
pub fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Self: Display,
pub fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Self: LowerExp,
pub fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Self: LowerHex,
pub fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Self: Octal,
pub fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Self: Pointer,
pub fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Self: UpperExp,
pub fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Self: UpperHex,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pipe for T where
T: ?Sized,
T: ?Sized,
pub fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
pub fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
pub fn pipe_ref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self) -> R
) -> R where
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut Self) -> R
) -> R where
R: 'a,
pub fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
pub fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
pub fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
Self: AsRef<U>,
R: 'a,
U: 'a + ?Sized,
pub fn pipe_as_mut<'a, U, R>(
&'a mut self,
func: impl FnOnce(&'a mut U) -> R
) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
&'a mut self,
func: impl FnOnce(&'a mut U) -> R
) -> R where
Self: AsMut<U>,
R: 'a,
U: 'a + ?Sized,
pub fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
pub fn pipe_deref_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: DerefMut<Target = T> + Deref,
T: 'a + ?Sized,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: DerefMut<Target = T> + Deref,
T: 'a + ?Sized,
R: 'a,
impl<T> Pipe for T
impl<T> PipeAsRef for T
pub fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
Self: AsRef<T>,
T: 'a,
R: 'a,
pub fn pipe_as_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: AsMut<T>,
T: 'a,
R: 'a,
impl<T> PipeBorrow for T
pub fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
Self: Borrow<T>,
T: 'a,
R: 'a,
pub fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
Self: BorrowMut<T>,
T: 'a,
R: 'a,
impl<T> PipeDeref for T
pub fn pipe_deref<'a, R>(
&'a self,
func: impl FnOnce(&'a Self::Target) -> R
) -> R where
Self: Deref,
R: 'a,
&'a self,
func: impl FnOnce(&'a Self::Target) -> R
) -> R where
Self: Deref,
R: 'a,
pub fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
Self: DerefMut,
R: 'a,
impl<T> PipeRef for T
pub fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
pub fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
R: 'a,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> Tap for T
pub fn tap(self, func: impl FnOnce(&Self)) -> Self
pub fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self
pub fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Self: Borrow<B>,
B: ?Sized,
pub fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Self: BorrowMut<B>,
B: ?Sized,
pub fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Self: AsRef<R>,
R: ?Sized,
pub fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Self: AsMut<R>,
R: ?Sized,
pub fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Self: Deref<Target = T>,
T: ?Sized,
pub fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
pub fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
pub fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
pub fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Self: Borrow<B>,
B: ?Sized,
pub fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Self: BorrowMut<B>,
B: ?Sized,
pub fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Self: AsRef<R>,
R: ?Sized,
pub fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Self: AsMut<R>,
R: ?Sized,
pub fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Self: Deref<Target = T>,
T: ?Sized,
pub fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
impl<T> Tap for T
pub fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
pub fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
pub fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
pub fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
U: ?Sized,
pub fn tap_ref<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
pub fn tap_ref_dbg<F, R>(self, func: F) -> Self where
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
pub fn tap_ref_mut<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
pub fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
U: ?Sized,
pub fn tap_borrow<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
pub fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
pub fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
pub fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
impl<T> TapDeref for T
pub fn tap_deref<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
pub fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
pub fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
pub fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
impl<T> TryConv for T
impl<T> TryConv for T
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,