mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-12-12 04:34:41 +04:00
Chore: Remove all double gonet import (#5402)
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
gonet "net"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ import (
|
|||||||
|
|
||||||
type Holder struct {
|
type Holder struct {
|
||||||
domainToIP cache.Lru
|
domainToIP cache.Lru
|
||||||
ipRange *gonet.IPNet
|
ipRange *net.IPNet
|
||||||
mu *sync.Mutex
|
mu *sync.Mutex
|
||||||
|
|
||||||
config *FakeDnsPool
|
config *FakeDnsPool
|
||||||
@@ -79,10 +78,10 @@ func (fkdns *Holder) initializeFromConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fkdns *Holder) initialize(ipPoolCidr string, lruSize int) error {
|
func (fkdns *Holder) initialize(ipPoolCidr string, lruSize int) error {
|
||||||
var ipRange *gonet.IPNet
|
var ipRange *net.IPNet
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if _, ipRange, err = gonet.ParseCIDR(ipPoolCidr); err != nil {
|
if _, ipRange, err = net.ParseCIDR(ipPoolCidr); err != nil {
|
||||||
return errors.New("Unable to parse CIDR for Fake DNS IP assignment").Base(err).AtError()
|
return errors.New("Unable to parse CIDR for Fake DNS IP assignment").Base(err).AtError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package fakedns
|
package fakedns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gonet "net"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -155,7 +154,7 @@ func TestFakeDNSMulti(t *testing.T) {
|
|||||||
assert.True(t, inPool)
|
assert.True(t, inPool)
|
||||||
})
|
})
|
||||||
t.Run("ipv6", func(t *testing.T) {
|
t.Run("ipv6", func(t *testing.T) {
|
||||||
ip, err := gonet.ResolveIPAddr("ip", "fddd:c5b4:ff5f:f4f0::5")
|
ip, err := net.ResolveIPAddr("ip", "fddd:c5b4:ff5f:f4f0::5")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
inPool := fakeMulti.IsIPInIPPool(net.IPAddress(ip.IP))
|
inPool := fakeMulti.IsIPInIPPool(net.IPAddress(ip.IP))
|
||||||
assert.True(t, inPool)
|
assert.True(t, inPool)
|
||||||
@@ -165,7 +164,7 @@ func TestFakeDNSMulti(t *testing.T) {
|
|||||||
assert.False(t, inPool)
|
assert.False(t, inPool)
|
||||||
})
|
})
|
||||||
t.Run("ipv6_inverse", func(t *testing.T) {
|
t.Run("ipv6_inverse", func(t *testing.T) {
|
||||||
ip, err := gonet.ResolveIPAddr("ip", "fcdd:c5b4:ff5f:f4f0::5")
|
ip, err := net.ResolveIPAddr("ip", "fcdd:c5b4:ff5f:f4f0::5")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
inPool := fakeMulti.IsIPInIPPool(net.IPAddress(ip.IP))
|
inPool := fakeMulti.IsIPInIPPool(net.IPAddress(ip.IP))
|
||||||
assert.False(t, inPool)
|
assert.False(t, inPool)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package inbound
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gonet "net"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@@ -565,12 +564,12 @@ func (w *dsWorker) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsLocal(ip net.IP) bool {
|
func IsLocal(ip net.IP) bool {
|
||||||
addrs, err := gonet.InterfaceAddrs()
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
if ipnet, ok := addr.(*gonet.IPNet); ok {
|
if ipnet, ok := addr.(*net.IPNet); ok {
|
||||||
if ipnet.IP.Equal(ip) {
|
if ipnet.IP.Equal(ip) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
gonet "net"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/dice"
|
"github.com/xtls/xray-core/common/dice"
|
||||||
@@ -398,7 +397,7 @@ func (h *Handler) ProxySettings() *serial.TypedMessage {
|
|||||||
|
|
||||||
func ParseRandomIP(addr net.Address, prefix string) net.Address {
|
func ParseRandomIP(addr net.Address, prefix string) net.Address {
|
||||||
|
|
||||||
_, ipnet, _ := gonet.ParseCIDR(addr.IP().String() + "/" + prefix)
|
_, ipnet, _ := net.ParseCIDR(addr.IP().String() + "/" + prefix)
|
||||||
|
|
||||||
ones, bits := ipnet.Mask.Size()
|
ones, bits := ipnet.Mask.Size()
|
||||||
subnetSize := new(big.Int).Lsh(big.NewInt(1), uint(bits-ones))
|
subnetSize := new(big.Int).Lsh(big.NewInt(1), uint(bits-ones))
|
||||||
@@ -412,5 +411,5 @@ func ParseRandomIP(addr net.Address, prefix string) net.Address {
|
|||||||
padded := make([]byte, len(ipnet.IP))
|
padded := make([]byte, len(ipnet.IP))
|
||||||
copy(padded[len(padded)-len(rndBytes):], rndBytes)
|
copy(padded[len(padded)-len(rndBytes):], rndBytes)
|
||||||
|
|
||||||
return net.ParseAddress(gonet.IP(padded).String())
|
return net.ParseAddress(net.IP(padded).String())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ var (
|
|||||||
|
|
||||||
type ListenConfig = net.ListenConfig
|
type ListenConfig = net.ListenConfig
|
||||||
|
|
||||||
|
type KeepAliveConfig = net.KeepAliveConfig
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Listen = net.Listen
|
Listen = net.Listen
|
||||||
ListenTCP = net.ListenTCP
|
ListenTCP = net.ListenTCP
|
||||||
@@ -26,6 +28,12 @@ var FileConn = net.FileConn
|
|||||||
// ParseIP is an alias of net.ParseIP
|
// ParseIP is an alias of net.ParseIP
|
||||||
var ParseIP = net.ParseIP
|
var ParseIP = net.ParseIP
|
||||||
|
|
||||||
|
var ParseCIDR = net.ParseCIDR
|
||||||
|
|
||||||
|
var ResolveIPAddr = net.ResolveIPAddr
|
||||||
|
|
||||||
|
var InterfaceByName = net.InterfaceByName
|
||||||
|
|
||||||
var SplitHostPort = net.SplitHostPort
|
var SplitHostPort = net.SplitHostPort
|
||||||
|
|
||||||
var CIDRMask = net.CIDRMask
|
var CIDRMask = net.CIDRMask
|
||||||
@@ -51,6 +59,8 @@ type (
|
|||||||
UnixConn = net.UnixConn
|
UnixConn = net.UnixConn
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type IPAddr = net.IPAddr
|
||||||
|
|
||||||
// IP is an alias for net.IP.
|
// IP is an alias for net.IP.
|
||||||
type (
|
type (
|
||||||
IP = net.IP
|
IP = net.IP
|
||||||
@@ -82,3 +92,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Resolver = net.Resolver
|
type Resolver = net.Resolver
|
||||||
|
|
||||||
|
var DefaultResolver = net.DefaultResolver
|
||||||
|
|
||||||
|
var JoinHostPort = net.JoinHostPort
|
||||||
|
|
||||||
|
var InterfaceAddrs = net.InterfaceAddrs
|
||||||
|
|
||||||
|
var Interfaces = net.Interfaces
|
||||||
|
|||||||
@@ -3,14 +3,13 @@ package wireguard
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.zx2c4.com/wireguard/conn"
|
"golang.zx2c4.com/wireguard/conn"
|
||||||
|
|
||||||
xnet "github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/features/dns"
|
"github.com/xtls/xray-core/features/dns"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
)
|
)
|
||||||
@@ -51,21 +50,21 @@ func (n *netBind) ParseEndpoint(s string) (conn.Endpoint, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := xnet.ParseAddress(ipStr)
|
addr := net.ParseAddress(ipStr)
|
||||||
if addr.Family() == xnet.AddressFamilyDomain {
|
if addr.Family() == net.AddressFamilyDomain {
|
||||||
ips, _, err := n.dns.LookupIP(addr.Domain(), n.dnsOption)
|
ips, _, err := n.dns.LookupIP(addr.Domain(), n.dnsOption)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if len(ips) == 0 {
|
} else if len(ips) == 0 {
|
||||||
return nil, dns.ErrEmptyResponse
|
return nil, dns.ErrEmptyResponse
|
||||||
}
|
}
|
||||||
addr = xnet.IPAddress(ips[0])
|
addr = net.IPAddress(ips[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
dst := xnet.Destination{
|
dst := net.Destination{
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Port: xnet.Port(portNum),
|
Port: net.Port(portNum),
|
||||||
Network: xnet.Network_UDP,
|
Network: net.Network_UDP,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &netEndpoint{
|
return &netEndpoint{
|
||||||
@@ -214,7 +213,7 @@ func (bind *netBindServer) Send(buff [][]byte, endpoint conn.Endpoint) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type netEndpoint struct {
|
type netEndpoint struct {
|
||||||
dst xnet.Destination
|
dst net.Destination
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +246,7 @@ func (e netEndpoint) SrcToString() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func toNetIpAddr(addr xnet.Address) netip.Addr {
|
func toNetIpAddr(addr net.Address) netip.Addr {
|
||||||
if addr.Family().IsIPv4() {
|
if addr.Family().IsIPv4() {
|
||||||
ip := addr.IP()
|
ip := addr.IP()
|
||||||
return netip.AddrFrom4([4]byte{ip[0], ip[1], ip[2], ip[3]})
|
return netip.AddrFrom4([4]byte{ip[0], ip[1], ip[2], ip[3]})
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package wireguard
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -13,7 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
"github.com/xtls/xray-core/common/log"
|
"github.com/xtls/xray-core/common/log"
|
||||||
xnet "github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/proxy/wireguard/gvisortun"
|
"github.com/xtls/xray-core/proxy/wireguard/gvisortun"
|
||||||
"gvisor.dev/gvisor/pkg/tcpip"
|
"gvisor.dev/gvisor/pkg/tcpip"
|
||||||
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
|
||||||
@@ -28,7 +27,7 @@ import (
|
|||||||
|
|
||||||
type tunCreator func(localAddresses []netip.Addr, mtu int, handler promiscuousModeHandler) (Tunnel, error)
|
type tunCreator func(localAddresses []netip.Addr, mtu int, handler promiscuousModeHandler) (Tunnel, error)
|
||||||
|
|
||||||
type promiscuousModeHandler func(dest xnet.Destination, conn net.Conn)
|
type promiscuousModeHandler func(dest net.Destination, conn net.Conn)
|
||||||
|
|
||||||
type Tunnel interface {
|
type Tunnel interface {
|
||||||
BuildDevice(ipc string, bind conn.Bind) error
|
BuildDevice(ipc string, bind conn.Bind) error
|
||||||
@@ -169,7 +168,7 @@ func createGVisorTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
|
|||||||
ep.SocketOptions().SetKeepAlive(true)
|
ep.SocketOptions().SetKeepAlive(true)
|
||||||
|
|
||||||
// local address is actually destination
|
// local address is actually destination
|
||||||
handler(xnet.TCPDestination(xnet.IPAddress(id.LocalAddress.AsSlice()), xnet.Port(id.LocalPort)), gonet.NewTCPConn(&wq, ep))
|
handler(net.TCPDestination(net.IPAddress(id.LocalAddress.AsSlice()), net.Port(id.LocalPort)), gonet.NewTCPConn(&wq, ep))
|
||||||
}(r)
|
}(r)
|
||||||
})
|
})
|
||||||
stack.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
|
stack.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
|
||||||
@@ -194,7 +193,7 @@ func createGVisorTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
|
|||||||
Timeout: 15 * time.Second,
|
Timeout: 15 * time.Second,
|
||||||
})
|
})
|
||||||
|
|
||||||
handler(xnet.UDPDestination(xnet.IPAddress(id.LocalAddress.AsSlice()), xnet.Port(id.LocalPort)), gonet.NewUDPConn(&wq, ep))
|
handler(net.UDPDestination(net.IPAddress(id.LocalAddress.AsSlice()), net.Port(id.LocalPort)), gonet.NewUDPConn(&wq, ep))
|
||||||
}(r)
|
}(r)
|
||||||
})
|
})
|
||||||
stack.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
|
stack.SetTransportProtocolHandler(udp.ProtocolNumber, udpForwarder.HandlePacket)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package internet
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
gonet "net"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@@ -183,7 +182,7 @@ func checkAddressPortStrategy(ctx context.Context, dest net.Destination, sockopt
|
|||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
return nil, errors.New("invalid address format", dest.Address.String())
|
return nil, errors.New("invalid address format", dest.Address.String())
|
||||||
}
|
}
|
||||||
_, srvRecords, err := gonet.DefaultResolver.LookupSRV(context.Background(), parts[0][1:], parts[1][1:], parts[2])
|
_, srvRecords, err := net.DefaultResolver.LookupSRV(context.Background(), parts[0][1:], parts[1][1:], parts[2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("failed to lookup SRV record").Base(err)
|
return nil, errors.New("failed to lookup SRV record").Base(err)
|
||||||
}
|
}
|
||||||
@@ -198,7 +197,7 @@ func checkAddressPortStrategy(ctx context.Context, dest net.Destination, sockopt
|
|||||||
}
|
}
|
||||||
if OverrideBy == "txt" {
|
if OverrideBy == "txt" {
|
||||||
errors.LogDebug(ctx, "query TXT record for "+dest.Address.String())
|
errors.LogDebug(ctx, "query TXT record for "+dest.Address.String())
|
||||||
txtRecords, err := gonet.DefaultResolver.LookupTXT(ctx, dest.Address.String())
|
txtRecords, err := net.DefaultResolver.LookupTXT(ctx, dest.Address.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogError(ctx, "failed to lookup SRV record: "+err.Error())
|
errors.LogError(ctx, "failed to lookup SRV record: "+err.Error())
|
||||||
return nil, errors.New("failed to lookup SRV record").Base(err)
|
return nil, errors.New("failed to lookup SRV record").Base(err)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gonet "net"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -99,7 +98,7 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
},
|
},
|
||||||
MinConnectTimeout: 5 * time.Second,
|
MinConnectTimeout: 5 * time.Second,
|
||||||
}),
|
}),
|
||||||
grpc.WithContextDialer(func(gctx context.Context, s string) (gonet.Conn, error) {
|
grpc.WithContextDialer(func(gctx context.Context, s string) (net.Conn, error) {
|
||||||
select {
|
select {
|
||||||
case <-gctx.Done():
|
case <-gctx.Done():
|
||||||
return nil, gctx.Err()
|
return nil, gctx.Err()
|
||||||
@@ -180,7 +179,7 @@ func getGrpcClient(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
}
|
}
|
||||||
|
|
||||||
conn, err := grpc.Dial(
|
conn, err := grpc.Dial(
|
||||||
gonet.JoinHostPort(grpcDestHost, dest.Port.String()),
|
net.JoinHostPort(grpcDestHost, dest.Port.String()),
|
||||||
dialOptions...,
|
dialOptions...,
|
||||||
)
|
)
|
||||||
globalDialerMap[dialerConf{dest, streamSettings}] = conn
|
globalDialerMap[dialerConf{dest, streamSettings}] = conn
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ package encoding
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
xnet "github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/net/cnc"
|
"github.com/xtls/xray-core/common/net/cnc"
|
||||||
"github.com/xtls/xray-core/common/signal/done"
|
"github.com/xtls/xray-core/common/signal/done"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
@@ -55,7 +54,7 @@ func NewHunkConn(hc HunkConn, cancel context.CancelFunc) net.Conn {
|
|||||||
if ok {
|
if ok {
|
||||||
header := md.Get("x-real-ip")
|
header := md.Get("x-real-ip")
|
||||||
if len(header) > 0 {
|
if len(header) > 0 {
|
||||||
realip := xnet.ParseAddress(header[0])
|
realip := net.ParseAddress(header[0])
|
||||||
if realip.Family().IsIP() {
|
if realip.Family().IsIP() {
|
||||||
rAddr = &net.TCPAddr{
|
rAddr = &net.TCPAddr{
|
||||||
IP: realip.IP(),
|
IP: realip.IP(),
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package internet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gonet "net"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -135,7 +134,7 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Interface != "" {
|
if config.Interface != "" {
|
||||||
iface, err := gonet.InterfaceByName(config.Interface)
|
iface, err := net.InterfaceByName(config.Interface)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to get interface ", config.Interface).Base(err)
|
return errors.New("failed to get interface ", config.Interface).Base(err)
|
||||||
@@ -226,7 +225,7 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Interface != "" {
|
if config.Interface != "" {
|
||||||
iface, err := gonet.InterfaceByName(config.Interface)
|
iface, err := net.InterfaceByName(config.Interface)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to get interface ", config.Interface).Base(err)
|
return errors.New("failed to get interface ", config.Interface).Base(err)
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ package splithttp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
gonet "net"
|
|
||||||
|
|
||||||
"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/transport/internet/browser_dialer"
|
"github.com/xtls/xray-core/transport/internet/browser_dialer"
|
||||||
"github.com/xtls/xray-core/transport/internet/websocket"
|
"github.com/xtls/xray-core/transport/internet/websocket"
|
||||||
)
|
)
|
||||||
@@ -19,13 +19,13 @@ func (c *BrowserDialerClient) IsClosed() bool {
|
|||||||
panic("not implemented yet")
|
panic("not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BrowserDialerClient) OpenStream(ctx context.Context, url string, body io.Reader, uploadOnly bool) (io.ReadCloser, gonet.Addr, gonet.Addr, error) {
|
func (c *BrowserDialerClient) OpenStream(ctx context.Context, url string, body io.Reader, uploadOnly bool) (io.ReadCloser, net.Addr, net.Addr, error) {
|
||||||
if body != nil {
|
if body != nil {
|
||||||
return nil, nil, nil, errors.New("bidirectional streaming for browser dialer not implemented yet")
|
return nil, nil, nil, errors.New("bidirectional streaming for browser dialer not implemented yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := browser_dialer.DialGet(url, c.transportConfig.GetRequestHeader(url))
|
conn, err := browser_dialer.DialGet(url, c.transportConfig.GetRequestHeader(url))
|
||||||
dummyAddr := &gonet.IPAddr{}
|
dummyAddr := &net.IPAddr{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, dummyAddr, dummyAddr, err
|
return nil, dummyAddr, dummyAddr, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
gonet "net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptrace"
|
"net/http/httptrace"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -42,7 +41,7 @@ func (c *DefaultDialerClient) IsClosed() bool {
|
|||||||
return c.closed
|
return c.closed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DefaultDialerClient) OpenStream(ctx context.Context, url string, body io.Reader, uploadOnly bool) (wrc io.ReadCloser, remoteAddr, localAddr gonet.Addr, err error) {
|
func (c *DefaultDialerClient) OpenStream(ctx context.Context, url string, body io.Reader, uploadOnly bool) (wrc io.ReadCloser, remoteAddr, localAddr net.Addr, err error) {
|
||||||
// this is done when the TCP/UDP connection to the server was established,
|
// this is done when the TCP/UDP connection to the server was established,
|
||||||
// and we can unblock the Dial function and print correct net addresses in
|
// and we can unblock the Dial function and print correct net addresses in
|
||||||
// logs
|
// logs
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package internet
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
gonet "net"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
// Chrome defaults
|
// Chrome defaults
|
||||||
keepAliveConfig := gonet.KeepAliveConfig{
|
keepAliveConfig := net.KeepAliveConfig{
|
||||||
Enable: true,
|
Enable: true,
|
||||||
Idle: 45 * time.Second,
|
Idle: 45 * time.Second,
|
||||||
Interval: 45 * time.Second,
|
Interval: 45 * time.Second,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package internet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gonet "net"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -95,7 +94,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
|
|||||||
if sockopt.TcpKeepAliveIdle*sockopt.TcpKeepAliveInterval < 0 {
|
if sockopt.TcpKeepAliveIdle*sockopt.TcpKeepAliveInterval < 0 {
|
||||||
return nil, errors.New("invalid TcpKeepAliveIdle or TcpKeepAliveInterval value: ", sockopt.TcpKeepAliveIdle, " ", sockopt.TcpKeepAliveInterval)
|
return nil, errors.New("invalid TcpKeepAliveIdle or TcpKeepAliveInterval value: ", sockopt.TcpKeepAliveIdle, " ", sockopt.TcpKeepAliveInterval)
|
||||||
}
|
}
|
||||||
lc.KeepAliveConfig = gonet.KeepAliveConfig{
|
lc.KeepAliveConfig = net.KeepAliveConfig{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Idle: -1,
|
Idle: -1,
|
||||||
Interval: -1,
|
Interval: -1,
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
gonet "net"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@@ -64,7 +63,7 @@ func dialWebSocket(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
tlsConfig := tConfig.GetTLSConfig(tls.WithDestination(dest), tls.WithNextProto("http/1.1"))
|
tlsConfig := tConfig.GetTLSConfig(tls.WithDestination(dest), tls.WithNextProto("http/1.1"))
|
||||||
dialer.TLSClientConfig = tlsConfig
|
dialer.TLSClientConfig = tlsConfig
|
||||||
if fingerprint := tls.GetFingerprint(tConfig.Fingerprint); fingerprint != nil {
|
if fingerprint := tls.GetFingerprint(tConfig.Fingerprint); fingerprint != nil {
|
||||||
dialer.NetDialTLSContext = func(_ context.Context, _, addr string) (gonet.Conn, error) {
|
dialer.NetDialTLSContext = func(_ context.Context, _, addr string) (net.Conn, error) {
|
||||||
// Like the NetDial in the dialer
|
// Like the NetDial in the dialer
|
||||||
pconn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
pconn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user