Skip to content

Commit

Permalink
feat(kad): make Distance private field public
Browse files Browse the repository at this point in the history
make Distance private field (U256) public

So that some `network density` in Distance can be calculated as below:

```rust
let density = U256::MAX / U256::from(estimated_network_size);
let density_distance = Distance(estimated_distance);
```

Pull-Request: #5705.
  • Loading branch information
maqi authored Dec 3, 2024
1 parent b187c14 commit d0590a7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.46.0", path = "protocols/identify" }
libp2p-identity = { version = "0.2.10" }
libp2p-kad = { version = "0.47.0", path = "protocols/kad" }
libp2p-kad = { version = "0.47.1", path = "protocols/kad" }
libp2p-mdns = { version = "0.46.0", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.3.1", path = "misc/memory-connection-limits" }
libp2p-metrics = { version = "0.15.0", path = "misc/metrics" }
Expand Down
5 changes: 5 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.47.1

- Expose Distance private field U256 to public.
See [PR 5705](https://github.com/libp2p/rust-libp2p/pull/5705).

## 0.47.0

- Expose a kad query facility allowing specify num_results dynamicaly.
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-kad"
edition = "2021"
rust-version = { workspace = true }
description = "Kademlia protocol for libp2p"
version = "0.47.0"
version = "0.47.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
4 changes: 2 additions & 2 deletions protocols/kad/src/kbucket/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::record;

construct_uint! {
/// 256-bit unsigned integer.
pub(super) struct U256(4);
pub struct U256(4);
}

/// A `Key` in the DHT keyspace with preserved preimage.
Expand Down Expand Up @@ -193,7 +193,7 @@ impl AsRef<KeyBytes> for KeyBytes {

/// A distance between two keys in the DHT keyspace.
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Debug)]
pub struct Distance(pub(super) U256);
pub struct Distance(pub U256);

impl Distance {
/// Returns the integer part of the base 2 logarithm of the [`Distance`].
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub use behaviour::{
QueryResult, QueryStats, Quorum, RoutingUpdate, StoreInserts,
};
pub use kbucket::{
Distance as KBucketDistance, EntryView, KBucketRef, Key as KBucketKey, NodeStatus,
Distance as KBucketDistance, EntryView, KBucketRef, Key as KBucketKey, NodeStatus, U256,
};
use libp2p_swarm::StreamProtocol;
pub use protocol::{ConnectionType, KadPeer};
Expand Down

0 comments on commit d0590a7

Please sign in to comment.