Skip to content

Conversation

@jeroenvanmaanen
Copy link

I added the possibility to persists the node-key, so that the listener can be restarted after a reboot or container restart. I use this for a dumbpipe that forwards a port from my development laptop to a dev-container that serves a Dioxus-app.

Together with the similar persisted node-id in the Iroh-P2P enabled remote_server for Zed (courtesy of dignifiedquire) this enables me to remotely develop an app without having to copy and paste a new connection-string each time the dev-container is restarted. See also the definition of the dev-rust-dioxus container-image.

This is the first time I used snafu (I am used to anyhow). The error-structs and associated trait-impls are quite verbose. Is this idiomatic, of do you have suggestions on how to improve it?

@n0bot n0bot bot added this to iroh Oct 20, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Oct 20, 2025
@dignifiedquire
Copy link
Contributor

Thanks, we usually use openssh key format, for storing the keys, you can see how here: https://github.com/n0-computer/iroh-n0des/blob/main/src/client.rs#L64

@jeroenvanmaanen
Copy link
Author

Verified that the node-id can be persisted using a Linux remote and a MacOs client. The persisted file is now a PEM file with an OPENSSH PRIVATE KEY in it.

src/main.rs Outdated
.map(Cow::from) // Reference
.or_else(|| {
std::env::home_dir().map(|mut p| {
p.push(".auth");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be stored in a platform-specific app folder?
eg. dirs::config_dir().join("dumbpipe").join("dumbpipe.key")
with https://crates.io/crates/dirs

Ok(Some(result)) => return result,
Ok(None) => {}
Err(error) => {
error!("Error reading persisted dumbpipe key: [{:?}]", error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of logging the error and continuing with overwriting the keyfile, instead I'd propose to abort here and tell the user to delete the keyfile or set a different path. Silently overwriting the file is no good practice IMO, it might destroy an actual key that was copied to the wrong place or such.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting this. My intention was to continue with an ephemeral key without overwriting an existing file. I tried to continue with the normal operation of dumbpipe wherever I could, but maybe a fail-fast design would be beter. If I abort here, then it would be consistent to abort when there is a parse error when reconstructing the key or when the file can't be written to. What do you think most users of dumbpipe would prefer: permissive or fail-fast?

src/main.rs Outdated

#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum PersistError {
Copy link
Member

@Frando Frando Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because dumbpipe is an application, I think you can remove this error enum and instead just return n0_snafu::Error (n0_snafu::Error is similar to anyhow::Error)

flub added a commit that referenced this pull request Oct 25, 2025
It is scary when folks have to worry about secrets being printed.  #84
will solve the key persistence in a much better way anyway.
@jeroenvanmaanen
Copy link
Author

I created a crate iroh-persist. (I did not publish it yet.) It makes persisting Iroh node-ids quite trivial. What do you think of it? Shall I replace the current implementation by a call of a function in this crate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

3 participants