Skip to content
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

make kad::kbucket::Distance public again? #4108

Closed
joshuef opened this issue Jun 24, 2023 · 12 comments · Fixed by #4109
Closed

make kad::kbucket::Distance public again? #4108

joshuef opened this issue Jun 24, 2023 · 12 comments · Fixed by #4109

Comments

@joshuef
Copy link
Contributor

joshuef commented Jun 24, 2023

We rely on the public kbucket::Key and use the .distance() in some functionality.

https://github.com/maidsafe/safe_network/blob/main/sn_protocol/src/lib.rs#L113C1-L116C6

I was have a look at upgrading but as of 0.52 Distance is no longer exposed. #4103

Is there a blocker to reenabling that as a pub API?

@joshuef joshuef changed the title kad::kbucket::Distance should be public make kad::kbucket::Distance public again? Jun 24, 2023
@mxinden
Copy link
Member

mxinden commented Jun 26, 2023

Sorry for the trouble. No objections from my end. Mind creating a pull request?

@joshuef
Copy link
Contributor Author

joshuef commented Jun 26, 2023

Perfect, will do!

@jsantell
Copy link
Contributor

Similarly, there are a few interfaces no longer exposed in 0.52.0 in KBucketRef (Distance, and EntryRefView specifically). Ran into this in our periodic peer dialer; should these KBucketRef interfaces be exposed, or perhaps is there a better way of handling?

  fn dial_next_peer(&mut self) {
        let mut to_dial = None;
        for kbucket in self.swarm.behaviour_mut().kad.kbuckets() {
            if let Some(range) = self.kad_last_range {
                if kbucket.range() == range {
                    continue;
                }
            }

            // find the first disconnected node
            for entry in kbucket.iter() {
                if entry.status == NodeStatus::Disconnected {
                    let peer_id = entry.node.key.preimage();

                    let dial_opts = DialOpts::peer_id(*peer_id)
                        .condition(PeerCondition::Disconnected)
                        .addresses(entry.node.value.clone().into_vec())
                        .extend_addresses_through_behaviour()
                        .build();
                    to_dial = Some((dial_opts, kbucket.range()));
                    break;
                }
            }
        }

        if let Some((dial_opts, range)) = to_dial {
            if let Err(e) = self.swarm.dial(dial_opts) {
                warn!("failed to dial: {:?}", e);
            }
            self.kad_last_range = Some(range);
        }
    }

@mxinden
Copy link
Member

mxinden commented Jun 27, 2023

@jsantell not opposed to exposing them, though in your above example, given that you don't reference the concrete types, do you actually need them exposed?

@mergify mergify bot closed this as completed in #4109 Jun 27, 2023
mergify bot pushed a commit that referenced this issue Jun 27, 2023
Adds back in Distance as a public type. Follows `KBucketKey` naming for clarity.

Resolves #4108.

Pull-Request: #4109.


  
Co-Authored-By: Josh Wilson <[email protected]>
  

  
Co-Authored-By: Max Inden <[email protected]>
@thomaseizinger
Copy link
Contributor

I was have a look at upgrading but as of 0.52 Distance is no longer exposed. #4103

Are you currently running 0.51.3? I am asking because we didn't just remove these types but had deprecation warnings on them before that they might/will be private soon. Our thinking was that people hopefully speak up before we make them private to avoid situations like this :)

But perhaps that didn't work? Are you currently seeing those deprecation warnings?

@cdata
Copy link

cdata commented Jun 27, 2023

I am asking because we didn't just remove these types but had deprecation warnings on them before that they might/will be private soon

Just chiming in to mention that we did not see deprecation warnings. The reason is probably because the libp2p_kad implementation was marked as deprecated but we used it via libp2p and it appears that the warnings were silenced during cargo build.

@jsantell
Copy link
Contributor

@jsantell not opposed to exposing them, though in your above example, given that you don't reference the concrete types, do you actually need them exposed?

In this snippet, we check the status of the KBucketRef and compare to NodeStatus and the Distance is stored in self.kad_last_range, though those are the only references. This logic mostly inspired by beetle/iroh, maybe there are better ways (using public interfaces) for a similar result?

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Jun 27, 2023

I am asking because we didn't just remove these types but had deprecation warnings on them before that they might/will be private soon

Just chiming in to mention that we did not see deprecation warnings. The reason is probably because the libp2p_kad implementation was marked as deprecated but we used it via libp2p and it appears that the warnings were silenced during cargo build.

Interesting, I just checked out your repo and I can see a deprecation warning in my IDE:

image

Yet, cargo check does not surface it. I'll investigate.

@thomaseizinger
Copy link
Contributor

This almost seems like a rustc bug to me. Even with double --verbose, the deprecation warning is not visible. Note that double --verbose does show warnings in other crates which tells me that this warning isn't silenced, it is simply never emitted.

@cdata
Copy link

cdata commented Jun 27, 2023

tells me that this warning isn't silenced, it is simply never emitted.

Sorry, yes, I am conflating my language here a bit. But, you're right, we don't even see the warning with -vv (though we do see some others). Possibly a rustc bug? 🤷

@thomaseizinger
Copy link
Contributor

Possibly a rustc bug? shrug

I think so yes although a quick search didn't reveal anything.

cc @mxinden It seems that most of our efforts around deprecating modules so far was not very successful.

@mxinden
Copy link
Member

mxinden commented Jul 10, 2023

nathanielc added a commit to nathanielc/rust-libp2p that referenced this issue Oct 13, 2023
The EntryView struct exposes the node status however its type is not public making it impossible to
use the status field.

This change re-exports NodeStatus according to the existing naming pattern.
See libp2p#4108 which was fixed however the NodeStatus type
was not exposed.
nathanielc added a commit to nathanielc/rust-libp2p that referenced this issue Oct 13, 2023
The EntryView struct exposes the node status however its type is not public making it impossible to
use the status field.

This change re-exports NodeStatus according to the existing naming pattern.
See libp2p#4108 which was fixed however the NodeStatus type
was not exposed.
nathanielc added a commit to nathanielc/rust-libp2p that referenced this issue Oct 16, 2023
The EntryView struct exposes the node status however its type is not public making it impossible to
use the status field.

This change re-exports NodeStatus according to the existing naming pattern.
See libp2p#4108 which was fixed however the NodeStatus type
was not exposed.
mergify bot pushed a commit that referenced this issue Oct 16, 2023
The `EntryView` struct exposes the node status however its type is not public making it impossible to use the status field. This change re-exports `NodeStatus`.

Related: #4108.

Pull-Request: #4645.
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 a pull request may close this issue.

5 participants