mirror of
https://github.com/tlsnotary/tlsn-js.git
synced 2026-02-19 11:55:09 -05:00
Run wstcp proxy automatically
This commit is contained in:
@@ -19,14 +19,7 @@ hyper-util = { version = "0.1", features = ["full"] }
|
||||
regex = "1.10.3"
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
sha1 = "0.10"
|
||||
tokio = { version = "1", features = [
|
||||
"rt",
|
||||
"rt-multi-thread",
|
||||
"macros",
|
||||
"net",
|
||||
"io-std",
|
||||
"fs",
|
||||
] }
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "net", "io-std", "fs", "process"] }
|
||||
tokio-util = { version = "0.7", features = ["compat"] }
|
||||
tower = { version = "0.4.12", features = ["make"] }
|
||||
tower-service = { version = "0.3" }
|
||||
@@ -39,7 +32,5 @@ tlsn = { git = "https://github.com/tlsnotary/tlsn.git", branch = "dev" }
|
||||
spansy = { git = "https://github.com/tlsnotary/tlsn-utils", package = "spansy", branch = "dev" }
|
||||
rangeset = "0.2.0"
|
||||
tower-util = "0.3.1"
|
||||
|
||||
[dev-dependencies]
|
||||
rustls = "0.23"
|
||||
webpki-roots = "0.26"
|
||||
wstcp = { git = "https://github.com/sile/wstcp.git", version = "0.2.1" }
|
||||
async-std = "1.13.2"
|
||||
|
||||
@@ -12,9 +12,10 @@ pub const SECRET: &str = "TLSNotary's private key 🤡";
|
||||
|
||||
/// Default server configuration
|
||||
pub struct Config {
|
||||
pub ws_host: String, // Address for WebSocket server
|
||||
pub ws_port: u16, // Port for WebSocket server
|
||||
pub server_uri: Uri, // URI of the server from which data is proven with TLSNotary
|
||||
pub ws_host: String, // Address for WebSocket server
|
||||
pub ws_port: u16, // Port for WebSocket server
|
||||
pub server_uri: Uri, // URI of the server from which data is proven with TLSNotary
|
||||
pub wstcp_proxy_port: u16, // Port for the wstcp proxy server
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -24,6 +25,7 @@ impl Default for Config {
|
||||
ws_port: 9816,
|
||||
server_uri:
|
||||
"https://raw.githubusercontent.com/tlsnotary/tlsn/refs/tags/v0.1.0-alpha.12/crates/server-fixture/server/src/data/1kb.json".parse::<Uri>().unwrap(),
|
||||
wstcp_proxy_port: 55688,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs};
|
||||
use tlsn_demo_server::{config::Config, run_ws_server};
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
|
||||
use wstcp::ProxyServer;
|
||||
|
||||
const TRACING_FILTER: &str = "INFO";
|
||||
|
||||
@@ -11,7 +13,41 @@ async fn main() -> Result<(), eyre::ErrReport> {
|
||||
.init();
|
||||
|
||||
let config: Config = Config::default();
|
||||
run_ws_server(&config).await?;
|
||||
|
||||
// Start wstcp proxy subprocess in background
|
||||
|
||||
// Run both servers in parallel
|
||||
let (ws_result, proxy_result) =
|
||||
tokio::join!(run_ws_server(&config), run_wstcp_proxy_async(&config));
|
||||
|
||||
// Handle results - if either fails, propagate the error
|
||||
ws_result?;
|
||||
proxy_result?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn run_wstcp_proxy_async(config: &Config) -> Result<(), eyre::ErrReport> {
|
||||
let bind_addr = SocketAddr::new(
|
||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||
config.wstcp_proxy_port,
|
||||
);
|
||||
let tcp_server_addr = format!("{}:443", config.server_domain())
|
||||
.to_socket_addrs()?
|
||||
.next()
|
||||
.ok_or_else(|| eyre::eyre!("Failed to resolve hostname"))?;
|
||||
|
||||
let listener = async_std::net::TcpListener::bind(bind_addr)
|
||||
.await
|
||||
.map_err(|e| eyre::eyre!("Failed to bind proxy listener: {}", e))?;
|
||||
|
||||
let proxy = ProxyServer::new(listener.incoming(), tcp_server_addr)
|
||||
.await
|
||||
.map_err(|e| eyre::eyre!("Failed to create proxy server: {}", e))?;
|
||||
|
||||
proxy
|
||||
.await
|
||||
.map_err(|e| eyre::eyre!("Proxy server error: {}", e))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user