This commit is contained in:
anlicheng 2026-04-16 11:13:33 +08:00
parent bfd635c307
commit 86346b315c

View File

@ -45,24 +45,25 @@ actor SessionManager {
func getSession(toAddress: Data) -> Session? { func getSession(toAddress: Data) -> Session? {
let timestamp = Int32(Date().timeIntervalSince1970) let timestamp = Int32(Date().timeIntervalSince1970)
guard var sessions = self.sessions[toAddress] else { guard var peerSessions = self.sessions[toAddress] else {
return nil return nil
} }
sessions = sessions.filter { $0.value.lastTimestamp + ttl >= timestamp } peerSessions = peerSessions.filter { $0.value.lastTimestamp + ttl >= timestamp }
guard !sessions.isEmpty else { guard !peerSessions.isEmpty else {
self.sessions.removeValue(forKey: toAddress) self.sessions.removeValue(forKey: toAddress)
return nil return nil
} }
guard var session = self.selectSession(in: sessions) else { guard var session = self.selectSession(in: peerSessions) else {
self.sessions[toAddress] = sessions self.sessions[toAddress] = peerSessions
return nil return nil
} }
session.updateLastTimestamp(timestamp) session.updateLastTimestamp(timestamp)
sessions[session.addressType] = session peerSessions[session.addressType] = session
self.sessions[toAddress] = sessions
self.sessions[toAddress] = peerSessions
return session return session
} }