Temporary code to test updates, this is not final at all.

This commit is contained in:
Ramil_Algayev 2025-01-04 17:20:16 +04:00
parent b1d272f8fb
commit bff04c7b7e
3 changed files with 13 additions and 13 deletions

@ -118,7 +118,7 @@ service BrainDaemonService {
rpc ListVMContracts (ListVMContractsReq) returns (stream VMContract); rpc ListVMContracts (ListVMContractsReq) returns (stream VMContract);
rpc GetUpdateVMReq (NodePubkey) returns (stream UpdateVMReq); rpc GetUpdateVMReq (NodePubkey) returns (stream UpdateVMReq);
rpc SendUpdateVMResp (stream UpdateVMResp) returns (Empty); rpc SendUpdateVMResp (stream UpdateVMResp) returns (Empty);
// rpc SendMeasurementArgs (NodePubkey) returns (MeasurementArgs); //rpc GetMeasurementArgs (ListVMContractsReq) returns (stream MeasurementArgs);
} }
message NodeFilters { message NodeFilters {

@ -1,5 +1,5 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::grpc::brain as grpc; use crate::grpc::brain::{self as grpc, MeasurementArgs};
use chrono::Utc; use chrono::Utc;
use dashmap::DashMap; use dashmap::DashMap;
use log::{debug, info, warn}; use log::{debug, info, warn};
@ -87,6 +87,7 @@ pub struct BrainData {
daemon_deletevm_tx: DashMap<String, Sender<grpc::DeleteVmReq>>, daemon_deletevm_tx: DashMap<String, Sender<grpc::DeleteVmReq>>,
daemon_newvm_tx: DashMap<String, Sender<grpc::NewVmReq>>, daemon_newvm_tx: DashMap<String, Sender<grpc::NewVmReq>>,
daemon_updatevm_tx: DashMap<String, Sender<grpc::UpdateVmReq>>, daemon_updatevm_tx: DashMap<String, Sender<grpc::UpdateVmReq>>,
daemon_get_measurement_tx: DashMap<String, Sender<MeasurementArgs>>,
} }
#[derive(Debug)] #[derive(Debug)]
@ -106,6 +107,7 @@ impl BrainData {
daemon_deletevm_tx: DashMap::new(), daemon_deletevm_tx: DashMap::new(),
daemon_newvm_tx: DashMap::new(), daemon_newvm_tx: DashMap::new(),
daemon_updatevm_tx: DashMap::new(), daemon_updatevm_tx: DashMap::new(),
daemon_get_measurement_tx: DashMap::new(),
} }
} }
@ -208,7 +210,7 @@ impl BrainData {
} }
let mut public_ipv4 = String::new(); let mut public_ipv4 = String::new();
let mut public_ipv6 = String::new(); let mut public_ipv6 = String::new();
for ip in new_vm_resp.ips { for ip in new_vm_resp.args.clone().unwrap_or(grpc::MeasurementArgs::default()).ips {
if let Ok(ipv4_addr) = std::net::Ipv4Addr::from_str(&ip.address) { if let Ok(ipv4_addr) = std::net::Ipv4Addr::from_str(&ip.address) {
if !ipv4_addr.is_private() && !ipv4_addr.is_link_local() { if !ipv4_addr.is_private() && !ipv4_addr.is_link_local() {
public_ipv4 = ipv4_addr.to_string(); public_ipv4 = ipv4_addr.to_string();
@ -221,7 +223,7 @@ impl BrainData {
} }
let contract = Contract { let contract = Contract {
uuid: new_vm_resp.uuid, uuid: new_vm_resp.uuid,
exposed_ports: new_vm_resp.exposed_ports, exposed_ports: new_vm_resp.args.unwrap_or(grpc::MeasurementArgs::default()).exposed_ports,
public_ipv4, public_ipv4,
public_ipv6, public_ipv6,
created_at: Utc::now().to_rfc3339(), created_at: Utc::now().to_rfc3339(),
@ -293,9 +295,7 @@ impl BrainData {
self.submit_newvm_resp(grpc::NewVmResp { self.submit_newvm_resp(grpc::NewVmResp {
error: "Daemon is offline.".to_string(), error: "Daemon is offline.".to_string(),
uuid: req.uuid, uuid: req.uuid,
exposed_ports: Vec::new(), args: None,
ovmf_hash: "".to_string(),
ips: Vec::new(),
}) })
.await; .await;
} }
@ -319,7 +319,7 @@ impl BrainData {
let _ = tx.send(grpc::UpdateVmResp { let _ = tx.send(grpc::UpdateVmResp {
uuid, uuid,
error: "Contract does not exist.".to_string(), error: "Contract does not exist.".to_string(),
ovmf_hash: "".to_string(), args: None,
}); });
return; return;
} }
@ -344,7 +344,7 @@ impl BrainData {
self.submit_updatevm_resp(grpc::UpdateVmResp { self.submit_updatevm_resp(grpc::UpdateVmResp {
uuid, uuid,
error: "Daemon is offline.".to_string(), error: "Daemon is offline.".to_string(),
ovmf_hash: "".to_string(), args: None,
}) })
.await; .await;
} }
@ -354,7 +354,7 @@ impl BrainData {
self.submit_updatevm_resp(grpc::UpdateVmResp { self.submit_updatevm_resp(grpc::UpdateVmResp {
uuid, uuid,
error: "Daemon is offline.".to_string(), error: "Daemon is offline.".to_string(),
ovmf_hash: "".to_string(), args: None,
}) })
.await; .await;
} }

@ -256,7 +256,7 @@ impl BrainDaemonService for BrainDaemonMock {
data.submit_updatevm_resp(UpdateVmResp { data.submit_updatevm_resp(UpdateVmResp {
error: "Daemon not connected.".to_string(), error: "Daemon not connected.".to_string(),
uuid: updatevmreq.uuid, uuid: updatevmreq.uuid,
ovmf_hash: "".to_string(), args: None,
}) })
.await; .await;
break; break;