Distributed Erlang over iroh P2P + TLS, with a bot powers SDK
0

Configure Feed

Select the types of activity you want to include in your feed.

erl-iroh / examples / two_bots.rs
1.6 kB 61 lines
1//! Spin up two bots in-process, connect over iroh, exchange a message. 2//! 3//! ```bash 4//! cargo run --example two_bots 5//! ``` 6 7use erl_iroh::bot::Bot; 8use erl_iroh::powers::Powers; 9use erl_iroh::term; 10use tracing_subscriber::EnvFilter; 11 12#[tokio::main] 13async fn main() -> erl_iroh::Result<()> { 14 tracing_subscriber::fmt() 15 .with_env_filter(EnvFilter::from_default_env().add_directive("erl_iroh=info".parse().unwrap())) 16 .init(); 17 18 let cookie = "two-bots-cookie"; 19 20 let alpha = Bot::builder("alpha") 21 .cookie(cookie) 22 .powers(Powers::all()) 23 .build() 24 .await?; 25 alpha.listen_iroh().await?; 26 27 // Give the accept loop a moment to arm. 28 tokio::time::sleep(std::time::Duration::from_millis(200)).await; 29 30 let beta = Bot::builder("beta") 31 .cookie(cookie) 32 .powers(Powers::all()) 33 .build() 34 .await?; 35 36 println!("alpha: {}", alpha.endpoint_id()); 37 println!("beta: {}", beta.endpoint_id()); 38 39 let handle = beta.connect_iroh(&alpha.endpoint_id_str()).await?; 40 println!( 41 "beta → alpha handshake ok (peer node name: {})", 42 handle.peer_name() 43 ); 44 45 // Fire a reg_send; alpha has no registered process, but the wire path works. 46 let _ = beta 47 .send( 48 handle.peer_name(), 49 "echo", 50 term::tuple2(term::atom("hi"), term::atom("from_beta")), 51 ) 52 .await; 53 54 println!("alpha peers: {:?}", alpha.peers().await); 55 println!("beta peers: {:?}", beta.peers().await); 56 println!("success"); 57 58 beta.shutdown().await; 59 alpha.shutdown().await; 60 Ok(()) 61}