Address review: consent race, unsigned advert bytes, antimeridian
- Uploads carry a consent generation: nothing is sent if sharing is turned off while a batch is being prepared, and a late response never touches a queue that was cleared and refilled - Parse only the signed 32 advert app-data bytes, as the firmware does, so appended unsigned bytes can't add the hidden marker or change the name - Split online map requests that cross the antimeridian into two valid boxes and merge the results - README: link the network map next to the website
This commit is contained in:
1 parent
49582d3f07
commit
e614fb32e2
8 files changed
+239
-14
No files matched your search
@@ -41,6 +41,51 @@ const _bbox = NetworkMapBbox(
|
||||
);
|
||||
|
||||
void main() {
|
||||
group('visible area to request boxes', () {
|
||||
List<List<double>>? boxes(double w, double s, double e, double n) =>
|
||||
NetworkMapBbox.forVisibleArea(
|
||||
west: w,
|
||||
south: s,
|
||||
east: e,
|
||||
north: n,
|
||||
)?.map((b) => [b.minLon, b.minLat, b.maxLon, b.maxLat]).toList();
|
||||
|
||||
test('normal area is one box', () {
|
||||
expect(boxes(-112.5, 33, -111.5, 34), [
|
||||
[-112.5, 33, -111.5, 34],
|
||||
]);
|
||||
});
|
||||
|
||||
test('wrapped across the antimeridian is split in two', () {
|
||||
expect(boxes(179, -18, -179, -16), [
|
||||
[179, -18, 180, -16],
|
||||
[-180, -18, -179, -16],
|
||||
]);
|
||||
});
|
||||
|
||||
test('unwrapped longitudes beyond 180 are normalised and split', () {
|
||||
expect(boxes(175, 0, 185, 5), [
|
||||
[175, 0, 180, 5],
|
||||
[-180, 0, -175, 5],
|
||||
]);
|
||||
expect(boxes(190, 0, 200, 5), [
|
||||
[-170, 0, -160, 5],
|
||||
]);
|
||||
});
|
||||
|
||||
test('too large an area asks to zoom in', () {
|
||||
expect(boxes(-130, 20, -60, 50), isNull);
|
||||
expect(boxes(170, -40, -170, 40), isNull);
|
||||
});
|
||||
|
||||
test('every box is valid for the server', () {
|
||||
for (final b in boxes(179.5, 10, -170.25, 12)!) {
|
||||
expect(b[0] < b[2], isTrue);
|
||||
expect(b[0] >= -180 && b[2] <= 180, isTrue);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('parses repeaters and sends bbox', () async {
|
||||
late Uri requested;
|
||||
final client = NetworkMapApiClient(
|
||||
|
||||
@@ -75,6 +75,7 @@ Future<List<int>> _signedAdvertPayload({
|
||||
double? lon,
|
||||
String? name,
|
||||
bool corruptSignature = false,
|
||||
List<int> unsignedSuffix = const [],
|
||||
}) async {
|
||||
final publicKey = (await keyPair.extractPublicKey()).bytes;
|
||||
final timestamp = [0x10, 0x20, 0x30, 0x40];
|
||||
@@ -99,7 +100,13 @@ Future<List<int>> _signedAdvertPayload({
|
||||
], keyPair: keyPair);
|
||||
final sigBytes = List<int>.from(signature.bytes);
|
||||
if (corruptSignature) sigBytes[10] ^= 0x01;
|
||||
return [...publicKey, ...timestamp, ...sigBytes, ...appData];
|
||||
return [
|
||||
...publicKey,
|
||||
...timestamp,
|
||||
...sigBytes,
|
||||
...appData,
|
||||
...unsignedSuffix,
|
||||
];
|
||||
}
|
||||
|
||||
void main() {
|
||||
@@ -279,6 +286,7 @@ void main() {
|
||||
double? lon,
|
||||
String? name,
|
||||
bool corrupt = false,
|
||||
List<int> unsignedSuffix = const [],
|
||||
}) async {
|
||||
return _rxFrame(
|
||||
payloadType: payloadTypeADVERT,
|
||||
@@ -291,6 +299,7 @@ void main() {
|
||||
lon: lon,
|
||||
name: name,
|
||||
corruptSignature: corrupt,
|
||||
unsignedSuffix: unsignedSuffix,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -361,6 +370,24 @@ void main() {
|
||||
expect(json['key'], keyHex);
|
||||
});
|
||||
|
||||
test('bytes after the signed 32 app-data bytes are ignored', () async {
|
||||
// flags (1) + location (8) + 23-byte name fill the signed 32 bytes.
|
||||
const name = 'Hilltop Repeater North1';
|
||||
expect(utf8.encode(name).length, 23);
|
||||
final frame = await advertFrame(
|
||||
type: advTypeRepeater,
|
||||
lat: 47.6,
|
||||
lon: -122.3,
|
||||
name: name,
|
||||
unsignedSuffix: utf8.encode(' \u{1F6AB} evil'),
|
||||
);
|
||||
final advert = (await buildAdvertRecord(frame, _receivedAt))!;
|
||||
final json = advert.toJson();
|
||||
expect(json['hidden'], false);
|
||||
expect(json['name'], name);
|
||||
expect(json['loc'], isNotNull);
|
||||
});
|
||||
|
||||
test('adverts with a bad signature are dropped', () async {
|
||||
final frame = await advertFrame(
|
||||
type: advTypeRepeater,
|
||||
|
||||
@@ -3,7 +3,9 @@ import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_connector.dart';
|
||||
import 'package:meshcore_open/services/app_settings_service.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_records.dart';
|
||||
import 'package:meshcore_open/services/network_map/network_map_upload_service.dart';
|
||||
import 'dart:async';
|
||||
import 'package:meshcore_open/storage/prefs_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
@@ -45,4 +47,91 @@ void main() {
|
||||
expect(service.packetsSentToday, 0);
|
||||
expect(requests, 0);
|
||||
});
|
||||
|
||||
group('withdrawing consent mid-upload', () {
|
||||
NetworkMapPacketRecord packet() => NetworkMapPacketRecord(
|
||||
t: DateTime.now().millisecondsSinceEpoch ~/ 60000 * 60,
|
||||
pt: 5,
|
||||
rt: 1,
|
||||
hw: 1,
|
||||
path: 'aa',
|
||||
snr: 6.5,
|
||||
rssi: -90,
|
||||
size: 48,
|
||||
h: '0011223344556677',
|
||||
scoped: false,
|
||||
);
|
||||
|
||||
Future<(NetworkMapUploadService, AppSettingsService)> setUpService(
|
||||
MockClient client,
|
||||
) async {
|
||||
final connector = _ConnectedConnector();
|
||||
final settings = AppSettingsService();
|
||||
await settings.loadSettings();
|
||||
await settings.setNetworkMapUploadEnabled(true);
|
||||
final service = NetworkMapUploadService(
|
||||
connector: connector,
|
||||
settings: settings,
|
||||
client: client,
|
||||
);
|
||||
addTearDown(() {
|
||||
service.dispose();
|
||||
connector.dispose();
|
||||
});
|
||||
return (service, settings);
|
||||
}
|
||||
|
||||
test(
|
||||
'nothing is sent when sharing is turned off before the POST',
|
||||
() async {
|
||||
var requests = 0;
|
||||
final (service, settings) = await setUpService(
|
||||
MockClient((_) async {
|
||||
requests++;
|
||||
return http.Response('{}', 202);
|
||||
}),
|
||||
);
|
||||
service.queuePacketForTest(packet());
|
||||
final upload = service.uploadNowForTest();
|
||||
await settings.setNetworkMapUploadEnabled(false);
|
||||
await upload;
|
||||
|
||||
expect(requests, 0);
|
||||
expect(service.queuedPacketCount, 0);
|
||||
expect(service.lastUploadAt, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
test('a late response never touches the refilled queue', () async {
|
||||
final response = Completer<http.Response>();
|
||||
final posted = Completer<void>();
|
||||
final (service, settings) = await setUpService(
|
||||
MockClient((_) {
|
||||
posted.complete();
|
||||
return response.future;
|
||||
}),
|
||||
);
|
||||
service.queuePacketForTest(packet());
|
||||
final upload = service.uploadNowForTest();
|
||||
await posted.future;
|
||||
|
||||
// Off and on again while the first POST is in flight, then new records.
|
||||
await settings.setNetworkMapUploadEnabled(false);
|
||||
await settings.setNetworkMapUploadEnabled(true);
|
||||
service.queuePacketForTest(packet());
|
||||
service.queuePacketForTest(packet());
|
||||
|
||||
response.complete(http.Response('{}', 202));
|
||||
await upload;
|
||||
|
||||
expect(service.queuedPacketCount, 2);
|
||||
expect(service.lastUploadAt, isNull);
|
||||
expect(service.packetsSentToday, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _ConnectedConnector extends MeshCoreConnector {
|
||||
@override
|
||||
bool get isConnected => true;
|
||||
}
|
||||
Reference in new issue
Block a user