-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Re-use channel Uplink / Downlink for UDP controls #8134
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
thebentern
wants to merge
11
commits into
master
Choose a base branch
from
uplink-downlink-udp-controls
base: master
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.
+110
−7
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6835392
Re-use Uplink / downlink controls for UDP
thebentern 42532d5
Size
thebentern 2b590d2
Update src/mesh/udp/UdpMulticastHandler.h
thebentern 888115e
Revert "Update src/mesh/udp/UdpMulticastHandler.h"
thebentern 6040e49
Merge branch 'master' into uplink-downlink-udp-controls
thebentern b76a229
Merge branch 'master' into uplink-downlink-udp-controls
thebentern c1e8c28
Revert "Revert cross-preset UDP bridging"
thebentern 87a4a6a
Fix isFromUs and account for channel hashes instead of indexes
thebentern 24940f7
Merge branch 'master' into uplink-downlink-udp-controls
thebentern f20ce2c
Merge branch 'master' into uplink-downlink-udp-controls
thebentern 5f9d0bb
Merge branch 'master' into uplink-downlink-udp-controls
thebentern 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -356,13 +356,55 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) | |
if (moduleConfig.mqtt.enabled && isFromUs(p) && mqtt) { | ||
mqtt->onSend(*p, *p_decoded, chIndex); | ||
} | ||
#endif | ||
#if HAS_UDP_MULTICAST | ||
if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST) { | ||
// We must have at least one channel setup for with uplink_enabled | ||
bool uplinkEnabled = false; | ||
for (int i = 0; i <= 7; i++) { | ||
if (channels.getByIndex(i).settings.uplink_enabled) | ||
uplinkEnabled = true; | ||
} | ||
if (uplinkEnabled) { | ||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p), chIndex); | ||
} | ||
} | ||
#endif | ||
packetPool.release(p_decoded); | ||
} | ||
|
||
#if HAS_UDP_MULTICAST | ||
if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST) { | ||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p)); | ||
// For packets that are already encrypted, we need to determine the channel from packet info | ||
else if (udpHandler && config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST && | ||
isFromUs(p)) { | ||
// Check if any channel has uplink enabled (for PKI support) | ||
bool uplinkEnabled = false; | ||
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. Maybe instead of this bool we can use an |
||
for (int i = 0; i <= 7; i++) { | ||
if (channels.getByIndex(i).settings.uplink_enabled) { | ||
uplinkEnabled = true; | ||
break; | ||
} | ||
} | ||
if (uplinkEnabled) { | ||
ChannelIndex chIndex = 0; // Default to primary channel | ||
|
||
// For PKI encrypted packets, use default channel if at least one channel has uplink | ||
if (p->pki_encrypted) { | ||
for (int i = 0; i <= 7; i++) { | ||
if (channels.getByIndex(i).settings.uplink_enabled) { | ||
chIndex = i; | ||
break; | ||
} | ||
} | ||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p), chIndex); | ||
} else { | ||
// For regular channel PSK encrypted packets, try to find the channel by hash | ||
int8_t foundIndex = channels.getIndexByHash(p->channel); | ||
if (foundIndex >= 0) { | ||
chIndex = foundIndex; | ||
udpHandler->onSend(const_cast<meshtastic_MeshPacket *>(p), chIndex); | ||
} | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
|
@@ -480,6 +522,35 @@ DecodeState perhapsDecode(meshtastic_MeshPacket *p) | |
} | ||
} | ||
|
||
#if HAS_UDP_MULTICAST | ||
// Fallback: for UDP multicast, try default preset names with default PSK if normal channel match failed | ||
if (!decrypted && p->transport_mechanism == meshtastic_MeshPacket_TransportMechanism_TRANSPORT_MULTICAST_UDP) { | ||
if (channels.setDefaultPresetCryptoForHash(p->channel)) { | ||
memcpy(bytes, p->encrypted.bytes, rawSize); | ||
crypto->decrypt(p->from, p->id, rawSize, bytes); | ||
|
||
meshtastic_Data decodedtmp; | ||
memset(&decodedtmp, 0, sizeof(decodedtmp)); | ||
if (pb_decode_from_bytes(bytes, rawSize, &meshtastic_Data_msg, &decodedtmp) && | ||
decodedtmp.portnum != meshtastic_PortNum_UNKNOWN_APP) { | ||
p->decoded = decodedtmp; | ||
p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; | ||
// Map to our local default channel index (name+PSK default), not necessarily primary | ||
ChannelIndex defaultIndex = channels.getPrimaryIndex(); | ||
for (ChannelIndex i = 0; i < channels.getNumChannels(); ++i) { | ||
if (channels.isDefaultChannel(i)) { | ||
defaultIndex = i; | ||
break; | ||
} | ||
} | ||
chIndex = defaultIndex; | ||
decrypted = true; | ||
} else { | ||
LOG_WARN("UDP fallback decode attempted but failed for hash 0x%x", p->channel); | ||
} | ||
} | ||
} | ||
#endif | ||
if (decrypted) { | ||
// parsing was successful | ||
p->channel = chIndex; // change to store the index instead of the hash | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFromUs(p)
is here still.