mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 02:21:14 +00:00
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:
@@ -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" }
|
||||
|
||||
@@ -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")`.
|
||||
|
||||
Reference in New Issue
Block a user