Add protocol version negotiation for future compatibility

- Add version negotiation messages (0x20 versionHello, 0x21 versionAck)
- Implement VersionHello and VersionAck message types with platform info
- Add ProtocolVersion struct for version management and negotiation
- Update BinaryProtocol to check supported versions
- Add version negotiation to connection flow before Noise handshake
- Maintain backward compatibility with legacy peers (assume v1)
- Add comprehensive test suite with 40+ test cases
- Update documentation with version negotiation details

This ensures BitChat clients can negotiate protocol versions for smooth
upgrades while maintaining full backward compatibility with existing clients.
This commit is contained in:
jack
2025-07-15 14:33:37 +02:00
parent 59927486eb
commit 3fb39b8a30
11 changed files with 1532 additions and 9 deletions
+20
View File
@@ -199,6 +199,26 @@ enum NoiseError: Error {
- Automatic cleanup of stale sessions
- Efficient key rotation
## Protocol Version Negotiation
BitChat implements protocol version negotiation to ensure compatibility between different client versions:
### Version Negotiation Flow
1. **Version Hello**: Upon connection, peers exchange supported protocol versions
2. **Version Agreement**: Peers agree on the highest common version
3. **Graceful Fallback**: Legacy peers without version negotiation assume protocol v1
### Message Types
```swift
case versionHello = 0x20 // Announce supported versions
case versionAck = 0x21 // Acknowledge and agree on version
```
### Backward Compatibility
- Peers that don't send version negotiation messages are assumed to support v1
- Future protocol versions can be added to `ProtocolVersion.supportedVersions`
- Incompatible peers receive a rejection message and disconnect gracefully
## Future Enhancements
### Post-Quantum Readiness