From 7475a7dab20e1169b0413160614dea64009c9971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Krzysztof=20Rekucki?= Date: Mon, 18 Nov 2024 14:19:27 +0100 Subject: [PATCH] + net-iroh missing cargo.toml --- core/net-iroh/Cargo.toml | 23 ++++++++++++++++++ core/net-iroh/examples/fake.rs | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 core/net-iroh/Cargo.toml create mode 100644 core/net-iroh/examples/fake.rs diff --git a/core/net-iroh/Cargo.toml b/core/net-iroh/Cargo.toml new file mode 100644 index 000000000..95d8fd2c3 --- /dev/null +++ b/core/net-iroh/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "net-iroh" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-rt.workspace = true +anyhow = "1.0.93" +bincode = "1.3.3" +futures = "0.3.31" +iroh-net = { version = "0.28.1", features = ['discovery-local-network', "iroh-relay"] } +rustyline = "14.0.0" +serde = { version = "1.0.214", features = ["derive"] } +ya-core-model = { workspace = true, features = ["net", "identity"] } +bytes = { version = "1" } +ethsign = { version = "0.8" } + + + +[lints] +workspace = true diff --git a/core/net-iroh/examples/fake.rs b/core/net-iroh/examples/fake.rs new file mode 100644 index 000000000..3d8ad54bf --- /dev/null +++ b/core/net-iroh/examples/fake.rs @@ -0,0 +1,43 @@ +use futures::prelude::*; +use iroh_net::discovery::dns::DnsDiscovery; +use iroh_net::discovery::local_swarm_discovery::LocalSwarmDiscovery; +use iroh_net::discovery::pkarr::dht::DhtDiscovery; +use iroh_net::discovery::pkarr::PkarrPublisher; +use iroh_net::discovery::ConcurrentDiscovery; +use iroh_net::key::SecretKey; +use iroh_net::Endpoint; + +#[actix_rt::main] +async fn main() -> anyhow::Result<()> { + let secret_key = SecretKey::generate(); + let id = secret_key.public(); + let dht = DhtDiscovery::builder() + .dht(true) + .secret_key(secret_key.clone()) + .build()?; + + let discovery = ConcurrentDiscovery::from_services(vec![ + Box::new(LocalSwarmDiscovery::new(id)?), + Box::new(dht), + ]); + let ep = Endpoint::builder() + .secret_key(secret_key) + .discovery(Box::new(discovery)) + .bind() + .await?; + + ep.discovery() + .unwrap() + .subscribe() + .unwrap() + .for_each(|di| { + eprintln!("di: {:?}", di); + async { () } + }) + .await; + + let addr = ep.node_addr().await?; + eprintln!("node addr = {:?}", addr); + + Ok(()) +}