Skip to content

Commit 29d512a

Browse files
authored
Merge pull request #653 from hashgraph/sr/mirror-tls
2 parents fafe577 + fec005e commit 29d512a

File tree

7 files changed

+244
-87
lines changed

7 files changed

+244
-87
lines changed

Cargo.lock

Lines changed: 180 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ sha3 = "0.10.2"
4141
thiserror = "1.0.31"
4242
time = "0.3.9"
4343
tokio = { version = "1.24.2", features = ["time"] }
44-
tonic = "0.9.0"
44+
tonic = { version = "0.9.0", features = ["tls", "tls-webpki-roots"] }
4545
tinystr = { version = "0.7.0", default-features = false }
4646
arc-swap = "1.6.0"
4747
rlp = "0.5.2"

src/client/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ impl Client {
238238
/// Current return values (reminder that these are semver exempt)
239239
///
240240
/// - mainnet: `["mainnet-public.mirrornode.hedera.com:443"]`
241-
/// - testnet: `["hcs.testnet.mirrornode.hedera.com:5600"]`
242-
/// - previewnet: `["hcs.previewnet.mirrornode.hedera.com:5600"]`
241+
/// - testnet: `["testnet.mirrornode.hedera.com:443"]`
242+
/// - previewnet: `["previewnet.mirrornode.hedera.com:443"]`
243243
///
244244
/// # Examples
245245
///
@@ -251,7 +251,7 @@ impl Client {
251251
/// let client = Client::for_testnet();
252252
///
253253
/// // note: This isn't *guaranteed* in a semver sense, but this is the current result.
254-
/// let expected = Vec::from(["hcs.testnet.mirrornode.hedera.com:5600".to_owned()]);
254+
/// let expected = Vec::from(["testnet.mirrornode.hedera.com:443".to_owned()]);
255255
/// assert_eq!(expected, client.mirror_network());
256256
///
257257
/// # }

src/client/network/mirror.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use std::time::Duration;
2525
use once_cell::sync::OnceCell;
2626
use tonic::transport::{
2727
Channel,
28+
ClientTlsConfig,
2829
Endpoint,
2930
};
3031
use triomphe::Arc;
@@ -33,9 +34,9 @@ use crate::ArcSwap;
3334

3435
pub(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)]
4142
pub(crate) struct MirrorNetwork(ArcSwap<MirrorNetworkData>);
@@ -50,15 +51,21 @@ impl Deref for MirrorNetwork {
5051

5152
impl 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 {
7178
pub(crate) struct MirrorNetworkData {
7279
addresses: Vec<Cow<'static, str>>,
7380
channel: OnceCell<Channel>,
81+
tls_config: ClientTlsConfig,
7482
}
7583

7684
impl 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

Comments
 (0)