From 4f99cfef95a517c772b64f577579548bd502407f Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Fri, 2 Dec 2022 13:39:57 -0800 Subject: [PATCH] more websocket progress --- client/src/client.rs | 9 ++++++--- client/src/rpc.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 108b323..4fdff70 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -24,6 +24,8 @@ pub struct Client { db: Option, fallback: Option, load_external_fallback: bool, + ws: bool, + http: bool, } impl Client where R: ExecutionRpc { @@ -45,6 +47,8 @@ impl Client where R: ExecutionRpc { db, fallback: config.fallback.clone(), load_external_fallback: config.load_external_fallback, + ws: config.with_ws, + http: config.with_http, }) } } @@ -52,9 +56,8 @@ impl Client where R: ExecutionRpc { impl Client { pub async fn start(&mut self) -> eyre::Result<()> { if let Some(rpc) = &mut self.rpc { - // We can start both ws and http servers since they only run if enabled in the config. - rpc.start_ws().await?; - rpc.start_http().await?; + if self.ws { rpc.start_ws().await?; } + if self.http { rpc.start_http().await?; } } if self.node.write().await.sync().await.is_err() { diff --git a/client/src/rpc.rs b/client/src/rpc.rs index fb1fb3b..5ca83e0 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -114,21 +114,23 @@ trait NetRpc { #[derive(Clone)] struct RpcInner where R: ExecutionRpc { node: Arc>>, - port: u16, + http_port: u16, + ws_port: u16, } impl From<&Rpc> for RpcInner where R: ExecutionRpc { fn from(rpc: &Rpc) -> Self { RpcInner { node: Arc::clone(&rpc.node), - port: rpc.port, + http_port: rpc.port, + ws_port: 4443, } } } impl RpcInner where R: ExecutionRpc { pub async fn start_http(&self) -> Result<(HttpServerHandle, SocketAddr)> { - let addr = format!("127.0.0.1:{}", self.port); + let addr = format!("127.0.0.1:{}", self.http_port); let server = HttpServerBuilder::default().build(addr).await?; let addr = server.local_addr()?; @@ -146,7 +148,7 @@ impl RpcInner where R: ExecutionRpc { } pub async fn start_ws(&self) -> Result<(WsServerHandle, SocketAddr)> { - let addr = format!("127.0.0.1:{}", self.port); + let addr = format!("127.0.0.1:{}", self.ws_port); let server = WsServerBuilder::default().build(addr).await?; let addr = server.local_addr()?;