mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-04 20:21:33 +00:00
libp2p-ping improvements. (#1049)
* libp2p-ping improvements. * re #950: Removes use of the `OneShotHandler`, but still sending each ping over a new substream, as seems to be intentional since #828. * re #842: Adds an integration test that exercises the ping behaviour through a Swarm, requiring the RTT to be below a threshold. This requires disabling Nagle's algorithm as it can interact badly with delayed ACKs (and has been observed to do so in the context of the new ping example and integration test). * re #864: Control of the inbound and outbound (sub)stream protocol upgrade timeouts has been moved from the `NodeHandlerWrapperBuilder` to the `ProtocolsHandler`. That may also alleviate the need for a custom timeout on an `OutboundSubstreamRequest` as a `ProtocolsHandler` is now free to adjust these timeouts over time. Other changes: * A new ping example. * Documentation improvements. * More documentation improvements. * Add PingPolicy and ensure no event is dropped. * Remove inbound_timeout/outbound_timeout. As per review comment, the inbound timeout is now configured as part of the `listen_protocol` and the outbound timeout as part of the `OutboundSubstreamRequest`. * Simplify and generalise. Generalise `ListenProtocol` to `SubstreamProtocol`, reusing it in the context of `ProtocolsHandlerEvent::OutboundSubstreamRequest`. * Doc comments for SubstreamProtocol. * Adapt to changes in master. * Relax upper bound for ping integration test rtt. For "slow" CI build machines?
This commit is contained in:
@ -37,7 +37,7 @@ pub trait NetworkBehaviour {
|
||||
/// Event generated by the swarm.
|
||||
type OutEvent;
|
||||
|
||||
/// Builds a new `ProtocolsHandler`.
|
||||
/// Creates a new `ProtocolsHandler` for a connection with a peer.
|
||||
fn new_handler(&mut self) -> Self::ProtocolsHandler;
|
||||
|
||||
/// Addresses that this behaviour is aware of for this specific peer, and that may allow
|
||||
@ -104,45 +104,48 @@ pub trait NetworkBehaviourEventProcess<TEvent> {
|
||||
fn inject_event(&mut self, event: TEvent);
|
||||
}
|
||||
|
||||
/// Action to perform.
|
||||
/// An action that a [`NetworkBehaviour`] can trigger in the [`Swarm`]
|
||||
/// in whose context it is executing.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum NetworkBehaviourAction<TInEvent, TOutEvent> {
|
||||
/// Generate an event for the outside.
|
||||
/// Instructs the `Swarm` to return an event when it is being polled.
|
||||
GenerateEvent(TOutEvent),
|
||||
|
||||
// TODO: report new raw connection for usage after intercepting an address dial
|
||||
|
||||
/// Instructs the swarm to dial the given multiaddress without any expectation of a peer id.
|
||||
/// Instructs the swarm to dial the given multiaddress, without a known `PeerId`.
|
||||
DialAddress {
|
||||
/// The address to dial.
|
||||
address: Multiaddr,
|
||||
},
|
||||
|
||||
/// Instructs the swarm to try reach the given peer.
|
||||
/// Instructs the swarm to dial a known `PeerId`.
|
||||
///
|
||||
/// In the future, a corresponding `inject_dial_failure` or `inject_connected` function call
|
||||
/// must be performed.
|
||||
/// On success, [`NetworkBehaviour::inject_connected`] is invoked.
|
||||
/// On failure, [`NetworkBehaviour::inject_dial_failure`] is invoked.
|
||||
DialPeer {
|
||||
/// The peer to try reach.
|
||||
peer_id: PeerId,
|
||||
},
|
||||
|
||||
/// If we're connected to the given peer, sends a message to the protocol handler.
|
||||
/// Instructs the `Swarm` to send a message to a connected peer.
|
||||
///
|
||||
/// If we're not connected to this peer, does nothing. If necessary, the implementation of
|
||||
/// `NetworkBehaviour` is supposed to track which peers we are connected to.
|
||||
/// If the `Swarm` is connected to the peer, the message is delivered to the remote's
|
||||
/// protocol handler. If there is no connection to the peer, the message is ignored.
|
||||
/// To ensure delivery, the `NetworkBehaviour` must keep track of connected peers.
|
||||
SendEvent {
|
||||
/// The peer which to send the message to.
|
||||
/// The peer to which to send the message.
|
||||
peer_id: PeerId,
|
||||
/// Event to send to the peer.
|
||||
/// The message to send.
|
||||
event: TInEvent,
|
||||
},
|
||||
|
||||
/// Reports that a remote observes us as this address.
|
||||
/// Informs the `Swarm` about a multi-address observed by a remote for
|
||||
/// the local node.
|
||||
///
|
||||
/// The swarm will pass this address through the transport's NAT traversal.
|
||||
ReportObservedAddr {
|
||||
/// The address we're being observed as.
|
||||
/// The observed address of the local node.
|
||||
address: Multiaddr,
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user