client/network: Rename DebugInfoBehaviour to PeerInfoBehaviour (#6556)

Information retrieved via `DebugInfoBehaviour` is not only used for
debugging purposes, e.g. disconnecting from nodes not responding to
pings, using external addresses retrieved via indentify, ...

In order for the name to reflect the usage of the module this commit
renames it.
This commit is contained in:
Max Inden
2020-07-08 11:08:47 +02:00
committed by GitHub
parent ce0b55ff09
commit 62f306d972
3 changed files with 21 additions and 22 deletions
+10 -10
View File
@@ -16,7 +16,7 @@
use crate::{
config::{ProtocolId, Role}, block_requests, light_client_handler, finality_requests,
debug_info, discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
peer_info, discovery::{DiscoveryBehaviour, DiscoveryConfig, DiscoveryOut},
protocol::{message::{self, Roles}, CustomMessageOutcome, Protocol},
Event, ObservedRole, DhtEvent, ExHashT,
};
@@ -39,7 +39,7 @@ pub struct Behaviour<B: BlockT, H: ExHashT> {
substrate: Protocol<B, H>,
/// Periodically pings and identifies the nodes we are connected to, and store information in a
/// cache.
debug_info: debug_info::DebugInfoBehaviour,
peer_info: peer_info::PeerInfoBehaviour,
/// Discovers nodes of the network.
discovery: DiscoveryBehaviour,
/// Block request handling.
@@ -113,7 +113,7 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
) -> Self {
Behaviour {
substrate,
debug_info: debug_info::DebugInfoBehaviour::new(user_agent, local_public_key),
peer_info: peer_info::PeerInfoBehaviour::new(user_agent, local_public_key),
discovery: disco_config.finish(),
block_requests,
finality_proof_requests,
@@ -153,8 +153,8 @@ impl<B: BlockT, H: ExHashT> Behaviour<B, H> {
/// Returns `None` if we don't know anything about this node. Always returns `Some` for nodes
/// we're connected to, meaning that if `None` is returned then we're not connected to that
/// node.
pub fn node(&self, peer_id: &PeerId) -> Option<debug_info::Node> {
self.debug_info.node(peer_id)
pub fn node(&self, peer_id: &PeerId) -> Option<peer_info::Node> {
self.peer_info.node(peer_id)
}
/// Registers a new notifications protocol.
@@ -355,10 +355,10 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<finality_requests::Even
}
}
impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<debug_info::DebugInfoEvent>
impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<peer_info::PeerInfoEvent>
for Behaviour<B, H> {
fn inject_event(&mut self, event: debug_info::DebugInfoEvent) {
let debug_info::DebugInfoEvent::Identified { peer_id, mut info } = event;
fn inject_event(&mut self, event: peer_info::PeerInfoEvent) {
let peer_info::PeerInfoEvent::Identified { peer_id, mut info } = event;
if info.listen_addrs.len() > 30 {
debug!(target: "sub-libp2p", "Node {:?} has reported more than 30 addresses; \
it is identified by {:?} and {:?}", peer_id, info.protocol_version,
@@ -380,8 +380,8 @@ impl<B: BlockT, H: ExHashT> NetworkBehaviourEventProcess<DiscoveryOut>
DiscoveryOut::UnroutablePeer(_peer_id) => {
// Obtaining and reporting listen addresses for unroutable peers back
// to Kademlia is handled by the `Identify` protocol, part of the
// `DebugInfoBehaviour`. See the `NetworkBehaviourEventProcess`
// implementation for `DebugInfoEvent`.
// `PeerInfoBehaviour`. See the `NetworkBehaviourEventProcess`
// implementation for `PeerInfoEvent`.
}
DiscoveryOut::Discovered(peer_id) => {
self.substrate.add_discovered_nodes(iter::once(peer_id));
+1 -1
View File
@@ -245,7 +245,7 @@
mod behaviour;
mod block_requests;
mod chain;
mod debug_info;
mod peer_info;
mod discovery;
mod finality_requests;
mod light_client_handler;
@@ -38,9 +38,8 @@ const CACHE_EXPIRE: Duration = Duration::from_secs(10 * 60);
/// Interval at which we perform garbage collection on the node info.
const GARBAGE_COLLECT_INTERVAL: Duration = Duration::from_secs(2 * 60);
/// Implementation of `NetworkBehaviour` that holds information about nodes in cache for diagnostic
/// purposes.
pub struct DebugInfoBehaviour {
/// Implementation of `NetworkBehaviour` that holds information about peers in cache.
pub struct PeerInfoBehaviour {
/// Periodically ping nodes, and close the connection if it's unresponsive.
ping: Ping,
/// Periodically identifies the remote and responds to incoming requests.
@@ -78,8 +77,8 @@ impl NodeInfo {
}
}
impl DebugInfoBehaviour {
/// Builds a new `DebugInfoBehaviour`.
impl PeerInfoBehaviour {
/// Builds a new `PeerInfoBehaviour`.
pub fn new(
user_agent: String,
local_public_key: PublicKey,
@@ -89,7 +88,7 @@ impl DebugInfoBehaviour {
Identify::new(proto_version, user_agent, local_public_key)
};
DebugInfoBehaviour {
PeerInfoBehaviour {
ping: Ping::new(PingConfig::new()),
identify,
nodes_info: FnvHashMap::default(),
@@ -154,8 +153,8 @@ impl<'a> Node<'a> {
/// Event that can be emitted by the behaviour.
#[derive(Debug)]
pub enum DebugInfoEvent {
/// We have obtained debug information from a peer, including the addresses it is listening
pub enum PeerInfoEvent {
/// We have obtained identity information from a peer, including the addresses it is listening
/// on.
Identified {
/// Id of the peer that has been identified.
@@ -165,12 +164,12 @@ pub enum DebugInfoEvent {
},
}
impl NetworkBehaviour for DebugInfoBehaviour {
impl NetworkBehaviour for PeerInfoBehaviour {
type ProtocolsHandler = IntoProtocolsHandlerSelect<
<Ping as NetworkBehaviour>::ProtocolsHandler,
<Identify as NetworkBehaviour>::ProtocolsHandler
>;
type OutEvent = DebugInfoEvent;
type OutEvent = PeerInfoEvent;
fn new_handler(&mut self) -> Self::ProtocolsHandler {
IntoProtocolsHandler::select(self.ping.new_handler(), self.identify.new_handler())
@@ -317,7 +316,7 @@ impl NetworkBehaviour for DebugInfoBehaviour {
match event {
IdentifyEvent::Received { peer_id, info, .. } => {
self.handle_identify_report(&peer_id, &info);
let event = DebugInfoEvent::Identified { peer_id, info };
let event = PeerInfoEvent::Identified { peer_id, info };
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
}
IdentifyEvent::Error { peer_id, error } =>