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
+3 -3
View File
@@ -61,7 +61,7 @@ class ChatViewModel: ObservableObject {
@Published var retentionEnabledChannels: Set<String> = [] // Channels where owner enabled retention for all members
@Published var channelVerificationStatus: [String: ChannelVerificationStatus] = [:] // Track verification status
let meshService = BluetoothMeshService()
var meshService = BluetoothMeshService()
private let userDefaults = UserDefaults.standard
private let nicknameKey = "bitchat.nickname"
private let joinedChannelsKey = "bitchat.joinedChannels"
@@ -959,13 +959,13 @@ class ChatViewModel: ObservableObject {
}
// Compute SHA256 hash of the derived key for public verification
private func computeKeyCommitment(for key: SymmetricKey) -> String {
internal func computeKeyCommitment(for key: SymmetricKey) -> String {
let keyData = key.withUnsafeBytes { Data($0) }
let hash = SHA256.hash(data: keyData)
return hash.compactMap { String(format: "%02x", $0) }.joined()
}
private func deriveChannelKey(from password: String, channelName: String) -> SymmetricKey {
internal func deriveChannelKey(from password: String, channelName: String) -> SymmetricKey {
// Get creator fingerprint for this channel
let creatorFingerprint = channelCreators[channelName]