mirror of
https://github.com/meshtastic/firmware.git
synced 2026-11-07 23:04:49 -05:00
Drop the BLE advertisement peer table, which nothing read
ESP32BLEMesh and NRF52BLEMesh each kept peers[] and peerCount, updated on every heard burst and pruned on a five-minute timeout, and nothing read them on either platform beyond a debug line counting new entries. Routing and dedup never consult it: the advertisement bearer is connectionless and keys nothing on the sender's address. The table, updatePeer(), pruneStale(), BLE_MESH_MAX_PEERS and BLE_MESH_PEER_TIMEOUT_MS go, and so does the scan address the ESP32 handler passed along only to fill it.
This commit is contained in:
1 parent
7126ee65a5
commit
f87dcdbe5c
4 files changed
+4
-130
No files matched your search
@@ -24,8 +24,6 @@ void ESP32BLEMesh::start()
|
||||
return;
|
||||
}
|
||||
|
||||
memset(peers, 0, sizeof(peers));
|
||||
peerCount = 0;
|
||||
isRunning = true;
|
||||
LOG_INFO("BLE mesh started (waiting for Bluetooth ready)");
|
||||
}
|
||||
@@ -250,7 +248,7 @@ void ESP32BLEMesh::handleAdvertisement(const struct ble_gap_disc_desc *desc)
|
||||
if (!isRunning || !desc)
|
||||
return;
|
||||
|
||||
handleAdvertisementData(desc->addr, desc->rssi, desc->data, desc->length_data);
|
||||
handleAdvertisementData(desc->rssi, desc->data, desc->length_data);
|
||||
}
|
||||
|
||||
#if BLE_MESH_USE_EXT_ADV
|
||||
@@ -263,11 +261,11 @@ void ESP32BLEMesh::handleExtendedAdvertisement(const struct ble_gap_ext_disc_des
|
||||
if (desc->data_status != BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE || !desc->data)
|
||||
return;
|
||||
|
||||
handleAdvertisementData(desc->addr, desc->rssi, desc->data, desc->length_data);
|
||||
handleAdvertisementData(desc->rssi, desc->data, desc->length_data);
|
||||
}
|
||||
#endif
|
||||
|
||||
void ESP32BLEMesh::handleAdvertisementData(const ble_addr_t &addr, int8_t rssi, const uint8_t *data, uint8_t len)
|
||||
void ESP32BLEMesh::handleAdvertisementData(int8_t rssi, const uint8_t *data, uint8_t len)
|
||||
{
|
||||
if (!isRunning || !data)
|
||||
return;
|
||||
@@ -288,7 +286,6 @@ void ESP32BLEMesh::handleAdvertisementData(const ble_addr_t &addr, int8_t rssi,
|
||||
const uint8_t *payload = &data[offset + 5];
|
||||
size_t payloadLen = adLen - 4;
|
||||
|
||||
updatePeer(addr, rssi);
|
||||
deliverToRouter(payload, payloadLen, rssi);
|
||||
return;
|
||||
}
|
||||
@@ -297,44 +294,4 @@ void ESP32BLEMesh::handleAdvertisementData(const ble_addr_t &addr, int8_t rssi,
|
||||
}
|
||||
}
|
||||
|
||||
void ESP32BLEMesh::updatePeer(const ble_addr_t &addr, int8_t rssi)
|
||||
{
|
||||
uint32_t now = millis();
|
||||
|
||||
for (uint8_t i = 0; i < peerCount; i++) {
|
||||
if (memcmp(&peers[i].addr, &addr, sizeof(ble_addr_t)) == 0) {
|
||||
peers[i].rssi = rssi;
|
||||
peers[i].lastSeenMs = now;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (peerCount >= BLE_MESH_MAX_PEERS)
|
||||
pruneStale();
|
||||
|
||||
if (peerCount < BLE_MESH_MAX_PEERS) {
|
||||
peers[peerCount].addr = addr;
|
||||
peers[peerCount].rssi = rssi;
|
||||
peers[peerCount].lastSeenMs = now;
|
||||
peers[peerCount].nodeNum = 0;
|
||||
peerCount++;
|
||||
LOG_DEBUG("BLE mesh new peer (%u total)", peerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void ESP32BLEMesh::pruneStale()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
uint8_t writeIdx = 0;
|
||||
|
||||
for (uint8_t i = 0; i < peerCount; i++) {
|
||||
if (now - peers[i].lastSeenMs < BLE_MESH_PEER_TIMEOUT_MS) {
|
||||
if (writeIdx != i)
|
||||
peers[writeIdx] = peers[i];
|
||||
writeIdx++;
|
||||
}
|
||||
}
|
||||
peerCount = writeIdx;
|
||||
}
|
||||
|
||||
#endif // HAS_BLE_MESH && ARCH_ESP32
|
||||
@@ -7,10 +7,6 @@
|
||||
// NimBLE comes from the ESP-IDF component, so the host headers are on the include path directly.
|
||||
#include "host/ble_gap.h"
|
||||
|
||||
#ifndef BLE_MESH_MAX_PEERS
|
||||
#define BLE_MESH_MAX_PEERS 8
|
||||
#endif
|
||||
|
||||
// Units of 0.625ms. Window equals interval: a sender emits only BLE_MESH_ADV_EVENTS repeats and
|
||||
// nothing retransmits until heard, so a gap in the duty cycle can only lose frames.
|
||||
#ifndef BLE_MESH_SCAN_INTERVAL
|
||||
@@ -30,10 +26,6 @@
|
||||
#define BLE_MESH_ADV_INSTANCE 1
|
||||
#endif
|
||||
|
||||
#ifndef BLE_MESH_PEER_TIMEOUT_MS
|
||||
#define BLE_MESH_PEER_TIMEOUT_MS 300000 // 5 minutes
|
||||
#endif
|
||||
|
||||
class ESP32BLEMesh : public BLEMeshHandler
|
||||
{
|
||||
public:
|
||||
@@ -58,19 +50,7 @@ class ESP32BLEMesh : public BLEMeshHandler
|
||||
bool configureAdvInstance();
|
||||
bool advInstanceConfigured = false;
|
||||
#endif
|
||||
void handleAdvertisementData(const ble_addr_t &addr, int8_t rssi, const uint8_t *data, uint8_t len);
|
||||
|
||||
// Peer tracking
|
||||
struct BLEMeshPeer {
|
||||
NodeNum nodeNum;
|
||||
ble_addr_t addr;
|
||||
int8_t rssi;
|
||||
uint32_t lastSeenMs;
|
||||
};
|
||||
BLEMeshPeer peers[BLE_MESH_MAX_PEERS];
|
||||
uint8_t peerCount = 0;
|
||||
void updatePeer(const ble_addr_t &addr, int8_t rssi);
|
||||
void pruneStale();
|
||||
void handleAdvertisementData(int8_t rssi, const uint8_t *data, uint8_t len);
|
||||
};
|
||||
|
||||
#endif // HAS_BLE_MESH && ARCH_ESP32
|
||||
@@ -35,8 +35,6 @@ void NRF52BLEMesh::start()
|
||||
}
|
||||
|
||||
instance = this;
|
||||
memset(peers, 0, sizeof(peers));
|
||||
peerCount = 0;
|
||||
isRunning = true;
|
||||
LOG_INFO("BLE mesh started (waiting for Bluetooth ready)");
|
||||
}
|
||||
@@ -248,7 +246,6 @@ void NRF52BLEMesh::handleScanResult(ble_gap_evt_adv_report_t *report)
|
||||
const uint8_t *payload = &data[offset + 5];
|
||||
size_t payloadLen = adLen - 4;
|
||||
|
||||
updatePeer(report->peer_addr, report->rssi);
|
||||
deliverToRouter(payload, payloadLen, report->rssi);
|
||||
return;
|
||||
}
|
||||
@@ -257,44 +254,4 @@ void NRF52BLEMesh::handleScanResult(ble_gap_evt_adv_report_t *report)
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52BLEMesh::updatePeer(const ble_gap_addr_t &addr, int8_t rssi)
|
||||
{
|
||||
uint32_t now = millis();
|
||||
|
||||
for (uint8_t i = 0; i < peerCount; i++) {
|
||||
if (memcmp(&peers[i].addr, &addr, sizeof(ble_gap_addr_t)) == 0) {
|
||||
peers[i].rssi = rssi;
|
||||
peers[i].lastSeenMs = now;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (peerCount >= BLE_MESH_MAX_PEERS)
|
||||
pruneStale();
|
||||
|
||||
if (peerCount < BLE_MESH_MAX_PEERS) {
|
||||
peers[peerCount].addr = addr;
|
||||
peers[peerCount].rssi = rssi;
|
||||
peers[peerCount].lastSeenMs = now;
|
||||
peers[peerCount].nodeNum = 0; // unknown until a packet from them decodes
|
||||
peerCount++;
|
||||
LOG_DEBUG("BLE mesh new peer (%u total)", peerCount);
|
||||
}
|
||||
}
|
||||
|
||||
void NRF52BLEMesh::pruneStale()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
uint8_t writeIdx = 0;
|
||||
|
||||
for (uint8_t i = 0; i < peerCount; i++) {
|
||||
if (now - peers[i].lastSeenMs < BLE_MESH_PEER_TIMEOUT_MS) {
|
||||
if (writeIdx != i)
|
||||
peers[writeIdx] = peers[i];
|
||||
writeIdx++;
|
||||
}
|
||||
}
|
||||
peerCount = writeIdx;
|
||||
}
|
||||
|
||||
#endif // HAS_BLE_MESH && ARCH_NRF52
|
||||
@@ -5,10 +5,6 @@
|
||||
#include "mesh/BLEMeshHandler.h"
|
||||
#include <bluefruit.h>
|
||||
|
||||
#ifndef BLE_MESH_MAX_PEERS
|
||||
#define BLE_MESH_MAX_PEERS 8
|
||||
#endif
|
||||
|
||||
// Units of 0.625ms. Window equals interval: continuous, as on ESP32.
|
||||
#ifndef BLE_MESH_SCAN_INTERVAL
|
||||
#define BLE_MESH_SCAN_INTERVAL 160 // 100ms
|
||||
@@ -21,10 +17,6 @@
|
||||
#define BLE_MESH_ADV_INTERVAL 48 // 30ms in units of 0.625ms
|
||||
#endif
|
||||
|
||||
#ifndef BLE_MESH_PEER_TIMEOUT_MS
|
||||
#define BLE_MESH_PEER_TIMEOUT_MS 300000 // 5 minutes
|
||||
#endif
|
||||
|
||||
class NRF52BLEMesh : public BLEMeshHandler
|
||||
{
|
||||
public:
|
||||
@@ -45,15 +37,6 @@ class NRF52BLEMesh : public BLEMeshHandler
|
||||
void stopScanning();
|
||||
void handleScanResult(ble_gap_evt_adv_report_t *report);
|
||||
|
||||
struct BLEMeshPeer {
|
||||
NodeNum nodeNum;
|
||||
ble_gap_addr_t addr;
|
||||
int8_t rssi;
|
||||
uint32_t lastSeenMs;
|
||||
};
|
||||
BLEMeshPeer peers[BLE_MESH_MAX_PEERS];
|
||||
uint8_t peerCount = 0;
|
||||
|
||||
// A SoftDevice advertising set of its own, allocated by passing BLE_GAP_ADV_SET_HANDLE_NOT_SET.
|
||||
// Handle 0 is Bluefruit's phone advertisement; sharing it means tearing that down and restoring
|
||||
// it around every frame, which is the fallback when the SoftDevice has no spare set.
|
||||
@@ -66,9 +49,6 @@ class NRF52BLEMesh : public BLEMeshHandler
|
||||
uint8_t advBuf[BLE_MESH_ADV_TOTAL_MAX];
|
||||
uint8_t advBufLen = 0;
|
||||
|
||||
void updatePeer(const ble_gap_addr_t &addr, int8_t rssi);
|
||||
void pruneStale();
|
||||
|
||||
static NRF52BLEMesh *instance;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user