Stratum IPC service (#1959)

* boot binaries reorg & helpers

* stratum ipc service

* spaces in cli
This commit is contained in:
Nikolay Volf
2016-08-24 20:35:38 +04:00
committed by Gav Wood
parent b0d462c6c9
commit d631162440
11 changed files with 304 additions and 89 deletions

View File

@@ -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())
);

View File

@@ -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 { }