add packet size option for UDP relay mode Quic
This commit is contained in:
parent
5e6ab51e5d
commit
7393397632
@ -36,6 +36,7 @@ pub struct Config {
|
|||||||
pub heartbeat_interval: u64,
|
pub heartbeat_interval: u64,
|
||||||
pub reduce_rtt: bool,
|
pub reduce_rtt: bool,
|
||||||
pub request_timeout: u64,
|
pub request_timeout: u64,
|
||||||
|
pub max_udp_relay_packet_size: usize,
|
||||||
pub local_addr: SocketAddr,
|
pub local_addr: SocketAddr,
|
||||||
pub socks5_auth: Arc<dyn Auth + Send + Sync>,
|
pub socks5_auth: Arc<dyn Auth + Send + Sync>,
|
||||||
pub log_level: LevelFilter,
|
pub log_level: LevelFilter,
|
||||||
@ -105,6 +106,7 @@ impl Config {
|
|||||||
let heartbeat_interval = raw.relay.heartbeat_interval;
|
let heartbeat_interval = raw.relay.heartbeat_interval;
|
||||||
let reduce_rtt = raw.relay.reduce_rtt;
|
let reduce_rtt = raw.relay.reduce_rtt;
|
||||||
let request_timeout = raw.relay.request_timeout;
|
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()));
|
let local_addr = SocketAddr::from((raw.local.ip, raw.local.port.unwrap()));
|
||||||
|
|
||||||
@ -127,6 +129,7 @@ impl Config {
|
|||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
reduce_rtt,
|
reduce_rtt,
|
||||||
request_timeout,
|
request_timeout,
|
||||||
|
max_udp_relay_packet_size,
|
||||||
local_addr,
|
local_addr,
|
||||||
socks5_auth,
|
socks5_auth,
|
||||||
log_level,
|
log_level,
|
||||||
@ -181,6 +184,9 @@ struct RawRelayConfig {
|
|||||||
|
|
||||||
#[serde(default = "default::request_timeout")]
|
#[serde(default = "default::request_timeout")]
|
||||||
request_timeout: u64,
|
request_timeout: u64,
|
||||||
|
|
||||||
|
#[serde(default = "default::max_udp_relay_packet_size")]
|
||||||
|
max_udp_relay_packet_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@ -220,6 +226,7 @@ impl Default for RawRelayConfig {
|
|||||||
disable_sni: default::disable_sni(),
|
disable_sni: default::disable_sni(),
|
||||||
reduce_rtt: default::reduce_rtt(),
|
reduce_rtt: default::reduce_rtt(),
|
||||||
request_timeout: default::request_timeout(),
|
request_timeout: default::request_timeout(),
|
||||||
|
max_udp_relay_packet_size: default::max_udp_relay_packet_size(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,6 +326,13 @@ impl RawConfig {
|
|||||||
"REQUEST_TIMEOUT",
|
"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(
|
opts.optopt(
|
||||||
"",
|
"",
|
||||||
"local-port",
|
"local-port",
|
||||||
@ -461,6 +475,10 @@ impl RawConfig {
|
|||||||
raw.relay.request_timeout = timeout.parse()?;
|
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") {
|
if let Some(local_ip) = matches.opt_str("local-ip") {
|
||||||
raw.local.ip = local_ip.parse()?;
|
raw.local.ip = local_ip.parse()?;
|
||||||
};
|
};
|
||||||
@ -563,6 +581,10 @@ mod default {
|
|||||||
8000
|
8000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(super) const fn max_udp_relay_packet_size() -> usize {
|
||||||
|
1500
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) const fn local_ip() -> IpAddr {
|
pub(super) const fn local_ip() -> IpAddr {
|
||||||
IpAddr::V4(Ipv4Addr::LOCALHOST)
|
IpAddr::V4(Ipv4Addr::LOCALHOST)
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ async fn main() {
|
|||||||
config.reduce_rtt,
|
config.reduce_rtt,
|
||||||
config.udp_relay_mode,
|
config.udp_relay_mode,
|
||||||
config.request_timeout,
|
config.request_timeout,
|
||||||
|
config.max_udp_relay_packet_size,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ pub struct Connection {
|
|||||||
stream_reg: Arc<StreamRegister>,
|
stream_reg: Arc<StreamRegister>,
|
||||||
udp_relay_mode: UdpRelayMode<(), ()>,
|
udp_relay_mode: UdpRelayMode<(), ()>,
|
||||||
is_closed: IsClosed,
|
is_closed: IsClosed,
|
||||||
|
default_max_udp_relay_packet_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
@ -172,6 +173,7 @@ impl Connection {
|
|||||||
stream_reg: Arc::new(StreamRegister::new()),
|
stream_reg: Arc::new(StreamRegister::new()),
|
||||||
udp_relay_mode: config.udp_relay_mode,
|
udp_relay_mode: config.udp_relay_mode,
|
||||||
is_closed: IsClosed::new(),
|
is_closed: IsClosed::new(),
|
||||||
|
default_max_udp_relay_packet_size: config.max_udp_relay_packet_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
// send auth
|
// send auth
|
||||||
@ -254,10 +256,10 @@ impl Connection {
|
|||||||
Some(size) => size,
|
Some(size) => size,
|
||||||
None => {
|
None => {
|
||||||
log::warn!("[relay] [connection] Failed to detect the max datagram size");
|
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);
|
super::MAX_UDP_RELAY_PACKET_SIZE.store(size, Ordering::Release);
|
||||||
@ -287,6 +289,7 @@ pub struct ConnectionConfig {
|
|||||||
udp_relay_mode: UdpRelayMode<(), ()>,
|
udp_relay_mode: UdpRelayMode<(), ()>,
|
||||||
heartbeat_interval: u64,
|
heartbeat_interval: u64,
|
||||||
reduce_rtt: bool,
|
reduce_rtt: bool,
|
||||||
|
max_udp_relay_packet_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectionConfig {
|
impl ConnectionConfig {
|
||||||
@ -297,6 +300,7 @@ impl ConnectionConfig {
|
|||||||
udp_relay_mode: UdpRelayMode<(), ()>,
|
udp_relay_mode: UdpRelayMode<(), ()>,
|
||||||
heartbeat_interval: u64,
|
heartbeat_interval: u64,
|
||||||
reduce_rtt: bool,
|
reduce_rtt: bool,
|
||||||
|
max_udp_relay_packet_size: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
quinn_config,
|
quinn_config,
|
||||||
@ -305,6 +309,7 @@ impl ConnectionConfig {
|
|||||||
udp_relay_mode,
|
udp_relay_mode,
|
||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
reduce_rtt,
|
reduce_rtt,
|
||||||
|
max_udp_relay_packet_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ pub async fn init(
|
|||||||
reduce_rtt: bool,
|
reduce_rtt: bool,
|
||||||
udp_relay_mode: UdpRelayMode<(), ()>,
|
udp_relay_mode: UdpRelayMode<(), ()>,
|
||||||
req_timeout: u64,
|
req_timeout: u64,
|
||||||
|
max_udp_relay_packet_size: usize,
|
||||||
) -> (impl Future<Output = ()>, Sender<Request>) {
|
) -> (impl Future<Output = ()>, Sender<Request>) {
|
||||||
let (req_tx, req_rx) = mpsc::channel(1);
|
let (req_tx, req_rx) = mpsc::channel(1);
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ pub async fn init(
|
|||||||
udp_relay_mode,
|
udp_relay_mode,
|
||||||
heartbeat_interval,
|
heartbeat_interval,
|
||||||
reduce_rtt,
|
reduce_rtt,
|
||||||
|
max_udp_relay_packet_size,
|
||||||
);
|
);
|
||||||
|
|
||||||
let conn = Arc::new(AsyncMutex::new(None));
|
let conn = Arc::new(AsyncMutex::new(None));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user