mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-13 01:51:23 +00:00
swarm/handler: replace inject_* methods (#3085)
Previously, we had one callback for each kind of message that a `ConnectionHandler` would receive from either its `NetworkBehaviour` or the connection itself. With this patch, we combine these functions, resulting in two callbacks: - `on_behaviour_event` - `on_connection_event` Resolves #3080.
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
use crate::behaviour::{FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
|
||||
use crate::handler::{
|
||||
ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol,
|
||||
ConnectionEvent, ConnectionHandlerEvent, FullyNegotiatedInbound, FullyNegotiatedOutbound,
|
||||
KeepAlive, SubstreamProtocol,
|
||||
};
|
||||
use crate::NegotiatedSubstream;
|
||||
use libp2p_core::connection::ConnectionId;
|
||||
use libp2p_core::upgrade::DeniedUpgrade;
|
||||
use libp2p_core::PeerId;
|
||||
use libp2p_core::{
|
||||
upgrade::{DeniedUpgrade, InboundUpgrade, OutboundUpgrade},
|
||||
Multiaddr,
|
||||
};
|
||||
use std::task::{Context, Poll};
|
||||
use void::Void;
|
||||
|
||||
@ -76,46 +73,10 @@ impl crate::handler::ConnectionHandler for ConnectionHandler {
|
||||
SubstreamProtocol::new(DeniedUpgrade, ())
|
||||
}
|
||||
|
||||
fn inject_fully_negotiated_inbound(
|
||||
&mut self,
|
||||
protocol: <Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Output,
|
||||
_: Self::InboundOpenInfo,
|
||||
) {
|
||||
void::unreachable(protocol);
|
||||
}
|
||||
|
||||
fn inject_fully_negotiated_outbound(
|
||||
&mut self,
|
||||
protocol: <Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Output,
|
||||
_: Self::OutboundOpenInfo,
|
||||
) {
|
||||
void::unreachable(protocol)
|
||||
}
|
||||
|
||||
fn inject_event(&mut self, v: Self::InEvent) {
|
||||
fn on_behaviour_event(&mut self, v: Self::InEvent) {
|
||||
void::unreachable(v)
|
||||
}
|
||||
|
||||
fn inject_address_change(&mut self, _: &Multiaddr) {}
|
||||
|
||||
fn inject_dial_upgrade_error(
|
||||
&mut self,
|
||||
_: Self::OutboundOpenInfo,
|
||||
_: ConnectionHandlerUpgrErr<
|
||||
<Self::OutboundProtocol as OutboundUpgrade<NegotiatedSubstream>>::Error,
|
||||
>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn inject_listen_upgrade_error(
|
||||
&mut self,
|
||||
_: Self::InboundOpenInfo,
|
||||
_: ConnectionHandlerUpgrErr<
|
||||
<Self::InboundProtocol as InboundUpgrade<NegotiatedSubstream>>::Error,
|
||||
>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn connection_keep_alive(&self) -> KeepAlive {
|
||||
KeepAlive::Yes
|
||||
}
|
||||
@ -133,4 +94,26 @@ impl crate::handler::ConnectionHandler for ConnectionHandler {
|
||||
> {
|
||||
Poll::Pending
|
||||
}
|
||||
|
||||
fn on_connection_event(
|
||||
&mut self,
|
||||
event: ConnectionEvent<
|
||||
Self::InboundProtocol,
|
||||
Self::OutboundProtocol,
|
||||
Self::InboundOpenInfo,
|
||||
Self::OutboundOpenInfo,
|
||||
>,
|
||||
) {
|
||||
match event {
|
||||
ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound {
|
||||
protocol, ..
|
||||
}) => void::unreachable(protocol),
|
||||
ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound {
|
||||
protocol, ..
|
||||
}) => void::unreachable(protocol),
|
||||
ConnectionEvent::DialUpgradeError(_)
|
||||
| ConnectionEvent::ListenUpgradeError(_)
|
||||
| ConnectionEvent::AddressChange(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user