Target signed fleet commands by region and GPS radius

This commit is contained in:
mikecarper committed 2026-10-09 01:32:12 -07:00
1 parent 8b3655d76a
commit 4d446c2cd0
24 files changed
+2447 -107

No files matched your search

+28 -3
View File
@@ -27,6 +27,13 @@ public:
static constexpr size_t FixedTargetMaxCommandLength = MaxEnvelopeLength - HeaderSize - SignatureSize;
static constexpr size_t MaxTargetBytes = 86;
static constexpr size_t MaxTargetCount = 17;
static constexpr uint8_t RegionRecordType = 0x20;
static constexpr uint8_t HomeRecordType = 0x21;
static constexpr uint8_t GeoRecordType = 0x22;
static constexpr size_t GeoRecordLength = 13;
static constexpr size_t MaxRegionNameLength = 30;
static constexpr uint32_t MinRadiusMeters = 1;
static constexpr uint32_t MaxRadiusMeters = 20050000;
static constexpr uint32_t MinEpoch = 1735689600UL; // 2025-01-01 UTC
static constexpr uint32_t MaxLifetime = 600;
static constexpr uint32_t MaxClockLead = 60;
@@ -43,9 +50,20 @@ public:
uint8_t count;
// Each record is a length/type byte (4, 6, or 16) followed by that many
// bytes. Prefixes are raw public-key bytes; complete keys are SHA-256/128.
// Region/home records are type 0x20/0x21, name length, then canonical name.
// GPS records are type 0x22, signed latitude/longitude E6, radius metres LE32.
uint8_t data[MaxTargetBytes];
};
enum class RegionTarget { Configured, Home };
// Names are length-delimited and case-sensitive, with one leading '#' alias
// removed by the encoder. The role matches against its existing RegionMap.
// This bounded, read-only callback must not execute or mutate any state.
using RegionMatcher = bool (*)(void* context, RegionTarget target,
const char* name, size_t length);
using GeoMatcher = bool (*)(void* context, int32_t latitude_e6,
int32_t longitude_e6, uint32_t radius_meters);
struct Fragment {
uint32_t sequence;
uint16_t total_length;
@@ -58,10 +76,15 @@ public:
// "all" becomes the reserved zero target; otherwise require one complete
// public key and derive the first 16 bytes of SHA-256, not a short node ID.
static bool parseTarget(const char* text, uint8_t* target);
// Parse one bounded token containing comma-separated 8-, 12-, or 64-digit
// public keys. "all" is accepted only alone and produces zero records.
// Parse one bounded token containing semicolon-separated public keys and named
// regions. Bare key-length tokens never fall back to region names; explicit
// region:/home: selectors permit ambiguous names. GPS circles use
// gps:latitude,longitude:radius-km. "all" is accepted alone.
static bool parseTargets(const char* text, size_t length, Targets& targets);
static bool commandAllowed(const char* command);
static bool withinRadius(int32_t center_latitude_e6, int32_t center_longitude_e6,
uint32_t radius_meters, int32_t local_latitude_e6,
int32_t local_longitude_e6);
// Return the exact envelope size, or zero on invalid input. The signature
// binds the domain, private channel key, complete header, and command bytes.
@@ -83,7 +106,9 @@ public:
// any mutation, and defer execution until the receive stack has unwound.
static bool decode(const Identity& publisher, const uint8_t* key,
const uint8_t* payload, size_t length, uint32_t now,
const uint8_t* self_public_key, Decoded& output);
const uint8_t* self_public_key, Decoded& output,
RegionMatcher matcher = nullptr, void* context = nullptr,
GeoMatcher geo_matcher = nullptr, void* geo_context = nullptr);
// Envelopes <= MaxPayloadLength travel unchanged. Longer envelopes use
// exactly two FMP1 frames, each bounded by the group payload limit.