Skip to content

Commit

Permalink
After auth reset force_expired flag (#100)
Browse files Browse the repository at this point in the history
* After auth reset force_expired flag

* Bump versions
  • Loading branch information
loriopatrick authored Sep 2, 2024
1 parent fe6e3ca commit 1653bf2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
]

[workspace.package]
version = "0.15.22"
version = "0.15.23"

[workspace.dependencies]
tokio = { version = "1.39", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/agent_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playit-agent-core"
version = "0.17.5"
version = "0.17.6"
edition = "2021"
description = "Contains the logic to create a playit.gg agent"
license = "BSD-2-Clause"
Expand Down
22 changes: 20 additions & 2 deletions packages/agent_core/src/agent_control/established_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ impl<A: AuthResource, IO: PacketIO> EstablishedControl<A, IO> {
self.registered.expires_at
}

pub fn is_expired(&self) -> bool {
self.force_expired || self.pong_at_auth.session_expire_at.is_none() || self.flow_changed()
pub fn is_expired(&self) -> Option<ExpiredReason> {
if self.force_expired {
return Some(ExpiredReason::Forced);
}
if self.pong_at_auth.session_expire_at.is_none() {
return Some(ExpiredReason::SessionNotSetup);
}
if self.flow_changed() {
return Some(ExpiredReason::FlowChanged);
}
None
}

pub fn set_expired(&mut self) {
Expand All @@ -65,6 +74,7 @@ impl<A: AuthResource, IO: PacketIO> EstablishedControl<A, IO> {
pub async fn authenticate(&mut self) -> Result<(), SetupError> {
let registered = self.conn.authenticate(&self.auth).await?;

self.force_expired = false;
self.registered = registered;
self.pong_at_auth = self.conn.pong_latest.clone();

Expand Down Expand Up @@ -115,3 +125,11 @@ impl<A: AuthResource, IO: PacketIO> EstablishedControl<A, IO> {
Ok(feed)
}
}


#[derive(Debug, PartialEq, Eq)]
pub enum ExpiredReason {
Forced,
SessionNotSetup,
FlowChanged,
}
4 changes: 3 additions & 1 deletion packages/agent_core/src/agent_control/maintained_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ impl<I: PacketIO, A: AuthResource> MaintainedControl<I, A> {
}

pub async fn update(&mut self) -> Option<NewClient> {
if self.control.is_expired() {
if let Some(reason) = self.control.is_expired() {
tracing::warn!(?reason, "session expired");

if let Err(error) = self.control.authenticate().await {
tracing::error!(?error, "failed to authenticate");
tokio::time::sleep(Duration::from_secs(2)).await;
Expand Down

0 comments on commit 1653bf2

Please sign in to comment.