1
0

add packet size option for UDP relay mode Quic

This commit is contained in:
EAimTY 2022-06-25 20:17:00 +09:00
parent 5e6ab51e5d
commit 7393397632
4 changed files with 32 additions and 2 deletions

View File

@ -36,6 +36,7 @@ pub struct Config {
pub heartbeat_interval: u64,
pub reduce_rtt: bool,
pub request_timeout: u64,
pub max_udp_relay_packet_size: usize,
pub local_addr: SocketAddr,
pub socks5_auth: Arc<dyn Auth + Send + Sync>,
pub log_level: LevelFilter,
@ -105,6 +106,7 @@ impl Config {
let heartbeat_interval = raw.relay.heartbeat_interval;
let reduce_rtt = raw.relay.reduce_rtt;
let request_timeout = raw.relay.request_timeout;
let max_udp_relay_packet_size = raw.relay.max_udp_relay_packet_size;
let local_addr = SocketAddr::from((raw.local.ip, raw.local.port.unwrap()));
@ -127,6 +129,7 @@ impl Config {
heartbeat_interval,
reduce_rtt,
request_timeout,
max_udp_relay_packet_size,
local_addr,
socks5_auth,
log_level,
@ -181,6 +184,9 @@ struct RawRelayConfig {
#[serde(default = "default::request_timeout")]
request_timeout: u64,
#[serde(default = "default::max_udp_relay_packet_size")]
max_udp_relay_packet_size: usize,
}
#[derive(Deserialize)]
@ -220,6 +226,7 @@ impl Default for RawRelayConfig {
disable_sni: default::disable_sni(),
reduce_rtt: default::reduce_rtt(),
request_timeout: default::request_timeout(),
max_udp_relay_packet_size: default::max_udp_relay_packet_size(),
}
}
}
@ -319,6 +326,13 @@ impl RawConfig {
"REQUEST_TIMEOUT",
);
opts.optopt(
"",
"max-udp-relay-packet-size",
"UDP relay mode QUIC can transmit UDP packets larger than the MTU. Set this to a higher value allows inbound to receive larger UDP packet. Default: 1500",
"MAX_UDP_RELAY_PACKET_SIZE",
);
opts.optopt(
"",
"local-port",
@ -461,6 +475,10 @@ impl RawConfig {
raw.relay.request_timeout = timeout.parse()?;
};
if let Some(size) = matches.opt_str("max-udp-relay-packet-size") {
raw.relay.max_udp_relay_packet_size = size.parse()?;
};
if let Some(local_ip) = matches.opt_str("local-ip") {
raw.local.ip = local_ip.parse()?;
};
@ -563,6 +581,10 @@ mod default {
8000
}
pub(super) const fn max_udp_relay_packet_size() -> usize {
1500
}
pub(super) const fn local_ip() -> IpAddr {
IpAddr::V4(Ipv4Addr::LOCALHOST)
}

View File

@ -37,6 +37,7 @@ async fn main() {
config.reduce_rtt,
config.udp_relay_mode,
config.request_timeout,
config.max_udp_relay_packet_size,
)
.await;

View File

@ -98,6 +98,7 @@ pub struct Connection {
stream_reg: Arc<StreamRegister>,
udp_relay_mode: UdpRelayMode<(), ()>,
is_closed: IsClosed,
default_max_udp_relay_packet_size: usize,
}
impl Connection {
@ -172,6 +173,7 @@ impl Connection {
stream_reg: Arc::new(StreamRegister::new()),
udp_relay_mode: config.udp_relay_mode,
is_closed: IsClosed::new(),
default_max_udp_relay_packet_size: config.max_udp_relay_packet_size,
};
// send auth
@ -254,10 +256,10 @@ impl Connection {
Some(size) => size,
None => {
log::warn!("[relay] [connection] Failed to detect the max datagram size");
65535
self.default_max_udp_relay_packet_size
}
},
UdpRelayMode::Quic(()) => 65535,
UdpRelayMode::Quic(()) => self.default_max_udp_relay_packet_size,
};
super::MAX_UDP_RELAY_PACKET_SIZE.store(size, Ordering::Release);
@ -287,6 +289,7 @@ pub struct ConnectionConfig {
udp_relay_mode: UdpRelayMode<(), ()>,
heartbeat_interval: u64,
reduce_rtt: bool,
max_udp_relay_packet_size: usize,
}
impl ConnectionConfig {
@ -297,6 +300,7 @@ impl ConnectionConfig {
udp_relay_mode: UdpRelayMode<(), ()>,
heartbeat_interval: u64,
reduce_rtt: bool,
max_udp_relay_packet_size: usize,
) -> Self {
Self {
quinn_config,
@ -305,6 +309,7 @@ impl ConnectionConfig {
udp_relay_mode,
heartbeat_interval,
reduce_rtt,
max_udp_relay_packet_size,
}
}
}

View File

@ -30,6 +30,7 @@ pub async fn init(
reduce_rtt: bool,
udp_relay_mode: UdpRelayMode<(), ()>,
req_timeout: u64,
max_udp_relay_packet_size: usize,
) -> (impl Future<Output = ()>, Sender<Request>) {
let (req_tx, req_rx) = mpsc::channel(1);
@ -40,6 +41,7 @@ pub async fn init(
udp_relay_mode,
heartbeat_interval,
reduce_rtt,
max_udp_relay_packet_size,
);
let conn = Arc::new(AsyncMutex::new(None));