fix: Drop grp data timestamp

ref: #1928
This commit is contained in:
Janez T 2026-03-19 09:22:12 +01:00
parent 2fe3c36b8f
commit 1fb26e7623
7 changed files with 23 additions and 30 deletions

View file

@ -17,7 +17,7 @@
#define PATH_HASH_SIZE 1
#define MAX_PACKET_PAYLOAD 184
#define MAX_GROUP_DATA_LENGTH (MAX_PACKET_PAYLOAD - CIPHER_BLOCK_SIZE - 6)
#define MAX_GROUP_DATA_LENGTH (MAX_PACKET_PAYLOAD - CIPHER_BLOCK_SIZE - 2)
#define MAX_PATH_SIZE 64
#define MAX_TRANS_UNIT 255

View file

@ -22,7 +22,7 @@ namespace mesh {
#define PAYLOAD_TYPE_ACK 0x03 // a simple ack
#define PAYLOAD_TYPE_ADVERT 0x04 // a node advertising its Identity
#define PAYLOAD_TYPE_GRP_TXT 0x05 // an (unverified) group text message (prefixed with channel hash, MAC) (enc data: timestamp, "name: msg")
#define PAYLOAD_TYPE_GRP_DATA 0x06 // an (unverified) group datagram (prefixed with channel hash, MAC) (enc data: timestamp, data_type, data_len, blob)
#define PAYLOAD_TYPE_GRP_DATA 0x06 // an (unverified) group datagram (prefixed with channel hash, MAC) (enc data: data_type, data_len, blob)
#define PAYLOAD_TYPE_ANON_REQ 0x07 // generic request (prefixed with dest_hash, ephemeral pub_key, MAC) (enc data: ...)
#define PAYLOAD_TYPE_PATH 0x08 // returned path (prefixed with dest/src hashes, MAC) (enc data: path, extra)
#define PAYLOAD_TYPE_TRACE 0x09 // trace a path, collecting SNI for each hop

View file

@ -374,16 +374,14 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes
// notify UI of this new message
onChannelMessageRecv(channel, packet, timestamp, (const char *) &data[5]); // let UI know
} else if (type == PAYLOAD_TYPE_GRP_DATA) {
if (len < 6) {
if (len < 2) {
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping short group data payload len=%d", (uint32_t)len);
return;
}
uint32_t timestamp;
memcpy(&timestamp, data, 4);
uint8_t data_type = data[4];
uint8_t data_len = data[5];
size_t available_len = len - 6;
uint8_t data_type = data[0];
uint8_t data_len = data[1];
size_t available_len = len - 2;
if (data_len > available_len) {
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping malformed group data type=%d len=%d available=%d",
@ -391,7 +389,7 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes
return;
}
onChannelDataRecv(channel, packet, timestamp, data_type, &data[6], data_len);
onChannelDataRecv(channel, packet, data_type, &data[2], data_len);
}
}
@ -483,7 +481,7 @@ bool BaseChatMesh::sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& chan
return false;
}
bool BaseChatMesh::sendGroupData(uint32_t timestamp, mesh::GroupChannel& channel, uint8_t data_type, const uint8_t* data, int data_len) {
bool BaseChatMesh::sendGroupData(mesh::GroupChannel& channel, uint8_t data_type, const uint8_t* data, int data_len) {
if (data_len < 0) {
MESH_DEBUG_PRINTLN("sendGroupData: invalid negative data_len=%d", data_len);
return false;
@ -493,13 +491,12 @@ bool BaseChatMesh::sendGroupData(uint32_t timestamp, mesh::GroupChannel& channel
return false;
}
uint8_t temp[6 + MAX_GROUP_DATA_LENGTH];
memcpy(temp, &timestamp, 4);
temp[4] = data_type;
temp[5] = (uint8_t)data_len;
if (data_len > 0) memcpy(&temp[6], data, data_len);
uint8_t temp[2 + MAX_GROUP_DATA_LENGTH];
temp[0] = data_type;
temp[1] = (uint8_t)data_len;
if (data_len > 0) memcpy(&temp[2], data, data_len);
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_DATA, channel, temp, 6 + data_len);
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_DATA, channel, temp, 2 + data_len);
if (pkt == NULL) {
MESH_DEBUG_PRINTLN("sendGroupData: unable to create group datagram, data_len=%d", data_len);
return false;

View file

@ -111,7 +111,7 @@ protected:
virtual uint32_t calcDirectTimeoutMillisFor(uint32_t pkt_airtime_millis, uint8_t path_len) const = 0;
virtual void onSendTimeout() = 0;
virtual void onChannelMessageRecv(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t timestamp, const char *text) = 0;
virtual void onChannelDataRecv(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint32_t timestamp, uint8_t data_type,
virtual void onChannelDataRecv(const mesh::GroupChannel& channel, mesh::Packet* pkt, uint8_t data_type,
const uint8_t* data, size_t data_len) {}
virtual uint8_t onContactRequest(const ContactInfo& contact, uint32_t sender_timestamp, const uint8_t* data, uint8_t len, uint8_t* reply) = 0;
virtual void onContactResponse(const ContactInfo& contact, const uint8_t* data, uint8_t len) = 0;
@ -150,7 +150,7 @@ public:
int sendMessage(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& expected_ack, uint32_t& est_timeout);
int sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout);
bool sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& channel, const char* sender_name, const char* text, int text_len);
bool sendGroupData(uint32_t timestamp, mesh::GroupChannel& channel, uint8_t data_type, const uint8_t* data, int data_len);
bool sendGroupData(mesh::GroupChannel& channel, uint8_t data_type, const uint8_t* data, int data_len);
int sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout);
int sendAnonReq(const ContactInfo& recipient, const uint8_t* data, uint8_t len, uint32_t& tag, uint32_t& est_timeout);
int sendRequest(const ContactInfo& recipient, uint8_t req_type, uint32_t& tag, uint32_t& est_timeout);