Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new location source field on wifi heartbeats #833

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch =
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
"disktree",
] }
helium-proto = { git = "https://github.com/helium/proto", branch = "master", features = [
helium-proto = { git = "https://github.com/helium/proto", branch = "bbalser/wifi-location-source", features = [
"services",
] }
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "bbalser/wifi-location-source" }
solana-client = "1.18"
solana-sdk = "1.18"
solana-program = "1.18"
Expand Down
9 changes: 8 additions & 1 deletion file_store/src/wifi_heartbeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use crate::{
};
use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{WifiHeartbeatIngestReportV1, WifiHeartbeatReqV1};
use helium_proto::services::poc_mobile::{
LocationSource, WifiHeartbeatIngestReportV1, WifiHeartbeatReqV1,
};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand All @@ -17,6 +19,7 @@ pub struct WifiHeartbeat {
pub location_validation_timestamp: Option<DateTime<Utc>>,
pub coverage_object: Vec<u8>,
pub timestamp: DateTime<Utc>,
pub location_source: LocationSource,
}

impl WifiHeartbeat {
Expand Down Expand Up @@ -47,6 +50,7 @@ impl TryFrom<WifiHeartbeatReqV1> for WifiHeartbeat {
} else {
v.location_validation_timestamp.to_timestamp().ok()
};
let location_source = v.location_source();
Ok(Self {
pubkey: v.pub_key.into(),
lat: v.lat,
Expand All @@ -55,6 +59,7 @@ impl TryFrom<WifiHeartbeatReqV1> for WifiHeartbeat {
coverage_object: v.coverage_object,
timestamp: v.timestamp.to_timestamp()?,
location_validation_timestamp,
location_source,
})
}
}
Expand Down Expand Up @@ -107,6 +112,7 @@ mod tests {
coverage_object: vec![],
timestamp: Utc::now().timestamp() as u64,
location_validation_timestamp: now as u64,
location_source: LocationSource::Skyhook.into(),
signature: vec![],
}),
};
Expand All @@ -120,6 +126,7 @@ mod tests {
coverage_object: vec![],
timestamp: Utc::now().timestamp() as u64,
location_validation_timestamp: 0,
location_source: LocationSource::Gps.into(),
signature: vec![],
}),
};
Expand Down
7 changes: 6 additions & 1 deletion mobile_verifier/src/heartbeats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use file_store::{
use futures::stream::{Stream, StreamExt};
use h3o::{CellIndex, LatLng};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile as proto;
use helium_proto::services::poc_mobile::{self as proto, LocationSource};
use retainer::Cache;
use rust_decimal::{prelude::ToPrimitive, Decimal};
use rust_decimal_macros::dec;
Expand Down Expand Up @@ -207,6 +207,7 @@ pub struct Heartbeat {
pub lon: f64,
pub coverage_object: Option<Uuid>,
pub location_validation_timestamp: Option<DateTime<Utc>>,
pub location_source: LocationSource,
pub timestamp: DateTime<Utc>,
}

Expand Down Expand Up @@ -254,6 +255,7 @@ impl From<CbrsHeartbeatIngestReport> for Heartbeat {
lat: value.report.lat,
lon: value.report.lon,
location_validation_timestamp: None,
location_source: LocationSource::Gps,
timestamp: value.received_timestamp,
}
}
Expand All @@ -270,6 +272,7 @@ impl From<WifiHeartbeatIngestReport> for Heartbeat {
lat: value.report.lat,
lon: value.report.lon,
location_validation_timestamp: value.report.location_validation_timestamp,
location_source: value.report.location_source,
timestamp: value.received_timestamp,
}
}
Expand Down Expand Up @@ -629,6 +632,7 @@ impl ValidatedHeartbeat {
.location_validation_timestamp
.map_or(0, |v| v.timestamp() as u64),
distance_to_asserted: self.distance_to_asserted.map_or(0, |v| v as u64),
location_source: self.heartbeat.location_source.into(),
..Default::default()
},
&[("validity", self.validity.as_str_name())],
Expand Down Expand Up @@ -796,6 +800,7 @@ mod test {
cbsd_id: None,
coverage_object: Some(coverage_object),
location_validation_timestamp: None,
location_source: LocationSource::Skyhook,
},
validity: Default::default(),
location_trust_score_multiplier: dec!(1.0),
Expand Down
4 changes: 3 additions & 1 deletion mobile_verifier/tests/integrations/heartbeats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use futures_util::TryStreamExt;
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::HeartbeatValidity;
use helium_proto::services::poc_mobile::{HeartbeatValidity, LocationSource};
use mobile_verifier::{
cell_type::CellType,
heartbeats::{HbType, Heartbeat, HeartbeatReward, ValidatedHeartbeat},
Expand All @@ -27,6 +27,7 @@ async fn test_save_wifi_heartbeat(pool: PgPool) -> anyhow::Result<()> {
coverage_object: Some(coverage_object),
location_validation_timestamp: None,
timestamp: "2023-08-23 00:00:00.000000000 UTC".parse().unwrap(),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::SercommIndoor,
distance_to_asserted: Some(1000), // Cannot be null
Expand Down Expand Up @@ -64,6 +65,7 @@ async fn test_save_cbrs_heartbeat(pool: PgPool) -> anyhow::Result<()> {
coverage_object: Some(coverage_object),
location_validation_timestamp: None,
timestamp: "2023-08-23 00:00:00.000000000 UTC".parse().unwrap(),
location_source: LocationSource::Gps,
},
cell_type: CellType::SercommIndoor,
distance_to_asserted: None,
Expand Down
Loading