-
Notifications
You must be signed in to change notification settings - Fork 19
replace duplicate code with common function #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
replace duplicate code with common function #394
Conversation
src/protocol/mod.rs
Outdated
@@ -141,3 +142,18 @@ pub trait UserProtocol: Send { | |||
/// Start the the user protocol event loop. | |||
async fn run(self: Box<Self>, service: TransportService) -> crate::Result<()>; | |||
} | |||
|
|||
pub fn sort_address(addresses: impl Iterator<Item = Multiaddr>, peer_id: PeerId) -> Vec<Multiaddr> { |
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.
nit: I would name this method ensure_address_with_peer
or similar, since it is not really sorting the input 👍
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.
Yeah, that's a better name. Would use that instead
@@ -188,17 +190,7 @@ impl RoutingTable { | |||
); | |||
|
|||
// TODO: https://github.com/paritytech/litep2p/issues/337 this has to be moved elsewhere at some point |
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.
We could probably remove the TODO here? Or do you think there are more places where this may happen? 🤔
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.
Oh yeah, I forgot to remove that. It's all covered now, no more duplicates
src/protocol/transport_service.rs
Outdated
} | ||
}) | ||
.collect(); | ||
let addresses = ensure_address_with_peer(addresses.into_iter(), *peer); |
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.
There's one tiny issue with this approach: we were previously collecting into a HashSet
, which deduplicates items. Whereas using the Vec by default, we could have duplicates here
Aims to resolve #337
Also fixes clippy warning issues