mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
core: migrate xray-core from git submodule to go mod and port QUIC outbounds to daeuniverse/outbound
The vendored core/xray submodule is dropped. xray-core is now pinned via a go mod pseudo-version resolving to v26.7.28 (commit 5ca6f4b7); v26 tags are not directly resolvable because Xray's module path lacks the /v26 suffix, so the pin must be made by commit hash. CI workflows and the AUR PKGBUILD no longer need "submodules: recursive" / "git submodule update". The juicity and tuic outbounds are ported from softwind to github.com/daeuniverse/outbound (temporarily replaced with an olicesx fork pending sticky-ip support): - Dialer calls use DialContext; the network string is decoded with netproxy.ParseMagicNetwork instead of a "udp" prefix check, since it may be binary-encoded via netproxy.MagicNetwork. - A packetConnAdapter wraps xray's UDP dial result: outbound asserts the underlay conn to netproxy.PacketConn whose ReadFrom/WriteTo signatures (netip.AddrPort / string) differ from net.PacketConn, while xray returns *internet.PacketConnWrapper.
This commit is contained in:
1 parent
9ac9e48487
commit
cffe97ca3d
10 files changed
+154
-56
No files matched your search
@@ -48,7 +48,6 @@ jobs:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
- name: Download Web Artifact
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
|
||||
@@ -27,7 +27,6 @@ jobs:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: recursive
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
[submodule "core/xray"]
|
||||
path = core/xray
|
||||
url = https://github.com/XTLS/Xray-core.git
|
||||
@@ -46,7 +46,7 @@ Function Build-v2rayA(){
|
||||
#Build Web Panel
|
||||
Set-Location -Path "$CurrentPath/gui"
|
||||
yarn; yarn build
|
||||
#Build v2raya-core (merged xray-core + MultiObservatory)
|
||||
#Build v2raya-core (xray-core from go mod + MultiObservatory)
|
||||
Set-Location -Path "$CurrentPath/core"
|
||||
${env:CGO_ENABLED} = "0"
|
||||
go build -trimpath -trimpath -ldflags "-s -w" -o "$CurrentPath/$v2rayaCoreBin" ./main
|
||||
|
||||
@@ -13,7 +13,7 @@ else
|
||||
fi
|
||||
# https://github.com/webpack/webpack/issues/14532#issuecomment-947012063
|
||||
cd "$CurrentDir"/gui && yarn --ignore-engines && OUTPUT_DIR="$CurrentDir"/service/server/router/web yarn --ignore-engines build
|
||||
# Build v2raya-core (merged xray-core + custom protocols)
|
||||
# Build v2raya-core (xray-core from go mod + custom protocols)
|
||||
cd "$CurrentDir"/core && CGO_ENABLED=0 go build -trimpath -ldflags "-X main.Version=$version -s -w" -o "$CurrentDir"/v2raya_core ./main
|
||||
|
||||
cd "$CurrentDir"/service && CGO_ENABLED=0 go build -trimpath -tags "with_gvisor" -ldflags "-X github.com/v2rayA/v2rayA/conf.Version=$version -s -w" -o "$CurrentDir"/v2raya
|
||||
+8
-9
@@ -1,5 +1,5 @@
|
||||
// This module is the v2rayA merged core (v2raya-core).
|
||||
// It wraps xray-core (as a git submodule) and adds MultiObservatory and
|
||||
// It wraps xray-core (fetched via go mod) and adds MultiObservatory and
|
||||
// v2ray-compatible gRPC services without modifying xray's source.
|
||||
//
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
@@ -10,10 +10,11 @@ go 1.26
|
||||
require (
|
||||
anytls v0.0.12
|
||||
github.com/daeuniverse/outbound v0.0.0-20250722064253-00c4fbb38759
|
||||
github.com/daeuniverse/softwind v0.0.0-20231230065827-eed67f20d2c1
|
||||
github.com/miekg/dns v1.1.72
|
||||
github.com/sagernet/sing v0.5.1
|
||||
github.com/xtls/xray-core v0.0.0-local
|
||||
github.com/sagernet/sing v0.6.0
|
||||
// Pseudo-version for Xray-core v26.7.28 (commit 5ca6f4b7). v26 tags are not
|
||||
// resolvable via go mod because Xray's module path lacks the /v26 suffix.
|
||||
github.com/xtls/xray-core v1.260327.1-0.20260728075948-5ca6f4b7d4dc
|
||||
golang.org/x/sys v0.47.0
|
||||
google.golang.org/grpc v1.83.2
|
||||
google.golang.org/protobuf v1.36.11
|
||||
@@ -27,7 +28,6 @@ require (
|
||||
github.com/awnumar/memguard v0.19.1 // indirect
|
||||
github.com/chen3feng/stl4go v0.1.1 // indirect
|
||||
github.com/cloudflare/circl v1.6.4 // indirect
|
||||
github.com/daeuniverse/quic-go v0.0.0-20250210145620-2083199a7851 // indirect
|
||||
github.com/dgryski/go-camellia v0.0.0-20191119043421-69a8a13fb23d // indirect
|
||||
github.com/dgryski/go-idea v0.0.0-20170306091226-d2fb45a411fb // indirect
|
||||
github.com/dgryski/go-rc2 v0.0.0-20150621095337-8a9021637152 // indirect
|
||||
@@ -42,7 +42,7 @@ require (
|
||||
github.com/klauspost/compress v1.17.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
|
||||
github.com/mzz2017/disk-bloom v1.0.1 // indirect
|
||||
github.com/mzz2017/quic-go v0.0.0-20231230054300-5221ce9164a3 // indirect
|
||||
github.com/olicesx/quic-go v0.0.0-20260910141758-62d80bbebb5b // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
|
||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pion/dtls/v3 v3.1.4 // indirect
|
||||
@@ -51,7 +51,6 @@ require (
|
||||
github.com/pion/transport/v4 v4.0.2 // indirect
|
||||
github.com/pires/go-proxyproto v0.15.0 // indirect
|
||||
github.com/quic-go/qpack v0.6.0 // indirect
|
||||
github.com/quic-go/qtls-go1-20 v0.4.1 // indirect
|
||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/sagernet/sing-shadowsocks v0.2.7 // indirect
|
||||
@@ -80,6 +79,6 @@ require (
|
||||
lukechampine.com/blake3 v1.4.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/xtls/xray-core => ./xray
|
||||
|
||||
replace anytls v0.0.12 => github.com/anytls/anytls-go v0.0.12
|
||||
|
||||
replace github.com/daeuniverse/outbound => github.com/olicesx/outbound v0.0.0-sticky-ip.0.20260917223728-6a44445c9106
|
||||
+8
-12
@@ -17,12 +17,6 @@ github.com/chen3feng/stl4go v0.1.1 h1:0L1+mDw7pomftKDruM23f1mA7miavOj6C6MZeadzN2
|
||||
github.com/chen3feng/stl4go v0.1.1/go.mod h1:5ml3psLgETJjRJnMbPE+JiHLrCpt+Ajc2weeTECXzWU=
|
||||
github.com/cloudflare/circl v1.6.4 h1:pOXuDTCEYyzydgUpQ0CQz3LsinKjiSk6nNP5Lt5K64U=
|
||||
github.com/cloudflare/circl v1.6.4/go.mod h1:YxarevkLlbaHuWsxG6vmYNWBEsSp4pnp7j+4VljMavY=
|
||||
github.com/daeuniverse/outbound v0.0.0-20250722064253-00c4fbb38759 h1:aklFtuD9AJ9toFveiPNfstY0o4owduvJ+iNpc61mhkU=
|
||||
github.com/daeuniverse/outbound v0.0.0-20250722064253-00c4fbb38759/go.mod h1:fywFXIIfFeyG+oMat6h7MExY99CNtERbhrH0DYSr/6g=
|
||||
github.com/daeuniverse/quic-go v0.0.0-20250210145620-2083199a7851 h1:AK4qfFw5CcHdOJcEpZj443NqskjhTvc+2cLOB5Cvrmk=
|
||||
github.com/daeuniverse/quic-go v0.0.0-20250210145620-2083199a7851/go.mod h1:hykVjD1wT/nAFcAkagZpziNAnXLwJOOpn0Ozohtgmsw=
|
||||
github.com/daeuniverse/softwind v0.0.0-20231230065827-eed67f20d2c1 h1:qh16GLF9TfntnLIwos49rj7Yj4EHICDe9ToesIjTm1c=
|
||||
github.com/daeuniverse/softwind v0.0.0-20231230065827-eed67f20d2c1/go.mod h1:ly72DcZIxHlKbOEz1qaSCh99lr7ns8T5JLpfww8hXrI=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -72,8 +66,10 @@ github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
|
||||
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
||||
github.com/mzz2017/disk-bloom v1.0.1 h1:rEF9MiXd9qMW3ibRpqcerLXULoTgRlM21yqqJl1B90M=
|
||||
github.com/mzz2017/disk-bloom v1.0.1/go.mod h1:JLHETtUu44Z6iBmsqzkOtFlRvXSlKnxjwiBRDapizDI=
|
||||
github.com/mzz2017/quic-go v0.0.0-20231230054300-5221ce9164a3 h1:V0C+4ZV0TzzKH05TAjtxAKODudB5dKyO6rayhtSO55I=
|
||||
github.com/mzz2017/quic-go v0.0.0-20231230054300-5221ce9164a3/go.mod h1:RVldHw4emztg37XspqsQSOqptlBuYTCHD/brBTROQSw=
|
||||
github.com/olicesx/outbound v0.0.0-sticky-ip.0.20260917223728-6a44445c9106 h1:kqR8X0kYgEfeXj2aB0UNSYD5sSvmmePvem4pdfT4Yds=
|
||||
github.com/olicesx/outbound v0.0.0-sticky-ip.0.20260917223728-6a44445c9106/go.mod h1:AuXipZhyrHm/ebwky2LR1NNqvIyAq9i1W/0RVvCZ+Xs=
|
||||
github.com/olicesx/quic-go v0.0.0-20260910141758-62d80bbebb5b h1:MLp1BCIfVjs6q3OHuHRwmD/HhEPWLnyFvr07uPZJqSQ=
|
||||
github.com/olicesx/quic-go v0.0.0-20260910141758-62d80bbebb5b/go.mod h1:yuQ0GMUyulYqdBASGfkodPJykc5grhEgGy/ptMaUa/o=
|
||||
github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU=
|
||||
github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk=
|
||||
github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8=
|
||||
@@ -94,16 +90,14 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
|
||||
github.com/quic-go/qpack v0.6.0/go.mod h1:lUpLKChi8njB4ty2bFLX2x4gzDqXwUpaO1DP9qMDZII=
|
||||
github.com/quic-go/qtls-go1-20 v0.4.1 h1:D33340mCNDAIKBqXuAvexTNMUByrYmFYVfKfDN5nfFs=
|
||||
github.com/quic-go/qtls-go1-20 v0.4.1/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
|
||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af h1:er2acxbi3N1nvEq6HXHUAR1nTWEJmQfqiGR8EVT9rfs=
|
||||
github.com/refraction-networking/utls v1.8.3-0.20260301010127-aa6edf4b11af/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
github.com/sagernet/sing v0.5.1 h1:mhL/MZVq0TjuvHcpYcFtmSD1BFOxZ/+8ofbNZcg1k1Y=
|
||||
github.com/sagernet/sing v0.5.1/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
||||
github.com/sagernet/sing v0.6.0 h1:jT55zAXrG7H3x+s/FlrC15xQy3LcmuZ2GGA9+8IJdt0=
|
||||
github.com/sagernet/sing v0.6.0/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.7 h1:zaopR1tbHEw5Nk6FAkM05wCslV6ahVegEZaKMv9ipx8=
|
||||
github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
@@ -121,6 +115,8 @@ github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
|
||||
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
||||
github.com/xtls/reality v0.0.0-20260322125925-9234c772ba8f h1:iy2JRioxmUpoJ3SzbFPyTxHZMbR/rSHP7dOOgYaq1O8=
|
||||
github.com/xtls/reality v0.0.0-20260322125925-9234c772ba8f/go.mod h1:DsJblcWDGt76+FVqBVwbwRhxyyNJsGV48gJLch0OOWI=
|
||||
github.com/xtls/xray-core v1.260327.1-0.20260728075948-5ca6f4b7d4dc h1:fkOkmgHWbF2Q8MdV9VxrsyxRz4OndcrUXUkh1ANBTg0=
|
||||
github.com/xtls/xray-core v1.260327.1-0.20260728075948-5ca6f4b7d4dc/go.mod h1:wukQoBGnQ6GaLTGuKwv8rCTgf80QxPj+6iznDZHQEWo=
|
||||
gitlab.com/yawning/chacha20.git v0.0.0-20230427033715-7877545b1b37 h1:ZrWBE3u/o9cHU2mySXf1687MaK09JOeZt1A+fHnCjmU=
|
||||
gitlab.com/yawning/chacha20.git v0.0.0-20230427033715-7877545b1b37/go.mod h1:3x6b94nWCP/a2XB/joOPMiGYUBvqbLfeY/BkHLeDs6s=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
|
||||
@@ -6,13 +6,14 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/daeuniverse/softwind/netproxy"
|
||||
"github.com/daeuniverse/softwind/protocol"
|
||||
_ "github.com/daeuniverse/softwind/protocol/juicity" // register juicity protocol
|
||||
outbound_netproxy "github.com/daeuniverse/outbound/netproxy"
|
||||
outbound_protocol "github.com/daeuniverse/outbound/protocol"
|
||||
_ "github.com/daeuniverse/outbound/protocol/juicity" // register juicity protocol
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
xray_buf "github.com/xtls/xray-core/common/buf"
|
||||
@@ -29,8 +30,8 @@ import (
|
||||
// Client is the juicity outbound handler.
|
||||
type Client struct {
|
||||
config *ClientConfig
|
||||
dialer netproxy.Dialer
|
||||
newDialer func(internet.Dialer) (netproxy.Dialer, error)
|
||||
dialer outbound_netproxy.Dialer
|
||||
newDialer func(internet.Dialer) (outbound_netproxy.Dialer, error)
|
||||
dialerOnce sync.Once
|
||||
dialerErr error
|
||||
}
|
||||
@@ -76,8 +77,8 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||
congestion = "bbr"
|
||||
}
|
||||
|
||||
newDialer := func(dialer internet.Dialer) (netproxy.Dialer, error) {
|
||||
return protocol.NewDialer("juicity", xrayDialer{dialer: dialer}, protocol.Header{
|
||||
newDialer := func(dialer internet.Dialer) (outbound_netproxy.Dialer, error) {
|
||||
return outbound_protocol.NewDialer("juicity", xrayDialer{dialer: dialer}, outbound_protocol.Header{
|
||||
ProxyAddress: config.Address,
|
||||
Feature1: congestion,
|
||||
TlsConfig: tlsCfg,
|
||||
@@ -97,16 +98,66 @@ type xrayDialer struct {
|
||||
dialer internet.Dialer
|
||||
}
|
||||
|
||||
func (d xrayDialer) Dial(network, addr string) (netproxy.Conn, error) {
|
||||
return d.DialContext(context.Background(), network, addr)
|
||||
}
|
||||
|
||||
func (d xrayDialer) DialContext(ctx context.Context, network, addr string) (netproxy.Conn, error) {
|
||||
func (d xrayDialer) DialContext(ctx context.Context, network, addr string) (outbound_netproxy.Conn, error) {
|
||||
destination, err := xrayDestination(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.dialer.Dial(ctx, destination)
|
||||
conn, err := d.dialer.Dial(ctx, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// QUIC-based protocols assert the underlay conn to netproxy.PacketConn,
|
||||
// whose ReadFrom/WriteTo signatures differ from net.PacketConn. xray's UDP
|
||||
// dial returns *internet.PacketConnWrapper, so adapt it here.
|
||||
if destination.Network == xray_net.Network_UDP {
|
||||
if pc, ok := conn.(net.PacketConn); ok {
|
||||
return &packetConnAdapter{conn: conn, pc: pc}, nil
|
||||
}
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("juicity: UDP dial returned %T, which is not a net.PacketConn", conn)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// packetConnAdapter adapts xray's UDP conn (net.Conn + net.PacketConn) to
|
||||
// outbound's netproxy.PacketConn interface.
|
||||
type packetConnAdapter struct {
|
||||
conn net.Conn
|
||||
pc net.PacketConn
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) Read(b []byte) (int, error) { return a.conn.Read(b) }
|
||||
func (a *packetConnAdapter) Write(b []byte) (int, error) { return a.conn.Write(b) }
|
||||
func (a *packetConnAdapter) Close() error { return a.conn.Close() }
|
||||
func (a *packetConnAdapter) SetDeadline(t time.Time) error {
|
||||
return a.conn.SetDeadline(t)
|
||||
}
|
||||
func (a *packetConnAdapter) SetReadDeadline(t time.Time) error {
|
||||
return a.conn.SetReadDeadline(t)
|
||||
}
|
||||
func (a *packetConnAdapter) SetWriteDeadline(t time.Time) error {
|
||||
return a.conn.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) ReadFrom(p []byte) (int, netip.AddrPort, error) {
|
||||
n, addr, err := a.pc.ReadFrom(p)
|
||||
if err != nil {
|
||||
return n, netip.AddrPort{}, err
|
||||
}
|
||||
ap, err := netip.ParseAddrPort(addr.String())
|
||||
if err != nil {
|
||||
return n, netip.AddrPort{}, err
|
||||
}
|
||||
return n, ap, nil
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) WriteTo(p []byte, addr string) (int, error) {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return a.pc.WriteTo(p, udpAddr)
|
||||
}
|
||||
|
||||
func xrayDestination(network, addr string) (xray_net.Destination, error) {
|
||||
@@ -119,7 +170,8 @@ func xrayDestination(network, addr string) (xray_net.Destination, error) {
|
||||
return xray_net.Destination{}, fmt.Errorf("juicity: invalid server port %q: %w", port, err)
|
||||
}
|
||||
address := xray_net.ParseAddress(host)
|
||||
if strings.HasPrefix(network, "udp") {
|
||||
mn, err := outbound_netproxy.ParseMagicNetwork(network)
|
||||
if err == nil && mn.Network == "udp" {
|
||||
return xray_net.UDPDestination(address, xray_net.Port(portNumber)), nil
|
||||
}
|
||||
return xray_net.TCPDestination(address, xray_net.Port(portNumber)), nil
|
||||
@@ -143,17 +195,17 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
// Build destination address string
|
||||
destAddr := fmt.Sprintf("%s:%d", destination.Address.String(), destination.Port.Value())
|
||||
|
||||
conn, err := c.dialer.Dial("tcp", destAddr)
|
||||
conn, err := c.dialer.DialContext(ctx, "tcp", destAddr)
|
||||
if err != nil {
|
||||
return errors.New("juicity: failed to dial destination").Base(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
postRequest := func() error {
|
||||
return xray_buf.Copy(link.Reader, xray_buf.NewWriter(netproxyConnAsWriter(conn)))
|
||||
return xray_buf.Copy(link.Reader, xray_buf.NewWriter(outboundConnWriter(conn)))
|
||||
}
|
||||
getResponse := func() error {
|
||||
return xray_buf.Copy(xray_buf.NewReader(netproxyConnAsReader(conn)), link.Writer)
|
||||
return xray_buf.Copy(xray_buf.NewReader(outboundConnReader(conn)), link.Writer)
|
||||
}
|
||||
|
||||
responseDoneAndCloseWriter := task.OnSuccess(getResponse, task.Close(link.Writer))
|
||||
@@ -164,15 +216,15 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
return nil
|
||||
}
|
||||
|
||||
// netproxyConn wraps a netproxy.Conn to expose io.Reader/io.Writer for xray's buf.
|
||||
type netproxyConn struct {
|
||||
c netproxy.Conn
|
||||
// outboundConn wraps outbound_netproxy.Conn to expose io.Reader/io.Writer for xray's buf.
|
||||
type outboundConn struct {
|
||||
c outbound_netproxy.Conn
|
||||
}
|
||||
|
||||
func netproxyConnAsReader(c netproxy.Conn) io.Reader { return &netproxyConn{c} }
|
||||
func netproxyConnAsWriter(c netproxy.Conn) io.Writer { return &netproxyConn{c} }
|
||||
func (n *netproxyConn) Read(b []byte) (int, error) { return n.c.Read(b) }
|
||||
func (n *netproxyConn) Write(b []byte) (int, error) { return n.c.Write(b) }
|
||||
func outboundConnReader(c outbound_netproxy.Conn) io.Reader { return &outboundConn{c} }
|
||||
func outboundConnWriter(c outbound_netproxy.Conn) io.Writer { return &outboundConn{c} }
|
||||
func (n *outboundConn) Read(b []byte) (int, error) { return n.c.Read(b) }
|
||||
func (n *outboundConn) Write(b []byte) (int, error) { return n.c.Write(b) }
|
||||
|
||||
func init() {
|
||||
common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
|
||||
|
||||
@@ -6,9 +6,11 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
outbound_netproxy "github.com/daeuniverse/outbound/netproxy"
|
||||
outbound_protocol "github.com/daeuniverse/outbound/protocol"
|
||||
@@ -110,7 +112,61 @@ func (d xrayDialer) DialContext(ctx context.Context, network, addr string) (outb
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d.dialer.Dial(ctx, destination)
|
||||
conn, err := d.dialer.Dial(ctx, destination)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// QUIC-based protocols assert the underlay conn to netproxy.PacketConn,
|
||||
// whose ReadFrom/WriteTo signatures differ from net.PacketConn. xray's UDP
|
||||
// dial returns *internet.PacketConnWrapper, so adapt it here.
|
||||
if destination.Network == xray_net.Network_UDP {
|
||||
if pc, ok := conn.(net.PacketConn); ok {
|
||||
return &packetConnAdapter{conn: conn, pc: pc}, nil
|
||||
}
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("tuic: UDP dial returned %T, which is not a net.PacketConn", conn)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
// packetConnAdapter adapts xray's UDP conn (net.Conn + net.PacketConn) to
|
||||
// outbound's netproxy.PacketConn interface.
|
||||
type packetConnAdapter struct {
|
||||
conn net.Conn
|
||||
pc net.PacketConn
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) Read(b []byte) (int, error) { return a.conn.Read(b) }
|
||||
func (a *packetConnAdapter) Write(b []byte) (int, error) { return a.conn.Write(b) }
|
||||
func (a *packetConnAdapter) Close() error { return a.conn.Close() }
|
||||
func (a *packetConnAdapter) SetDeadline(t time.Time) error {
|
||||
return a.conn.SetDeadline(t)
|
||||
}
|
||||
func (a *packetConnAdapter) SetReadDeadline(t time.Time) error {
|
||||
return a.conn.SetReadDeadline(t)
|
||||
}
|
||||
func (a *packetConnAdapter) SetWriteDeadline(t time.Time) error {
|
||||
return a.conn.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) ReadFrom(p []byte) (int, netip.AddrPort, error) {
|
||||
n, addr, err := a.pc.ReadFrom(p)
|
||||
if err != nil {
|
||||
return n, netip.AddrPort{}, err
|
||||
}
|
||||
ap, err := netip.ParseAddrPort(addr.String())
|
||||
if err != nil {
|
||||
return n, netip.AddrPort{}, err
|
||||
}
|
||||
return n, ap, nil
|
||||
}
|
||||
|
||||
func (a *packetConnAdapter) WriteTo(p []byte, addr string) (int, error) {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return a.pc.WriteTo(p, udpAddr)
|
||||
}
|
||||
|
||||
func xrayDestination(network, addr string) (xray_net.Destination, error) {
|
||||
@@ -123,7 +179,8 @@ func xrayDestination(network, addr string) (xray_net.Destination, error) {
|
||||
return xray_net.Destination{}, fmt.Errorf("tuic: invalid server port %q: %w", port, err)
|
||||
}
|
||||
address := xray_net.ParseAddress(host)
|
||||
if strings.HasPrefix(network, "udp") {
|
||||
mn, err := outbound_netproxy.ParseMagicNetwork(network)
|
||||
if err == nil && mn.Network == "udp" {
|
||||
return xray_net.UDPDestination(address, xray_net.Port(portNumber)), nil
|
||||
}
|
||||
return xray_net.TCPDestination(address, xray_net.Port(portNumber)), nil
|
||||
|
||||
@@ -17,7 +17,6 @@ backup=("etc/default/v2raya")
|
||||
build() {
|
||||
[ -d "$srcdir/v2rayA-$pkgver" ] && rm -rf "$srcdir/v2rayA-$pkgver"
|
||||
git clone --depth 1 --branch "v$pkgver" "https://github.com/v2rayA/v2rayA.git" "$srcdir/v2rayA-$pkgver" >/dev/null 2>&1
|
||||
cd "$srcdir/v2rayA-$pkgver" && git submodule update --init
|
||||
cd "$srcdir/v2rayA-$pkgver/gui"
|
||||
yarn --check-files --ignore-engines
|
||||
OUTPUT_DIR="$srcdir/v2rayA-$pkgver/service/server/router/web" yarn --ignore-engines build
|
||||
|
||||
Reference in new issue
Block a user