feat(swarm): remove deprecated IntoConnectionHandler

This removes the deprecated `IntoConnectionHandler` trait and all its implementations. Consequently, `NetworkBehaviour::new_handler` and `NetworkBehaviour::addresses_of_peer` are now gone and the two `handle_` functions are now required to implement.

Related: #3647.

Pull-Request: #3884.
This commit is contained in:
Thomas Eizinger
2023-05-08 10:30:29 +02:00
committed by GitHub
parent b4e724dd72
commit 0e36c7c072
15 changed files with 38 additions and 371 deletions

View File

@ -18,8 +18,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#[allow(deprecated)]
use crate::handler::IntoConnectionHandler;
use crate::handler::{
AddressChange, ConnectionEvent, ConnectionHandler, ConnectionHandlerEvent,
ConnectionHandlerUpgrErr, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound,
@ -28,60 +26,9 @@ use crate::handler::{
use crate::upgrade::SendWrapper;
use either::Either;
use futures::future;
use libp2p_core::{
upgrade::{SelectUpgrade, UpgradeError},
ConnectedPoint,
};
use libp2p_identity::PeerId;
use libp2p_core::upgrade::{SelectUpgrade, UpgradeError};
use std::{cmp, task::Context, task::Poll};
/// Implementation of `IntoConnectionHandler` that combines two protocols into one.
#[derive(Debug, Clone)]
pub struct IntoConnectionHandlerSelect<TProto1, TProto2> {
/// The first protocol.
proto1: TProto1,
/// The second protocol.
proto2: TProto2,
}
impl<TProto1, TProto2> IntoConnectionHandlerSelect<TProto1, TProto2> {
/// Builds a `IntoConnectionHandlerSelect`.
pub(crate) fn new(proto1: TProto1, proto2: TProto2) -> Self {
IntoConnectionHandlerSelect { proto1, proto2 }
}
pub fn into_inner(self) -> (TProto1, TProto2) {
(self.proto1, self.proto2)
}
}
#[allow(deprecated)]
impl<TProto1, TProto2> IntoConnectionHandler for IntoConnectionHandlerSelect<TProto1, TProto2>
where
TProto1: IntoConnectionHandler,
TProto2: IntoConnectionHandler,
{
type Handler = ConnectionHandlerSelect<TProto1::Handler, TProto2::Handler>;
fn into_handler(
self,
remote_peer_id: &PeerId,
connected_point: &ConnectedPoint,
) -> Self::Handler {
ConnectionHandlerSelect {
proto1: self.proto1.into_handler(remote_peer_id, connected_point),
proto2: self.proto2.into_handler(remote_peer_id, connected_point),
}
}
fn inbound_protocol(&self) -> <Self::Handler as ConnectionHandler>::InboundProtocol {
SelectUpgrade::new(
SendWrapper(self.proto1.inbound_protocol()),
SendWrapper(self.proto2.inbound_protocol()),
)
}
}
/// Implementation of [`ConnectionHandler`] that combines two protocols into one.
#[derive(Debug, Clone)]
pub struct ConnectionHandlerSelect<TProto1, TProto2> {