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,86 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultFileScope = "default"
|
||||
clientFileDomain = "client"
|
||||
serverFileDomain = "server"
|
||||
serverTransportScopeSuffix = "#tg:"
|
||||
)
|
||||
|
||||
func normalizeFileScope(scope string) string {
|
||||
cleaned := strings.TrimSpace(scope)
|
||||
if cleaned == "" {
|
||||
return defaultFileScope
|
||||
}
|
||||
return cleaned
|
||||
}
|
||||
|
||||
func clientFileScope() string {
|
||||
return clientFileDomain
|
||||
}
|
||||
|
||||
func serverFileScope(peer any) string {
|
||||
logical := logicalConnFromPeer(peer)
|
||||
if logical == nil {
|
||||
return serverFileDomain + ":unknown"
|
||||
}
|
||||
id := strings.TrimSpace(logical.ID())
|
||||
if id == "" {
|
||||
return serverFileDomain + ":unknown"
|
||||
}
|
||||
return serverFileDomain + ":" + id
|
||||
}
|
||||
|
||||
func serverTransportScope(peer any) string {
|
||||
logical := logicalConnFromPeer(peer)
|
||||
if logical == nil {
|
||||
return serverFileDomain + ":unknown"
|
||||
}
|
||||
return serverTransportScopeByGeneration(logical, logical.transportGenerationSnapshot())
|
||||
}
|
||||
|
||||
func serverTransportScopeForTransport(transport *TransportConn) string {
|
||||
if transport == nil {
|
||||
return serverFileDomain + ":unknown"
|
||||
}
|
||||
return transport.transportScope()
|
||||
}
|
||||
|
||||
func serverTransportScopeByGeneration(peer any, generation uint64) string {
|
||||
base := serverFileScope(peer)
|
||||
if generation == 0 {
|
||||
return base
|
||||
}
|
||||
return base + serverTransportScopeSuffix + strconv.FormatUint(generation, 10)
|
||||
}
|
||||
|
||||
func serverTransportDeliveryScopes(peer any) []string {
|
||||
logical := logicalConnFromPeer(peer)
|
||||
if logical == nil {
|
||||
return []string{serverFileDomain + ":unknown"}
|
||||
}
|
||||
base := serverFileScope(logical)
|
||||
transport := serverTransportScope(logical)
|
||||
if transport == base {
|
||||
return []string{base}
|
||||
}
|
||||
return []string{transport, base}
|
||||
}
|
||||
|
||||
func serverTransportDeliveryScopesForTransport(transport *TransportConn) []string {
|
||||
if transport == nil {
|
||||
return []string{serverFileDomain + ":unknown"}
|
||||
}
|
||||
return transport.deliveryScopes()
|
||||
}
|
||||
|
||||
func scopeBelongsToServerFileScope(scope string, base string) bool {
|
||||
scope = normalizeFileScope(scope)
|
||||
base = normalizeFileScope(base)
|
||||
return scope == base || strings.HasPrefix(scope, base+serverTransportScopeSuffix)
|
||||
}
|
||||
Reference in New Issue
Block a user