Skip to content

Commit

Permalink
Don't override default functions unless necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Jul 20, 2021
1 parent 2dd3abd commit dc690e4
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 88 deletions.
6 changes: 1 addition & 5 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::topic::Topic;
use crate::FloodsubConfig;
use cuckoofilter::{CuckooError, CuckooFilter};
use fnv::FnvHashSet;
use libp2p_core::{Multiaddr, PeerId, connection::ConnectionId};
use libp2p_core::{PeerId, connection::ConnectionId};
use libp2p_swarm::{
NetworkBehaviour,
NetworkBehaviourAction,
Expand Down Expand Up @@ -249,10 +249,6 @@ impl NetworkBehaviour for Floodsub {
Default::default()
}

fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, id: &PeerId) {
// We need to send our subscriptions to the newly-connected node.
if self.target_peers.contains(id) {
Expand Down
4 changes: 0 additions & 4 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2804,10 +2804,6 @@ where
)
}

fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, peer_id: &PeerId) {
// Ignore connections from blacklisted peers.
if self.blacklisted_peers.contains(peer_id) {
Expand Down
15 changes: 4 additions & 11 deletions protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,6 @@ impl NetworkBehaviour for Identify {
IdentifyHandler::new(self.config.initial_delay, self.config.interval)
}

fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, _: &PeerId) {
}

fn inject_connection_established(&mut self, peer_id: &PeerId, conn: &ConnectionId, endpoint: &ConnectedPoint) {
let addr = match endpoint {
ConnectedPoint::Dialer { address } => address.clone(),
Expand Down Expand Up @@ -517,8 +510,8 @@ mod tests {
pin_mut!(swarm2_fut);

match future::select(swarm1_fut, swarm2_fut).await.factor_second().0 {
future::Either::Left(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
future::Either::Left(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
..
})) => {
assert_eq!(info.public_key, pubkey2);
Expand All @@ -528,8 +521,8 @@ mod tests {
assert!(info.listen_addrs.is_empty());
return;
}
future::Either::Right(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
future::Either::Right(SwarmEvent::Behaviour(IdentifyEvent::Received {
info,
..
})) => {
assert_eq!(info.public_key, pubkey1);
Expand Down
15 changes: 1 addition & 14 deletions protocols/mdns/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use if_watch::{IfEvent, IfWatcher};
use lazy_static::lazy_static;
use libp2p_core::connection::ListenerId;
use libp2p_core::{
address_translation, connection::ConnectionId, multiaddr::Protocol, Multiaddr, PeerId,
address_translation, multiaddr::Protocol, Multiaddr, PeerId,
};
use libp2p_swarm::{
protocols_handler::DummyProtocolsHandler, NetworkBehaviour, NetworkBehaviourAction,
Expand Down Expand Up @@ -254,19 +254,6 @@ impl NetworkBehaviour for Mdns {
.collect()
}

fn inject_connected(&mut self, _: &PeerId) {}

fn inject_disconnected(&mut self, _: &PeerId) {}

fn inject_event(
&mut self,
_: PeerId,
_: ConnectionId,
ev: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
) {
void::unreachable(ev)
}

fn inject_new_listen_addr(&mut self, _id: ListenerId, _addr: &Multiaddr) {
self.timeout
.set_interval_at(Instant::now(), self.query_interval);
Expand Down
10 changes: 1 addition & 9 deletions protocols/ping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub mod handler;
pub use handler::{PingConfig, PingResult, PingSuccess, PingFailure};
use handler::PingHandler;

use libp2p_core::{Multiaddr, PeerId, connection::ConnectionId};
use libp2p_core::{PeerId, connection::ConnectionId};
use libp2p_swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters};
use std::{collections::VecDeque, task::Context, task::Poll};
use void::Void;
Expand Down Expand Up @@ -95,14 +95,6 @@ impl NetworkBehaviour for Ping {
PingHandler::new(self.config.clone())
}

fn addresses_of_peer(&mut self, _peer_id: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, _: &PeerId) {}

fn inject_disconnected(&mut self, _: &PeerId) {}

fn inject_event(&mut self, peer: PeerId, _: ConnectionId, result: PingResult) {
self.events.push_front(PingEvent { peer, result })
}
Expand Down
20 changes: 0 additions & 20 deletions protocols/relay/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,26 +1358,6 @@ impl libp2p_swarm::NetworkBehaviour for KeepAliveBehaviour {
}
}

fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, _: &PeerId) {}

fn inject_connection_established(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint) {}

fn inject_disconnected(&mut self, _: &PeerId) {}

fn inject_connection_closed(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint) {}

fn inject_event(
&mut self,
_: PeerId,
_: ConnectionId,
_: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent,
) {
}

fn poll(
&mut self,
_: &mut Context<'_>,
Expand Down
17 changes: 1 addition & 16 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
}
this.behaviour.inject_new_listen_addr(listener_id, &listen_addr);
return Poll::Ready(SwarmEvent::NewListenAddr {
listener_id,
listener_id,
address: listen_addr
});
}
Expand Down Expand Up @@ -1156,21 +1156,6 @@ impl NetworkBehaviour for DummyBehaviour {
protocols_handler::DummyProtocolsHandler::default()
}

fn addresses_of_peer(&mut self, _: &PeerId) -> Vec<Multiaddr> {
Vec::new()
}

fn inject_connected(&mut self, _: &PeerId) {}

fn inject_connection_established(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint) {}

fn inject_disconnected(&mut self, _: &PeerId) {}

fn inject_connection_closed(&mut self, _: &PeerId, _: &ConnectionId, _: &ConnectedPoint) {}

fn inject_event(&mut self, _: PeerId, _: ConnectionId,
_: <Self::ProtocolsHandler as ProtocolsHandler>::OutEvent) {}

fn poll(&mut self, _: &mut Context<'_>, _: &mut impl PollParameters) ->
Poll<NetworkBehaviourAction<<Self::ProtocolsHandler as
ProtocolsHandler>::InEvent, Self::OutEvent>>
Expand Down
9 changes: 0 additions & 9 deletions swarm/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ where
self.addresses.get(p).map_or(Vec::new(), |v| v.clone())
}

fn inject_connected(&mut self, _: &PeerId) {
}

fn inject_disconnected(&mut self, _: &PeerId) {
}

fn inject_event(&mut self, _: PeerId, _: ConnectionId, _: THandler::OutEvent) {
}

fn poll(&mut self, _: &mut Context, _: &mut impl PollParameters) ->
Poll<NetworkBehaviourAction<THandler::InEvent, Self::OutEvent>>
{
Expand Down

0 comments on commit dc690e4

Please sign in to comment.