Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add support for tls connections in network-v2 rpc client #1655

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading