mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-31 00:41:59 +00:00
feat(swarm)!: allow NetworkBehaviour
s to manage connections
Previously, a `ConnectionHandler` was immediately requested from the `NetworkBehaviour` as soon as a new dial was initiated or a new incoming connection accepted. With this patch, we delay the creation of the handler until the connection is actually established and fully upgraded, i.e authenticated and multiplexed. As a consequence, `NetworkBehaviour::new_handler` is now deprecated in favor of a new set of callbacks: - `NetworkBehaviour::handle_pending_inbound_connection` - `NetworkBehaviour::handle_pending_outbound_connection` - `NetworkBehaviour::handle_established_inbound_connection` - `NetworkBehaviour::handle_established_outbound_connection` All callbacks are fallible, allowing the `NetworkBehaviour` to abort the connection either immediately or after it is fully established. All callbacks also receive a `ConnectionId` parameter which uniquely identifies the connection. For example, in case a `NetworkBehaviour` issues a dial via `NetworkBehaviourAction::Dial`, it can unambiguously detect this dial in these lifecycle callbacks via the `ConnectionId`. Finally, `NetworkBehaviour::handle_pending_outbound_connection` also replaces `NetworkBehaviour::addresses_of_peer` by allowing the behaviour to return more addresses to be used for the dial. Resolves #2824. Pull-Request: #3254.
This commit is contained in:
@@ -244,6 +244,9 @@ impl<TBvEv, THandleErr> super::Recorder<libp2p_swarm::SwarmEvent<TBvEv, THandleE
|
||||
libp2p_swarm::DialError::WrongPeerId { .. } => {
|
||||
record(OutgoingConnectionError::WrongPeerId)
|
||||
}
|
||||
libp2p_swarm::DialError::Denied { .. } => {
|
||||
record(OutgoingConnectionError::Denied)
|
||||
}
|
||||
};
|
||||
}
|
||||
libp2p_swarm::SwarmEvent::BannedPeer { endpoint, .. } => {
|
||||
@@ -344,6 +347,7 @@ enum OutgoingConnectionError {
|
||||
WrongPeerId,
|
||||
TransportMultiaddrNotSupported,
|
||||
TransportOther,
|
||||
Denied,
|
||||
}
|
||||
|
||||
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
|
||||
@@ -360,6 +364,7 @@ enum IncomingConnectionError {
|
||||
TransportErrorOther,
|
||||
Aborted,
|
||||
ConnectionLimit,
|
||||
Denied,
|
||||
}
|
||||
|
||||
impl From<&libp2p_swarm::ListenError> for IncomingConnectionError {
|
||||
@@ -377,6 +382,7 @@ impl From<&libp2p_swarm::ListenError> for IncomingConnectionError {
|
||||
libp2p_core::transport::TransportError::Other(_),
|
||||
) => IncomingConnectionError::TransportErrorOther,
|
||||
libp2p_swarm::ListenError::Aborted => IncomingConnectionError::Aborted,
|
||||
libp2p_swarm::ListenError::Denied { .. } => IncomingConnectionError::Denied,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user