-
Notifications
You must be signed in to change notification settings - Fork 237
refactor(iroh)!: Extract net and node rpc #2927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4d30302
a749306
c9ff5cd
d301ed7
cea6d32
ac5b0e0
b4821d1
940b28d
6fe36b3
b47eb11
f97acb7
f60c829
2d671b6
69c7fb0
06d49ca
c911ff8
c8a0e48
377143e
0b6042f
11c15fd
8ab5f83
97ffc0f
3e04bd1
172c890
8288006
3449d4e
4f9cf48
06feab6
8e1d4e9
807c11d
28d8d96
59a62f2
fa52a9c
e97e243
1d77a0b
1834989
d4002c4
09124d5
c89780c
0f6d98d
e6da450
e387c09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "iroh-node-util" | ||
description = "Utilities to build binaries containing an iroh-net endpoint" | ||
readme = "README.md" | ||
license = "MIT OR Apache-2.0" | ||
version = "0.28.0" | ||
edition = "2021" | ||
authors = ["n0 team"] | ||
repository = "https://github.com/n0-computer/iroh" | ||
keywords = ["quic", "networking", "holepunching", "p2p"] | ||
|
||
# Sadly this also needs to be updated in .github/workflows/ci.yml | ||
rust-version = "1.76" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
tokio = "1" | ||
iroh-net = { path = "../iroh-net" } | ||
tempfile = "3" | ||
strum = "0.26" | ||
nested_enum_utils = "0.1.0" | ||
quic-rpc = "0.15.0" | ||
quic-rpc-derive = "0.15.0" | ||
serde = "1" | ||
serde-error = "0.1.3" | ||
futures-lite = "2.5.0" | ||
tracing = "0.1.40" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# iroh-node-util | ||
|
||
This crate provides utilities to build binaries containing an iroh-net endpoint. | ||
|
||
# License | ||
|
||
This project is licensed under either of | ||
|
||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or | ||
http://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or | ||
http://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted | ||
for inclusion in this project by you, as defined in the Apache-2.0 license, | ||
shall be dual licensed as above, without any additional terms or conditions. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#![deny(missing_docs, rustdoc::broken_intra_doc_links)] | ||
//! Utilities for building iroh nodes. | ||
pub mod rpc; | ||
|
||
use std::path::PathBuf; | ||
|
||
use anyhow::Context; | ||
use iroh_net::key::SecretKey; | ||
use tokio::io::AsyncWriteExt; | ||
|
||
/// Loads a [`SecretKey`] from the provided file, or stores a newly generated one | ||
/// at the given location. | ||
pub async fn load_secret_key(key_path: PathBuf) -> anyhow::Result<SecretKey> { | ||
if key_path.exists() { | ||
let keystr = tokio::fs::read(key_path).await?; | ||
let secret_key = SecretKey::try_from_openssh(keystr).context("invalid keyfile")?; | ||
Ok(secret_key) | ||
} else { | ||
let secret_key = SecretKey::generate(); | ||
let ser_key = secret_key.to_openssh()?; | ||
|
||
// Try to canonicalize if possible | ||
let key_path = key_path.canonicalize().unwrap_or(key_path); | ||
let key_path_parent = key_path.parent().ok_or_else(|| { | ||
anyhow::anyhow!("no parent directory found for '{}'", key_path.display()) | ||
})?; | ||
tokio::fs::create_dir_all(&key_path_parent).await?; | ||
|
||
// write to tempfile | ||
let (file, temp_file_path) = tempfile::NamedTempFile::new_in(key_path_parent) | ||
.context("unable to create tempfile")? | ||
.into_parts(); | ||
let mut file = tokio::fs::File::from_std(file); | ||
file.write_all(ser_key.as_bytes()) | ||
.await | ||
.context("unable to write keyfile")?; | ||
file.flush().await?; | ||
drop(file); | ||
|
||
// move file | ||
tokio::fs::rename(temp_file_path, key_path) | ||
.await | ||
.context("failed to rename keyfile")?; | ||
|
||
Ok(secret_key) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! RPC client, server and protocol to control iroh-net endpoints and iroh nodes | ||
pub mod client; | ||
pub mod proto; | ||
pub mod server; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! Client to interact with iroh nodes and endpoints. | ||
use anyhow::Result; | ||
use futures_lite::{Stream, StreamExt}; | ||
|
||
pub mod net; | ||
pub mod node; | ||
|
||
fn flatten<T, E1, E2>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add this to quic-rpc? its used everywhere 🤣 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used? In the context of streaming responses, right? I can maybe add it somewhere in client as an util... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not super urgent, but I am adding it to quic-rpc: n0-computer/quic-rpc#120 |
||
s: impl Stream<Item = Result<Result<T, E1>, E2>>, | ||
) -> impl Stream<Item = Result<T>> | ||
where | ||
E1: std::error::Error + Send + Sync + 'static, | ||
E2: std::error::Error + Send + Sync + 'static, | ||
{ | ||
s.map(|res| match res { | ||
Ok(Ok(res)) => Ok(res), | ||
Ok(Err(err)) => Err(err.into()), | ||
Err(err) => Err(err.into()), | ||
}) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.