mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge pull request #1928 from dz0ny/feat/grp-data-upstream
feat: Add support for PAYLOAD_TYPE_GRP_DATA
This commit is contained in:
commit
91aed048e9
9 changed files with 161 additions and 10 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#define PATH_HASH_SIZE 1
|
||||
|
||||
#define MAX_PACKET_PAYLOAD 184
|
||||
#define MAX_GROUP_DATA_LENGTH (MAX_PACKET_PAYLOAD - CIPHER_BLOCK_SIZE - 3)
|
||||
#define MAX_PATH_SIZE 64
|
||||
#define MAX_TRANS_UNIT 255
|
||||
|
||||
|
|
@ -100,4 +101,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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: data_type(uint16), 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,8 +353,18 @@ 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) {
|
||||
uint8_t txt_type = data[4];
|
||||
if (type == PAYLOAD_TYPE_GRP_TXT && len > 5 && (txt_type >> 2) == 0) { // 0 = plain text msg
|
||||
if (type == PAYLOAD_TYPE_GRP_TXT) {
|
||||
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;
|
||||
}
|
||||
|
||||
uint32_t timestamp;
|
||||
memcpy(×tamp, data, 4);
|
||||
|
||||
|
|
@ -363,6 +373,23 @@ 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 < 3) {
|
||||
MESH_DEBUG_PRINTLN("onGroupDataRecv: dropping short group data payload len=%d", (uint32_t)len);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t data_type = ((uint16_t)data[0]) | (((uint16_t)data[1]) << 8);
|
||||
uint8_t data_len = data[2];
|
||||
size_t available_len = len - 3;
|
||||
|
||||
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, data_type, &data[3], data_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -454,6 +481,31 @@ bool BaseChatMesh::sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& chan
|
|||
return false;
|
||||
}
|
||||
|
||||
bool BaseChatMesh::sendGroupData(mesh::GroupChannel& channel, uint16_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;
|
||||
}
|
||||
if (data_len > MAX_GROUP_DATA_LENGTH) {
|
||||
MESH_DEBUG_PRINTLN("sendGroupData: data_len=%d exceeds max=%d", data_len, MAX_GROUP_DATA_LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t temp[3 + MAX_GROUP_DATA_LENGTH];
|
||||
temp[0] = (uint8_t)(data_type & 0xFF);
|
||||
temp[1] = (uint8_t)(data_type >> 8);
|
||||
temp[2] = (uint8_t)data_len;
|
||||
if (data_len > 0) memcpy(&temp[3], data, data_len);
|
||||
|
||||
auto pkt = createGroupDatagram(PAYLOAD_TYPE_GRP_DATA, channel, temp, 3 + data_len);
|
||||
if (pkt == NULL) {
|
||||
MESH_DEBUG_PRINTLN("sendGroupData: unable to create group datagram, data_len=%d", data_len);
|
||||
return false;
|
||||
}
|
||||
sendFloodScoped(channel, pkt);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseChatMesh::shareContactZeroHop(const ContactInfo& contact) {
|
||||
int plen = getBlobByKey(contact.id.pub_key, PUB_KEY_SIZE, temp_buf); // retrieve last raw advert packet
|
||||
if (plen == 0) return false; // not found
|
||||
|
|
|
|||
|
|
@ -111,6 +111,8 @@ 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, uint16_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;
|
||||
virtual void handleReturnPathRetry(const ContactInfo& contact, const uint8_t* path, uint8_t path_len);
|
||||
|
|
@ -148,6 +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(mesh::GroupChannel& channel, uint16_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);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TXT_TYPE_PLAIN 0 // a plain text message
|
||||
#define TXT_TYPE_CLI_DATA 1 // a CLI command
|
||||
#define TXT_TYPE_SIGNED_PLAIN 2 // plain text, signed by sender
|
||||
#define TXT_TYPE_PLAIN 0 // a plain text message
|
||||
#define TXT_TYPE_CLI_DATA 1 // a CLI command
|
||||
#define TXT_TYPE_SIGNED_PLAIN 2 // plain text, signed by sender
|
||||
#define DATA_TYPE_DEV 0xFFFF // developer namespace for experimenting with group/channel datagrams and building apps
|
||||
|
||||
class StrHelper {
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue