Skip to content

Commit

Permalink
Change coverage map to treat hotspot_key as bytes rather than a Publi…
Browse files Browse the repository at this point in the history
…cKeyBinary (#825)

* Change coverage map to treat hotspot_key as bytes rather than a PublicKeyBinary

* Remove more deps
  • Loading branch information
bbalser authored Jun 6, 2024
1 parent 6420804 commit 08cd5aa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 91 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions coverage_map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ edition.workspace = true

[dependencies]
chrono = { workspace = true }
h3o = { workspace = true }
helium-crypto = { workspace = true }
helium-proto = { workspace = true }
hex-assignments = { path = "../hex_assignments" }
hextree = { workspace = true }
uuid = { workspace = true }
22 changes: 6 additions & 16 deletions coverage_map/src/indoor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use hex_assignments::assignment::HexAssignments;
use hextree::Cell;

Expand All @@ -14,7 +13,7 @@ pub type IndoorCellTree = HashMap<Cell, BTreeMap<SignalLevel, BinaryHeap<IndoorC

#[derive(Eq, Debug, Clone)]
pub struct IndoorCoverageLevel {
hotspot_key: PublicKeyBinary,
hotspot_key: Vec<u8>,
cbsd_id: Option<String>,
seniority_timestamp: DateTime<Utc>,
signal_level: SignalLevel,
Expand Down Expand Up @@ -53,7 +52,7 @@ pub fn insert_indoor_coverage_object(indoor: &mut IndoorCellTree, coverage_objec

pub fn insert_indoor_coverage(
indoor: &mut IndoorCellTree,
hotspot: &PublicKeyBinary,
hotspot: &[u8],
cbsd_id: &Option<String>,
seniority_timestamp: DateTime<Utc>,
hex_coverage: UnrankedCoverage,
Expand All @@ -64,7 +63,7 @@ pub fn insert_indoor_coverage(
.entry(hex_coverage.signal_level)
.or_default()
.push(IndoorCoverageLevel {
hotspot_key: hotspot.clone(),
hotspot_key: hotspot.to_vec(),
cbsd_id: cbsd_id.clone(),
seniority_timestamp,
signal_level: hex_coverage.signal_level,
Expand Down Expand Up @@ -234,12 +233,9 @@ mod test {
}

fn indoor_cbrs_coverage(cbsd_id: &str, signal_level: SignalLevel) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: true,
hotspot_key: owner,
hotspot_key: vec![1, 0],
seniority_timestamp: Utc::now(),
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand All @@ -256,12 +252,9 @@ mod test {
signal_level: SignalLevel,
seniority_timestamp: DateTime<Utc>,
) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: true,
hotspot_key: owner,
hotspot_key: vec![1, 0],
seniority_timestamp,
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand All @@ -278,12 +271,9 @@ mod test {
location: Cell,
seniority_timestamp: DateTime<Utc>,
) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: true,
hotspot_key: owner,
hotspot_key: vec![1, 0],
seniority_timestamp,
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand Down
90 changes: 31 additions & 59 deletions coverage_map/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::HashMap, num::NonZeroU32};

use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use hex_assignments::assignment::HexAssignments;
use hextree::Cell;

Expand Down Expand Up @@ -120,14 +119,14 @@ impl CoverageMapBuilder {
/// Data structure from mapping radios to their ranked hex coverage
#[derive(Clone, Default, Debug)]
pub struct CoverageMap {
wifi_hotspots: HashMap<PublicKeyBinary, Vec<RankedCoverage>>,
wifi_hotspots: HashMap<Vec<u8>, Vec<RankedCoverage>>,
cbrs_radios: HashMap<String, Vec<RankedCoverage>>,
}

impl CoverageMap {
/// Returns the hexes covered by the WiFi hotspot. The returned slice can be empty, indicating that
/// the hotspot did not meet the criteria to be ranked in any hex.
pub fn get_wifi_coverage(&self, wifi_hotspot: &PublicKeyBinary) -> &[RankedCoverage] {
pub fn get_wifi_coverage(&self, wifi_hotspot: &[u8]) -> &[RankedCoverage] {
self.wifi_hotspots
.get(wifi_hotspot)
.map(Vec::as_slice)
Expand All @@ -148,7 +147,7 @@ impl CoverageMap {
#[derive(Clone, Debug)]
pub struct CoverageObject {
pub indoor: bool,
pub hotspot_key: PublicKeyBinary,
pub hotspot_key: Vec<u8>,
pub cbsd_id: Option<String>,
pub seniority_timestamp: DateTime<Utc>,
pub coverage: Vec<UnrankedCoverage>,
Expand All @@ -168,7 +167,7 @@ pub struct UnrankedCoverage {
pub struct RankedCoverage {
pub hex: Cell,
pub rank: usize,
pub hotspot_key: PublicKeyBinary,
pub hotspot_key: Vec<u8>,
pub cbsd_id: Option<String>,
pub assignments: HexAssignments,
pub boosted: Option<NonZeroU32>,
Expand Down Expand Up @@ -233,41 +232,33 @@ mod test {

#[test]
fn test_indoor_wifi_submap() {
let radio1 = vec![1, 1, 1];
let radio2 = vec![1, 1, 2];
let radio3 = vec![1, 1, 3];

let mut coverage_map_builder = CoverageMapBuilder::default();
coverage_map_builder.insert_coverage_object(indoor_wifi_coverage(
"11xtYwQYnvkFYnJ9iZ8kmnetYKwhdi87Mcr36e1pVLrhBMPLjV9",
&radio1,
0x8a1fb46622dffff,
SignalLevel::High,
));
coverage_map_builder.insert_coverage_object(indoor_wifi_coverage(
"11PGVtgW9aM9ynfvns5USUsynYQ7EsMpxVqWuDKqFogKQX7etkR",
&radio2,
0x8c2681a3064d9ff,
SignalLevel::Low,
));
let submap_builder = coverage_map_builder.submap(vec![indoor_wifi_coverage(
"11ibmJmQXTL6qMh4cq9pJ7tUtrpafWaVjjT6qhY7CNvjyvY9g1",
&radio3,
0x8c2681a3064d9ff,
SignalLevel::High,
)]);
let submap = submap_builder.build(&NoBoostedHexes, Utc::now());
let cov_1 = submap.get_wifi_coverage(
&"11xtYwQYnvkFYnJ9iZ8kmnetYKwhdi87Mcr36e1pVLrhBMPLjV9"
.parse()
.unwrap(),
);
let cov_1 = submap.get_wifi_coverage(&radio1);
assert_eq!(cov_1.len(), 0);
let cov_2 = submap.get_wifi_coverage(
&"11PGVtgW9aM9ynfvns5USUsynYQ7EsMpxVqWuDKqFogKQX7etkR"
.parse()
.unwrap(),
);
let cov_2 = submap.get_wifi_coverage(&radio2);
assert_eq!(cov_2.len(), 1);
assert_eq!(cov_2[0].rank, 2);
let cov_3 = submap.get_wifi_coverage(
&"11ibmJmQXTL6qMh4cq9pJ7tUtrpafWaVjjT6qhY7CNvjyvY9g1"
.parse()
.unwrap(),
);
let cov_3 = submap.get_wifi_coverage(&radio3);
assert_eq!(cov_3.len(), 1);
assert_eq!(cov_3[0].rank, 1);
}
Expand Down Expand Up @@ -300,41 +291,30 @@ mod test {

#[test]
fn test_outdoor_wifi_submap() {
let radio1 = vec![1, 1, 1];
let radio2 = vec![1, 1, 2];
let radio3 = vec![1, 1, 3];

let mut coverage_map_builder = CoverageMapBuilder::default();
coverage_map_builder.insert_coverage_object(outdoor_wifi_coverage(
"11xtYwQYnvkFYnJ9iZ8kmnetYKwhdi87Mcr36e1pVLrhBMPLjV9",
&radio1,
0x8a1fb46622dffff,
3,
));
coverage_map_builder.insert_coverage_object(outdoor_wifi_coverage(
"11PGVtgW9aM9ynfvns5USUsynYQ7EsMpxVqWuDKqFogKQX7etkR",
&radio2,
0x8c2681a3064d9ff,
1,
));
let submap_builder = coverage_map_builder.submap(vec![outdoor_wifi_coverage(
"11ibmJmQXTL6qMh4cq9pJ7tUtrpafWaVjjT6qhY7CNvjyvY9g1",
0x8c2681a3064d9ff,
2,
)]);
let submap_builder =
coverage_map_builder.submap(vec![outdoor_wifi_coverage(&radio3, 0x8c2681a3064d9ff, 2)]);
let submap = submap_builder.build(&NoBoostedHexes, Utc::now());
let cov_1 = submap.get_wifi_coverage(
&"11xtYwQYnvkFYnJ9iZ8kmnetYKwhdi87Mcr36e1pVLrhBMPLjV9"
.parse()
.unwrap(),
);
let cov_1 = submap.get_wifi_coverage(&radio1);
assert_eq!(cov_1.len(), 0);
let cov_2 = submap.get_wifi_coverage(
&"11PGVtgW9aM9ynfvns5USUsynYQ7EsMpxVqWuDKqFogKQX7etkR"
.parse()
.unwrap(),
);
let cov_2 = submap.get_wifi_coverage(&radio2);
assert_eq!(cov_2.len(), 1);
assert_eq!(cov_2[0].rank, 2);
let cov_3 = submap.get_wifi_coverage(
&"11ibmJmQXTL6qMh4cq9pJ7tUtrpafWaVjjT6qhY7CNvjyvY9g1"
.parse()
.unwrap(),
);
let cov_3 = submap.get_wifi_coverage(&radio3);
assert_eq!(cov_3.len(), 1);
assert_eq!(cov_3[0].rank, 1);
}
Expand All @@ -348,12 +328,9 @@ mod test {
}

fn indoor_cbrs_coverage(cbsd_id: &str, hex: u64, signal_level: SignalLevel) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: true,
hotspot_key: owner,
hotspot_key: vec![1, 0],
seniority_timestamp: Utc::now(),
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand All @@ -365,11 +342,10 @@ mod test {
}
}

fn indoor_wifi_coverage(owner: &str, hex: u64, signal_level: SignalLevel) -> CoverageObject {
let owner: PublicKeyBinary = owner.parse().expect("failed owner parse");
fn indoor_wifi_coverage(owner: &[u8], hex: u64, signal_level: SignalLevel) -> CoverageObject {
CoverageObject {
indoor: true,
hotspot_key: owner,
hotspot_key: owner.to_vec(),
seniority_timestamp: Utc::now(),
cbsd_id: None,
coverage: vec![UnrankedCoverage {
Expand All @@ -382,12 +358,9 @@ mod test {
}

fn outdoor_cbrs_coverage(cbsd_id: &str, hex: u64, signal_power: i32) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: false,
hotspot_key: owner,
hotspot_key: vec![0, 0],
seniority_timestamp: Utc::now(),
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand All @@ -399,11 +372,10 @@ mod test {
}
}

fn outdoor_wifi_coverage(owner: &str, hex: u64, signal_power: i32) -> CoverageObject {
let owner: PublicKeyBinary = owner.parse().expect("failed owner parse");
fn outdoor_wifi_coverage(owner: &[u8], hex: u64, signal_power: i32) -> CoverageObject {
CoverageObject {
indoor: false,
hotspot_key: owner,
hotspot_key: owner.to_vec(),
seniority_timestamp: Utc::now(),
cbsd_id: None,
coverage: vec![UnrankedCoverage {
Expand Down
12 changes: 4 additions & 8 deletions coverage_map/src/outdoor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use chrono::{DateTime, Utc};
use helium_crypto::PublicKeyBinary;
use hex_assignments::assignment::HexAssignments;
use hextree::Cell;

Expand All @@ -15,7 +14,7 @@ pub type OutdoorCellTree = HashMap<Cell, BinaryHeap<OutdoorCoverageLevel>>;

#[derive(Eq, Debug, Clone)]
pub struct OutdoorCoverageLevel {
hotspot_key: PublicKeyBinary,
hotspot_key: Vec<u8>,
cbsd_id: Option<String>,
seniority_timestamp: DateTime<Utc>,
signal_power: i32,
Expand Down Expand Up @@ -62,7 +61,7 @@ pub fn insert_outdoor_coverage_object(

pub fn insert_outdoor_coverage(
outdoor: &mut OutdoorCellTree,
hotspot: &PublicKeyBinary,
hotspot: &[u8],
cbsd_id: &Option<String>,
seniority_timestamp: DateTime<Utc>,
hex_coverage: UnrankedCoverage,
Expand All @@ -71,7 +70,7 @@ pub fn insert_outdoor_coverage(
.entry(hex_coverage.location)
.or_default()
.push(OutdoorCoverageLevel {
hotspot_key: hotspot.clone(),
hotspot_key: hotspot.to_vec(),
cbsd_id: cbsd_id.clone(),
seniority_timestamp,
signal_level: hex_coverage.signal_level,
Expand Down Expand Up @@ -171,12 +170,9 @@ mod test {
signal_power: i32,
seniority_timestamp: DateTime<Utc>,
) -> CoverageObject {
let owner: PublicKeyBinary = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6"
.parse()
.expect("failed owner parse");
CoverageObject {
indoor: false,
hotspot_key: owner,
hotspot_key: vec![0, 0],
seniority_timestamp,
cbsd_id: Some(cbsd_id.to_string()),
coverage: vec![UnrankedCoverage {
Expand Down

0 comments on commit 08cd5aa

Please sign in to comment.