Merge nucleic/rustic-maple-marten into dev
This commit is contained in:
@@ -28,6 +28,11 @@ struct PairedHost: Codable, Equatable {
|
||||
var relayRoomID: String?
|
||||
var relayMembershipToken: String?
|
||||
var relayURL: String?
|
||||
/// When the gossiped addresses this record's dial hints came from were stamped at their
|
||||
/// origin (`PeerAddresses.updatedAt`) — the freshness clock `mergePairedHost` arbitrates
|
||||
/// with, so a Mac gossiping a stale snapshot can't clobber a fresher one. Nil for records
|
||||
/// predating the field and for hints seeded straight from a pairing QR.
|
||||
var addressesUpdatedAt: Date? = nil
|
||||
|
||||
var transportHint: SyncTransportHint { transport.flatMap(SyncTransportHint.init(rawValue:)) ?? .lan }
|
||||
}
|
||||
@@ -119,9 +124,17 @@ enum IdentityStore {
|
||||
static func mergePairedHost(_ host: PairedHost) {
|
||||
var hosts = pairedHosts()
|
||||
if let index = hosts.firstIndex(where: { $0.fingerprint == host.fingerprint }) {
|
||||
var merged = host
|
||||
let existing = hosts[index]
|
||||
// Freshness gate on the dial hints: two Macs can gossip disagreeing snapshots of a
|
||||
// third's addresses (one still holds its pre-relaunch LAN port). Adopting the incoming
|
||||
// hints blindly made the record — and every dial loop keyed off it — flip-flop between
|
||||
// the stale and fresh snapshots on alternating pushes. The origin's `updatedAt` rides
|
||||
// in as `addressesUpdatedAt`; an undated record loses to any dated one.
|
||||
let incomingAt = host.addressesUpdatedAt ?? .distantPast
|
||||
let existingAt = existing.addressesUpdatedAt ?? .distantPast
|
||||
var merged = incomingAt >= existingAt ? host : existing
|
||||
merged.deviceID = existing.deviceID // keep our established id for this host
|
||||
merged.hostName = host.hostName // labels carry no clock; newest gossip wins
|
||||
merged.relayMembershipToken = host.relayMembershipToken ?? existing.relayMembershipToken
|
||||
merged.relayRoomID = host.relayRoomID ?? existing.relayRoomID
|
||||
merged.relayURL = host.relayURL ?? existing.relayURL
|
||||
|
||||
Reference in New Issue
Block a user