simple clear

This commit is contained in:
Fangliding
2026-10-18 22:30:54 +08:00
parent 0396b34eff
commit 8d0deebf86
3 changed files with 4 additions and 21 deletions
+1 -12
View File
@@ -100,21 +100,12 @@ type ServerUDPSession struct {
func (s *ServerUDPSession) CheckPacketID(packetID uint64) bool {
s.Lock()
defer s.Unlock()
if s.Window == nil {
s.Window = new(SlidingWindow)
}
return s.Window.Check(packetID)
}
// CommitPacketID records a packet ID after the packet has been fully validated.
// It re-checks the window under the lock, so when the same packet is validated
// concurrently (e.g. by the workers of two client source addresses), only one is accepted.
func (s *ServerUDPSession) CommitPacketID(packetID uint64) bool {
s.Lock()
defer s.Unlock()
if s.Window == nil {
s.Window = new(SlidingWindow)
}
return s.Window.CheckAndAdd(packetID)
}
@@ -127,9 +118,6 @@ func (s *ServerUDPSession) getClientBodyCipher() cipher.AEAD {
func (s *ServerUDPSession) commitClientPacket(packetID uint64, bodyAead cipher.AEAD) bool {
s.Lock()
defer s.Unlock()
if s.Window == nil {
s.Window = new(SlidingWindow)
}
if !s.Window.CheckAndAdd(packetID) {
return false
}
@@ -161,6 +149,7 @@ func (m *UDPSessionManager) GetOrCreate(sessionID uint64) *ServerUDPSession {
s := &ServerUDPSession{
SessionID: sessionID,
Window: new(SlidingWindow),
manager: m,
}
s.LastActive.Store(now)