Compare commits
	
		
			1 Commits
		
	
	
		
			44e560fcc0
			...
			79968b2d1e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 79968b2d1e | 
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -395,7 +395,7 @@ dependencies = [
 | 
				
			|||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "detee-shared"
 | 
					name = "detee-shared"
 | 
				
			||||||
version = "0.1.0"
 | 
					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 = [
 | 
					dependencies = [
 | 
				
			||||||
 "bincode",
 | 
					 "bincode",
 | 
				
			||||||
 "prost",
 | 
					 "prost",
 | 
				
			||||||
 | 
				
			|||||||
@ -24,7 +24,8 @@ serde_json = "1.0.135"
 | 
				
			|||||||
bs58 = "0.5.1"
 | 
					bs58 = "0.5.1"
 | 
				
			||||||
chrono = "0.4.39"
 | 
					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" }
 | 
					# detee-shared = { path = "../detee-shared" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[build-dependencies]
 | 
					[build-dependencies]
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ use sha2::{Digest, Sha256};
 | 
				
			|||||||
use std::{fs::File, io::Read, io::Write};
 | 
					use std::{fs::File, io::Read, io::Write};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub(crate) const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem";
 | 
					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://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_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 VM_BOOT_DIR: &str = "/var/lib/detee/boot/";
 | 
				
			||||||
pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml";
 | 
					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::{global::*, snp_proto::VmDaemonMessage};
 | 
				
			||||||
use crate::snp_proto::VmDaemonMessage;
 | 
					 | 
				
			||||||
use anyhow::Result;
 | 
					use anyhow::Result;
 | 
				
			||||||
 | 
					use detee_shared::vm_proto::DeleteVmReq;
 | 
				
			||||||
use log::{debug, info, warn};
 | 
					use log::{debug, info, warn};
 | 
				
			||||||
use snp_proto::{
 | 
					use snp_proto::{brain_vm_daemon_client::BrainVmDaemonClient, BrainVmMessage, RegisterVmNodeReq};
 | 
				
			||||||
    brain_vm_daemon_client::BrainVmDaemonClient, BrainVmMessage, RegisterVmNodeReq, VmContract,
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
use tokio::{
 | 
					use tokio::{
 | 
				
			||||||
    sync::mpsc::{Receiver, Sender},
 | 
					    sync::mpsc::{Receiver, Sender},
 | 
				
			||||||
    task::JoinSet,
 | 
					    task::JoinSet,
 | 
				
			||||||
@ -36,9 +34,8 @@ async fn client(network: &str) -> Result<BrainVmDaemonClient<Channel>> {
 | 
				
			|||||||
    Ok(BrainVmDaemonClient::new(channel))
 | 
					    Ok(BrainVmDaemonClient::new(channel))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> {
 | 
					pub async fn register_node(config: &crate::config::Config) -> Result<Vec<DeleteVmReq>> {
 | 
				
			||||||
    use tonic::metadata::AsciiMetadataValue;
 | 
					    use tonic::{metadata::AsciiMetadataValue, Request};
 | 
				
			||||||
    use tonic::Request;
 | 
					 | 
				
			||||||
    let mut client = client(&config.network).await?;
 | 
					    let mut client = client(&config.network).await?;
 | 
				
			||||||
    debug!("Starting node registration...");
 | 
					    debug!("Starting node registration...");
 | 
				
			||||||
    let ip_info = IP_INFO.clone();
 | 
					    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 {
 | 
					    while let Some(stream_update) = grpc_stream.next().await {
 | 
				
			||||||
        match stream_update {
 | 
					        match stream_update {
 | 
				
			||||||
            Ok(node) => {
 | 
					            Ok(node) => {
 | 
				
			||||||
                debug!("Received contract from brain: {node:?}");
 | 
					                debug!("Received deleted VM from brain: {node:?}");
 | 
				
			||||||
                contracts.push(node);
 | 
					                contracts.push(node);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Err(e) => {
 | 
					            Err(e) => {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								src/main.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										28
									
								
								src/main.rs
									
									
									
									
									
								
							@ -3,8 +3,7 @@ mod global;
 | 
				
			|||||||
mod grpc;
 | 
					mod grpc;
 | 
				
			||||||
mod state;
 | 
					mod state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::global::*;
 | 
					use crate::{config::Config, global::*, grpc::snp_proto};
 | 
				
			||||||
use crate::{config::Config, grpc::snp_proto};
 | 
					 | 
				
			||||||
use anyhow::{anyhow, Result};
 | 
					use anyhow::{anyhow, Result};
 | 
				
			||||||
use log::{debug, info, warn};
 | 
					use log::{debug, info, warn};
 | 
				
			||||||
use std::{fs::File, path::Path};
 | 
					use std::{fs::File, path::Path};
 | 
				
			||||||
@ -205,17 +204,14 @@ impl VMHandler {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn clear_deleted_contracts(&mut self, contracts: Vec<snp_proto::VmContract>) {
 | 
					    fn clear_deleted_contracts(&mut self, deleted_vms: Vec<snp_proto::DeleteVmReq>) {
 | 
				
			||||||
        for uuid in self.res.existing_vms.clone() {
 | 
					        for deleted_vm in deleted_vms {
 | 
				
			||||||
            if contracts.iter().find(|c| c.uuid == uuid).is_none() {
 | 
					            let uuid = deleted_vm.uuid;
 | 
				
			||||||
                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")
 | 
				
			||||||
                let content =
 | 
					            {
 | 
				
			||||||
                    match std::fs::read_to_string(VM_CONFIG_DIR.to_string() + &uuid + ".yaml") {
 | 
					 | 
				
			||||||
                Ok(content) => content,
 | 
					                Ok(content) => content,
 | 
				
			||||||
                Err(e) => {
 | 
					                Err(e) => {
 | 
				
			||||||
                            log::error!(
 | 
					                    log::debug!("Could not find VM config for {uuid}. Maybe it already got deleted? Error: {e:?}");
 | 
				
			||||||
                                "Could not find VM config for {uuid}. Cannot delete VM: {e:?}"
 | 
					 | 
				
			||||||
                            );
 | 
					 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
@ -232,7 +228,6 @@ impl VMHandler {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[tokio::main]
 | 
					#[tokio::main]
 | 
				
			||||||
@ -252,13 +247,12 @@ async fn main() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        let mut vm_handler = VMHandler::new(brain_msg_rx, daemon_msg_tx.clone());
 | 
					        let mut vm_handler = VMHandler::new(brain_msg_rx, daemon_msg_tx.clone());
 | 
				
			||||||
        let network = vm_handler.config.network.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).");
 | 
					        info!("Registering with the brain and getting back deleted VMs.");
 | 
				
			||||||
        let mut contracts: Vec<String> = Vec::new();
 | 
					 | 
				
			||||||
        match grpc::register_node(&vm_handler.config).await {
 | 
					        match grpc::register_node(&vm_handler.config).await {
 | 
				
			||||||
            Ok(c) => {
 | 
					            Ok(deleted_vms) => {
 | 
				
			||||||
                contracts.append(&mut c.iter().map(|c| c.uuid.clone()).collect());
 | 
					                vm_handler.clear_deleted_contracts(deleted_vms)
 | 
				
			||||||
                vm_handler.clear_deleted_contracts(c)
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Err(e) => log::error!("Could not get contracts from brain: {e:?}"),
 | 
					            Err(e) => log::error!("Could not get contracts from brain: {e:?}"),
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user