Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions client/network/src/peer_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ pub struct Node<'a>(&'a NodeInfo);

impl<'a> Node<'a> {
/// Returns the endpoint of an established connection to the peer.
pub fn endpoint(&self) -> &'a ConnectedPoint {
&self.0.endpoints[0] // `endpoints` are non-empty by definition
///
/// Returns `None` if we are disconnected from the node.
pub fn endpoint(&self) -> Option<&'a ConnectedPoint> {
self.0.endpoints.get(0)
}

/// Returns the latest version information we know of.
pub fn client_version(&self) -> Option<&'a str> {
self.0.client_version.as_ref().map(|s| &s[..])
self.0.client_version.as_deref()
}

/// Returns the latest ping time we know of for this node. `None` if we never successfully
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let known_addresses = NetworkBehaviour::addresses_of_peer(swarm.behaviour_mut(), peer_id)
.into_iter().collect();

let endpoint = if let Some(e) = swarm.behaviour_mut().node(peer_id).map(|i| i.endpoint()) {
let endpoint = if let Some(e) = swarm.behaviour_mut().node(peer_id).map(|i| i.endpoint()).flatten() {
e.clone().into()
} else {
error!(target: "sub-libp2p", "Found state inconsistency between custom protocol \
Expand Down