Skip to content

Commit

Permalink
correct DA client http2 connection
Browse files Browse the repository at this point in the history
  • Loading branch information
musitdev committed Mar 3, 2025
1 parent 7b6f1f7 commit 7e8d9b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion protocol-units/da/movement/protocol/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = { workspace = true }

[dependencies]
movement-da-light-node-proto = { workspace = true, features = ["client"] }
tonic = { workspace = true}
tonic = { workspace = true, features = ["tls", "tls-webpki-roots"]}
tonic-web = { workspace = true }
hyper-util = { workspace = true }
tower = { workspace = true }
Expand Down
17 changes: 16 additions & 1 deletion protocol-units/da/movement/protocol/client/src/http2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use movement_da_light_node_proto::light_node_service_client::LightNodeServiceClient;
use std::time::Duration;
use tonic::transport::{Channel, ClientTlsConfig};

#[derive(Debug, Clone)]
pub struct Http2 {
Expand All @@ -8,7 +10,20 @@ pub struct Http2 {
impl Http2 {
/// Connects to a light node service using the given connection string.
pub async fn connect(connection_string: &str) -> Result<Self, anyhow::Error> {
let client = LightNodeServiceClient::connect(connection_string.to_string()).await?;
let endpoint = Channel::from_shared(connection_string.to_string())?;

// Dynamically configure TLS based on the scheme (http or https)
let endpoint = if connection_string.starts_with("https://") {
endpoint
.tls_config(ClientTlsConfig::new().with_enabled_roots())?
.http2_keep_alive_interval(Duration::from_secs(10))
} else {
endpoint
};

let channel = endpoint.connect().await?;
let client = LightNodeServiceClient::new(channel);

Ok(Http2 { client })
}

Expand Down

0 comments on commit 7e8d9b6

Please sign in to comment.