more websocket progress
This commit is contained in:
parent
81e5a08828
commit
4f99cfef95
|
@ -24,6 +24,8 @@ pub struct Client<DB: Database, R: ExecutionRpc> {
|
||||||
db: Option<DB>,
|
db: Option<DB>,
|
||||||
fallback: Option<String>,
|
fallback: Option<String>,
|
||||||
load_external_fallback: bool,
|
load_external_fallback: bool,
|
||||||
|
ws: bool,
|
||||||
|
http: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Client<FileDB, R> where R: ExecutionRpc {
|
impl<R> Client<FileDB, R> where R: ExecutionRpc {
|
||||||
|
@ -45,6 +47,8 @@ impl<R> Client<FileDB, R> where R: ExecutionRpc {
|
||||||
db,
|
db,
|
||||||
fallback: config.fallback.clone(),
|
fallback: config.fallback.clone(),
|
||||||
load_external_fallback: config.load_external_fallback,
|
load_external_fallback: config.load_external_fallback,
|
||||||
|
ws: config.with_ws,
|
||||||
|
http: config.with_http,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,9 +56,8 @@ impl<R> Client<FileDB, R> where R: ExecutionRpc {
|
||||||
impl<DB: Database, R: ExecutionRpc> Client<DB, R> {
|
impl<DB: Database, R: ExecutionRpc> Client<DB, R> {
|
||||||
pub async fn start(&mut self) -> eyre::Result<()> {
|
pub async fn start(&mut self) -> eyre::Result<()> {
|
||||||
if let Some(rpc) = &mut self.rpc {
|
if let Some(rpc) = &mut self.rpc {
|
||||||
// We can start both ws and http servers since they only run if enabled in the config.
|
if self.ws { rpc.start_ws().await?; }
|
||||||
rpc.start_ws().await?;
|
if self.http { rpc.start_http().await?; }
|
||||||
rpc.start_http().await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.node.write().await.sync().await.is_err() {
|
if self.node.write().await.sync().await.is_err() {
|
||||||
|
|
|
@ -114,21 +114,23 @@ trait NetRpc {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct RpcInner<R> where R: ExecutionRpc {
|
struct RpcInner<R> where R: ExecutionRpc {
|
||||||
node: Arc<RwLock<Node<R>>>,
|
node: Arc<RwLock<Node<R>>>,
|
||||||
port: u16,
|
http_port: u16,
|
||||||
|
ws_port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> From<&Rpc<R>> for RpcInner<R> where R: ExecutionRpc {
|
impl<R> From<&Rpc<R>> for RpcInner<R> where R: ExecutionRpc {
|
||||||
fn from(rpc: &Rpc<R>) -> Self {
|
fn from(rpc: &Rpc<R>) -> Self {
|
||||||
RpcInner {
|
RpcInner {
|
||||||
node: Arc::clone(&rpc.node),
|
node: Arc::clone(&rpc.node),
|
||||||
port: rpc.port,
|
http_port: rpc.port,
|
||||||
|
ws_port: 4443,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> RpcInner<R> where R: ExecutionRpc {
|
impl<R> RpcInner<R> where R: ExecutionRpc {
|
||||||
pub async fn start_http(&self) -> Result<(HttpServerHandle, SocketAddr)> {
|
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 server = HttpServerBuilder::default().build(addr).await?;
|
||||||
|
|
||||||
let addr = server.local_addr()?;
|
let addr = server.local_addr()?;
|
||||||
|
@ -146,7 +148,7 @@ impl<R> RpcInner<R> where R: ExecutionRpc {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_ws(&self) -> Result<(WsServerHandle, SocketAddr)> {
|
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 server = WsServerBuilder::default().build(addr).await?;
|
||||||
|
|
||||||
let addr = server.local_addr()?;
|
let addr = server.local_addr()?;
|
||||||
|
|
Loading…
Reference in New Issue