22//!
33//! Provides support for storage, and `PubSub` functionality.
44
5+ #![ allow( unused, dead_code, deprecated) ]
6+
57use std:: str:: FromStr ;
68
79use derive_more:: { Display , From , Into } ;
10+ use futures:: { pin_mut, stream:: BoxStream , Stream , StreamExt } ;
811/// IPFS Content Identifier.
912pub use ipld_core:: cid:: Cid ;
1013/// IPLD
1114pub use ipld_core:: ipld:: Ipld ;
15+ use libp2p:: gossipsub:: { Message as PubsubMessage , MessageId as PubsubMessageId } ;
1216/// `rust_ipfs` re-export.
1317pub use rust_ipfs;
14- /// libp2p re-exports.
15- pub use rust_ipfs:: libp2p:: futures:: { pin_mut, stream:: BoxStream , FutureExt , StreamExt } ;
1618/// Peer Info type.
1719pub use rust_ipfs:: p2p:: PeerInfo ;
1820/// Enum for specifying paths in IPFS.
@@ -27,23 +29,17 @@ pub use rust_ipfs::Ipfs;
2729pub use rust_ipfs:: Multiaddr ;
2830/// Peer ID type.
2931pub use rust_ipfs:: PeerId ;
30- /// Stream for `PubSub` Topic Subscriptions.
31- pub use rust_ipfs:: SubscriptionStream ;
32- /// Builder type for IPFS Node configuration.
33- use rust_ipfs:: UninitializedIpfsDefault as UninitializedIpfs ;
3432use rust_ipfs:: {
35- dag:: ResolveError ,
36- libp2p:: gossipsub:: { Message as PubsubMessage , MessageId as PubsubMessageId } ,
37- unixfs:: AddOpt ,
38- PubsubEvent , Quorum ,
33+ builder:: UninitializedIpfs , dag:: ResolveError , dummy, gossipsub:: IntoGossipsubTopic ,
34+ unixfs:: AddOpt , PubsubEvent , Quorum , ToRecordKey ,
3935} ;
4036
4137#[ derive( Debug , Display , From , Into ) ]
4238/// `PubSub` Message ID.
4339pub struct MessageId ( pub PubsubMessageId ) ;
4440
4541/// Builder type for IPFS Node configuration.
46- pub struct IpfsBuilder ( UninitializedIpfs ) ;
42+ pub struct IpfsBuilder ( UninitializedIpfs < dummy :: Behaviour > ) ;
4743
4844impl IpfsBuilder {
4945 #[ must_use]
@@ -78,25 +74,25 @@ impl IpfsBuilder {
7874 )
7975 }
8076
81- #[ must_use]
82- /// Set the transport configuration for the IPFS node.
83- pub fn set_transport_configuration (
84- self ,
85- transport : rust_ipfs:: p2p:: TransportConfig ,
86- ) -> Self {
87- Self ( self . 0 . set_transport_configuration ( transport) )
88- }
89-
90- #[ must_use]
91- /// Disable TLS for the IPFS node.
92- pub fn disable_tls ( self ) -> Self {
93- let transport = rust_ipfs:: p2p:: TransportConfig {
94- enable_quic : false ,
95- enable_secure_websocket : false ,
96- ..Default :: default ( )
97- } ;
98- Self ( self . 0 . set_transport_configuration ( transport) )
99- }
77+ // #[must_use]
78+ // // / Set the transport configuration for the IPFS node.
79+ // pub fn set_transport_configuration(
80+ // self,
81+ // transport: rust_ipfs::p2p::TransportConfig,
82+ // ) -> Self {
83+ // Self(self.0.set_transport_configuration(transport))
84+ // }
85+
86+ // #[must_use]
87+ // // / Disable TLS for the IPFS node.
88+ // pub fn disable_tls(self) -> Self {
89+ // let transport = rust_ipfs::p2p::TransportConfig {
90+ // enable_quic: false,
91+ // enable_secure_websocket: false,
92+ // ..Default::default()
93+ // };
94+ // Self(self.0.set_transport_configuration(transport))
95+ // }
10096
10197 /// Start the IPFS node.
10298 ///
@@ -134,7 +130,7 @@ impl HermesIpfs {
134130 . with_default ( )
135131 . set_default_listener ( )
136132 // TODO(saibatizoku): Re-Enable default transport config when libp2p Cert bug is fixed
137- . disable_tls ( )
133+ // .disable_tls()
138134 . start ( )
139135 . await ?;
140136 Ok ( HermesIpfs { node } )
@@ -394,7 +390,7 @@ impl HermesIpfs {
394390 key : impl AsRef < [ u8 ] > ,
395391 value : impl Into < Vec < u8 > > ,
396392 ) -> anyhow:: Result < ( ) > {
397- self . node . dht_put ( key, value, Quorum :: One ) . await
393+ self . node . dht_put ( key, value. into ( ) , Quorum :: One ) . await
398394 }
399395
400396 /// Get content from DHT.
@@ -412,7 +408,7 @@ impl HermesIpfs {
412408 /// Returns error if unable to get content from DHT
413409 pub async fn dht_get (
414410 & self ,
415- key : impl AsRef < [ u8 ] > ,
411+ key : impl AsRef < [ u8 ] > + ToRecordKey ,
416412 ) -> anyhow:: Result < Vec < u8 > > {
417413 let record_stream = self . node . dht_get ( key) . await ?;
418414 pin_mut ! ( record_stream) ;
@@ -473,7 +469,8 @@ impl HermesIpfs {
473469 & self ,
474470 topic : impl Into < Option < String > > ,
475471 ) -> anyhow:: Result < BoxStream < ' static , PubsubEvent > > {
476- self . node . pubsub_events ( topic) . await
472+ //self.node.pubsub_events(topic).await
473+ todo ! ( )
477474 }
478475
479476 /// Subscribes to a pubsub topic.
@@ -489,12 +486,16 @@ impl HermesIpfs {
489486 /// ## Errors
490487 ///
491488 /// Returns error if unable to subscribe to pubsub topic.
492- pub async fn pubsub_subscribe (
493- & self ,
494- topic : impl Into < String > ,
495- ) -> anyhow:: Result < SubscriptionStream > {
496- self . node . pubsub_subscribe ( topic) . await
497- }
489+ // pub async fn pubsub_subscribe(
490+ // &self,
491+ // topic: impl Into<String>,
492+ // ) -> anyhow::Result<SubscriptionStream> {
493+ // self.node.pubsub_subscribe(topic).await
494+
495+ // // TODO ?
496+ // // self.node.pubsub_subscribe(topic.into()).await?;
497+ // // let stream = self.node.pubsub_listener(topic.into()).await?;
498+ // }
498499
499500 /// Unsubscribes from a pubsub topic.
500501 ///
@@ -511,9 +512,10 @@ impl HermesIpfs {
511512 /// Returns error if unable to unsubscribe from pubsub topic.
512513 pub async fn pubsub_unsubscribe (
513514 & self ,
514- topic : impl Into < String > ,
515+ topic : impl Into < String > + IntoGossipsubTopic ,
515516 ) -> anyhow:: Result < bool > {
516- self . node . pubsub_unsubscribe ( topic) . await
517+ //self.node.pubsub_unsubscribe(topic).await
518+ todo ! ( )
517519 }
518520
519521 /// Publishes a message to a pubsub topic.
@@ -535,10 +537,11 @@ impl HermesIpfs {
535537 topic : impl Into < String > ,
536538 message : Vec < u8 > ,
537539 ) -> anyhow:: Result < MessageId > {
538- self . node
539- . pubsub_publish ( topic, message)
540- . await
541- . map ( std:: convert:: Into :: into)
540+ // self.node
541+ // .pubsub_publish(topic, message)
542+ // .await
543+ // .map(std::convert::Into::into)
544+ todo ! ( )
542545 }
543546
544547 /// Ban peer from node.
@@ -647,15 +650,15 @@ impl FromStr for GetIpfsFile {
647650 }
648651}
649652
650- /// Handle stream of messages from the IPFS pubsub topic
651- pub fn subscription_stream_task (
652- stream : SubscriptionStream ,
653- handler : fn ( PubsubMessage ) ,
654- ) -> tokio:: task:: JoinHandle < ( ) > {
655- tokio:: spawn ( async move {
656- pin_mut ! ( stream) ;
657- while let Some ( msg) = stream. next ( ) . await {
658- handler ( msg) ;
659- }
660- } )
661- }
653+ ///// Handle stream of messages from the IPFS pubsub topic
654+ // pub fn subscription_stream_task(
655+ // stream: SubscriptionStream,
656+ // handler: fn(PubsubMessage),
657+ // ) -> tokio::task::JoinHandle<()> {
658+ // tokio::spawn(async move {
659+ // pin_mut!(stream);
660+ // while let Some(msg) = stream.next().await {
661+ // handler(msg);
662+ // }
663+ // })
664+ // }
0 commit comments