feat(notify): 重构通信内核并补齐 stream/bulk/record/transfer 能力
- 引入 LogicalConn/TransportConn 分层,ClientConn 保留兼容适配层 - 新增 Stream、Bulk、RecordStream 三条数据面能力及对应控制路径 - 完成 transfer/file 传输内核与状态快照、诊断能力 - 补齐 reconnect、inbound dispatcher、modern psk 等基础模块 - 增加大规模回归、并发与基准测试覆盖 - 更新依赖库
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package notify
|
||||
|
||||
import "time"
|
||||
|
||||
type expiredDetachedClientCandidate struct {
|
||||
logical *LogicalConn
|
||||
detachedAt time.Time
|
||||
}
|
||||
|
||||
func (s *ServerCommon) shutdownMonitorPool() {
|
||||
s.getPendingWaitPool().closeAll()
|
||||
s.getFileAckPool().closeAll()
|
||||
s.getSignalAckPool().closeAll()
|
||||
}
|
||||
|
||||
func (s *ServerCommon) monitorPoolTick(now time.Time) {
|
||||
s.getPendingWaitPool().cleanupExpired(s.noFinSyncMsgMaxKeepSeconds, now)
|
||||
s.cleanupExpiredDetachedClients(now)
|
||||
s.cleanupLostHeartbeatClients(now)
|
||||
}
|
||||
|
||||
func (s *ServerCommon) cleanupLostHeartbeatClients(now time.Time) {
|
||||
if s.maxHeartbeatLostSeconds == 0 {
|
||||
return
|
||||
}
|
||||
for _, logical := range s.snapshotLostHeartbeatClients(now.Unix()) {
|
||||
if logical.shouldPreserveLogicalPeerOnTransportLoss() {
|
||||
s.detachLogicalSessionTransport(logical, "heartbeat timeout", nil)
|
||||
continue
|
||||
}
|
||||
s.stopLogicalSession(logical, "heartbeat timeout", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerCommon) snapshotLostHeartbeatClients(nowUnix int64) []*LogicalConn {
|
||||
allLogicals := s.GetLogicalConnList()
|
||||
logicals := make([]*LogicalConn, 0, len(allLogicals))
|
||||
for _, logical := range allLogicals {
|
||||
if logical == nil {
|
||||
continue
|
||||
}
|
||||
if logical.shouldPreserveLogicalPeerOnTransportLoss() && !logical.transportAttachedSnapshot() {
|
||||
continue
|
||||
}
|
||||
if nowUnix-logical.lastHeartbeatUnixSnapshot() > s.maxHeartbeatLostSeconds {
|
||||
logicals = append(logicals, logical)
|
||||
}
|
||||
}
|
||||
return logicals
|
||||
}
|
||||
|
||||
func (s *ServerCommon) cleanupExpiredDetachedClients(now time.Time) {
|
||||
keepSec := s.DetachedClientKeepSec()
|
||||
if keepSec <= 0 {
|
||||
return
|
||||
}
|
||||
keep := time.Duration(keepSec) * time.Second
|
||||
for _, candidate := range s.snapshotExpiredDetachedClients(now, keep) {
|
||||
logical := candidate.logical
|
||||
if logical == nil || !logical.logicalTransportDetachedSnapshot() {
|
||||
continue
|
||||
}
|
||||
detach := logical.transportDetachSnapshot()
|
||||
if detach == nil || !detach.At.Equal(candidate.detachedAt) {
|
||||
continue
|
||||
}
|
||||
if now.Sub(detach.At) < keep {
|
||||
continue
|
||||
}
|
||||
s.stopLogicalSession(logical, "detached transport expired", nil)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerCommon) snapshotExpiredDetachedClients(now time.Time, keep time.Duration) []expiredDetachedClientCandidate {
|
||||
if keep <= 0 {
|
||||
return nil
|
||||
}
|
||||
allLogicals := s.GetLogicalConnList()
|
||||
clients := make([]expiredDetachedClientCandidate, 0, len(allLogicals))
|
||||
for _, logical := range allLogicals {
|
||||
if logical == nil || !logical.logicalTransportDetachedSnapshot() {
|
||||
continue
|
||||
}
|
||||
detach := logical.transportDetachSnapshot()
|
||||
if detach == nil || detach.At.IsZero() {
|
||||
continue
|
||||
}
|
||||
if now.Sub(detach.At) < keep {
|
||||
continue
|
||||
}
|
||||
clients = append(clients, expiredDetachedClientCandidate{
|
||||
logical: logical,
|
||||
detachedAt: detach.At,
|
||||
})
|
||||
}
|
||||
return clients
|
||||
}
|
||||
Reference in New Issue
Block a user