From 4fc284a8e9f3e086de4859e8b06d98eda3d2db04 Mon Sep 17 00:00:00 2001 From: yaotthaha-vscode <95022881+yaotthaha@users.noreply.github.com> Date: Wed, 1 Dec 2021 23:06:00 +0800 Subject: [PATCH] Try to fix UDP error --- transport/internet/quic/conn.go | 17 +++++++++++++++-- transport/internet/quic/dialer.go | 2 +- transport/internet/quic/hub.go | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/transport/internet/quic/conn.go b/transport/internet/quic/conn.go index 067e6951..648b5fcc 100644 --- a/transport/internet/quic/conn.go +++ b/transport/internet/quic/conn.go @@ -4,6 +4,7 @@ import ( "crypto/cipher" "crypto/rand" "errors" + "syscall" "time" "github.com/lucas-clemente/quic-go" @@ -15,12 +16,12 @@ import ( ) type sysConn struct { - conn net.PacketConn + conn *net.UDPConn header internet.PacketHeader auth cipher.AEAD } -func wrapSysConn(rawConn net.PacketConn, config *Config) (*sysConn, error) { +func wrapSysConn(rawConn *net.UDPConn, config *Config) (*sysConn, error) { header, err := getHeader(config) if err != nil { return nil, err @@ -128,6 +129,14 @@ func (c *sysConn) LocalAddr() net.Addr { return c.conn.LocalAddr() } +func (c *sysConn) SetReadBuffer(bytes int) error { + return c.conn.SetReadBuffer(bytes) +} + +func (c *sysConn) SetWriteBuffer(bytes int) error { + return c.conn.SetWriteBuffer(bytes) +} + func (c *sysConn) SetDeadline(t time.Time) error { return c.conn.SetDeadline(t) } @@ -140,6 +149,10 @@ func (c *sysConn) SetWriteDeadline(t time.Time) error { return c.conn.SetWriteDeadline(t) } +func (c *sysConn) SyscallConn() (syscall.RawConn, error) { + return c.conn.SyscallConn() +} + type interConn struct { stream quic.Stream local net.Addr diff --git a/transport/internet/quic/dialer.go b/transport/internet/quic/dialer.go index 131cec74..3d057dc9 100644 --- a/transport/internet/quic/dialer.go +++ b/transport/internet/quic/dialer.go @@ -154,7 +154,7 @@ func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsCo KeepAlive: true, } - conn, err := wrapSysConn(rawConn, config) + conn, err := wrapSysConn(rawConn.(*net.UDPConn), config) if err != nil { rawConn.Close() return nil, err diff --git a/transport/internet/quic/hub.go b/transport/internet/quic/hub.go index ee3cf053..d8524721 100644 --- a/transport/internet/quic/hub.go +++ b/transport/internet/quic/hub.go @@ -108,7 +108,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti MaxIncomingUniStreams: -1, } - conn, err := wrapSysConn(rawConn, config) + conn, err := wrapSysConn(rawConn.(*net.UDPConn), config) if err != nil { conn.Close() return nil, err