Skip to content

Commit

Permalink
fix: add support for tls connections in network-v2 rpc client (#1655)
Browse files Browse the repository at this point in the history
  • Loading branch information
yourbuddyconner authored Oct 17, 2024
1 parent 3b661c0 commit 1b0d5fe
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions crates/sdk/src/network-v2/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::sync::OnceCell;
use tokio::try_join;
use tonic::transport::channel::ClientTlsConfig;
use tonic::transport::Channel;

use crate::network_v2::proto::artifact::{
Expand Down Expand Up @@ -58,14 +59,32 @@ impl NetworkClient {
/// Get a connected RPC client.
async fn get_rpc(&self) -> Result<ProverNetworkClient<Channel>> {
let rpc_url = Self::rpc_url();
let channel = Channel::from_shared(rpc_url)?.connect().await?;
Ok(ProverNetworkClient::new(channel.clone()))
let mut endpoint = Channel::from_shared(rpc_url.clone())?;

// Check if the URL scheme is HTTPS and configure TLS.
if rpc_url.starts_with("https://") {
println!("Using TLS");
let tls_config = ClientTlsConfig::new().with_enabled_roots();
endpoint = endpoint.tls_config(tls_config)?;
}

let channel = endpoint.connect().await?;
Ok(ProverNetworkClient::new(channel))
}

/// Get a connected artifact store client.
async fn get_store(&self) -> Result<ArtifactStoreClient<Channel>> {
let rpc_url = Self::rpc_url();
let channel = Channel::from_shared(rpc_url)?.connect().await?;
let mut endpoint = Channel::from_shared(rpc_url.clone())?;

// Check if the URL scheme is HTTPS and configure TLS.
if rpc_url.starts_with("https://") {
println!("Using TLS");
let tls_config = ClientTlsConfig::new().with_enabled_roots();
endpoint = endpoint.tls_config(tls_config)?;
}

let channel = endpoint.connect().await?;
Ok(ArtifactStoreClient::new(channel.clone()))
}

Expand Down Expand Up @@ -203,6 +222,9 @@ impl NetworkClient {
let response =
self.http.put(&presigned_url).body(bincode::serialize::<T>(item)?).send().await?;

if !response.status().is_success() {
log::debug!("Artifact upload failed with status: {}", response.status());
}
assert!(response.status().is_success());

Ok(uri)
Expand Down

0 comments on commit 1b0d5fe

Please sign in to comment.