Cheap routing optimizations#57
Merged
callebtc merged 3 commits intopermissionlesstech:mainfrom Jul 13, 2025
Merged
Conversation
Collaborator
|
Awesome, thank you! Can you expand on point 2? Shouldn't we relay private messages even if the sender and recipient don't have a direct connection? Maybe I'm misunderstanding |
Contributor
Author
Yes, indeed. So in |
Contributor
Author
|
That reminded me that the direct send may fail (e.g. connection was lost in the meantime), so we should also fall back to broadcast in that case. Latest commit ensures that. |
- Don't relay back to sender or relayer - Only send to connected device if recipientID matches one - Don't relay our own ACK/read receipt
Collaborator
|
Best PR so far. Thank you. |
5 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sending a packet is currently implemented by sequentially sending to each connected peripheral or central. We can reduce airtime and battery usage without requiring any control packets to be sent. Since Bitchat relies on the connection-oriented mode of BLE, we already have knowledge about our 0-hop neighborhood. After a key exchange we can map a Bluetooth address to a Bitchat
peerIDfor a bit more intelligent routing.This PR makes sure to:
senderIDor the relayer of this packet, as they already generated or received the packet. While these will be ignored by the receiver, let’s not waste airtime on this in the first place.recipientID, if we’re directly connected. This potentially avoids a lot of unnecessary rebroadcasting.Most important changes are in
broadcastPacket(). I introduced a newaddressPeerMapto map Bluetooth addresses topeerIDs, and aRoutedPacketdata structure containing aBitchatPacketand routing metadata.Tested with Android devices. It’s backwards compatible with both Android and iOS since no new packets or header entries are needed, it only mitigates unnecessary transmissions. Since this is a protocol-level optimization, I’ll open an issue requesting these optimizations for iOS also.