This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
More geth compatibility. #666
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ extern crate rpassword; | |
#[cfg(feature = "rpc")] | ||
extern crate ethcore_rpc as rpc; | ||
|
||
use std::net::{SocketAddr}; | ||
use std::net::{SocketAddr, IpAddr}; | ||
use std::env; | ||
use std::process::exit; | ||
use std::path::PathBuf; | ||
|
@@ -70,28 +70,26 @@ Parity. Ethereum Client. | |
Copyright 2015, 2016 Ethcore (UK) Limited | ||
|
||
Usage: | ||
parity daemon <pid-file> [options] [ --no-bootstrap | <enode>... ] | ||
parity daemon <pid-file> [options] | ||
parity account (new | list) | ||
parity [options] [ --no-bootstrap | <enode>... ] | ||
parity [options] | ||
|
||
Protocol Options: | ||
--chain CHAIN Specify the blockchain type. CHAIN may be either a JSON chain specification file | ||
or olympic, frontier, homestead, mainnet, morden, or testnet [default: homestead]. | ||
--testnet Equivalent to --chain testnet (geth-compatible). | ||
--networkid INDEX Override the network identifier from the chain we are on. | ||
--db-path PATH Specify the database & configuration directory path [default: $HOME/.parity] | ||
--pruning Client should prune the state/storage trie. | ||
-d --datadir PATH Specify the database & configuration directory path [default: $HOME/.parity] | ||
--keys-path PATH Specify the path for JSON key files to be found [default: $HOME/.web3/keys] | ||
--identity NAME Specify your node's name. | ||
|
||
Networking Options: | ||
--no-bootstrap Don't bother trying to connect to any nodes initially. | ||
--listen-address URL Specify the IP/port on which to listen for peers [default: 0.0.0.0:30304]. | ||
--public-address URL Specify the IP/port on which peers may connect. | ||
--address URL Equivalent to --listen-address URL --public-address URL. | ||
--port PORT Override the port on which the node should listen [default: 30303]. | ||
--peers NUM Try to maintain that many peers [default: 25]. | ||
--nat METHOD Specify method to use for determining public address. Must be one of: any, none, | ||
upnp, extip:(IP) [default: any]. | ||
--bootnodes NODES Specify additional comma-separated bootnodes. | ||
--no-bootstrap Don't bother trying to connect to standard bootnodes. | ||
--no-discovery Disable new peer discovery. | ||
--no-upnp Disable trying to figure out the correct public adderss over UPnP. | ||
--node-key KEY Specify node secret key, either as 64-character hex string or input to SHA3 operation. | ||
|
||
API and Console Options: | ||
|
@@ -101,16 +99,11 @@ API and Console Options: | |
--jsonrpc-cors URL Specify CORS header for JSON-RPC API responses [default: null]. | ||
--jsonrpc-apis APIS Specify the APIs available through the JSONRPC interface. APIS is a comma-delimited | ||
list of API name. Possible name are web3, eth and net. [default: web3,eth,net]. | ||
--rpc Equivalent to --jsonrpc (geth-compatible). | ||
--rpcaddr HOST Equivalent to --jsonrpc-addr HOST (geth-compatible). | ||
--rpcport PORT Equivalent to --jsonrpc-port PORT (geth-compatible). | ||
--rpcapi APIS Equivalent to --jsonrpc-apis APIS (geth-compatible). | ||
--rpccorsdomain URL Equivalent to --jsonrpc-cors URL (geth-compatible). | ||
|
||
Sealing/Mining Options: | ||
--author ADDRESS Specify the block author (aka "coinbase") address for sending block rewards | ||
from sealed blocks [default: 0037a6b811ffeb6e072da21179d11b1406371c63]. | ||
--extradata STRING Specify a custom extra-data for authored blocks, no more than 32 characters. | ||
--extra-data STRING Specify a custom extra-data for authored blocks, no more than 32 characters. | ||
|
||
Memory Footprint Options: | ||
--cache-pref-size BYTES Specify the prefered size of the blockchain cache in bytes [default: 16384]. | ||
|
@@ -119,6 +112,21 @@ Memory Footprint Options: | |
--cache MEGABYTES Set total amount of cache to use for the entire system, mutually exclusive with | ||
other cache options (geth-compatible). | ||
|
||
Geth-Compatibility Options | ||
--datadir PATH Equivalent to --db-path PATH. | ||
--testnet Equivalent to --chain testnet. | ||
--networkid INDEX Override the network identifier from the chain we are on. | ||
--rpc Equivalent to --jsonrpc. | ||
--rpcaddr HOST Equivalent to --jsonrpc-addr HOST. | ||
--rpcport PORT Equivalent to --jsonrpc-port PORT. | ||
--rpcapi APIS Equivalent to --jsonrpc-apis APIS. | ||
--rpccorsdomain URL Equivalent to --jsonrpc-cors URL. | ||
--maxpeers COUNT Equivalent to --peers COUNT. | ||
--nodekey KEY Equivalent to --node-key KEY. | ||
--nodiscover Equivalent to --no-discovery. | ||
--etherbase ADDRESS Equivalent to --author ADDRESS. | ||
--extradata STRING Equivalent to --extra-data STRING. | ||
|
||
Miscellaneous Options: | ||
-l --logging LOGGING Specify the logging level. | ||
-v --version Show information about version. | ||
|
@@ -132,22 +140,18 @@ struct Args { | |
cmd_new: bool, | ||
cmd_list: bool, | ||
arg_pid_file: String, | ||
arg_enode: Vec<String>, | ||
flag_chain: String, | ||
flag_testnet: bool, | ||
flag_datadir: String, | ||
flag_networkid: Option<String>, | ||
flag_db_path: String, | ||
flag_identity: String, | ||
flag_cache: Option<usize>, | ||
flag_keys_path: String, | ||
flag_bootnodes: Option<String>, | ||
flag_pruning: bool, | ||
flag_no_bootstrap: bool, | ||
flag_listen_address: String, | ||
flag_public_address: Option<String>, | ||
flag_address: Option<String>, | ||
flag_port: u16, | ||
flag_peers: usize, | ||
flag_no_discovery: bool, | ||
flag_no_upnp: bool, | ||
flag_nat: String, | ||
flag_node_key: Option<String>, | ||
flag_cache_pref_size: usize, | ||
flag_cache_max_size: usize, | ||
|
@@ -157,15 +161,24 @@ struct Args { | |
flag_jsonrpc_port: u16, | ||
flag_jsonrpc_cors: String, | ||
flag_jsonrpc_apis: String, | ||
flag_logging: Option<String>, | ||
flag_version: bool, | ||
// geth-compatibility... | ||
flag_nodekey: Option<String>, | ||
flag_nodiscover: bool, | ||
flag_maxpeers: Option<usize>, | ||
flag_author: String, | ||
flag_extra_data: Option<String>, | ||
flag_datadir: Option<String>, | ||
flag_extradata: Option<String>, | ||
flag_etherbase: Option<String>, | ||
flag_rpc: bool, | ||
flag_rpcaddr: Option<String>, | ||
flag_rpcport: Option<u16>, | ||
flag_rpccorsdomain: Option<String>, | ||
flag_rpcapi: Option<String>, | ||
flag_logging: Option<String>, | ||
flag_version: bool, | ||
flag_author: String, | ||
flag_extra_data: Option<String>, | ||
flag_testnet: bool, | ||
flag_networkid: Option<String>, | ||
} | ||
|
||
fn setup_log(init: &Option<String>) { | ||
|
@@ -245,15 +258,17 @@ impl Configuration { | |
} | ||
|
||
fn path(&self) -> String { | ||
self.args.flag_datadir.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()) | ||
let d = self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_db_path); | ||
d.replace("$HOME", env::home_dir().unwrap().to_str().unwrap()) | ||
} | ||
|
||
fn author(&self) -> Address { | ||
Address::from_str(&self.args.flag_author).unwrap_or_else(|_| die!("{}: Invalid address for --author. Must be 40 hex characters, without the 0x at the beginning.", self.args.flag_author)) | ||
let d = self.args.flag_etherbase.as_ref().unwrap_or(&self.args.flag_author); | ||
Address::from_str(d).unwrap_or_else(|_| die!("{}: Invalid address for --author. Must be 40 hex characters, without the 0x at the beginning.", self.args.flag_author)) | ||
} | ||
|
||
fn extra_data(&self) -> Bytes { | ||
match self.args.flag_extra_data { | ||
match self.args.flag_extradata.as_ref().or(self.args.flag_extra_data.as_ref()) { | ||
Some(ref x) if x.len() <= 32 => x.as_bytes().to_owned(), | ||
None => version_data(), | ||
Some(ref x) => { die!("{}: Extra data must be at most 32 characters.", x); } | ||
|
@@ -285,45 +300,40 @@ impl Configuration { | |
} | ||
|
||
fn init_nodes(&self, spec: &Spec) -> Vec<String> { | ||
if self.args.flag_no_bootstrap { Vec::new() } else { | ||
match self.args.arg_enode.len() { | ||
0 => spec.nodes().clone(), | ||
_ => self.args.arg_enode.iter().map(|s| Self::normalize_enode(s).unwrap_or_else(||die!("{}: Invalid node address format given for a boot node.", s))).collect(), | ||
} | ||
let mut r = if self.args.flag_no_bootstrap { Vec::new() } else { spec.nodes().clone() }; | ||
if let Some(ref x) = self.args.flag_bootnodes { | ||
r.extend(x.split(",").map(|s| Self::normalize_enode(s).unwrap_or_else(||die!("{}: Invalid node address format given for a boot node.", s)))); | ||
} | ||
r | ||
} | ||
|
||
#[cfg_attr(all(nightly, feature="dev"), allow(useless_format))] | ||
fn net_addresses(&self) -> (Option<SocketAddr>, Option<SocketAddr>) { | ||
let mut listen_address = None; | ||
let mut public_address = None; | ||
let listen_address = Some(SocketAddr::new(IpAddr::from_str("127.0.0.1").unwrap(), self.args.flag_port)); | ||
|
||
let host = if self.args.flag_nat.starts_with("extip:") { | ||
&self.args.flag_nat[6..] | ||
} else { | ||
"127.0.0.1" | ||
}; | ||
let public_address = Some(SocketAddr::new( | ||
IpAddr::from_str(&host).unwrap_or_else(|_| die!("{}: Invalid host given with --net extip:", host)), | ||
self.args.flag_port | ||
)); | ||
|
||
if let Some(ref a) = self.args.flag_address { | ||
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --address", a))); | ||
listen_address = public_address; | ||
} | ||
if listen_address.is_none() { | ||
listen_address = Some(SocketAddr::from_str(self.args.flag_listen_address.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --listen-address", self.args.flag_listen_address))); | ||
} | ||
if let Some(ref a) = self.args.flag_public_address { | ||
if public_address.is_some() { | ||
die!("Conflicting flags provided: --address and --public-address"); | ||
} | ||
public_address = Some(SocketAddr::from_str(a.as_ref()).unwrap_or_else(|_| die!("{}: Invalid listen/public address given with --public-address", a))); | ||
} | ||
(listen_address, public_address) | ||
} | ||
|
||
fn net_settings(&self, spec: &Spec) -> NetworkConfiguration { | ||
let mut ret = NetworkConfiguration::new(); | ||
ret.nat_enabled = !self.args.flag_no_upnp; | ||
ret.nat_enabled = self.args.flag_nat == "any" || self.args.flag_nat == "upnp"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and this? perhaps we should make an option from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If "any" means "auto" then setting |
||
ret.boot_nodes = self.init_nodes(spec); | ||
let (listen, public) = self.net_addresses(); | ||
ret.listen_address = listen; | ||
ret.public_address = public; | ||
ret.use_secret = self.args.flag_node_key.as_ref().map(|s| Secret::from_str(&s).unwrap_or_else(|_| s.sha3())); | ||
ret.discovery_enabled = !self.args.flag_no_discovery; | ||
ret.ideal_peers = self.args.flag_peers as u32; | ||
ret.discovery_enabled = !self.args.flag_no_discovery && !self.args.flag_nodiscover; | ||
ret.ideal_peers = self.args.flag_maxpeers.unwrap_or(self.args.flag_peers) as u32; | ||
let mut net_path = PathBuf::from(&self.path()); | ||
net_path.push("network"); | ||
ret.config_path = Some(net_path.to_str().unwrap().to_owned()); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arkpar does this look ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will listen on loopback interface only. Use
"0.0.0.0"
to listen on all interfaces