Skip to content

Commit

Permalink
client: switch to the modified version of quinn
Browse files Browse the repository at this point in the history
  • Loading branch information
EAimTY committed Mar 14, 2022
1 parent 16c95d2 commit f04ac1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bytes = "1.1"
futures-util = { version = "0.3", default-features = false }
getopts = "0.2"
parking_lot = "0.12"
quinn = "0.8"
quinn = { git = "https://github.com/EAimTY/quinn", branch = "0.8.x" }
rand = "0.8"
rustls = { version = "0.20", features = ["quic"], default-features = false }
thiserror = "1.0"
Expand Down
61 changes: 31 additions & 30 deletions client/src/relay/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use tokio::sync::{
use tuic_protocol::{Address as TuicAddress, Command as TuicCommand, Response as TuicResponse};

pub struct Connection {
pub controller: QuinnConnection,
pub assoc_map: HashMap<u32, MpscSender<(Bytes, Address)>>,
pub uni_streams: IncomingUniStreams,
pub datagrams: Datagrams,
controller: QuinnConnection,
assoc_map: HashMap<u32, MpscSender<(Bytes, Address)>>,
uni_streams: IncomingUniStreams,
datagrams: Datagrams,
}

impl Connection {
Expand Down Expand Up @@ -51,6 +51,32 @@ impl Connection {
addr: Address,
tx: OneshotSender<Option<(SendStream, RecvStream)>>,
) {
let conn = self.controller.clone();

tokio::spawn(async move {
let res: Result<()> = try {
let (mut send, mut recv) = conn.open_bi().await?;

let addr = TuicAddress::from(addr);
let cmd = TuicCommand::new_connect(addr);

cmd.write_to(&mut send).await?;

let resp = TuicResponse::read_from(&mut recv).await?;

if resp.is_succeeded() {
let _ = tx.send(Some((send, recv)));
return;
}
};

match res {
Ok(()) => (),
Err(err) => eprintln!("{err}"),
}

let _ = tx.send(None);
});
}

pub fn handle_associate(
Expand All @@ -62,7 +88,7 @@ impl Connection {
}

pub async fn is_closed(&self) -> bool {
self.controller.open_uni().await.is_err()
self.controller.is_closed()
}

async fn authenticate(conn: QuinnConnection, token_digest: [u8; 32]) {
Expand All @@ -83,28 +109,3 @@ impl Connection {

async fn listen_incoming() {}
}

async fn handle_command_connect(
mut send: SendStream,
mut recv: RecvStream,
addr: Address,
tx: OneshotSender<Option<(SendStream, RecvStream)>>,
) {
let addr = TuicAddress::from(addr);
let cmd = TuicCommand::new_connect(addr);

match cmd.write_to(&mut send).await {
Ok(()) => match TuicResponse::read_from(&mut recv).await {
Ok(res) => {
if res.is_succeeded() {
let _ = tx.send(Some((send, recv)));
return;
}
}
Err(err) => eprintln!("{err}"),
},
Err(err) => eprintln!("{err}"),
}

let _ = tx.send(None);
}

0 comments on commit f04ac1c

Please sign in to comment.