Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47cbf7fa3c | |||
| f7e6510199 | |||
| 025c87e54a | |||
| dff8ffb3da | |||
| 228f1e13aa | |||
| 15968585f3 | |||
| 4951994ebe | |||
| 756a2d1327 |
@@ -73,7 +73,6 @@
|
|||||||
- [Xray_bash_onekey](https://github.com/hello-yunshu/Xray_bash_onekey), [XTool](https://github.com/LordPenguin666/XTool), [VPainLess](https://github.com/vpainless/vpainless)
|
- [Xray_bash_onekey](https://github.com/hello-yunshu/Xray_bash_onekey), [XTool](https://github.com/LordPenguin666/XTool), [VPainLess](https://github.com/vpainless/vpainless)
|
||||||
- [v2ray-agent](https://github.com/mack-a/v2ray-agent), [Xray_onekey](https://github.com/wulabing/Xray_onekey), [ProxySU](https://github.com/proxysu/ProxySU)
|
- [v2ray-agent](https://github.com/mack-a/v2ray-agent), [Xray_onekey](https://github.com/wulabing/Xray_onekey), [ProxySU](https://github.com/proxysu/ProxySU)
|
||||||
- Magisk
|
- Magisk
|
||||||
- [NetProxy-Magisk](https://github.com/Fanju6/NetProxy-Magisk)
|
|
||||||
- [Xray4Magisk](https://github.com/Asterisk4Magisk/Xray4Magisk)
|
- [Xray4Magisk](https://github.com/Asterisk4Magisk/Xray4Magisk)
|
||||||
- [Xray_For_Magisk](https://github.com/E7KMbb/Xray_For_Magisk)
|
- [Xray_For_Magisk](https://github.com/E7KMbb/Xray_For_Magisk)
|
||||||
- Homebrew
|
- Homebrew
|
||||||
@@ -120,7 +119,6 @@
|
|||||||
- [SimpleXray](https://github.com/lhear/SimpleXray)
|
- [SimpleXray](https://github.com/lhear/SimpleXray)
|
||||||
- [XrayFA](https://github.com/Q7DF1/XrayFA)
|
- [XrayFA](https://github.com/Q7DF1/XrayFA)
|
||||||
- [AnyPortal](https://github.com/AnyPortal/AnyPortal)
|
- [AnyPortal](https://github.com/AnyPortal/AnyPortal)
|
||||||
- [NetProxy-Magisk](https://github.com/Fanju6/NetProxy-Magisk)
|
|
||||||
- [OneXray](https://github.com/OneXray/OneXray)
|
- [OneXray](https://github.com/OneXray/OneXray)
|
||||||
- iOS & macOS arm64 & tvOS
|
- iOS & macOS arm64 & tvOS
|
||||||
- [Happ](https://apps.apple.com/app/happ-proxy-utility/id6504287215) | [Happ RU](https://apps.apple.com/ru/app/happ-proxy-utility-plus/id6746188973) | [Happ tvOS](https://apps.apple.com/us/app/happ-proxy-utility-for-tv/id6748297274)
|
- [Happ](https://apps.apple.com/app/happ-proxy-utility/id6504287215) | [Happ RU](https://apps.apple.com/ru/app/happ-proxy-utility-plus/id6746188973) | [Happ tvOS](https://apps.apple.com/us/app/happ-proxy-utility-for-tv/id6748297274)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package singbridge
|
|||||||
import (
|
import (
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,14 +18,14 @@ func ToNetwork(network string) net.Network {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToDestination(socksaddr M.Socksaddr, network net.Network) net.Destination {
|
func ToDestination(socksaddr M.Socksaddr, network net.Network) (net.Destination, error) {
|
||||||
// IsFqdn() implicitly checks if the domain name is valid
|
// IsFqdn() implicitly checks if the domain name is valid
|
||||||
if socksaddr.IsFqdn() {
|
if socksaddr.IsFqdn() {
|
||||||
return net.Destination{
|
return net.Destination{
|
||||||
Network: network,
|
Network: network,
|
||||||
Address: net.DomainAddress(socksaddr.Fqdn),
|
Address: net.DomainAddress(socksaddr.Fqdn),
|
||||||
Port: net.Port(socksaddr.Port),
|
Port: net.Port(socksaddr.Port),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsIP() implicitly checks if the IP address is valid
|
// IsIP() implicitly checks if the IP address is valid
|
||||||
@@ -33,10 +34,10 @@ func ToDestination(socksaddr M.Socksaddr, network net.Network) net.Destination {
|
|||||||
Network: network,
|
Network: network,
|
||||||
Address: net.IPAddress(socksaddr.Addr.AsSlice()),
|
Address: net.IPAddress(socksaddr.Addr.AsSlice()),
|
||||||
Port: net.Port(socksaddr.Port),
|
Port: net.Port(socksaddr.Port),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return net.Destination{}
|
return net.Destination{}, errors.New("invalid socks address: ", socksaddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToSocksaddr(destination net.Destination) M.Socksaddr {
|
func ToSocksaddr(destination net.Destination) M.Socksaddr {
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ func NewDialer(dialer internet.Dialer) *XrayDialer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *XrayDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
func (d *XrayDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||||
return d.Dialer.Dial(ctx, ToDestination(destination, ToNetwork(network)))
|
dest, err := ToDestination(destination, ToNetwork(network))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return d.Dialer.Dial(ctx, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *XrayDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
func (d *XrayDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||||
@@ -43,13 +47,17 @@ func NewOutboundDialer(outbound proxy.Outbound, dialer internet.Dialer) *XrayOut
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *XrayOutboundDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
func (d *XrayOutboundDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||||
|
dest, err := ToDestination(destination, ToNetwork(network))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
if len(outbounds) == 0 {
|
if len(outbounds) == 0 {
|
||||||
outbounds = []*session.Outbound{{}}
|
outbounds = []*session.Outbound{{}}
|
||||||
ctx = session.ContextWithOutbounds(ctx, outbounds)
|
ctx = session.ContextWithOutbounds(ctx, outbounds)
|
||||||
}
|
}
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
ob.Target = ToDestination(destination, ToNetwork(network))
|
ob.Target = dest
|
||||||
|
|
||||||
opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)}
|
opts := []pipe.Option{pipe.WithSizeLimit(64 * 1024)}
|
||||||
uplinkReader, uplinkWriter := pipe.New(opts...)
|
uplinkReader, uplinkWriter := pipe.New(opts...)
|
||||||
|
|||||||
@@ -31,15 +31,23 @@ func NewDispatcher(dispatcher routing.Dispatcher, newErrorFunc func(values ...an
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dispatcher) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
|
func (d *Dispatcher) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
|
||||||
|
dest, err := ToDestination(metadata.Destination, net.Network_TCP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
xConn := NewConn(conn)
|
xConn := NewConn(conn)
|
||||||
return d.upstream.DispatchLink(ctx, ToDestination(metadata.Destination, net.Network_TCP), &transport.Link{
|
return d.upstream.DispatchLink(ctx, dest, &transport.Link{
|
||||||
Reader: xConn,
|
Reader: xConn,
|
||||||
Writer: xConn,
|
Writer: xConn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dispatcher) NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata M.Metadata) error {
|
func (d *Dispatcher) NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata M.Metadata) error {
|
||||||
return d.upstream.DispatchLink(ctx, ToDestination(metadata.Destination, net.Network_UDP), &transport.Link{
|
dest, err := ToDestination(metadata.Destination, net.Network_UDP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.upstream.DispatchLink(ctx, dest, &transport.Link{
|
||||||
Reader: buf.NewPacketReader(conn.(io.Reader)),
|
Reader: buf.NewPacketReader(conn.(io.Reader)),
|
||||||
Writer: buf.NewWriter(conn.(io.Writer)),
|
Writer: buf.NewWriter(conn.(io.Writer)),
|
||||||
})
|
})
|
||||||
|
|||||||
+22
-26
@@ -10,15 +10,21 @@ import (
|
|||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CopyPacketConn(ctx context.Context, inboundConn net.Conn, link *transport.Link, destination net.Destination, serverConn net.PacketConn) error {
|
func CopyPacketConn(ctx context.Context, inboundConn net.Conn, link *transport.Link, destination net.Destination, serverConn net.PacketConn) error {
|
||||||
|
cancel := func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
common.Interrupt(serverConn)
|
||||||
|
}
|
||||||
conn := &PacketConnWrapper{
|
conn := &PacketConnWrapper{
|
||||||
Reader: link.Reader,
|
Reader: link.Reader,
|
||||||
Writer: link.Writer,
|
Writer: link.Writer,
|
||||||
Dest: destination,
|
Dest: destination,
|
||||||
Conn: inboundConn,
|
Conn: inboundConn,
|
||||||
|
T: signal.CancelAfterInactivity(ctx, cancel, 300*time.Second),
|
||||||
}
|
}
|
||||||
return ReturnError(bufio.CopyPacketConn(ctx, conn, bufio.NewPacketConn(serverConn)))
|
return ReturnError(bufio.CopyPacketConn(ctx, conn, bufio.NewPacketConn(serverConn)))
|
||||||
}
|
}
|
||||||
@@ -29,11 +35,13 @@ type PacketConnWrapper struct {
|
|||||||
net.Conn
|
net.Conn
|
||||||
Dest net.Destination
|
Dest net.Destination
|
||||||
cached buf.MultiBuffer
|
cached buf.MultiBuffer
|
||||||
|
|
||||||
|
// A simple patch to avoid goroutine leak since sing infra cannot awake read block by write err
|
||||||
|
T *signal.ActivityTimer
|
||||||
}
|
}
|
||||||
|
|
||||||
// This ReadPacket implemented a timeout to avoid goroutine leak like PipeConnWrapper.Read()
|
|
||||||
// as a temporarily solution
|
|
||||||
func (w *PacketConnWrapper) ReadPacket(buffer *B.Buffer) (M.Socksaddr, error) {
|
func (w *PacketConnWrapper) ReadPacket(buffer *B.Buffer) (M.Socksaddr, error) {
|
||||||
|
w.T.Update()
|
||||||
if w.cached != nil {
|
if w.cached != nil {
|
||||||
mb, bb := buf.SplitFirst(w.cached)
|
mb, bb := buf.SplitFirst(w.cached)
|
||||||
if bb == nil {
|
if bb == nil {
|
||||||
@@ -51,30 +59,12 @@ func (w *PacketConnWrapper) ReadPacket(buffer *B.Buffer) (M.Socksaddr, error) {
|
|||||||
return ToSocksaddr(destination), nil
|
return ToSocksaddr(destination), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mb, err := w.ReadMultiBuffer()
|
||||||
// timeout
|
if err != nil {
|
||||||
type readResult struct {
|
// uplinkonly
|
||||||
mb buf.MultiBuffer
|
w.T.SetTimeout(3 * time.Second)
|
||||||
err error
|
return M.Socksaddr{}, err
|
||||||
}
|
}
|
||||||
c := make(chan readResult, 1)
|
|
||||||
go func() {
|
|
||||||
mb, err := w.ReadMultiBuffer()
|
|
||||||
c <- readResult{mb: mb, err: err}
|
|
||||||
}()
|
|
||||||
var mb buf.MultiBuffer
|
|
||||||
select {
|
|
||||||
case <-time.After(60 * time.Second):
|
|
||||||
common.Close(w.Reader)
|
|
||||||
common.Interrupt(w.Reader)
|
|
||||||
return M.Socksaddr{}, buf.ErrReadTimeout
|
|
||||||
case result := <-c:
|
|
||||||
if result.err != nil {
|
|
||||||
return M.Socksaddr{}, result.err
|
|
||||||
}
|
|
||||||
mb = result.mb
|
|
||||||
}
|
|
||||||
|
|
||||||
nb, bb := buf.SplitFirst(mb)
|
nb, bb := buf.SplitFirst(mb)
|
||||||
if bb == nil {
|
if bb == nil {
|
||||||
return M.Socksaddr{}, nil
|
return M.Socksaddr{}, nil
|
||||||
@@ -93,9 +83,15 @@ func (w *PacketConnWrapper) ReadPacket(buffer *B.Buffer) (M.Socksaddr, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *PacketConnWrapper) WritePacket(buffer *B.Buffer, destination M.Socksaddr) error {
|
func (w *PacketConnWrapper) WritePacket(buffer *B.Buffer, destination M.Socksaddr) error {
|
||||||
|
w.T.Update()
|
||||||
|
endpoint, err := ToDestination(destination, net.Network_UDP)
|
||||||
|
if err != nil {
|
||||||
|
// uplinkonly
|
||||||
|
w.T.SetTimeout(3 * time.Second)
|
||||||
|
return err
|
||||||
|
}
|
||||||
vBuf := buf.New()
|
vBuf := buf.New()
|
||||||
vBuf.Write(buffer.Bytes())
|
vBuf.Write(buffer.Bytes())
|
||||||
endpoint := ToDestination(destination, net.Network_UDP)
|
|
||||||
vBuf.UDP = &endpoint
|
vBuf.UDP = &endpoint
|
||||||
return w.Writer.WriteMultiBuffer(buf.MultiBuffer{vBuf})
|
return w.Writer.WriteMultiBuffer(buf.MultiBuffer{vBuf})
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,6 +23,11 @@ func CopyConn(ctx context.Context, inboundConn net.Conn, link *transport.Link, s
|
|||||||
} else {
|
} else {
|
||||||
conn.R = &buf.BufferedReader{Reader: link.Reader}
|
conn.R = &buf.BufferedReader{Reader: link.Reader}
|
||||||
}
|
}
|
||||||
|
cancel := func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
common.Interrupt(serverConn)
|
||||||
|
}
|
||||||
|
conn.T = signal.CancelAfterInactivity(ctx, cancel, 300*time.Second)
|
||||||
return ReturnError(bufio.CopyConn(ctx, conn, serverConn))
|
return ReturnError(bufio.CopyConn(ctx, conn, serverConn))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,35 +35,27 @@ type PipeConnWrapper struct {
|
|||||||
R io.Reader
|
R io.Reader
|
||||||
W buf.Writer
|
W buf.Writer
|
||||||
net.Conn
|
net.Conn
|
||||||
|
|
||||||
|
// A simple patch to avoid goroutine leak since sing infra cannot awake read block by write err
|
||||||
|
T *signal.ActivityTimer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PipeConnWrapper) Close() error {
|
func (w *PipeConnWrapper) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This Read implemented a timeout to avoid goroutine leak.
|
|
||||||
// as a temporarily solution
|
|
||||||
func (w *PipeConnWrapper) Read(b []byte) (n int, err error) {
|
func (w *PipeConnWrapper) Read(b []byte) (n int, err error) {
|
||||||
type readResult struct {
|
w.T.Update()
|
||||||
n int
|
n, err = w.R.Read(b)
|
||||||
err error
|
if err != nil {
|
||||||
}
|
// uplinkonly
|
||||||
c := make(chan readResult, 1)
|
w.T.SetTimeout(3 * time.Second)
|
||||||
go func() {
|
|
||||||
n, err := w.R.Read(b)
|
|
||||||
c <- readResult{n: n, err: err}
|
|
||||||
}()
|
|
||||||
select {
|
|
||||||
case result := <-c:
|
|
||||||
return result.n, result.err
|
|
||||||
case <-time.After(300 * time.Second):
|
|
||||||
common.Close(w.R)
|
|
||||||
common.Interrupt(w.R)
|
|
||||||
return 0, buf.ErrReadTimeout
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PipeConnWrapper) Write(p []byte) (n int, err error) {
|
func (w *PipeConnWrapper) Write(p []byte) (n int, err error) {
|
||||||
|
w.T.Update()
|
||||||
n = len(p)
|
n = len(p)
|
||||||
var mb buf.MultiBuffer
|
var mb buf.MultiBuffer
|
||||||
pLen := len(p)
|
pLen := len(p)
|
||||||
@@ -76,6 +74,8 @@ func (w *PipeConnWrapper) Write(p []byte) (n int, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
n = 0
|
n = 0
|
||||||
buf.ReleaseMulti(mb)
|
buf.ReleaseMulti(mb)
|
||||||
|
// downlinkonly
|
||||||
|
w.T.SetTimeout(3 * time.Second)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
Version_x byte = 26
|
Version_x byte = 26
|
||||||
Version_y byte = 4
|
Version_y byte = 5
|
||||||
Version_z byte = 25
|
Version_z byte = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -497,8 +497,8 @@ func (b Bandwidth) Bps() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UdpHop struct {
|
type UdpHop struct {
|
||||||
PortList json.RawMessage `json:"ports"`
|
PortList PortList `json:"ports"`
|
||||||
Interval *Int32Range `json:"interval"`
|
Interval Int32Range `json:"interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Masquerade struct {
|
type Masquerade struct {
|
||||||
@@ -2142,18 +2142,7 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
return nil, errors.New("unknown congestion control: ", c.FinalMask.QuicParams.Congestion, ", valid values: reno, bbr, brutal, force-brutal")
|
return nil, errors.New("unknown congestion control: ", c.FinalMask.QuicParams.Congestion, ", valid values: reno, bbr, brutal, force-brutal")
|
||||||
}
|
}
|
||||||
|
|
||||||
var hop *PortList
|
if (c.FinalMask.QuicParams.UdpHop.Interval.From != 0 && c.FinalMask.QuicParams.UdpHop.Interval.From < 5) || (c.FinalMask.QuicParams.UdpHop.Interval.To != 0 && c.FinalMask.QuicParams.UdpHop.Interval.To < 5) {
|
||||||
if err := json.Unmarshal(c.FinalMask.QuicParams.UdpHop.PortList, &hop); err != nil {
|
|
||||||
hop = &PortList{}
|
|
||||||
}
|
|
||||||
|
|
||||||
var inertvalMin, inertvalMax int64
|
|
||||||
if c.FinalMask.QuicParams.UdpHop.Interval != nil {
|
|
||||||
inertvalMin = int64(c.FinalMask.QuicParams.UdpHop.Interval.From)
|
|
||||||
inertvalMax = int64(c.FinalMask.QuicParams.UdpHop.Interval.To)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inertvalMin != 0 && inertvalMin < 5) || (inertvalMax != 0 && inertvalMax < 5) {
|
|
||||||
return nil, errors.New("Interval must be at least 5")
|
return nil, errors.New("Interval must be at least 5")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2190,9 +2179,9 @@ func (c *StreamConfig) Build() (*internet.StreamConfig, error) {
|
|||||||
BrutalUp: up,
|
BrutalUp: up,
|
||||||
BrutalDown: down,
|
BrutalDown: down,
|
||||||
UdpHop: &internet.UdpHop{
|
UdpHop: &internet.UdpHop{
|
||||||
Ports: hop.Build().Ports(),
|
Ports: c.FinalMask.QuicParams.UdpHop.PortList.Build().Ports(),
|
||||||
IntervalMin: inertvalMin,
|
IntervalMin: int64(c.FinalMask.QuicParams.UdpHop.Interval.From),
|
||||||
IntervalMax: inertvalMax,
|
IntervalMax: int64(c.FinalMask.QuicParams.UdpHop.Interval.To),
|
||||||
},
|
},
|
||||||
InitStreamReceiveWindow: c.FinalMask.QuicParams.InitStreamReceiveWindow,
|
InitStreamReceiveWindow: c.FinalMask.QuicParams.InitStreamReceiveWindow,
|
||||||
MaxStreamReceiveWindow: c.FinalMask.QuicParams.MaxStreamReceiveWindow,
|
MaxStreamReceiveWindow: c.FinalMask.QuicParams.MaxStreamReceiveWindow,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package shadowsocks_2022
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
shadowsocks "github.com/sagernet/sing-shadowsocks"
|
shadowsocks "github.com/sagernet/sing-shadowsocks"
|
||||||
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
||||||
@@ -18,6 +19,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/common/singbridge"
|
"github.com/xtls/xray-core/common/singbridge"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
"github.com/xtls/xray-core/transport/internet/stat"
|
||||||
@@ -115,7 +117,11 @@ func (i *Inbound) NewConnection(ctx context.Context, conn net.Conn, metadata M.M
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -136,7 +142,10 @@ func (i *Inbound) NewPacketConnection(ctx context.Context, conn N.PacketConn, me
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
link, err := dispatcher.Dispatch(ctx, destination)
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -145,6 +154,9 @@ func (i *Inbound) NewPacketConnection(ctx context.Context, conn N.PacketConn, me
|
|||||||
Reader: link.Reader,
|
Reader: link.Reader,
|
||||||
Writer: link.Writer,
|
Writer: link.Writer,
|
||||||
Dest: destination,
|
Dest: destination,
|
||||||
|
T: signal.CancelAfterInactivity(ctx, func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
}, 300*time.Second),
|
||||||
}
|
}
|
||||||
return bufio.CopyPacketConn(ctx, conn, outConn)
|
return bufio.CopyPacketConn(ctx, conn, outConn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
||||||
C "github.com/sagernet/sing/common"
|
C "github.com/sagernet/sing/common"
|
||||||
@@ -22,6 +23,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/common/singbridge"
|
"github.com/xtls/xray-core/common/singbridge"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
@@ -237,11 +239,10 @@ func (i *MultiUserInbound) NewConnection(ctx context.Context, conn net.Conn, met
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
|
||||||
if !destination.IsValid() {
|
if err != nil {
|
||||||
return errors.New("invalid destination")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
link, err := dispatcher.Dispatch(ctx, destination)
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -262,7 +263,10 @@ func (i *MultiUserInbound) NewPacketConnection(ctx context.Context, conn N.Packe
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
link, err := dispatcher.Dispatch(ctx, destination)
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -271,6 +275,9 @@ func (i *MultiUserInbound) NewPacketConnection(ctx context.Context, conn N.Packe
|
|||||||
Reader: link.Reader,
|
Reader: link.Reader,
|
||||||
Writer: link.Writer,
|
Writer: link.Writer,
|
||||||
Dest: destination,
|
Dest: destination,
|
||||||
|
T: signal.CancelAfterInactivity(ctx, func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
}, 300*time.Second),
|
||||||
}
|
}
|
||||||
return bufio.CopyPacketConn(ctx, conn, outConn)
|
return bufio.CopyPacketConn(ctx, conn, outConn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
|
||||||
C "github.com/sagernet/sing/common"
|
C "github.com/sagernet/sing/common"
|
||||||
@@ -20,6 +21,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/common/singbridge"
|
"github.com/xtls/xray-core/common/singbridge"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
"github.com/xtls/xray-core/features/routing"
|
"github.com/xtls/xray-core/features/routing"
|
||||||
@@ -138,7 +140,11 @@ func (i *RelayInbound) NewConnection(ctx context.Context, conn net.Conn, metadat
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to tcp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -161,7 +167,10 @@ func (i *RelayInbound) NewPacketConnection(ctx context.Context, conn N.PacketCon
|
|||||||
})
|
})
|
||||||
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
errors.LogInfo(ctx, "tunnelling request to udp:", metadata.Destination)
|
||||||
dispatcher := session.DispatcherFromContext(ctx)
|
dispatcher := session.DispatcherFromContext(ctx)
|
||||||
destination := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
destination, err := singbridge.ToDestination(metadata.Destination, net.Network_UDP)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
link, err := dispatcher.Dispatch(ctx, destination)
|
link, err := dispatcher.Dispatch(ctx, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -170,6 +179,9 @@ func (i *RelayInbound) NewPacketConnection(ctx context.Context, conn N.PacketCon
|
|||||||
Reader: link.Reader,
|
Reader: link.Reader,
|
||||||
Writer: link.Writer,
|
Writer: link.Writer,
|
||||||
Dest: destination,
|
Dest: destination,
|
||||||
|
T: signal.CancelAfterInactivity(ctx, func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
}, 300*time.Second),
|
||||||
}
|
}
|
||||||
return bufio.CopyPacketConn(ctx, conn, outConn)
|
return bufio.CopyPacketConn(ctx, conn, outConn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/session"
|
"github.com/xtls/xray-core/common/session"
|
||||||
|
"github.com/xtls/xray-core/common/signal"
|
||||||
"github.com/xtls/xray-core/common/singbridge"
|
"github.com/xtls/xray-core/common/singbridge"
|
||||||
"github.com/xtls/xray-core/transport"
|
"github.com/xtls/xray-core/transport"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
@@ -142,6 +143,9 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
|
|||||||
Writer: link.Writer,
|
Writer: link.Writer,
|
||||||
Conn: inboundConn,
|
Conn: inboundConn,
|
||||||
Dest: destination,
|
Dest: destination,
|
||||||
|
T: signal.CancelAfterInactivity(ctx, func() {
|
||||||
|
common.Interrupt(link.Reader)
|
||||||
|
}, 300*time.Second),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -730,8 +730,6 @@ type SocketConfig struct {
|
|||||||
// ReceiveOriginalDestAddress is for enabling IP_RECVORIGDSTADDR socket
|
// ReceiveOriginalDestAddress is for enabling IP_RECVORIGDSTADDR socket
|
||||||
// option. This option is for UDP only.
|
// option. This option is for UDP only.
|
||||||
ReceiveOriginalDestAddress bool `protobuf:"varint,4,opt,name=receive_original_dest_address,json=receiveOriginalDestAddress,proto3" json:"receive_original_dest_address,omitempty"`
|
ReceiveOriginalDestAddress bool `protobuf:"varint,4,opt,name=receive_original_dest_address,json=receiveOriginalDestAddress,proto3" json:"receive_original_dest_address,omitempty"`
|
||||||
BindAddress []byte `protobuf:"bytes,5,opt,name=bind_address,json=bindAddress,proto3" json:"bind_address,omitempty"`
|
|
||||||
BindPort uint32 `protobuf:"varint,6,opt,name=bind_port,json=bindPort,proto3" json:"bind_port,omitempty"`
|
|
||||||
AcceptProxyProtocol bool `protobuf:"varint,7,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"`
|
AcceptProxyProtocol bool `protobuf:"varint,7,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"`
|
||||||
DomainStrategy DomainStrategy `protobuf:"varint,8,opt,name=domain_strategy,json=domainStrategy,proto3,enum=xray.transport.internet.DomainStrategy" json:"domain_strategy,omitempty"`
|
DomainStrategy DomainStrategy `protobuf:"varint,8,opt,name=domain_strategy,json=domainStrategy,proto3,enum=xray.transport.internet.DomainStrategy" json:"domain_strategy,omitempty"`
|
||||||
DialerProxy string `protobuf:"bytes,9,opt,name=dialer_proxy,json=dialerProxy,proto3" json:"dialer_proxy,omitempty"`
|
DialerProxy string `protobuf:"bytes,9,opt,name=dialer_proxy,json=dialerProxy,proto3" json:"dialer_proxy,omitempty"`
|
||||||
@@ -811,20 +809,6 @@ func (x *SocketConfig) GetReceiveOriginalDestAddress() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SocketConfig) GetBindAddress() []byte {
|
|
||||||
if x != nil {
|
|
||||||
return x.BindAddress
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SocketConfig) GetBindPort() uint32 {
|
|
||||||
if x != nil {
|
|
||||||
return x.BindPort
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (x *SocketConfig) GetAcceptProxyProtocol() bool {
|
func (x *SocketConfig) GetAcceptProxyProtocol() bool {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.AcceptProxyProtocol
|
return x.AcceptProxyProtocol
|
||||||
@@ -1066,14 +1050,12 @@ const file_transport_internet_config_proto_rawDesc = "" +
|
|||||||
"\x05level\x18\x03 \x01(\tR\x05level\x12\x10\n" +
|
"\x05level\x18\x03 \x01(\tR\x05level\x12\x10\n" +
|
||||||
"\x03opt\x18\x04 \x01(\tR\x03opt\x12\x14\n" +
|
"\x03opt\x18\x04 \x01(\tR\x03opt\x12\x14\n" +
|
||||||
"\x05value\x18\x05 \x01(\tR\x05value\x12\x12\n" +
|
"\x05value\x18\x05 \x01(\tR\x05value\x12\x12\n" +
|
||||||
"\x04type\x18\x06 \x01(\tR\x04type\"\x89\t\n" +
|
"\x04type\x18\x06 \x01(\tR\x04type\"\xc9\b\n" +
|
||||||
"\fSocketConfig\x12\x12\n" +
|
"\fSocketConfig\x12\x12\n" +
|
||||||
"\x04mark\x18\x01 \x01(\x05R\x04mark\x12\x10\n" +
|
"\x04mark\x18\x01 \x01(\x05R\x04mark\x12\x10\n" +
|
||||||
"\x03tfo\x18\x02 \x01(\x05R\x03tfo\x12H\n" +
|
"\x03tfo\x18\x02 \x01(\x05R\x03tfo\x12H\n" +
|
||||||
"\x06tproxy\x18\x03 \x01(\x0e20.xray.transport.internet.SocketConfig.TProxyModeR\x06tproxy\x12A\n" +
|
"\x06tproxy\x18\x03 \x01(\x0e20.xray.transport.internet.SocketConfig.TProxyModeR\x06tproxy\x12A\n" +
|
||||||
"\x1dreceive_original_dest_address\x18\x04 \x01(\bR\x1areceiveOriginalDestAddress\x12!\n" +
|
"\x1dreceive_original_dest_address\x18\x04 \x01(\bR\x1areceiveOriginalDestAddress\x122\n" +
|
||||||
"\fbind_address\x18\x05 \x01(\fR\vbindAddress\x12\x1b\n" +
|
|
||||||
"\tbind_port\x18\x06 \x01(\rR\bbindPort\x122\n" +
|
|
||||||
"\x15accept_proxy_protocol\x18\a \x01(\bR\x13acceptProxyProtocol\x12P\n" +
|
"\x15accept_proxy_protocol\x18\a \x01(\bR\x13acceptProxyProtocol\x12P\n" +
|
||||||
"\x0fdomain_strategy\x18\b \x01(\x0e2'.xray.transport.internet.DomainStrategyR\x0edomainStrategy\x12!\n" +
|
"\x0fdomain_strategy\x18\b \x01(\x0e2'.xray.transport.internet.DomainStrategyR\x0edomainStrategy\x12!\n" +
|
||||||
"\fdialer_proxy\x18\t \x01(\tR\vdialerProxy\x125\n" +
|
"\fdialer_proxy\x18\t \x01(\tR\vdialerProxy\x125\n" +
|
||||||
|
|||||||
@@ -124,10 +124,6 @@ message SocketConfig {
|
|||||||
// option. This option is for UDP only.
|
// option. This option is for UDP only.
|
||||||
bool receive_original_dest_address = 4;
|
bool receive_original_dest_address = 4;
|
||||||
|
|
||||||
bytes bind_address = 5;
|
|
||||||
|
|
||||||
uint32 bind_port = 6;
|
|
||||||
|
|
||||||
bool accept_proxy_protocol = 7;
|
bool accept_proxy_protocol = 7;
|
||||||
|
|
||||||
DomainStrategy domain_strategy = 8;
|
DomainStrategy domain_strategy = 8;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package hysteria
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
go_tls "crypto/tls"
|
go_tls "crypto/tls"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -64,7 +65,7 @@ func (c *client) close() {
|
|||||||
c.udpSM = nil
|
c.udpSM = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) dial() error {
|
func (c *client) dial(ctx context.Context) error {
|
||||||
status := c.status()
|
status := c.status()
|
||||||
if status == StatusActive {
|
if status == StatusActive {
|
||||||
return nil
|
return nil
|
||||||
@@ -113,30 +114,54 @@ func (c *client) dial() error {
|
|||||||
// quicConfig.KeepAlivePeriod = 10 * time.Second
|
// quicConfig.KeepAlivePeriod = 10 * time.Second
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
udpHopDialer := func(addr *net.UDPAddr) (net.PacketConn, error) {
|
||||||
|
conn, err := internet.DialSystem(ctx, net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)), c.socketConfig)
|
||||||
|
if err != nil {
|
||||||
|
errors.LogInfoInner(context.Background(), err, "skip hop: failed to dial to dest")
|
||||||
|
return nil, errors.New("")
|
||||||
|
}
|
||||||
|
|
||||||
|
var pktConn net.PacketConn
|
||||||
|
|
||||||
|
switch c := conn.(type) {
|
||||||
|
case *internet.PacketConnWrapper:
|
||||||
|
pktConn = c.PacketConn
|
||||||
|
default:
|
||||||
|
panic(reflect.TypeOf(c))
|
||||||
|
}
|
||||||
|
|
||||||
|
return pktConn, nil
|
||||||
|
}
|
||||||
|
|
||||||
var pktConn net.PacketConn
|
var pktConn net.PacketConn
|
||||||
var udpAddr *net.UDPAddr
|
var udpAddr *net.UDPAddr
|
||||||
var err error
|
|
||||||
udpAddr, err = net.ResolveUDPAddr("udp", c.dest.NetAddr())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(quicParams.UdpHop.Ports) > 0 {
|
if len(quicParams.UdpHop.Ports) > 0 {
|
||||||
pktConn, err = udphop.NewUDPHopPacketConn(udphop.ToAddrs(udpAddr.IP, quicParams.UdpHop.Ports), time.Duration(quicParams.UdpHop.IntervalMin)*time.Second, time.Duration(quicParams.UdpHop.IntervalMax)*time.Second, c.udpHopDialer)
|
index := rand.Intn(len(quicParams.UdpHop.Ports))
|
||||||
|
c.dest.Port = net.Port(quicParams.UdpHop.Ports[index])
|
||||||
|
conn, err := internet.DialSystem(ctx, c.dest, c.socketConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errors.New("failed to dial to dest").Base(err)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
conn, err := internet.DialSystem(context.Background(), c.dest, c.socketConfig)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
switch c := conn.(type) {
|
switch c := conn.(type) {
|
||||||
case *internet.PacketConnWrapper:
|
case *internet.PacketConnWrapper:
|
||||||
pktConn = c.PacketConn
|
pktConn = c.PacketConn
|
||||||
case *net.UDPConn:
|
udpAddr = conn.RemoteAddr().(*net.UDPAddr)
|
||||||
pktConn = c
|
default:
|
||||||
|
panic(reflect.TypeOf(c))
|
||||||
|
}
|
||||||
|
pktConn = udphop.NewUDPHopPacketConn(udphop.ToAddrs(udpAddr.IP, quicParams.UdpHop.Ports), time.Duration(quicParams.UdpHop.IntervalMin)*time.Second, time.Duration(quicParams.UdpHop.IntervalMax)*time.Second, udpHopDialer, pktConn, index)
|
||||||
|
} else {
|
||||||
|
conn, err := internet.DialSystem(ctx, c.dest, c.socketConfig)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("failed to dial to dest").Base(err)
|
||||||
|
}
|
||||||
|
switch c := conn.(type) {
|
||||||
|
case *internet.PacketConnWrapper:
|
||||||
|
pktConn = c.PacketConn
|
||||||
|
udpAddr = c.RemoteAddr().(*net.UDPAddr)
|
||||||
case *cnc.Connection:
|
case *cnc.Connection:
|
||||||
pktConn = &internet.FakePacketConn{Conn: c}
|
pktConn = &internet.FakePacketConn{Conn: c}
|
||||||
|
udpAddr = &net.UDPAddr{IP: c.RemoteAddr().(*net.TCPAddr).IP, Port: c.RemoteAddr().(*net.TCPAddr).Port}
|
||||||
default:
|
default:
|
||||||
panic(reflect.TypeOf(c))
|
panic(reflect.TypeOf(c))
|
||||||
}
|
}
|
||||||
@@ -228,11 +253,11 @@ func (c *client) dial() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) tcp() (stat.Connection, error) {
|
func (c *client) tcp(ctx context.Context) (stat.Connection, error) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
err := c.dial()
|
err := c.dial(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -251,11 +276,11 @@ func (c *client) tcp() (stat.Connection, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) udp() (stat.Connection, error) {
|
func (c *client) udp(ctx context.Context) (stat.Connection, error) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
err := c.dial()
|
err := c.dial(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -271,29 +296,6 @@ func (c *client) clean() {
|
|||||||
c.Unlock()
|
c.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) udpHopDialer(addr *net.UDPAddr) (net.PacketConn, error) {
|
|
||||||
conn, err := internet.DialSystem(context.Background(), net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)), c.socketConfig)
|
|
||||||
if err != nil {
|
|
||||||
errors.LogInfoInner(context.Background(), err, "skip hop: failed to dial to dest")
|
|
||||||
return nil, errors.New("failed to dial to dest").Base(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var pktConn net.PacketConn
|
|
||||||
|
|
||||||
switch c := conn.(type) {
|
|
||||||
case *internet.PacketConnWrapper:
|
|
||||||
pktConn = c.PacketConn
|
|
||||||
case *net.UDPConn:
|
|
||||||
pktConn = c
|
|
||||||
default:
|
|
||||||
errors.LogInfo(context.Background(), "skip hop: invalid conn ", reflect.TypeOf(c))
|
|
||||||
conn.Close()
|
|
||||||
return nil, errors.New("invalid conn ", reflect.TypeOf(c))
|
|
||||||
}
|
|
||||||
|
|
||||||
return pktConn, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type dialerConf struct {
|
type dialerConf struct {
|
||||||
net.Destination
|
net.Destination
|
||||||
*internet.MemoryStreamConfig
|
*internet.MemoryStreamConfig
|
||||||
@@ -356,9 +358,9 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
if datagram {
|
if datagram {
|
||||||
return c.udp()
|
return c.udp(ctx)
|
||||||
}
|
}
|
||||||
return c.tcp()
|
return c.tcp(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ type udpPacket struct {
|
|||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUDPHopPacketConn(addrs []net.Addr, hopIntervalMin time.Duration, hopIntervalMax time.Duration, listenUDPFunc func(addr *net.UDPAddr) (net.PacketConn, error)) (net.PacketConn, error) {
|
func NewUDPHopPacketConn(addrs []net.Addr, hopIntervalMin time.Duration, hopIntervalMax time.Duration, listenUDPFunc func(addr *net.UDPAddr) (net.PacketConn, error), currentConn net.PacketConn, addrIndex int) net.PacketConn {
|
||||||
if len(addrs) == 0 {
|
if len(addrs) == 0 {
|
||||||
panic("len(addrs) == 0")
|
panic("len(addrs) == 0")
|
||||||
}
|
}
|
||||||
@@ -75,8 +75,8 @@ func NewUDPHopPacketConn(addrs []net.Addr, hopIntervalMin time.Duration, hopInte
|
|||||||
HopIntervalMax: hopIntervalMax,
|
HopIntervalMax: hopIntervalMax,
|
||||||
ListenUDPFunc: listenUDPFunc,
|
ListenUDPFunc: listenUDPFunc,
|
||||||
prevConn: nil,
|
prevConn: nil,
|
||||||
currentConn: nil,
|
currentConn: currentConn,
|
||||||
addrIndex: rand.Intn(len(addrs)),
|
addrIndex: addrIndex,
|
||||||
recvQueue: make(chan *udpPacket, packetQueueSize),
|
recvQueue: make(chan *udpPacket, packetQueueSize),
|
||||||
closeChan: make(chan struct{}),
|
closeChan: make(chan struct{}),
|
||||||
bufPool: sync.Pool{
|
bufPool: sync.Pool{
|
||||||
@@ -85,14 +85,9 @@ func NewUDPHopPacketConn(addrs []net.Addr, hopIntervalMin time.Duration, hopInte
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var err error
|
|
||||||
hConn.currentConn, err = listenUDPFunc(hConn.Addrs[hConn.addrIndex].(*net.UDPAddr))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
go hConn.recvLoop(hConn.currentConn)
|
go hConn.recvLoop(hConn.currentConn)
|
||||||
go hConn.hopLoop()
|
go hConn.hopLoop()
|
||||||
return hConn, nil
|
return hConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UdpHopPacketConn) recvLoop(conn net.PacketConn) {
|
func (u *UdpHopPacketConn) recvLoop(conn net.PacketConn) {
|
||||||
|
|||||||
@@ -58,14 +58,14 @@ func DialKCP(ctx context.Context, dest net.Destination, streamSettings *internet
|
|||||||
|
|
||||||
if streamSettings.UdpmaskManager != nil {
|
if streamSettings.UdpmaskManager != nil {
|
||||||
var pktConn net.PacketConn
|
var pktConn net.PacketConn
|
||||||
var udpAddr = conn.RemoteAddr().(*net.UDPAddr)
|
var udpAddr *net.UDPAddr
|
||||||
switch c := conn.(type) {
|
switch c := conn.(type) {
|
||||||
case *internet.PacketConnWrapper:
|
case *internet.PacketConnWrapper:
|
||||||
pktConn = c.PacketConn
|
pktConn = c.PacketConn
|
||||||
case *net.UDPConn:
|
udpAddr = c.RemoteAddr().(*net.UDPAddr)
|
||||||
pktConn = c
|
|
||||||
case *cnc.Connection:
|
case *cnc.Connection:
|
||||||
pktConn = &internet.FakePacketConn{Conn: c}
|
pktConn = &internet.FakePacketConn{Conn: c}
|
||||||
|
udpAddr = &net.UDPAddr{IP: c.RemoteAddr().(*net.TCPAddr).IP, Port: c.RemoteAddr().(*net.TCPAddr).Port}
|
||||||
default:
|
default:
|
||||||
panic(reflect.TypeOf(c))
|
panic(reflect.TypeOf(c))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,32 +288,6 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindAddr(fd uintptr, address []byte, port uint32) error {
|
|
||||||
setReuseAddr(fd)
|
|
||||||
setReusePort(fd)
|
|
||||||
|
|
||||||
var sockaddr unix.Sockaddr
|
|
||||||
|
|
||||||
switch len(address) {
|
|
||||||
case net.IPv4len:
|
|
||||||
a4 := &unix.SockaddrInet4{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a4.Addr[:], address)
|
|
||||||
sockaddr = a4
|
|
||||||
case net.IPv6len:
|
|
||||||
a6 := &unix.SockaddrInet6{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a6.Addr[:], address)
|
|
||||||
sockaddr = a6
|
|
||||||
default:
|
|
||||||
return errors.New("unexpected length of ip")
|
|
||||||
}
|
|
||||||
|
|
||||||
return unix.Bind(int(fd), sockaddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setReuseAddr(fd uintptr) error {
|
func setReuseAddr(fd uintptr) error {
|
||||||
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
|
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
|
||||||
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
|
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
|
||||||
|
|||||||
@@ -222,32 +222,6 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
|
||||||
setReuseAddr(fd)
|
|
||||||
setReusePort(fd)
|
|
||||||
|
|
||||||
var sockaddr syscall.Sockaddr
|
|
||||||
|
|
||||||
switch len(ip) {
|
|
||||||
case net.IPv4len:
|
|
||||||
a4 := &syscall.SockaddrInet4{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a4.Addr[:], ip)
|
|
||||||
sockaddr = a4
|
|
||||||
case net.IPv6len:
|
|
||||||
a6 := &syscall.SockaddrInet6{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a6.Addr[:], ip)
|
|
||||||
sockaddr = a6
|
|
||||||
default:
|
|
||||||
return errors.New("unexpected length of ip")
|
|
||||||
}
|
|
||||||
|
|
||||||
return syscall.Bind(int(fd), sockaddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setReuseAddr(fd uintptr) error {
|
func setReuseAddr(fd uintptr) error {
|
||||||
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
|
||||||
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
|
return errors.New("failed to set SO_REUSEADDR").Base(err).AtWarning()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package internet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,32 +11,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
|
||||||
setReuseAddr(fd)
|
|
||||||
setReusePort(fd)
|
|
||||||
|
|
||||||
var sockaddr syscall.Sockaddr
|
|
||||||
|
|
||||||
switch len(ip) {
|
|
||||||
case net.IPv4len:
|
|
||||||
a4 := &syscall.SockaddrInet4{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a4.Addr[:], ip)
|
|
||||||
sockaddr = a4
|
|
||||||
case net.IPv6len:
|
|
||||||
a6 := &syscall.SockaddrInet6{
|
|
||||||
Port: int(port),
|
|
||||||
}
|
|
||||||
copy(a6.Addr[:], ip)
|
|
||||||
sockaddr = a6
|
|
||||||
default:
|
|
||||||
return errors.New("unexpected length of ip")
|
|
||||||
}
|
|
||||||
|
|
||||||
return syscall.Bind(int(fd), sockaddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
// applyOutboundSocketOptions applies socket options for outbound connection.
|
// applyOutboundSocketOptions applies socket options for outbound connection.
|
||||||
// note that unlike other part of Xray, this function needs network with speified network stack(tcp4/tcp6/udp4/udp6)
|
// note that unlike other part of Xray, this function needs network with speified network stack(tcp4/tcp6/udp4/udp6)
|
||||||
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setReuseAddr(fd uintptr) error {
|
func setReuseAddr(fd uintptr) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,10 +181,6 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setReuseAddr(fd uintptr) error {
|
func setReuseAddr(fd uintptr) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
gotls "crypto/tls"
|
gotls "crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -199,7 +200,7 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
conn, err := internet.DialSystem(ctx, net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)), streamSettings.SocketSettings)
|
conn, err := internet.DialSystem(ctx, net.UDPDestination(net.IPAddress(addr.IP), net.Port(addr.Port)), streamSettings.SocketSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogInfoInner(context.Background(), err, "skip hop: failed to dial to dest")
|
errors.LogInfoInner(context.Background(), err, "skip hop: failed to dial to dest")
|
||||||
return nil, errors.New("failed to dial to dest").Base(err)
|
return nil, errors.New("")
|
||||||
}
|
}
|
||||||
|
|
||||||
var pktConn net.PacketConn
|
var pktConn net.PacketConn
|
||||||
@@ -207,12 +208,8 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
switch c := conn.(type) {
|
switch c := conn.(type) {
|
||||||
case *internet.PacketConnWrapper:
|
case *internet.PacketConnWrapper:
|
||||||
pktConn = c.PacketConn
|
pktConn = c.PacketConn
|
||||||
case *net.UDPConn:
|
|
||||||
pktConn = c
|
|
||||||
default:
|
default:
|
||||||
errors.LogInfo(context.Background(), "skip hop: invalid conn ", reflect.TypeOf(c))
|
panic(reflect.TypeOf(c))
|
||||||
conn.Close()
|
|
||||||
return nil, errors.New("invalid conn ", reflect.TypeOf(c))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pktConn, nil
|
return pktConn, nil
|
||||||
@@ -220,28 +217,33 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
|
|
||||||
var pktConn net.PacketConn
|
var pktConn net.PacketConn
|
||||||
var udpAddr *net.UDPAddr
|
var udpAddr *net.UDPAddr
|
||||||
var err error
|
|
||||||
udpAddr, err = net.ResolveUDPAddr("udp", dest.NetAddr())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(quicParams.UdpHop.Ports) > 0 {
|
if len(quicParams.UdpHop.Ports) > 0 {
|
||||||
pktConn, err = udphop.NewUDPHopPacketConn(udphop.ToAddrs(udpAddr.IP, quicParams.UdpHop.Ports), time.Duration(quicParams.UdpHop.IntervalMin)*time.Second, time.Duration(quicParams.UdpHop.IntervalMax)*time.Second, udpHopDialer)
|
index := rand.Intn(len(quicParams.UdpHop.Ports))
|
||||||
if err != nil {
|
dest.Port = net.Port(quicParams.UdpHop.Ports[index])
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, errors.New("failed to dial to dest").Base(err)
|
||||||
}
|
}
|
||||||
switch c := conn.(type) {
|
switch c := conn.(type) {
|
||||||
case *internet.PacketConnWrapper:
|
case *internet.PacketConnWrapper:
|
||||||
pktConn = c.PacketConn
|
pktConn = c.PacketConn
|
||||||
case *net.UDPConn:
|
udpAddr = conn.RemoteAddr().(*net.UDPAddr)
|
||||||
pktConn = c
|
default:
|
||||||
|
panic(reflect.TypeOf(c))
|
||||||
|
}
|
||||||
|
pktConn = udphop.NewUDPHopPacketConn(udphop.ToAddrs(udpAddr.IP, quicParams.UdpHop.Ports), time.Duration(quicParams.UdpHop.IntervalMin)*time.Second, time.Duration(quicParams.UdpHop.IntervalMax)*time.Second, udpHopDialer, pktConn, index)
|
||||||
|
} else {
|
||||||
|
conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("failed to dial to dest").Base(err)
|
||||||
|
}
|
||||||
|
switch c := conn.(type) {
|
||||||
|
case *internet.PacketConnWrapper:
|
||||||
|
pktConn = c.PacketConn
|
||||||
|
udpAddr = c.RemoteAddr().(*net.UDPAddr)
|
||||||
case *cnc.Connection:
|
case *cnc.Connection:
|
||||||
pktConn = &internet.FakePacketConn{Conn: c}
|
pktConn = &internet.FakePacketConn{Conn: c}
|
||||||
|
udpAddr = &net.UDPAddr{IP: c.RemoteAddr().(*net.TCPAddr).IP, Port: c.RemoteAddr().(*net.TCPAddr).Port}
|
||||||
default:
|
default:
|
||||||
panic(reflect.TypeOf(c))
|
panic(reflect.TypeOf(c))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ type Listener struct {
|
|||||||
server http.Server
|
server http.Server
|
||||||
h3server *http3.Server
|
h3server *http3.Server
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
h3listener Qface
|
h3listener http3.QUICListener
|
||||||
config *Config
|
config *Config
|
||||||
addConn internet.ConnHandler
|
addConn internet.ConnHandler
|
||||||
isH3 bool
|
isH3 bool
|
||||||
@@ -519,8 +519,8 @@ func ListenXH(ctx context.Context, address net.Address, port net.Port, streamSet
|
|||||||
return nil, errors.New("failed to listen QUIC for XHTTP/3 on ", address, ":", port).Base(err)
|
return nil, errors.New("failed to listen QUIC for XHTTP/3 on ", address, ":", port).Base(err)
|
||||||
}
|
}
|
||||||
l.h3listener = &QListener{
|
l.h3listener = &QListener{
|
||||||
Qface: l.h3listener,
|
QUICListener: l.h3listener,
|
||||||
quicParams: quicParams,
|
quicParams: quicParams,
|
||||||
}
|
}
|
||||||
errors.LogInfo(ctx, "listening QUIC for XHTTP/3 on ", address, ":", port)
|
errors.LogInfo(ctx, "listening QUIC for XHTTP/3 on ", address, ":", port)
|
||||||
|
|
||||||
@@ -615,21 +615,13 @@ func init() {
|
|||||||
common.Must(internet.RegisterTransportListener(protocolName, ListenXH))
|
common.Must(internet.RegisterTransportListener(protocolName, ListenXH))
|
||||||
}
|
}
|
||||||
|
|
||||||
type Qface interface {
|
|
||||||
Accept(ctx context.Context) (*quic.Conn, error)
|
|
||||||
Addr() net.Addr
|
|
||||||
Close() error
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ Qface = (*quic.EarlyListener)(nil)
|
|
||||||
|
|
||||||
type QListener struct {
|
type QListener struct {
|
||||||
Qface
|
http3.QUICListener
|
||||||
quicParams *internet.QuicParams
|
quicParams *internet.QuicParams
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *QListener) Accept(ctx context.Context) (*quic.Conn, error) {
|
func (l *QListener) Accept(ctx context.Context) (*quic.Conn, error) {
|
||||||
conn, err := l.Qface.Accept(ctx)
|
conn, err := l.QUICListener.Accept(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,14 +44,10 @@ func resolveSrcAddr(network net.Network, src net.Address) net.Addr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasBindAddr(sockopt *SocketConfig) bool {
|
|
||||||
return sockopt != nil && len(sockopt.BindAddress) > 0 && sockopt.BindPort > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) {
|
func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest net.Destination, sockopt *SocketConfig) (net.Conn, error) {
|
||||||
errors.LogDebug(ctx, "dialing to "+dest.String())
|
errors.LogDebug(ctx, "dialing to "+dest.String())
|
||||||
|
|
||||||
if dest.Network == net.Network_UDP && !hasBindAddr(sockopt) {
|
if dest.Network == net.Network_UDP {
|
||||||
srcAddr := resolveSrcAddr(net.Network_UDP, src)
|
srcAddr := resolveSrcAddr(net.Network_UDP, src)
|
||||||
if srcAddr == nil {
|
if srcAddr == nil {
|
||||||
srcAddr = &net.UDPAddr{
|
srcAddr = &net.UDPAddr{
|
||||||
@@ -132,11 +128,6 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||||||
if err := applyOutboundSocketOptions(network, address, fd, sockopt); err != nil {
|
if err := applyOutboundSocketOptions(network, address, fd, sockopt); err != nil {
|
||||||
errors.LogInfoInner(ctx, err, "failed to apply socket options")
|
errors.LogInfoInner(ctx, err, "failed to apply socket options")
|
||||||
}
|
}
|
||||||
if dest.Network == net.Network_UDP && hasBindAddr(sockopt) {
|
|
||||||
if err := bindAddr(fd, sockopt.BindAddress, sockopt.BindPort); err != nil {
|
|
||||||
errors.LogInfoInner(ctx, err, "failed to bind source address to ", sockopt.BindAddress)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -228,7 +219,7 @@ type FakePacketConn struct {
|
|||||||
|
|
||||||
func (c *FakePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
func (c *FakePacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
||||||
n, err = c.Read(p)
|
n, err = c.Read(p)
|
||||||
return n, c.RemoteAddr(), err
|
return n, &net.UDPAddr{IP: c.Conn.RemoteAddr().(*net.TCPAddr).IP, Port: c.Conn.RemoteAddr().(*net.TCPAddr).Port}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakePacketConn) WriteTo(p []byte, _ net.Addr) (n int, err error) {
|
func (c *FakePacketConn) WriteTo(p []byte, _ net.Addr) (n int, err error) {
|
||||||
@@ -236,15 +227,5 @@ func (c *FakePacketConn) WriteTo(p []byte, _ net.Addr) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakePacketConn) LocalAddr() net.Addr {
|
func (c *FakePacketConn) LocalAddr() net.Addr {
|
||||||
return &net.UDPAddr{
|
return &net.UDPAddr{IP: c.Conn.LocalAddr().(*net.TCPAddr).IP, Port: c.Conn.LocalAddr().(*net.TCPAddr).Port}
|
||||||
IP: []byte{0, 0, 0, 0},
|
|
||||||
Port: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FakePacketConn) RemoteAddr() net.Addr {
|
|
||||||
return &net.UDPAddr{
|
|
||||||
IP: []byte{0, 0, 0, 0},
|
|
||||||
Port: 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,14 @@ func init() {
|
|||||||
|
|
||||||
if streamSettings != nil && streamSettings.UdpmaskManager != nil {
|
if streamSettings != nil && streamSettings.UdpmaskManager != nil {
|
||||||
var pktConn net.PacketConn
|
var pktConn net.PacketConn
|
||||||
var udpAddr = conn.RemoteAddr().(*net.UDPAddr)
|
var udpAddr *net.UDPAddr
|
||||||
switch c := conn.(type) {
|
switch c := conn.(type) {
|
||||||
case *internet.PacketConnWrapper:
|
case *internet.PacketConnWrapper:
|
||||||
pktConn = c.PacketConn
|
pktConn = c.PacketConn
|
||||||
case *net.UDPConn:
|
udpAddr = c.RemoteAddr().(*net.UDPAddr)
|
||||||
pktConn = c
|
|
||||||
case *cnc.Connection:
|
case *cnc.Connection:
|
||||||
pktConn = &internet.FakePacketConn{Conn: c}
|
pktConn = &internet.FakePacketConn{Conn: c}
|
||||||
|
udpAddr = &net.UDPAddr{IP: c.RemoteAddr().(*net.TCPAddr).IP, Port: c.RemoteAddr().(*net.TCPAddr).Port}
|
||||||
default:
|
default:
|
||||||
panic(reflect.TypeOf(c))
|
panic(reflect.TypeOf(c))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user