now update_vm_resp.args.dtrfs_api_endpoint does get the node ip from the brain if it didn't have a public ip

This commit is contained in:
Ramil_Algayev 2025-01-06 23:41:39 +04:00
parent 554468e8b6
commit ab4361ad5e

@ -184,7 +184,7 @@ impl BrainData {
self.daemon_newvm_tx.insert(node_pubkey.to_string(), tx); self.daemon_newvm_tx.insert(node_pubkey.to_string(), tx);
} }
pub async fn submit_newvm_resp(&self, new_vm_resp: grpc::NewVmResp) { pub async fn submit_newvm_resp(&self, mut new_vm_resp: grpc::NewVmResp) {
let newvmreq = match self.tmp_newvm_reqs.remove(&new_vm_resp.uuid) { let newvmreq = match self.tmp_newvm_reqs.remove(&new_vm_resp.uuid) {
Some((_, r)) => r, Some((_, r)) => r,
None => { None => {
@ -192,6 +192,15 @@ impl BrainData {
"Received confirmation for ghost NewVMReq {}", "Received confirmation for ghost NewVMReq {}",
new_vm_resp.uuid new_vm_resp.uuid
); );
new_vm_resp.error = "Received confirmation for ghost NewVMReq.".to_string();
return;
}
};
let args = match new_vm_resp.args.clone() {
Some(args) => args,
None => {
log::error!("NewVmResp does not contain MeasurementArgs for {}", new_vm_resp.uuid);
new_vm_resp.error = "Daemon did not return measurement args.".to_string();
return; return;
} }
}; };
@ -208,13 +217,6 @@ 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();
let args = match new_vm_resp.args {
Some(args) => args,
None => {
log::error!("NewVmResp does not contain MeasurementArgs for {}", new_vm_resp.uuid);
return;
}
};
for ip in args.ips { for ip in args.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) {
@ -247,7 +249,7 @@ impl BrainData {
self.contracts.write().unwrap().push(contract); self.contracts.write().unwrap().push(contract);
} }
pub async fn submit_updatevm_resp(&self, resp: grpc::UpdateVmResp) { pub async fn submit_updatevm_resp(&self, mut resp: grpc::UpdateVmResp) {
let updatevmreq = match self.tmp_updatevm_reqs.remove(&resp.uuid) { let updatevmreq = match self.tmp_updatevm_reqs.remove(&resp.uuid) {
Some((_, r)) => r, Some((_, r)) => r,
None => { None => {
@ -255,9 +257,15 @@ impl BrainData {
"Received confirmation for ghost UpdateVMRequest {}", "Received confirmation for ghost UpdateVMRequest {}",
resp.uuid resp.uuid
); );
resp.error = "Received confirmation for ghost UpdateVMRequest.".to_string();
return; return;
} }
}; };
if let None = resp.args {
log::error!("NewVmResp does not contain MeasurementArgs for {}", resp.uuid);
resp.error = "Daemon did not return measurement args.".to_string();
return;
};
if let Err(e) = updatevmreq.1.send(resp.clone()) { if let Err(e) = updatevmreq.1.send(resp.clone()) {
log::error!("CLI RX dropped before receiving UpdateVMResp {resp:?}. Error is: {e:?}"); log::error!("CLI RX dropped before receiving UpdateVMResp {resp:?}. Error is: {e:?}");
} }
@ -266,6 +274,21 @@ impl BrainData {
} }
let mut contracts = self.contracts.write().unwrap(); let mut contracts = self.contracts.write().unwrap();
if let Some(contract) = contracts.iter_mut().find(|c| c.uuid == resp.uuid) { if let Some(contract) = contracts.iter_mut().find(|c| c.uuid == resp.uuid) {
let args = resp.args.as_mut().unwrap();
if args.dtrfs_api_endpoint.starts_with(':') {
if let Some(node) = self.find_nodes_by_pubkey(&contract.node_pubkey) {
args.dtrfs_api_endpoint = format!("{}{}", node.ip, args.dtrfs_api_endpoint);
} else {
// This should never happen.
log::error!(
"Node {} not found for contract {}. Cannot update contract.",
contract.node_pubkey,
contract.uuid
);
return;
}
}
contract.disk_size_gb = updatevmreq.0.disk_size_gb; contract.disk_size_gb = updatevmreq.0.disk_size_gb;
contract.vcpus = updatevmreq.0.vcpus; contract.vcpus = updatevmreq.0.vcpus;
contract.memory_mb = updatevmreq.0.memory_mb; contract.memory_mb = updatevmreq.0.memory_mb;