Skip to content

Commit 67c6001

Browse files
authored
Add 300Mbps speedtest validation with bounds checking (#1031)
* Add 300MB speedtest validation with bounds checking Implements SpeedtestValueOutOfBounds validation to reject speedtests exceeding 300MB upload/download limits. * Remove redundant cloning * Rename confusing constant * fixes * Renames in tests
1 parent c90e296 commit 67c6001

File tree

5 files changed

+351
-22
lines changed

5 files changed

+351
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,5 @@ anchor-lang = { git = "https://github.com/madninja/anchor.git", branch = "madnin
168168
# helium-proto = { path = "../proto" }
169169
# beacon = { path = "../proto/beacon" }
170170

171-
172-
# [patch.'https://github.com/helium/proto']
173-
# helium-proto = { git = "https://www.github.com/helium/proto.git", branch = "kurotych/carrier-enablement" }
171+
[patch.'https://github.com/helium/proto']
172+
helium-proto = { git = "https://www.github.com/helium/proto.git", branch = "kurotych/speedtest-bounds" }

coverage_point_calculator/src/speedtest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ type Millis = u32;
1111
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd)]
1212
pub struct BytesPs(u64);
1313

14-
impl BytesPs {
15-
const BYTES_PER_MEGABYTE: u64 = 125_000;
14+
pub const BYTES_PER_MEGABIT: u64 = 125_000;
1615

16+
impl BytesPs {
1717
pub fn new(bytes_per_second: u64) -> Self {
1818
Self(bytes_per_second)
1919
}
2020

2121
pub fn mbps(megabytes_per_second: u64) -> Self {
22-
Self(megabytes_per_second * Self::BYTES_PER_MEGABYTE)
22+
Self(megabytes_per_second * BYTES_PER_MEGABIT)
2323
}
2424

2525
fn as_mbps(&self) -> u64 {
26-
self.0 / Self::BYTES_PER_MEGABYTE
26+
self.0 / BYTES_PER_MEGABIT
2727
}
2828

2929
pub fn as_bps(&self) -> u64 {

mobile_verifier/src/speedtests.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
Settings,
44
};
55
use chrono::{DateTime, Utc};
6+
use coverage_point_calculator::speedtest::BYTES_PER_MEGABIT;
67
use file_store::{
78
file_info_poller::FileInfoStream, file_sink::FileSinkClient, file_source,
89
file_upload::FileUpload, BucketClient,
@@ -28,6 +29,10 @@ use task_manager::{ManagedTask, TaskManager};
2829
use tokio::sync::mpsc::Receiver;
2930

3031
const SPEEDTEST_AVG_MAX_DATA_POINTS: usize = 6;
32+
// The limit must be 300 megabits per second.
33+
// Values in proto are in bytes/sec format.
34+
// Convert 300 megabits per second to bytes per second.
35+
const SPEEDTEST_MAX_BYTES_PER_SECOND: u64 = 300 * BYTES_PER_MEGABIT;
3136

3237
pub type EpochSpeedTests = HashMap<PublicKeyBinary, Vec<Speedtest>>;
3338

@@ -173,11 +178,15 @@ where
173178
&self,
174179
speedtest: &CellSpeedtestIngestReport,
175180
) -> anyhow::Result<SpeedtestResult> {
176-
let pubkey = speedtest.report.pubkey.clone();
181+
if speedtest.report.upload_speed > SPEEDTEST_MAX_BYTES_PER_SECOND
182+
|| speedtest.report.download_speed > SPEEDTEST_MAX_BYTES_PER_SECOND
183+
{
184+
return Ok(SpeedtestResult::SpeedtestValueOutOfBounds);
185+
}
177186

178187
match self
179188
.gateway_info_resolver
180-
.resolve_gateway_info(&pubkey)
189+
.resolve_gateway_info(&speedtest.report.pubkey)
181190
.await?
182191
{
183192
Some(gw_info) if gw_info.is_data_only() => {

0 commit comments

Comments
 (0)