*: Dial with handler and return handler on error and closed (#2191)

Require `NetworkBehaviourAction::{DialPeer,DialAddress}` to contain a
`ProtocolsHandler`. This allows a behaviour to attach custom state to its
handler. The behaviour would no longer need to track this state separately
during connection establishment, thus reducing state required in a behaviour.
E.g. in the case of `libp2p-kad` the behaviour can include a `GetRecord` request
in its handler, or e.g. in the case of `libp2p-request-response` the behaviour
can include the first request in the handler.

Return `ProtocolsHandler` on connection error and close. This allows a behaviour
to extract its custom state previously included in the handler on connection
failure and connection closing. E.g. in the case of `libp2p-kad` the behaviour
could extract the attached `GetRecord` from the handler of the failed connection
and then start another connection attempt with a new handler with the same
`GetRecord` or bubble up an error to the user.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
This commit is contained in:
Max Inden
2021-08-31 17:00:51 +02:00
committed by GitHub
parent b55ee69645
commit c161acfb50
38 changed files with 1111 additions and 477 deletions

View File

@ -230,7 +230,7 @@ enum PendingConnectionError {
InvalidPeerId,
TransportErrorMultiaddrNotSupported,
TransportErrorOther,
ConnectionLimit,
Aborted,
Io,
}
@ -248,8 +248,8 @@ impl<TTransErr> From<&libp2p_core::connection::PendingConnectionError<TTransErr>
libp2p_core::connection::PendingConnectionError::Transport(
libp2p_core::transport::TransportError::Other(_),
) => PendingConnectionError::TransportErrorOther,
libp2p_core::connection::PendingConnectionError::ConnectionLimit(_) => {
PendingConnectionError::ConnectionLimit
libp2p_core::connection::PendingConnectionError::Aborted => {
PendingConnectionError::Aborted
}
libp2p_core::connection::PendingConnectionError::IO(_) => PendingConnectionError::Io,
}