apply comments from code review

This commit is contained in:
Jane Lusby 2020-06-16 11:02:01 -07:00 committed by Henry de Valence
parent d09c339dc5
commit b0ecd019b6
2 changed files with 10 additions and 24 deletions

View File

@ -8,7 +8,7 @@ mod start;
mod version; mod version;
use self::{ use self::{
config::ConfigCmd, connect::ConnectCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartArgs, config::ConfigCmd, connect::ConnectCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartCmd,
version::VersionCmd, version::VersionCmd,
}; };
use crate::config::ZebradConfig; use crate::config::ZebradConfig;
@ -45,7 +45,7 @@ pub enum ZebradCmd {
/// The `start` subcommand /// The `start` subcommand
#[options(help = "start the application")] #[options(help = "start the application")]
Start(StartArgs), Start(StartCmd),
/// The `version` subcommand /// The `version` subcommand
#[options(help = "display version information")] #[options(help = "display version information")]

View File

@ -39,20 +39,13 @@ static GENESIS: BlockHeaderHash = BlockHeaderHash([
/// `start` subcommand /// `start` subcommand
#[derive(Command, Debug, Options)] #[derive(Command, Debug, Options)]
pub struct StartArgs { pub struct StartCmd {
/// Filter strings /// Filter strings
#[options(free)] #[options(free)]
filters: Vec<String>, filters: Vec<String>,
/// The address of the node to connect to.
#[options(
help = "The address of the node to connect to.",
default = "127.0.0.1:8233"
)]
addr: std::net::SocketAddr,
} }
impl StartArgs { impl StartCmd {
async fn start(&self) -> Result<(), Report> { async fn start(&self) -> Result<(), Report> {
info!(?self, "begin tower-based peer handling test stub"); info!(?self, "begin tower-based peer handling test stub");
@ -65,12 +58,7 @@ impl StartArgs {
1, 1,
); );
let mut config = app_config().network.clone(); let config = app_config().network.clone();
// Use a different listen addr so that we don't conflict with another local node.
config.listen_addr = "127.0.0.1:38233".parse()?;
// Connect only to the specified peer.
config.initial_mainnet_peers.insert(self.addr.to_string());
let state = zebra_state::in_memory::init(); let state = zebra_state::in_memory::init();
let (peer_set, _address_book) = zebra_network::init(config, node).await; let (peer_set, _address_book) = zebra_network::init(config, node).await;
let retry_peer_set = tower::retry::Retry::new(zebra_network::RetryErrors, peer_set.clone()); let retry_peer_set = tower::retry::Retry::new(zebra_network::RetryErrors, peer_set.clone());
@ -78,7 +66,7 @@ impl StartArgs {
let mut downloaded_block_heights = BTreeSet::<BlockHeight>::new(); let mut downloaded_block_heights = BTreeSet::<BlockHeight>::new();
downloaded_block_heights.insert(BlockHeight(0)); downloaded_block_heights.insert(BlockHeight(0));
let mut connect = ZebraNode { let mut connect = Core {
retry_peer_set, retry_peer_set,
peer_set, peer_set,
state, state,
@ -92,11 +80,9 @@ impl StartArgs {
} }
} }
impl Runnable for StartArgs { impl Runnable for StartCmd {
/// Start the application. /// Start the application.
fn run(&self) { fn run(&self) {
info!(connect.addr = ?self.addr);
let rt = app_writer() let rt = app_writer()
.state_mut() .state_mut()
.components .components
@ -119,7 +105,7 @@ impl Runnable for StartArgs {
} }
} }
impl config::Override<ZebradConfig> for StartArgs { impl config::Override<ZebradConfig> for StartCmd {
// Process the given command line options, overriding settings from // Process the given command line options, overriding settings from
// a configuration file using explicit flags taken from command-line // a configuration file using explicit flags taken from command-line
// arguments. // arguments.
@ -132,7 +118,7 @@ impl config::Override<ZebradConfig> for StartArgs {
} }
} }
struct ZebraNode<ZN, ZS> struct Core<ZN, ZS>
where where
ZN: Service<zebra_network::Request>, ZN: Service<zebra_network::Request>,
{ {
@ -145,7 +131,7 @@ where
downloaded_block_heights: BTreeSet<BlockHeight>, downloaded_block_heights: BTreeSet<BlockHeight>,
} }
impl<ZN, ZS> ZebraNode<ZN, ZS> impl<ZN, ZS> Core<ZN, ZS>
where where
ZN: Service<zebra_network::Request, Response = zebra_network::Response, Error = Error> ZN: Service<zebra_network::Request, Response = zebra_network::Response, Error = Error>
+ Send + Send