Skip to content

Commit

Permalink
feat(kad): add mode getter on Behaviour (#5573)
Browse files Browse the repository at this point in the history
## Description

Small PR adding a getter for the `mode` attribute of the
`kad::Behaviour` in order to get the mode that the DHT is operating in,
at the moment.

In our project, we needed to expose an API endpoint which included the
mode that the DHT was operating. Having a getter was necessary so we are
upstreaming this change.

## Notes & open questions

<!--
Any notes, remarks or open questions you have to make about the PR which
don't need to go into the final commit message.
-->

## Change checklist

<!-- Please add a Changelog entry in the appropriate crates and bump the
crate versions if needed. See
<https://github.com/libp2p/rust-libp2p/blob/master/docs/release.md#development-between-releases>-->

- [x] I have performed a self-review of my own code
- [x] I have made corresponding changes to the documentation
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] A changelog entry has been made in the appropriate crates
  • Loading branch information
stormshield-frb authored Aug 29, 2024
1 parent e63975d commit cefd22b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- Expose a kad query facility allowing specify num_results dynamicly.
See [PR 5555](https://github.com/libp2p/rust-libp2p/pull/5555).
- Add `mode` getter on `Behaviour`.
See [PR 5573](https://github.com/libp2p/rust-libp2p/pull/5573).


## 0.46.2

Expand Down
5 changes: 5 additions & 0 deletions protocols/kad/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,11 @@ where
}
}

/// Get the [`Mode`] in which the DHT is currently operating.
pub fn mode(&self) -> Mode {
self.mode
}

fn reconfigure_mode(&mut self) {
if self.connections.is_empty() {
return;
Expand Down

0 comments on commit cefd22b

Please sign in to comment.