From 528577c17b0be59c6508a79f9e2af3d56ef426c9 Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Thu, 28 Nov 2024 00:40:12 -0500 Subject: [PATCH] chore: update example --- examples/block_exchange.rs | 4 +--- examples/custom_behaviour.rs | 2 +- examples/echo-stream.rs | 2 +- examples/pubsub.rs | 7 +++---- examples/wasm-example/src/lib.rs | 6 +----- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/examples/block_exchange.rs b/examples/block_exchange.rs index e6749c71f..a1c54e546 100644 --- a/examples/block_exchange.rs +++ b/examples/block_exchange.rs @@ -23,9 +23,7 @@ async fn main() -> anyhow::Result<()> { let addrs = node_a.listening_addresses().await?; - for addr in addrs { - node_b.add_peer((peer_id, addr)).await?; - } + node_b.add_peer((peer_id, addrs)).await?; let block_a = ipld!({ "name": "alice", diff --git a/examples/custom_behaviour.rs b/examples/custom_behaviour.rs index ad65581a7..a66e86572 100644 --- a/examples/custom_behaviour.rs +++ b/examples/custom_behaviour.rs @@ -9,7 +9,7 @@ async fn main() -> anyhow::Result<()> { // Initialize the repo and start a daemon let ipfs: Ipfs = UninitializedIpfs::new() .with_custom_behaviour(ext_behaviour::Behaviour) - .add_listening_addr("/ip4/0.0.0.0/tcp/0".parse()?) + .add_listening_addr("/ip4/127.0.0.1/tcp/0".parse()?) .start() .await?; diff --git a/examples/echo-stream.rs b/examples/echo-stream.rs index e12d7ac33..87c5350d5 100644 --- a/examples/echo-stream.rs +++ b/examples/echo-stream.rs @@ -29,7 +29,7 @@ async fn main() -> anyhow::Result<()> { // Initialize the repo and start a daemon let ipfs = UninitializedIpfs::new() .set_keypair(&keypair) - .add_listening_addr("/ip4/0.0.0.0/tcp/0".parse()?) + .add_listening_addr("/ip4/127.0.0.1/tcp/0".parse()?) .with_streams() .start() .await?; diff --git a/examples/pubsub.rs b/examples/pubsub.rs index 7b38b26ae..57dac8529 100644 --- a/examples/pubsub.rs +++ b/examples/pubsub.rs @@ -1,6 +1,5 @@ use clap::Parser; use futures::FutureExt; -use ipld_core::ipld; use libp2p::futures::StreamExt; use libp2p::Multiaddr; use rust_ipfs::p2p::MultiaddrExt; @@ -278,10 +277,10 @@ async fn main() -> anyhow::Result<()> { //Note: This is temporary as a similar implementation will be used internally in the future async fn topic_discovery(ipfs: Ipfs, topic: String) -> anyhow::Result<()> { - let cid = ipfs.put_dag(ipld!(topic)).await?; - ipfs.provide(cid).await?; + let topic_bytes = topic.as_bytes().to_vec(); + ipfs.dht_provide(topic_bytes.clone()).await?; loop { - let mut stream = ipfs.get_providers(cid).await?.boxed(); + let mut stream = ipfs.dht_get_providers(topic_bytes.clone()).await?.boxed(); while let Some(_providers) = stream.next().await {} tokio::time::sleep(Duration::from_millis(50)).await; } diff --git a/examples/wasm-example/src/lib.rs b/examples/wasm-example/src/lib.rs index e70ed7a48..d251602ae 100644 --- a/examples/wasm-example/src/lib.rs +++ b/examples/wasm-example/src/lib.rs @@ -32,11 +32,7 @@ pub async fn run() -> Result<(), JsError> { let addrs = node_a.listening_addresses().await.unwrap(); - for addr in addrs { - node_b.add_peer((peer_id, addr)).await.unwrap(); - } - - node_b.connect(peer_id).await.unwrap(); + node_b.add_peer((peer_id, addrs)).await.unwrap(); let block_a = ipld!({ "name": "alice",