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 1 commit
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
Prev Previous commit
Improve tracing in peerset
  • Loading branch information
debris committed Apr 4, 2019
commit e920d3b48ffb2d5a020853b220e62c7a20e9b2c5
5 changes: 4 additions & 1 deletion core/network-libp2p/src/custom_proto/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ impl<TMessage, TSubstream> CustomProto<TMessage, TSubstream> {

/// Indicates to the peerset that we have discovered new addresses for a given node.
pub fn add_discovered_nodes<I: IntoIterator<Item = PeerId>>(&mut self, peer_ids: I) {
self.peerset.discovered(peer_ids);
self.peerset.discovered(peer_ids.into_iter().map(|peer_id| {
debug!(target: "sub-libp2p", "PSM <= Discovered({:?})", peer_id);
peer_id
}));
}

/// Returns the state of the peerset manager, for debugging purposes.
Expand Down
17 changes: 14 additions & 3 deletions core/peerset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ impl Peerset {
/// Because of concurrency issues, it is acceptable to call `incoming` with a `PeerId` the
/// peerset is already connected to, in which case it must not answer.
pub fn incoming(&mut self, peer_id: PeerId, index: IncomingIndex) {
trace!("Incoming {}\nin_slots={:?}\nout_slots={:?}", peer_id, self.data.in_slots, self.data.out_slots);
trace!(
target: "peerset",
"Incoming {:?}\nin_slots={:?}\nout_slots={:?}",
peer_id, self.data.in_slots, self.data.out_slots
);
// if `reserved_only` is set, but this peer is not a part of our discovered list,
// a) it is not reserved, so we reject the connection
// b) we are already connected to it, so we reject the connection
Expand Down Expand Up @@ -417,7 +421,11 @@ impl Peerset {
/// Must only be called after the PSM has either generated a `Connect` message with this
/// `PeerId`, or accepted an incoming connection with this `PeerId`.
pub fn dropped(&mut self, peer_id: PeerId) {
trace!("Dropping {}\nin_slots={:?}\nout_slots={:?}", peer_id, self.data.in_slots, self.data.out_slots);
trace!(
target: "peerset",
"Dropping {:?}\nin_slots={:?}\nout_slots={:?}",
peer_id, self.data.in_slots, self.data.out_slots
);
// Automatically connect back if reserved.
if self.data.in_slots.is_connected_and_reserved(&peer_id) || self.data.out_slots.is_connected_and_reserved(&peer_id) {
self.message_queue.push_back(Message::Connect(peer_id));
Expand All @@ -440,8 +448,11 @@ impl Peerset {
/// > of the PSM to remove `PeerId`s that fail to dial too often.
pub fn discovered<I: IntoIterator<Item = PeerId>>(&mut self, peer_ids: I) {
for peer_id in peer_ids {
if !self.data.in_slots.contains(&peer_id) && !self.data.out_slots.contains(&peer_id) {
if !self.data.in_slots.contains(&peer_id) && !self.data.out_slots.contains(&peer_id) && !self.data.discovered.contains(&peer_id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this additional check in data.discovered, so we can print peer_id without cloning it

trace!(target: "peerset", "Discovered new peer: {:?}", peer_id);
self.data.discovered.add_peer(peer_id, SlotType::Common);
} else {
trace!(target: "peerset", "Discovered known peer: {:?}", peer_id);
}
}

Expand Down