swarm/behaviour: Replace inject_* with on_event (#3011)

This commit is contained in:
João Oliveira
2022-11-17 09:28:40 +00:00
committed by GitHub
parent a714864885
commit 3df3c88f3d
38 changed files with 2482 additions and 1652 deletions

View File

@ -1,4 +1,4 @@
use crate::behaviour::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use crate::behaviour::{FromSwarm, NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use crate::handler::{
ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive, SubstreamProtocol,
};
@ -29,7 +29,7 @@ impl NetworkBehaviour for Behaviour {
ConnectionHandler
}
fn inject_event(&mut self, _: PeerId, _: ConnectionId, event: Void) {
fn on_connection_handler_event(&mut self, _: PeerId, _: ConnectionId, event: Void) {
void::unreachable(event)
}
@ -40,6 +40,23 @@ impl NetworkBehaviour for Behaviour {
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
Poll::Pending
}
fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
match event {
FromSwarm::ConnectionEstablished(_)
| FromSwarm::ConnectionClosed(_)
| FromSwarm::AddressChange(_)
| FromSwarm::DialFailure(_)
| FromSwarm::ListenFailure(_)
| FromSwarm::NewListener(_)
| FromSwarm::NewListenAddr(_)
| FromSwarm::ExpiredListenAddr(_)
| FromSwarm::ListenerError(_)
| FromSwarm::ListenerClosed(_)
| FromSwarm::NewExternalAddr(_)
| FromSwarm::ExpiredExternalAddr(_) => {}
}
}
}
/// Implementation of [`ConnectionHandler`] that doesn't handle anything but keeps the connection alive.