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

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

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion coverage_map/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition.workspace = true
[dependencies]
chrono = { workspace = true }
h3o = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h30, helium-proto, and uuid are also candidates for removal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!, removed 530cb59

helium-crypto = { workspace = true }
helium-proto = { workspace = true }
hex-assignments = { path = "../hex_assignments" }
hextree = { workspace = true }
Expand Down
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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not very important, but these don't even need to be length 2. They could just be vec![0], vec![1], etc.

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