Skip to content

Commit

Permalink
drop device type DB null support, simplify ev thing thereafter
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Oct 16, 2023
1 parent 0d02a5e commit 8232fd5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
11 changes: 4 additions & 7 deletions mobile_config/src/gateway_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub type GatewayInfoStream = BoxStream<'static, GatewayInfo>;
#[derive(Clone, Debug)]
pub struct GatewayMetadata {
pub location: u64,
pub device_type: Option<String>,
pub device_type: String,
}

#[derive(Clone, Debug)]
Expand All @@ -32,11 +32,10 @@ pub trait GatewayInfoResolver {
impl From<GatewayInfoProto> 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 {
Expand All @@ -57,7 +56,7 @@ impl TryFrom<GatewayInfo> 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
Expand Down Expand Up @@ -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<Self> {
let device_type = row
.get::<Option<Json<String>>, &str>("device_type")
.map(|s| s.to_string());
let device_type = row.get::<Json<String>, &str>("device_type").to_string();
let metadata = row
.get::<Option<i64>, &str>("location")
.map(|loc| GatewayMetadata {
Expand Down
6 changes: 3 additions & 3 deletions mobile_verifier/src/cell_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ impl CellType {
}
}

pub fn from_asserted(s: &Option<String>) -> Option<Self> {
pub fn from_asserted(device_type: &String) -> Option<Self> {
// 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,
}
}
Expand Down
19 changes: 3 additions & 16 deletions mobile_verifier/src/heartbeats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
Expand Down

0 comments on commit 8232fd5

Please sign in to comment.