From 8232fd59f2b1a18da95c8f3ef0cbfa5e5aa34355 Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Thu, 28 Sep 2023 15:19:24 +0100 Subject: [PATCH] drop device type DB null support, simplify ev thing thereafter --- mobile_config/src/gateway_info.rs | 11 ++++------- mobile_verifier/src/cell_type.rs | 6 +++--- mobile_verifier/src/heartbeats/mod.rs | 19 +++---------------- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/mobile_config/src/gateway_info.rs b/mobile_config/src/gateway_info.rs index 3c68fe532..f594d2fb0 100644 --- a/mobile_config/src/gateway_info.rs +++ b/mobile_config/src/gateway_info.rs @@ -8,7 +8,7 @@ pub type GatewayInfoStream = BoxStream<'static, GatewayInfo>; #[derive(Clone, Debug)] pub struct GatewayMetadata { pub location: u64, - pub device_type: Option, + pub device_type: String, } #[derive(Clone, Debug)] @@ -32,11 +32,10 @@ pub trait GatewayInfoResolver { impl From for GatewayInfo { fn from(info: GatewayInfoProto) -> Self { let metadata = if let Some(metadata) = info.metadata { - let device_type = metadata.device_type.parse().ok(); u64::from_str_radix(&metadata.location, 16) .map(|location| GatewayMetadata { location, - device_type, + device_type: metadata.device_type, }) .ok() } else { @@ -57,7 +56,7 @@ impl TryFrom for GatewayInfoProto { let metadata = if let Some(metadata) = info.metadata { Some(GatewayMetadataProto { location: hextree::Cell::from_raw(metadata.location)?.to_string(), - device_type: metadata.device_type.unwrap_or_default(), + device_type: metadata.device_type, }) } else { None @@ -109,9 +108,7 @@ pub(crate) mod db { impl sqlx::FromRow<'_, sqlx::postgres::PgRow> for GatewayInfo { fn from_row(row: &sqlx::postgres::PgRow) -> sqlx::Result { - let device_type = row - .get::>, &str>("device_type") - .map(|s| s.to_string()); + let device_type = row.get::, &str>("device_type").to_string(); let metadata = row .get::, &str>("location") .map(|loc| GatewayMetadata { diff --git a/mobile_verifier/src/cell_type.rs b/mobile_verifier/src/cell_type.rs index 8a9d717e6..1d4f47429 100644 --- a/mobile_verifier/src/cell_type.rs +++ b/mobile_verifier/src/cell_type.rs @@ -88,11 +88,11 @@ impl CellType { } } - pub fn from_asserted(s: &Option) -> Option { + pub fn from_asserted(device_type: &String) -> Option { // TODO: currently only handling wifi indoor, handle other cell types // when foundation device type values are in use - match s { - Some(s) if s.eq("wifiIndoor") => Some(CellType::NovaGenericWifiIndoor), + match device_type { + device_type if device_type.eq("wifiIndoor") => Some(CellType::NovaGenericWifiIndoor), _ => None, } } diff --git a/mobile_verifier/src/heartbeats/mod.rs b/mobile_verifier/src/heartbeats/mod.rs index ebe215735..a0d8ee109 100644 --- a/mobile_verifier/src/heartbeats/mod.rs +++ b/mobile_verifier/src/heartbeats/mod.rs @@ -400,22 +400,9 @@ pub async fn validate_heartbeat( )); }; - // verify the HB cell type matches that on chain - // TODO: currently only handling wifi indoor - // make this check generic and applicable to all cell types - // when device data is available in the db - match ( - heartbeat.hb_type.clone(), - CellType::from_asserted(&metadata.device_type), - ) { - (HBType::Wifi, Some(asserted_celltype)) if asserted_celltype != cell_type => { - return Ok((cell_type, proto::HeartbeatValidity::BadCellType, None)); - } - (HBType::Wifi, None) => { - return Ok((cell_type, proto::HeartbeatValidity::BadCellType, None)) - } - _ => (), - }; + if CellType::from_asserted(&metadata.device_type) != Some(cell_type) { + return Ok((cell_type, proto::HeartbeatValidity::BadCellType, None)); + } let distance_to_asserted = if heartbeat.hb_type == HBType::Wifi { Some(heartbeat.asserted_distance(metadata.location)?)