-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
56 lines (43 loc) · 1.6 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use quic::{terror, ServerConfig};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
fn main() {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::DEBUG)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let _ = run();
}
#[tokio::main]
async fn run() -> Result<(), terror::Error> {
let mut cert_path = std::env::current_dir().unwrap();
cert_path.push("cert");
cert_path.push("cert.der");
let mut key_path = std::env::current_dir().unwrap();
key_path.push("cert");
key_path.push("key.der");
let mut server = ServerConfig::new(
"[::1]:4433",
"/Users/christophbritsch/Library/Application Support/org.quinn.quinn-examples/cert.der",
"/Users/christophbritsch/Library/Application Support/org.quinn.quinn-examples/key.der",
)
.with_supported_protocols(vec!["hq-29".to_owned()])
.build()
.await?;
println!("{}", server.address);
let mut data = [0u8; 1024];
while let Some(connection) = server.accept().await {
println!("new connection!");
tokio::spawn(async move {
while let Ok((recv, _send)) = connection.accept_bidirectional_stream().await {
tokio::spawn(async move {
println!("NEW BIDIRECTIONAL STREAM FROM MAIN!");
while let Ok(Some(read)) = recv.read(&mut data).await {
println!("read stream data: {:?}", std::str::from_utf8(&data[..read]));
}
});
}
});
}
Ok(())
}