- 引入 LogicalConn/TransportConn 分层,ClientConn 保留兼容适配层 - 新增 Stream、Bulk、RecordStream 三条数据面能力及对应控制路径 - 完成 transfer/file 传输内核与状态快照、诊断能力 - 补齐 reconnect、inbound dispatcher、modern psk 等基础模块 - 增加大规模回归、并发与基准测试覆盖 - 更新依赖库
106 lines
2.2 KiB
Go
106 lines
2.2 KiB
Go
package notify
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
var _ net.Conn = (*streamHandle)(nil)
|
|
|
|
func streamLocalAddrSnapshot(logical *LogicalConn, transport *TransportConn) net.Addr {
|
|
if logical != nil {
|
|
if conn := logical.transportSnapshot(); conn != nil && conn.LocalAddr() != nil {
|
|
return conn.LocalAddr()
|
|
}
|
|
server := logical.Server()
|
|
if common, ok := server.(*ServerCommon); ok {
|
|
if common.listener != nil && common.listener.Addr() != nil {
|
|
return common.listener.Addr()
|
|
}
|
|
if udp := common.serverUDPListenerSnapshot(); udp != nil && udp.LocalAddr() != nil {
|
|
return udp.LocalAddr()
|
|
}
|
|
}
|
|
}
|
|
if transport != nil {
|
|
return transportLocalAddrSnapshot(transport)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func streamRemoteAddrSnapshot(logical *LogicalConn, transport *TransportConn) net.Addr {
|
|
if transport != nil && transport.RemoteAddr() != nil {
|
|
return transport.RemoteAddr()
|
|
}
|
|
if logical != nil {
|
|
return logical.RemoteAddr()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func transportLocalAddrSnapshot(transport *TransportConn) net.Addr {
|
|
if transport == nil {
|
|
return nil
|
|
}
|
|
logical := transport.LogicalConn()
|
|
if logical == nil {
|
|
return nil
|
|
}
|
|
conn := logical.transportSnapshot()
|
|
if conn == nil || conn.LocalAddr() == nil {
|
|
return nil
|
|
}
|
|
if transport.TransportGeneration() != 0 && transport.TransportGeneration() != logical.transportGenerationSnapshot() {
|
|
return nil
|
|
}
|
|
return conn.LocalAddr()
|
|
}
|
|
|
|
func signalStreamDeadlineChangeLocked(ch *chan struct{}) {
|
|
if ch == nil {
|
|
return
|
|
}
|
|
current := *ch
|
|
if current != nil {
|
|
close(current)
|
|
}
|
|
*ch = make(chan struct{})
|
|
}
|
|
|
|
func streamEffectiveDeadline(now time.Time, timeout time.Duration, explicit time.Time) time.Time {
|
|
deadline := explicit
|
|
if timeout > 0 {
|
|
timeoutDeadline := now.Add(timeout)
|
|
if deadline.IsZero() || timeoutDeadline.Before(deadline) {
|
|
deadline = timeoutDeadline
|
|
}
|
|
}
|
|
return deadline
|
|
}
|
|
|
|
func streamDeadlineChanged(ch <-chan struct{}) bool {
|
|
if ch == nil {
|
|
return false
|
|
}
|
|
select {
|
|
case <-ch:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func normalizeStreamDeadlineError(err error) error {
|
|
switch {
|
|
case err == nil:
|
|
return nil
|
|
case errors.Is(err, context.DeadlineExceeded):
|
|
return os.ErrDeadlineExceeded
|
|
default:
|
|
return err
|
|
}
|
|
}
|