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
+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")`.