Выпуск WDTT Plus v11

This commit is contained in:
Ivan4537 committed 2026-07-07 22:55:52 +03:00
1 parent a842c6965e
commit b3aad32990
25 files changed
+1722 -146

No files matched your search

+3 -3
View File
@@ -79,7 +79,7 @@ func NewDispatcher(ctx context.Context, localConn net.PacketConn, stats *Stats)
cancel: dcancel,
stats: stats,
}
empty := make([]*WorkerSlot, 0)
d.workers.Store(&empty)
@@ -149,7 +149,7 @@ func (d *Dispatcher) readLoop() {
pkt = pkt[:n]
d.clientAddr.Store(&addr)
atomic.AddInt64(&d.stats.TotalBytesUp, int64(n))
d.stats.TotalBytesUp.Add(int64(n))
workersPtr := d.workers.Load()
if workersPtr == nil || len(*workersPtr) == 0 {
@@ -219,7 +219,7 @@ func (d *Dispatcher) writeLoop() {
return
}
}
atomic.AddInt64(&d.stats.TotalBytesDown, int64(len(pkt)))
d.stats.TotalBytesDown.Add(int64(len(pkt)))
putPktBuf(pkt)
}
}
+12 -11
View File
@@ -296,10 +296,10 @@ func RunSession(
}
log.Printf("[ВОРКЕР #%d] [DTLS] Соединение установлено ✓", sessionID)
atomic.AddInt32(&stats.ActiveConnections, 1)
stats.ActiveConnections.Add(1)
globalActiveConnections.Add(1)
defer func() {
atomic.AddInt32(&stats.ActiveConnections, -1)
stats.ActiveConnections.Add(-1)
globalActiveConnections.Add(-1)
}()
@@ -336,9 +336,10 @@ func RunSession(
d.Register(slot)
defer d.Unregister(slot)
lastServerRxAt := time.Now().UnixNano()
var lastUserTrafficAt int64
var keepalivePongSeen int32
var lastServerRxAt atomic.Int64
lastServerRxAt.Store(time.Now().UnixNano())
var lastUserTrafficAt atomic.Int64
var keepalivePongSeen atomic.Int32
// Proxy DTLS ↔ Dispatcher
var proxyWg sync.WaitGroup
@@ -380,16 +381,16 @@ func RunSession(
return
case <-t.C:
now := time.Now()
lastRxUnix := atomic.LoadInt64(&lastServerRxAt)
lastRxUnix := lastServerRxAt.Load()
lastRx := time.Unix(0, lastRxUnix)
if atomic.LoadInt32(&keepalivePongSeen) != 0 && now.Sub(lastRx) > keepalivePongTimeout {
if keepalivePongSeen.Load() != 0 && now.Sub(lastRx) > keepalivePongTimeout {
log.Printf("[ВОРКЕР #%d] [HEALTH] сервер не отвечает на keepalive %.0f сек, перезапуск воркера", sessionID, now.Sub(lastRx).Seconds())
sessCancel()
return
}
lastTxUnix := atomic.LoadInt64(&lastUserTrafficAt)
lastTxUnix := lastUserTrafficAt.Load()
if lastTxUnix > lastRxUnix &&
now.Sub(time.Unix(0, lastTxUnix)) > unansweredUserTrafficTimeout &&
now.Sub(lastRx) > unansweredUserTrafficTimeout {
@@ -420,7 +421,7 @@ func RunSession(
log.Printf("[ВОРКЕР #%d] Ошибка Writer: %v", sessionID, writeErr)
return
}
atomic.StoreInt64(&lastUserTrafficAt, time.Now().UnixNano())
lastUserTrafficAt.Store(time.Now().UnixNano())
}
}
}()
@@ -445,11 +446,11 @@ func RunSession(
return
}
atomic.StoreInt64(&lastServerRxAt, time.Now().UnixNano())
lastServerRxAt.Store(time.Now().UnixNano())
// Skip keepalive pong from server
if n == 1 && pkt[0] == keepaliveByte {
atomic.StoreInt32(&keepalivePongSeen, 1)
keepalivePongSeen.Store(1)
putPktBuf(pkt)
continue
}
+6 -6
View File
@@ -9,9 +9,9 @@ import (
var globalActiveConnections atomic.Int32
type Stats struct {
ActiveConnections int32
TotalBytesUp int64
TotalBytesDown int64
ActiveConnections atomic.Int32
TotalBytesUp atomic.Int64
TotalBytesDown atomic.Int64
}
func NewStats() *Stats {
@@ -27,9 +27,9 @@ func (s *Stats) RunLoop(shutdown <-chan struct{}) {
case <-shutdown:
return
case <-ticker.C:
active := atomic.LoadInt32(&s.ActiveConnections)
up := atomic.LoadInt64(&s.TotalBytesUp)
down := atomic.LoadInt64(&s.TotalBytesDown)
active := s.ActiveConnections.Load()
up := s.TotalBytesUp.Load()
down := s.TotalBytesDown.Load()
upMB := float64(up) / (1024.0 * 1024.0)
downMB := float64(down) / (1024.0 * 1024.0)