Integrate identify into peer manager (#1011)

This commit is contained in:
Age Manning
2020-04-17 16:02:14 +10:00
committed by GitHub
parent 6edb4f655c
commit 0b2b379f14
4 changed files with 158 additions and 17 deletions

View File

@@ -7,12 +7,14 @@ use crate::{NetworkGlobals, PeerId};
use futures::prelude::*;
use futures::Stream;
use hashmap_delay::HashSetDelay;
use libp2p::identify::IdentifyInfo;
use slog::{crit, debug, error, warn};
use smallvec::SmallVec;
use std::sync::Arc;
use std::time::{Duration, Instant};
use types::EthSpec;
mod client;
mod peer_info;
mod peerdb;
@@ -242,6 +244,16 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
self.update_reputations();
}
/// Updates `PeerInfo` with `identify` information.
pub fn identify(&mut self, peer_id: &PeerId, info: &IdentifyInfo) {
if let Some(peer_info) = self.network_globals.peers.write().peer_info_mut(peer_id) {
peer_info.client = client::Client::from_identify_info(info);
peer_info.listening_addresses = info.listen_addrs.clone();
} else {
crit!(self.log, "Received an Identify response from an unknown peer"; "peer_id" => format!("{}", peer_id));
}
}
/* Internal functions */
/// Registers a peer as connected. The `ingoing` parameter determines if the peer is being