This repository has been archived by the owner on Sep 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: First pass on a
bootstrap
CLI in noosphere-ns to spin up DHT
bootstrap nodes for the name system.
- Loading branch information
Showing
11 changed files
with
613 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
|
||
use clap::{Parser, Subcommand}; | ||
use serde::Deserialize; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser)] | ||
#[clap(name = "bootstrap_nns")] | ||
pub struct CLI { | ||
#[clap(subcommand)] | ||
pub command: CLICommand, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
pub enum CLICommand { | ||
/// Run DHT nodes in the Noosphere Name System. | ||
Run { | ||
/// The path to the bootstrap configuration, a TOML file, containing | ||
/// entries for keyname/port pairs. | ||
#[clap(short, long)] | ||
config: Option<PathBuf>, | ||
|
||
/// If no configuration path provided, the name of the Noosphere keypair to use | ||
/// stored in `~/.noosphere/keys/`. | ||
#[clap(short, long)] | ||
key: Option<String>, | ||
|
||
/// If no configuration path provided, the listening port of this DHT node. | ||
#[clap(short, long)] | ||
port: Option<u16>, | ||
}, | ||
|
||
/// Utility to create keys compatible with Noosphere. | ||
KeyGen { | ||
/// The name of the key to be stored in `~/.noosphere/keys/`. | ||
#[clap(short, long)] | ||
key: String, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct CLIConfigNode { | ||
pub key: String, | ||
pub port: Option<u16>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct CLIConfig { | ||
pub nodes: Vec<CLIConfigNode>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#[cfg(target_arch = "wasm32")] | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
Ok(()) | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod cli; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
mod runner; | ||
#[cfg(not(target_arch = "wasm32"))] | ||
mod utils; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
mod inner { | ||
pub use crate::cli::{CLICommand, CLI}; | ||
pub use crate::runner::{Runner, RunnerConfig}; | ||
pub use anyhow::{anyhow, Result}; | ||
pub use clap::Parser; | ||
pub use noosphere::key::{InsecureKeyStorage, KeyStorage}; | ||
pub use tokio; | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
use inner::*; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let key_storage = InsecureKeyStorage::new(&utils::get_keys_dir()?)?; | ||
|
||
match CLI::parse().command { | ||
command @ CLICommand::Run { .. } => { | ||
let mut runner = | ||
Runner::from(RunnerConfig::try_from_command(&key_storage, command).await?); | ||
utils::run_until_abort(runner.run()).await?; | ||
Ok(()) | ||
} | ||
CLICommand::KeyGen { key } => { | ||
if key_storage.require_key(&key).await.is_ok() { | ||
println!("Key \"{}\" already exists in `~/.noosphere/keys/`.", &key); | ||
} else { | ||
key_storage.create_key(&key).await?; | ||
println!("Key \"{}\" created in `~/.noosphere/keys/`.", &key); | ||
} | ||
Ok(()) | ||
} | ||
} | ||
} |
Oops, something went wrong.