more goodies

This commit is contained in:
Jonathan Bennett
2025-12-15 11:41:35 -06:00
parent a184885023
commit d2661974f6
2 changed files with 45 additions and 3 deletions

View File

@@ -147,6 +147,10 @@ StoreForwardPlusPlusModule::StoreForwardPlusPlusModule()
sqlite3_prepare_v2(ppDb, "DELETE from local_messages where message_hash=?", -1, &removeScratch, NULL);
sqlite3_prepare_v2(ppDb, "UPDATE channel_messages SET payload=? WHERE message_hash=?", -1, &updatePayloadStmt, NULL);
sqlite3_prepare_v2(ppDb, "SELECT payload from local_messages WHERE message_hash=?", -1, &getPayloadFromScratchStmt, NULL);
encryptedOk = true;
// wait about 15 seconds after boot for the first runOnce()
@@ -259,8 +263,14 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac
addToChain(t->encapsulated_to, t->encapsulated_from, t->encapsulated_id, false, _channel_hash, t->message.bytes,
t->message.size, t->message_hash.bytes, t->chain_hash.bytes, t->root_hash.bytes, t->encapsulated_rxtime,
"", 0);
if (isInScratch(t->message_hash.bytes))
if (isInScratch(t->message_hash.bytes)) {
// TODO: Copy payload from scratch into chain
std::string payloadFromScratch = getPayloadFromScratch(t->message_hash.bytes);
if (payloadFromScratch != "") {
updatePayload(t->message_hash.bytes, payloadFromScratch.c_str(), payloadFromScratch.size());
}
removeFromScratch(t->message_hash.bytes);
}
requestNextMessage(t->root_hash.bytes, t->chain_hash.bytes);
// check for message hash in scratch
@@ -363,7 +373,8 @@ ProcessMessage StoreForwardPlusPlusModule::handleReceived(const meshtastic_MeshP
router->p_encrypted->encrypted.size, message_hash_bytes, chain_hash_bytes, root_hash_bytes, mp.rx_time,
(char *)mp.decoded.payload.bytes, mp.decoded.payload.size);
// TODO: If under 25% usage, go ahead and trigger a canon announce
// TODO: Limit to 25% bandwidth
canonAnnounce(message_hash_bytes, chain_hash_bytes, root_hash_bytes);
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
@@ -627,6 +638,7 @@ bool StoreForwardPlusPlusModule::addToChain(uint32_t to, uint32_t from, uint32_t
size_t payload_len)
{
LOG_WARN("Add to chain");
// TODO: Make a data structure for this data
// push a message into the local chain DB
@@ -753,6 +765,30 @@ void StoreForwardPlusPlusModule::removeFromScratch(uint8_t *message_hash_bytes)
sqlite3_reset(removeScratch);
}
void StoreForwardPlusPlusModule::updatePayload(uint8_t *message_hash_bytes, const char *payload_bytes, size_t payload_len)
{
LOG_WARN("updatePayload");
sqlite3_bind_text(updatePayloadStmt, 1, payload_bytes, payload_len, NULL);
sqlite3_bind_blob(updatePayloadStmt, 2, message_hash_bytes, 32, NULL);
auto res = sqlite3_step(updatePayloadStmt);
const char *_error_mesg = sqlite3_errmsg(ppDb);
LOG_WARN("step %u, %s", res, _error_mesg);
sqlite3_reset(updatePayloadStmt);
}
std::string StoreForwardPlusPlusModule::getPayloadFromScratch(uint8_t *message_hash_bytes)
{
LOG_WARN("getPayloadFromScratch");
sqlite3_bind_blob(getPayloadFromScratchStmt, 2, message_hash_bytes, 32, NULL);
auto res = sqlite3_step(getPayloadFromScratchStmt);
const char *_error_mesg = sqlite3_errmsg(ppDb);
LOG_WARN("step %u, %s", res, _error_mesg);
const char *tmp_text = (char *)sqlite3_column_text(getPayloadFromScratchStmt, 0);
size_t payload_len = sqlite3_column_bytes(getPayloadFromScratchStmt, 0);
std::string tmp_string(tmp_text, payload_len);
return tmp_string;
}
// announce latest hash
// chain_end_announce

View File

@@ -49,6 +49,8 @@ class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForward
sqlite3_stmt *checkDup;
sqlite3_stmt *checkScratch;
sqlite3_stmt *removeScratch;
sqlite3_stmt *updatePayloadStmt;
sqlite3_stmt *getPayloadFromScratchStmt;
// returns wasfound
bool getRootFromChannelHash(ChannelHash, uint8_t *);
@@ -67,7 +69,7 @@ class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForward
void requestNextMessage(uint8_t *, uint8_t *);
bool broadcastLink(uint8_t *_chain_hash, uint8_t *_root_hash);
bool broadcastLink(uint8_t *, uint8_t *);
bool addToChain(uint32_t, uint32_t, uint32_t, bool, ChannelHash, uint8_t *, size_t, uint8_t *, uint8_t *, uint8_t *, uint32_t,
char *, size_t);
@@ -81,6 +83,10 @@ class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForward
void removeFromScratch(uint8_t *);
void updatePayload(uint8_t *, const char *, size_t);
std::string getPayloadFromScratch(uint8_t *);
enum chain_types {
channel_chain = 0,
};