Skip to content
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

refactor(iroh-cli)!: move net and node cli into iroh-node-util under the cli feature #2954

Merged
merged 49 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4d30302
refactor(iroh): extract docs RPC into iroh-docs
dignifiedquire Oct 30, 2024
a749306
remove dead code
dignifiedquire Oct 30, 2024
c9ff5cd
fix?
divagant-martian Oct 30, 2024
d301ed7
doc needs to be used with a different param
divagant-martian Oct 30, 2024
cea6d32
more fixes
divagant-martian Oct 30, 2024
ac5b0e0
it compiles again
dignifiedquire Oct 31, 2024
b4821d1
fixup cli
dignifiedquire Oct 31, 2024
940b28d
extract authors
dignifiedquire Oct 31, 2024
6fe36b3
Merge branch 'main' into refactor-extract-rpc-docs
rklaehn Nov 7, 2024
b47eb11
Update to latest quic-rpc
rklaehn Nov 7, 2024
f97acb7
fix docs
rklaehn Nov 7, 2024
f60c829
Merge branch 'main' into refactor-extract-rpc-docs
rklaehn Nov 7, 2024
2d671b6
fix default author in example
rklaehn Nov 7, 2024
69c7fb0
remove entry.content_bytes from examples
rklaehn Nov 7, 2024
06d49ca
Merge branch 'main' into refactor-extract-rpc-docs
rklaehn Nov 7, 2024
c911ff8
Merge branch 'main' into refactor-extract-rpc-docs
rklaehn Nov 7, 2024
c8a0e48
Add generics for docs engine
rklaehn Nov 7, 2024
377143e
Merge branch 'main' into refactor-extract-rpc-docs
rklaehn Nov 12, 2024
0b6042f
Go back to .authors(), at least for the client.
rklaehn Nov 12, 2024
11c15fd
Also export authors client
rklaehn Nov 12, 2024
8ab5f83
fix example
rklaehn Nov 12, 2024
97ffc0f
WIP
rklaehn Nov 13, 2024
3e04bd1
Merge branch 'main' into extract-node-rpc
rklaehn Nov 13, 2024
172c890
refactor: Add new crate iroh-node-util (name TBD)...
rklaehn Nov 14, 2024
8288006
Merge branch 'main' into extract-node-rpc
rklaehn Nov 14, 2024
3449d4e
Merge branch 'main' into extract-node-rpc
rklaehn Nov 19, 2024
4f9cf48
remove dead code and remove example
rklaehn Nov 19, 2024
06feab6
remove util methods
rklaehn Nov 19, 2024
8e1d4e9
add a LOICENSE
rklaehn Nov 19, 2024
807c11d
clippy
rklaehn Nov 19, 2024
28d8d96
use a trait
rklaehn Nov 19, 2024
59a62f2
WIP
rklaehn Nov 19, 2024
fa52a9c
wire up metrics
rklaehn Nov 19, 2024
e97e243
Add some docs for the trait to be implemented
rklaehn Nov 19, 2024
1d77a0b
fix docs
rklaehn Nov 19, 2024
1834989
fix dependency versions
rklaehn Nov 19, 2024
d4002c4
Add README.md and description
rklaehn Nov 19, 2024
09124d5
Add docs everywhere it makes sense...
rklaehn Nov 19, 2024
89b12cb
Add logging and config stuff from iroh-cli
rklaehn Nov 19, 2024
c89780c
format cargo.toml
rklaehn Nov 19, 2024
0db1759
Merge branch 'extract-node-rpc' into move-dirs-next-stuff
rklaehn Nov 19, 2024
fcb48da
Use everything possible from iroh-node-util
rklaehn Nov 19, 2024
8fb024e
fix docs
rklaehn Nov 19, 2024
a300ab6
try to get docs to work again with features
rklaehn Nov 19, 2024
2a3d840
Add cli submodule
rklaehn Nov 19, 2024
7c44b04
Merge branch 'main' into cli
rklaehn Nov 20, 2024
b61564c
move toplevel rpc commands into iroh-node-util as well
rklaehn Nov 20, 2024
c3f4986
Add comments about the various dependencies
rklaehn Nov 20, 2024
f9b8fd8
Merge branch 'main' into node-net-cli
rklaehn Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ iroh-blobs = { version = "0.28.1", features = ["cli"] }
iroh-docs = { version = "0.28.0", features = ["cli"] }
iroh-gossip = { version = "0.28.1", features = ["cli"] }
iroh-metrics = { version = "0.28.0" }
iroh-node-util = { path = "../iroh-node-util", features = ["config", "logging"] }
iroh-node-util = { path = "../iroh-node-util", features = ["config", "logging", "cli"] }
parking_lot = "0.12.1"
pkarr = { version = "2.2.0", default-features = false }
portable-atomic = "1"
Expand Down
2 changes: 1 addition & 1 deletion iroh-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ use crate::config::NodeConfig;

