This commit is contained in:
Fangliding
2026-11-26 21:09:20 +08:00
parent 2e9bac5648
commit e04430d18f
8 changed files with 391 additions and 230 deletions
+17 -14
View File
@@ -103,27 +103,23 @@ func (s *ServerUDPSession) CheckPacketID(packetID uint64) bool {
return s.Window.Check(packetID)
}
func (s *ServerUDPSession) CommitPacketID(packetID uint64) bool {
s.Lock()
defer s.Unlock()
return s.Window.CheckAndAdd(packetID)
}
func (s *ServerUDPSession) getClientBodyCipher() cipher.AEAD {
s.Lock()
defer s.Unlock()
return s.clientBodyCipher
}
func (s *ServerUDPSession) commitClientPacket(packetID uint64, bodyAead cipher.AEAD) bool {
func (s *ServerUDPSession) Commit(packetID uint64, bodyAead cipher.AEAD, user *protocol.MemoryUser, userPSK []byte) bool {
s.Lock()
defer s.Unlock()
if s.User != nil && user != nil && s.User != user {
return false
}
if !s.Window.CheckAndAdd(packetID) {
return false
}
if s.clientBodyCipher == nil {
if s.clientBodyCipher == nil && bodyAead != nil {
s.clientBodyCipher = bodyAead
}
if s.User == nil && user != nil {
s.User = user
s.UserPSK = userPSK
}
s.LastActive.Store(time.Now().Unix())
return true
}
@@ -140,6 +136,13 @@ func NewUDPSessionManager(timeout time.Duration) *UDPSessionManager {
}
}
func (m *UDPSessionManager) Get(sessionID uint64) *ServerUDPSession {
if s, ok := m.sessions.Load(sessionID); ok {
return s
}
return nil
}
func (m *UDPSessionManager) GetOrCreate(sessionID uint64) *ServerUDPSession {
now := time.Now().Unix()
if s, ok := m.sessions.Load(sessionID); ok {