This commit is contained in:
Jonathan Bennett
2025-12-14 21:54:51 -06:00
parent 4552efce81
commit f10d2fb8c2
2 changed files with 46 additions and 24 deletions

View File

@@ -230,6 +230,11 @@ bool StoreForwardPlusPlusModule::handleReceivedProtobuf(const meshtastic_MeshPac
} else if (t->sfpp_message_type == meshtastic_StoreForwardPlusPlus_SFPP_message_type_LINK_PROVIDE) {
LOG_WARN("Link Provide received!");
ChannelHash _channel_hash = getChannelHashFromRoot(t->root_hash.bytes);
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);
}
return true;
@@ -314,31 +319,10 @@ ProcessMessage StoreForwardPlusPlusModule::handleReceived(const meshtastic_MeshP
// select HEX(commit_hash),HEX(channel_hash), payload, destination from channel_messages order by rowid desc;
// push a message into the local chain DB
// destination
sqlite3_bind_int(stmt, 1, mp.to);
// sender
sqlite3_bind_int(stmt, 2, mp.from);
// packet_id
sqlite3_bind_int(stmt, 3, mp.id);
// want_ack
sqlite3_bind_int(stmt, 4, mp.want_ack);
// channel_hash
sqlite3_bind_int(stmt, 5, router->p_encrypted->channel);
// encrypted_bytes
sqlite3_bind_blob(stmt, 6, router->p_encrypted->encrypted.bytes, router->p_encrypted->encrypted.size, NULL);
// message_hash
sqlite3_bind_blob(stmt, 7, message_hash_bytes, 32, NULL);
// rx_time
sqlite3_bind_int(stmt, 8, mp.rx_time);
// commit_hash
sqlite3_bind_blob(stmt, 9, chain_hash_bytes, 32, NULL);
// payload
sqlite3_bind_text(stmt, 10, (char *)mp.decoded.payload.bytes, mp.decoded.payload.size, NULL);
sqlite3_step(stmt);
sqlite3_reset(stmt);
addToChain(mp.to, mp.from, mp.id, mp.want_ack, router->p_encrypted->channel, router->p_encrypted->encrypted.bytes,
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);
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
@@ -572,6 +556,41 @@ bool StoreForwardPlusPlusModule::broadcastLink(uint8_t *_chain_hash, uint8_t *_r
return true;
}
bool StoreForwardPlusPlusModule::addToChain(uint32_t to, uint32_t from, uint32_t id, bool want_ack, ChannelHash channel_hash,
uint8_t *encrypted_bytes, size_t encrypted_len, uint8_t *_message_hash,
uint8_t *_chain_hash, uint8_t *_root_hash, uint32_t _rx_time, char *payload_bytes,
size_t payload_len)
{
// push a message into the local chain DB
// destination
sqlite3_bind_int(stmt, 1, to);
// sender
sqlite3_bind_int(stmt, 2, from);
// packet_id
sqlite3_bind_int(stmt, 3, id);
// want_ack
sqlite3_bind_int(stmt, 4, want_ack);
// channel_hash
sqlite3_bind_int(stmt, 5, channel_hash);
// encrypted_bytes
sqlite3_bind_blob(stmt, 6, encrypted_bytes, encrypted_len, NULL);
// message_hash
sqlite3_bind_blob(stmt, 7, _message_hash, 32, NULL);
// rx_time
sqlite3_bind_int(stmt, 8, _rx_time);
// commit_hash
sqlite3_bind_blob(stmt, 9, _chain_hash, 32, NULL);
// payload
sqlite3_bind_text(stmt, 10, payload_bytes, payload_len, NULL);
sqlite3_step(stmt);
sqlite3_reset(stmt);
return true;
}
// announce latest hash
// chain_end_announce

View File

@@ -65,6 +65,9 @@ class StoreForwardPlusPlusModule : public ProtobufModule<meshtastic_StoreForward
bool broadcastLink(uint8_t *_chain_hash, uint8_t *_root_hash);
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);
enum chain_types {
channel_chain = 0,
};