mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-25 04:35:17 +00:00
Use parametrized Endpoint instead of ClientStateStream type
This commit is contained in:
+8
-20
@@ -15,15 +15,15 @@ pub struct QuicStream {}
|
||||
|
||||
impl QuicStream {
|
||||
pub fn connect(server: &str, port: u16) -> ConnectFuture {
|
||||
let mut state = ClientStreamState::new();
|
||||
let packet = state.endpoint.initial(server);
|
||||
let mut endpoint = Endpoint::new(ClientTls::new(), Side::Client, None);
|
||||
let packet = endpoint.initial(server);
|
||||
let mut buf = Vec::with_capacity(65536);
|
||||
packet.encode(&state.endpoint.encode_key(&packet.header), &mut buf);
|
||||
packet.encode(&endpoint.encode_key(&packet.header), &mut buf);
|
||||
|
||||
let addr = (server, port).to_socket_addrs().unwrap().next().unwrap();
|
||||
let sock = UdpSocket::bind(&"0.0.0.0:0".parse().unwrap()).unwrap();
|
||||
ConnectFuture {
|
||||
state,
|
||||
endpoint,
|
||||
future: ConnectFutureState::InitialSent(sock.send_dgram(buf, &addr)),
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ impl QuicStream {
|
||||
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
pub struct ConnectFuture {
|
||||
state: ClientStreamState,
|
||||
endpoint: Endpoint<ClientTls>,
|
||||
future: ConnectFutureState,
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ impl Future for ConnectFuture {
|
||||
let packet = {
|
||||
let mut pbuf = &mut buf[..len];
|
||||
let decode = Packet::start_decode(pbuf);
|
||||
let key = self.state.endpoint.decode_key(&decode.header);
|
||||
let key = self.endpoint.decode_key(&decode.header);
|
||||
decode.finish(&key)
|
||||
};
|
||||
|
||||
let req = match self.state.endpoint.handle_handshake(&packet) {
|
||||
let req = match self.endpoint.handle_handshake(&packet) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
return Err(io::Error::new(
|
||||
@@ -73,7 +73,7 @@ impl Future for ConnectFuture {
|
||||
}
|
||||
};
|
||||
|
||||
req.encode(&self.state.endpoint.encode_key(&req.header), &mut buf);
|
||||
req.encode(&self.endpoint.encode_key(&req.header), &mut buf);
|
||||
new = Some(ConnectFutureState::InitialSent(sock.send_dgram(buf, &addr)));
|
||||
};
|
||||
if let Some(future) = new.take() {
|
||||
@@ -90,18 +90,6 @@ impl Future for ConnectFuture {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct ClientStreamState {
|
||||
pub(crate) endpoint: Endpoint<ClientTls>,
|
||||
}
|
||||
|
||||
impl ClientStreamState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
endpoint: Endpoint::new(ClientTls::new(), Side::Client, None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ConnectFutureState {
|
||||
InitialSent(SendDgram<Vec<u8>>),
|
||||
WaitingForResponse(RecvDgram<Vec<u8>>),
|
||||
|
||||
Reference in New Issue
Block a user