new brain proto and new staging address
This commit is contained in:
		
							parent
							
								
									82c4653a1c
								
							
						
					
					
						commit
						145815a133
					
				
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -395,7 +395,7 @@ dependencies = [ | ||||
| [[package]] | ||||
| name = "detee-shared" | ||||
| version = "0.1.0" | ||||
| source = "git+ssh://git@gitea.detee.cloud/testnet/proto?branch=main#b5289f1f5ba3ddae2ee066d6deb073ce92436b71" | ||||
| source = "git+ssh://git@gitea.detee.cloud/testnet/proto?branch=surreal_brain#d6ca058d2de78b5257517034bca2b2c7d5929db8" | ||||
| dependencies = [ | ||||
|  "bincode", | ||||
|  "prost", | ||||
|  | ||||
| @ -24,7 +24,8 @@ serde_json = "1.0.135" | ||||
| bs58 = "0.5.1" | ||||
| chrono = "0.4.39" | ||||
| 
 | ||||
| detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto", branch = "main" } | ||||
| # TODO: switch this back to main after the upgrade | ||||
| detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto", branch = "surreal_brain" } | ||||
| # detee-shared = { path = "../detee-shared" } | ||||
| 
 | ||||
| [build-dependencies] | ||||
|  | ||||
| @ -6,7 +6,7 @@ use sha2::{Digest, Sha256}; | ||||
| use std::{fs::File, io::Read, io::Write}; | ||||
| 
 | ||||
| pub(crate) const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem"; | ||||
| pub(crate) const BRAIN_STAGING: (&str, &str) = ("https://159.65.58.38:31337", "staging-brain"); | ||||
| pub(crate) const BRAIN_STAGING: (&str, &str) = ("https://149.36.48.100:31337", "staging-brain"); | ||||
| pub(crate) const BRAIN_TESTING: (&str, &str) = ("https://164.92.249.180:31337", "testnet-brain"); | ||||
| pub(crate) const VM_BOOT_DIR: &str = "/var/lib/detee/boot/"; | ||||
| pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml"; | ||||
|  | ||||
							
								
								
									
										15
									
								
								src/grpc.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										15
									
								
								src/grpc.rs
									
									
									
									
									
								
							| @ -1,10 +1,8 @@ | ||||
| use crate::global::*; | ||||
| use crate::snp_proto::VmDaemonMessage; | ||||
| use crate::{global::*, snp_proto::VmDaemonMessage}; | ||||
| use anyhow::Result; | ||||
| use detee_shared::vm_proto::DeleteVmReq; | ||||
| use log::{debug, info, warn}; | ||||
| use snp_proto::{ | ||||
|     brain_vm_daemon_client::BrainVmDaemonClient, BrainVmMessage, RegisterVmNodeReq, VmContract, | ||||
| }; | ||||
| use snp_proto::{brain_vm_daemon_client::BrainVmDaemonClient, BrainVmMessage, RegisterVmNodeReq}; | ||||
| use tokio::{ | ||||
|     sync::mpsc::{Receiver, Sender}, | ||||
|     task::JoinSet, | ||||
| @ -36,9 +34,8 @@ async fn client(network: &str) -> Result<BrainVmDaemonClient<Channel>> { | ||||
|     Ok(BrainVmDaemonClient::new(channel)) | ||||
| } | ||||
| 
 | ||||
| pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> { | ||||
|     use tonic::metadata::AsciiMetadataValue; | ||||
|     use tonic::Request; | ||||
| pub async fn register_node(config: &crate::config::Config) -> Result<Vec<DeleteVmReq>> { | ||||
|     use tonic::{metadata::AsciiMetadataValue, Request}; | ||||
|     let mut client = client(&config.network).await?; | ||||
|     debug!("Starting node registration..."); | ||||
|     let ip_info = IP_INFO.clone(); | ||||
| @ -68,7 +65,7 @@ pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContr | ||||
|     while let Some(stream_update) = grpc_stream.next().await { | ||||
|         match stream_update { | ||||
|             Ok(node) => { | ||||
|                 debug!("Received contract from brain: {node:?}"); | ||||
|                 debug!("Received deleted VM from brain: {node:?}"); | ||||
|                 contracts.push(node); | ||||
|             } | ||||
|             Err(e) => { | ||||
|  | ||||
							
								
								
									
										56
									
								
								src/main.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										56
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -3,8 +3,7 @@ mod global; | ||||
| mod grpc; | ||||
| mod state; | ||||
| 
 | ||||
| use crate::global::*; | ||||
| use crate::{config::Config, grpc::snp_proto}; | ||||
| use crate::{config::Config, global::*, grpc::snp_proto}; | ||||
| use anyhow::{anyhow, Result}; | ||||
| use log::{debug, info, warn}; | ||||
| use std::{fs::File, path::Path}; | ||||
| @ -205,31 +204,27 @@ impl VMHandler { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fn clear_deleted_contracts(&mut self, contracts: Vec<snp_proto::VmContract>) { | ||||
|         for uuid in self.res.existing_vms.clone() { | ||||
|             if contracts.iter().find(|c| c.uuid == uuid).is_none() { | ||||
|                 info!("VM {uuid} exists locally but not found in brain. Deleting..."); | ||||
|                 let content = | ||||
|                     match std::fs::read_to_string(VM_CONFIG_DIR.to_string() + &uuid + ".yaml") { | ||||
|                         Ok(content) => content, | ||||
|                         Err(e) => { | ||||
|                             log::error!( | ||||
|                                 "Could not find VM config for {uuid}. Cannot delete VM: {e:?}" | ||||
|                             ); | ||||
|                             continue; | ||||
|                         } | ||||
|                     }; | ||||
|                 let vm: crate::state::VM = match serde_yaml::from_str(&content) { | ||||
|                     Ok(vm) => vm, | ||||
|                     Err(e) => { | ||||
|                         log::error!("VM config corrupted for {uuid}. Cannot delete VM: {e:?}"); | ||||
|                         continue; | ||||
|                     } | ||||
|                 }; | ||||
|                 match vm.delete(&mut self.res) { | ||||
|                     Ok(()) => info!("Successfully deleted VM {uuid}"), | ||||
|                     Err(e) => log::error!("Deletion failed for VM {uuid}: {e:?}"), | ||||
|     fn clear_deleted_contracts(&mut self, deleted_vms: Vec<snp_proto::DeleteVmReq>) { | ||||
|         for deleted_vm in deleted_vms { | ||||
|             let uuid = deleted_vm.uuid; | ||||
|             let content = match std::fs::read_to_string(VM_CONFIG_DIR.to_string() + &uuid + ".yaml") | ||||
|             { | ||||
|                 Ok(content) => content, | ||||
|                 Err(e) => { | ||||
|                     log::debug!("Could not find VM config for {uuid}. Maybe it already got deleted? Error: {e:?}"); | ||||
|                     continue; | ||||
|                 } | ||||
|             }; | ||||
|             let vm: crate::state::VM = match serde_yaml::from_str(&content) { | ||||
|                 Ok(vm) => vm, | ||||
|                 Err(e) => { | ||||
|                     log::error!("VM config corrupted for {uuid}. Cannot delete VM: {e:?}"); | ||||
|                     continue; | ||||
|                 } | ||||
|             }; | ||||
|             match vm.delete(&mut self.res) { | ||||
|                 Ok(()) => info!("Successfully deleted VM {uuid}"), | ||||
|                 Err(e) => log::error!("Deletion failed for VM {uuid}: {e:?}"), | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| @ -252,13 +247,12 @@ async fn main() { | ||||
| 
 | ||||
|         let mut vm_handler = VMHandler::new(brain_msg_rx, daemon_msg_tx.clone()); | ||||
|         let network = vm_handler.config.network.clone(); | ||||
|         let contracts: Vec<String> = vm_handler.res.existing_vms.clone().into_iter().collect(); | ||||
| 
 | ||||
|         info!("Registering with the brain and getting back VM Contracts (if they exist)."); | ||||
|         let mut contracts: Vec<String> = Vec::new(); | ||||
|         info!("Registering with the brain and getting back deleted VMs."); | ||||
|         match grpc::register_node(&vm_handler.config).await { | ||||
|             Ok(c) => { | ||||
|                 contracts.append(&mut c.iter().map(|c| c.uuid.clone()).collect()); | ||||
|                 vm_handler.clear_deleted_contracts(c) | ||||
|             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