feat: prepare 3.2.0 with Local Proxy and gateway IP preference

This commit is contained in:
Kevin Yue committed 2026-10-22 23:52:58 +08:00
1 parent 69d67721a6
commit 915c130c70
47 files changed
+3965 -233

No files matched your search

+67
View File
@@ -58,6 +58,8 @@ impl LaunchGuiRequest {
#[derive(Deserialize, Serialize, Type, Clone)]
pub struct ConnectArgs {
#[serde(default)]
packet_delivery: crate::script_tun::PacketDelivery,
vpnc_script: Option<String>,
host_identity: Option<HostIdentity>,
ignore_tls_errors: bool,
@@ -79,6 +81,8 @@ pub struct ConnectArgs {
reconnect_timeout: u32,
mtu: u32,
disable_ipv6: bool,
#[serde(default)]
gateway_ip_preference: crate::gateway::GatewayIpPreference,
no_dtls: bool,
local_hostname: Option<String>,
force_dpd: u32,
@@ -88,8 +92,13 @@ pub struct ConnectArgs {
}
impl ConnectArgs {
pub fn packet_delivery(&self) -> &crate::script_tun::PacketDelivery {
&self.packet_delivery
}
fn new() -> Self {
Self {
packet_delivery: Default::default(),
vpnc_script: None,
host_identity: None,
ignore_tls_errors: false,
@@ -107,6 +116,7 @@ impl ConnectArgs {
reconnect_timeout: 300,
mtu: 0,
disable_ipv6: false,
gateway_ip_preference: Default::default(),
no_dtls: false,
local_hostname: None,
force_dpd: 0,
@@ -195,6 +205,10 @@ impl ConnectArgs {
self.disable_ipv6
}
pub fn gateway_ip_preference(&self) -> crate::gateway::GatewayIpPreference {
self.gateway_ip_preference
}
pub fn no_dtls(&self) -> bool {
self.no_dtls
}
@@ -232,6 +246,7 @@ impl fmt::Debug for ConnectArgs {
.field("reconnect_timeout", &self.reconnect_timeout)
.field("mtu", &self.mtu)
.field("disable_ipv6", &self.disable_ipv6)
.field("gateway_ip_preference", &self.gateway_ip_preference)
.field("no_dtls", &self.no_dtls)
.field("allow_extend_session", &self.allow_extend_session)
.finish_non_exhaustive()
@@ -248,17 +263,40 @@ impl Drop for ConnectArgs {
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
pub struct ConnectRequest {
#[serde(default)]
restart_of: Option<u64>,
info: ConnectInfo,
plan: ConnectionPlan,
args: ConnectArgs,
}
impl ConnectRequest {
pub fn with_restart_of(mut self, attempt: Option<u64>) -> Self {
self.restart_of = attempt;
self
}
pub fn restart_of(&self) -> Option<u64> {
self.restart_of
}
/// Release the one-shot payload once tunnel setup has taken ownership of it.
pub fn release_script_tun_bootstrap(&mut self) {
if let crate::script_tun::PacketDelivery::ScriptTun(request) = &mut self.args.packet_delivery {
request.bootstrap = Default::default();
}
}
pub fn with_packet_delivery(mut self, mode: crate::script_tun::PacketDelivery) -> Self {
self.info.set_packet_delivery(mode.kind());
self.args.packet_delivery = mode;
self
}
pub fn new(info: ConnectInfo, plan: ConnectionPlan) -> Self {
Self {
info,
plan,
args: ConnectArgs::new(),
restart_of: None,
}
}
@@ -327,6 +365,11 @@ impl ConnectRequest {
self
}
pub fn with_gateway_ip_preference(mut self, preference: crate::gateway::GatewayIpPreference) -> Self {
self.args.gateway_ip_preference = preference;
self
}
pub fn with_no_dtls(mut self, no_dtls: bool) -> Self {
self.args.no_dtls = no_dtls;
self
@@ -458,6 +501,30 @@ mod tests {
assert_eq!(value["args"]["allowExtendSession"], json!(true));
}
#[test]
fn gateway_preference_round_trips_and_defaults_for_existing_requests() {
use crate::gateway::GatewayIpPreference;
for preference in [
GatewayIpPreference::Auto,
GatewayIpPreference::Ipv4,
GatewayIpPreference::Ipv6,
] {
let request = test_request(test_connect_info())
.with_disable_ipv6(true)
.with_gateway_ip_preference(preference);
let value = serde_json::to_value(&request).unwrap();
let decoded: ConnectRequest = serde_json::from_value(value).unwrap();
assert_eq!(decoded.args().gateway_ip_preference(), preference);
assert!(decoded.args().disable_ipv6());
}
let request = test_request(test_connect_info()).with_disable_ipv6(true);
let mut value = serde_json::to_value(request).unwrap();
value["args"].as_object_mut().unwrap().remove("gateway_ip_preference");
let decoded: ConnectRequest = serde_json::from_value(value).unwrap();
assert_eq!(decoded.args().gateway_ip_preference(), GatewayIpPreference::Auto);
assert!(decoded.args().disable_ipv6());
}
#[test]
fn with_os_profile_sets_user_agent_from_profile() {
let profile = OsProfileBuilder::new(ClientOs::Linux).client_version("6.0.0").build();
+32
View File
@@ -10,6 +10,10 @@ use crate::{
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
pub struct ConnectInfo {
#[serde(default)]
packet_delivery: crate::script_tun::PacketDeliveryKind,
#[serde(default)]
script_tun_identity: Option<crate::script_tun::Identity>,
portal: String,
gateway: Gateway,
gateways: Vec<Gateway>,
@@ -71,14 +75,33 @@ fn unix_timestamp() -> u32 {
}
impl ConnectInfo {
pub fn script_tun_identity(&self) -> Option<crate::script_tun::Identity> {
self.script_tun_identity
}
pub fn set_script_tun_identity(&mut self, identity: crate::script_tun::Identity) {
self.script_tun_identity = Some(identity);
}
pub fn packet_delivery(&self) -> &crate::script_tun::PacketDeliveryKind {
&self.packet_delivery
}
pub fn set_packet_delivery(&mut self, mode: crate::script_tun::PacketDeliveryKind) {
self.packet_delivery = mode;
self.script_tun_identity = None;
}
pub fn new(portal: String, gateway: Gateway, gateways: Vec<Gateway>) -> Self {
Self {
packet_delivery: Default::default(),
script_tun_identity: None,
portal,
gateway,
gateways,
}
}
pub fn portal(&self) -> &str {
&self.portal
}
pub fn gateway(&self) -> &Gateway {
&self.gateway
}
@@ -87,6 +110,7 @@ impl ConnectInfo {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum VpnState {
ReconnectRequired(Box<ReconnectRequest>),
Disconnected,
Failed(String),
Connecting(Box<ConnectInfo>),
@@ -119,3 +143,11 @@ mod tests {
assert!(value["connected"]["connectedAt"].as_u64().is_some());
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Type)]
#[serde(rename_all = "camelCase")]
pub struct ReconnectRequest {
pub attempt: u64,
pub owner: uuid::Uuid,
pub info: ConnectInfo,
}