1414//! * The task that reads lines from stdin and publishes them as either node.
1515use std:: io:: Write ;
1616
17- use hermes_ipfs :: { FutureExt , HermesIpfs , StreamExt , pin_mut} ;
18- use rust_ipfs :: PubsubEvent ;
17+ use futures :: { FutureExt , StreamExt , pin_mut} ;
18+ use hermes_ipfs :: HermesIpfs ;
1919use rustyline_async:: Readline ;
2020
2121#[ allow( clippy:: indexing_slicing) ]
@@ -57,15 +57,11 @@ async fn start_bootstrapped_nodes() -> anyhow::Result<(HermesIpfs, HermesIpfs)>
5757/// Main function
5858async fn main ( ) -> anyhow:: Result < ( ) > {
5959 let topic = String :: from ( "ipfs-chat" ) ;
60- let option_topic = Option :: Some ( topic. clone ( ) ) ;
6160
6261 // Initialize the repo and start a daemon
6362 let ( hermes_a, hermes_b) = start_bootstrapped_nodes ( ) . await ?;
6463 let ( mut rl, mut stdout) = Readline :: new ( format ! ( "{} > " , "Write message to publish" ) ) ?;
6564
66- let mut event_stream = hermes_a. pubsub_events ( option_topic. clone ( ) ) . await ?;
67- let mut event_stream_b = hermes_b. pubsub_events ( option_topic) . await ?;
68-
6965 let stream = hermes_a. pubsub_subscribe ( topic. clone ( ) ) . await ?;
7066 let stream_b = hermes_b. pubsub_subscribe ( topic. clone ( ) ) . await ?;
7167
@@ -79,24 +75,12 @@ async fn main() -> anyhow::Result<()> {
7975 tokio:: select! {
8076 data = stream. next( ) => {
8177 if let Some ( msg) = data {
82- writeln!( stdout, "NODE A RECV: {}" , String :: from_utf8_lossy ( & msg. data ) ) ?;
78+ writeln!( stdout, "NODE A RECV: {:? }" , & msg) ?;
8379 }
8480 }
8581 data = stream_b. next( ) => {
8682 if let Some ( msg) = data {
87- writeln!( stdout, "NODE B RECV: {}" , String :: from_utf8_lossy( & msg. data) ) ?;
88- }
89- }
90- Some ( event) = event_stream. next( ) => {
91- match event {
92- PubsubEvent :: Subscribe { peer_id, topic } => writeln!( stdout, "{peer_id} subscribed to {topic:?}" ) ?,
93- PubsubEvent :: Unsubscribe { peer_id, topic } => writeln!( stdout, "{peer_id} unsubscribed from {topic:?}" ) ?,
94- }
95- }
96- Some ( event) = event_stream_b. next( ) => {
97- match event {
98- PubsubEvent :: Subscribe { peer_id , topic} => writeln!( stdout, "{peer_id} subscribed to {topic:?}" ) ?,
99- PubsubEvent :: Unsubscribe { peer_id, topic } => writeln!( stdout, "{peer_id} unsubscribed from {topic:?}" ) ?,
83+ writeln!( stdout, "NODE B RECV: {:?}" , & msg) ?;
10084 }
10185 }
10286 line = rl. readline( ) . fuse( ) => match line {
0 commit comments