Integrate operator in app node handling

rename operator_pubkey to operator_wallet
This commit is contained in:
Noor 2025-03-10 08:56:22 +00:00
parent 55280ec499
commit 92a26c5f66
Signed by: noormohammedb
GPG Key ID: E424C39E19EFD7DF
3 changed files with 27 additions and 19 deletions

2
Cargo.lock generated

@ -420,7 +420,7 @@ dependencies = [
[[package]]
name = "detee-shared"
version = "0.1.0"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#b8f37dec1845d29ea0b69035712e6ebb214376f4"
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#dc1e2dd0cd70f0915245fe3cae0863eab838fe5a"
dependencies = [
"base64",
"prost",

@ -56,6 +56,7 @@ pub struct OperatorData {
pub email: String,
pub banned_users: HashSet<String>,
pub vm_nodes: HashSet<String>,
pub app_nodes: HashSet<String>,
}
impl From<AccountData> for grpc::AccountBalance {
@ -230,7 +231,7 @@ impl From<AppContract> for AppContractPB {
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
pub struct AppNode {
pub node_pubkey: String,
pub operator_pubkey: String,
pub operator_wallet: String,
pub country: String,
pub region: String,
pub city: String,
@ -246,13 +247,6 @@ pub struct AppNode {
#[derive(Default, Serialize, Deserialize)]
pub struct BrainData {
// amount of nanoLP in each account
// accounts: DashMap<String, AccountData>,
// vm_nodes: RwLock<Vec<VmNode>>,
// vm_contracts: RwLock<Vec<VmContract>>,
// tmp_newvm_reqs: DashMap<String, (grpc::NewVmReq, OneshotSender<grpc::NewVmResp>)>,
// tmp_updatevm_reqs: DashMap<String, (grpc::UpdateVmReq, OneshotSender<grpc::UpdateVmResp>)>,
// daemon_tx: DashMap<String, Sender<grpc::BrainVmMessage>>,
accounts: DashMap<String, AccountData>,
operators: DashMap<String, OperatorData>,
vm_nodes: RwLock<Vec<VmNode>>,
@ -950,6 +944,7 @@ impl BrainData {
email: String::new(),
banned_users: HashSet::new(),
vm_nodes: HashSet::from([node_pubkey.to_string()]),
app_nodes: HashSet::new(),
});
}
@ -1153,7 +1148,9 @@ impl BrainData {
self.app_daemon_tx.remove(node_pubkey);
}
pub fn insert_app_node(&self, node: AppNode) {
pub fn register_app_node(&self, node: AppNode) {
info!("Registering app node {node:?}");
self.add_app_node_to_operator(&node.operator_wallet, &node.node_pubkey);
let mut nodes = self.app_nodes.write().unwrap();
for n in nodes.iter_mut() {
if n.node_pubkey == node.node_pubkey {
@ -1166,6 +1163,21 @@ impl BrainData {
nodes.push(node);
}
pub fn add_app_node_to_operator(&self, operator_wallet: &str, node_pubkey: &str) {
self.operators
.entry(operator_wallet.to_string())
.and_modify(|op| {
op.app_nodes.insert(node_pubkey.to_string());
})
.or_insert(OperatorData {
escrow: 0,
email: String::new(),
banned_users: HashSet::new(),
vm_nodes: HashSet::new(),
app_nodes: HashSet::from([node_pubkey.to_string()]),
});
}
pub fn find_app_contract_by_uuid(&self, uuid: &str) -> Option<AppContract> {
let contracts = self.app_contracts.read().unwrap();
contracts.iter().find(|c| c.uuid == uuid).cloned()
@ -1185,7 +1197,7 @@ impl BrainData {
contracts
}
pub fn find_app_contracts_by_node_pubkey(&self, node_pubkey: &str) -> Vec<AppContract> {
pub fn find_app_contracts_by_node(&self, node_pubkey: &str) -> Vec<AppContract> {
let app_contracts = self.app_contracts.read().unwrap();
app_contracts
.iter()

@ -531,26 +531,22 @@ impl BrainAppDaemon for BrainAppDaemonMock {
log::info!(
"registering app node_key : {}, operator_key: {}",
&req_data.node_pubkey,
&req_data.operator_pubkey
&req_data.operator_wallet
);
let app_node = crate::data::AppNode {
node_pubkey: req_data.node_pubkey.clone(),
operator_pubkey: req_data.operator_pubkey,
operator_wallet: req_data.operator_wallet,
ip: req_data.main_ip,
city: req_data.city,
region: req_data.region,
country: req_data.country,
..Default::default()
};
self.data.register_app_node(app_node);
self.data.insert_app_node(app_node);
log::info!("Sending existing contracts to {}", &req_data.node_pubkey);
let app_contracts = self
.data
.find_app_contracts_by_node_pubkey(&req_data.node_pubkey);
let app_contracts = self.data.find_app_contracts_by_node(&req_data.node_pubkey);
let (tx, rx) = mpsc::channel(6);
tokio::spawn(async move {
for contract in app_contracts {