diff --git a/libs/sdk-common/src/breez_server.rs b/libs/sdk-common/src/breez_server.rs index c78e0b786..0cc668370 100644 --- a/libs/sdk-common/src/breez_server.rs +++ b/libs/sdk-common/src/breez_server.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use anyhow::Result; use log::trace; use tokio::sync::Mutex; @@ -30,18 +32,25 @@ pub struct BreezServer { impl BreezServer { pub fn new(server_url: String, api_key: Option) -> Result { Ok(Self { - grpc_channel: Mutex::new(Endpoint::from_shared(server_url.clone())?.connect_lazy()), + grpc_channel: Mutex::new(Self::create_endpoint(&server_url)?.connect_lazy()), api_key, server_url, }) } pub async fn reconnect(&self) -> Result<()> { - *self.grpc_channel.lock().await = - Endpoint::from_shared(self.server_url.clone())?.connect_lazy(); + *self.grpc_channel.lock().await = Self::create_endpoint(&self.server_url)?.connect_lazy(); Ok(()) } + fn create_endpoint(server_url: &str) -> Result { + Ok(Endpoint::from_shared(server_url.to_string())? + .http2_keep_alive_interval(Duration::new(5, 0)) + .tcp_keepalive(Some(Duration::from_secs(5))) + .keep_alive_timeout(Duration::from_secs(5)) + .keep_alive_while_idle(true)) + } + fn api_key_metadata(&self) -> Result>, ServiceConnectivityError> { match &self.api_key { Some(key) => Ok(Some(format!("Bearer {key}").parse().map_err(