new brain proto and new staging address
This commit is contained in:
parent
e0561875d8
commit
217ab03164
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -1,7 +1,6 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
@ -397,7 +396,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",
|
||||
|
@ -26,7 +26,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]
|
||||
|
@ -8,7 +8,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://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 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,12 +1,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
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,
|
||||
@ -38,9 +36,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();
|
||||
@ -70,7 +67,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) => {
|
||||
|
28
src/main.rs
28
src/main.rs
@ -5,8 +5,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};
|
||||
@ -207,17 +206,14 @@ 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") {
|
||||
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::error!(
|
||||
"Could not find VM config for {uuid}. Cannot delete VM: {e:?}"
|
||||
);
|
||||
log::debug!("Could not find VM config for {uuid}. Maybe it already got deleted? Error: {e:?}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
@ -235,7 +231,6 @@ impl VMHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@ -254,13 +249,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