Single place where RPC apis are created.

This commit is contained in:
Tomasz Drwięga 2016-05-28 13:42:53 +02:00
parent 129ad0bbcb
commit 07399d377f
9 changed files with 201 additions and 129 deletions

View File

@ -52,6 +52,7 @@ extern crate serde_json;
extern crate jsonrpc_core; extern crate jsonrpc_core;
extern crate jsonrpc_http_server; extern crate jsonrpc_http_server;
extern crate parity_dapps; extern crate parity_dapps;
extern crate ethcore_rpc;
mod endpoint; mod endpoint;
mod apps; mod apps;
@ -66,6 +67,7 @@ use std::net::SocketAddr;
use std::collections::HashMap; use std::collections::HashMap;
use jsonrpc_core::{IoHandler, IoDelegate}; use jsonrpc_core::{IoHandler, IoDelegate};
use router::auth::{Authorization, NoAuth, HttpBasicAuth}; use router::auth::{Authorization, NoAuth, HttpBasicAuth};
use ethcore_rpc::Extendable;
static DAPPS_DOMAIN : &'static str = ".parity"; static DAPPS_DOMAIN : &'static str = ".parity";
@ -74,6 +76,12 @@ pub struct ServerBuilder {
handler: Arc<IoHandler>, handler: Arc<IoHandler>,
} }
impl Extendable for ServerBuilder {
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
self.handler.add_delegate(delegate);
}
}
impl ServerBuilder { impl ServerBuilder {
/// Construct new dapps server /// Construct new dapps server
pub fn new() -> Self { pub fn new() -> Self {
@ -82,11 +90,6 @@ impl ServerBuilder {
} }
} }
/// Add io delegate.
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
self.handler.add_delegate(delegate);
}
/// Asynchronously start server with no authentication, /// Asynchronously start server with no authentication,
/// returns result with `Server` handle on success or an error. /// returns result with `Server` handle on success or an error.
pub fn start_unsecure_http(&self, addr: &SocketAddr) -> Result<Server, ServerError> { pub fn start_unsecure_http(&self, addr: &SocketAddr) -> Result<Server, ServerError> {

View File

@ -17,14 +17,9 @@
use std::sync::Arc; use std::sync::Arc;
use std::str::FromStr; use std::str::FromStr;
use std::net::SocketAddr; use std::net::SocketAddr;
use ethcore::client::Client;
use ethsync::EthSync;
use ethminer::{Miner, ExternalMiner};
use util::RotatingLogger;
use util::panics::PanicHandler; use util::panics::PanicHandler;
use util::keys::store::AccountService;
use util::network_settings::NetworkSettings;
use die::*; use die::*;
use rpc_apis;
#[cfg(feature = "dapps")] #[cfg(feature = "dapps")]
pub use ethcore_dapps::Server as WebappServer; pub use ethcore_dapps::Server as WebappServer;
@ -41,13 +36,7 @@ pub struct Configuration {
pub struct Dependencies { pub struct Dependencies {
pub panic_handler: Arc<PanicHandler>, pub panic_handler: Arc<PanicHandler>,
pub client: Arc<Client>, pub apis: Arc<rpc_apis::Dependencies>,
pub sync: Arc<EthSync>,
pub secret_store: Arc<AccountService>,
pub miner: Arc<Miner>,
pub external_miner: Arc<ExternalMiner>,
pub logger: Arc<RotatingLogger>,
pub settings: Arc<NetworkSettings>,
} }
pub fn new(configuration: Configuration, deps: Dependencies) -> Option<WebappServer> { pub fn new(configuration: Configuration, deps: Dependencies) -> Option<WebappServer> {
@ -92,18 +81,11 @@ pub fn setup_dapps_server(
url: &SocketAddr, url: &SocketAddr,
auth: Option<(String, String)> auth: Option<(String, String)>
) -> WebappServer { ) -> WebappServer {
use ethcore_rpc::v1::*;
use ethcore_dapps as dapps; use ethcore_dapps as dapps;
let server = dapps::ServerBuilder::new(); let server = dapps::ServerBuilder::new();
server.add_delegate(Web3Client::new().to_delegate()); // TODO [ToDr] Specify apis
server.add_delegate(NetClient::new(&deps.sync).to_delegate()); let server = rpc_apis::setup_rpc(server, deps.apis.clone(), None);
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate());
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate());
let start_result = match auth { let start_result = match auth {
None => { None => {
server.start_unsecure_http(url) server.start_unsecure_http(url)

View File

@ -69,6 +69,7 @@ mod cli;
mod configuration; mod configuration;
mod migration; mod migration;
mod signer; mod signer;
mod rpc_apis;
use std::io::{Write, Read, BufReader, BufRead}; use std::io::{Write, Read, BufReader, BufRead};
use std::ops::Deref; use std::ops::Deref;
@ -197,8 +198,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
// Sync // Sync
let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone()); let sync = EthSync::register(service.network(), sync_config, client.clone(), miner.clone());
let dependencies = Arc::new(rpc::Dependencies { let deps_for_rpc_apis = Arc::new(rpc_apis::Dependencies {
panic_handler: panic_handler.clone(),
client: client.clone(), client: client.clone(),
sync: sync.clone(), sync: sync.clone(),
secret_store: account_service.clone(), secret_store: account_service.clone(),
@ -208,6 +208,11 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
settings: network_settings.clone(), settings: network_settings.clone(),
}); });
let dependencies = rpc::Dependencies {
panic_handler: panic_handler.clone(),
apis: deps_for_rpc_apis.clone(),
};
// Setup http rpc // Setup http rpc
let rpc_server = rpc::new_http(rpc::HttpConfiguration { let rpc_server = rpc::new_http(rpc::HttpConfiguration {
enabled: network_settings.rpc_enabled, enabled: network_settings.rpc_enabled,
@ -229,13 +234,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
pass: conf.args.flag_dapps_pass.clone(), pass: conf.args.flag_dapps_pass.clone(),
}, dapps::Dependencies { }, dapps::Dependencies {
panic_handler: panic_handler.clone(), panic_handler: panic_handler.clone(),
client: client.clone(), apis: deps_for_rpc_apis.clone(),
sync: sync.clone(),
secret_store: account_service.clone(),
miner: miner.clone(),
external_miner: external_miner.clone(),
logger: logger.clone(),
settings: network_settings.clone(),
}); });
// Set up a signer // Set up a signer
@ -244,11 +243,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
port: conf.args.flag_signer_port, port: conf.args.flag_signer_port,
}, signer::Dependencies { }, signer::Dependencies {
panic_handler: panic_handler.clone(), panic_handler: panic_handler.clone(),
client: client.clone(), apis: deps_for_rpc_apis.clone(),
sync: sync.clone(),
secret_store: account_service.clone(),
miner: miner.clone(),
external_miner: external_miner.clone(),
}); });
// Register IO handler // Register IO handler

View File

@ -15,19 +15,13 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use std::net::SocketAddr; use std::net::SocketAddr;
use ethcore::client::Client;
use ethsync::EthSync;
use ethminer::{Miner, ExternalMiner};
use util::RotatingLogger;
use util::panics::PanicHandler; use util::panics::PanicHandler;
use util::keys::store::AccountService;
use util::network_settings::NetworkSettings;
use die::*; use die::*;
use jsonipc; use jsonipc;
use rpc_apis;
#[cfg(feature = "rpc")] #[cfg(feature = "rpc")]
pub use ethcore_rpc::Server as RpcServer; pub use ethcore_rpc::Server as RpcServer;
@ -52,16 +46,10 @@ pub struct IpcConfiguration {
pub struct Dependencies { pub struct Dependencies {
pub panic_handler: Arc<PanicHandler>, pub panic_handler: Arc<PanicHandler>,
pub client: Arc<Client>, pub apis: Arc<rpc_apis::Dependencies>,
pub sync: Arc<EthSync>,
pub secret_store: Arc<AccountService>,
pub miner: Arc<Miner>,
pub external_miner: Arc<ExternalMiner>,
pub logger: Arc<RotatingLogger>,
pub settings: Arc<NetworkSettings>,
} }
pub fn new_http(conf: HttpConfiguration, deps: &Arc<Dependencies>) -> Option<RpcServer> { pub fn new_http(conf: HttpConfiguration, deps: &Dependencies) -> Option<RpcServer> {
if !conf.enabled { if !conf.enabled {
return None; return None;
} }
@ -78,59 +66,23 @@ pub fn new_http(conf: HttpConfiguration, deps: &Arc<Dependencies>) -> Option<Rpc
Some(setup_http_rpc_server(deps, &addr, conf.cors, apis)) Some(setup_http_rpc_server(deps, &addr, conf.cors, apis))
} }
pub fn new_ipc(conf: IpcConfiguration, deps: &Arc<Dependencies>) -> Option<jsonipc::Server> { pub fn new_ipc(conf: IpcConfiguration, deps: &Dependencies) -> Option<jsonipc::Server> {
if !conf.enabled { return None; } if !conf.enabled { return None; }
let apis = conf.apis.split(',').collect(); let apis = conf.apis.split(',').collect();
Some(setup_ipc_rpc_server(deps, &conf.socket_addr, apis)) Some(setup_ipc_rpc_server(deps, &conf.socket_addr, apis))
} }
fn setup_rpc_server(apis: Vec<&str>, deps: &Arc<Dependencies>) -> Server { fn setup_rpc_server(apis: Vec<&str>, deps: &Dependencies) -> Server {
use ethcore_rpc::v1::*; let apis = rpc_apis::from_str(apis);
let server = Server::new(); let server = Server::new();
let mut modules = BTreeMap::new(); rpc_apis::setup_rpc(server, deps.apis.clone(), Some(apis))
for api in apis.into_iter() {
match api {
"web3" => {
modules.insert("web3".to_owned(), "1.0".to_owned());
server.add_delegate(Web3Client::new().to_delegate());
},
"net" => {
modules.insert("net".to_owned(), "1.0".to_owned());
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
},
"eth" => {
modules.insert("eth".to_owned(), "1.0".to_owned());
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
},
"personal" => {
modules.insert("personal".to_owned(), "1.0".to_owned());
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate())
},
"ethcore" => {
modules.insert("ethcore".to_owned(), "1.0".to_owned());
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate())
},
"traces" => {
modules.insert("traces".to_owned(), "1.0".to_owned());
server.add_delegate(TracesClient::new(&deps.client).to_delegate())
},
_ => {
die!("{}: Invalid API name to be enabled.", api);
},
}
}
server.add_delegate(RpcClient::new(modules).to_delegate());
server
} }
#[cfg(not(feature = "rpc"))] #[cfg(not(feature = "rpc"))]
pub fn setup_http_rpc_server( pub fn setup_http_rpc_server(
_deps: Dependencies, _deps: &Dependencies,
_url: &SocketAddr, _url: &SocketAddr,
_cors_domain: Option<String>, _cors_domain: Vec<String>,
_apis: Vec<&str>, _apis: Vec<&str>,
) -> ! { ) -> ! {
die!("Your Parity version has been compiled without JSON-RPC support.") die!("Your Parity version has been compiled without JSON-RPC support.")
@ -138,27 +90,31 @@ pub fn setup_http_rpc_server(
#[cfg(feature = "rpc")] #[cfg(feature = "rpc")]
pub fn setup_http_rpc_server( pub fn setup_http_rpc_server(
dependencies: &Arc<Dependencies>, dependencies: &Dependencies,
url: &SocketAddr, url: &SocketAddr,
cors_domains: Vec<String>, cors_domains: Vec<String>,
apis: Vec<&str>, apis: Vec<&str>,
) -> RpcServer { ) -> RpcServer {
let server = setup_rpc_server(apis, dependencies); let server = setup_rpc_server(apis, dependencies);
let start_result = server.start_http(url, cors_domains); let start_result = server.start_http(url, cors_domains);
let deps = dependencies.clone(); let ph = dependencies.panic_handler.clone();
match start_result { match start_result {
Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err), Err(RpcServerError::IoError(err)) => die_with_io_error("RPC", err),
Err(e) => die!("RPC: {:?}", e), Err(e) => die!("RPC: {:?}", e),
Ok(server) => { Ok(server) => {
server.set_panic_handler(move || { server.set_panic_handler(move || {
deps.panic_handler.notify_all("Panic in RPC thread.".to_owned()); ph.notify_all("Panic in RPC thread.".to_owned());
}); });
server server
}, },
} }
} }
#[cfg(not(feature = "rpc"))]
pub fn setup_ipc_rpc_server(dependencies: &Arc<Dependencies>, addr: &str, apis: Vec<&str>) -> jsonipc::Server { pub fn setup_ipc_rpc_server(_dependencies: &Dependencies, _addr: &str, _apis: Vec<&str>) -> ! {
die!("Your Parity version has been compiled without JSON-RPC support.")
}
#[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); let server = setup_rpc_server(apis, dependencies);
match server.start_ipc(addr) { match server.start_ipc(addr) {
Err(jsonipc::Error::Io(io_error)) => die_with_io_error("RPC", io_error), Err(jsonipc::Error::Io(io_error)) => die_with_io_error("RPC", io_error),

136
parity/rpc_apis.rs Normal file
View File

@ -0,0 +1,136 @@
// 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/>.
use std::collections::BTreeMap;
use std::str::FromStr;
use std::sync::Arc;
use die::*;
use ethsync::EthSync;
use ethminer::{Miner, ExternalMiner};
use ethcore::client::Client;
use util::RotatingLogger;
use util::keys::store::AccountService;
use util::network_settings::NetworkSettings;
use ethcore_rpc::Extendable;
pub enum Api {
Web3,
Net,
Eth,
Personal,
Ethcore,
Traces,
Rpc,
}
pub enum ApiError {
UnknownApi(String)
}
impl FromStr for Api {
type Err = ApiError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
use self::Api::*;
match s {
"web3" => Ok(Web3),
"net" => Ok(Net),
"eth" => Ok(Eth),
"personal" => Ok(Personal),
"ethcore" => Ok(Ethcore),
"traces" => Ok(Traces),
"rpc" => Ok(Rpc),
e => Err(ApiError::UnknownApi(e.into())),
}
}
}
pub struct Dependencies {
pub client: Arc<Client>,
pub sync: Arc<EthSync>,
pub secret_store: Arc<AccountService>,
pub miner: Arc<Miner>,
pub external_miner: Arc<ExternalMiner>,
pub logger: Arc<RotatingLogger>,
pub settings: Arc<NetworkSettings>,
}
fn to_modules(apis: &[Api]) -> BTreeMap<String, String> {
let mut modules = BTreeMap::new();
for api in apis {
let (name, version) = match *api {
Api::Web3 => ("web3", "1.0"),
Api::Net => ("net", "1.0"),
Api::Eth => ("eth", "1.0"),
Api::Personal => ("personal", "1.0"),
Api::Ethcore => ("ethcore", "1.0"),
Api::Traces => ("traces", "1.0"),
Api::Rpc => ("rpc", "1.0"),
};
modules.insert(name.into(), version.into());
}
modules
}
pub fn from_str(apis: Vec<&str>) -> Vec<Api> {
apis.into_iter()
.map(Api::from_str)
.collect::<Result<Vec<Api>, ApiError>>()
.unwrap_or_else(|e| match e {
ApiError::UnknownApi(s) => die!("Unknown RPC API specified: {}", s),
})
}
pub fn setup_rpc<T: Extendable>(server: T, deps: Arc<Dependencies>, apis: Option<Vec<Api>>) -> T {
use ethcore_rpc::v1::*;
let apis = match apis {
Some(api) => api,
None => vec![Api::Web3, Api::Net, Api::Eth, Api::Personal, Api::Ethcore, Api::Traces, Api::Rpc],
};
for api in &apis {
match *api {
Api::Web3 => {
server.add_delegate(Web3Client::new().to_delegate());
},
Api::Net => {
server.add_delegate(NetClient::new(&deps.sync).to_delegate());
},
Api::Eth => {
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
},
Api::Personal => {
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate())
},
Api::Ethcore => {
server.add_delegate(EthcoreClient::new(&deps.miner, deps.logger.clone(), deps.settings.clone()).to_delegate())
},
Api::Traces => {
server.add_delegate(TracesClient::new(&deps.client).to_delegate())
},
Api::Rpc => {
let modules = to_modules(&apis);
server.add_delegate(RpcClient::new(modules).to_delegate());
}
}
}
server
}

View File

@ -15,12 +15,9 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::sync::Arc; use std::sync::Arc;
use ethcore::client::Client;
use ethsync::EthSync;
use ethminer::{Miner, ExternalMiner};
use util::keys::store::AccountService;
use util::panics::{PanicHandler, ForwardPanic}; use util::panics::{PanicHandler, ForwardPanic};
use die::*; use die::*;
use rpc_apis;
#[cfg(feature = "ethcore-signer")] #[cfg(feature = "ethcore-signer")]
use ethcore_signer as signer; use ethcore_signer as signer;
@ -36,11 +33,7 @@ pub struct Configuration {
pub struct Dependencies { pub struct Dependencies {
pub panic_handler: Arc<PanicHandler>, pub panic_handler: Arc<PanicHandler>,
pub client: Arc<Client>, pub apis: Arc<rpc_apis::Dependencies>,
pub sync: Arc<EthSync>,
pub secret_store: Arc<AccountService>,
pub miner: Arc<Miner>,
pub external_miner: Arc<ExternalMiner>,
} }
pub fn start(conf: Configuration, deps: Dependencies) -> Option<SignerServer> { pub fn start(conf: Configuration, deps: Dependencies) -> Option<SignerServer> {
@ -58,14 +51,9 @@ fn do_start(conf: Configuration, deps: Dependencies) -> SignerServer {
}); });
let start_result = { let start_result = {
use ethcore_rpc::v1::*;
let server = signer::ServerBuilder::new(); let server = signer::ServerBuilder::new();
server.add_delegate(Web3Client::new().to_delegate()); // TODO [ToDr] Setup APIS
server.add_delegate(NetClient::new(&deps.sync).to_delegate()); let server = rpc_apis::setup_rpc(server, deps.apis, None);
server.add_delegate(EthClient::new(&deps.client, &deps.sync, &deps.secret_store, &deps.miner, &deps.external_miner).to_delegate());
server.add_delegate(EthSigningUnsafeClient::new(&deps.client, &deps.secret_store, &deps.miner).to_delegate());
server.add_delegate(EthFilterClient::new(&deps.client, &deps.miner).to_delegate());
server.add_delegate(PersonalClient::new(&deps.secret_store, &deps.client, &deps.miner).to_delegate());
server.start(addr) server.start(addr)
}; };

View File

@ -40,11 +40,24 @@ use self::jsonrpc_core::{IoHandler, IoDelegate};
pub use jsonrpc_http_server::{Server, RpcServerError}; pub use jsonrpc_http_server::{Server, RpcServerError};
pub mod v1; pub mod v1;
/// An object that can be extended with `IoDelegates`
pub trait Extendable {
/// Add `Delegate` to this object.
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>);
}
/// Http server. /// Http server.
pub struct RpcServer { pub struct RpcServer {
handler: Arc<jsonrpc_core::io::IoHandler>, handler: Arc<jsonrpc_core::io::IoHandler>,
} }
impl Extendable for RpcServer {
/// Add io delegate.
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
self.handler.add_delegate(delegate);
}
}
impl RpcServer { impl RpcServer {
/// Construct new http server object. /// Construct new http server object.
pub fn new() -> RpcServer { pub fn new() -> RpcServer {
@ -53,11 +66,6 @@ impl RpcServer {
} }
} }
/// Add io delegate.
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
self.handler.add_delegate(delegate);
}
/// Start http server asynchronously and returns result with `Server` handle on success or an error. /// Start http server asynchronously and returns result with `Server` handle on success or an error.
pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> { pub fn start_http(&self, addr: &SocketAddr, cors_domains: Vec<String>) -> Result<Server, RpcServerError> {
let cors_domains = cors_domains.into_iter() let cors_domains = cors_domains.into_iter()

View File

@ -35,3 +35,5 @@ pub use self::personal::Personal;
pub use self::ethcore::Ethcore; pub use self::ethcore::Ethcore;
pub use self::traces::Traces; pub use self::traces::Traces;
pub use self::rpc::Rpc; pub use self::rpc::Rpc;

View File

@ -25,6 +25,7 @@ use std::sync::Arc;
use std::net::SocketAddr; use std::net::SocketAddr;
use util::panics::{PanicHandler, OnPanicListener, MayPanic}; use util::panics::{PanicHandler, OnPanicListener, MayPanic};
use jsonrpc_core::{IoHandler, IoDelegate}; use jsonrpc_core::{IoHandler, IoDelegate};
use rpc::Extendable;
mod session; mod session;
@ -57,6 +58,12 @@ impl Default for ServerBuilder {
} }
} }
impl Extendable for ServerBuilder {
fn add_delegate<D: Send + Sync + 'static>(&self, delegate: IoDelegate<D>) {
self.handler.add_delegate(delegate);
}
}
impl ServerBuilder { impl ServerBuilder {
/// Creates new `ServerBuilder` /// Creates new `ServerBuilder`
pub fn new() -> Self { pub fn new() -> Self {
@ -65,11 +72,6 @@ impl ServerBuilder {
} }
} }
/// Adds rpc delegate
pub fn add_delegate<D>(&self, delegate: IoDelegate<D>) where D: Send + Sync + 'static {
self.handler.add_delegate(delegate);
}
/// Starts a new `WebSocket` server in separate thread. /// Starts a new `WebSocket` server in separate thread.
/// Returns a `Server` handle which closes the server when droped. /// Returns a `Server` handle which closes the server when droped.
pub fn start(self, addr: SocketAddr) -> Result<Server, ServerError> { pub fn start(self, addr: SocketAddr) -> Result<Server, ServerError> {