Don't add useless peers to table

This commit is contained in:
arkpar 2016-02-17 14:06:19 +01:00
parent e4baf37bf8
commit eef193e8bd

View File

@ -361,24 +361,21 @@ impl Discovery {
debug!(target: "discovery", "Expired ping"); debug!(target: "discovery", "Expired ping");
return Err(NetworkError::Expired); return Err(NetworkError::Expired);
} }
let mut entry = NodeEntry { id: node.clone(), endpoint: source.clone() }; let mut added_map = HashMap::new();
if !entry.endpoint.is_valid() { let entry = NodeEntry { id: node.clone(), endpoint: source.clone() };
debug!(target: "discovery", "Got bad address: {:?}, using {:?} instead", entry, from); if !entry.endpoint.is_valid() || !entry.endpoint.is_global() {
entry.endpoint.address = from.clone(); debug!(target: "discovery", "Got bad address: {:?}", entry);
}
if !entry.endpoint.is_global() {
debug!(target: "discovery", "Got local address: {:?}, using {:?} instead", entry, from);
entry.endpoint.address = from.clone();
} }
else {
self.update_node(entry.clone()); self.update_node(entry.clone());
added_map.insert(node.clone(), entry);
}
let hash = rlp.as_raw().sha3(); let hash = rlp.as_raw().sha3();
let mut response = RlpStream::new_list(2); let mut response = RlpStream::new_list(2);
dest.to_rlp_list(&mut response); dest.to_rlp_list(&mut response);
response.append(&hash); response.append(&hash);
self.send_packet(PACKET_PONG, &entry.endpoint.udp_address(), &response.drain()); self.send_packet(PACKET_PONG, from, &response.drain());
let mut added_map = HashMap::new();
added_map.insert(node.clone(), entry);
Ok(Some(TableUpdates { added: added_map, removed: HashSet::new() })) Ok(Some(TableUpdates { added: added_map, removed: HashSet::new() }))
} }