-
Notifications
You must be signed in to change notification settings - Fork 657
feat: Add support for PAYLOAD_TYPE_GRP_DATA #1928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dz0ny
wants to merge
10
commits into
meshcore-dev:dev
Choose a base branch
from
dz0ny:feat/grp-data-upstream
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9b84278
feat: Add support for PAYLOAD_TYPE_GRP_DATA
dz0ny 0e98939
feat: Require 0xFF for custom payloads
dz0ny a21b83b
fix: address comments
dz0ny f25d7a8
fix: Align channel data framing
dz0ny 37b72ff
fix: Scope group data docs
dz0ny 896d60c
fix: Keep data docs only
dz0ny 2fe3c36
fix: Trim grp docs
dz0ny 1fb26e7
fix: Drop grp data timestamp
dz0ny 2f68769
fix: Widen grp data type
dz0ny ae9fcb3
fix: Rename grp dev type
dz0ny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. old check was |
||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.