From dde2d88dde8f77318996d5c9400f1e73cbe415fc Mon Sep 17 00:00:00 2001 From: Noor Date: Wed, 18 Jun 2025 11:40:23 +0000 Subject: [PATCH] Improves brain connection reliability Updates the brain connection logic to randomly select from a list of available URLs for staging and testnet environments. --- src/global.rs | 27 +++++++++++++++++++++++++-- src/grpc.rs | 4 ++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/global.rs b/src/global.rs index 4a0dcca..2d23fe7 100644 --- a/src/global.rs +++ b/src/global.rs @@ -3,20 +3,43 @@ use anyhow::Result; use ed25519_dalek::SigningKey; use log::{info, warn}; +use rand::Rng; use sha2::{Digest, Sha256}; use std::fs::File; use std::io::{Read, Write}; use std::sync::LazyLock; pub const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem"; -pub const BRAIN_STAGING: (&str, &str) = ("https://159.65.58.38:31337", "staging-brain"); -pub const BRAIN_TESTING: (&str, &str) = ("https://164.92.249.180:31337", "testnet-brain"); +pub(crate) const BRAIN_STAGING_URLS: [&str; 3] = [ + "https://184.107.169.199:49092", + "https://149.22.95.1:47855", + "https://149.36.48.99:48843", +]; +pub(crate) const BRAIN_TESTING_URLS: [&str; 3] = [ + "https://184.107.169.199:45223", + "https://149.22.95.1:44522", + "https://149.36.48.99:48638", +]; pub const PACKAGE_ARCHIVE_POSTFIX: &str = "-enclave_package.tar.gz"; pub const PACKAGE_ARCHIVE_DIR_PATH: &str = "/var/lib/detee/archives"; pub const PACKAGE_DIR_PATH: &str = "/var/lib/detee/enclaves"; pub const APP_NAME_PREFIX: &str = "dtpm"; +pub static BRAIN_STAGING: LazyLock<(&str, &str)> = LazyLock::new(|| { + ( + BRAIN_STAGING_URLS[rand::thread_rng().gen_range(0..BRAIN_STAGING_URLS.len())], + "staging-brain", + ) +}); + +pub static BRAIN_TESTING: LazyLock<(&str, &str)> = LazyLock::new(|| { + ( + BRAIN_TESTING_URLS[rand::thread_rng().gen_range(0..BRAIN_TESTING_URLS.len())], + "testnet-brain", + ) +}); + // const DETEE_DIR_ENV_NAME: &str = "DETEE_DIR"; pub static IP_INFO: LazyLock = diff --git a/src/grpc.rs b/src/grpc.rs index 1047a18..2b50c2f 100644 --- a/src/grpc.rs +++ b/src/grpc.rs @@ -26,8 +26,8 @@ pub struct ConnectionData { async fn client(network: &str) -> Result> { let (brain_url, brain_san) = match network { - "staging" => BRAIN_STAGING, - "testnet" => BRAIN_TESTING, + "staging" => *BRAIN_STAGING, + "testnet" => *BRAIN_TESTING, _ => { return Err(anyhow::anyhow!( "The only networks currently supported are staging and testnet."