Integrate operator in app node handling
rename operator_pubkey to operator_wallet
This commit is contained in:
parent
55280ec499
commit
92a26c5f66
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -420,7 +420,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/noormohammedb/detee-shared?branch=stable_01#b8f37dec1845d29ea0b69035712e6ebb214376f4"
|
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#dc1e2dd0cd70f0915245fe3cae0863eab838fe5a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"prost",
|
"prost",
|
||||||
|
32
src/data.rs
32
src/data.rs
@ -56,6 +56,7 @@ pub struct OperatorData {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
pub banned_users: HashSet<String>,
|
pub banned_users: HashSet<String>,
|
||||||
pub vm_nodes: HashSet<String>,
|
pub vm_nodes: HashSet<String>,
|
||||||
|
pub app_nodes: HashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AccountData> for grpc::AccountBalance {
|
impl From<AccountData> for grpc::AccountBalance {
|
||||||
@ -230,7 +231,7 @@ impl From<AppContract> for AppContractPB {
|
|||||||
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct AppNode {
|
pub struct AppNode {
|
||||||
pub node_pubkey: String,
|
pub node_pubkey: String,
|
||||||
pub operator_pubkey: String,
|
pub operator_wallet: String,
|
||||||
pub country: String,
|
pub country: String,
|
||||||
pub region: String,
|
pub region: String,
|
||||||
pub city: String,
|
pub city: String,
|
||||||
@ -246,13 +247,6 @@ pub struct AppNode {
|
|||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize)]
|
#[derive(Default, Serialize, Deserialize)]
|
||||||
pub struct BrainData {
|
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>,
|
accounts: DashMap<String, AccountData>,
|
||||||
operators: DashMap<String, OperatorData>,
|
operators: DashMap<String, OperatorData>,
|
||||||
vm_nodes: RwLock<Vec<VmNode>>,
|
vm_nodes: RwLock<Vec<VmNode>>,
|
||||||
@ -950,6 +944,7 @@ impl BrainData {
|
|||||||
email: String::new(),
|
email: String::new(),
|
||||||
banned_users: HashSet::new(),
|
banned_users: HashSet::new(),
|
||||||
vm_nodes: HashSet::from([node_pubkey.to_string()]),
|
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);
|
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();
|
let mut nodes = self.app_nodes.write().unwrap();
|
||||||
for n in nodes.iter_mut() {
|
for n in nodes.iter_mut() {
|
||||||
if n.node_pubkey == node.node_pubkey {
|
if n.node_pubkey == node.node_pubkey {
|
||||||
@ -1166,6 +1163,21 @@ impl BrainData {
|
|||||||
nodes.push(node);
|
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> {
|
pub fn find_app_contract_by_uuid(&self, uuid: &str) -> Option<AppContract> {
|
||||||
let contracts = self.app_contracts.read().unwrap();
|
let contracts = self.app_contracts.read().unwrap();
|
||||||
contracts.iter().find(|c| c.uuid == uuid).cloned()
|
contracts.iter().find(|c| c.uuid == uuid).cloned()
|
||||||
@ -1185,7 +1197,7 @@ impl BrainData {
|
|||||||
contracts
|
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();
|
let app_contracts = self.app_contracts.read().unwrap();
|
||||||
app_contracts
|
app_contracts
|
||||||
.iter()
|
.iter()
|
||||||
|
12
src/grpc.rs
12
src/grpc.rs
@ -531,26 +531,22 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
|||||||
log::info!(
|
log::info!(
|
||||||
"registering app node_key : {}, operator_key: {}",
|
"registering app node_key : {}, operator_key: {}",
|
||||||
&req_data.node_pubkey,
|
&req_data.node_pubkey,
|
||||||
&req_data.operator_pubkey
|
&req_data.operator_wallet
|
||||||
);
|
);
|
||||||
|
|
||||||
let app_node = crate::data::AppNode {
|
let app_node = crate::data::AppNode {
|
||||||
node_pubkey: req_data.node_pubkey.clone(),
|
node_pubkey: req_data.node_pubkey.clone(),
|
||||||
operator_pubkey: req_data.operator_pubkey,
|
operator_wallet: req_data.operator_wallet,
|
||||||
ip: req_data.main_ip,
|
ip: req_data.main_ip,
|
||||||
city: req_data.city,
|
city: req_data.city,
|
||||||
region: req_data.region,
|
region: req_data.region,
|
||||||
country: req_data.country,
|
country: req_data.country,
|
||||||
..Default::default()
|
..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);
|
log::info!("Sending existing contracts to {}", &req_data.node_pubkey);
|
||||||
|
let app_contracts = self.data.find_app_contracts_by_node(&req_data.node_pubkey);
|
||||||
let app_contracts = self
|
|
||||||
.data
|
|
||||||
.find_app_contracts_by_node_pubkey(&req_data.node_pubkey);
|
|
||||||
|
|
||||||
let (tx, rx) = mpsc::channel(6);
|
let (tx, rx) = mpsc::channel(6);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
for contract in app_contracts {
|
for contract in app_contracts {
|
||||||
|
Loading…
Reference in New Issue
Block a user