inbound/quic: fix an NAT issue caused by missing source address and stream ID

This commit is contained in:
eric committed 2021-06-25 15:00:12 +08:00
1 parent 489d80f738
commit 2b042bed83
4 files changed
+28 -4

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ impl Stream for Incoming {
Poll::Ready(
ready!(Pin::new(&mut self.acceptor).poll_next(cx)).map(|stream| {
let mut sess = self.sess.clone();
sess.stream_id = Some(stream.id());
sess.stream_id = Some(stream.id().into());
SingleInboundTransport::Stream(Box::new(SimpleProxyStream(stream)), sess)
}),
)
+11 -2
View File
@@ -10,7 +10,10 @@ use futures::{
Future,
};
use crate::proxy::{InboundDatagram, InboundTransport, SingleInboundTransport, UdpInboundHandler};
use crate::{
proxy::{InboundDatagram, InboundTransport, SingleInboundTransport, UdpInboundHandler},
session::Session,
};
use super::QuicProxyStream;
@@ -77,9 +80,15 @@ impl Stream for Incoming {
for (idx, new_conn) in self.new_conns.iter_mut().enumerate() {
match Pin::new(&mut new_conn.bi_streams).poll_next(cx) {
Poll::Ready(Some(Ok((send, recv)))) => {
let mut sess = Session {
source: new_conn.connection.remote_address(),
..Default::default()
};
// TODO Check whether the index suitable for this purpose.
sess.stream_id = Some(send.id().index());
stream.replace(SingleInboundTransport::Stream(
Box::new(QuicProxyStream { recv, send }),
Default::default(), // FIXME
sess,
));
break;
}
+1 -1
View File
@@ -25,7 +25,7 @@ impl std::fmt::Display for Network {
}
}
pub type StreamId = u16;
pub type StreamId = u64;
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct DatagramSource {
+15
View File
@@ -140,6 +140,21 @@ pub fn test_configs(configs: Vec<String>, socks_addr: &str, socks_port: u16) {
assert_eq!(msg, &buf[..n]);
assert_eq!(&raddr, &sess.destination);
// Test if we can handle a second UDP session. This can fail in stream
// transports if the stream ID has not been correctly set.
let dgram = handler.handle_udp(&sess, None).await.unwrap();
let (mut r, mut s) = dgram.split();
let msg = b"ghi";
let n = s.send_to(&msg.to_vec(), &sess.destination).await.unwrap();
assert_eq!(msg.len(), n);
let mut buf = vec![0u8; 2 * 1024];
let (n, raddr) = timeout(Duration::from_secs(1), r.recv_from(&mut buf))
.await
.unwrap()
.unwrap();
assert_eq!(msg, &buf[..n]);
assert_eq!(&raddr, &sess.destination);
// Cancel the background task.
bg_task_handle.abort();
};