From 165a2f190d0ad14d23fd456cbee2626e3f70269d Mon Sep 17 00:00:00 2001 From: jeffgrunewald Date: Thu, 14 Dec 2023 12:51:44 -0500 Subject: [PATCH] move mobile device type out of metadata --- Cargo.lock | 4 +- Cargo.toml | 4 +- mobile_config/src/gateway_info.rs | 67 ++++++++++++---------------- mobile_config/src/gateway_service.rs | 2 +- mobile_verifier/src/lib.rs | 10 ++--- 5 files changed, 37 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 818c15028..8c8b49eb8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,7 +1197,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "beacon" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=andymck/verify-hb-cell-type#867ca9cc1e53edf96345e378a27f2497e04ecd07" +source = "git+https://github.com/helium/proto?branch=master#de51ede124884329e89b99b43d5d8c7bb7cc3012" dependencies = [ "base64 0.21.0", "byteorder", @@ -3047,7 +3047,7 @@ dependencies = [ [[package]] name = "helium-proto" version = "0.1.0" -source = "git+https://github.com/helium/proto?branch=andymck/verify-hb-cell-type#867ca9cc1e53edf96345e378a27f2497e04ecd07" +source = "git+https://github.com/helium/proto?branch=master#de51ede124884329e89b99b43d5d8c7bb7cc3012" dependencies = [ "bytes", "prost", diff --git a/Cargo.toml b/Cargo.toml index 7264c21f8..acc156d5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,14 +60,14 @@ sqlx = {version = "0", features = [ "runtime-tokio-rustls" ]} helium-crypto = {version = "0.8.1", features=["sqlx-postgres", "multisig"]} -helium-proto = {git = "https://github.com/helium/proto", branch = "andymck/verify-hb-cell-type", features = ["services"]} +helium-proto = {git = "https://github.com/helium/proto", branch = "master", features = ["services"]} hextree = "*" solana-client = "1.14" solana-sdk = "1.14" solana-program = "1.11" spl-token = "3.5.0" reqwest = {version = "0", default-features=false, features = ["gzip", "json", "rustls-tls"]} -beacon = { git = "https://github.com/helium/proto", branch = "andymck/verify-hb-cell-type" } +beacon = { git = "https://github.com/helium/proto", branch = "master" } humantime = "2" metrics = "0" metrics-exporter-prometheus = "0" diff --git a/mobile_config/src/gateway_info.rs b/mobile_config/src/gateway_info.rs index 075bcfac6..991da5c12 100644 --- a/mobile_config/src/gateway_info.rs +++ b/mobile_config/src/gateway_info.rs @@ -9,38 +9,30 @@ pub type GatewayInfoStream = BoxStream<'static, GatewayInfo>; #[derive(Clone, Debug)] pub struct GatewayMetadata { - pub device_type: DeviceType, - pub location: Option, + pub location: u64, } #[derive(Clone, Debug)] pub struct GatewayInfo { pub address: PublicKeyBinary, - pub metadata: GatewayMetadata, + pub metadata: Option, + pub device_type: DeviceType, } impl From for GatewayInfo { fn from(info: GatewayInfoProto) -> Self { - let location = if info - .metadata - .as_ref() - .is_some_and(|meta| meta.location.is_empty()) - { - None + let metadata = if let Some(ref metadata) = info.metadata { + u64::from_str_radix(&metadata.location, 26) + .map(|location| GatewayMetadata { location }) + .ok() } else { - info.metadata - .as_ref() - .and_then(|meta| u64::from_str_radix(&meta.location, 16).ok()) + None }; + let device_type = info.device_type().into(); Self { address: info.address.into(), - metadata: GatewayMetadata { - location, - device_type: info - .metadata - .map(|meta| meta.device_type().into()) - .unwrap_or(DeviceType::Cbrs), - }, + metadata, + device_type, } } } @@ -49,19 +41,17 @@ impl TryFrom for GatewayInfoProto { type Error = hextree::Error; fn try_from(info: GatewayInfo) -> Result { - let location = info - .metadata - .location - .map(hextree::Cell::from_raw) - .transpose()? - .map(|cell| cell.to_string()) - .unwrap_or_default(); + let metadata = if let Some(metadata) = info.metadata { + Some(GatewayMetadataProto { + location: hextree::Cell::from_raw(metadata.location)?.to_string(), + }) + } else { + None + }; Ok(Self { address: info.address.into(), - metadata: Some(GatewayMetadataProto { - location, - device_type: info.metadata.device_type as i32, - }), + metadata, + device_type: info.device_type as i32, }) } } @@ -93,8 +83,8 @@ impl std::str::FromStr for DeviceType { fn from_str(s: &str) -> Result { let result = match s { "cbrs" => Self::Cbrs, - "wifi_indoor" => Self::WifiIndoor, - "wifi_outdoor" => Self::WifiOutdoor, + "wifiIndoor" => Self::WifiIndoor, + "wifiOutdoor" => Self::WifiOutdoor, _ => return Err(DeviceTypeParseError), }; Ok(result) @@ -140,23 +130,24 @@ pub(crate) mod db { impl sqlx::FromRow<'_, sqlx::postgres::PgRow> for GatewayInfo { fn from_row(row: &sqlx::postgres::PgRow) -> sqlx::Result { - let metadata = GatewayMetadata { - location: row + let metadata = row .get::, &str>("location") - .map(|loc| loc as u64), - device_type: DeviceType::from_str( + .map(|loc| GatewayMetadata { + location: loc as u64, + }); + let device_type = DeviceType::from_str( row.get::, &str>("device_type") .to_string() .as_ref(), ) - .map_err(|err| sqlx::Error::Decode(Box::new(err)))?, - }; + .map_err(|err| sqlx::Error::Decode(Box::new(err)))?; Ok(Self { address: PublicKeyBinary::from_str( &bs58::encode(row.get::<&[u8], &str>("entity_key")).into_string(), ) .map_err(|err| sqlx::Error::Decode(Box::new(err)))?, metadata, + device_type, }) } } diff --git a/mobile_config/src/gateway_service.rs b/mobile_config/src/gateway_service.rs index 2ac6139c7..7801c5db1 100644 --- a/mobile_config/src/gateway_service.rs +++ b/mobile_config/src/gateway_service.rs @@ -74,7 +74,7 @@ impl mobile_config::Gateway for GatewayService { Err(Status::not_found(pubkey.to_string())) }, |info| { - if info.metadata.location.is_some() { + if info.metadata.is_some() { telemetry::count_gateway_chain_lookup("asserted"); } else { telemetry::count_gateway_chain_lookup("not-asserted"); diff --git a/mobile_verifier/src/lib.rs b/mobile_verifier/src/lib.rs index 2080c4141..0729475d9 100644 --- a/mobile_verifier/src/lib.rs +++ b/mobile_verifier/src/lib.rs @@ -41,17 +41,13 @@ impl GatewayResolver for mobile_config::GatewayClient { address: &helium_crypto::PublicKeyBinary, ) -> Result { use mobile_config::client::gateway_client::GatewayInfoResolver; - use mobile_config::gateway_info::{GatewayInfo, GatewayMetadata}; + use mobile_config::gateway_info::GatewayInfo; match self.resolve_gateway_info(address).await? { None => Ok(GatewayResolution::GatewayNotFound), Some(GatewayInfo { - metadata: - GatewayMetadata { - location: Some(location), - .. - }, + metadata: Some(metadata), .. - }) => Ok(GatewayResolution::AssertedLocation(location)), + }) => Ok(GatewayResolution::AssertedLocation(metadata.location)), Some(_) => Ok(GatewayResolution::GatewayNotAsserted), } }