diff --git a/adapter/outbound/hysteria.go b/adapter/outbound/hysteria.go index b8f69d2d..dd0f78c0 100644 --- a/adapter/outbound/hysteria.go +++ b/adapter/outbound/hysteria.go @@ -47,7 +47,9 @@ type Hysteria struct { } func (h *Hysteria) DialContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.Conn, error) { - tcpConn, err := h.client.DialTCP(metadata.RemoteAddress()) + tcpConn, err := h.client.DialTCP(metadata.RemoteAddress(), hyDialer(func() (net.PacketConn, error) { + return dialer.ListenPacket(ctx, "udp", "", h.Base.DialOptions(opts...)...) + })) if err != nil { return nil, err } @@ -55,7 +57,9 @@ func (h *Hysteria) DialContext(ctx context.Context, metadata *C.Metadata, opts . } func (h *Hysteria) ListenPacketContext(ctx context.Context, metadata *C.Metadata, opts ...dialer.Option) (C.PacketConn, error) { - udpConn, err := h.client.DialUDP() + udpConn, err := h.client.DialUDP(hyDialer(func() (net.PacketConn, error) { + return dialer.ListenPacket(ctx, "udp", "", h.Base.DialOptions(opts...)...) + })) if err != nil { return nil, err } @@ -252,3 +256,9 @@ func (c *hyPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { n = len(p) return } + +type hyDialer func() (net.PacketConn, error) + +func (h hyDialer) ListenPacket() (net.PacketConn, error) { + return h() +} diff --git a/go.mod b/go.mod index b8d175fd..627ae2d5 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( replace github.com/vishvananda/netlink => github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820 -replace github.com/tobyxdd/hysteria => github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c +replace github.com/tobyxdd/hysteria => github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15 replace github.com/lucas-clemente/quic-go => github.com/tobyxdd/quic-go v0.27.1-0.20220512040129-ed2a645d9218 diff --git a/go.sum b/go.sum index 69fab4d5..b607e0c9 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c h1:lY+JVXfSLwe4RjjC0Vwi6xEVZtivWK/CD5wdUVHagVc= -github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c/go.mod h1:bXVjOca4Xf3JRenwuPKu02XaOiZwejrMSlgsu/U88J4= +github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15 h1:SraqLzYEGfrV8ETkVYc5evvCrn95hMFdCtcXXP8bA9Y= +github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15/go.mod h1:bXVjOca4Xf3JRenwuPKu02XaOiZwejrMSlgsu/U88J4= github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820 h1:fGKWZ25VApYnuPZoNeqdH/nZtHa2XMajwH6Yj/OgoVc= github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/test/go.mod b/test/go.mod index ead198f9..cd18184a 100644 --- a/test/go.mod +++ b/test/go.mod @@ -15,7 +15,7 @@ replace github.com/Dreamacro/clash => ../ replace github.com/vishvananda/netlink => github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820 -replace github.com/tobyxdd/hysteria => github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c +replace github.com/tobyxdd/hysteria => github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15 replace github.com/lucas-clemente/quic-go => github.com/tobyxdd/quic-go v0.27.1-0.20220512040129-ed2a645d9218 diff --git a/test/go.sum b/test/go.sum index c08e8a0b..a83dd82a 100644 --- a/test/go.sum +++ b/test/go.sum @@ -42,8 +42,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c h1:lY+JVXfSLwe4RjjC0Vwi6xEVZtivWK/CD5wdUVHagVc= -github.com/MetaCubeX/hysteria v1.0.5-0.20220607054137-3c4d6a5cb41c/go.mod h1:bXVjOca4Xf3JRenwuPKu02XaOiZwejrMSlgsu/U88J4= +github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15 h1:SraqLzYEGfrV8ETkVYc5evvCrn95hMFdCtcXXP8bA9Y= +github.com/MetaCubeX/hysteria v1.0.5-0.20220607074613-210c46c75b15/go.mod h1:bXVjOca4Xf3JRenwuPKu02XaOiZwejrMSlgsu/U88J4= github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820 h1:fGKWZ25VApYnuPZoNeqdH/nZtHa2XMajwH6Yj/OgoVc= github.com/MetaCubeX/netlink v1.2.0-beta.0.20220529072258-d6853f887820/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=