-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasmtime-cli): add UDS/WebTransport/QUIC support
- Loading branch information
1 parent
7b02ba9
commit 6492159
Showing
6 changed files
with
267 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use core::net::{Ipv6Addr, SocketAddr}; | ||
|
||
use anyhow::Context as _; | ||
use clap::Parser; | ||
use quinn::{ClientConfig, Endpoint}; | ||
use tracing::instrument; | ||
|
||
pub const DEFAULT_ADDR: &str = "[::1]:4433"; | ||
|
||
/// QUIC transport | ||
#[derive(Parser, Debug)] | ||
pub enum Command { | ||
Run(RunArgs), | ||
} | ||
|
||
/// Run a command component | ||
#[derive(Parser, Debug)] | ||
pub struct RunArgs { | ||
/// Invocation timeout | ||
#[arg(long, default_value = crate::DEFAULT_TIMEOUT)] | ||
timeout: humantime::Duration, | ||
|
||
/// Address to send import invocations to | ||
#[arg(long, default_value = DEFAULT_ADDR)] | ||
import_addr: SocketAddr, | ||
|
||
/// Server name to use for import connection | ||
#[arg(long)] | ||
import_san: String, | ||
|
||
/// Path or URL to Wasm command component | ||
workload: String, | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn handle_run( | ||
RunArgs { | ||
timeout, | ||
import_addr, | ||
import_san, | ||
ref workload, | ||
}: RunArgs, | ||
) -> anyhow::Result<()> { | ||
let mut ep = Endpoint::client((Ipv6Addr::UNSPECIFIED, 0).into()) | ||
.context("failed to create QUIC endpoint")?; | ||
// TODO: Allow TLS configuration via runtime flags | ||
// TODO: Support WebPKI | ||
ep.set_default_client_config(ClientConfig::with_platform_verifier()); | ||
let conn = ep | ||
.connect(import_addr, &import_san) | ||
.context("failed to connect using QUIC")?; | ||
let conn = conn.await.context("failed to establish QUIC connection")?; | ||
crate::handle_run( | ||
wrpc_transport_quic::Client::from(conn), | ||
(), | ||
*timeout, | ||
workload, | ||
) | ||
.await | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn run(cmd: Command) -> anyhow::Result<()> { | ||
match cmd { | ||
Command::Run(args) => handle_run(args).await, | ||
// TODO: Implement serving | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use std::path::PathBuf; | ||
use std::sync::Arc; | ||
|
||
use anyhow::Context as _; | ||
use clap::Parser; | ||
use tracing::{error, instrument}; | ||
|
||
/// Unix Domain Socket transport | ||
#[derive(Parser, Debug)] | ||
pub enum Command { | ||
Run(RunArgs), | ||
Serve(ServeArgs), | ||
} | ||
|
||
/// Run a command component | ||
#[derive(Parser, Debug)] | ||
pub struct RunArgs { | ||
/// Invocation timeout | ||
#[arg(long, default_value = crate::DEFAULT_TIMEOUT)] | ||
timeout: humantime::Duration, | ||
|
||
/// Path to send import invocations to | ||
#[arg(long)] | ||
import: PathBuf, | ||
|
||
/// Path or URL to Wasm command component | ||
workload: String, | ||
} | ||
|
||
/// Serve a reactor component | ||
#[derive(Parser, Debug)] | ||
pub struct ServeArgs { | ||
/// Invocation timeout | ||
#[arg(long, default_value = crate::DEFAULT_TIMEOUT)] | ||
timeout: humantime::Duration, | ||
|
||
/// Path to send import invocations to | ||
#[arg(long)] | ||
import: PathBuf, | ||
|
||
/// Path to listen for export invocations on | ||
#[arg(long)] | ||
export: PathBuf, | ||
|
||
/// Path or URL to Wasm command component | ||
workload: String, | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn handle_run( | ||
RunArgs { | ||
timeout, | ||
import, | ||
ref workload, | ||
}: RunArgs, | ||
) -> anyhow::Result<()> { | ||
crate::handle_run( | ||
wrpc_transport::unix::Client::from(import), | ||
(), | ||
*timeout, | ||
workload, | ||
) | ||
.await | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn handle_serve( | ||
ServeArgs { | ||
timeout, | ||
export, | ||
import, | ||
ref workload, | ||
}: ServeArgs, | ||
) -> anyhow::Result<()> { | ||
let lis = tokio::net::UnixListener::bind(&export).with_context(|| { | ||
format!( | ||
"failed to bind Unix socket listener on `{}`", | ||
export.display() | ||
) | ||
})?; | ||
let srv = Arc::new(wrpc_transport::Server::default()); | ||
let accept = tokio::spawn({ | ||
let srv = Arc::clone(&srv); | ||
async move { | ||
loop { | ||
if let Err(err) = srv.accept(&lis).await { | ||
error!(?err, "failed to accept Unix socket connection"); | ||
} | ||
} | ||
} | ||
}); | ||
let res = crate::handle_serve( | ||
srv.as_ref(), | ||
wrpc_transport::unix::Client::from(import), | ||
(), | ||
*timeout, | ||
workload, | ||
) | ||
.await; | ||
accept.abort(); | ||
res | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn run(cmd: Command) -> anyhow::Result<()> { | ||
match cmd { | ||
Command::Run(args) => handle_run(args).await, | ||
Command::Serve(args) => handle_serve(args).await, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use anyhow::Context as _; | ||
use clap::Parser; | ||
use tracing::instrument; | ||
use wtransport::{ClientConfig, Endpoint}; | ||
|
||
pub const DEFAULT_ADDR: &str = "https://localhost:4433"; | ||
|
||
/// WebTransport transport | ||
#[derive(Parser, Debug)] | ||
pub enum Command { | ||
Run(RunArgs), | ||
} | ||
|
||
/// Run a command component | ||
#[derive(Parser, Debug)] | ||
pub struct RunArgs { | ||
/// Invocation timeout | ||
#[arg(long, default_value = crate::DEFAULT_TIMEOUT)] | ||
timeout: humantime::Duration, | ||
|
||
/// Address to send import invocations to | ||
#[arg(long, default_value = DEFAULT_ADDR)] | ||
import: String, | ||
|
||
/// Path or URL to Wasm command component | ||
workload: String, | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn handle_run( | ||
RunArgs { | ||
timeout, | ||
import, | ||
ref workload, | ||
}: RunArgs, | ||
) -> anyhow::Result<()> { | ||
let ep = Endpoint::client(ClientConfig::default()) | ||
.context("failed to create WebTransport endpoint")?; | ||
// TODO: Allow TLS configuration via runtime flags | ||
// TODO: Support WebPKI | ||
let conn = ep | ||
.connect(import) | ||
.await | ||
.context("failed to connect using WebTransport")?; | ||
crate::handle_run( | ||
wrpc_transport_web::Client::from(conn), | ||
(), | ||
*timeout, | ||
workload, | ||
) | ||
.await | ||
} | ||
|
||
#[instrument(level = "trace", ret(level = "trace"))] | ||
pub async fn run(cmd: Command) -> anyhow::Result<()> { | ||
match cmd { | ||
Command::Run(args) => handle_run(args).await, | ||
// TODO: Implement serving | ||
} | ||
} |