Add repeater flood filters and transport scopes
This commit is contained in:
1 parent
5e030ce77b
commit
09c8aaba9c
25 files changed
+1222
-111
No files matched your search
+2
-2
@@ -380,10 +380,10 @@ protected:
|
||||
*/
|
||||
virtual void onRawDataRecv(Packet* packet) { }
|
||||
|
||||
#if defined(ENABLE_OTA)
|
||||
/** OTA transport is dormant unless the role has actually switched into a temporary-radio window. */
|
||||
/** True only while the role has actually switched into a temporary-radio window. */
|
||||
virtual bool isTempRadioActive() const { return false; }
|
||||
|
||||
#if defined(ENABLE_OTA)
|
||||
/**
|
||||
* \brief An OTA-over-LoRa packet (PAYLOAD_TYPE_OTA) has been received. Subclasses forward the
|
||||
* payload bytes to their OtaManager. See docs/ota_protocol.md.
|
||||
|
||||
@@ -272,7 +272,7 @@ int RegionMap::getTransportKeysFor(const RegionEntry& src, TransportKey dest[],
|
||||
return num;
|
||||
}
|
||||
|
||||
RegionEntry* RegionMap::findMatch(mesh::Packet* packet, uint8_t mask) {
|
||||
RegionEntry* RegionMap::findMatch(const mesh::Packet* packet, uint8_t mask) {
|
||||
for (int i = 0; i < num_regions; i++) {
|
||||
auto region = ®ions[i];
|
||||
if ((region->flags & mask) == 0) { // does region allow this? (per 'mask' param)
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
bool save(FILESYSTEM* _fs, const char* path=NULL);
|
||||
|
||||
RegionEntry* putRegion(const char* name, uint16_t parent_id, uint16_t id = 0);
|
||||
RegionEntry* findMatch(mesh::Packet* packet, uint8_t mask);
|
||||
RegionEntry* findMatch(const mesh::Packet* packet, uint8_t mask);
|
||||
RegionEntry& getWildcard() { return wildcard; }
|
||||
RegionEntry* findByName(const char* name);
|
||||
RegionEntry* findByNamePrefix(const char* prefix);
|
||||
|
||||
@@ -39,7 +39,9 @@ void PacketQueue::rebuildNextTime() {
|
||||
}
|
||||
}
|
||||
|
||||
mesh::Packet* PacketQueue::get(uint32_t now) {
|
||||
mesh::Packet* PacketQueue::get(uint32_t now, bool resolve_flood_scope,
|
||||
FloodScopePreference scope_preference,
|
||||
void* scope_preference_context) {
|
||||
uint8_t min_pri = 0xFF;
|
||||
int best_idx = -1;
|
||||
for (int j = 0; j < _num; j++) {
|
||||
@@ -51,6 +53,10 @@ mesh::Packet* PacketQueue::get(uint32_t now) {
|
||||
}
|
||||
if (best_idx < 0) return NULL; // empty, or all items are still in the future
|
||||
|
||||
if (resolve_flood_scope) {
|
||||
applyBestFloodTransportScope(_table[best_idx], scope_preference,
|
||||
scope_preference_context);
|
||||
}
|
||||
return removeByIdx(best_idx);
|
||||
}
|
||||
|
||||
@@ -97,7 +103,52 @@ bool PacketQueue::add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled
|
||||
return true;
|
||||
}
|
||||
|
||||
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size): unused(pool_size), send_queue(pool_size), rx_queue(pool_size) {
|
||||
void PacketQueue::applyBestFloodTransportScope(mesh::Packet* packet,
|
||||
FloodScopePreference scope_preference,
|
||||
void* scope_preference_context) const {
|
||||
// Scope validity is application-specific. Without a validator there is no
|
||||
// safe way to distinguish a locally-allowed scope from arbitrary codes.
|
||||
if (packet == NULL || !packet->isRouteFlood()
|
||||
|| packet->getPayloadType() == PAYLOAD_TYPE_TRACE
|
||||
|| scope_preference == NULL) return;
|
||||
|
||||
uint8_t packet_hash[MAX_HASH_SIZE];
|
||||
packet->calculatePacketHash(packet_hash);
|
||||
|
||||
const mesh::Packet* best = NULL;
|
||||
uint8_t best_hops = 0xFF;
|
||||
uint8_t best_preference = 0;
|
||||
for (int i = 0; i < _num; i++) {
|
||||
const mesh::Packet* candidate = _table[i];
|
||||
if (candidate == NULL || candidate->getRouteType() != ROUTE_TYPE_TRANSPORT_FLOOD) continue;
|
||||
uint8_t candidate_hash[MAX_HASH_SIZE];
|
||||
candidate->calculatePacketHash(candidate_hash);
|
||||
if (memcmp(packet_hash, candidate_hash, sizeof(packet_hash)) != 0) continue;
|
||||
|
||||
uint8_t hops = candidate->getPathHashCount();
|
||||
uint8_t preference = scope_preference(candidate, scope_preference_context);
|
||||
if (preference == 0) continue; // unknown, denied, or otherwise unusable here
|
||||
if (best == NULL || hops < best_hops
|
||||
|| (hops == best_hops && preference > best_preference)) {
|
||||
best = candidate;
|
||||
best_hops = hops;
|
||||
best_preference = preference;
|
||||
}
|
||||
}
|
||||
if (best == NULL) return;
|
||||
|
||||
// Keep the receive-quality winner's path, SNR, and schedule, but give it the
|
||||
// scope carried by the shortest equivalent scoped copy. Equal paths prefer
|
||||
// the most specific locally-recognized scope supplied by the application.
|
||||
packet->header = (packet->header & (uint8_t)~PH_ROUTE_MASK) | ROUTE_TYPE_TRANSPORT_FLOOD;
|
||||
if (packet != best) {
|
||||
memcpy(packet->transport_codes, best->transport_codes, sizeof(packet->transport_codes));
|
||||
}
|
||||
}
|
||||
|
||||
StaticPoolPacketManager::StaticPoolPacketManager(int pool_size)
|
||||
: unused(pool_size), send_queue(pool_size), rx_queue(pool_size),
|
||||
flood_scope_preference(NULL), flood_scope_preference_context(NULL) {
|
||||
// load up our unusued Packet pool
|
||||
for (int i = 0; i < pool_size; i++) {
|
||||
unused.add(new mesh::Packet(), 0, 0);
|
||||
@@ -159,7 +210,8 @@ void StaticPoolPacketManager::queueInbound(mesh::Packet* packet, uint32_t schedu
|
||||
}
|
||||
}
|
||||
mesh::Packet* StaticPoolPacketManager::getNextInbound(uint32_t now) {
|
||||
return rx_queue.get(now);
|
||||
return rx_queue.get(now, true, flood_scope_preference,
|
||||
flood_scope_preference_context);
|
||||
}
|
||||
|
||||
bool StaticPoolPacketManager::getNextInboundTime(uint32_t now, uint32_t& scheduled_for) const {
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include <Dispatcher.h>
|
||||
|
||||
// Zero rejects a candidate as unknown/denied; positive values rank eligible
|
||||
// scopes, with larger values preferred when received path lengths are equal.
|
||||
typedef uint8_t (*FloodScopePreference)(const mesh::Packet* packet, void* context);
|
||||
|
||||
class PacketQueue {
|
||||
mesh::Packet** _table;
|
||||
uint8_t* _pri_table;
|
||||
@@ -10,10 +14,15 @@ class PacketQueue {
|
||||
uint32_t _next_schedule;
|
||||
|
||||
void rebuildNextTime();
|
||||
void applyBestFloodTransportScope(mesh::Packet* packet,
|
||||
FloodScopePreference scope_preference,
|
||||
void* scope_preference_context) const;
|
||||
|
||||
public:
|
||||
PacketQueue(int max_entries);
|
||||
mesh::Packet* get(uint32_t now);
|
||||
mesh::Packet* get(uint32_t now, bool resolve_flood_scope = false,
|
||||
FloodScopePreference scope_preference = NULL,
|
||||
void* scope_preference_context = NULL);
|
||||
mesh::Packet* peek(uint32_t now) const;
|
||||
bool add(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for);
|
||||
int count() const { return _num; }
|
||||
@@ -25,10 +34,17 @@ public:
|
||||
|
||||
class StaticPoolPacketManager : public mesh::PacketManager {
|
||||
PacketQueue unused, send_queue, rx_queue;
|
||||
FloodScopePreference flood_scope_preference;
|
||||
void* flood_scope_preference_context;
|
||||
|
||||
public:
|
||||
StaticPoolPacketManager(int pool_size);
|
||||
|
||||
void setFloodScopePreference(FloodScopePreference preference, void* context) {
|
||||
flood_scope_preference = preference;
|
||||
flood_scope_preference_context = context;
|
||||
}
|
||||
|
||||
mesh::Packet* allocNew() override;
|
||||
void free(mesh::Packet* packet) override;
|
||||
bool queueOutbound(mesh::Packet* packet, uint8_t priority, uint32_t scheduled_for) override;
|
||||
|
||||
Reference in new issue
Block a user