mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-28 06:45:15 +00:00
+1
-1
@@ -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 - 5)
|
||||
#define MAX_GROUP_DATA_LENGTH (MAX_PACKET_PAYLOAD - CIPHER_BLOCK_SIZE - 6)
|
||||
#define MAX_PATH_SIZE 64
|
||||
#define MAX_TRANS_UNIT 255
|
||||
|
||||
|
||||
+1
-1
@@ -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, blob)
|
||||
#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_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
|
||||
|
||||
@@ -353,15 +353,15 @@ int BaseChatMesh::searchChannelsByHash(const uint8_t* hash, mesh::GroupChannel d
|
||||
#endif
|
||||
|
||||
void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::GroupChannel& channel, uint8_t* data, size_t len) {
|
||||
if (len < 5) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping short group payload len=%d", (uint32_t)len);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t data_type = data[4];
|
||||
if (type == PAYLOAD_TYPE_GRP_TXT) {
|
||||
if ((data_type >> 2) != 0) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping unsupported group text type=%d", (uint32_t)data_type);
|
||||
if (len < 5) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping short group text payload len=%d", (uint32_t)len);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t txt_type = data[4];
|
||||
if ((txt_type >> 2) != 0) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping unsupported group text type=%d", (uint32_t)txt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -374,9 +374,24 @@ 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) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping short group data payload len=%d", (uint32_t)len);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t timestamp;
|
||||
memcpy(×tamp, data, 4);
|
||||
onChannelDataRecv(channel, packet, timestamp, data_type, &data[5], len - 5);
|
||||
uint8_t data_type = data[4];
|
||||
uint8_t data_len = data[5];
|
||||
size_t available_len = len - 6;
|
||||
|
||||
if (data_len > available_len) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping malformed group data type=%d len=%d available=%d",
|
||||
(uint32_t)data_type, (uint32_t)data_len, (uint32_t)available_len);
|
||||
return;
|
||||
}
|
||||
|
||||
onChannelDataRecv(channel, packet, timestamp, data_type, &data[6], data_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,12 +493,13 @@ bool BaseChatMesh::sendGroupData(uint32_t timestamp, mesh::GroupChannel& channel
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t temp[5 + MAX_GROUP_DATA_LENGTH];
|
||||
uint8_t temp[6 + MAX_GROUP_DATA_LENGTH];
|
||||
memcpy(temp, ×tamp, 4);
|
||||
temp[4] = data_type;
|
||||
if (data_len > 0) memcpy(&temp[5], data, data_len);
|
||||
temp[5] = (uint8_t)data_len;
|
||||
if (data_len > 0) memcpy(&temp[6], data, data_len);
|
||||
|
||||
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_DATA, channel, temp, 5 + data_len);
|
||||
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_DATA, channel, temp, 6 + data_len);
|
||||
if (pkt == NULL) {
|
||||
MESH_DEBUG_PRINTLN("sendGroupData: unable to create group datagram, data_len=%d", data_len);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user