Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Nov 28, 2024
1 parent 22cb11b commit 528577c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
4 changes: 1 addition & 3 deletions examples/block_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down
2 changes: 1 addition & 1 deletion examples/echo-stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
7 changes: 3 additions & 4 deletions examples/pubsub.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions examples/wasm-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 528577c

Please sign in to comment.