feat: add portable GlobalProtect APIs and iOS tunnel support

This commit is contained in:
Kevin Yue committed 2026-11-01 23:34:18 +08:00
1 parent 4f8f828a0b
commit da90bc80e3
112 files changed
+3864 -3011

No files matched your search

+1 -4
View File
@@ -263,13 +263,10 @@ impl Cli {
fn build_os_profile(&self) -> OsProfile {
let mut builder = OsProfile::builder(ClientOs::from(self.os));
if let Some(host_id) = self.host_id.as_deref() {
builder = builder.host_id_override(host_id);
}
if let Some(client_version) = self.client_version.as_deref() {
builder = builder.client_version(client_version);
}
builder.build()
gpapi::os_profile::desktop::collect_profile(builder, self.host_id.as_deref())
}
fn external_browser_requested(&self) -> bool {
+2 -2
View File
@@ -243,7 +243,7 @@ impl Cli {
CliCommand::Hip(args) => HipHandler::new(args).handle().await,
CliCommand::Diagnostics(_) => unreachable!("diagnostics is dispatched before VPN setup"),
CliCommand::DetectInternalHost { address, hostname } => {
let internal = gpapi::session::network::native::detect_in_helper(*address, hostname)?;
let internal = gpapi::session::desktop::network::native::detect_in_helper(*address, hostname)?;
println!("{}", serde_json::to_string(&internal)?);
Ok(())
}
@@ -252,7 +252,7 @@ impl Cli {
port,
disable_ipv6,
} => {
let addresses = gpapi::session::network::native::lookup_in_helper(host, *port, *disable_ipv6)?;
let addresses = gpapi::session::desktop::network::native::lookup_in_helper(host, *port, *disable_ipv6)?;
println!("{}", serde_json::to_string(&addresses)?);
Ok(())
}
+4 -12
View File
@@ -203,10 +203,7 @@ pub(super) fn build_os_profile_with_host_id(args: &ConnectArgs, host_id: Option<
if let Some(local_hostname) = args.local_hostname.as_deref() {
builder = builder.computer_name_override(local_hostname.to_string());
}
if let Some(host_id) = host_id {
builder = builder.host_id_override(host_id);
}
builder.build()
gpapi::os_profile::desktop::collect_profile(builder, host_id)
}
pub(super) fn cookie_cache_path(args: &ConnectArgs) -> Option<PathBuf> {
@@ -489,14 +486,9 @@ mod tests {
("ipv4", GatewayIpPreference::Ipv4),
("ipv6", GatewayIpPreference::Ipv6),
] {
let cli = ConnectArgsTestCli::try_parse_from([
"test",
"portal.example.com",
"--ip-preference",
value,
"--disable-ipv6",
])
.unwrap();
let cli =
ConnectArgsTestCli::try_parse_from(["test", "portal.example.com", "--ip-preference", value, "--disable-ipv6"])
.unwrap();
assert_eq!(cli.args.ip_preference, expected);
assert!(cli.args.disable_ipv6);
}
+17 -13
View File
@@ -360,22 +360,26 @@ impl ConnectHandler<'_> {
match login {
GatewayLogin::Authenticated(authentication) => {
let descriptor = Gateway::new(gateway.to_string(), gateway.to_string());
client.register_session(
descriptor.clone(),
authentication.clone(),
&mut self.sessions.borrow_mut(),
);
self
.sessions
.borrow_mut()
.register_login(descriptor.clone(), authentication.clone(), &client);
self.check_cancelled()?;
if internal && authentication.mode() == SessionMode::NonTunnel && !self.args.cookie_only {
client
.bind_non_tunnel(self.args.disable_ipv6, None, &cancellation)
.await
.map_err(|error| error.context(gpapi::gateway::GatewayLoginProtocolError))?;
client.update_registered_session(&descriptor, &authentication, &mut self.sessions.borrow_mut());
}
let binding = if internal && authentication.mode() == SessionMode::NonTunnel && !self.args.cookie_only {
Some(
self
.sessions
.borrow_mut()
.bind_non_tunnel(&descriptor, &client, self.args.disable_ipv6, None, &cancellation)
.await
.map_err(|error| error.context(gpapi::gateway::GatewayLoginProtocolError))?,
)
} else {
None
};
return Ok(GatewayLoginSession {
authentication,
extension_auth: SessionExtensionAuth::new(cred.clone(), client),
extension_auth: SessionExtensionAuth::new(cred.clone(), client).with_binding(binding),
});
}
GatewayLogin::Mfa(message, input_str) => {
+3 -3
View File
@@ -2,14 +2,14 @@ use std::sync::Arc;
use anyhow::{Context, bail, ensure};
use gpapi::{
collection::CollectionControl,
credential::AuthCookieCredential,
gateway::{Gateway, GatewayLoginContext, GatewaySelection},
portal::PortalConfig,
process::collection::CollectionControl,
session::{
MaintenanceState, SessionEndReason, SessionMode,
network::PhysicalNetwork,
non_tunnel::{SessionCallbacks, SessionExit, maintain_non_tunnel_sessions},
desktop::network::PhysicalNetwork,
desktop::non_tunnel::{SessionCallbacks, SessionExit, maintain_non_tunnel_sessions},
},
};
use log::{info, warn};
+4 -4
View File
@@ -19,8 +19,8 @@ use gpapi::{
gateway::GatewaySelection,
gp_params::GpParams,
os_profile::OsProfile,
portal::{PreloginOptions, prelogin, retrieve_config},
session::GatewaySessions,
portal::{PreloginOptions, discovery::discover, prelogin},
session::desktop::GatewaySessions,
utils::request::RequestIdentityError,
};
use inquire::{Password, PasswordDisplayMode, Select};
@@ -282,7 +282,7 @@ impl<'a> ConnectHandler<'a> {
let cached = self.cached_portal_credential(portal);
let cached_config = match cached {
Some(cred) => match retrieve_config(portal, &cred, &gp_params, &self.cancellation).await {
Some(cred) => match discover(portal, &cred, &gp_params, &self.cancellation).await {
Ok(config) => Some((cred, config)),
Err(error) => {
self.check_cancelled()?;
@@ -301,7 +301,7 @@ impl<'a> ConnectHandler<'a> {
.await?;
prelogin = replacement;
self.check_cancelled()?;
let config = retrieve_config(portal, &cred, &gp_params, &self.cancellation).await?;
let config = discover(portal, &cred, &gp_params, &self.cancellation).await?;
(cred, config)
}
};
+4 -2
View File
@@ -1,6 +1,8 @@
//! Dashboard presentation only; connection ownership and sampling stay outside this module.
use crossterm::event::KeyCode;
use gpapi::session::tunnel::{TunnelList, TunnelPhase, TunnelState, TunnelStatisticsSnapshot, TunnelStatisticsState};
use gpapi::session::desktop::tunnel::{
TunnelList, TunnelPhase, TunnelState, TunnelStatisticsSnapshot, TunnelStatisticsState,
};
use ratatui::{
Frame,
buffer::Buffer,
@@ -338,7 +340,7 @@ pub(super) fn render_tunnel(
#[cfg(test)]
mod tests {
use gpapi::session::tunnel::{TunnelStatistics, TunnelStatisticsView, TunnelTransport};
use gpapi::session::desktop::tunnel::{TunnelStatistics, TunnelStatisticsView, TunnelTransport};
use ratatui::{Terminal, backend::TestBackend};
use super::*;
+3 -3
View File
@@ -15,7 +15,7 @@ use crossterm::{
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use gpapi::session::tunnel::TunnelPhase;
use gpapi::session::desktop::tunnel::TunnelPhase;
use log::Level;
use nix::unistd::{getpgrp, tcgetpgrp};
use ratatui::{
@@ -317,7 +317,7 @@ fn footer_text(logs: bool, ending: &str, scrollable: bool, width: u16) -> Paragr
fn notice_for_status(
notice: Option<Notice>,
phase: TunnelPhase,
transport: gpapi::session::tunnel::TunnelTransport,
transport: gpapi::session::desktop::tunnel::TunnelTransport,
) -> Notice {
notice.unwrap_or_else(|| Notice {
level: Level::Info,
@@ -345,7 +345,7 @@ mod tests {
#[test]
fn status_transitions_cannot_overwrite_an_existing_warning() {
use gpapi::session::tunnel::TunnelTransport;
use gpapi::session::desktop::tunnel::TunnelTransport;
let warning = Notice {
level: Level::Warn,
message: "ESP unavailable; using SSL".into(),
+6 -5
View File
@@ -3,8 +3,8 @@ use std::time::Duration;
use clap::Args;
use gpapi::{
clap::args::Os,
collection::CollectionBudget,
os_profile::{ClientOs, OsProfileBuilder},
process::collection::CollectionBudget,
};
use gphip::{ReportContext, ReportInput, generate_report_with_control};
@@ -51,11 +51,12 @@ impl<'a> HipHandler<'a> {
if let Some(os_version) = self.args.os_version.as_deref() {
builder = builder.os_version(os_version);
}
if let Some(host_id) = self.args.host_id.as_deref() {
builder = builder.host_id_override(host_id);
}
let input = ReportInput {
profile: builder.build_with_control(&budget)?,
profile: gpapi::os_profile::desktop::collect_profile_with_control(
builder,
self.args.host_id.as_deref(),
&budget,
)?,
context: ReportContext::Connected {
cookie: self.args.cookie.clone(),
client_ip: self.args.client_ip.clone(),
+4 -3
View File
@@ -182,9 +182,10 @@ mod tests {
#[test]
fn builds_session_context_from_os_profile() {
let profile = OsProfile::builder(gpapi::os_profile::ClientOs::Mac)
.client_version("6.3.1-12".to_string())
.build();
let profile = gpapi::os_profile::desktop::collect_profile(
OsProfile::builder(gpapi::os_profile::ClientOs::Mac).client_version("6.3.1-12".to_string()),
None,
);
let expected_user_agent = profile.user_agent().to_string();
let ctx = build_session_context(SessionContextInput {
+1 -1
View File
@@ -635,7 +635,7 @@ mod tests {
vpnc_script: None,
auth_executable: String::new(),
host_info: HostInfo {
host_identity: HostIdentity::collect(),
host_identity: gpapi::os_profile::desktop::collect_identity(),
},
},
};
+4 -4
View File
@@ -87,14 +87,14 @@ pub fn install(request: InstallRequest, approving_uid: u32) -> anyhow::Result<Ap
}
pub fn resolve(approval_id: &str, desktop_uid: u32) -> anyhow::Result<ApprovedScript> {
let budget = gpapi::process::collection::CollectionBudget::new(std::time::Duration::from_secs(60));
let budget = gpapi::collection::CollectionBudget::new(std::time::Duration::from_secs(60));
resolve_with_control(approval_id, desktop_uid, &budget)
}
pub fn resolve_with_control(
approval_id: &str,
desktop_uid: u32,
control: &dyn gpapi::process::collection::CollectionControl,
control: &dyn gpapi::collection::CollectionControl,
) -> anyhow::Result<ApprovedScript> {
control.check()?;
ensure!(desktop_uid != 0, "Root is not a desktop HIP approval owner");
@@ -199,7 +199,7 @@ fn install_at(
}
fn resolve_at(base: &Path, approval_id: &str, desktop_uid: u32, file_owner: u32) -> anyhow::Result<ApprovedScript> {
let budget = gpapi::process::collection::CollectionBudget::new(std::time::Duration::from_secs(60));
let budget = gpapi::collection::CollectionBudget::new(std::time::Duration::from_secs(60));
resolve_at_with_control(base, approval_id, desktop_uid, file_owner, &budget)
}
@@ -208,7 +208,7 @@ fn resolve_at_with_control(
approval_id: &str,
desktop_uid: u32,
file_owner: u32,
control: &dyn gpapi::process::collection::CollectionControl,
control: &dyn gpapi::collection::CollectionControl,
) -> anyhow::Result<ApprovedScript> {
control.check()?;
let info = read_metadata_at(base, approval_id, desktop_uid, file_owner)?;
+3 -3
View File
@@ -158,12 +158,12 @@ fn generate(
request.host_id.as_ref().is_none_or(|id| id.len() <= 256),
"Invalid HIP host ID"
);
let budget = gpapi::process::collection::CollectionBudget::new(PREVIEW_TIMEOUT);
let budget = gpapi::collection::CollectionBudget::new(PREVIEW_TIMEOUT);
let check = || {
if cancellation.is_cancelled() {
return Err(io::Error::new(io::ErrorKind::Interrupted, "HIP preview cancelled"));
}
gpapi::process::collection::CollectionControl::check(&budget)
gpapi::collection::CollectionControl::check(&budget)
};
check()?;
let profile = crate::hip_source::profile(
@@ -227,7 +227,7 @@ mod tests {
},
edited_report: None,
desktop_uid: None,
identity: HostIdentity::from_parts(
identity: gpapi::os_profile::desktop::identity_from_parts(
"device".into(),
"host".into(),
"serial".into(),
+8 -8
View File
@@ -125,7 +125,7 @@ pub(crate) fn generate(
profile: &OsProfile,
edited: Option<&str>,
request: &HipRequest,
control: &dyn gpapi::process::collection::CollectionControl,
control: &dyn gpapi::collection::CollectionControl,
preview: bool,
) -> anyhow::Result<String> {
control.check()?;
@@ -177,9 +177,9 @@ pub(crate) fn profile(
os_version: Option<String>,
host_id: Option<String>,
hostname: Option<String>,
control: &dyn gpapi::process::collection::CollectionControl,
control: &dyn gpapi::collection::CollectionControl,
) -> io::Result<OsProfile> {
let identity = HostIdentity::from_parts(
let identity = gpapi::os_profile::desktop::identity_from_parts(
hostname.unwrap_or_else(|| identity.computer().into()),
host_id.unwrap_or_else(|| identity.host_id().into()),
identity.serialno().into(),
@@ -192,7 +192,7 @@ pub(crate) fn profile(
if let Some(os_version) = os_version {
builder = builder.os_version(os_version);
}
builder.build_with_control(control)
gpapi::os_profile::desktop::collect_profile_with_control(builder, None, control)
}
fn generation_error(error: anyhow::Error) -> io::Error {
@@ -209,7 +209,7 @@ mod tests {
fn fixture_profile() -> OsProfile {
profile(
&HostIdentity::from_parts(
&gpapi::os_profile::desktop::identity_from_parts(
"device".into(),
"host".into(),
"serial".into(),
@@ -220,7 +220,7 @@ mod tests {
Some("negotiated-version".into()),
None,
None,
&gpapi::process::collection::CollectionBudget::new(std::time::Duration::from_secs(60)),
&gpapi::collection::CollectionBudget::new(std::time::Duration::from_secs(60)),
)
.unwrap()
}
@@ -235,7 +235,7 @@ mod tests {
#[test]
fn profile_retains_negotiated_identity_and_os_version() {
let identity = HostIdentity::from_parts(
let identity = gpapi::os_profile::desktop::identity_from_parts(
"original".into(),
"original-id".into(),
"serial".into(),
@@ -248,7 +248,7 @@ mod tests {
Some("negotiated-os".into()),
Some("negotiated-host".into()),
Some("negotiated-name".into()),
&gpapi::process::collection::CollectionBudget::new(std::time::Duration::from_secs(60)),
&gpapi::collection::CollectionBudget::new(std::time::Duration::from_secs(60)),
)
.unwrap();
assert_eq!(profile.os_version(), "negotiated-os");
+4 -1
View File
@@ -833,7 +833,10 @@ mod tests {
}
let valid = gphip::generate_report(&gphip::ReportInput {
profile: gpapi::os_profile::OsProfile::builder(gpapi::os_profile::ClientOs::Linux).build(),
profile: gpapi::os_profile::desktop::collect_profile(
gpapi::os_profile::OsProfile::builder(gpapi::os_profile::ClientOs::Linux),
None,
),
context: gphip::ReportContext::Preview,
})
.unwrap();
+6 -6
View File
@@ -420,7 +420,7 @@ enum LifecycleEvent {
MembersChanged {
attempt: u64,
members: Vec<gpapi::session::GatewaySessionSummary>,
failures: Vec<gpapi::session::GatewayFailureSummary>,
failures: Vec<gpapi::session::desktop::GatewayFailureSummary>,
},
Ended {
attempt: u64,
@@ -679,7 +679,7 @@ impl VpnTask {
&self,
attempt: u64,
members: Vec<gpapi::session::GatewaySessionSummary>,
failures: Vec<gpapi::session::GatewayFailureSummary>,
failures: Vec<gpapi::session::desktop::GatewayFailureSummary>,
) {
let Some(active) = &self.active else {
return;
@@ -855,12 +855,12 @@ pub(crate) fn test_connect_request(info: ConnectInfo) -> ConnectRequest {
} else {
"fixture"
};
let binding = gpapi::session::network::GatewayBinding::new(
let binding = gpapi::session::desktop::network::GatewayBinding::new(
endpoint,
std::net::SocketAddr::new(source, 0),
interface.into(),
1,
gpapi::session::ClientAddresses {
gpapi::session::desktop::ClientAddresses {
ipv4: match source {
std::net::IpAddr::V4(ip) => Some(ip),
_ => None,
@@ -873,8 +873,8 @@ pub(crate) fn test_connect_request(info: ConnectInfo) -> ConnectRequest {
"0".repeat(64),
)
.unwrap();
let plan = gpapi::session::ConnectionPlan::new(
vec![gpapi::session::AuthenticatedGateway {
let plan = gpapi::session::desktop::ConnectionPlan::new(
vec![gpapi::session::desktop::AuthenticatedGateway {
gateway: info.gateway().clone(),
binding: Some(binding),
authentication: gpapi::session::GatewayAuthentication::new("authcookie=token&user=user".into(), "tunnel".into())
+2 -2
View File
@@ -1,10 +1,10 @@
use std::{sync::Arc, time::Duration};
use anyhow::Context;
use gpapi::process::collection::CollectionControl;
use gpapi::collection::CollectionControl;
use gpapi::session::{
GatewaySessionSummary, MaintenanceState, SessionEndReason,
non_tunnel::{SessionCallbacks, SessionExit, maintain_non_tunnel_sessions},
desktop::non_tunnel::{SessionCallbacks, SessionExit, maintain_non_tunnel_sessions},
};
use log::warn;
use tokio::sync::{mpsc, watch};
@@ -11,7 +11,10 @@ use gpapi::{
transport::ServiceResult,
vpn_state::{ConnectInfo, VpnState},
},
session::{ClientAddresses, GatewayAuthentication, GatewaySession, GatewaySessions, transport::GatewayTransport},
session::{
GatewayAuthentication, desktop::ClientAddresses, desktop::GatewaySession, desktop::GatewaySessions,
transport::GatewayTransport,
},
};
use openssl::{
asn1::Asn1Time,
@@ -70,7 +73,7 @@ async fn cancelled_pending_owner_logs_out_and_releases_admission_after_response(
let mut member = fixture.plan().members()[0].clone();
member.authentication =
GatewayAuthentication::new("authcookie=fixture&user=fixture".into(), "internal".into()).unwrap();
let plan = gpapi::session::ConnectionPlan::new(vec![member], vec![], fixture.plan().policy()).unwrap();
let plan = gpapi::session::desktop::ConnectionPlan::new(vec![member], vec![], fixture.plan().policy()).unwrap();
let request = gpapi::service::request::ConnectRequest::new(fixture.info().clone(), plan);
let mut prepared = PreparedConnection::lifecycle_fixture(request);
let mut params = GpParams::builder(prepared.resources.profile.clone());
+26 -18
View File
@@ -2,11 +2,13 @@ use std::{sync::Arc, time::Duration};
use anyhow::Context;
use gpapi::{
collection::{CollectionBudget, CollectionControl},
gp_params::GpParams,
os_profile::OsProfile,
process::collection::{CollectionBudget, CollectionControl},
service::request::ConnectRequest,
session::{GatewaySession, GatewaySessions, network::PhysicalNetwork, transport::GatewayTransport},
session::{
desktop::GatewaySession, desktop::GatewaySessions, desktop::network::PhysicalNetwork, transport::GatewayTransport,
},
};
use tokio_util::sync::CancellationToken;
@@ -149,14 +151,17 @@ impl PreparedConnection {
/// Lifecycle-only fixtures own no issued server sessions. Protocol ownership
/// checks use actual gateway transports rather than this actor-state fixture.
pub(crate) fn lifecycle_fixture(request: ConnectRequest) -> Self {
let profile = OsProfile::builder(gpapi::os_profile::ClientOs::Linux)
.host_identity(gpapi::os_profile::HostIdentity::from_parts(
"fixture".into(),
"fixture-host".into(),
"fixture-serial".into(),
"02:00:00:00:00:01".into(),
))
.build();
let profile = gpapi::os_profile::desktop::collect_profile(
OsProfile::builder(gpapi::os_profile::ClientOs::Linux).host_identity(
gpapi::os_profile::desktop::identity_from_parts(
"fixture".into(),
"fixture-host".into(),
"fixture-serial".into(),
"02:00:00:00:00:01".into(),
),
),
None,
);
Self {
request,
resources: Arc::new(ConnectionResources {
@@ -217,14 +222,17 @@ mod tests {
#[tokio::test]
async fn ordinary_tunnel_preparation_needs_no_physical_binding_or_resolver() {
let gateway = Gateway::new("fixture".into(), "does-not-resolve.invalid".into());
let profile = OsProfile::builder(gpapi::os_profile::ClientOs::Linux)
.host_identity(gpapi::os_profile::HostIdentity::from_parts(
"fixture".into(),
"fixture-host".into(),
"fixture-serial".into(),
"02:00:00:00:00:01".into(),
))
.build();
let profile = gpapi::os_profile::desktop::collect_profile(
OsProfile::builder(gpapi::os_profile::ClientOs::Linux).host_identity(
gpapi::os_profile::desktop::identity_from_parts(
"fixture".into(),
"fixture-host".into(),
"fixture-serial".into(),
"02:00:00:00:00:01".into(),
),
),
None,
);
let request = super::super::test_connect_request(ConnectInfo::new("portal.example.com".into(), gateway, vec![]))
.with_os_profile(&profile)
.with_disable_ipv6(true);
+4 -4
View File
@@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};
use anyhow::{Context, ensure};
use gpapi::{
process::collection::{CollectionBudget, CollectionControl},
collection::{CollectionBudget, CollectionControl},
service::request::ConnectRequest,
session::SessionMode,
};
@@ -77,8 +77,8 @@ pub(super) fn spawn(
.all(|member| member.authentication.mode() == SessionMode::NonTunnel)
{
match super::non_tunnel::run(&mut input, source, guard, cancellation.clone(), events.clone()).await {
Ok(gpapi::session::non_tunnel::SessionExit::Disconnected) => {}
Ok(gpapi::session::non_tunnel::SessionExit::Failed(reason)) => {
Ok(gpapi::session::desktop::non_tunnel::SessionExit::Disconnected) => {}
Ok(gpapi::session::desktop::non_tunnel::SessionExit::Failed(reason)) => {
let message = match reason {
gpapi::session::SessionEndReason::InvalidCookie => {
"Internal gateway authentication expired; connect again"
@@ -312,7 +312,7 @@ async fn run_tunnel(
prepared: &PreparedTunnel,
approval: &crate::hip_source::HipApproval,
lifecycle: &LifecycleHandle,
sessions: &mut gpapi::session::GatewaySessions,
sessions: &mut gpapi::session::desktop::GatewaySessions,
cancellation: CancellationToken,
events: mpsc::Sender<LifecycleEvent>,
) {
+3 -3
View File
@@ -60,7 +60,7 @@ pub(super) async fn run(
events: mpsc::Sender<LifecycleEvent>,
session_id: uuid::Uuid,
registry: Arc<crate::session_registry::SessionRegistry>,
sessions: &mut gpapi::session::GatewaySessions,
sessions: &mut gpapi::session::desktop::GatewaySessions,
) -> anyhow::Result<()> {
let attempt = identity.attempt;
let (native_tx, native) = mpsc::channel(64);
@@ -219,12 +219,12 @@ async fn supervise(
fn observed_network(
config: openconnect::tunnel::Configuration,
) -> anyhow::Result<gpapi::session::tunnel::NegotiatedNetwork> {
) -> anyhow::Result<gpapi::session::desktop::tunnel::NegotiatedNetwork> {
ensure!(
!config.truncated && !config.dns.truncated && !config.search_domains.truncated,
"VPN configuration is truncated"
);
Ok(gpapi::session::tunnel::NegotiatedNetwork {
Ok(gpapi::session::desktop::tunnel::NegotiatedNetwork {
addresses: [config.ipv4, config.ipv6.or(config.netmask6)]
.into_iter()
.flatten()
+6 -4
View File
@@ -41,7 +41,7 @@ pub(crate) struct ConnectionControl {
connection_id: Uuid,
tx: mpsc::Sender<ConnectionCommand>,
close_tx: watch::Sender<Option<CloseReason>>,
statistics: watch::Sender<Option<gpapi::session::tunnel::TunnelStatisticsSnapshot>>,
statistics: watch::Sender<Option<gpapi::session::desktop::tunnel::TunnelStatisticsSnapshot>>,
statistics_enabled: Arc<AtomicBool>,
committed: Arc<AtomicBool>,
}
@@ -102,13 +102,15 @@ impl ConnectionControl {
self.statistics.send_replace(None);
}
pub fn publish_statistics(&self, snapshot: gpapi::session::tunnel::TunnelStatisticsSnapshot) {
pub fn publish_statistics(&self, snapshot: gpapi::session::desktop::tunnel::TunnelStatisticsSnapshot) {
if self.statistics_enabled() && !self.is_closed() {
self.statistics.send_replace(Some(snapshot));
}
}
pub fn subscribe_statistics(&self) -> watch::Receiver<Option<gpapi::session::tunnel::TunnelStatisticsSnapshot>> {
pub fn subscribe_statistics(
&self,
) -> watch::Receiver<Option<gpapi::session::desktop::tunnel::TunnelStatisticsSnapshot>> {
self.statistics.subscribe()
}
@@ -750,7 +752,7 @@ mod tests {
.unwrap();
assert!(matches!(reply, ServerMessage::Reply {
id,
result: ServiceResult::TunnelStatisticsSnapshot(gpapi::session::tunnel::TunnelStatisticsSnapshot::Unavailable { reason: gpapi::session::tunnel::TunnelUnavailableReason::NoTunnel }),
result: ServiceResult::TunnelStatisticsSnapshot(gpapi::session::desktop::tunnel::TunnelStatisticsSnapshot::Unavailable { reason: gpapi::session::desktop::tunnel::TunnelUnavailableReason::NoTunnel }),
} if id == statistics_id));
let update_id = Uuid::new_v4();
+4 -4
View File
@@ -9,7 +9,7 @@ use gpapi::{
vpn_env::{HostInfo, VpnEnv},
vpn_state::VpnState,
},
session::tunnel::{TunnelStatisticsSnapshot, TunnelUnavailableReason},
session::desktop::tunnel::{TunnelStatisticsSnapshot, TunnelUnavailableReason},
utils::lock_file::LockFile,
};
use log::{info, warn};
@@ -397,7 +397,7 @@ fn build_snapshot(vpn_state: VpnState) -> VpnEnv {
vpnc_script: find_vpnc_script(),
auth_executable: binary_paths::gpauth().to_string_lossy().into_owned(),
host_info: HostInfo {
host_identity: HostIdentity::collect(),
host_identity: gpapi::os_profile::desktop::collect_identity(),
},
}
}
@@ -488,7 +488,7 @@ mod tests {
#[tokio::test]
async fn statistics_demand_is_per_attachment_and_does_not_consume_revisions() {
use gpapi::service::transport::ServiceResult;
use gpapi::session::tunnel::TunnelStatisticsState;
use gpapi::session::desktop::tunnel::TunnelStatisticsState;
let (context, registry) = context();
let (a, a_session, a_generation, _a_rx) = attach(&context, &registry).await;
let (b, b_session, b_generation, _b_rx) = attach(&context, &registry).await;
@@ -564,7 +564,7 @@ mod tests {
#[test]
fn snapshot_budget_trims_observation_without_changing_existing_metadata() {
use gpapi::session::tunnel::{TunnelConfiguration, TunnelPhase, TunnelState, TunnelTransport};
use gpapi::session::desktop::tunnel::{TunnelConfiguration, TunnelPhase, TunnelState, TunnelTransport};
let mut snapshot = build_snapshot(VpnState::Disconnected);
let mut configuration = TunnelConfiguration::default();
configuration.included_routes.items = vec!["r".repeat(1000); 15];