Skip to content

Add Peer to Peer communication

Choose a tag to compare

@juano2310 juano2310 released this 09 Nov 18:04
· 24 commits to main since this release

New Features:

  • Peer-to-peer messaging API: New sendPeerMessage(targetClientId, message) method for direct client-to-client communication
  • Security restriction: Only clients with permanent IDs (1-100, registered with serial numbers) can send/receive peer messages
  • ID range separation:
    • IDs 1-100: Permanent IDs for registered clients (supports P2P)
    • IDs 101-254: Temporary IDs for unregistered clients (pub/sub only)
  • New message type: CAN_PS_PEER_MSG (0x09) protocol command

Implementation Changes:

  • Added handlePeerMessage() in broker to validate and forward peer messages
  • Added _nextTempID field to track temporary ID assignments (starts at 101)
  • Enhanced onDirectMessage() callback to handle both broker and peer messages
  • Extended frame support for long peer messages

Documentation:

  • New PEER_TO_PEER.md guide explaining P2P architecture and usage
  • Updated PUBSUB_API.md with sendPeerMessage() documentation
  • Updated SERIAL_NUMBER_MANAGEMENT.md with ID range table and P2P capabilities
  • Updated QUICK_REFERENCE.md with unified messaging commands

Examples:

  • New PeerToPeer.ino example demonstrating direct client-to-client messaging
  • Updated ClientWithSerial.ino with unified msg:id:message command supporting both broker and peer messages

Protocol Enhancements:

  • Broker validates sender and receiver have permanent IDs before forwarding
  • Serial number verification in ID responses to prevent ID conflicts
  • Improved subscription cleanup when clients disconnect