mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-01 23:50:38 +00:00
add airtime throttling
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
// I've done a lot of this in SQLite for now, but honestly it needs to happen in memory, and get saved to sqlite during downtime
|
||||
|
||||
// TODO: Message asking for the message x spots from the tip of the chain.
|
||||
// This would allow individual nodes to apt in, grab the latest fe messages, and not need to sync the entire chain
|
||||
|
||||
// TODO: add counter?
|
||||
|
||||
// TODO: Put some channel usage limits on this: Should be limited to 25% utilization, for instance
|
||||
|
||||
// TODO: custom hops. 1 maybe 0
|
||||
@@ -193,6 +198,7 @@ StoreForwardPlusPlusModule::StoreForwardPlusPlusModule()
|
||||
int32_t StoreForwardPlusPlusModule::runOnce()
|
||||
{
|
||||
LOG_WARN("StoreForward++ runONce");
|
||||
pendingRun = false;
|
||||
if (getRTCQuality() < RTCQualityNTP) {
|
||||
LOG_WARN("StoreForward++ deferred due to time quality %u", getRTCQuality());
|
||||
return 5 * 60 * 1000;
|
||||
@@ -226,13 +232,15 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac
|
||||
|
||||
if (t->sfpp_message_type == meshtastic_StoreForwardPlusPlus_SFPP_message_type_CANON_ANNOUNCE) {
|
||||
|
||||
// TODO: Regardless of where we are in the chain, if we have a newer message, send it back.
|
||||
if (portduino_config.sfpp_stratum0) {
|
||||
LOG_WARN("Received a CANON_ANNOUNCE while stratum 0");
|
||||
uint8_t next_commit_hash[32] = {0};
|
||||
if (getNextHash(t->root_hash.bytes, t->root_hash.size, t->commit_hash.bytes, t->commit_hash.size, next_commit_hash)) {
|
||||
printBytes("next chain hash: ", next_commit_hash, 32);
|
||||
|
||||
broadcastLink(next_commit_hash, 32);
|
||||
if (airTime->isTxAllowedChannelUtil(true)) {
|
||||
broadcastLink(next_commit_hash, 32);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uint8_t tmp_root_hash_bytes[32] = {0};
|
||||
@@ -279,11 +287,15 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac
|
||||
return true;
|
||||
}
|
||||
}
|
||||
requestNextMessage(t->root_hash.bytes, t->root_hash.size, last_message_commit_hash, 32);
|
||||
if (airTime->isTxAllowedChannelUtil(true)) {
|
||||
requestNextMessage(t->root_hash.bytes, t->root_hash.size, last_message_commit_hash, 32);
|
||||
}
|
||||
}
|
||||
} else { // if chainEnd()
|
||||
LOG_WARN("No Messages on this chain, request!");
|
||||
requestNextMessage(t->root_hash.bytes, t->root_hash.size, t->root_hash.bytes, t->root_hash.size);
|
||||
if (airTime->isTxAllowedChannelUtil(true)) {
|
||||
requestNextMessage(t->root_hash.bytes, t->root_hash.size, t->root_hash.bytes, t->root_hash.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (t->sfpp_message_type == meshtastic_StoreForwardPlusPlus_SFPP_message_type_LINK_REQUEST) {
|
||||
@@ -323,7 +335,10 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac
|
||||
|
||||
// calculate the commit_hash
|
||||
addToChain(incoming_link);
|
||||
setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain
|
||||
if (!pendingRun) {
|
||||
setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain
|
||||
pendingRun = true;
|
||||
}
|
||||
rebroadcastLinkObject(incoming_link);
|
||||
} else {
|
||||
addToChain(incoming_link);
|
||||
@@ -385,9 +400,10 @@ ProcessMessage StoreForwardPlusPlusModule::handleReceived(const meshtastic_MeshP
|
||||
}
|
||||
addToChain(lo);
|
||||
|
||||
// TODO: check if interval is already sooner?
|
||||
setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain
|
||||
|
||||
if (!pendingRun) {
|
||||
setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain
|
||||
pendingRun = true;
|
||||
}
|
||||
// canonAnnounce(lo.message_hash, lo.commit_hash, lo.root_hash, lo.rx_time);
|
||||
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
|
||||
} else if (mp.decoded.portnum == meshtastic_PortNum_STORE_FORWARD_PLUSPLUS_APP) {
|
||||
|
||||
@@ -126,6 +126,8 @@ class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForward
|
||||
|
||||
bool lookUpFullRootHash(uint8_t *partial_root_hash, size_t partial_root_hash_len, uint8_t *full_root_hash);
|
||||
|
||||
bool pendingRun = false;
|
||||
|
||||
enum chain_types {
|
||||
channel_chain = 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user