From 8c3766921378dc57870c12994c211a8ebc95a308 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 3 Jan 2026 20:59:41 -0600 Subject: [PATCH] Check links behind when receiving a link --- src/modules/Native/StoreForwardPlusPlus.cpp | 24 ++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/modules/Native/StoreForwardPlusPlus.cpp b/src/modules/Native/StoreForwardPlusPlus.cpp index 52b193c24..5ae69a51d 100644 --- a/src/modules/Native/StoreForwardPlusPlus.cpp +++ b/src/modules/Native/StoreForwardPlusPlus.cpp @@ -403,6 +403,11 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac link_object incoming_link; incoming_link.validObject = false; + link_object chain_end; + + // get tip of chain for this channel + if (t->root_hash.size >= SFPP_SHORT_HASH_SIZE) + chain_end = getLinkFromCount(0, t->root_hash.bytes, t->root_hash.size); updatePeers(mp, t->sfpp_message_type); @@ -436,9 +441,6 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac return true; } - // get tip of chain for this channel - link_object chain_end = getLinkFromCount(0, t->root_hash.bytes, t->root_hash.size); - if (chain_end.rx_time != 0) { if (t->commit_hash.size >= SFPP_SHORT_HASH_SIZE && memcmp(chain_end.commit_hash, t->commit_hash.bytes, t->commit_hash.size) == 0) { @@ -620,7 +622,7 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac // if this packet is new to us, we rebroadcast it rebroadcastLinkObject(incoming_link); } else { - LOG_DEBUG("StoreForwardpp Got previously unseen text, but not rebroadcasting because rxtime was &u", + LOG_DEBUG("StoreForwardpp Got previously unseen text, but not rebroadcasting because rxtime was %u", incoming_link.rx_time); } @@ -638,10 +640,22 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac if (incoming_link.rx_time > getValidTime(RTCQuality::RTCQualityNTP, true) - rebroadcastTimeout) { rebroadcastLinkObject(incoming_link); } else { - LOG_DEBUG("StoreForwardpp Got previously unseen text, but not rebroadcasting because rxtime was &u", + LOG_DEBUG("StoreForwardpp Got previously unseen text, but not rebroadcasting because rxtime was %u", incoming_link.rx_time); } } + if (chain_end.rx_time != 0) { + int64_t links_behind = 0; + if (t->chain_count != 0) { + links_behind = t->chain_count - chain_end.counter; + } + LOG_DEBUG("StoreForwardpp Links behind: %ld", links_behind); + if (links_behind > portduino_config.sfpp_backlog_limit) { + LOG_INFO("StoreForwardpp Chain behind limit, dumping DB"); + clearChain(t->root_hash.bytes, t->root_hash.size); + return true; + } + } requestNextMessage(incoming_link.root_hash, incoming_link.root_hash_len, incoming_link.commit_hash, incoming_link.commit_hash_len); } else {