fix: transport.UDPConn 新增了 WithUDPLinuxTimestamping(false) 开关

This commit is contained in:
mochangkang committed 2026-03-27 01:59:17 +08:00
1 parent 5b231141a7
commit 8cec6a0766
7 files changed
+154 -37

No files matched your search

+10 -1
View File
@@ -22,6 +22,7 @@ type clientOptions struct {
kcpPacketDebugLogger transport.KCPPacketDebugLogger
kcpSessionStatsLogger transport.KCPSessionStatsLogger
kcpSessionStatsInterval time.Duration
udpLinuxTimestamping bool
bindIP string
bindDevice string
}
@@ -72,6 +73,13 @@ func WithBindDevice(device string) Option {
}
}
// WithUDPLinuxTimestamping controls whether UDP clients enable Linux timestamping.
func WithUDPLinuxTimestamping(enabled bool) Option {
return func(options *clientOptions) {
options.udpLinuxTimestamping = enabled
}
}
// Client 表示一个已经连接到 server 的 peer。
type Client struct {
id string
@@ -84,7 +92,8 @@ type Client struct {
// Dial 连接到 server,并立即发送 register 消息完成身份注册。
func Dial(serverAddr, peerID string, opts ...Option) (*Client, error) {
options := clientOptions{
logger: latencylog.NoopLogger{},
logger: latencylog.NoopLogger{},
udpLinuxTimestamping: true,
}
for _, opt := range opts {
opt(&options)
+3 -1
View File
@@ -24,7 +24,8 @@ type UDPClient struct {
// DialUDP 通过 UDP 连接到 server,并发送 register 消息完成身份注册。
func DialUDP(serverAddr, peerID string, opts ...Option) (*UDPClient, error) {
options := clientOptions{
logger: latencylog.NoopLogger{},
logger: latencylog.NoopLogger{},
udpLinuxTimestamping: true,
}
for _, opt := range opts {
opt(&options)
@@ -56,6 +57,7 @@ func DialUDP(serverAddr, peerID string, opts ...Option) (*UDPClient, error) {
rawConn,
nil, // peer 侧已连接模式,不需要指定 peerAddr
transport.WithUDPLogger(options.logger, latencylog.NodeRolePeer, peerID),
transport.WithUDPLinuxTimestamping(options.udpLinuxTimestamping),
transport.WithUDPTXTimestampDebugLogger(options.txTimestampDebugLogger),
)
if err != nil {