App engine features #1
40
src/data.rs
40
src/data.rs
@ -40,6 +40,9 @@ pub enum Error {
|
|||||||
|
|
||||||
#[error("Could not find contract {0}")]
|
#[error("Could not find contract {0}")]
|
||||||
AppContractNotFound(String),
|
AppContractNotFound(String),
|
||||||
|
|
||||||
|
#[error("Could not find contract {0}")]
|
||||||
|
ContractNotFound(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
|
||||||
@ -247,7 +250,7 @@ impl From<AppContract> for AppContractPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, Hash, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
#[derive(Eq, PartialEq, Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct AppNode {
|
pub struct AppNode {
|
||||||
pub node_pubkey: String,
|
pub node_pubkey: String,
|
||||||
pub operator_wallet: String,
|
pub operator_wallet: String,
|
||||||
@ -262,7 +265,8 @@ pub struct AppNode {
|
|||||||
pub max_ports_per_app: u32,
|
pub max_ports_per_app: u32,
|
||||||
// nanotokens per unit per minute
|
// nanotokens per unit per minute
|
||||||
pub price: u64,
|
pub price: u64,
|
||||||
|
// 1st String is user wallet and 2nd String is report message
|
||||||
|
pub reports: HashMap<String, String>,
|
||||||
pub offline_minutes: u64,
|
pub offline_minutes: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,10 +598,15 @@ impl BrainData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_node(&self, admin_pubkey: String, node: &str, report: String) {
|
pub fn report_any_node(&self, admin_pubkey: String, node: &str, report: String) {
|
||||||
let mut nodes = self.vm_nodes.write().unwrap();
|
let mut vm_nodes = self.vm_nodes.write().unwrap();
|
||||||
if let Some(node) = nodes.iter_mut().find(|n| n.public_key == node) {
|
if let Some(vm_node) = vm_nodes.iter_mut().find(|n| n.public_key == node) {
|
||||||
node.reports.insert(admin_pubkey, report);
|
vm_node.reports.insert(admin_pubkey.clone(), report.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut app_nodes = self.app_nodes.write().unwrap();
|
||||||
|
if let Some(app_node) = app_nodes.iter_mut().find(|n| n.node_pubkey == node) {
|
||||||
|
app_node.reports.insert(admin_pubkey, report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1239,6 +1248,25 @@ impl BrainData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BrainData {
|
||||||
|
pub fn find_any_contract_by_uuid(
|
||||||
|
&self,
|
||||||
|
uuid: &str,
|
||||||
|
) -> Result<(Option<VmContract>, Option<AppContract>), Error> {
|
||||||
|
let contracts = self.vm_contracts.read().unwrap();
|
||||||
|
if let Some(vm_contract) = contracts.iter().cloned().find(|c| c.uuid == uuid) {
|
||||||
|
return Ok((Some(vm_contract), None));
|
||||||
|
}
|
||||||
|
|
||||||
|
let app_contracts = self.app_contracts.read().unwrap();
|
||||||
|
if let Some(app_contract) = app_contracts.iter().cloned().find(|c| c.uuid == uuid) {
|
||||||
|
return Ok((None, Some(app_contract)));
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(Error::ContractNotFound(uuid.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BrainData {
|
impl BrainData {
|
||||||
pub fn add_app_daemon_tx(&self, node_pubkey: &str, tx: Sender<BrainMessageApp>) {
|
pub fn add_app_daemon_tx(&self, node_pubkey: &str, tx: Sender<BrainMessageApp>) {
|
||||||
self.app_daemon_tx.insert(node_pubkey.to_string(), tx);
|
self.app_daemon_tx.insert(node_pubkey.to_string(), tx);
|
||||||
|
16
src/grpc.rs
16
src/grpc.rs
@ -99,17 +99,23 @@ impl BrainGeneralCli for BrainGeneraClilMock {
|
|||||||
|
|
||||||
async fn report_node(&self, req: Request<ReportNodeReq>) -> Result<Response<Empty>, Status> {
|
async fn report_node(&self, req: Request<ReportNodeReq>) -> Result<Response<Empty>, Status> {
|
||||||
let req = check_sig_from_req(req)?;
|
let req = check_sig_from_req(req)?;
|
||||||
match self.data.find_contract_by_uuid(&req.contract) {
|
match self.data.find_any_contract_by_uuid(&req.contract) {
|
||||||
Ok(contract)
|
Ok((Some(vm_contract), _))
|
||||||
if contract.admin_pubkey == req.admin_pubkey
|
if vm_contract.admin_pubkey == req.admin_pubkey
|
||||||
&& contract.node_pubkey == req.node_pubkey =>
|
&& vm_contract.node_pubkey == req.node_pubkey =>
|
||||||
|
{
|
||||||
|
()
|
||||||
|
}
|
||||||
|
Ok((_, Some(app_contract)))
|
||||||
|
if app_contract.admin_pubkey == req.admin_pubkey
|
||||||
|
&& app_contract.node_pubkey == req.node_pubkey =>
|
||||||
{
|
{
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
_ => return Err(Status::unauthenticated("No contract found by this ID.")),
|
_ => return Err(Status::unauthenticated("No contract found by this ID.")),
|
||||||
};
|
};
|
||||||
self.data
|
self.data
|
||||||
.report_node(req.admin_pubkey, &req.node_pubkey, req.reason);
|
.report_any_node(req.admin_pubkey, &req.node_pubkey, req.reason);
|
||||||
Ok(Response::new(Empty {}))
|
Ok(Response::new(Empty {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user