default wallet receive to listen on 127.0.0.1 (#229)

* default wallet receive to listen on 127.0.0.1, optional flag on wallet command to listen on 0.0.0.0
* fix simulnet for new wallet port/interface config
This commit is contained in:
AntiochP 2017-11-02 16:19:22 -04:00 committed by Ignotus Peverell
parent 8a42a692ce
commit 17bf3c2702
4 changed files with 31 additions and 13 deletions

View file

@ -279,7 +279,7 @@ impl LocalServerContainer {
let mut wallet_config = WalletConfig::default(); let mut wallet_config = WalletConfig::default();
wallet_config.api_http_addr = format!("http://{}", url); wallet_config.api_listen_port = format!("{}", self.config.wallet_port);
wallet_config.check_node_api_http_addr = self.config.wallet_validating_node_url.clone(); wallet_config.check_node_api_http_addr = self.config.wallet_validating_node_url.clone();
wallet_config.data_file_dir = self.working_dir.clone(); wallet_config.data_file_dir = self.working_dir.clone();

View file

@ -174,6 +174,11 @@ fn main() {
.long("port") .long("port")
.help("Port on which to run the wallet receiver when in receiver mode") .help("Port on which to run the wallet receiver when in receiver mode")
.takes_value(true)) .takes_value(true))
.arg(Arg::with_name("external")
.short("e")
.long("external")
.help("Listen on 0.0.0.0 interface to allow external connections (default is 127.0.0.1)")
.takes_value(false))
.arg(Arg::with_name("api_server_address") .arg(Arg::with_name("api_server_address")
.short("a") .short("a")
.long("api_server_address") .long("api_server_address")
@ -338,8 +343,11 @@ fn wallet_command(wallet_args: &ArgMatches) {
let mut wallet_config = WalletConfig::default(); let mut wallet_config = WalletConfig::default();
if let Some(port) = wallet_args.value_of("port") { if let Some(port) = wallet_args.value_of("port") {
let default_ip = "0.0.0.0"; wallet_config.api_listen_port = port.to_string();
wallet_config.api_http_addr = format!("{}:{}", default_ip, port); }
if wallet_args.is_present("external") {
wallet_config.api_listen_interface = "0.0.0.0".to_string();
} }
if let Some(dir) = wallet_args.value_of("dir") { if let Some(dir) = wallet_args.value_of("dir") {

View file

@ -24,7 +24,7 @@ pub fn start_rest_apis(wallet_config: WalletConfig, keychain: Keychain) {
info!( info!(
LOGGER, LOGGER,
"Starting the Grin wallet receiving daemon at {}...", "Starting the Grin wallet receiving daemon at {}...",
wallet_config.api_http_addr wallet_config.api_listen_addr()
); );
let receive_tx_handler = WalletReceiver { let receive_tx_handler = WalletReceiver {
@ -43,7 +43,7 @@ pub fn start_rest_apis(wallet_config: WalletConfig, keychain: Keychain) {
let mut apis = ApiServer::new("/v1".to_string()); let mut apis = ApiServer::new("/v1".to_string());
apis.register_handler(router); apis.register_handler(router);
apis.start(wallet_config.api_http_addr).unwrap_or_else(|e| { apis.start(wallet_config.api_listen_addr()).unwrap_or_else(|e| {
error!(LOGGER, "Failed to start Grin wallet receiver: {}.", e); error!(LOGGER, "Failed to start Grin wallet receiver: {}.", e);
}); });
} }

View file

@ -153,10 +153,13 @@ impl From<hyper::error::UriError> for Error {
pub struct WalletConfig { pub struct WalletConfig {
// Whether to run a wallet // Whether to run a wallet
pub enable_wallet: bool, pub enable_wallet: bool,
// The api address that this api server (i.e. this wallet) will run // The api interface/ip_address that this api server (i.e. this wallet) will run
pub api_http_addr: String, // by default this is 127.0.0.1 (and will not accept connections from external clients)
// The api address of a running server node, against which transaction inputs will be checked pub api_listen_interface: String,
// during send // The port this wallet will run on
pub api_listen_port: String,
// The api address of a running server node against which transaction inputs
// will be checked during send
pub check_node_api_http_addr: String, pub check_node_api_http_addr: String,
// The directory in which wallet files are stored // The directory in which wallet files are stored
pub data_file_dir: String, pub data_file_dir: String,
@ -166,13 +169,20 @@ impl Default for WalletConfig {
fn default() -> WalletConfig { fn default() -> WalletConfig {
WalletConfig { WalletConfig {
enable_wallet: false, enable_wallet: false,
api_http_addr: "0.0.0.0:13415".to_string(), api_listen_interface: "127.0.0.1".to_string(),
api_listen_port: "13415".to_string(),
check_node_api_http_addr: "http://127.0.0.1:13413".to_string(), check_node_api_http_addr: "http://127.0.0.1:13413".to_string(),
data_file_dir: ".".to_string(), data_file_dir: ".".to_string(),
} }
} }
} }
impl WalletConfig {
pub fn api_listen_addr(&self) -> String {
format!("{}:{}", self.api_listen_interface, self.api_listen_port)
}
}
/// Status of an output that's being tracked by the wallet. Can either be /// Status of an output that's being tracked by the wallet. Can either be
/// unconfirmed, spent, unspent, or locked (when it's been used to generate /// unconfirmed, spent, unspent, or locked (when it's been used to generate
/// a transaction but we don't have confirmation that the transaction was /// a transaction but we don't have confirmation that the transaction was