-
Notifications
You must be signed in to change notification settings - Fork 999
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
chore(libp2p): expose Behaviour::connected
and Behaviour::addresses
#4101
Conversation
I am okay with exposing this information but I'd like to do it via a function please and not by making fields public. |
Signed-off-by: ozkanonur <[email protected]>
@@ -922,7 +933,8 @@ where | |||
const EMPTY_QUEUE_SHRINK_THRESHOLD: usize = 100; | |||
|
|||
/// Internal information tracked for an established connection. | |||
struct Connection { | |||
#[derive(Clone)] | |||
pub struct Connection { |
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.
This had to be pub
for:
rust-libp2p/protocols/request-response/src/lib.rs
Lines 355 to 359 in 9c75886
/// The currently connected peers, their pending outbound and inbound responses and their known, | |
/// reachable addresses, if any. | |
pub fn connected(&self) -> HashMap<PeerId, SmallVec<[Connection; 2]>> { | |
self.connected.clone() | |
} |
Because of the existing similar implementations, I decided to |
Thinking about it, I'd say it would be better to create a new That keeps the API of others small. Other implementations have a Design-sketch:
Alternatively, we could add a primitive such as What exactly is your usecase? |
Note that the API of As such, I wouldn't rely on it in your code. |
We need to find addresses associated with a given peer(e.g. https://github.com/KomodoPlatform/atomicDEX-API/blob/1d8bebd150785123168e770b33e87fac236f0949/mm2src/mm2_libp2p/src/peers_exchange.rs#L110-L126) in our p2p implementation. The layer was built on top of our fork, now I am migrating/refactoring the p2p layer of our project and this PR is kind a blocker for us(just like #3973).
Not all implementations of PS: It seems that we are not the only ones facing this problem. The reason I proposed this PR was due to a discussion I came across at #3254 (comment). |
The issue is that we are adding a public API here and removing that is a breaking change later. It might be simple in implementation but it is still a commitment to our users. Once it is released, people will start using it. The quickest solution is for you to write yourself a Similarly to https://github.com/libp2p/rust-libp2p/blob/master/misc/allow-block-list/src/lib.rs, you can use Does that work for you? |
I opened an issue here: #4103 |
Right. I see the point, thanks for clarification.
Yeah, we can do it that way too. I keep this PR as a draft until then. |
It appears that Connection and it's fields need to be accessible in order for us to implement things like For instance, have a look at rust-libp2p/protocols/request-response/src/lib.rs Lines 611 to 638 in 85a846a
|
Even if we create |
I don't really understand why you need the You can just implement rust-libp2p/swarm/src/behaviour.rs Line 194 in 85a846a
See https://github.com/libp2p/rust-libp2p/blob/master/misc/allow-block-list/src/lib.rs for a really simple implementation (but with a different goal). |
To include
That's what I am already doing |
Yeah, just duplicate what is necessary :) We try to avoid dependencies between top-level crates like this. It is "bad enough" that every crate depends on |
I'd prefer it to return a reference, so I can decide whether to clone or not, on the call site. |
This PR will be refactored almost completely(to implement |
Could you explain the motive behind exposing |
Closing this in favor of #4103. |
Description
This pull request aims to meet the need of
addresses_of_peer
function which was removed from the codebase. By exposing these fields, developers will be able to create their own abstracted layers without the need for direct implementation in the libp2p tree.Notes
see #3254 (comment)