This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Peerset::discovered accepts many peer ids #2213
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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)); | ||
|
|
@@ -434,16 +442,20 @@ impl Peerset { | |
| self.alloc_slots(); | ||
| } | ||
|
|
||
| /// Adds a discovered peer id to the PSM. | ||
| /// Adds discovered peer ids to the PSM. | ||
| /// | ||
| /// > **Note**: There is no equivalent "expired" message, meaning that it is the responsibility | ||
| /// > of the PSM to remove `PeerId`s that fail to dial too often. | ||
| pub fn discovered(&mut self, peer_id: PeerId) { | ||
| if self.data.in_slots.contains(&peer_id) || self.data.out_slots.contains(&peer_id) { | ||
| return; | ||
| 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) && !self.data.discovered.contains(&peer_id) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this additional check in |
||
| 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); | ||
| } | ||
| } | ||
|
|
||
| self.data.discovered.add_peer(peer_id, SlotType::Common); | ||
| self.alloc_slots(); | ||
| } | ||
|
|
||
|
|
@@ -721,9 +733,9 @@ mod tests { | |
| }; | ||
|
|
||
| let (mut peerset, _handle) = Peerset::from_config(config); | ||
| peerset.discovered(discovered.clone()); | ||
| peerset.discovered(discovered.clone()); | ||
| peerset.discovered(discovered2); | ||
| peerset.discovered(Some(discovered.clone())); | ||
| peerset.discovered(Some(discovered.clone())); | ||
| peerset.discovered(Some(discovered2)); | ||
|
|
||
| assert_messages(peerset, vec![ | ||
| Message::Connect(bootnode), | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what to do about this
debug!. I could move print it inPeerset::discoveredif neededThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to have the logging both in
sub-libp2pand in the peerset.I guess we could have a custom iterator that does the same as
Iterator::mapbut also implementsDropand prints the elements that are ignored?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for suggestion. I realised that we can just print all items inside
.mapcombinator. I fixed it in the latest commit