Skip to content

Commit

Permalink
Support new location source field on wifi heartbeats
Browse files Browse the repository at this point in the history
  • Loading branch information
bbalser committed Jun 24, 2024
1 parent 6ce7d68 commit f96ff4c
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 15 deletions.
6 changes: 3 additions & 3 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 @@ -69,7 +69,7 @@ helium-crypto = { version = "0.8.4", features = ["sqlx-postgres", "multisig"] }
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",
] }
solana-client = "1.16"
Expand All @@ -81,7 +81,7 @@ reqwest = { version = "0", default-features = false, features = [
"json",
"rustls-tls",
] }
beacon = { git = "https://github.com/helium/proto", branch = "master" }
beacon = { git = "https://github.com/helium/proto", branch = "bbalser/wifi-location-source" }
humantime = "2"
humantime-serde = "1"
metrics = ">=0.22"
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 @@ -17,7 +17,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 @@ -199,6 +199,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 @@ -246,6 +247,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 @@ -262,6 +264,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 @@ -612,6 +615,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 @@ -937,6 +941,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
16 changes: 14 additions & 2 deletions mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use file_store::{
};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
CoverageObjectValidity, HeartbeatValidity, RadioReward, SeniorityUpdateReason, SignalLevel,
UnallocatedReward,
CoverageObjectValidity, HeartbeatValidity, LocationSource, RadioReward, SeniorityUpdateReason,
SignalLevel, UnallocatedReward,
};
use hextree::Cell;
use mobile_config::boosted_hex_info::BoostedHexInfo;
Expand Down Expand Up @@ -1034,6 +1034,7 @@ async fn seed_heartbeats_v1(
coverage_object: Some(cov_obj_1.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1061,6 +1062,7 @@ async fn seed_heartbeats_v1(
coverage_object: Some(cov_obj_2.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1088,6 +1090,7 @@ async fn seed_heartbeats_v1(
coverage_object: Some(cov_obj_3.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1136,6 +1139,7 @@ async fn seed_heartbeats_v2(
coverage_object: Some(cov_obj_1.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1163,6 +1167,7 @@ async fn seed_heartbeats_v2(
coverage_object: Some(cov_obj_2.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1190,6 +1195,7 @@ async fn seed_heartbeats_v2(
coverage_object: Some(cov_obj_3.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1240,6 +1246,7 @@ async fn seed_heartbeats_v3(
coverage_object: Some(cov_obj_1.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1267,6 +1274,7 @@ async fn seed_heartbeats_v3(
coverage_object: Some(cov_obj_2.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1294,6 +1302,7 @@ async fn seed_heartbeats_v3(
coverage_object: Some(cov_obj_3.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(300),
Expand Down Expand Up @@ -1342,6 +1351,7 @@ async fn seed_heartbeats_v4(
coverage_object: Some(cov_obj_1.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1369,6 +1379,7 @@ async fn seed_heartbeats_v4(
coverage_object: Some(cov_obj_2.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down Expand Up @@ -1397,6 +1408,7 @@ async fn seed_heartbeats_v4(
coverage_object: Some(cov_obj_3.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::SercommOutdoor,
distance_to_asserted: Some(1),
Expand Down
3 changes: 2 additions & 1 deletion mobile_verifier/tests/integrations/last_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use chrono::{DateTime, Duration, Utc};
use file_store::coverage::RadioHexSignalLevel;
use h3o::LatLng;
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile as proto;
use helium_proto::services::poc_mobile::{self as proto, LocationSource};
use mobile_verifier::{
coverage::{CoverageObject, CoverageObjectCache},
geofence::GeofenceValidator,
Expand Down Expand Up @@ -291,6 +291,7 @@ impl HeartbeatBuilder {
coverage_object: Some(self.coverage_object.coverage_object.uuid),
location_validation_timestamp: self.location_validation_timestamp,
timestamp: self.timestamp.unwrap_or(Utc::now()),
location_source: LocationSource::Skyhook,
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion mobile_verifier/tests/integrations/modeled_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::stream::{self, StreamExt};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::{
mobile_config::NetworkKeyRole,
poc_mobile::{CoverageObjectValidity, SignalLevel},
poc_mobile::{CoverageObjectValidity, LocationSource, SignalLevel},
};
use hextree::Cell;
use mobile_config::boosted_hex_info::{BoostedHexInfo, BoostedHexes};
Expand Down Expand Up @@ -1392,6 +1392,7 @@ async fn ensure_lower_trust_score_for_distant_heartbeats(pool: PgPool) -> anyhow
location_validation_timestamp: Some(DateTime::<Utc>::MIN_UTC),
operation_mode: true,
coverage_object: Vec::from(coverage_object_uuid.into_bytes()),
location_source: LocationSource::Skyhook,
},
received_timestamp: Utc::now(),
};
Expand All @@ -1407,6 +1408,7 @@ async fn ensure_lower_trust_score_for_distant_heartbeats(pool: PgPool) -> anyhow
location_validation_timestamp: Some(DateTime::<Utc>::MIN_UTC),
operation_mode: true,
coverage_object: Vec::from(coverage_object_uuid.into_bytes()),
location_source: LocationSource::Skyhook,
},
received_timestamp: Utc::now(),
};
Expand Down
7 changes: 5 additions & 2 deletions mobile_verifier/tests/integrations/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use file_store::{
};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
CoverageObjectValidity, GatewayReward, HeartbeatValidity, RadioReward, SeniorityUpdateReason,
SignalLevel, UnallocatedReward, UnallocatedRewardType,
CoverageObjectValidity, GatewayReward, HeartbeatValidity, LocationSource, RadioReward,
SeniorityUpdateReason, SignalLevel, UnallocatedReward, UnallocatedRewardType,
};
use mobile_verifier::{
cell_type::CellType,
Expand Down Expand Up @@ -186,6 +186,7 @@ async fn seed_heartbeats(
coverage_object: Some(cov_obj_1.coverage_object.uuid),
location_validation_timestamp: None,
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Gps,
},
cell_type: CellType::SercommIndoor,
distance_to_asserted: None,
Expand Down Expand Up @@ -214,6 +215,7 @@ async fn seed_heartbeats(
coverage_object: Some(cov_obj_2.coverage_object.uuid),
location_validation_timestamp: None,
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Gps,
},
cell_type: CellType::SercommOutdoor,
distance_to_asserted: None,
Expand Down Expand Up @@ -241,6 +243,7 @@ async fn seed_heartbeats(
coverage_object: Some(cov_obj_3.coverage_object.uuid),
location_validation_timestamp: Some(ts - ChronoDuration::hours(24)),
timestamp: ts + ChronoDuration::hours(n),
location_source: LocationSource::Skyhook,
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
Expand Down
5 changes: 4 additions & 1 deletion mobile_verifier/tests/integrations/seniority.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use chrono::{DateTime, Utc};
use helium_proto::services::poc_mobile::{HeartbeatValidity, SeniorityUpdateReason};
use helium_proto::services::poc_mobile::{
HeartbeatValidity, LocationSource, SeniorityUpdateReason,
};
use mobile_verifier::cell_type::CellType;
use mobile_verifier::coverage::Seniority;
use mobile_verifier::heartbeats::{
Expand All @@ -25,6 +27,7 @@ async fn test_seniority_updates(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: None,
Expand Down

0 comments on commit f96ff4c

Please sign in to comment.