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,120 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (s *ServerCommon) GetLogicalConn(id string) *LogicalConn {
|
||||
registry := s.getPeerRegistry()
|
||||
if registry == nil {
|
||||
return nil
|
||||
}
|
||||
return registry.getLogical(id)
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetClient(id string) *ClientConn {
|
||||
logical := s.GetLogicalConn(id)
|
||||
if logical == nil {
|
||||
return nil
|
||||
}
|
||||
return logical.compatClientConn()
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetCurrentTransportConn(id string) *TransportConn {
|
||||
logical := s.GetLogicalConn(id)
|
||||
if logical == nil {
|
||||
return nil
|
||||
}
|
||||
return s.GetCurrentTransportConnByLogical(logical)
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetCurrentTransportConnByLogical(c *LogicalConn) *TransportConn {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return s.resolveOutboundTransport(c)
|
||||
}
|
||||
|
||||
func (s *ServerCommon) resolveLogicalBySource(source string) *LogicalConn {
|
||||
registry := s.getPeerRegistry()
|
||||
if registry == nil {
|
||||
return nil
|
||||
}
|
||||
return registry.resolveLogicalBySource(source)
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetClientLists() []*ClientConn {
|
||||
logicals := s.GetLogicalConnList()
|
||||
list := make([]*ClientConn, 0, len(logicals))
|
||||
for _, logical := range logicals {
|
||||
client := logical.compatClientConn()
|
||||
if client != nil {
|
||||
list = append(list, client)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetLogicalConnList() []*LogicalConn {
|
||||
registry := s.getPeerRegistry()
|
||||
if registry == nil {
|
||||
return nil
|
||||
}
|
||||
return registry.logicalList()
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetCurrentTransportConnList() []*TransportConn {
|
||||
logicals := s.GetLogicalConnList()
|
||||
list := make([]*TransportConn, 0, len(logicals))
|
||||
for _, logical := range logicals {
|
||||
if logical == nil {
|
||||
continue
|
||||
}
|
||||
transport := s.resolveOutboundTransport(logical)
|
||||
if transport == nil {
|
||||
continue
|
||||
}
|
||||
list = append(list, transport)
|
||||
}
|
||||
sort.Slice(list, func(i int, j int) bool {
|
||||
if list[i].ClientID() == list[j].ClientID() {
|
||||
return list[i].TransportGeneration() < list[j].TransportGeneration()
|
||||
}
|
||||
return list[i].ClientID() < list[j].ClientID()
|
||||
})
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *ServerCommon) GetClientAddrs() []net.Addr {
|
||||
logicals := s.GetLogicalConnList()
|
||||
list := make([]net.Addr, 0, len(logicals))
|
||||
for _, logical := range logicals {
|
||||
addr := logical.RemoteAddr()
|
||||
if addr == nil {
|
||||
continue
|
||||
}
|
||||
list = append(list, addr)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *ServerCommon) snapshotDetachedLogicals() []*LogicalConn {
|
||||
registry := s.getPeerRegistry()
|
||||
if registry == nil {
|
||||
return nil
|
||||
}
|
||||
list := registry.detachedLogicals()
|
||||
sort.Slice(list, func(i int, j int) bool {
|
||||
left := list[i]
|
||||
right := list[j]
|
||||
if left == nil || right == nil {
|
||||
return left != nil
|
||||
}
|
||||
if left.ID() == right.ID() {
|
||||
return addrString(left.RemoteAddr()) < addrString(right.RemoteAddr())
|
||||
}
|
||||
return left.ID() < right.ID()
|
||||
})
|
||||
return list
|
||||
}
|
||||
Reference in New Issue
Block a user