Skip to content

Commit 8d89aac

Browse files
musitdevnicholasflintwillow
authored andcommitted
fix: Correct DA client http2 connection (#1079)
1 parent 750d594 commit 8d89aac

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

protocol-units/da/movement/protocol/client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rust-version = { workspace = true }
1313

1414
[dependencies]
1515
movement-da-light-node-proto = { workspace = true, features = ["client"] }
16-
tonic = { workspace = true}
16+
tonic = { workspace = true, features = ["tls", "tls-webpki-roots"]}
1717
tonic-web = { workspace = true }
1818
hyper-util = { workspace = true }
1919
tower = { workspace = true }

protocol-units/da/movement/protocol/client/src/http2.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use movement_da_light_node_proto::light_node_service_client::LightNodeServiceClient;
2+
use std::time::Duration;
3+
use tonic::transport::{Channel, ClientTlsConfig};
24

35
#[derive(Debug, Clone)]
46
pub struct Http2 {
@@ -8,7 +10,20 @@ pub struct Http2 {
810
impl Http2 {
911
/// Connects to a light node service using the given connection string.
1012
pub async fn connect(connection_string: &str) -> Result<Self, anyhow::Error> {
11-
let client = LightNodeServiceClient::connect(connection_string.to_string()).await?;
13+
let endpoint = Channel::from_shared(connection_string.to_string())?;
14+
15+
// Dynamically configure TLS based on the scheme (http or https)
16+
let endpoint = if connection_string.starts_with("https://") {
17+
endpoint
18+
.tls_config(ClientTlsConfig::new().with_enabled_roots())?
19+
.http2_keep_alive_interval(Duration::from_secs(10))
20+
} else {
21+
endpoint
22+
};
23+
24+
let channel = endpoint.connect().await?;
25+
let client = LightNodeServiceClient::new(channel);
26+
1227
Ok(Http2 { client })
1328
}
1429

0 commit comments

Comments
 (0)