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

@@ -290,8 +290,7 @@ Bytes 7+: Message Text (UTF-8, variable length)
Byte 0: 0x3E
Byte 1: Data Type (`data_type`)
Byte 2: Channel Index (0-7)
Bytes 3-6: Timestamp (32-bit little-endian Unix timestamp, seconds)
Bytes 7+: Binary payload bytes (variable length)
Bytes 3+: Binary payload bytes (variable length)
```
**Data Type / Transport Mapping**:
@@ -299,8 +298,10 @@ Bytes 7+: Binary payload bytes (variable length)
- `0x00` is invalid for this command.
- Values other than `0xFF` are reserved for official protocol extensions.
**Note**: Applications that need a timestamp should encode it inside the binary payload.
**Limits**:
- Maximum payload length is `160` bytes.
- Maximum payload length is `166` bytes.
- Larger payloads are rejected with `PACKET_ERROR`.
**Response**: `PACKET_OK` (0x00) on success

View File

@@ -94,7 +94,7 @@
#define RESP_ALLOWED_REPEAT_FREQ 26
#define RESP_CODE_CHANNEL_DATA_RECV 27
#define MAX_CHANNEL_DATA_LENGTH (MAX_FRAME_SIZE - 12)
#define MAX_CHANNEL_DATA_LENGTH (MAX_FRAME_SIZE - 8)
#define SEND_TIMEOUT_BASE_MILLIS 500
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
@@ -569,7 +569,7 @@ void MyMesh::onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packe
#endif
}
void MyMesh::onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint32_t timestamp, uint8_t data_type,
void MyMesh::onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint8_t data_type,
const uint8_t *data, size_t data_len) {
if (data_len > MAX_CHANNEL_DATA_LENGTH) {
MESH_DEBUG_PRINTLN("onChannelDataRecv: dropping payload_len=%d exceeds frame limit=%d",
@@ -588,8 +588,6 @@ void MyMesh::onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *
out_frame[i++] = pkt->isRouteFlood() ? pkt->path_len : 0xFF;
out_frame[i++] = data_type;
out_frame[i++] = (uint8_t)data_len;
memcpy(&out_frame[i], &timestamp, 4);
i += 4;
int copy_len = (int)data_len;
if (copy_len > 0) {
@@ -1096,9 +1094,6 @@ void MyMesh::handleCmdFrame(size_t len) {
int i = 1;
uint8_t data_type = cmd_frame[i++];
uint8_t channel_idx = cmd_frame[i++];
uint32_t msg_timestamp;
memcpy(&msg_timestamp, &cmd_frame[i], 4);
i += 4;
const uint8_t *payload = &cmd_frame[i];
int payload_len = (len > (size_t)i) ? (int)(len - i) : 0;
@@ -1110,7 +1105,7 @@ void MyMesh::handleCmdFrame(size_t len) {
} else if (payload_len > MAX_CHANNEL_DATA_LENGTH) {
MESH_DEBUG_PRINTLN("CMD_SEND_CHANNEL_DATA payload too long: %d > %d", payload_len, MAX_CHANNEL_DATA_LENGTH);
writeErrFrame(ERR_CODE_ILLEGAL_ARG);
} else if (sendGroupData(msg_timestamp, channel.channel, data_type, payload, payload_len)) {
} else if (sendGroupData(channel.channel, data_type, payload, payload_len)) {
writeOKFrame();
} else {
writeErrFrame(ERR_CODE_TABLE_FULL);

View File

@@ -137,7 +137,7 @@ protected:
const uint8_t *sender_prefix, const char *text) override;
void onChannelMessageRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint32_t timestamp,
const char *text) override;
void onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint32_t timestamp, uint8_t data_type,
void onChannelDataRecv(const mesh::GroupChannel &channel, mesh::Packet *pkt, uint8_t data_type,
const uint8_t *data, size_t data_len) override;
uint8_t onContactRequest(const ContactInfo &contact, uint32_t sender_timestamp, const uint8_t *data,

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);