Stratum IPC service (#1959)
* boot binaries reorg & helpers * stratum ipc service * spaces in cli
This commit is contained in:
@@ -4,6 +4,10 @@ name = "ethcore-stratum"
|
||||
version = "1.4.0"
|
||||
license = "GPL-3.0"
|
||||
authors = ["Ethcore <admin@ethcore.io>"]
|
||||
build = "build.rs"
|
||||
|
||||
[build-dependencies]
|
||||
ethcore-ipc-codegen = { path = "../ipc/codegen" }
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
@@ -14,6 +18,9 @@ ethcore-util = { path = "../util" }
|
||||
ethcore-devtools = { path = "../devtools" }
|
||||
lazy_static = "0.2"
|
||||
env_logger = "0.3"
|
||||
ethcore-ipc = { path = "../ipc/rpc" }
|
||||
semver = "0.2"
|
||||
ethcore-ipc-nano = { path = "../ipc/nano" }
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
||||
21
stratum/build.rs
Normal file
21
stratum/build.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
extern crate ethcore_ipc_codegen;
|
||||
|
||||
fn main() {
|
||||
ethcore_ipc_codegen::derive_ipc("src/traits.rs").unwrap();
|
||||
}
|
||||
@@ -20,6 +20,8 @@ extern crate json_tcp_server;
|
||||
extern crate jsonrpc_core;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate ethcore_util as util;
|
||||
extern crate ethcore_ipc as ipc;
|
||||
extern crate semver;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate mio;
|
||||
@@ -31,9 +33,16 @@ extern crate env_logger;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
mod traits;
|
||||
mod traits {
|
||||
//! Stratum ipc interfaces specification
|
||||
#![allow(dead_code, unused_assignments, unused_variables, missing_docs)] // codegen issues
|
||||
include!(concat!(env!("OUT_DIR"), "/traits.rs"));
|
||||
}
|
||||
|
||||
pub use traits::{JobDispatcher, PushWorkHandler, Error};
|
||||
pub use traits::{
|
||||
JobDispatcher, PushWorkHandler, Error, ServiceConfiguration,
|
||||
RemoteWorkHandler, RemoteJobDispatcher,
|
||||
};
|
||||
|
||||
use json_tcp_server::Server as JsonRpcServer;
|
||||
use jsonrpc_core::{IoHandler, Params, IoDelegate, to_value, from_params};
|
||||
@@ -133,8 +142,8 @@ impl Stratum {
|
||||
let mut job_que = self.job_que.write();
|
||||
let workers = self.workers.read();
|
||||
for socket_addr in job_que.drain() {
|
||||
if let Some(ref worker_id) = workers.get(&socket_addr) {
|
||||
let job_payload = self.dispatcher.job(worker_id);
|
||||
if let Some(worker_id) = workers.get(&socket_addr) {
|
||||
let job_payload = self.dispatcher.job(worker_id.to_owned());
|
||||
job_payload.map(
|
||||
|json| self.rpc_server.push_message(&socket_addr, json.as_bytes())
|
||||
);
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Stratum ipc interfaces specification
|
||||
|
||||
use std;
|
||||
use std::error::Error as StdError;
|
||||
use util::H256;
|
||||
use ipc::IpcConfig;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Binary)]
|
||||
pub enum Error {
|
||||
NoWork,
|
||||
NoWorkers,
|
||||
@@ -32,6 +32,8 @@ impl From<std::io::Error> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Ipc)]
|
||||
#[ipc(client_ident="RemoteJobDispatcher")]
|
||||
/// Interface that can provide pow/blockchain-specific responses for the clients
|
||||
pub trait JobDispatcher: Send + Sync {
|
||||
// json for initial client handshake
|
||||
@@ -39,9 +41,11 @@ pub trait JobDispatcher: Send + Sync {
|
||||
// json for difficulty dispatch
|
||||
fn difficulty(&self) -> Option<String> { None }
|
||||
// json for job update given worker_id (payload manager should split job!)
|
||||
fn job(&self, _worker_id: &str) -> Option<String> { None }
|
||||
fn job(&self, _worker_id: String) -> Option<String> { None }
|
||||
}
|
||||
|
||||
#[derive(Ipc)]
|
||||
#[ipc(client_ident="RemoteWorkHandler")]
|
||||
/// Interface that can handle requests to push job for workers
|
||||
pub trait PushWorkHandler: Send + Sync {
|
||||
/// push the same work package for all workers (`payload`: json of pow-specific set of work specification)
|
||||
@@ -50,3 +54,12 @@ pub trait PushWorkHandler: Send + Sync {
|
||||
/// push the work packages worker-wise (`payload`: json of pow-specific set of work specification)
|
||||
fn push_work(&self, payloads: Vec<String>) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
#[derive(Binary)]
|
||||
pub struct ServiceConfiguration {
|
||||
pub listen_addr: String,
|
||||
pub secret: Option<H256>,
|
||||
}
|
||||
|
||||
impl IpcConfig for PushWorkHandler { }
|
||||
impl IpcConfig for JobDispatcher { }
|
||||
|
||||
Reference in New Issue
Block a user