From effb5871a600fcd3076987b07954d0f705754261 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Wed, 5 Nov 2025 13:30:03 +0100 Subject: [PATCH 01/13] Bump and stub incompatible functions --- rust/c509-certificate/Cargo.toml | 2 +- rust/hermes-ipfs/Cargo.toml | 6 +- rust/hermes-ipfs/src/lib.rs | 119 ++++++++++++++++--------------- 3 files changed, 66 insertions(+), 61 deletions(-) diff --git a/rust/c509-certificate/Cargo.toml b/rust/c509-certificate/Cargo.toml index 67b96ec2e12..36d649f3898 100644 --- a/rust/c509-certificate/Cargo.toml +++ b/rust/c509-certificate/Cargo.toml @@ -23,7 +23,7 @@ hex = "0.4.3" oid = "0.2.1" oid-registry = "0.7.1" asn1-rs = "0.6.2" -anyhow = "1.0.95" +anyhow = "1.0.99" bimap = "0.6.3" strum = "0.26.3" strum_macros = "0.26.4" diff --git a/rust/hermes-ipfs/Cargo.toml b/rust/hermes-ipfs/Cargo.toml index 106e4c73aa2..44220398902 100644 --- a/rust/hermes-ipfs/Cargo.toml +++ b/rust/hermes-ipfs/Cargo.toml @@ -13,13 +13,15 @@ repository.workspace = true workspace = true [dependencies] -anyhow = "1.0.95" +anyhow = "1.0.100" derive_more = {version = "2.0.1", features = ["from","into","display"] } ipld-core = { version = "0.4.1", features = ["serde"]} # A fork of crates-io version with updated dependencies (`libp2p` and `ring` in particular). # rev-26b99cb as at July 30, 2025 -rust-ipfs = { version = "0.15.0", git = "https://github.com/dariusc93/rust-ipfs", rev = "26b99cb" } +rust-ipfs = { version = "0.15.0", git = "https://github.com/dariusc93/rust-ipfs", rev = "0a6269e05a4ccfaa547a47a56f92171e4abc0564" } tokio = "1.46.0" +futures = "0.3.31" +libp2p = "0.56.0" [dev-dependencies] # Dependencies used by examples diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 442dddc5f23..75bd10cee0b 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -2,17 +2,19 @@ //! //! Provides support for storage, and `PubSub` functionality. +#![allow(unused, dead_code, deprecated)] + use std::str::FromStr; use derive_more::{Display, From, Into}; +use futures::{pin_mut, stream::BoxStream, Stream, StreamExt}; /// IPFS Content Identifier. pub use ipld_core::cid::Cid; /// IPLD pub use ipld_core::ipld::Ipld; +use libp2p::gossipsub::{Message as PubsubMessage, MessageId as PubsubMessageId}; /// `rust_ipfs` re-export. pub use rust_ipfs; -/// libp2p re-exports. -pub use rust_ipfs::libp2p::futures::{pin_mut, stream::BoxStream, FutureExt, StreamExt}; /// Peer Info type. pub use rust_ipfs::p2p::PeerInfo; /// Enum for specifying paths in IPFS. @@ -27,15 +29,9 @@ pub use rust_ipfs::Ipfs; pub use rust_ipfs::Multiaddr; /// Peer ID type. pub use rust_ipfs::PeerId; -/// Stream for `PubSub` Topic Subscriptions. -pub use rust_ipfs::SubscriptionStream; -/// Builder type for IPFS Node configuration. -use rust_ipfs::UninitializedIpfsDefault as UninitializedIpfs; use rust_ipfs::{ - dag::ResolveError, - libp2p::gossipsub::{Message as PubsubMessage, MessageId as PubsubMessageId}, - unixfs::AddOpt, - PubsubEvent, Quorum, + builder::UninitializedIpfs, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, + unixfs::AddOpt, PubsubEvent, Quorum, ToRecordKey, }; #[derive(Debug, Display, From, Into)] @@ -43,7 +39,7 @@ use rust_ipfs::{ pub struct MessageId(pub PubsubMessageId); /// Builder type for IPFS Node configuration. -pub struct IpfsBuilder(UninitializedIpfs); +pub struct IpfsBuilder(UninitializedIpfs); impl IpfsBuilder { #[must_use] @@ -78,25 +74,25 @@ impl IpfsBuilder { ) } - #[must_use] - /// Set the transport configuration for the IPFS node. - pub fn set_transport_configuration( - self, - transport: rust_ipfs::p2p::TransportConfig, - ) -> Self { - Self(self.0.set_transport_configuration(transport)) - } - - #[must_use] - /// Disable TLS for the IPFS node. - pub fn disable_tls(self) -> Self { - let transport = rust_ipfs::p2p::TransportConfig { - enable_quic: false, - enable_secure_websocket: false, - ..Default::default() - }; - Self(self.0.set_transport_configuration(transport)) - } + // #[must_use] + // /// Set the transport configuration for the IPFS node. + // pub fn set_transport_configuration( + // self, + // transport: rust_ipfs::p2p::TransportConfig, + // ) -> Self { + // Self(self.0.set_transport_configuration(transport)) + // } + + // #[must_use] + // /// Disable TLS for the IPFS node. + // pub fn disable_tls(self) -> Self { + // let transport = rust_ipfs::p2p::TransportConfig { + // enable_quic: false, + // enable_secure_websocket: false, + // ..Default::default() + // }; + // Self(self.0.set_transport_configuration(transport)) + // } /// Start the IPFS node. /// @@ -134,7 +130,7 @@ impl HermesIpfs { .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed - .disable_tls() + //.disable_tls() .start() .await?; Ok(HermesIpfs { node }) @@ -394,7 +390,7 @@ impl HermesIpfs { key: impl AsRef<[u8]>, value: impl Into>, ) -> anyhow::Result<()> { - self.node.dht_put(key, value, Quorum::One).await + self.node.dht_put(key, value.into(), Quorum::One).await } /// Get content from DHT. @@ -412,7 +408,7 @@ impl HermesIpfs { /// Returns error if unable to get content from DHT pub async fn dht_get( &self, - key: impl AsRef<[u8]>, + key: impl AsRef<[u8]> + ToRecordKey, ) -> anyhow::Result> { let record_stream = self.node.dht_get(key).await?; pin_mut!(record_stream); @@ -473,7 +469,8 @@ impl HermesIpfs { &self, topic: impl Into>, ) -> anyhow::Result> { - self.node.pubsub_events(topic).await + //self.node.pubsub_events(topic).await + todo!() } /// Subscribes to a pubsub topic. @@ -489,12 +486,16 @@ impl HermesIpfs { /// ## Errors /// /// Returns error if unable to subscribe to pubsub topic. - pub async fn pubsub_subscribe( - &self, - topic: impl Into, - ) -> anyhow::Result { - self.node.pubsub_subscribe(topic).await - } + // pub async fn pubsub_subscribe( + // &self, + // topic: impl Into, + // ) -> anyhow::Result { + // self.node.pubsub_subscribe(topic).await + + // // TODO ? + // // self.node.pubsub_subscribe(topic.into()).await?; + // // let stream = self.node.pubsub_listener(topic.into()).await?; + // } /// Unsubscribes from a pubsub topic. /// @@ -511,9 +512,10 @@ impl HermesIpfs { /// Returns error if unable to unsubscribe from pubsub topic. pub async fn pubsub_unsubscribe( &self, - topic: impl Into, + topic: impl Into + IntoGossipsubTopic, ) -> anyhow::Result { - self.node.pubsub_unsubscribe(topic).await + //self.node.pubsub_unsubscribe(topic).await + todo!() } /// Publishes a message to a pubsub topic. @@ -535,10 +537,11 @@ impl HermesIpfs { topic: impl Into, message: Vec, ) -> anyhow::Result { - self.node - .pubsub_publish(topic, message) - .await - .map(std::convert::Into::into) + // self.node + // .pubsub_publish(topic, message) + // .await + // .map(std::convert::Into::into) + todo!() } /// Ban peer from node. @@ -647,15 +650,15 @@ impl FromStr for GetIpfsFile { } } -/// Handle stream of messages from the IPFS pubsub topic -pub fn subscription_stream_task( - stream: SubscriptionStream, - handler: fn(PubsubMessage), -) -> tokio::task::JoinHandle<()> { - tokio::spawn(async move { - pin_mut!(stream); - while let Some(msg) = stream.next().await { - handler(msg); - } - }) -} +///// Handle stream of messages from the IPFS pubsub topic +// pub fn subscription_stream_task( +// stream: SubscriptionStream, +// handler: fn(PubsubMessage), +// ) -> tokio::task::JoinHandle<()> { +// tokio::spawn(async move { +// pin_mut!(stream); +// while let Some(msg) = stream.next().await { +// handler(msg); +// } +// }) +// } From 62f4c73e8250ac2b05c95168b45db980737fce65 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Thu, 6 Nov 2025 11:39:27 +0100 Subject: [PATCH 02/13] Update `pubsub_subscribe` --- rust/hermes-ipfs/Cargo.toml | 1 + rust/hermes-ipfs/src/lib.rs | 57 +++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/rust/hermes-ipfs/Cargo.toml b/rust/hermes-ipfs/Cargo.toml index 44220398902..4f32bd8bf19 100644 --- a/rust/hermes-ipfs/Cargo.toml +++ b/rust/hermes-ipfs/Cargo.toml @@ -22,6 +22,7 @@ rust-ipfs = { version = "0.15.0", git = "https://github.com/dariusc93/rust-ipfs" tokio = "1.46.0" futures = "0.3.31" libp2p = "0.56.0" +connexa = { version = "0.4.1", features = ["identify", "dcutr", "gossipsub", "autonat", "relay", "kad", "keypair_base64_encoding", "ping", "request-response", "request-response-misc", "rendezvous", "mdns"] } [dev-dependencies] # Dependencies used by examples diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 75bd10cee0b..24dfa1542e1 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -31,7 +31,7 @@ pub use rust_ipfs::Multiaddr; pub use rust_ipfs::PeerId; use rust_ipfs::{ builder::UninitializedIpfs, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, - unixfs::AddOpt, PubsubEvent, Quorum, ToRecordKey, + unixfs::AddOpt, GossipsubMessage, PubsubEvent, Quorum, ToRecordKey, }; #[derive(Debug, Display, From, Into)] @@ -481,21 +481,19 @@ impl HermesIpfs { /// /// ## Returns /// - /// * `SubscriptionStream` + /// * Stream of `GossipsubEvent` /// /// ## Errors /// /// Returns error if unable to subscribe to pubsub topic. - // pub async fn pubsub_subscribe( - // &self, - // topic: impl Into, - // ) -> anyhow::Result { - // self.node.pubsub_subscribe(topic).await - - // // TODO ? - // // self.node.pubsub_subscribe(topic.into()).await?; - // // let stream = self.node.pubsub_listener(topic.into()).await?; - // } + pub async fn pubsub_subscribe( + &self, + topic: impl Into, + ) -> anyhow::Result> { + let topic = topic.into(); + self.node.pubsub_subscribe(&topic).await?; + self.node.pubsub_listener(&topic).await + } /// Unsubscribes from a pubsub topic. /// @@ -650,15 +648,26 @@ impl FromStr for GetIpfsFile { } } -///// Handle stream of messages from the IPFS pubsub topic -// pub fn subscription_stream_task( -// stream: SubscriptionStream, -// handler: fn(PubsubMessage), -// ) -> tokio::task::JoinHandle<()> { -// tokio::spawn(async move { -// pin_mut!(stream); -// while let Some(msg) = stream.next().await { -// handler(msg); -// } -// }) -// } +/// Handle stream of messages from the IPFS pubsub topic +pub fn subscription_stream_task( + stream: BoxStream<'static, connexa::prelude::GossipsubEvent>, + handler: H, +) -> tokio::task::JoinHandle<()> +where + H: Fn(GossipsubMessage) + Send + 'static, +{ + tokio::spawn(async move { + pin_mut!(stream); + while let Some(msg) = stream.next().await { + match msg { + connexa::prelude::GossipsubEvent::Subscribed { peer_id } => { + unimplemented!("GossipsubEvent::Subscribed") + }, + connexa::prelude::GossipsubEvent::Unsubscribed { peer_id } => { + unimplemented!("GossipsubEvent::Unsubscribed") + }, + connexa::prelude::GossipsubEvent::Message { message } => handler(message), + }; + } + }) +} From c6521645b8936f07b9c64865d43624167a507c0e Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Thu, 6 Nov 2025 13:01:51 +0100 Subject: [PATCH 03/13] Update `IpfsBuilder` --- rust/hermes-ipfs/src/lib.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 24dfa1542e1..ef301d024e5 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -4,7 +4,7 @@ #![allow(unused, dead_code, deprecated)] -use std::str::FromStr; +use std::{convert::Infallible, str::FromStr}; use derive_more::{Display, From, Into}; use futures::{pin_mut, stream::BoxStream, Stream, StreamExt}; @@ -31,7 +31,7 @@ pub use rust_ipfs::Multiaddr; pub use rust_ipfs::PeerId; use rust_ipfs::{ builder::UninitializedIpfs, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, - unixfs::AddOpt, GossipsubMessage, PubsubEvent, Quorum, ToRecordKey, + unixfs::AddOpt, GossipsubMessage, NetworkBehaviour, PubsubEvent, Quorum, ToRecordKey, }; #[derive(Debug, Display, From, Into)] @@ -39,9 +39,10 @@ use rust_ipfs::{ pub struct MessageId(pub PubsubMessageId); /// Builder type for IPFS Node configuration. -pub struct IpfsBuilder(UninitializedIpfs); +pub struct IpfsBuilder(UninitializedIpfs) +where N: NetworkBehaviour + Send + Sync; -impl IpfsBuilder { +impl IpfsBuilder where N: NetworkBehaviour + Send + Sync { #[must_use] /// Create a new` IpfsBuilder`. pub fn new() -> Self { @@ -103,12 +104,6 @@ impl IpfsBuilder { } } -impl Default for IpfsBuilder { - fn default() -> Self { - Self::new() - } -} - /// Hermes IPFS Node. pub struct HermesIpfs { /// IPFS node @@ -126,7 +121,7 @@ impl HermesIpfs { /// /// Returns an error if the IPFS daemon fails to start. pub async fn start() -> anyhow::Result { - let node: Ipfs = IpfsBuilder::new() + let node: Ipfs = IpfsBuilder::::new() .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed From 8755609df56f2cc37d4a5f50c70b1b5842e9b250 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 10:24:31 +0100 Subject: [PATCH 04/13] Update `pubsub_unsubscribe()` --- rust/hermes-ipfs/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index ef301d024e5..744456ae420 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -42,7 +42,9 @@ pub struct MessageId(pub PubsubMessageId); pub struct IpfsBuilder(UninitializedIpfs) where N: NetworkBehaviour + Send + Sync; -impl IpfsBuilder where N: NetworkBehaviour + Send + Sync { +impl IpfsBuilder +where N: NetworkBehaviour + Send + Sync +{ #[must_use] /// Create a new` IpfsBuilder`. pub fn new() -> Self { @@ -496,19 +498,14 @@ impl HermesIpfs { /// /// * `topic` - `impl Into` /// - /// ## Returns - /// - /// * `bool` - /// /// ## Errors /// /// Returns error if unable to unsubscribe from pubsub topic. pub async fn pubsub_unsubscribe( &self, topic: impl Into + IntoGossipsubTopic, - ) -> anyhow::Result { - //self.node.pubsub_unsubscribe(topic).await - todo!() + ) -> anyhow::Result<()> { + self.node.pubsub_unsubscribe(topic).await } /// Publishes a message to a pubsub topic. From 6b7b55d16b5b11878bdfd7dee5528a2d351ea863 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 10:37:44 +0100 Subject: [PATCH 05/13] Update `pubsub_publish()` --- rust/hermes-ipfs/src/lib.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 744456ae420..a9b667e529d 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -515,23 +515,15 @@ impl HermesIpfs { /// * `topic` - `impl Into` /// * `message` - `Vec` /// - /// ## Returns - /// - /// * `Result` - /// /// ## Errors /// /// Returns error if unable to publish to a pubsub topic. pub async fn pubsub_publish( &self, - topic: impl Into, + topic: impl IntoGossipsubTopic, message: Vec, - ) -> anyhow::Result { - // self.node - // .pubsub_publish(topic, message) - // .await - // .map(std::convert::Into::into) - todo!() + ) -> anyhow::Result<()> { + self.node.pubsub_publish(topic, message).await } /// Ban peer from node. From 5da7e6bc6fdc9160258c8f3cbe29d609cae8aa33 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 11:02:59 +0100 Subject: [PATCH 06/13] Wire the pubsub events --- rust/hermes-ipfs/src/lib.rs | 50 +++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index a9b667e529d..31fb1f73dfa 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -449,27 +449,6 @@ impl HermesIpfs { self.node.bootstrap().await } - /// Returns a stream of pubsub swarm events for a topic. - /// - /// ## Parameters - /// - /// * `topic` - `impl Into>` - /// - /// ## Returns - /// - /// * A result with `BoxStream<'static, PubsubEvent>` - /// - /// ## Errors - /// - /// Returns error if unable to retrieve pubsub swarm events. - pub async fn pubsub_events( - &self, - topic: impl Into>, - ) -> anyhow::Result> { - //self.node.pubsub_events(topic).await - todo!() - } - /// Subscribes to a pubsub topic. /// /// ## Parameters @@ -632,25 +611,42 @@ impl FromStr for GetIpfsFile { } } +/// GossipsubEvents related to subscription state +#[derive(Display, Debug)] +pub enum SubscriptionStatusEvent { + /// Peer has been subscribed + Subscribed { + /// Peer id + peer_id: PeerId, + }, + /// Peer has been unsubscribed + Unsubscribed { + /// Peer id + peer_id: PeerId, + }, +} + /// Handle stream of messages from the IPFS pubsub topic -pub fn subscription_stream_task( +pub fn subscription_stream_task( stream: BoxStream<'static, connexa::prelude::GossipsubEvent>, - handler: H, + message_handler: MH, + subscription_handler: SH, ) -> tokio::task::JoinHandle<()> where - H: Fn(GossipsubMessage) + Send + 'static, + MH: Fn(GossipsubMessage) + Send + 'static, + SH: Fn(SubscriptionStatusEvent) + Send + 'static, { tokio::spawn(async move { pin_mut!(stream); while let Some(msg) = stream.next().await { match msg { connexa::prelude::GossipsubEvent::Subscribed { peer_id } => { - unimplemented!("GossipsubEvent::Subscribed") + subscription_handler(SubscriptionStatusEvent::Subscribed { peer_id }) }, connexa::prelude::GossipsubEvent::Unsubscribed { peer_id } => { - unimplemented!("GossipsubEvent::Unsubscribed") + subscription_handler(SubscriptionStatusEvent::Unsubscribed { peer_id }) }, - connexa::prelude::GossipsubEvent::Message { message } => handler(message), + connexa::prelude::GossipsubEvent::Message { message } => message_handler(message), }; } }) From 4715d8116e7e9346a690f82af0fe79a0fff75bf2 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 11:23:29 +0100 Subject: [PATCH 07/13] Remove references to no longer available transport configuration --- rust/hermes-ipfs/src/lib.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 31fb1f73dfa..1fcb6a0b624 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -77,26 +77,6 @@ where N: NetworkBehaviour + Send + Sync ) } - // #[must_use] - // /// Set the transport configuration for the IPFS node. - // pub fn set_transport_configuration( - // self, - // transport: rust_ipfs::p2p::TransportConfig, - // ) -> Self { - // Self(self.0.set_transport_configuration(transport)) - // } - - // #[must_use] - // /// Disable TLS for the IPFS node. - // pub fn disable_tls(self) -> Self { - // let transport = rust_ipfs::p2p::TransportConfig { - // enable_quic: false, - // enable_secure_websocket: false, - // ..Default::default() - // }; - // Self(self.0.set_transport_configuration(transport)) - // } - /// Start the IPFS node. /// /// ## Errors @@ -127,7 +107,8 @@ impl HermesIpfs { .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed - //.disable_tls() + // TODO(rafal-ch): TLS is disabled by default, we can enable it by calling + // `IpfsBuilder::enable_secure...()` .enable_secure_websocket() .start() .await?; Ok(HermesIpfs { node }) From cc2742da80c47ad6f1285f04347a75f5cb7fb81d Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 11:24:33 +0100 Subject: [PATCH 08/13] Fix comment --- 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 1fcb6a0b624..ae61f240fbe 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -108,7 +108,8 @@ impl HermesIpfs { .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed // TODO(rafal-ch): TLS is disabled by default, we can enable it by calling - // `IpfsBuilder::enable_secure...()` .enable_secure_websocket() + // on of the `IpfsBuilder::enable_secure...()` flavors. + //.enable_secure_websocket() .start() .await?; Ok(HermesIpfs { node }) From c01fbc97c616779f5bc278f60842ea8385f505c7 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 11:29:30 +0100 Subject: [PATCH 09/13] Clean up deprecated and unused --- rust/hermes-ipfs/examples/hermes-ipfs-cli.rs | 4 ++-- rust/hermes-ipfs/src/lib.rs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs b/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs index f8926792db0..cdc47e2587c 100644 --- a/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs +++ b/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs @@ -1,7 +1,7 @@ //! Hermes IPFS VFS compatibility use clap::{Parser, Subcommand}; -use hermes_ipfs::{HermesIpfs, IpfsBuilder}; +use hermes_ipfs::{HermesIpfs, HermesIpfsBuilder}; use lipsum::lipsum; use rust_ipfs::IpfsPath; @@ -44,7 +44,7 @@ async fn main() -> anyhow::Result<()> { let args = Cli::parse(); let base_dir = dirs::data_dir().unwrap_or_else(|| std::path::PathBuf::from(".")); let ipfs_data_path = base_dir.as_path().join("hermes/ipfs"); - let builder = IpfsBuilder::new() + let builder = HermesIpfsBuilder::new() .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index ae61f240fbe..61e7ebf80d6 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -2,17 +2,15 @@ //! //! Provides support for storage, and `PubSub` functionality. -#![allow(unused, dead_code, deprecated)] - use std::{convert::Infallible, str::FromStr}; use derive_more::{Display, From, Into}; -use futures::{pin_mut, stream::BoxStream, Stream, StreamExt}; +use futures::{pin_mut, stream::BoxStream, StreamExt}; /// IPFS Content Identifier. pub use ipld_core::cid::Cid; /// IPLD pub use ipld_core::ipld::Ipld; -use libp2p::gossipsub::{Message as PubsubMessage, MessageId as PubsubMessageId}; +use libp2p::gossipsub::MessageId as PubsubMessageId; /// `rust_ipfs` re-export. pub use rust_ipfs; /// Peer Info type. @@ -30,8 +28,8 @@ pub use rust_ipfs::Multiaddr; /// Peer ID type. pub use rust_ipfs::PeerId; use rust_ipfs::{ - builder::UninitializedIpfs, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, - unixfs::AddOpt, GossipsubMessage, NetworkBehaviour, PubsubEvent, Quorum, ToRecordKey, + builder::IpfsBuilder, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, unixfs::AddOpt, + GossipsubMessage, NetworkBehaviour, Quorum, ToRecordKey, }; #[derive(Debug, Display, From, Into)] @@ -39,16 +37,16 @@ use rust_ipfs::{ pub struct MessageId(pub PubsubMessageId); /// Builder type for IPFS Node configuration. -pub struct IpfsBuilder(UninitializedIpfs) +pub struct HermesIpfsBuilder(IpfsBuilder) where N: NetworkBehaviour + Send + Sync; -impl IpfsBuilder +impl HermesIpfsBuilder where N: NetworkBehaviour + Send + Sync { #[must_use] /// Create a new` IpfsBuilder`. pub fn new() -> Self { - Self(UninitializedIpfs::new()) + Self(IpfsBuilder::new()) } #[must_use] @@ -103,7 +101,7 @@ impl HermesIpfs { /// /// Returns an error if the IPFS daemon fails to start. pub async fn start() -> anyhow::Result { - let node: Ipfs = IpfsBuilder::::new() + let node: Ipfs = HermesIpfsBuilder::::new() .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed From b11811f953751b744dcef65099de06a6bed25294 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 11:48:58 +0100 Subject: [PATCH 10/13] Update dictionary --- .config/dictionaries/project.dic | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.config/dictionaries/project.dic b/.config/dictionaries/project.dic index ece094a570b..6f45bf29a5b 100644 --- a/.config/dictionaries/project.dic +++ b/.config/dictionaries/project.dic @@ -12,10 +12,12 @@ asyncio Attributes auditability Auliffe +autonat auxdata babystep backpressure bech +Behaviour bimap bindgen bkioshn @@ -48,6 +50,7 @@ ciphertexts Coap codegen codepoints +connexa coti coverallsapp cpus @@ -62,6 +65,7 @@ Datelike DBSTATUS dbsync dcbor +dcutr decompressor delegators devnet @@ -141,6 +145,7 @@ jormungandr Jörmungandr jsonschema Justfile +keypair kiduri labelloc lcov @@ -245,6 +250,7 @@ pytype qpsg qrcode quic +rafal rankdir rapidoc readlinkat From e8311789ba9b0498bbb5fbb5c038347cf454acb0 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 12:11:16 +0100 Subject: [PATCH 11/13] Update tests --- rust/hermes-ipfs/examples/hermes-ipfs-cli.rs | 5 ++-- rust/hermes-ipfs/examples/pubsub.rs | 24 ++++---------------- rust/hermes-ipfs/examples/put-get-dht.rs | 3 ++- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs b/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs index cdc47e2587c..0bc0f81aa15 100644 --- a/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs +++ b/rust/hermes-ipfs/examples/hermes-ipfs-cli.rs @@ -1,6 +1,7 @@ //! Hermes IPFS VFS compatibility use clap::{Parser, Subcommand}; +use connexa::dummy; use hermes_ipfs::{HermesIpfs, HermesIpfsBuilder}; use lipsum::lipsum; use rust_ipfs::IpfsPath; @@ -44,11 +45,11 @@ async fn main() -> anyhow::Result<()> { let args = Cli::parse(); let base_dir = dirs::data_dir().unwrap_or_else(|| std::path::PathBuf::from(".")); let ipfs_data_path = base_dir.as_path().join("hermes/ipfs"); - let builder = HermesIpfsBuilder::new() + let builder = HermesIpfsBuilder::::new() .with_default() .set_default_listener() // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed - .disable_tls() + //.enable_secure_websocket() .set_disk_storage(ipfs_data_path); let hermes_node: HermesIpfs = builder.start().await?.into(); match args.command { diff --git a/rust/hermes-ipfs/examples/pubsub.rs b/rust/hermes-ipfs/examples/pubsub.rs index 78695b677bb..957bb0eeecf 100644 --- a/rust/hermes-ipfs/examples/pubsub.rs +++ b/rust/hermes-ipfs/examples/pubsub.rs @@ -14,8 +14,8 @@ //! * The task that reads lines from stdin and publishes them as either node. use std::io::Write; -use hermes_ipfs::{pin_mut, FutureExt, HermesIpfs, StreamExt}; -use rust_ipfs::PubsubEvent; +use futures::{pin_mut, FutureExt, StreamExt}; +use hermes_ipfs::HermesIpfs; use rustyline_async::Readline; #[allow(clippy::indexing_slicing)] @@ -57,15 +57,11 @@ async fn start_bootstrapped_nodes() -> anyhow::Result<(HermesIpfs, HermesIpfs)> /// Main function async fn main() -> anyhow::Result<()> { let topic = String::from("ipfs-chat"); - let option_topic = Option::Some(topic.clone()); // Initialize the repo and start a daemon let (hermes_a, hermes_b) = start_bootstrapped_nodes().await?; let (mut rl, mut stdout) = Readline::new(format!("{} > ", "Write message to publish"))?; - let mut event_stream = hermes_a.pubsub_events(option_topic.clone()).await?; - let mut event_stream_b = hermes_b.pubsub_events(option_topic).await?; - let stream = hermes_a.pubsub_subscribe(topic.clone()).await?; let stream_b = hermes_b.pubsub_subscribe(topic.clone()).await?; @@ -79,24 +75,12 @@ async fn main() -> anyhow::Result<()> { tokio::select! { data = stream.next() => { if let Some(msg) = data { - writeln!(stdout, "NODE A RECV: {}", String::from_utf8_lossy(&msg.data))?; + writeln!(stdout, "NODE A RECV: {:?}", &msg)?; } } data = stream_b.next() => { if let Some(msg) = data { - writeln!(stdout, "NODE B RECV: {}", String::from_utf8_lossy(&msg.data))?; - } - } - Some(event) = event_stream.next() => { - match event { - PubsubEvent::Subscribe { peer_id, topic } => writeln!(stdout, "{peer_id} subscribed to {topic:?}")?, - PubsubEvent::Unsubscribe { peer_id, topic } => writeln!(stdout, "{peer_id} unsubscribed from {topic:?}")?, - } - } - Some(event) = event_stream_b.next() => { - match event { - PubsubEvent::Subscribe { peer_id , topic} => writeln!(stdout, "{peer_id} subscribed to {topic:?}")?, - PubsubEvent::Unsubscribe { peer_id, topic } => writeln!(stdout, "{peer_id} unsubscribed from {topic:?}")?, + writeln!(stdout, "NODE B RECV: {:?}", &msg)?; } } line = rl.readline().fuse() => match line { diff --git a/rust/hermes-ipfs/examples/put-get-dht.rs b/rust/hermes-ipfs/examples/put-get-dht.rs index 3cfacc9f5b1..1af79d9c0a7 100644 --- a/rust/hermes-ipfs/examples/put-get-dht.rs +++ b/rust/hermes-ipfs/examples/put-get-dht.rs @@ -48,7 +48,8 @@ async fn main() -> anyhow::Result<()> { println!("* Hermes IPFS node A is publishing 'my_key' to DHT."); hermes_ipfs_a.dht_put(b"my_key", ipfs_file).await?; println!("* Hermes IPFS node B is getting 'my_key' from DHT."); - let data_retrieved = hermes_ipfs_b.dht_get(b"my_key").await?; + let key: Vec = "my_key".bytes().collect(); + let data_retrieved = hermes_ipfs_b.dht_get(key).await?; let data = String::from_utf8(data_retrieved)?; println!(" Got data: {data:?}"); // Stop the nodes and exit. From b18033caa8fd649193f998cab2673fc834add2af Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 12:30:24 +0100 Subject: [PATCH 12/13] Fix lints --- rust/hermes-ipfs/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index 61e7ebf80d6..e415849dde5 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -40,6 +40,12 @@ pub struct MessageId(pub PubsubMessageId); pub struct HermesIpfsBuilder(IpfsBuilder) where N: NetworkBehaviour + Send + Sync; +impl Default for HermesIpfsBuilder { + fn default() -> Self { + Self(IpfsBuilder::new()) + } +} + impl HermesIpfsBuilder where N: NetworkBehaviour + Send + Sync { @@ -591,7 +597,7 @@ impl FromStr for GetIpfsFile { } } -/// GossipsubEvents related to subscription state +/// `GossipsubEvents` related to subscription state #[derive(Display, Debug)] pub enum SubscriptionStatusEvent { /// Peer has been subscribed @@ -621,13 +627,13 @@ where while let Some(msg) = stream.next().await { match msg { connexa::prelude::GossipsubEvent::Subscribed { peer_id } => { - subscription_handler(SubscriptionStatusEvent::Subscribed { peer_id }) + subscription_handler(SubscriptionStatusEvent::Subscribed { peer_id }); }, connexa::prelude::GossipsubEvent::Unsubscribed { peer_id } => { - subscription_handler(SubscriptionStatusEvent::Unsubscribed { peer_id }) + subscription_handler(SubscriptionStatusEvent::Unsubscribed { peer_id }); }, connexa::prelude::GossipsubEvent::Message { message } => message_handler(message), - }; + } } }) } From 5e8e90fef9c853388f66670d6bfb4983e88dcf80 Mon Sep 17 00:00:00 2001 From: rafal-ch Date: Fri, 7 Nov 2025 12:39:01 +0100 Subject: [PATCH 13/13] Fix formatting --- rust/hermes-ipfs/examples/pubsub.rs | 2 +- rust/hermes-ipfs/src/lib.rs | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rust/hermes-ipfs/examples/pubsub.rs b/rust/hermes-ipfs/examples/pubsub.rs index 957bb0eeecf..48b296ebc11 100644 --- a/rust/hermes-ipfs/examples/pubsub.rs +++ b/rust/hermes-ipfs/examples/pubsub.rs @@ -14,7 +14,7 @@ //! * The task that reads lines from stdin and publishes them as either node. use std::io::Write; -use futures::{pin_mut, FutureExt, StreamExt}; +use futures::{FutureExt, StreamExt, pin_mut}; use hermes_ipfs::HermesIpfs; use rustyline_async::Readline; diff --git a/rust/hermes-ipfs/src/lib.rs b/rust/hermes-ipfs/src/lib.rs index e415849dde5..2a80db0a3ff 100644 --- a/rust/hermes-ipfs/src/lib.rs +++ b/rust/hermes-ipfs/src/lib.rs @@ -5,7 +5,7 @@ use std::{convert::Infallible, str::FromStr}; use derive_more::{Display, From, Into}; -use futures::{pin_mut, stream::BoxStream, StreamExt}; +use futures::{StreamExt, pin_mut, stream::BoxStream}; /// IPFS Content Identifier. pub use ipld_core::cid::Cid; /// IPLD @@ -13,12 +13,6 @@ pub use ipld_core::ipld::Ipld; use libp2p::gossipsub::MessageId as PubsubMessageId; /// `rust_ipfs` re-export. pub use rust_ipfs; -/// Peer Info type. -pub use rust_ipfs::p2p::PeerInfo; -/// Enum for specifying paths in IPFS. -pub use rust_ipfs::path::IpfsPath; -/// Storage type for IPFS node. -pub use rust_ipfs::repo::StorageTypes; /// Server, Client, or Auto mode pub use rust_ipfs::DhtMode; /// Server, Client, or Auto mode @@ -27,9 +21,15 @@ pub use rust_ipfs::Ipfs; pub use rust_ipfs::Multiaddr; /// Peer ID type. pub use rust_ipfs::PeerId; +/// Peer Info type. +pub use rust_ipfs::p2p::PeerInfo; +/// Enum for specifying paths in IPFS. +pub use rust_ipfs::path::IpfsPath; +/// Storage type for IPFS node. +pub use rust_ipfs::repo::StorageTypes; use rust_ipfs::{ - builder::IpfsBuilder, dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, unixfs::AddOpt, - GossipsubMessage, NetworkBehaviour, Quorum, ToRecordKey, + GossipsubMessage, NetworkBehaviour, Quorum, ToRecordKey, builder::IpfsBuilder, + dag::ResolveError, dummy, gossipsub::IntoGossipsubTopic, unixfs::AddOpt, }; #[derive(Debug, Display, From, Into)]