Added CLI flags

This commit is contained in:
maciejhirsz 2017-02-16 14:41:33 +01:00
parent 451cf42452
commit ad8e3f0230
9 changed files with 49 additions and 16 deletions

View File

@ -29,6 +29,7 @@ mod handler;
use std::io::Write;
use std::sync::Arc;
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
use error::ServerError;
use handler::{IpfsHandler, Out};
use hyper::server::{Listening, Handler, Request, Response};
@ -128,8 +129,8 @@ fn write_chunk<W: Write>(transport: &mut W, progress: &mut usize, data: &[u8]) -
}
}
pub fn start_server(client: Arc<BlockChainClient>) -> Result<Listening, ServerError> {
let addr = "0.0.0.0:5001".parse().expect("can't fail on static input; qed");
pub fn start_server(port: u16, client: Arc<BlockChainClient>) -> Result<Listening, ServerError> {
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port);
Ok(
hyper::Server::http(&addr)?

View File

@ -68,7 +68,7 @@ user = "test_user"
pass = "test_pass"
[ipfs]
disable = true
enable = false
port = 5001
[mining]

View File

@ -39,7 +39,7 @@ user = "username"
pass = "password"
[ipfs]
disable = true
enable = false
port = 5001
[mining]

View File

@ -190,9 +190,9 @@ usage! {
flag_dapps_apis_all: bool = false, or |_| None,
// IPFS
flag_ipfs_off: bool = true,
or |c: &Config| otry!(c.ipfs).disable.clone(),
flag_ipfs_port: u16 = 5001u16,
flag_ipfs_api: bool = false,
or |c: &Config| otry!(c.ipfs).enable.clone(),
flag_ipfs_api_port: u16 = 5001u16,
or |c: &Config| otry!(c.ipfs).port.clone(),
// -- Sealing/Mining Options
@ -418,7 +418,7 @@ struct Dapps {
#[derive(Default, Debug, PartialEq, RustcDecodable)]
struct Ipfs {
disable: Option<bool>,
enable: Option<bool>,
port: Option<u16>,
}
@ -651,8 +651,8 @@ mod tests {
flag_dapps_apis_all: false,
// IPFS
flag_ipfs_off: true,
flag_ipfs_port: 5001u16,
flag_ipfs_api: false,
flag_ipfs_api_port: 5001u16,
// -- Sealing/Mining Options
flag_author: Some("0xdeadbeefcafe0000000000000000000000000001".into()),
@ -840,7 +840,7 @@ mod tests {
pass: Some("password".into())
}),
ipfs: Some(Ipfs {
disable: Some(true),
enable: Some(false),
port: Some(5001)
}),
mining: Some(Mining {

View File

@ -175,9 +175,9 @@ API and Console Options:
--dapps-apis-all Expose all possible RPC APIs on Dapps port.
WARNING: INSECURE. Used only for development.
(default: {flag_dapps_apis_all})
--no-ipfs Disable IPFS-compatible HTTP API. (default: {flag_ipfs_off})
--ipfs-port PORT Configure on which port the IPFS HTTP API should listen.
(default: {flag_ipfs_port})
--ipfs-api Enable IPFS-compatible HTTP API. (default: {flag_ipfs_api})
--ipfs-api-port PORT Configure on which port the IPFS HTTP API should listen.
(default: {flag_ipfs_api_port})
Sealing/Mining Options:
--author ADDRESS Specify the block author (aka "coinbase") address

View File

@ -37,6 +37,7 @@ use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig;
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
use dapps::Configuration as DappsConfiguration;
use ipfs::Configuration as IpfsConfiguration;
use signer::{Configuration as SignerConfiguration};
use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack};
use run::RunCmd;
@ -118,6 +119,7 @@ impl Configuration {
let geth_compatibility = self.args.flag_geth;
let ui_address = self.ui_port().map(|port| (self.ui_interface(), port));
let dapps_conf = self.dapps_config();
let ipfs_conf = self.ipfs_config();
let signer_conf = self.signer_config();
let format = self.format()?;
@ -342,6 +344,7 @@ impl Configuration {
ui_address: ui_address,
net_settings: self.network_settings(),
dapps_conf: dapps_conf,
ipfs_conf: ipfs_conf,
signer_conf: signer_conf,
dapp: self.dapp_to_open()?,
ui: self.args.cmd_ui,
@ -539,6 +542,13 @@ impl Configuration {
}
}
fn ipfs_config(&self) -> IpfsConfiguration {
IpfsConfiguration {
enabled: self.args.flag_ipfs_api,
port: self.args.flag_ipfs_api_port,
}
}
fn dapp_to_open(&self) -> Result<Option<String>, String> {
if !self.args.cmd_dapp {
return Ok(None);
@ -1101,6 +1111,7 @@ mod tests {
ui_address: Some(("127.0.0.1".into(), 8180)),
net_settings: Default::default(),
dapps_conf: Default::default(),
ipfs_conf: Default::default(),
signer_conf: Default::default(),
ui: false,
dapp: None,

16
parity/ipfs.rs Normal file
View File

@ -0,0 +1,16 @@
pub use parity_ipfs::start_server;
#[derive(Debug, PartialEq, Clone)]
pub struct Configuration {
pub enabled: bool,
pub port: u16,
}
impl Default for Configuration {
fn default() -> Self {
Configuration {
enabled: false,
port: 5001,
}
}
}

View File

@ -56,7 +56,7 @@ extern crate ethcore_signer;
extern crate ethcore_util as util;
extern crate ethsync;
extern crate parity_hash_fetch as hash_fetch;
extern crate parity_ipfs as ipfs;
extern crate parity_ipfs;
extern crate parity_reactor;
extern crate parity_updater as updater;
extern crate rpc_cli;
@ -88,6 +88,7 @@ mod cache;
mod cli;
mod configuration;
mod dapps;
mod ipfs;
mod deprecated;
mod dir;
mod helpers;

View File

@ -94,6 +94,7 @@ pub struct RunCmd {
pub ui_address: Option<(String, u16)>,
pub net_settings: NetworkSettings,
pub dapps_conf: dapps::Configuration,
pub ipfs_conf: ipfs::Configuration,
pub signer_conf: signer::Configuration,
pub dapp: Option<String>,
pub ui: bool,
@ -422,7 +423,10 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
let signer_server = signer::start(cmd.signer_conf.clone(), signer_deps)?;
// the ipfs server
let ipfs_server = ipfs::start_server(client.clone())?;
let ipfs_server = match cmd.ipfs_conf.enabled {
true => Some(ipfs::start_server(cmd.ipfs_conf.port, client.clone())?),
false => None,
};
// the informant
let informant = Arc::new(Informant::new(