From 8f960fc45f0dbae0bad525f71c10b430fe7cb687 Mon Sep 17 00:00:00 2001 From: torlando-tech Date: Fri, 31 Oct 2025 23:15:02 -0400 Subject: [PATCH] feat: Add peripheral fragmenter creation for bidirectional BLE data flow Enable BLE peripheral connections to send data by creating fragmenters in handle_peripheral_data() after identity handshake. Previously, fragmenters were only created for central connections (_connect_to_peer), which caused "No fragmenter for peer" warnings when peripheral-only connections attempted to transmit data. This fix ensures bidirectional data flow works correctly regardless of which device initiates the BLE connection, completing the unified interface architecture. Impact: Fixes announce rebroadcasting from peripheral-only connections and enables full mesh networking over BLE. Tested on Raspberry Pi 4 with BlueZ 5.76. Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude --- src/RNS/Interfaces/BLEInterface.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/RNS/Interfaces/BLEInterface.py b/src/RNS/Interfaces/BLEInterface.py index 1643139..85bb66b 100644 --- a/src/RNS/Interfaces/BLEInterface.py +++ b/src/RNS/Interfaces/BLEInterface.py @@ -1863,6 +1863,19 @@ class BLEInterface(Interface): RNS.log(f"{self} migrated interface from legacy ({legacy_conn_id}) to identity-based ({central_identity_hash})", RNS.LOG_INFO) + # Create fragmenter/reassembler for peripheral connection to enable bidirectional data flow + # This is critical: fragmenters must exist for BOTH central and peripheral connections + frag_key = self._get_fragmenter_key(central_identity, sender_address) + with self.frag_lock: + if frag_key not in self.fragmenters: + # Get MTU from GATT server for this peripheral connection + mtu = self.gatt_server.get_central_mtu(sender_address) if self.gatt_server else 23 + self.fragmenters[frag_key] = BLEFragmenter(mtu=mtu) + self.reassemblers[frag_key] = BLEReassembler(timeout=self.connection_timeout) + RNS.log(f"{self} created fragmenter for peripheral connection (key: {frag_key[:16]}, MTU: {mtu})", RNS.LOG_DEBUG) + else: + RNS.log(f"{self} fragmenter already exists for peripheral connection (key: {frag_key[:16]})", RNS.LOG_EXTREME) + return # Don't process handshake as data # Update fragmenter MTU if GATT server has learned a new MTU