pub(crate) mod console;
pub(crate) mod doctor;
pub(crate) mod net;
pub(crate) mod rpc;
pub(crate) mod start;
pub(crate) use iroh_blobs::{cli as blobs, cli::tags};
pub(crate) use iroh_docs::{cli as docs, cli::authors};
pub(crate) use iroh_gossip::cli as gossip;
pub(crate) use iroh_node_util::cli::net;

/// iroh is a tool for building distributed apps.
///
Expand Down
43 changes: 5 additions & 38 deletions iroh-cli/src/commands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::Result;
use clap::Subcommand;
use iroh::client::Iroh;
use iroh_docs::cli::ConsoleEnv;
use iroh_node_util::cli::node::NodeCommands;

use super::{
authors::AuthorCommands, blobs::BlobCommands, docs::DocCommands, gossip::GossipCommands,
Expand Down Expand Up @@ -74,56 +75,22 @@ pub enum RpcCommands {
command: TagCommands,
},

/// Get statistics and metrics from the running node.
Stats,
/// Get status of the running node.
Status,
/// Shutdown the running node.
Shutdown {
/// Shutdown mode.
///
/// Hard shutdown will immediately terminate the process, soft shutdown will wait
/// for all connections to close.
#[clap(long, default_value_t = false)]
force: bool,
},
#[clap(flatten)]
Node(NodeCommands),
}

impl RpcCommands {
/// Run the RPC command given the iroh client and the console environment.
pub async fn run(self, iroh: &Iroh, env: &ConsoleEnv) -> Result<()> {
let node_id = || async move { iroh.net().node_addr().await };
match self {
Self::Net { command } => command.run(iroh).await,
Self::Net { command } => command.run(&iroh.net()).await,
Self::Blobs { command } => command.run(&iroh.blobs(), node_id().await?).await,
Self::Docs { command } => command.run(&iroh.docs(), &iroh.blobs(), env).await,
Self::Authors { command } => command.run(&iroh.authors(), env).await,
Self::Tags { command } => command.run(&iroh.tags()).await,
Self::Gossip { command } => command.run(&iroh.gossip()).await,
Self::Stats => {
let stats = iroh.node().stats().await?;
for (name, details) in stats.iter() {
println!(
"{:23} : {:>6} ({})",
name, details.value, details.description
);
}
Ok(())
}
Self::Shutdown { force } => {
iroh.node().shutdown(force).await?;
Ok(())
}
Self::Status => {
let response = iroh.node().status().await?;
println!("Listening addresses: {:#?}", response.listen_addrs);
println!("Node ID: {}", response.addr.node_id);
println!("Version: {}", response.version);
if let Some(addr) = response.rpc_addr {
println!("RPC Addr: {}", addr);
}
Ok(())
}
Self::Node(command) => command.run(&iroh.node()).await,
}
}
}
13 changes: 12 additions & 1 deletion iroh-node-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workspace = true

