From 9d68a93a3cdd58f1ea28ffa0f43d5bc2ad1bfbcc Mon Sep 17 00:00:00 2001 From: cong-or Date: Tue, 9 Dec 2025 21:14:11 +0000 Subject: [PATCH 1/6] feat(rust/hermes-ipfs): Add with_keypair method for persistent keypair support This adds a method to that allows creating an IPFS node builder with an existing keypair instead of generating a new one. This enables stable peer IDs across restarts when keypairs are loaded from disk. The method wraps and follows the same --- rust/hermes-ipfs/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 2a5cb6fb47..3b95efa7a5 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -58,6 +58,18 @@ where N: NetworkBehaviour + Send + Sync Self(IpfsBuilder::new()) } + #[must_use] + /// Create a new `IpfsBuilder` with an existing keypair. + /// + /// ## Parameters + /// - `keypair`: An existing keypair (can be libp2p::identity::Keypair or compatible type) + /// + /// ## Errors + /// Returns an error if the keypair is invalid. + pub fn with_keypair(keypair: impl connexa::builder::IntoKeypair) -> std::io::Result { + Ok(Self(IpfsBuilder::with_keypair(keypair)?)) + } + #[must_use] /// Set the default configuration for the IPFS node. pub fn with_default(self) -> Self { From bcdb2a9b017c9aa91c79660274c04d92b8cda1bc Mon Sep 17 00:00:00 2001 From: cong-or Date: Tue, 9 Dec 2025 23:27:32 +0000 Subject: [PATCH 2/6] feat(hermes-ipfs): Add small mesh configuration for testing environments Add method to HermesIpfsBuilder that configures Gossipsub with mesh parameters suitable for 2-3 node test networks: - mesh_n_low: 1 (minimum peers) - mesh_n: 2 (target peers) - mesh_n_high: 3 (maximum peers) - mesh_outbound_min: 1 Default Gossipsub configuration expects mesh_n=6 peers, which doesn't work in small test environments. This method provides an alternative to for testing scenarios. Use via environment variable HERMES_P2P_TEST_MODE=true to enable small mesh configuration automatically. --- rust/hermes-ipfs/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 3b95efa7a5..abdb63dfe9 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -34,6 +34,7 @@ use rust_ipfs::{ GossipsubMessage, NetworkBehaviour, Quorum, ToRecordKey, builder::IpfsBuilder, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, unixfs::AddOpt, }; +use libp2p::gossipsub::Config as GossipsubConfig; #[derive(Debug, Display, From, Into)] /// `PubSub` Message ID. @@ -76,6 +77,25 @@ where N: NetworkBehaviour + Send + Sync Self(self.0.with_default()) } + #[must_use] + /// Set configuration with small Gossipsub mesh for testing (2-3 node environments). + /// + /// This configures Gossipsub with mesh parameters suitable for small test networks: + /// - mesh_n_low: 1 (minimum peers) + /// - mesh_n: 2 (target peers) + /// - mesh_n_high: 3 (maximum peers) + /// + /// Use this instead of `with_default()` in test environments with few nodes. + pub fn with_small_mesh_config(self) -> Self { + let config = GossipsubConfig::default() + .mesh_n_low(1) + .mesh_n(2) + .mesh_n_high(3) + .mesh_outbound_min(1); + + Self(self.0.with_default().set_gossipsub_config(config)) + } + #[must_use] /// Set the default listener for the IPFS node. pub fn set_default_listener(self) -> Self { From 79d70853b52d8d4cb4e910178670b9420cc91220 Mon Sep 17 00:00:00 2001 From: cong-or Date: Tue, 9 Dec 2025 23:36:02 +0000 Subject: [PATCH 3/6] fix(hermes-ipfs): Use correct GossipsubConfigBuilder API for small mesh config --- rust/hermes-ipfs/src/lib.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index abdb63dfe9..a34dc59d58 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -34,7 +34,6 @@ use rust_ipfs::{ GossipsubMessage, NetworkBehaviour, Quorum, ToRecordKey, builder::IpfsBuilder, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, unixfs::AddOpt, }; -use libp2p::gossipsub::Config as GossipsubConfig; #[derive(Debug, Display, From, Into)] /// `PubSub` Message ID. @@ -84,16 +83,24 @@ where N: NetworkBehaviour + Send + Sync /// - mesh_n_low: 1 (minimum peers) /// - mesh_n: 2 (target peers) /// - mesh_n_high: 3 (maximum peers) + /// - mesh_outbound_min: 1 /// /// Use this instead of `with_default()` in test environments with few nodes. pub fn with_small_mesh_config(self) -> Self { - let config = GossipsubConfig::default() - .mesh_n_low(1) - .mesh_n(2) - .mesh_n_high(3) - .mesh_outbound_min(1); + use connexa::builder::Builder; - Self(self.0.with_default().set_gossipsub_config(config)) + Self( + self.0 + .with_default_behaviour() + .with_gossipsub_with_config(|keypair, mut config| { + config + .mesh_n_low(1) + .mesh_n(2) + .mesh_n_high(3) + .mesh_outbound_min(1); + (config, libp2p::gossipsub::MessageAuthenticity::Signed(keypair.clone())) + }) + ) } #[must_use] From 5acad4fe7cf775e737b7ae86231aa01c1b128934 Mon Sep 17 00:00:00 2001 From: cong-or Date: Tue, 9 Dec 2025 23:46:57 +0000 Subject: [PATCH 4/6] revert: Remove small mesh config (requires rust-ipfs modifications) --- rust/hermes-ipfs/src/lib.rs | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index a34dc59d58..3b95efa7a5 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -76,33 +76,6 @@ where N: NetworkBehaviour + Send + Sync Self(self.0.with_default()) } - #[must_use] - /// Set configuration with small Gossipsub mesh for testing (2-3 node environments). - /// - /// This configures Gossipsub with mesh parameters suitable for small test networks: - /// - mesh_n_low: 1 (minimum peers) - /// - mesh_n: 2 (target peers) - /// - mesh_n_high: 3 (maximum peers) - /// - mesh_outbound_min: 1 - /// - /// Use this instead of `with_default()` in test environments with few nodes. - pub fn with_small_mesh_config(self) -> Self { - use connexa::builder::Builder; - - Self( - self.0 - .with_default_behaviour() - .with_gossipsub_with_config(|keypair, mut config| { - config - .mesh_n_low(1) - .mesh_n(2) - .mesh_n_high(3) - .mesh_outbound_min(1); - (config, libp2p::gossipsub::MessageAuthenticity::Signed(keypair.clone())) - }) - ) - } - #[must_use] /// Set the default listener for the IPFS node. pub fn set_default_listener(self) -> Self { From aa5005687da406ad474eabd89b6fbb05b98ed645 Mon Sep 17 00:00:00 2001 From: cong-or Date: Wed, 10 Dec 2025 00:33:40 +0000 Subject: [PATCH 5/6] fmt --- rust/hermes-ipfs/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 3b95efa7a5..1937738b3c 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -62,7 +62,8 @@ where N: NetworkBehaviour + Send + Sync /// Create a new `IpfsBuilder` with an existing keypair. /// /// ## Parameters - /// - `keypair`: An existing keypair (can be libp2p::identity::Keypair or compatible type) + /// - `keypair`: An existing keypair (can be libp2p::identity::Keypair or compatible + /// type) /// /// ## Errors /// Returns an error if the keypair is invalid. From 5e5aa04e9f3406aef861be4483176332fadaf201 Mon Sep 17 00:00:00 2001 From: cong-or Date: Wed, 10 Dec 2025 00:48:32 +0000 Subject: [PATCH 6/6] fmt --- rust/hermes-ipfs/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 1937738b3c..68f4b69e1a 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -58,11 +58,10 @@ where N: NetworkBehaviour + Send + Sync Self(IpfsBuilder::new()) } - #[must_use] /// Create a new `IpfsBuilder` with an existing keypair. /// /// ## Parameters - /// - `keypair`: An existing keypair (can be libp2p::identity::Keypair or compatible + /// - `keypair`: An existing keypair (can be `libp2p::identity::Keypair` or compatible /// type) /// /// ## Errors