@@ -25,6 +25,7 @@ use std::time::Duration;
2525use once_cell:: sync:: OnceCell ;
2626use tonic:: transport:: {
2727 Channel ,
28+ ClientTlsConfig ,
2829 Endpoint ,
2930} ;
3031use triomphe:: Arc ;
@@ -33,9 +34,9 @@ use crate::ArcSwap;
3334
3435pub ( crate ) const MAINNET : & str = "mainnet-public.mirrornode.hedera.com:443" ;
3536
36- pub ( crate ) const TESTNET : & str = "hcs. testnet.mirrornode.hedera.com:5600 " ;
37+ pub ( crate ) const TESTNET : & str = "testnet.mirrornode.hedera.com:443 " ;
3738
38- pub ( crate ) const PREVIEWNET : & str = "hcs. previewnet.mirrornode.hedera.com:5600 " ;
39+ pub ( crate ) const PREVIEWNET : & str = "previewnet.mirrornode.hedera.com:443 " ;
3940
4041#[ derive( Default ) ]
4142pub ( crate ) struct MirrorNetwork ( ArcSwap < MirrorNetworkData > ) ;
@@ -50,15 +51,21 @@ impl Deref for MirrorNetwork {
5051
5152impl MirrorNetwork {
5253 pub ( crate ) fn mainnet ( ) -> Self {
53- Self ( ArcSwap :: new ( Arc :: new ( MirrorNetworkData :: from_static ( & [ MAINNET ] ) ) ) )
54+ Self :: network ( MAINNET )
5455 }
5556
5657 pub ( crate ) fn testnet ( ) -> Self {
57- Self ( ArcSwap :: new ( Arc :: new ( MirrorNetworkData :: from_static ( & [ TESTNET ] ) ) ) )
58+ Self :: network ( TESTNET )
5859 }
5960
6061 pub ( crate ) fn previewnet ( ) -> Self {
61- Self ( ArcSwap :: new ( Arc :: new ( MirrorNetworkData :: from_static ( & [ PREVIEWNET ] ) ) ) )
62+ Self :: network ( PREVIEWNET )
63+ }
64+
65+ fn network ( address : & ' static str ) -> Self {
66+ let tls_config = ClientTlsConfig :: new ( ) . domain_name ( address. split_once ( ':' ) . unwrap ( ) . 0 ) ;
67+
68+ Self ( ArcSwap :: new ( Arc :: new ( MirrorNetworkData :: from_static ( & [ address] , tls_config) ) ) )
6269 }
6370
6471 #[ cfg( feature = "serde" ) ]
@@ -71,21 +78,22 @@ impl MirrorNetwork {
7178pub ( crate ) struct MirrorNetworkData {
7279 addresses : Vec < Cow < ' static , str > > ,
7380 channel : OnceCell < Channel > ,
81+ tls_config : ClientTlsConfig ,
7482}
7583
7684impl MirrorNetworkData {
7785 pub ( crate ) fn from_addresses ( addresses : Vec < Cow < ' static , str > > ) -> Self {
78- Self { addresses, channel : OnceCell :: new ( ) }
86+ Self { addresses, channel : OnceCell :: new ( ) , tls_config : ClientTlsConfig :: new ( ) }
7987 }
8088
81- pub ( crate ) fn from_static ( network : & [ & ' static str ] ) -> Self {
89+ pub ( crate ) fn from_static ( network : & [ & ' static str ] , tls_config : ClientTlsConfig ) -> Self {
8290 let mut addresses = Vec :: with_capacity ( network. len ( ) ) ;
8391
8492 for address in network {
8593 addresses. push ( Cow :: Borrowed ( * address) ) ;
8694 }
8795
88- Self { addresses, channel : OnceCell :: new ( ) }
96+ Self { addresses, channel : OnceCell :: new ( ) , tls_config }
8997 }
9098
9199 pub ( crate ) fn channel ( & self ) -> Channel {
@@ -96,6 +104,8 @@ impl MirrorNetworkData {
96104 Endpoint :: from_shared ( uri)
97105 . unwrap ( )
98106 . keep_alive_timeout ( Duration :: from_secs ( 10 ) )
107+ . tls_config ( self . tls_config . clone ( ) )
108+ . unwrap ( )
99109 . keep_alive_while_idle ( true )
100110 . tcp_keepalive ( Some ( Duration :: from_secs ( 10 ) ) )
101111 . connect_timeout ( Duration :: from_secs ( 10 ) )
0 commit comments