Improves brain connection reliability
Updates the brain connection logic to randomly select from a list of available URLs for staging and testnet environments.
This commit is contained in:
		
							parent
							
								
									79968b2d1e
								
							
						
					
					
						commit
						8d07122df2
					
				| @ -2,12 +2,19 @@ use anyhow::Result; | ||||
| use ed25519_dalek::SigningKey; | ||||
| use lazy_static::lazy_static; | ||||
| use log::{info, warn}; | ||||
| use rand::Rng; | ||||
| use sha2::{Digest, Sha256}; | ||||
| use std::{fs::File, io::Read, io::Write}; | ||||
| use std::{ | ||||
|     fs::File, | ||||
|     io::{Read, Write}, | ||||
|     sync::LazyLock, | ||||
| }; | ||||
| 
 | ||||
| pub(crate) const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem"; | ||||
| pub(crate) const BRAIN_STAGING: (&str, &str) = ("https://184.107.169.199:49092", "staging-brain"); | ||||
| pub(crate) 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(crate) const VM_BOOT_DIR: &str = "/var/lib/detee/boot/"; | ||||
| pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml"; | ||||
| pub(crate) const VM_CONFIG_DIR: &str = "/etc/detee/daemon/vms/"; | ||||
| @ -22,6 +29,14 @@ pub(crate) const OVMF_HASH: &str = | ||||
| pub(crate) const OVMF_URL: &str = | ||||
|     "https://drive.google.com/uc?export=download&id=1V-vLkaiLaGmFSjrN84Z6nELQOxKNAoSJ"; | ||||
| 
 | ||||
| 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") | ||||
| }); | ||||
| 
 | ||||
| lazy_static! { | ||||
|     pub static ref PUBLIC_KEY: String = get_public_key(); | ||||
|     pub static ref IP_INFO: IPInfo = get_ip_info().unwrap(); | ||||
|  | ||||
| @ -16,14 +16,16 @@ pub mod snp_proto { | ||||
| 
 | ||||
| async fn client(network: &str) -> Result<BrainVmDaemonClient<Channel>> { | ||||
|     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." | ||||
|             )) | ||||
|         } | ||||
|     }; | ||||
|     info!("brain_url: {brain_url}, brain_san: {brain_san}"); | ||||
| 
 | ||||
|     let pem = std::fs::read_to_string(DETEE_ROOT_CA)?; | ||||
|     let ca = Certificate::from_pem(pem); | ||||
| 
 | ||||
|  | ||||
| @ -251,9 +251,7 @@ async fn main() { | ||||
| 
 | ||||
|         info!("Registering with the brain and getting back deleted VMs."); | ||||
|         match grpc::register_node(&vm_handler.config).await { | ||||
|             Ok(deleted_vms) => { | ||||
|                 vm_handler.clear_deleted_contracts(deleted_vms) | ||||
|             } | ||||
|             Ok(deleted_vms) => vm_handler.clear_deleted_contracts(deleted_vms), | ||||
|             Err(e) => log::error!("Could not get contracts from brain: {e:?}"), | ||||
|         }; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user