fix: vless server close

This commit is contained in:
wwqgtxx
2025-08-10 22:43:31 +08:00
parent 1b0c72bfab
commit 2a915a5c94
3 changed files with 31 additions and 6 deletions

View File

@@ -27,6 +27,7 @@ type ServerInstance struct {
dKeyNfs *mlkem.DecapsulationKey768
minutes time.Duration
sessions map[[21]byte]*ServerSession
stop bool
}
type ServerConn struct {
@@ -52,6 +53,9 @@ func (i *ServerInstance) Init(dKeyNfsData []byte, minutes time.Duration) (err er
time.Sleep(time.Minute)
now := time.Now()
i.Lock()
if i.stop {
return
}
for index, session := range i.sessions {
if now.After(session.expire) {
delete(i.sessions, index)
@@ -64,6 +68,13 @@ func (i *ServerInstance) Init(dKeyNfsData []byte, minutes time.Duration) (err er
return
}
func (i *ServerInstance) Close() (err error) {
i.Lock()
defer i.Unlock()
i.stop = true
return
}
func (i *ServerInstance) Handshake(conn net.Conn) (net.Conn, error) {
if i.dKeyNfs == nil {
return nil, errors.New("uninitialized")