Skip to content

Conversation

seun-ja
Copy link

@seun-ja seun-ja commented May 16, 2025

Aims to resolve #337

Also fixes clippy warning issues

@@ -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> {
Copy link
Collaborator

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 👍

Copy link
Author

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
Copy link
Collaborator

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? 🤔

Copy link
Author

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

}
})
.collect();
let addresses = ensure_address_with_peer(addresses.into_iter(), *peer);
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

address: Create common functionality to remove code duplicate
2 participants