Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Windows build (#1253)
Browse files Browse the repository at this point in the history
* Networking refactoring

* Fixed typo

* Trace logging

* Updated dependencies for windows build

* Windows fixes

* use mio 0.5

* nix build

* Windows build fix

* style

* removed unused import

* ipc crate version bump

* ipc config for named pipes

* tweaks and fixes

* tweaks and fixes

* final version bump

* Fixed tests

* Disable color output on windows

* Added missing doc
  • Loading branch information
arkpar authored and gavofyork committed Jun 13, 2016
1 parent 4ef4819 commit 6b12334
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 197 deletions.
30 changes: 25 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ docopt = "0.6"
time = "0.1"
ctrlc = { git = "https://github.com/ethcore/rust-ctrlc.git" }
fdlimit = { path = "util/fdlimit" }
daemonize = "0.2"
num_cpus = "0.2"
number_prefix = "0.2"
rpassword = "0.2.1"
Expand All @@ -37,6 +36,9 @@ ethcore-ipc = { path = "ipc/rpc" }
json-ipc-server = { git = "https://github.com/ethcore/json-ipc-server.git" }
ansi_term = "0.7"

[target.'cfg(not(windows))'.dependencies]
daemonize = "0.2"

[dependencies.hyper]
version = "0.8"
default-features = false
Expand Down
24 changes: 20 additions & 4 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,14 @@ impl Configuration {
}

fn geth_ipc_path(&self) -> String {
if self.args.flag_testnet { path::ethereum::with_testnet("geth.ipc") }
else { path::ethereum::with_default("geth.ipc") }
.to_str().unwrap().to_owned()
if cfg!(windows) {
r"\\.\pipe\geth.ipc".to_owned()
}
else {
if self.args.flag_testnet { path::ethereum::with_testnet("geth.ipc") }
else { path::ethereum::with_default("geth.ipc") }
.to_str().unwrap().to_owned()
}
}

pub fn keys_iterations(&self) -> u32 {
Expand Down Expand Up @@ -358,7 +363,18 @@ impl Configuration {

fn ipc_path(&self) -> String {
if self.args.flag_geth { self.geth_ipc_path() }
else { Configuration::replace_home(&self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone())) }
else {
if cfg!(windows) {
r"\\.\pipe\parity.jsonrpc".to_owned()
}
else {
Configuration::replace_home(&self.args.flag_ipcpath.clone().unwrap_or(self.args.flag_ipc_path.clone()))
}
}
}

pub fn have_color(&self) -> bool {
!self.args.flag_no_color && !cfg!(windows)
}

pub fn signer_port(&self) -> Option<u16> {
Expand Down
33 changes: 22 additions & 11 deletions parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern crate log as rlog;
extern crate env_logger;
extern crate ctrlc;
extern crate fdlimit;
#[cfg(not(windows))]
extern crate daemonize;
extern crate time;
extern crate number_prefix;
Expand Down Expand Up @@ -86,7 +87,6 @@ use ethcore::service::ClientService;
use ethcore::spec::Spec;
use ethsync::EthSync;
use ethcore::miner::{Miner, MinerService, ExternalMiner};
use daemonize::Daemonize;
use migration::migrate;
use informant::Informant;

Expand Down Expand Up @@ -115,11 +115,7 @@ fn execute(conf: Configuration) {
execute_upgrades(&conf, &spec, &client_config);

if conf.args.cmd_daemon {
Daemonize::new()
.pid_file(conf.args.arg_pid_file.clone())
.chown_pid_file(true)
.start()
.unwrap_or_else(|e| die!("Couldn't daemonize; {}", e));
daemonize(&conf);
}

if conf.args.cmd_account {
Expand All @@ -145,6 +141,20 @@ fn execute(conf: Configuration) {
execute_client(conf, spec, client_config);
}

#[cfg(not(windows))]
fn daemonize(conf: &Configuration) {
use daemonize::Daemonize;
Daemonize::new()
.pid_file(conf.args.arg_pid_file.clone())
.chown_pid_file(true)
.start()
.unwrap_or_else(|e| die!("Couldn't daemonize; {}", e));
}

#[cfg(windows)]
fn daemonize(_conf: &Configuration) {
}

fn execute_upgrades(conf: &Configuration, spec: &Spec, client_config: &ClientConfig) {
match ::upgrade::upgrade(Some(&conf.path())) {
Ok(upgrades_applied) if upgrades_applied > 0 => {
Expand Down Expand Up @@ -228,6 +238,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)

// setup ipc rpc
let _ipc_server = rpc::new_ipc(conf.ipc_settings(), &dependencies);
debug!("IPC: {}", conf.ipc_settings());

if conf.args.flag_webapp { println!("WARNING: Flag -w/--webapp is deprecated. Dapps server is now on by default. Ignoring."); }
let dapps_server = dapps::new(dapps::Configuration {
Expand Down Expand Up @@ -255,7 +266,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
// Register IO handler
let io_handler = Arc::new(ClientIoHandler {
client: service.client(),
info: Informant::new(!conf.args.flag_no_color),
info: Informant::new(conf.have_color()),
sync: sync.clone(),
accounts: account_service.clone(),
});
Expand Down Expand Up @@ -375,8 +386,8 @@ fn execute_import(conf: Configuration) {
panic_handler.forward_from(&service);
let client = service.client();

let mut instream: Box<Read> = if let Some(f) = conf.args.arg_file {
let f = File::open(&f).unwrap_or_else(|_| die!("Cannot open the file given: {}", f));
let mut instream: Box<Read> = if let Some(ref f) = conf.args.arg_file {
let f = File::open(f).unwrap_or_else(|_| die!("Cannot open the file given: {}", f));
Box::new(f)
} else {
Box::new(::std::io::stdin())
Expand All @@ -386,7 +397,7 @@ fn execute_import(conf: Configuration) {
let mut first_read = 0;

let format = match conf.args.flag_format {
Some(x) => match x.deref() {
Some(ref x) => match x.deref() {
"binary" | "bin" => DataFormat::Binary,
"hex" => DataFormat::Hex,
x => die!("Invalid --format parameter given: {:?}", x),
Expand All @@ -407,7 +418,7 @@ fn execute_import(conf: Configuration) {
}
};

let informant = Informant::new(!conf.args.flag_no_color);
let informant = Informant::new(conf.have_color());

let do_import = |bytes| {
while client.queue_info().is_full() { sleep(Duration::from_secs(1)); }
Expand Down
26 changes: 20 additions & 6 deletions parity/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use util::panics::PanicHandler;
use die::*;
use jsonipc;
use rpc_apis;
use std::fmt;

#[cfg(feature = "rpc")]
pub use ethcore_rpc::Server as RpcServer;
Expand All @@ -44,6 +45,17 @@ pub struct IpcConfiguration {
pub apis: String,
}

impl fmt::Display for IpcConfiguration {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.enabled {
write!(f, "endpoint address [{}], api list [{}]", self.socket_addr, self.apis)
}
else {
write!(f, "disabled")
}
}
}

pub struct Dependencies {
pub panic_handler: Arc<PanicHandler>,
pub apis: Arc<rpc_apis::Dependencies>,
Expand All @@ -66,12 +78,6 @@ pub fn new_http(conf: HttpConfiguration, deps: &Dependencies) -> Option<RpcServe
Some(setup_http_rpc_server(deps, &addr, conf.cors, apis))
}

pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option<jsonipc::Server> {
if !conf.enabled { return None; }
let apis = conf.apis.split(',').collect();
Some(setup_ipc_rpc_server(deps, &conf.socket_addr, apis))
}

fn setup_rpc_server(apis: Vec<&str>, deps: &Dependencies) -> Server {
let apis = rpc_apis::from_str(apis);
let server = Server::new();
Expand Down Expand Up @@ -109,10 +115,18 @@ pub fn setup_http_rpc_server(
},
}
}

#[cfg(not(feature = "rpc"))]
pub fn setup_ipc_rpc_server(_dependencies: &Dependencies, _addr: &str, _apis: Vec<&str>) -> ! {
die!("Your Parity version has been compiled without JSON-RPC support.")
}

pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option<jsonipc::Server> {
if !conf.enabled { return None; }
let apis = conf.apis.split(',').collect();
Some(setup_ipc_rpc_server(deps, &conf.socket_addr, apis))
}

#[cfg(feature = "rpc")]
pub fn setup_ipc_rpc_server(dependencies: &Dependencies, addr: &str, apis: Vec<&str>) -> jsonipc::Server {
let server = setup_rpc_server(apis, dependencies);
Expand Down
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ log = "0.3"
env_logger = "0.3"
rustc-serialize = "0.3"
arrayvec = "0.3"
mio = "0.5.1"
mio = { git = "https://github.com/ethcore/mio", branch = "v0.5.x" }
nix ="0.5.0"
rand = "0.3.12"
time = "0.1.34"
Expand Down
2 changes: 1 addition & 1 deletion util/src/io/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<Message> IoService<Message> where Message: Send + Sync + Clone + 'static {
/// Starts IO event loop
pub fn start() -> Result<IoService<Message>, UtilError> {
let panic_handler = PanicHandler::new_in_arc();
let mut event_loop = EventLoop::new().unwrap();
let mut event_loop = EventLoop::new().unwrap();
let channel = event_loop.channel();
let panic = panic_handler.clone();
let thread = thread::spawn(move || {
Expand Down
8 changes: 8 additions & 0 deletions util/src/keys/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ pub struct KeyDirectory {
}

/// Restricts the permissions of given path only to the owner.
#[cfg(not(windows))]
pub fn restrict_permissions_owner(file_path: &Path) -> Result<(), i32> {
let cstr = ::std::ffi::CString::new(file_path.to_str().unwrap()).unwrap();
match unsafe { ::libc::chmod(cstr.as_ptr(), ::libc::S_IWUSR | ::libc::S_IRUSR) } {
Expand All @@ -474,6 +475,13 @@ pub fn restrict_permissions_owner(file_path: &Path) -> Result<(), i32> {
}
}

/// Restricts the permissions of given path only to the owner.
#[cfg(windows)]
pub fn restrict_permissions_owner(_file_path: &Path) -> Result<(), i32> {
//TODO: implement me
Ok(())
}

impl KeyDirectory {
/// Initializes new cache directory context with a given `path`
pub fn new(path: &Path) -> KeyDirectory {
Expand Down
Loading

0 comments on commit 6b12334

Please sign in to comment.