From 9e960d98e4914793493cbf60bdbf397c3248ec1b Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Wed, 4 Sep 2024 21:45:43 +0000 Subject: [PATCH] daemon: session doesn't need to be mutable --- daemon/src/connection.rs | 14 +++++++------- daemon/src/main.rs | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/daemon/src/connection.rs b/daemon/src/connection.rs index b6dc686..36935a7 100644 --- a/daemon/src/connection.rs +++ b/daemon/src/connection.rs @@ -269,7 +269,7 @@ impl CMSession { tokio::spawn(async move { cloned.send_heartbeat_task(interval).await }); } - async fn send_heartbeat_task(mut self, interval_secs: u32) -> eyre::Result<()> { + async fn send_heartbeat_task(self, interval_secs: u32) -> eyre::Result<()> { let mut interval = tokio::time::interval(time::Duration::from_secs(interval_secs as u64)); loop { interval.tick().await; @@ -277,18 +277,18 @@ impl CMSession { } } - pub fn set_steam_id(&mut self, new_steam_id: u64) { + pub fn set_steam_id(&self, new_steam_id: u64) { let mut inner = self.inner.lock().expect("Lock was poisoned"); inner.steam_id = Some(new_steam_id); } - pub fn set_client_session_id(&mut self, new_client_session_id: i32) { + pub fn set_client_session_id(&self, new_client_session_id: i32) { let mut inner = self.inner.lock().expect("Lock was poisoned"); inner.client_session_id = new_client_session_id; } pub fn call_service_method( - &mut self, + &self, method: String, body: T, ) -> CallServiceMethod { @@ -306,7 +306,7 @@ impl CMSession { /// Send a message without a jobid. /// Returns as soon as the message is in the send buffer pub fn send_notification( - &mut self, + &self, action: EMsg, body: T, ) -> eyre::Result<()> { @@ -339,7 +339,7 @@ impl CMSession { /// Subscribe to receive a notification every time a message of a /// given type is received pub fn subscribe_message_type( - &mut self, + &self, action: EMsg, ) -> broadcast::Receiver { let mut inner = self.inner.lock().expect("Lock was poisoned"); @@ -355,7 +355,7 @@ impl CMSession { #[must_use = "futures do nothing unless polled"] pub struct CallServiceMethod<'a, T: protobuf::Message, U: protobuf::Message> { - session: &'a mut CMSession, + session: &'a CMSession, body: T, method: String, jobid: Option, diff --git a/daemon/src/main.rs b/daemon/src/main.rs index 7cac8cb..ce98cf1 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -28,7 +28,7 @@ pub async fn main() -> eyre::Result<()> { let servers = connection::bootstrap_find_servers().await?; log::debug!("Found servers: {:?}", servers); - let mut session = connection::CMSession::connect(&servers[0]).await?; + let session = connection::CMSession::connect(&servers[0]).await?; session.send_notification( EMsg::k_EMsgClientHello, @@ -97,7 +97,6 @@ pub async fn main() -> eyre::Result<()> { let session_cloned = session.clone(); let poll_handle = tokio::spawn(async move { - let mut session = session_cloned; loop { interval.tick().await; let request = CAuthentication_PollAuthSessionStatus_Request { @@ -106,7 +105,7 @@ pub async fn main() -> eyre::Result<()> { ..Default::default() }; let response: CMProtoBufMessage = - session + session_cloned .call_service_method( "Authentication.PollAuthSessionStatus#1".to_string(), request, @@ -164,7 +163,7 @@ pub async fn main() -> eyre::Result<()> { }, )?; - let mut session_cloned = session.clone(); + let session_cloned = session.clone(); tokio::spawn(async move { let license_list_raw = session_cloned .subscribe_message_type(EMsg::k_EMsgClientLicenseList)