-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(connection-pool): Keep only fluence peers in the connection pool #1440
Changes from 3 commits
640f13f
41e1f02
ec564dc
7b037ed
44f1cd8
2ceedd5
b63007b
ab19e1c
e4339cc
d6c26c8
b84d0c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ impl Kademlia { | |
} | ||
} | ||
|
||
pub fn add_kad_node(&mut self, peer: PeerId, addresses: Vec<Multiaddr>) { | ||
pub fn add_kad_node(&mut self, peer: PeerId, addresses: &Vec<Multiaddr>) { | ||
for addr in addresses { | ||
self.kademlia.add_address(&peer, addr.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to remove .clone |
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use libp2p::{ | |
core::{multiaddr::Protocol, Multiaddr}, | ||
identify::Event as IdentifyEvent, | ||
}; | ||
use particle_protocol::PROTOCOL_NAME; | ||
|
||
use super::FluenceNetworkBehaviour; | ||
|
||
|
@@ -36,17 +37,42 @@ impl FluenceNetworkBehaviour { | |
info.listen_addrs | ||
); | ||
|
||
let addresses = filter_addresses(info.listen_addrs, allow_local_addresses); | ||
let addresses = filter_addresses(&info.listen_addrs, allow_local_addresses); | ||
|
||
// Add addresses to connection pool disregarding whether it supports kademlia or not | ||
// we want to have full info on non-kademlia peers as well | ||
self.connection_pool | ||
.add_discovered_addresses(peer_id, addresses.clone()); | ||
let mut supports_kademlia = false; | ||
let mut supports_fluence = false; | ||
|
||
let supports_kademlia = | ||
info.protocols.iter().any(|p| p.contains("/ipfs/kad/1.0.0")); | ||
if supports_kademlia { | ||
self.kademlia.add_kad_node(peer_id, addresses); | ||
for protocol in info.protocols.iter() { | ||
if !supports_kademlia && protocol.contains("/ipfs/kad/1.0.0") { | ||
supports_kademlia = true; | ||
} | ||
if !supports_fluence && protocol.contains(PROTOCOL_NAME) { | ||
supports_fluence = true; | ||
} | ||
if supports_fluence && supports_kademlia { | ||
break; | ||
} | ||
} | ||
|
||
if supports_fluence { | ||
log::debug!(target: "network", "Found fluence peer {}: : protocols: {:?} version: {} listen addrs {:?}", peer_id, info.protocols, | ||
folex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
info.protocol_version, | ||
info.listen_addrs); | ||
// Add addresses to connection pool disregarding whether it supports kademlia or not | ||
// we want to have full info on non-kademlia peers as well | ||
self.connection_pool | ||
.add_discovered_addresses(peer_id, &addresses); | ||
if supports_kademlia { | ||
self.kademlia.add_kad_node(peer_id, &addresses); | ||
} | ||
} else { | ||
log::debug!( | ||
folex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target: "protocols", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"Found peer {} not supported fluence protocol, protocols: {:?} version: {} listen addrs {:?}. skipping...", | ||
peer_id, info.protocols, | ||
info.protocol_version, | ||
info.listen_addrs | ||
); | ||
} | ||
} | ||
|
||
|
@@ -61,18 +87,18 @@ impl FluenceNetworkBehaviour { | |
} | ||
} | ||
|
||
fn filter_addresses(addresses: Vec<Multiaddr>, allow_local: bool) -> Vec<Multiaddr> { | ||
fn filter_addresses(addresses: &Vec<Multiaddr>, allow_local: bool) -> Vec<Multiaddr> { | ||
// Deduplicate addresses | ||
let addresses: Vec<_> = addresses.into_iter().unique().collect(); | ||
let addresses = addresses.into_iter().unique(); | ||
|
||
if allow_local { | ||
// Return all addresses | ||
addresses | ||
addresses.cloned().collect() | ||
} else { | ||
// Keep only global addresses | ||
addresses | ||
.into_iter() | ||
.filter(|maddr| !is_local_maddr(maddr)) | ||
.cloned() | ||
.collect() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&[]
? or clippy will complainThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done