diff options
Diffstat (limited to 'examples/server.rs')
-rw-r--r-- | examples/server.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/examples/server.rs b/examples/server.rs index 4e6e8b39..90f01022 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -47,8 +47,7 @@ struct Client { partial_responses: HashMap<u64, PartialResponse>, } -type ClientMap = - HashMap<quiche::ConnectionId<'static>, (net::SocketAddr, Client)>; +type ClientMap = HashMap<quiche::ConnectionId<'static>, Client>; fn main() { let mut buf = [0; 65535]; @@ -118,8 +117,7 @@ fn main() { // Find the shorter timeout from all the active connections. // // TODO: use event loop that properly supports timers - let timeout = - clients.values().filter_map(|(_, c)| c.conn.timeout()).min(); + let timeout = clients.values().filter_map(|c| c.conn.timeout()).min(); poll.poll(&mut events, timeout).unwrap(); @@ -132,12 +130,12 @@ fn main() { if events.is_empty() { debug!("timed out"); - clients.values_mut().for_each(|(_, c)| c.conn.on_timeout()); + clients.values_mut().for_each(|c| c.conn.on_timeout()); break 'read; } - let (len, src) = match socket.recv_from(&mut buf) { + let (len, from) = match socket.recv_from(&mut buf) { Ok(v) => v, Err(e) => { @@ -177,7 +175,7 @@ fn main() { // Lookup a connection based on the packet's connection ID. If there // is no connection matching, create a new one. - let (_, client) = if !clients.contains_key(&hdr.dcid) && + let client = if !clients.contains_key(&hdr.dcid) && !clients.contains_key(&conn_id) { if hdr.ty != quiche::Type::Initial { @@ -194,7 +192,7 @@ fn main() { let out = &out[..len]; - if let Err(e) = socket.send_to(out, &src) { + if let Err(e) = socket.send_to(out, &from) { if e.kind() == std::io::ErrorKind::WouldBlock { debug!("send() would block"); break; @@ -217,7 +215,7 @@ fn main() { if token.is_empty() { warn!("Doing stateless retry"); - let new_token = mint_token(&hdr, &src); + let new_token = mint_token(&hdr, &from); let len = quiche::retry( &hdr.scid, @@ -231,7 +229,7 @@ fn main() { let out = &out[..len]; - if let Err(e) = socket.send_to(out, &src) { + if let Err(e) = socket.send_to(out, &from) { if e.kind() == std::io::ErrorKind::WouldBlock { debug!("send() would block"); break; @@ -242,7 +240,7 @@ fn main() { continue 'read; } - let odcid = validate_token(&src, token); + let odcid = validate_token(&from, token); // The token was not valid, meaning the retry failed, so // drop the packet. @@ -263,14 +261,15 @@ fn main() { debug!("New connection: dcid={:?} scid={:?}", hdr.dcid, scid); let conn = - quiche::accept(&scid, odcid.as_ref(), &mut config).unwrap(); + quiche::accept(&scid, odcid.as_ref(), from, &mut config) + .unwrap(); let client = Client { conn, partial_responses: HashMap::new(), }; - clients.insert(scid.clone(), (src, client)); + clients.insert(scid.clone(), client); clients.get_mut(&scid).unwrap() } else { @@ -281,8 +280,10 @@ fn main() { } }; + let recv_info = quiche::RecvInfo { from }; + // Process potentially coalesced packets. - let read = match client.conn.recv(pkt_buf) { + let read = match client.conn.recv(pkt_buf, recv_info) { Ok(v) => v, Err(e) => { @@ -329,9 +330,9 @@ fn main() { // Generate outgoing QUIC packets for all active connections and send // them on the UDP socket, until quiche reports that there are no more // packets to be sent. - for (peer, client) in clients.values_mut() { + for client in clients.values_mut() { loop { - let write = match client.conn.send(&mut out) { + let (write, send_info) = match client.conn.send(&mut out) { Ok(v) => v, Err(quiche::Error::Done) => { @@ -347,8 +348,7 @@ fn main() { }, }; - // TODO: coalesce packets. - if let Err(e) = socket.send_to(&out[..write], &peer) { + if let Err(e) = socket.send_to(&out[..write], &send_info.to) { if e.kind() == std::io::ErrorKind::WouldBlock { debug!("send() would block"); break; @@ -362,7 +362,7 @@ fn main() { } // Garbage collect closed connections. - clients.retain(|_, (_, ref mut c)| { + clients.retain(|_, ref mut c| { debug!("Collecting garbage"); if c.conn.is_closed() { |