Struct libp2p::request_response::Throttled [−][src]
pub struct Throttled<C> where
C: RequestResponseCodec + Send,
<C as RequestResponseCodec>::Protocol: Sync, { /* fields omitted */ }
Expand description
A wrapper around RequestResponse
which adds request limits per peer.
Implementations
impl<C> Throttled<C> where
C: RequestResponseCodec + Send + Clone,
<C as RequestResponseCodec>::Protocol: Sync,
impl<C> Throttled<C> where
C: RequestResponseCodec + Send + Clone,
<C as RequestResponseCodec>::Protocol: Sync,
pub fn new<I>(c: C, protos: I, cfg: RequestResponseConfig) -> Throttled<C> where
C: Send,
I: IntoIterator<Item = (<C as RequestResponseCodec>::Protocol, ProtocolSupport)>,
<C as RequestResponseCodec>::Protocol: Sync,
pub fn new<I>(c: C, protos: I, cfg: RequestResponseConfig) -> Throttled<C> where
C: Send,
I: IntoIterator<Item = (<C as RequestResponseCodec>::Protocol, ProtocolSupport)>,
<C as RequestResponseCodec>::Protocol: Sync,
Create a new throttled request-response behaviour.
Wrap an existing RequestResponse
behaviour and apply send/recv limits.
Set the global default receive limit per peer.
Override the receive limit of a single peer.
Remove any limit overrides for the given peer.
Has the limit of outbound requests been reached for the given peer?
pub fn send_request(
&mut self,
p: &PeerId,
req: <C as RequestResponseCodec>::Request
) -> Result<RequestId, <C as RequestResponseCodec>::Request>
pub fn send_request(
&mut self,
p: &PeerId,
req: <C as RequestResponseCodec>::Request
) -> Result<RequestId, <C as RequestResponseCodec>::Request>
Send a request to a peer.
If the limit of outbound requests has been reached, the request is
returned. Sending more outbound requests should only be attempted
once Event::ResumeSending
has been received from NetworkBehaviour::poll
.
pub fn send_response(
&mut self,
ch: ResponseChannel<Message<<C as RequestResponseCodec>::Response>>,
res: <C as RequestResponseCodec>::Response
) -> Result<(), <C as RequestResponseCodec>::Response>
pub fn send_response(
&mut self,
ch: ResponseChannel<Message<<C as RequestResponseCodec>::Response>>,
res: <C as RequestResponseCodec>::Response
) -> Result<(), <C as RequestResponseCodec>::Response>
Answer an inbound request with a response.
See RequestResponse::send_response
for details.
Add a known peer address.
See RequestResponse::add_address
for details.
Remove a previously added peer address.
See RequestResponse::remove_address
for details.
Are we connected to the given peer?
See RequestResponse::is_connected
for details.
Are we waiting for a response to the given request?
See RequestResponse::is_pending_outbound
for details.
Is the remote waiting for the local node to respond to the given request?
See RequestResponse::is_pending_inbound
for details.
Trait Implementations
impl<C> NetworkBehaviour for Throttled<C> where
C: RequestResponseCodec + Send + Clone + 'static,
<C as RequestResponseCodec>::Protocol: Sync,
impl<C> NetworkBehaviour for Throttled<C> where
C: RequestResponseCodec + Send + Clone + 'static,
<C as RequestResponseCodec>::Protocol: Sync,
type ProtocolsHandler = RequestResponseHandler<Codec<C>>
type ProtocolsHandler = RequestResponseHandler<Codec<C>>
Handler for all the protocols the network behaviour supports.
type OutEvent = Event<<C as RequestResponseCodec>::Request, <C as RequestResponseCodec>::Response, Message<<C as RequestResponseCodec>::Response>>
type OutEvent = Event<<C as RequestResponseCodec>::Request, <C as RequestResponseCodec>::Response, Message<<C as RequestResponseCodec>::Response>>
Event generated by the NetworkBehaviour
and that the swarm will report back.
Creates a new ProtocolsHandler
for a connection with a peer. Read more
Addresses that this behaviour is aware of for this specific peer, and that may allow reaching the peer. Read more
pub fn inject_connection_established(
&mut self,
p: &PeerId,
id: &ConnectionId,
end: &ConnectedPoint
)
pub fn inject_connection_established(
&mut self,
p: &PeerId,
id: &ConnectionId,
end: &ConnectedPoint
)
Informs the behaviour about a newly established connection to a peer.
pub fn inject_connection_closed(
&mut self,
peer: &PeerId,
id: &ConnectionId,
end: &ConnectedPoint
)
pub fn inject_connection_closed(
&mut self,
peer: &PeerId,
id: &ConnectionId,
end: &ConnectedPoint
)
Informs the behaviour about a closed connection to a peer. Read more
Indicate to the behaviour that we connected to the node with the given peer id. Read more
Indicates to the behaviour that we disconnected from the node with the given peer id. Read more
Indicates to the behaviour that we tried to dial all the addresses known for a node, but failed. Read more
pub fn inject_event(
&mut self,
p: PeerId,
i: ConnectionId,
e: RequestResponseHandlerEvent<Codec<C>>
)
pub fn inject_event(
&mut self,
p: PeerId,
i: ConnectionId,
e: RequestResponseHandlerEvent<Codec<C>>
)
Informs the behaviour about an event generated by the handler dedicated to the peer identified by peer_id
.
for the behaviour. Read more
pub fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<RequestProtocol<Codec<C>>, <Throttled<C> as NetworkBehaviour>::OutEvent>>
pub fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<RequestProtocol<Codec<C>>, <Throttled<C> as NetworkBehaviour>::OutEvent>>
Polls for things that swarm should do. Read more
fn inject_address_change(
&mut self,
&PeerId,
&ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
fn inject_address_change(
&mut self,
&PeerId,
&ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
Informs the behaviour that the ConnectedPoint
of an existing connection has changed.
Indicates to the behaviour that we tried to reach an address, but failed. Read more
Indicates to the behaviour that a new listener was created.
Indicates to the behaviour that we have started listening on a new multiaddr.
Indicates to the behaviour that a multiaddr we were listening on has expired, which means that we are no longer listening in it. Read more
A listener experienced an error.
A listener closed.
Indicates to the behaviour that we have discovered a new external address for us.
Indicates to the behaviour that an external address was removed.
Auto Trait Implementations
impl<C> !RefUnwindSafe for Throttled<C>
impl<C> Sync for Throttled<C> where
C: Sync,
<C as RequestResponseCodec>::Request: Sync,
<C as RequestResponseCodec>::Response: Sync,
impl<C> Unpin for Throttled<C> where
C: Unpin,
<C as RequestResponseCodec>::Protocol: Unpin,
<C as RequestResponseCodec>::Request: Unpin,
<C as RequestResponseCodec>::Response: Unpin,
impl<C> !UnwindSafe for Throttled<C>