ask for peers with PEER_LIST capability when asking for more peers (#1969)

do not simply look for peers with the same capabilities we have
This commit is contained in:
Antioch Peverell 2018-11-13 10:59:33 +00:00 committed by GitHub
parent c631b45ab6
commit 236fe56f60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -395,7 +395,7 @@ impl Peer {
} }
pub fn send_peer_request(&self, capab: Capabilities) -> Result<(), Error> { pub fn send_peer_request(&self, capab: Capabilities) -> Result<(), Error> {
trace!("Asking {} for more peers.", self.info.addr); trace!("Asking {} for more peers {:?}", self.info.addr, capab);
self.connection.as_ref().unwrap().lock().send( self.connection.as_ref().unwrap().lock().send(
&GetPeerAddrs { &GetPeerAddrs {
capabilities: capab, capabilities: capab,

View file

@ -89,7 +89,6 @@ pub fn connect_and_monitor(
monitor_peers( monitor_peers(
peers.clone(), peers.clone(),
p2p_server.config.clone(), p2p_server.config.clone(),
capabilities,
tx.clone(), tx.clone(),
preferred_peers.clone(), preferred_peers.clone(),
); );
@ -116,7 +115,6 @@ pub fn connect_and_monitor(
fn monitor_peers( fn monitor_peers(
peers: Arc<p2p::Peers>, peers: Arc<p2p::Peers>,
config: p2p::P2PConfig, config: p2p::P2PConfig,
capabilities: p2p::Capabilities,
tx: mpsc::Sender<SocketAddr>, tx: mpsc::Sender<SocketAddr>,
preferred_peers_list: Option<Vec<SocketAddr>>, preferred_peers_list: Option<Vec<SocketAddr>>,
) { ) {
@ -178,7 +176,7 @@ fn monitor_peers(
config.port, config.port,
p.info.addr, p.info.addr,
); );
let _ = p.send_peer_request(capabilities); let _ = p.send_peer_request(p2p::Capabilities::PEER_LIST);
connected_peers.push(p.info.addr) connected_peers.push(p.info.addr)
} }
@ -212,6 +210,7 @@ fn monitor_peers(
p2p::Capabilities::UNKNOWN, p2p::Capabilities::UNKNOWN,
config.peer_max_count() as usize, config.peer_max_count() as usize,
); );
for p in new_peers.iter().filter(|p| !peers.is_known(&p.addr)) { for p in new_peers.iter().filter(|p| !peers.is_known(&p.addr)) {
trace!( trace!(
"monitor_peers: on {}:{}, queue to soon try {}", "monitor_peers: on {}:{}, queue to soon try {}",
@ -249,7 +248,8 @@ fn connect_to_seeds_and_preferred_peers(
peers_preferred_list: Option<Vec<SocketAddr>>, peers_preferred_list: Option<Vec<SocketAddr>>,
) { ) {
// check if we have some peers in db // check if we have some peers in db
let peers = peers.find_peers(p2p::State::Healthy, p2p::Capabilities::FULL_NODE, 100); // look for peers that are able to give us other peers (via PEER_LIST capability)
let peers = peers.find_peers(p2p::State::Healthy, p2p::Capabilities::PEER_LIST, 100);
// if so, get their addresses, otherwise use our seeds // if so, get their addresses, otherwise use our seeds
let mut peer_addrs = if peers.len() > 3 { let mut peer_addrs = if peers.len() > 3 {