diff --git a/src/modules/Native/StoreForwardPlusPlus.cpp b/src/modules/Native/StoreForwardPlusPlus.cpp index f70544049..3cd635c03 100644 --- a/src/modules/Native/StoreForwardPlusPlus.cpp +++ b/src/modules/Native/StoreForwardPlusPlus.cpp @@ -6,7 +6,9 @@ // TODO: non-stratum0 nodes need to be pointed at their upstream source? Maybe -// TODO: Work without sending some of the hashes/ short hashes +// TODO: trickle syncing when the mesh is busy + +// TODO: There will come a point where the chain is too big to sync // things may get weird if there are multiple stratum-0 nodes on a single mesh. Come up with mitigations @@ -132,7 +134,6 @@ StoreForwardPlusPlusModule::StoreForwardPlusPlusModule() // store schema version somewhere - // TODO: Move all the statements here, and make sure all the hashes are WHERE substr() // prepared statements *should* make this faster. sqlite3_prepare_v2(ppDb, "INSERT INTO channel_messages (destination, sender, packet_id, root_hash, \ encrypted_bytes, message_hash, rx_time, commit_hash, payload) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);", @@ -228,7 +229,6 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac if (portduino_config.sfpp_stratum0) { LOG_WARN("Received a CANON_ANNOUNCE while stratum 0"); uint8_t next_commit_hash[32] = {0}; - // TODO: check hash sizes 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); @@ -261,7 +261,6 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac if (memcmp(last_message_commit_hash, t->commit_hash.bytes, t->commit_hash.size) == 0) { LOG_WARN("End of chain matches!"); sendFromScratch(router->p_encrypted->channel); - // TODO: Send a message from the local queue } else { ("End of chain does not match!"); @@ -291,7 +290,6 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac uint8_t next_commit_hash[32] = {0}; LOG_WARN("Received link request"); - // TODO: sizes 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); @@ -304,7 +302,6 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac } else if (t->sfpp_message_type == meshtastic_StoreForwardPlusPlus_SFPP_message_type_LINK_PROVIDE) { LOG_WARN("Link Provide received!"); - // TODO: Check for root hash in mappings link_object incoming_link = ingestLinkMessage(t); if (incoming_link.root_hash_len == 0) { @@ -321,12 +318,12 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac if (isInDB(incoming_link.message_hash, incoming_link.message_hash_len)) { LOG_WARN("Received link already in chain"); // TODO: respond with next link? + return true; } // calculate the commit_hash addToChain(incoming_link); - // not super thrilled about doing two broadcasts. Maybe just schedule the canonAnnounce? - canonAnnounce(incoming_link.message_hash, incoming_link.commit_hash, incoming_link.root_hash, incoming_link.rx_time); + setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain rebroadcastLinkObject(incoming_link); } else { addToChain(incoming_link); @@ -388,8 +385,10 @@ ProcessMessage StoreForwardPlusPlusModule::handleReceived(const meshtastic_MeshP } addToChain(lo); - // TODO: Limit to 25% bandwidth - canonAnnounce(lo.message_hash, lo.commit_hash, lo.root_hash, lo.rx_time); + // TODO: check if interval is already sooner? + setIntervalFromNow(60 * 1000); // run again in 60 seconds to announce the new tip of chain + + // 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) { LOG_WARN("Got a STORE_FORWARD++ packet"); @@ -722,8 +721,6 @@ bool StoreForwardPlusPlusModule::addToChain(link_object &lo) bool StoreForwardPlusPlusModule::addToScratch(link_object &lo) { - // TODO: Make a data structure for this data - // push a message into the local chain DB // destination sqlite3_bind_int(scratch_insert_stmt, 1, lo.to); @@ -881,7 +878,6 @@ StoreForwardPlusPlusModule::ingestTextPacket(const meshtastic_MeshPacket &mp, co return lo; } -// TODO: the hashes in this message may be short, need to handle that StoreForwardPlusPlusModule::link_object StoreForwardPlusPlusModule::ingestLinkMessage(meshtastic_StoreForwardPlusPlus *t) { link_object lo; @@ -906,8 +902,6 @@ StoreForwardPlusPlusModule::link_object StoreForwardPlusPlusModule::ingestLinkMe message_hash.finalize(lo.message_hash, 32); lo.message_hash_len = 32; - // TODO: recalculate these - // look up full root hash and copy over the partial if it matches if (lookUpFullRootHash(t->root_hash.bytes, t->root_hash.size, lo.root_hash)) { printBytes("Found full root hash: 0x", lo.root_hash, 32);