File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
protocol-units/da/movement/protocol/client Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ rust-version = { workspace = true }
13
13
14
14
[dependencies ]
15
15
movement-da-light-node-proto = { workspace = true , features = [" client" ] }
16
- tonic = { workspace = true }
16
+ tonic = { workspace = true , features = [ " tls " , " tls-webpki-roots " ] }
17
17
tonic-web = { workspace = true }
18
18
hyper-util = { workspace = true }
19
19
tower = { workspace = true }
Original file line number Diff line number Diff line change 1
1
use movement_da_light_node_proto:: light_node_service_client:: LightNodeServiceClient ;
2
+ use std:: time:: Duration ;
3
+ use tonic:: transport:: { Channel , ClientTlsConfig } ;
2
4
3
5
#[ derive( Debug , Clone ) ]
4
6
pub struct Http2 {
@@ -8,7 +10,20 @@ pub struct Http2 {
8
10
impl Http2 {
9
11
/// Connects to a light node service using the given connection string.
10
12
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
+
12
27
Ok ( Http2 { client } )
13
28
}
14
29
You can’t perform that action at this time.
0 commit comments