Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/simple_repeater/MyMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,30 @@ uint32_t MyMesh::getDirectRetransmitDelay(const mesh::Packet *packet) {
return getRNG()->nextInt(0, 5*t + 1);
}

uint8_t MyMesh::getForwardPriority(const mesh::Packet* packet, uint8_t default_priority) {
// check admin-relevant packet types only
uint8_t type = packet->getPayloadType();
if (type != PAYLOAD_TYPE_REQ &&
type != PAYLOAD_TYPE_RESPONSE &&
type != PAYLOAD_TYPE_TXT_MSG &&
type != PAYLOAD_TYPE_PATH) {
return default_priority;
}

if (packet->payload_len < 2) return default_priority;
uint8_t src_hash = packet->payload[1]; // payload[0] is dest_hash

// check ACL for admin sender
for (int i = 0; i < acl.getNumClients(); i++) {
auto client = acl.getClientByIdx(i);
if (client->id.isHashMatch(&src_hash) && client->isAdmin()) {
return 0; // highest priority
}
}

return default_priority;
}

bool MyMesh::filterRecvFloodPacket(mesh::Packet* pkt) {
// just try to determine region for packet (apply later in allowPacketForward())
if (pkt->getRouteType() == ROUTE_TYPE_TRANSPORT_FLOOD) {
Expand Down
2 changes: 2 additions & 0 deletions examples/simple_repeater/MyMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
return _prefs.multi_acks;
}

uint8_t getForwardPriority(const mesh::Packet* packet, uint8_t default_priority) override;

#if ENV_INCLUDE_GPS == 1
void applyGpsPrefs() {
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
Expand Down
10 changes: 8 additions & 2 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ uint32_t Mesh::getCADFailRetryDelay() const {
return _rng->nextInt(1, 4)*120;
}

uint8_t Mesh::getForwardPriority(const Packet* packet, uint8_t default_priority) {
return default_priority;
}

int Mesh::searchPeersByHash(const uint8_t* hash) {
return 0; // not found
}
Expand Down Expand Up @@ -330,8 +334,10 @@ DispatcherAction Mesh::routeRecvPacket(Packet* packet) {
packet->path_len += self_id.copyHashTo(&packet->path[packet->path_len]);

uint32_t d = getRetransmitDelay(packet);
// as this propagates outwards, give it lower and lower priority
return ACTION_RETRANSMIT_DELAYED(packet->path_len, d); // give priority to closer sources, than ones further away
// lower priority as this propagates outward (closer sources forwarded first)
uint8_t default_priority = packet->path_len;
uint8_t priority = getForwardPriority(packet, default_priority);
return ACTION_RETRANSMIT_DELAYED(priority, d);
}
return ACTION_RELEASE;
}
Expand Down
8 changes: 8 additions & 0 deletions src/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ class Mesh : public Dispatcher {
*/
virtual uint8_t getExtraAckTransmitCount() const;

/**
* \brief Override to adjust packet forwarding priority
* \param packet packet being routed
* \param default_priority priority from base routing (lower = higher priority)
* \returns adjusted priority
*/
virtual uint8_t getForwardPriority(const Packet* packet, uint8_t default_priority);

/**
* \brief Perform search of local DB of peers/contacts.
* \returns Number of peers with matching hash
Expand Down