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>,
|
||||
fallback: Option<String>,
|
||||
load_external_fallback: bool,
|
||||
ws: bool,
|
||||
http: bool,
|
||||
}
|
||||
|
||||
impl<R> Client<FileDB, R> where R: ExecutionRpc {
|
||||
|
@ -45,6 +47,8 @@ impl<R> Client<FileDB, R> 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<R> Client<FileDB, R> where R: ExecutionRpc {
|
|||
impl<DB: Database, R: ExecutionRpc> Client<DB, R> {
|
||||
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() {
|
||||
|
|
|
@ -114,21 +114,23 @@ trait NetRpc {
|
|||
#[derive(Clone)]
|
||||
struct RpcInner<R> where R: ExecutionRpc {
|
||||
node: Arc<RwLock<Node<R>>>,
|
||||
port: u16,
|
||||
http_port: u16,
|
||||
ws_port: u16,
|
||||
}
|
||||
|
||||
impl<R> From<&Rpc<R>> for RpcInner<R> where R: ExecutionRpc {
|
||||
fn from(rpc: &Rpc<R>) -> Self {
|
||||
RpcInner {
|
||||
node: Arc::clone(&rpc.node),
|
||||
port: rpc.port,
|
||||
http_port: rpc.port,
|
||||
ws_port: 4443,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> RpcInner<R> 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<R> RpcInner<R> 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()?;
|
||||
|
|
Loading…
Reference in New Issue