2023-04-24 17:18:55 +00:00
|
|
|
use quiche::h3::webtransport;
|
|
|
|
use warp::transport;
|
|
|
|
|
|
|
|
use std::time;
|
2023-04-14 20:32:02 +00:00
|
|
|
|
|
|
|
use clap::Parser;
|
2023-04-24 17:18:55 +00:00
|
|
|
use env_logger;
|
2023-04-14 20:32:02 +00:00
|
|
|
|
|
|
|
/// Search for a pattern in a file and display the lines that contain it.
|
|
|
|
#[derive(Parser)]
|
|
|
|
struct Cli {
|
|
|
|
/// Listen on this address
|
|
|
|
#[arg(short, long, default_value = "127.0.0.1:4443")]
|
|
|
|
addr: String,
|
|
|
|
|
|
|
|
/// Use the certificate file at this path
|
|
|
|
#[arg(short, long, default_value = "../cert/localhost.crt")]
|
|
|
|
cert: String,
|
|
|
|
|
|
|
|
/// Use the private key at this path
|
|
|
|
#[arg(short, long, default_value = "../cert/localhost.key")]
|
|
|
|
key: String,
|
2023-04-24 17:18:55 +00:00
|
|
|
|
|
|
|
/// Use the media file at this path
|
|
|
|
#[arg(short, long, default_value = "../media/fragmented.mp4")]
|
|
|
|
media: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Connection {
|
|
|
|
webtransport: Option<webtransport::ServerSession>,
|
2023-04-13 17:20:17 +00:00
|
|
|
}
|
2023-04-14 20:32:02 +00:00
|
|
|
|
2023-04-24 17:18:55 +00:00
|
|
|
impl transport::App for Connection {
|
|
|
|
fn poll(&mut self, conn: &mut quiche::Connection, session: &mut webtransport::ServerSession) -> anyhow::Result<()> {
|
|
|
|
if !conn.is_established() {
|
|
|
|
// Wait until the handshake finishes
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.webtransport.is_none() {
|
|
|
|
self.webtransport = Some(webtransport::ServerSession::with_transport(conn)?)
|
|
|
|
}
|
|
|
|
|
|
|
|
let webtransport = self.webtransport.as_mut().unwrap();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn timeout(&self) -> Option<time::Duration> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
|
|
env_logger::init();
|
|
|
|
|
2023-04-14 20:32:02 +00:00
|
|
|
let args = Cli::parse();
|
|
|
|
|
2023-04-24 17:18:55 +00:00
|
|
|
let server_config = transport::Config{
|
2023-04-14 20:32:02 +00:00
|
|
|
addr: args.addr,
|
|
|
|
cert: args.cert,
|
|
|
|
key: args.key,
|
|
|
|
};
|
|
|
|
|
2023-04-24 17:18:55 +00:00
|
|
|
let mut server = transport::Server::<Connection>::new(server_config).unwrap();
|
|
|
|
server.run()
|
2023-04-14 20:32:02 +00:00
|
|
|
}
|