2019-08-29 14:46:54 -07:00
|
|
|
//! Zebrad Subcommands
|
|
|
|
|
2019-10-18 17:04:41 -07:00
|
|
|
mod config;
|
Add a `connect` command for testing.
With `./src/zcashd -debug=net -logips=1`:
```
2019-09-19 15:24:38 Added connection to 127.0.0.1:35932 peer=1
2019-09-19 15:24:38 connection from 127.0.0.1:35932 accepted
2019-09-19 15:24:38 socket closed
2019-09-19 15:24:38 disconnecting peer=1
```
With `RUST_LOG="trace"`, `cargo run connect`:
```
Sep 19 08:24:24.530 INFO zebrad::commands::connect: version=Version { version: Version(170007), services: Services(1), timestamp: 2019-09-19T15:24:24.530059300Z, address_recv: (Services(1), V4(127.0.0.1:8233)), address_from: (Services(1), V4(127.0.0.1:9000)), nonce: Nonce(1), user_agent: "Zebra Connect", start_height: BlockHeight(0), relay: false }
Sep 19 08:24:24.530 TRACE Task::run: tokio_executor::threadpool::task: state=Running
Sep 19 08:24:24.530 DEBUG Task::run: tokio_net::driver::reactor: adding I/O source token=0
Sep 19 08:24:24.530 INFO zebrad::commands::connect: version_bytes="24e9276476657273696f6e000000000063000000cb30ab03179802000100000000000000a89d835d00000000010000000000000000000000000000000000ffff7f0000012029010000000000000000000000000000000000ffff7f000001232801000000000000000d5a6562726120436f6e6e6563740000000000"
Sep 19 08:24:24.530 TRACE Task::run: log: registering with poller
```
2019-09-11 22:30:32 -07:00
|
|
|
mod connect;
|
2020-02-18 11:55:55 -08:00
|
|
|
mod revhex;
|
2019-10-24 13:28:42 -07:00
|
|
|
mod seed;
|
2019-08-29 14:46:54 -07:00
|
|
|
mod start;
|
|
|
|
mod version;
|
|
|
|
|
2019-10-24 13:28:42 -07:00
|
|
|
use self::{
|
2020-06-16 11:02:01 -07:00
|
|
|
config::ConfigCmd, connect::ConnectCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartCmd,
|
2020-02-18 11:55:55 -08:00
|
|
|
version::VersionCmd,
|
2019-10-24 13:28:42 -07:00
|
|
|
};
|
2019-08-29 14:46:54 -07:00
|
|
|
use crate::config::ZebradConfig;
|
|
|
|
use abscissa_core::{
|
|
|
|
config::Override, Command, Configurable, FrameworkError, Help, Options, Runnable,
|
|
|
|
};
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
/// Zebrad Configuration Filename
|
|
|
|
pub const CONFIG_FILE: &str = "zebrad.toml";
|
|
|
|
|
|
|
|
/// Zebrad Subcommands
|
|
|
|
#[derive(Command, Debug, Options, Runnable)]
|
|
|
|
pub enum ZebradCmd {
|
2019-10-18 17:04:41 -07:00
|
|
|
/// The `config` subcommand
|
|
|
|
#[options(help = "generate a skeleton configuration")]
|
|
|
|
Config(ConfigCmd),
|
|
|
|
|
Add a `connect` command for testing.
With `./src/zcashd -debug=net -logips=1`:
```
2019-09-19 15:24:38 Added connection to 127.0.0.1:35932 peer=1
2019-09-19 15:24:38 connection from 127.0.0.1:35932 accepted
2019-09-19 15:24:38 socket closed
2019-09-19 15:24:38 disconnecting peer=1
```
With `RUST_LOG="trace"`, `cargo run connect`:
```
Sep 19 08:24:24.530 INFO zebrad::commands::connect: version=Version { version: Version(170007), services: Services(1), timestamp: 2019-09-19T15:24:24.530059300Z, address_recv: (Services(1), V4(127.0.0.1:8233)), address_from: (Services(1), V4(127.0.0.1:9000)), nonce: Nonce(1), user_agent: "Zebra Connect", start_height: BlockHeight(0), relay: false }
Sep 19 08:24:24.530 TRACE Task::run: tokio_executor::threadpool::task: state=Running
Sep 19 08:24:24.530 DEBUG Task::run: tokio_net::driver::reactor: adding I/O source token=0
Sep 19 08:24:24.530 INFO zebrad::commands::connect: version_bytes="24e9276476657273696f6e000000000063000000cb30ab03179802000100000000000000a89d835d00000000010000000000000000000000000000000000ffff7f0000012029010000000000000000000000000000000000ffff7f000001232801000000000000000d5a6562726120436f6e6e6563740000000000"
Sep 19 08:24:24.530 TRACE Task::run: log: registering with poller
```
2019-09-11 22:30:32 -07:00
|
|
|
/// The `connect` subcommand
|
|
|
|
#[options(help = "testing stub for dumping network messages")]
|
|
|
|
Connect(ConnectCmd),
|
2019-10-24 13:28:42 -07:00
|
|
|
|
2020-02-18 11:55:55 -08:00
|
|
|
/// The `help` subcommand
|
|
|
|
#[options(help = "get usage information")]
|
|
|
|
Help(Help<Self>),
|
|
|
|
|
|
|
|
/// The `revhex` subcommand
|
|
|
|
#[options(help = "reverses the endianness of a hex string, like a block or transaction hash")]
|
|
|
|
Revhex(RevhexCmd),
|
|
|
|
|
2019-10-24 13:28:42 -07:00
|
|
|
/// The `seed` subcommand
|
|
|
|
#[options(help = "dns seeder")]
|
|
|
|
Seed(SeedCmd),
|
2020-02-18 11:55:55 -08:00
|
|
|
|
|
|
|
/// The `start` subcommand
|
|
|
|
#[options(help = "start the application")]
|
2020-06-16 11:02:01 -07:00
|
|
|
Start(StartCmd),
|
2020-02-18 11:55:55 -08:00
|
|
|
|
|
|
|
/// The `version` subcommand
|
|
|
|
#[options(help = "display version information")]
|
|
|
|
Version(VersionCmd),
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// This trait allows you to define how application configuration is loaded.
|
|
|
|
impl Configurable<ZebradConfig> for ZebradCmd {
|
|
|
|
/// Location of the configuration file
|
|
|
|
fn config_path(&self) -> Option<PathBuf> {
|
2019-09-09 13:05:42 -07:00
|
|
|
let filename = std::env::current_dir().ok().map(|mut dir_path| {
|
|
|
|
dir_path.push(CONFIG_FILE);
|
|
|
|
dir_path
|
|
|
|
});
|
2019-08-29 14:46:54 -07:00
|
|
|
|
2019-09-09 13:05:42 -07:00
|
|
|
let if_exists = |f: PathBuf| if f.exists() { Some(f) } else { None };
|
|
|
|
|
2020-02-04 22:53:24 -08:00
|
|
|
filename.and_then(if_exists)
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Apply changes to the config after it's been loaded, e.g. overriding
|
|
|
|
/// values in a config file using command-line options.
|
|
|
|
///
|
|
|
|
/// This can be safely deleted if you don't want to override config
|
|
|
|
/// settings from command-line options.
|
2019-09-09 13:05:42 -07:00
|
|
|
fn process_config(&self, config: ZebradConfig) -> Result<ZebradConfig, FrameworkError> {
|
2019-08-29 14:46:54 -07:00
|
|
|
match self {
|
|
|
|
ZebradCmd::Start(cmd) => cmd.override_config(config),
|
|
|
|
_ => Ok(config),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|