[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive"], optional = true }
tokio = "1"
iroh-net = { path = "../iroh-net" }
tempfile = "3"
Expand All @@ -29,16 +30,26 @@ serde-error = "0.1.3"
futures-lite = "2.5.0"
tracing = "0.1.40"

derive_more = { version = "1.0.0", features = ["display"], optional = true }
# config
dirs-next = { version = "2.0.0", optional = true }

# logging
derive_more = { version = "1.0.0", features = ["display"], optional = true }
rustyline = { version = "12.0.0", optional = true }
serde_with = { version = "3.7.0", optional = true }
tracing-appender = { version = "0.2.3", optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }

# cli
colored = { version = "2.0.4", optional = true }
comfy-table = { version = "7.0.1", optional = true }
time = { version = "0.3", features = ["formatting"], optional = true }
human-time = { version = "0.1.6", optional = true }

[features]
logging = ["dep:derive_more", "dep:serde_with", "dep:rustyline", "dep:tracing-appender", "dep:tracing-subscriber"]
config = ["dep:dirs-next"]
cli = ["dep:clap", "dep:colored", "dep:comfy-table", "dep:time", "dep:human-time"]

[package.metadata.docs.rs]
all-features = true
Expand Down
3 changes: 3 additions & 0 deletions iroh-node-util/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Cli commands.
pub mod net;
pub mod node;
24 changes: 10 additions & 14 deletions iroh-cli/src/commands/net.rs → iroh-node-util/src/cli/net.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Define the net subcommands.

use std::{net::SocketAddr, time::Duration};

use anyhow::Result;
Expand All @@ -8,17 +7,14 @@ use colored::Colorize;
use comfy_table::{presets::NOTHING, Cell, Table};
use futures_lite::{Stream, StreamExt};
use human_time::ToHumanTimeString;
use iroh::{
client::Iroh,
net::{
endpoint::{DirectAddrInfo, RemoteInfo},
NodeAddr, NodeId, RelayUrl,
},
use iroh_net::{
endpoint::{DirectAddrInfo, RemoteInfo},
NodeAddr, NodeId, RelayUrl,
};

/// Commands to manage the iroh network.
#[derive(Subcommand, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
#[allow(clippy::large_enum_variant, missing_docs)]
pub enum NetCommands {
/// Get information about the different remote nodes.
RemoteList,
Expand All @@ -38,10 +34,10 @@ pub enum NetCommands {

impl NetCommands {
/// Runs the net command given the iroh client.
pub async fn run(self, iroh: &Iroh) -> Result<()> {
pub async fn run(self, client: &crate::rpc::client::net::Client) -> Result<()> {
match self {
Self::RemoteList => {
let connections = iroh.net().remote_info_iter().await?;
let connections = client.remote_info_iter().await?;
let timestamp = time::OffsetDateTime::now_utc()
.format(&time::format_description::well_known::Rfc2822)
.unwrap_or_else(|_| String::from("failed to get current time"));
Expand All @@ -54,14 +50,14 @@ impl NetCommands {
);
}
Self::Remote { node_id } => {
let info = iroh.net().remote_info(node_id).await?;
let info = client.remote_info(node_id).await?;
match info {
Some(info) => println!("{}", fmt_info(info)),
None => println!("Not Found"),
}
}
Self::NodeAddr => {
let addr = iroh.net().node_addr().await?;
let addr = client.node_addr().await?;
println!("Node ID: {}", addr.node_id);
let relay = addr
.info
Expand All @@ -83,10 +79,10 @@ impl NetCommands {
if let Some(relay) = relay {
addr = addr.with_relay_url(relay);
}
iroh.net().add_node_addr(addr).await?;
client.add_node_addr(addr).await?;
}
Self::HomeRelay => {
let relay = iroh.net().home_relay().await?;
let relay = client.home_relay().await?;
let relay = relay
.map(|s| s.to_string())
.unwrap_or_else(|| "Not Available".to_string());
Expand Down
55 changes: 55 additions & 0 deletions iroh-node-util/src/cli/node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! Node commands
use clap::Subcommand;

use crate::rpc::client::node;

/// Commands to manage the iroh RPC.
#[derive(Subcommand, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum NodeCommands {
/// Get statistics and metrics from the running node.
Stats,
/// Get status of the running node.
Status,
/// Shutdown the running node.
Shutdown {
/// Shutdown mode.
///
/// Hard shutdown will immediately terminate the process, soft shutdown will wait
/// for all connections to close.
#[clap(long, default_value_t = false)]
force: bool,
},
}

impl NodeCommands {
/// Run the RPC command given the iroh client and the console environment.
pub async fn run(self, node: &node::Client) -> anyhow::Result<()> {
match self {
Self::Stats => {
let stats = node.stats().await?;
for (name, details) in stats.iter() {
println!(
"{:23} : {:>6} ({})",
name, details.value, details.description
);
}
Ok(())
}
Self::Shutdown { force } => {
node.shutdown(force).await?;
Ok(())
}
Self::Status => {
let response = node.status().await?;
println!("Listening addresses: {:#?}", response.listen_addrs);
println!("Node ID: {}", response.addr.node_id);
println!("Version: {}", response.version);
if let Some(addr) = response.rpc_addr {
println!("RPC Addr: {}", addr);
}
Ok(())
}
}
}
}
3 changes: 3 additions & 0 deletions iroh-node-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Utilities for building iroh nodes.
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![cfg_attr(iroh_docsrs, feature(doc_cfg))]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "cli")))]
#[cfg(feature = "cli")]
pub mod cli;
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "config")))]
#[cfg(feature = "config")]
pub mod config;
Expand Down
Loading