Files
meshcore-open/lib/connector/raw_packet.dart
T
zjs81 bc14de586f Add opt-in network map uploads and online map view
- Opt-in upload of header-only packet records and repeater/room server
  adverts to map.meshcoreopen.org about once a minute; payloads, channel
  and DM hashes and transport codes are stripped on the phone, locations
  snapped to a ~2 km grid, install ID rotates daily
- One-time opt-in dialog on first radio connection; toggle and status in
  App settings
- Local / Online / Both switch on the map screen with online repeater
  hexagons, links, add-to-contacts and manage
- Node purchase banner on the connect screen (affiliate link, disclosed)
- Privacy policy and network map documentation
- Translations for all locales
2026-10-11 21:54:16 -07:00

30 lines
1005 B
Dart

import 'dart:typed_data';
import 'package:crypto/crypto.dart' as crypto;
/// Decodes the firmware's encoded path_len byte into actual byte length.
/// Bits 0-5: hash count (0-63), Bits 6-7: hash size code (0=1byte ... 3=4bytes).
int decodePathByteLen(int pathLenRaw) {
if (pathLenRaw == 0xFF || pathLenRaw == 0) return 0;
final hashCount = pathLenRaw & 63;
final hashSize = decodePathHashWidth(pathLenRaw);
return hashCount * hashSize;
}
int decodePathHashWidth(int pathLenRaw) {
if (pathLenRaw == 0xFF) return 1;
return ((pathLenRaw >> 6) & 0x03) + 1;
}
/// Firmware-compatible packet hash: SHA256(payloadType + payload) -> first 8 bytes as hex.
String computePacketHash(int payloadType, Uint8List payload) {
final input = Uint8List(1 + payload.length);
input[0] = payloadType;
input.setRange(1, input.length, payload);
final digest = crypto.sha256.convert(input).bytes;
return digest
.sublist(0, 8)
.map((b) => b.toRadixString(16).padLeft(2, '0'))
.join();
}