Add IPC support (#6348)

This is useful for both security and performance reasons. IPC is faster
than TCP, and it is subject to OS access controls.
This commit is contained in:
Demi Obenour
2020-06-16 10:14:12 +00:00
committed by GitHub
parent e99ff8ee96
commit e2f5e4bd74
10 changed files with 136 additions and 1 deletions
+1
View File
@@ -22,3 +22,4 @@ sp-runtime = { version = "2.0.0-rc3", path = "../../primitives/runtime" }
[target.'cfg(not(target_os = "unknown"))'.dependencies]
http = { package = "jsonrpc-http-server", version = "14.2.0" }
ws = { package = "jsonrpc-ws-server", version = "14.2.0" }
ipc = { version = "14.2.0", package = "jsonrpc-ipc-server" }
+19
View File
@@ -62,6 +62,8 @@ pub fn rpc_handler<M: PubSubMetadata>(
mod inner {
use super::*;
/// Type alias for ipc server
pub type IpcServer = ipc::Server;
/// Type alias for http server
pub type HttpServer = http::Server;
/// Type alias for ws server
@@ -89,6 +91,23 @@ mod inner {
.start_http(addr)
}
/// Start IPC server listening on given path.
///
/// **Note**: Only available if `not(target_os = "unknown")`.
pub fn start_ipc<M: pubsub::PubSubMetadata + Default>(
addr: &str,
io: RpcHandler<M>,
) -> io::Result<ipc::Server> {
let builder = ipc::ServerBuilder::new(io);
#[cfg(target_os = "unix")]
builder.set_security_attributes({
let security_attributes = ipc::SecurityAttributes::empty();
security_attributes.set_mode(0o600)?;
security_attributes
});
builder.start(addr)
}
/// Start WS server listening on given address.
///
/// **Note**: Only available if `not(target_os = "unknown")`.