From 858a4cd954bf52be108ebc63bbb00b52964770dd Mon Sep 17 00:00:00 2001 From: Krishang Shah <93703995+kamuik16@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:52:32 +0530 Subject: [PATCH] chore: identify::Config fields private (#5663) ## Description Closes #5660 ## Change checklist - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [x] 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 --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/identify/CHANGELOG.md | 5 +++ protocols/identify/Cargo.toml | 2 +- protocols/identify/src/behaviour.rs | 49 ++++++++++++++++++++++++----- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a6278717f1..e5e41d3bdf8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2778,7 +2778,7 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.45.1" +version = "0.46.0" dependencies = [ "async-std", "asynchronous-codec", diff --git a/Cargo.toml b/Cargo.toml index 780d26240db..aab7f0d71d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ libp2p-dcutr = { version = "0.12.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.42.0", path = "transports/dns" } libp2p-floodsub = { version = "0.45.0", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" } -libp2p-identify = { version = "0.45.1", path = "protocols/identify" } +libp2p-identify = { version = "0.46.0", path = "protocols/identify" } libp2p-identity = { version = "0.2.9" } libp2p-kad = { version = "0.47.0", path = "protocols/kad" } libp2p-mdns = { version = "0.46.0", path = "protocols/mdns" } diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index c5778ff92ee..9051c331bbc 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.46.0 + +- Make `identify::Config` fields private and add getter functions. + See [PR 5663](https://github.com/libp2p/rust-libp2p/pull/5663). + ## 0.45.1 - Add `hide_listen_addrs` option to prevent leaking (local) listen addresses. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index c3fb585c99c..13c43b6a71f 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-identify" edition = "2021" rust-version = { workspace = true } description = "Nodes identification protocol for libp2p" -version = "0.45.1" +version = "0.46.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index c8672674c1a..1f82cd154e3 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -117,20 +117,20 @@ pub struct Behaviour { pub struct Config { /// Application-specific version of the protocol family used by the peer, /// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`. - pub protocol_version: String, + protocol_version: String, /// The public key of the local node. To report on the wire. - pub local_public_key: PublicKey, + local_public_key: PublicKey, /// Name and version of the local peer implementation, similar to the /// `User-Agent` header in the HTTP protocol. /// /// Defaults to `rust-libp2p/`. - pub agent_version: String, + agent_version: String, /// The interval at which identification requests are sent to /// the remote on established connections after the first request, /// i.e. the delay between identification requests. /// /// Defaults to 5 minutes. - pub interval: Duration, + interval: Duration, /// Whether new or expired listen addresses of the local node should /// trigger an active push of an identify message to all connected peers. @@ -140,19 +140,19 @@ pub struct Config { /// i.e. before the next periodic identify request with each peer. /// /// Disabled by default. - pub push_listen_addr_updates: bool, + push_listen_addr_updates: bool, /// How many entries of discovered peers to keep before we discard /// the least-recently used one. /// /// Disabled by default. - pub cache_size: usize, + cache_size: usize, /// Whether to include our listen addresses in our responses. If enabled, /// we will effectively only share our external addresses. /// /// Disabled by default. - pub hide_listen_addrs: bool, + hide_listen_addrs: bool, } impl Config { @@ -202,6 +202,41 @@ impl Config { self.hide_listen_addrs = b; self } + + /// Get the protocol version of the Config. + pub fn protocol_version(&self) -> &str { + &self.protocol_version + } + + /// Get the local public key of the Config. + pub fn local_public_key(&self) -> &PublicKey { + &self.local_public_key + } + + /// Get the agent version of the Config. + pub fn agent_version(&self) -> &str { + &self.agent_version + } + + /// Get the interval of the Config. + pub fn interval(&self) -> Duration { + self.interval + } + + /// Get the push listen address updates boolean value of the Config. + pub fn push_listen_addr_updates(&self) -> bool { + self.push_listen_addr_updates + } + + /// Get the cache size of the Config. + pub fn cache_size(&self) -> usize { + self.cache_size + } + + /// Get the hide listen address boolean value of the Config. + pub fn hide_listen_addrs(&self) -> bool { + self.hide_listen_addrs + } } impl Behaviour {