Skip to content

Commit 90370cf

Browse files
authored
fix: improve VPN discovery and IPv6 route handling (#97)
* fix: discover and probe available VPN endpoints * fix: skip IPv6 routes without a tunnel address * fix: harden VPN endpoint probing * fix: construct VPN endpoint URLs from candidate hosts
1 parent 6c7b26e commit 90370cf

2 files changed

Lines changed: 489 additions & 108 deletions

File tree

src/api.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::config::Config;
77
use crate::template::Template;
88

99
pub const URL_GET_COMPANY: &str = "https://corplink.volcengine.cn/api/match";
10+
pub(crate) const CORPLINK_APP_VERSION: &str = "201000";
1011

1112
const URL_GET_LOGIN_METHOD: &str = "{{url}}/api/login/setting?os={{os}}&os_version={{version}}";
1213
const URL_GET_TPS_LOGIN_METHOD: &str = "{{url}}/api/tpslogin/link?os={{os}}&os_version={{version}}";
@@ -18,7 +19,8 @@ const URL_VERIFY_CODE: &str = "{{url}}/api/login/code/verify?os={{os}}&os_versio
1819
const URL_LOGIN_PASSWORD: &str = "{{url}}/api/login?os={{os}}&os_version={{version}}";
1920
const URL_LOGIN_PASSWORD_V1: &str =
2021
"{{url}}/api/v1/login?os={{os}}&os_version={{version}}&client_source=FeiLian";
21-
const URL_LIST_VPN: &str = "{{url}}/api/vpn/list?os={{os}}&os_version={{version}}";
22+
const URL_LIST_VPN: &str =
23+
"{{url}}/api/vpn/list?os={{os}}&os_version={{version}}&app_version={{app_version}}";
2224

2325
const URL_PING_VPN_HOST: &str = "{{url}}/vpn/ping?os={{os}}&os_version={{version}}";
2426
const URL_FETCH_PEER_INFO: &str = "{{url}}/vpn/conn?os={{os}}&os_version={{version}}";
@@ -54,6 +56,7 @@ struct UserUrlParam {
5456
url: String,
5557
os: String,
5658
version: String,
59+
app_version: String,
5760
}
5861

5962
#[derive(Clone, Serialize)]
@@ -112,6 +115,7 @@ impl ApiUrl {
112115
.context("server url missing in config")?,
113116
os: os.clone(),
114117
version: version.clone(),
118+
app_version: CORPLINK_APP_VERSION.to_string(),
115119
},
116120
vpn_param: VpnUrlParam {
117121
url: "".to_string(),
@@ -145,3 +149,27 @@ impl ApiUrl {
145149
}
146150
}
147151
}
152+
153+
#[cfg(test)]
154+
mod tests {
155+
use serde_json::json;
156+
157+
use super::*;
158+
159+
#[test]
160+
fn list_vpn_url_includes_app_version() {
161+
let conf: Config = serde_json::from_value(json!({
162+
"company_name": "test",
163+
"username": "test",
164+
"server": "https://vpn.example.com"
165+
}))
166+
.unwrap();
167+
168+
let api_url = ApiUrl::new(&conf).unwrap();
169+
170+
assert_eq!(
171+
api_url.get_api_url(&ApiName::ListVPN),
172+
"https://vpn.example.com/api/vpn/list?os=Android&os_version=2&app_version=201000"
173+
);
174+
}
175+
}

0 commit comments

Comments
 (0)