From 730f2a97a8b9903c508ef47aa6a6de80daff38f8 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Thu, 28 Nov 2024 23:43:04 +0200 Subject: [PATCH 1/2] configure grpc connection for breez server (cherry picked from commit a5073e73105e9265cacd3169c741e7209c03a596) --- libs/sdk-common/src/breez_server.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/sdk-common/src/breez_server.rs b/libs/sdk-common/src/breez_server.rs index f1e10b6a2..08e83fff1 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; @@ -29,18 +31,26 @@ 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))) + .http2_keep_alive_interval(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( From d4c6fae9e1b12111a9094d40c49555d910cdfb23 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Fri, 29 Nov 2024 16:59:40 +0200 Subject: [PATCH 2/2] remove duplicate call --- libs/sdk-common/src/breez_server.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/sdk-common/src/breez_server.rs b/libs/sdk-common/src/breez_server.rs index 08e83fff1..035babc1f 100644 --- a/libs/sdk-common/src/breez_server.rs +++ b/libs/sdk-common/src/breez_server.rs @@ -46,7 +46,6 @@ impl BreezServer { Ok(Endpoint::from_shared(server_url.to_string())? .http2_keep_alive_interval(Duration::new(5, 0)) .tcp_keepalive(Some(Duration::from_secs(5))) - .http2_keep_alive_interval(Duration::from_secs(5)) .keep_alive_timeout(Duration::from_secs(5)) .keep_alive_while_idle(true)) }