fix: Only launch network endpoints for server commands

Fixes #669.
This commit is contained in:
teor 2020-07-16 17:04:42 +10:00 committed by Henry de Valence
parent c13907d1af
commit 49a3a7d6d1
2 changed files with 29 additions and 3 deletions

View File

@ -101,10 +101,19 @@ impl Application for ZebradApp {
metrics::MetricsEndpoint, tokio::TokioComponent, tracing::TracingEndpoint,
};
// `None` outputs zebrad usage information and exits
let command_is_server = match &command.command {
None => false,
Some(c) => c.is_server(),
};
let mut components = self.framework_components(command)?;
components.push(Box::new(TokioComponent::new()?));
components.push(Box::new(TracingEndpoint::new()?));
components.push(Box::new(MetricsEndpoint::new()?));
// Launch network endpoints for long-running commands
if command_is_server {
components.push(Box::new(TracingEndpoint::new()?));
components.push(Box::new(MetricsEndpoint::new()?));
}
self.state.components.register(components)
}

View File

@ -7,11 +7,14 @@ mod seed;
mod start;
mod version;
use self::ZebradCmd::*;
use self::{
connect::ConnectCmd, generate::GenerateCmd, revhex::RevhexCmd, seed::SeedCmd, start::StartCmd,
version::VersionCmd,
};
use crate::config::ZebradConfig;
use abscissa_core::{
config::Override, Command, Configurable, FrameworkError, Help, Options, Runnable,
};
@ -61,13 +64,27 @@ impl ZebradCmd {
/// If the command is `None`, then abscissa writes zebrad usage information
/// to stdout.
pub(crate) fn uses_stdout(&self) -> bool {
use ZebradCmd::*;
match self {
// List all the commands, so new commands have to make a choice here
Generate(_) | Help(_) | Revhex(_) | Version(_) => true,
Connect(_) | Seed(_) | Start(_) => false,
}
}
/// Returns true if this command is a server command.
///
/// For example, `Start` acts as a Zcash node.
///
/// Usage note: `abscissa_core::EntryPoint` stores an `Option<ZerbradCmd>`.
/// If the command is `None`, then abscissa prints zebrad's usage
/// information, then exits.
pub(crate) fn is_server(&self) -> bool {
match self {
// List all the commands, so new commands have to make a choice here
Connect(_) | Seed(_) | Start(_) => true,
Generate(_) | Help(_) | Revhex(_) | Version(_) => false,
}
}
}
/// This trait allows you to define how application configuration is loaded.