Skip to content

Commit

Permalink
swarm: remove no longer required DummyBehaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Oct 11, 2022
1 parent af7cf9b commit fb0d273
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
55 changes: 0 additions & 55 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub mod dummy;
pub mod handler;
pub mod keep_alive;

use behaviour::FromSwarm;
pub use behaviour::{
CloseConnection, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
};
Expand Down Expand Up @@ -1537,60 +1536,6 @@ impl error::Error for DialError {
}
}

/// Dummy implementation of [`NetworkBehaviour`] that doesn't do anything.
#[derive(Clone)]
pub struct DummyBehaviour {
keep_alive: KeepAlive,
}

impl DummyBehaviour {
pub fn with_keep_alive(keep_alive: KeepAlive) -> Self {
Self { keep_alive }
}

pub fn keep_alive_mut(&mut self) -> &mut KeepAlive {
&mut self.keep_alive
}
}

impl Default for DummyBehaviour {
fn default() -> Self {
Self {
keep_alive: KeepAlive::No,
}
}
}

impl NetworkBehaviour for DummyBehaviour {
type ConnectionHandler = handler::DummyConnectionHandler;
type OutEvent = void::Void;

fn new_handler(&mut self) -> Self::ConnectionHandler {
handler::DummyConnectionHandler {
keep_alive: self.keep_alive,
}
}

fn on_swarm_event(&mut self, _event: FromSwarm<Self::ConnectionHandler>) {}

fn on_connection_handler_event(
&mut self,
_peer_id: PeerId,
_connection_id: ConnectionId,
event: crate::THandlerOutEvent<Self>,
) {
void::unreachable(event)
}

fn poll(
&mut self,
_: &mut Context<'_>,
_: &mut impl PollParameters,
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
Poll::Pending
}
}

/// Information about the connections obtained by [`Swarm::network_info()`].
#[derive(Clone, Debug)]
pub struct NetworkInfo {
Expand Down
4 changes: 2 additions & 2 deletions swarm/tests/public_api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use libp2p::core::transport::ListenerId;
use libp2p::swarm::behaviour::FromSwarm;
use libp2p::swarm::handler::DummyConnectionHandler;
use libp2p::swarm::dummy;

#[test]
// test to break compilation everytime a variant changes,
// forcing us to revisit each implementation
fn swarm_event_variants() {
let event: FromSwarm<'_, DummyConnectionHandler> = FromSwarm::ListenerClosed {
let event: FromSwarm<'_, dummy::ConnectionHandler> = FromSwarm::ListenerClosed {
listener_id: ListenerId::new(),
reason: Ok(()),
};
Expand Down

0 comments on commit fb0d273

Please sign in to comment.