mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 01:56:48 +08:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
98a72b6fb4 | ||
![]() |
4f6f12616c | ||
![]() |
c87cf8ff52 | ||
![]() |
f7bd98b13c | ||
![]() |
d8934cf839 | ||
![]() |
ce8c415d43 | ||
![]() |
034a485afe | ||
![]() |
384d07999c | ||
![]() |
513f18bf53 | ||
![]() |
817fa72874 | ||
![]() |
0a252ac15d | ||
![]() |
6ba0dbafd7 | ||
![]() |
59e5d24280 | ||
![]() |
7d3d6b05e3 | ||
![]() |
55e045d098 | ||
![]() |
5a96ef632d | ||
![]() |
1f570d9cef | ||
![]() |
2d7b0e8cd4 | ||
![]() |
ec1fd008c4 | ||
![]() |
17825b25f2 | ||
![]() |
83ae38497b | ||
![]() |
7b4a686b74 | ||
![]() |
48ac662298 | ||
![]() |
1a238cbb7d | ||
![]() |
44b1dd0e67 |
2
.github/docker/Dockerfile
vendored
2
.github/docker/Dockerfile
vendored
@@ -22,7 +22,7 @@ VOLUME /etc/xray
|
|||||||
ARG TZ=Asia/Shanghai
|
ARG TZ=Asia/Shanghai
|
||||||
ENV TZ=$TZ
|
ENV TZ=$TZ
|
||||||
ENTRYPOINT [ "/usr/bin/xray" ]
|
ENTRYPOINT [ "/usr/bin/xray" ]
|
||||||
CMD [ "-config", "/etc/xray/config.json" ]
|
CMD [ "-confdir", "/etc/xray/" ]
|
||||||
|
|
||||||
ARG flavor=v2fly
|
ARG flavor=v2fly
|
||||||
COPY --from=build --chmod=644 /$flavor /usr/share/xray
|
COPY --from=build --chmod=644 /$flavor /usr/share/xray
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestQUICNameServer(t *testing.T) {
|
func TestQUICNameServer(t *testing.T) {
|
||||||
url, err := url.Parse("quic://dns.adguard.com")
|
url, err := url.Parse("quic://dns.adguard-dns.com")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP)
|
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
@@ -42,7 +42,7 @@ func TestQUICNameServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQUICNameServerWithIPv4Override(t *testing.T) {
|
func TestQUICNameServerWithIPv4Override(t *testing.T) {
|
||||||
url, err := url.Parse("quic://dns.adguard.com")
|
url, err := url.Parse("quic://dns.adguard-dns.com")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP4)
|
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP4)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
@@ -65,7 +65,7 @@ func TestQUICNameServerWithIPv4Override(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQUICNameServerWithIPv6Override(t *testing.T) {
|
func TestQUICNameServerWithIPv6Override(t *testing.T) {
|
||||||
url, err := url.Parse("quic://dns.adguard.com")
|
url, err := url.Parse("quic://dns.adguard-dns.com")
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP6)
|
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP6)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package router_test
|
package router_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -13,16 +14,25 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func getAssetPath(file string) (string, error) {
|
||||||
wd, err := os.Getwd()
|
path := platform.GetAssetLocation(file)
|
||||||
common.Must(err)
|
_, err := os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
path := filepath.Join("..", "..", "resources", file)
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return "", fmt.Errorf("can't find %s in standard asset locations or {project_root}/resources", file)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("can't stat %s: %v", path, err)
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("can't stat %s: %v", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
|
return path, nil
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "resources", "geoip.dat")))
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) {
|
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "resources", "geosite.dat")))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||||
@@ -217,10 +227,15 @@ func TestGeoIPMatcher6US(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadGeoIP(country string) ([]*router.CIDR, error) {
|
func loadGeoIP(country string) ([]*router.CIDR, error) {
|
||||||
geoipBytes, err := filesystem.ReadAsset("geoip.dat")
|
path, err := getAssetPath("geoip.dat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
geoipBytes, err := filesystem.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var geoipList router.GeoIPList
|
var geoipList router.GeoIPList
|
||||||
if err := proto.Unmarshal(geoipBytes, &geoipList); err != nil {
|
if err := proto.Unmarshal(geoipBytes, &geoipList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
package router_test
|
package router_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -10,7 +8,6 @@ import (
|
|||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"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/platform"
|
|
||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/protocol/http"
|
"github.com/xtls/xray-core/common/protocol/http"
|
||||||
@@ -20,18 +17,6 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
|
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat")))
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) {
|
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat")))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func withBackground() routing.Context {
|
func withBackground() routing.Context {
|
||||||
return &routing_session.Context{}
|
return &routing_session.Context{}
|
||||||
}
|
}
|
||||||
@@ -316,10 +301,15 @@ func TestRoutingRule(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadGeoSite(country string) ([]*Domain, error) {
|
func loadGeoSite(country string) ([]*Domain, error) {
|
||||||
geositeBytes, err := filesystem.ReadAsset("geosite.dat")
|
path, err := getAssetPath("geosite.dat")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
geositeBytes, err := filesystem.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var geositeList GeoSiteList
|
var geositeList GeoSiteList
|
||||||
if err := proto.Unmarshal(geositeBytes, &geositeList); err != nil {
|
if err := proto.Unmarshal(geositeBytes, &geositeList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -16,6 +16,7 @@ func TestFileLogger(t *testing.T) {
|
|||||||
common.Must(err)
|
common.Must(err)
|
||||||
path := f.Name()
|
path := f.Name()
|
||||||
common.Must(f.Close())
|
common.Must(f.Close())
|
||||||
|
defer os.Remove(path)
|
||||||
|
|
||||||
creator, err := CreateFileLogWriter(path)
|
creator, err := CreateFileLogWriter(path)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
Version_x byte = 24
|
Version_x byte = 24
|
||||||
Version_y byte = 11
|
Version_y byte = 11
|
||||||
Version_z byte = 11
|
Version_z byte = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
6
go.mod
6
go.mod
@@ -14,10 +14,10 @@ require (
|
|||||||
github.com/pires/go-proxyproto v0.8.0
|
github.com/pires/go-proxyproto v0.8.0
|
||||||
github.com/quic-go/quic-go v0.46.0
|
github.com/quic-go/quic-go v0.46.0
|
||||||
github.com/refraction-networking/utls v1.6.7
|
github.com/refraction-networking/utls v1.6.7
|
||||||
github.com/sagernet/sing v0.5.0
|
github.com/sagernet/sing v0.5.1
|
||||||
github.com/sagernet/sing-shadowsocks v0.2.7
|
github.com/sagernet/sing-shadowsocks v0.2.7
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771
|
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.10.0
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e
|
||||||
github.com/vishvananda/netlink v1.3.0
|
github.com/vishvananda/netlink v1.3.0
|
||||||
github.com/xtls/reality v0.0.0-20240712055506-48f0b2d5ed6d
|
github.com/xtls/reality v0.0.0-20240712055506-48f0b2d5ed6d
|
||||||
@@ -28,7 +28,7 @@ require (
|
|||||||
golang.org/x/sys v0.27.0
|
golang.org/x/sys v0.27.0
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
||||||
google.golang.org/grpc v1.67.1
|
google.golang.org/grpc v1.67.1
|
||||||
google.golang.org/protobuf v1.35.1
|
google.golang.org/protobuf v1.35.2
|
||||||
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489
|
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489
|
||||||
h12.io/socks v1.0.3
|
h12.io/socks v1.0.3
|
||||||
lukechampine.com/blake3 v1.3.0
|
lukechampine.com/blake3 v1.3.0
|
||||||
|
12
go.sum
12
go.sum
@@ -54,16 +54,16 @@ github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B
|
|||||||
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0=
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
|
||||||
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
|
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
|
||||||
github.com/sagernet/sing v0.5.0 h1:soo2wVwLcieKWWKIksFNK6CCAojUgAppqQVwyRYGkEM=
|
github.com/sagernet/sing v0.5.1 h1:mhL/MZVq0TjuvHcpYcFtmSD1BFOxZ/+8ofbNZcg1k1Y=
|
||||||
github.com/sagernet/sing v0.5.0/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
|
github.com/sagernet/sing v0.5.1/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 h1:zaopR1tbHEw5Nk6FAkM05wCslV6ahVegEZaKMv9ipx8=
|
||||||
github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE=
|
github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE=
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 h1:emzAzMZ1L9iaKCTxdy3Em8Wv4ChIAGnfiz18Cda70g4=
|
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 h1:emzAzMZ1L9iaKCTxdy3Em8Wv4ChIAGnfiz18Cda70g4=
|
||||||
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
|
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI=
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI=
|
||||||
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU=
|
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU=
|
||||||
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=
|
github.com/vishvananda/netlink v1.3.0 h1:X7l42GfcV4S6E4vHTsw48qbrV+9PVojNfIhZcwQdrZk=
|
||||||
@@ -129,8 +129,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:
|
|||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
|
||||||
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
|
||||||
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
|
||||||
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
|
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
|
||||||
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
@@ -42,6 +42,10 @@ type Address struct {
|
|||||||
net.Address
|
net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v Address) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(v.Address.String())
|
||||||
|
}
|
||||||
|
|
||||||
func (v *Address) UnmarshalJSON(data []byte) error {
|
func (v *Address) UnmarshalJSON(data []byte) error {
|
||||||
var rawStr string
|
var rawStr string
|
||||||
if err := json.Unmarshal(data, &rawStr); err != nil {
|
if err := json.Unmarshal(data, &rawStr); err != nil {
|
||||||
|
@@ -2,57 +2,15 @@ package conf_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/app/dns"
|
"github.com/xtls/xray-core/app/dns"
|
||||||
"github.com/xtls/xray-core/app/router"
|
|
||||||
"github.com/xtls/xray-core/common"
|
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/platform"
|
|
||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
|
||||||
. "github.com/xtls/xray-core/infra/conf"
|
. "github.com/xtls/xray-core/infra/conf"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
|
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "resources", "geoip.dat")))
|
|
||||||
}
|
|
||||||
|
|
||||||
geositeFilePath := filepath.Join(wd, "geosite.dat")
|
|
||||||
os.Setenv("xray.location.asset", wd)
|
|
||||||
geositeFile, err := os.OpenFile(geositeFilePath, os.O_CREATE|os.O_WRONLY, 0o600)
|
|
||||||
common.Must(err)
|
|
||||||
defer geositeFile.Close()
|
|
||||||
|
|
||||||
list := &router.GeoSiteList{
|
|
||||||
Entry: []*router.GeoSite{
|
|
||||||
{
|
|
||||||
CountryCode: "TEST",
|
|
||||||
Domain: []*router.Domain{
|
|
||||||
{Type: router.Domain_Full, Value: "example.com"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
listBytes, err := proto.Marshal(list)
|
|
||||||
common.Must(err)
|
|
||||||
common.Must2(geositeFile.Write(listBytes))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDNSConfigParsing(t *testing.T) {
|
func TestDNSConfigParsing(t *testing.T) {
|
||||||
geositePath := platform.GetAssetLocation("geosite.dat")
|
|
||||||
defer func() {
|
|
||||||
os.Remove(geositePath)
|
|
||||||
os.Unsetenv("xray.location.asset")
|
|
||||||
}()
|
|
||||||
|
|
||||||
parserCreator := func() func(string) (proto.Message, error) {
|
parserCreator := func() func(string) (proto.Message, error) {
|
||||||
return func(s string) (proto.Message, error) {
|
return func(s string) (proto.Message, error) {
|
||||||
config := new(DNSConfig)
|
config := new(DNSConfig)
|
||||||
|
@@ -2,6 +2,7 @@ package conf_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -18,21 +19,44 @@ import (
|
|||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func getAssetPath(file string) (string, error) {
|
||||||
wd, err := os.Getwd()
|
path := platform.GetAssetLocation(file)
|
||||||
common.Must(err)
|
_, err := os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) {
|
path := filepath.Join("..", "..", "resources", file)
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "resources", "geoip.dat")))
|
_, err := os.Stat(path)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return "", fmt.Errorf("can't find %s in standard asset locations or {project_root}/resources", file)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("can't stat %s: %v", path, err)
|
||||||
|
}
|
||||||
|
return path, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("can't stat %s: %v", path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("xray.location.asset", wd)
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToCidrList(t *testing.T) {
|
func TestToCidrList(t *testing.T) {
|
||||||
t.Log(os.Getenv("xray.location.asset"))
|
tempDir, err := os.MkdirTemp("", "test-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't create temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoiptestrouter.dat"), "geoip.dat"))
|
geoipPath, err := getAssetPath("geoip.dat")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
common.Must(filesystem.CopyFile(filepath.Join(tempDir, "geoip.dat"), geoipPath))
|
||||||
|
common.Must(filesystem.CopyFile(filepath.Join(tempDir, "geoiptestrouter.dat"), geoipPath))
|
||||||
|
|
||||||
|
os.Setenv("xray.location.asset", tempDir)
|
||||||
|
defer os.Unsetenv("xray.location.asset")
|
||||||
|
|
||||||
ips := StringList([]string{
|
ips := StringList([]string{
|
||||||
"geoip:us",
|
"geoip:us",
|
||||||
@@ -44,7 +68,7 @@ func TestToCidrList(t *testing.T) {
|
|||||||
"ext-ip:geoiptestrouter.dat:!ca",
|
"ext-ip:geoiptestrouter.dat:!ca",
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err := ToCidrList(ips)
|
_, err = ToCidrList(ips)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to parse geoip list, got %s", err)
|
t.Fatalf("Failed to parse geoip list, got %s", err)
|
||||||
}
|
}
|
||||||
|
@@ -149,6 +149,7 @@ type WebSocketConfig struct {
|
|||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Headers map[string]string `json:"headers"`
|
Headers map[string]string `json:"headers"`
|
||||||
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
||||||
|
HeartbeatPeriod uint32 `json:"heartbeatPeriod"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
@@ -178,6 +179,7 @@ func (c *WebSocketConfig) Build() (proto.Message, error) {
|
|||||||
Header: c.Headers,
|
Header: c.Headers,
|
||||||
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
||||||
Ed: ed,
|
Ed: ed,
|
||||||
|
HeartbeatPeriod: c.HeartbeatPeriod,
|
||||||
}
|
}
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
@@ -235,6 +237,8 @@ type SplitHTTPConfig struct {
|
|||||||
DownloadSettings *StreamConfig `json:"downloadSettings"`
|
DownloadSettings *StreamConfig `json:"downloadSettings"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
Extra json.RawMessage `json:"extra"`
|
Extra json.RawMessage `json:"extra"`
|
||||||
|
NoGRPCHeader bool `json:"noGRPCHeader"`
|
||||||
|
KeepAlivePeriod int64 `json:"keepAlivePeriod"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Xmux struct {
|
type Xmux struct {
|
||||||
@@ -306,7 +310,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
|
|||||||
switch c.Mode {
|
switch c.Mode {
|
||||||
case "":
|
case "":
|
||||||
c.Mode = "auto"
|
c.Mode = "auto"
|
||||||
case "auto", "packet-up", "stream-up":
|
case "auto", "packet-up", "stream-up", "stream-one":
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported mode: " + c.Mode)
|
return nil, errors.New("unsupported mode: " + c.Mode)
|
||||||
}
|
}
|
||||||
@@ -322,9 +326,14 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
|
|||||||
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
|
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
|
||||||
Xmux: &muxProtobuf,
|
Xmux: &muxProtobuf,
|
||||||
Mode: c.Mode,
|
Mode: c.Mode,
|
||||||
|
NoGRPCHeader: c.NoGRPCHeader,
|
||||||
|
KeepAlivePeriod: c.KeepAlivePeriod,
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if c.DownloadSettings != nil {
|
if c.DownloadSettings != nil {
|
||||||
|
if c.Mode == "stream-one" {
|
||||||
|
return nil, errors.New(`Can not use "downloadSettings" in "stream-one" mode.`)
|
||||||
|
}
|
||||||
if c.Extra != nil {
|
if c.Extra != nil {
|
||||||
c.DownloadSettings.SocketSettings = nil
|
c.DownloadSettings.SocketSettings = nil
|
||||||
}
|
}
|
||||||
@@ -705,8 +714,10 @@ func (p TransportProtocol) Build() (string, error) {
|
|||||||
case "ws", "websocket":
|
case "ws", "websocket":
|
||||||
return "websocket", nil
|
return "websocket", nil
|
||||||
case "h2", "h3", "http":
|
case "h2", "h3", "http":
|
||||||
|
errors.PrintDeprecatedFeatureWarning("HTTP transport", "XHTTP transport")
|
||||||
return "http", nil
|
return "http", nil
|
||||||
case "grpc":
|
case "grpc":
|
||||||
|
errors.PrintMigrateFeatureInfo("gRPC transport", "XHTTP transport")
|
||||||
return "grpc", nil
|
return "grpc", nil
|
||||||
case "httpupgrade":
|
case "httpupgrade":
|
||||||
return "httpupgrade", nil
|
return "httpupgrade", nil
|
||||||
|
@@ -491,12 +491,12 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||||||
rawInput = (*bytes.Buffer)(unsafe.Pointer(p + r.Offset))
|
rawInput = (*bytes.Buffer)(unsafe.Pointer(p + r.Offset))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return errors.New(account.ID.String() + " is not able to use " + requestAddons.Flow).AtWarning()
|
return errors.New("account " + account.ID.String() + " is not able to use the flow " + requestAddons.Flow).AtWarning()
|
||||||
}
|
}
|
||||||
case "":
|
case "":
|
||||||
inbound.CanSpliceCopy = 3
|
inbound.CanSpliceCopy = 3
|
||||||
if account.Flow == vless.XRV && (request.Command == protocol.RequestCommandTCP || isMuxAndNotXUDP(request, first)) {
|
if account.Flow == vless.XRV && (request.Command == protocol.RequestCommandTCP || isMuxAndNotXUDP(request, first)) {
|
||||||
return errors.New(account.ID.String() + " is not able to use \"\". Note that the pure TLS proxy has certain TLS in TLS characters.").AtWarning()
|
return errors.New("account " + account.ID.String() + " is rejected since the client flow is empty. Note that the pure TLS proxy has certain TLS in TLS characters.").AtWarning()
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return errors.New("unknown request flow " + requestAddons.Flow).AtWarning()
|
return errors.New("unknown request flow " + requestAddons.Flow).AtWarning()
|
||||||
|
@@ -81,7 +81,7 @@ func (v *TimedUserValidator) GetAEAD(userHash []byte) (*protocol.MemoryUser, boo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
return userd.(*protocol.MemoryUser), true, err
|
return userd.(*protocol.MemoryUser), true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *TimedUserValidator) Remove(email string) bool {
|
func (v *TimedUserValidator) Remove(email string) bool {
|
||||||
|
@@ -144,15 +144,20 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||||||
Reason: "",
|
Reason: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
if s.info.inboundTag != nil {
|
// what's this?
|
||||||
ctx = session.ContextWithInbound(ctx, s.info.inboundTag)
|
// Session information should not be shared between different connections
|
||||||
}
|
// why reuse them in server level? This will cause incorrect destoverride and unexpected routing behavior.
|
||||||
if s.info.outboundTag != nil {
|
// Disable it temporarily. Maybe s.info should be removed.
|
||||||
ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{s.info.outboundTag})
|
|
||||||
}
|
// if s.info.inboundTag != nil {
|
||||||
if s.info.contentTag != nil {
|
// ctx = session.ContextWithInbound(ctx, s.info.inboundTag)
|
||||||
ctx = session.ContextWithContent(ctx, s.info.contentTag)
|
// }
|
||||||
}
|
// if s.info.outboundTag != nil {
|
||||||
|
// ctx = session.ContextWithOutbounds(ctx, []*session.Outbound{s.info.outboundTag})
|
||||||
|
// }
|
||||||
|
// if s.info.contentTag != nil {
|
||||||
|
// ctx = session.ContextWithContent(ctx, s.info.contentTag)
|
||||||
|
// }
|
||||||
|
|
||||||
link, err := s.info.dispatcher.Dispatch(ctx, dest)
|
link, err := s.info.dispatcher.Dispatch(ctx, dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -4,16 +4,18 @@ package wireguard
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
goerrors "errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/sagernet/sing/common/control"
|
"github.com/sagernet/sing/common/control"
|
||||||
"github.com/vishvananda/netlink"
|
"github.com/vishvananda/netlink"
|
||||||
|
"github.com/xtls/xray-core/common/errors"
|
||||||
wgtun "golang.zx2c4.com/wireguard/tun"
|
wgtun "golang.zx2c4.com/wireguard/tun"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,6 +29,23 @@ type deviceNet struct {
|
|||||||
rules []*netlink.Rule
|
rules []*netlink.Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
tableIndex int = 10230
|
||||||
|
mu sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func allocateIPv6TableIndex() int {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
|
|
||||||
|
if tableIndex > 10230 {
|
||||||
|
errors.LogInfo(context.Background(), "allocate new ipv6 table index: ", tableIndex)
|
||||||
|
}
|
||||||
|
currentIndex := tableIndex
|
||||||
|
tableIndex++
|
||||||
|
return currentIndex
|
||||||
|
}
|
||||||
|
|
||||||
func newDeviceNet(interfaceName string) *deviceNet {
|
func newDeviceNet(interfaceName string) *deviceNet {
|
||||||
var dialer net.Dialer
|
var dialer net.Dialer
|
||||||
bindControl := control.BindToInterface(control.NewDefaultInterfaceFinder(), interfaceName, -1)
|
bindControl := control.BindToInterface(control.NewDefaultInterfaceFinder(), interfaceName, -1)
|
||||||
@@ -68,7 +87,7 @@ func (d *deviceNet) Close() (err error) {
|
|||||||
if len(errs) == 0 {
|
if len(errs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.Join(errs...)
|
return goerrors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousModeHandler) (t Tunnel, err error) {
|
func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousModeHandler) (t Tunnel, err error) {
|
||||||
@@ -138,7 +157,7 @@ func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ipv6TableIndex := 1023
|
ipv6TableIndex := allocateIPv6TableIndex()
|
||||||
if v6 != nil {
|
if v6 != nil {
|
||||||
r := &netlink.Route{Table: ipv6TableIndex}
|
r := &netlink.Route{Table: ipv6TableIndex}
|
||||||
for {
|
for {
|
||||||
|
@@ -96,6 +96,7 @@ func InitializeServerConfig(config *core.Config) (*exec.Cmd, error) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
testBinaryPath string
|
testBinaryPath string
|
||||||
|
testBinaryCleanFn func()
|
||||||
testBinaryPathGen sync.Once
|
testBinaryPathGen sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ func genTestBinaryPath() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tempDir = dir
|
tempDir = dir
|
||||||
|
testBinaryCleanFn = func() { os.RemoveAll(dir) }
|
||||||
return nil
|
return nil
|
||||||
}))
|
}))
|
||||||
file := filepath.Join(tempDir, "xray.test")
|
file := filepath.Join(tempDir, "xray.test")
|
||||||
|
12
testing/scenarios/main_test.go
Normal file
12
testing/scenarios/main_test.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package scenarios
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
genTestBinaryPath()
|
||||||
|
defer testBinaryCleanFn()
|
||||||
|
|
||||||
|
m.Run()
|
||||||
|
}
|
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func (c *Config) getHosts() []string {
|
func (c *Config) getHosts() []string {
|
||||||
if len(c.Host) == 0 {
|
if len(c.Host) == 0 {
|
||||||
return []string{"www.example.com"}
|
return []string{""}
|
||||||
}
|
}
|
||||||
return c.Host
|
return c.Host
|
||||||
}
|
}
|
||||||
|
@@ -215,9 +215,16 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Host := httpSettings.getRandomHost()
|
||||||
|
if Host == "" && net.ParseAddress(dest.NetAddr()).Family().IsDomain() {
|
||||||
|
Host = dest.Address.String()
|
||||||
|
} else if Host == "" {
|
||||||
|
Host = "www.example.com"
|
||||||
|
}
|
||||||
|
|
||||||
request := &http.Request{
|
request := &http.Request{
|
||||||
Method: httpMethod,
|
Method: httpMethod,
|
||||||
Host: httpSettings.getRandomHost(),
|
Host: Host,
|
||||||
Body: breader,
|
Body: breader,
|
||||||
URL: &url.URL{
|
URL: &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
|
@@ -255,7 +255,7 @@ func UClient(c net.Conn, config *Config, ctx context.Context, dest net.Destinati
|
|||||||
// Do not close the connection
|
// Do not close the connection
|
||||||
}()
|
}()
|
||||||
time.Sleep(time.Duration(randBetween(config.SpiderY[8], config.SpiderY[9])) * time.Millisecond) // return
|
time.Sleep(time.Duration(randBetween(config.SpiderY[8], config.SpiderY[9])) * time.Millisecond) // return
|
||||||
return nil, errors.New("REALITY: processed invalid connection")
|
return nil, errors.New("REALITY: processed invalid connection").AtWarning()
|
||||||
}
|
}
|
||||||
return uConn, nil
|
return uConn, nil
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,10 @@ import (
|
|||||||
// has no fields because everything is global state :O)
|
// has no fields because everything is global state :O)
|
||||||
type BrowserDialerClient struct{}
|
type BrowserDialerClient struct{}
|
||||||
|
|
||||||
|
func (c *BrowserDialerClient) Open(ctx context.Context, pureURL string) (io.WriteCloser, io.ReadCloser) {
|
||||||
|
panic("not implemented yet")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *BrowserDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
|
func (c *BrowserDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
|
||||||
panic("not implemented yet")
|
panic("not implemented yet")
|
||||||
}
|
}
|
||||||
@@ -25,7 +29,7 @@ func (c *BrowserDialerClient) OpenDownload(ctx context.Context, baseURL string)
|
|||||||
return nil, dummyAddr, dummyAddr, err
|
return nil, dummyAddr, dummyAddr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return websocket.NewConnection(conn, dummyAddr, nil), conn.RemoteAddr(), conn.LocalAddr(), nil
|
return websocket.NewConnection(conn, dummyAddr, nil, 0), conn.RemoteAddr(), conn.LocalAddr(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BrowserDialerClient) SendUploadRequest(ctx context.Context, url string, payload io.ReadWriteCloser, contentLength int64) error {
|
func (c *BrowserDialerClient) SendUploadRequest(ctx context.Context, url string, payload io.ReadWriteCloser, contentLength int64) error {
|
||||||
|
@@ -29,6 +29,10 @@ type DialerClient interface {
|
|||||||
// (ctx, baseURL) -> uploadWriter
|
// (ctx, baseURL) -> uploadWriter
|
||||||
// baseURL already contains sessionId
|
// baseURL already contains sessionId
|
||||||
OpenUpload(context.Context, string) io.WriteCloser
|
OpenUpload(context.Context, string) io.WriteCloser
|
||||||
|
|
||||||
|
// (ctx, pureURL) -> (uploadWriter, downloadReader)
|
||||||
|
// pureURL can not contain sessionId
|
||||||
|
Open(context.Context, string) (io.WriteCloser, io.ReadCloser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements splithttp.DialerClient in terms of direct network connections
|
// implements splithttp.DialerClient in terms of direct network connections
|
||||||
@@ -42,10 +46,37 @@ type DefaultDialerClient struct {
|
|||||||
dialUploadConn func(ctxInner context.Context) (net.Conn, error)
|
dialUploadConn func(ctxInner context.Context) (net.Conn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *DefaultDialerClient) Open(ctx context.Context, pureURL string) (io.WriteCloser, io.ReadCloser) {
|
||||||
|
reader, writer := io.Pipe()
|
||||||
|
req, _ := http.NewRequestWithContext(ctx, "POST", pureURL, reader)
|
||||||
|
req.Header = c.transportConfig.GetRequestHeader()
|
||||||
|
if !c.transportConfig.NoGRPCHeader {
|
||||||
|
req.Header.Set("Content-Type", "application/grpc")
|
||||||
|
}
|
||||||
|
wrc := &WaitReadCloser{Wait: make(chan struct{})}
|
||||||
|
go func() {
|
||||||
|
response, err := c.client.Do(req)
|
||||||
|
if err != nil || response.StatusCode != 200 {
|
||||||
|
if err != nil {
|
||||||
|
errors.LogInfoInner(ctx, err, "failed to open ", pureURL)
|
||||||
|
} else {
|
||||||
|
errors.LogInfo(ctx, "unexpected status ", response.StatusCode)
|
||||||
|
}
|
||||||
|
wrc.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wrc.Set(response.Body)
|
||||||
|
}()
|
||||||
|
return writer, wrc
|
||||||
|
}
|
||||||
|
|
||||||
func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
|
func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL string) io.WriteCloser {
|
||||||
reader, writer := io.Pipe()
|
reader, writer := io.Pipe()
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", baseURL, reader)
|
req, _ := http.NewRequestWithContext(ctx, "POST", baseURL, reader)
|
||||||
req.Header = c.transportConfig.GetRequestHeader()
|
req.Header = c.transportConfig.GetRequestHeader()
|
||||||
|
if !c.transportConfig.NoGRPCHeader {
|
||||||
|
req.Header.Set("Content-Type", "application/grpc")
|
||||||
|
}
|
||||||
go c.client.Do(req)
|
go c.client.Do(req)
|
||||||
return writer
|
return writer
|
||||||
}
|
}
|
||||||
@@ -223,3 +254,40 @@ func (c downloadBody) Close() error {
|
|||||||
c.cancel()
|
c.cancel()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WaitReadCloser struct {
|
||||||
|
Wait chan struct{}
|
||||||
|
io.ReadCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaitReadCloser) Set(rc io.ReadCloser) {
|
||||||
|
w.ReadCloser = rc
|
||||||
|
defer func() {
|
||||||
|
if recover() != nil {
|
||||||
|
rc.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
close(w.Wait)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaitReadCloser) Read(b []byte) (int, error) {
|
||||||
|
if w.ReadCloser == nil {
|
||||||
|
if <-w.Wait; w.ReadCloser == nil {
|
||||||
|
return 0, io.ErrClosedPipe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return w.ReadCloser.Read(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WaitReadCloser) Close() error {
|
||||||
|
if w.ReadCloser != nil {
|
||||||
|
return w.ReadCloser.Close()
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if recover() != nil && w.ReadCloser != nil {
|
||||||
|
w.ReadCloser.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
close(w.Wait)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -37,6 +37,8 @@ type Config struct {
|
|||||||
Xmux *Multiplexing `protobuf:"bytes,9,opt,name=xmux,proto3" json:"xmux,omitempty"`
|
Xmux *Multiplexing `protobuf:"bytes,9,opt,name=xmux,proto3" json:"xmux,omitempty"`
|
||||||
DownloadSettings *internet.StreamConfig `protobuf:"bytes,10,opt,name=downloadSettings,proto3" json:"downloadSettings,omitempty"`
|
DownloadSettings *internet.StreamConfig `protobuf:"bytes,10,opt,name=downloadSettings,proto3" json:"downloadSettings,omitempty"`
|
||||||
Mode string `protobuf:"bytes,11,opt,name=mode,proto3" json:"mode,omitempty"`
|
Mode string `protobuf:"bytes,11,opt,name=mode,proto3" json:"mode,omitempty"`
|
||||||
|
NoGRPCHeader bool `protobuf:"varint,12,opt,name=noGRPCHeader,proto3" json:"noGRPCHeader,omitempty"`
|
||||||
|
KeepAlivePeriod int64 `protobuf:"varint,13,opt,name=keepAlivePeriod,proto3" json:"keepAlivePeriod,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
func (x *Config) Reset() {
|
||||||
@@ -146,6 +148,20 @@ func (x *Config) GetMode() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Config) GetNoGRPCHeader() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.NoGRPCHeader
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Config) GetKeepAlivePeriod() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.KeepAlivePeriod
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
type RandRangeConfig struct {
|
type RandRangeConfig struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@@ -278,7 +294,7 @@ var file_transport_internet_splithttp_config_proto_rawDesc = []byte{
|
|||||||
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x1a, 0x1f,
|
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x1a, 0x1f,
|
||||||
0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
|
0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
|
||||||
0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
|
0x65, 0x74, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
|
||||||
0x96, 0x06, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f,
|
0xe4, 0x06, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f,
|
||||||
0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x12,
|
0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x12,
|
||||||
0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61,
|
0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61,
|
||||||
0x74, 0x68, 0x12, 0x4d, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03,
|
0x74, 0x68, 0x12, 0x4d, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03,
|
||||||
@@ -323,47 +339,52 @@ var file_transport_internet_splithttp_config_proto_rawDesc = []byte{
|
|||||||
0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61,
|
0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61,
|
||||||
0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x10, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61,
|
0x6d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x10, 0x64, 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61,
|
||||||
0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x6f, 0x64,
|
0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x6f, 0x64,
|
||||||
0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x1a, 0x39, 0x0a,
|
0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6d, 0x6f, 0x64, 0x65, 0x12, 0x22, 0x0a,
|
||||||
0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
|
0x0c, 0x6e, 0x6f, 0x47, 0x52, 0x50, 0x43, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x0c, 0x20,
|
||||||
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
|
0x01, 0x28, 0x08, 0x52, 0x0c, 0x6e, 0x6f, 0x47, 0x52, 0x50, 0x43, 0x48, 0x65, 0x61, 0x64, 0x65,
|
||||||
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
|
0x72, 0x12, 0x28, 0x0a, 0x0f, 0x6b, 0x65, 0x65, 0x70, 0x41, 0x6c, 0x69, 0x76, 0x65, 0x50, 0x65,
|
||||||
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x35, 0x0a, 0x0f, 0x52, 0x61, 0x6e, 0x64,
|
0x72, 0x69, 0x6f, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x6b, 0x65, 0x65, 0x70,
|
||||||
0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x66,
|
0x41, 0x6c, 0x69, 0x76, 0x65, 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x1a, 0x39, 0x0a, 0x0b, 0x48,
|
||||||
0x72, 0x6f, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12,
|
0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
|
||||||
0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x6f, 0x22,
|
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
|
||||||
0xfe, 0x02, 0x0a, 0x0c, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x78, 0x69, 0x6e, 0x67,
|
0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c,
|
||||||
0x12, 0x5a, 0x0a, 0x0e, 0x6d, 0x61, 0x78, 0x43, 0x6f, 0x6e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e,
|
0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x35, 0x0a, 0x0f, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61,
|
||||||
0x63, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e,
|
0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f,
|
||||||
0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
|
0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a,
|
||||||
0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e,
|
0x02, 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x6f, 0x22, 0xfe, 0x02,
|
||||||
0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x6d, 0x61,
|
0x0a, 0x0c, 0x4d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c, 0x65, 0x78, 0x69, 0x6e, 0x67, 0x12, 0x5a,
|
||||||
0x78, 0x43, 0x6f, 0x6e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x5a, 0x0a, 0x0e,
|
0x0a, 0x0e, 0x6d, 0x61, 0x78, 0x43, 0x6f, 0x6e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, 0x79,
|
||||||
0x6d, 0x61, 0x78, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72,
|
||||||
0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e,
|
|
||||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73,
|
|
||||||
0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e,
|
|
||||||
0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x6d, 0x61, 0x78, 0x43, 0x6f, 0x6e,
|
|
||||||
0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x5a, 0x0a, 0x0e, 0x63, 0x4d, 0x61, 0x78,
|
|
||||||
0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
|
|
||||||
0x32, 0x32, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72,
|
|
||||||
0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74,
|
|
||||||
0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f,
|
|
||||||
0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54,
|
|
||||||
0x69, 0x6d, 0x65, 0x73, 0x12, 0x5a, 0x0a, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x66, 0x65,
|
|
||||||
0x74, 0x69, 0x6d, 0x65, 0x4d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78,
|
|
||||||
0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e,
|
|
||||||
0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70,
|
|
||||||
0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67,
|
|
||||||
0x52, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x66, 0x65, 0x74, 0x69, 0x6d, 0x65, 0x4d, 0x73,
|
|
||||||
0x42, 0x85, 0x01, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72,
|
|
||||||
0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
|
0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
|
||||||
0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69,
|
0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52,
|
||||||
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72,
|
0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x6d, 0x61, 0x78, 0x43,
|
||||||
0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72,
|
0x6f, 0x6e, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x5a, 0x0a, 0x0e, 0x6d, 0x61,
|
||||||
0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x73, 0x70, 0x6c, 0x69, 0x74,
|
0x78, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01,
|
||||||
0x68, 0x74, 0x74, 0x70, 0xaa, 0x02, 0x21, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e,
|
0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
||||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53,
|
0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c,
|
||||||
0x70, 0x6c, 0x69, 0x74, 0x48, 0x74, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65,
|
||||||
|
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e, 0x6d, 0x61, 0x78, 0x43, 0x6f, 0x6e, 0x6e, 0x65,
|
||||||
|
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x5a, 0x0a, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x52, 0x65,
|
||||||
|
0x75, 0x73, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32,
|
||||||
|
0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e,
|
||||||
|
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74,
|
||||||
|
0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66,
|
||||||
|
0x69, 0x67, 0x52, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x52, 0x65, 0x75, 0x73, 0x65, 0x54, 0x69, 0x6d,
|
||||||
|
0x65, 0x73, 0x12, 0x5a, 0x0a, 0x0e, 0x63, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x66, 0x65, 0x74, 0x69,
|
||||||
|
0x6d, 0x65, 0x4d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x32, 0x2e, 0x78, 0x72, 0x61,
|
||||||
|
0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65,
|
||||||
|
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52,
|
||||||
|
0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x0e,
|
||||||
|
0x63, 0x4d, 0x61, 0x78, 0x4c, 0x69, 0x66, 0x65, 0x74, 0x69, 0x6d, 0x65, 0x4d, 0x73, 0x42, 0x85,
|
||||||
|
0x01, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e,
|
||||||
|
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73,
|
||||||
|
0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68,
|
||||||
|
0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79,
|
||||||
|
0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f,
|
||||||
|
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74,
|
||||||
|
0x74, 0x70, 0xaa, 0x02, 0x21, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70,
|
||||||
|
0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x70, 0x6c,
|
||||||
|
0x69, 0x74, 0x48, 0x74, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -20,6 +20,8 @@ message Config {
|
|||||||
Multiplexing xmux = 9;
|
Multiplexing xmux = 9;
|
||||||
xray.transport.internet.StreamConfig downloadSettings = 10;
|
xray.transport.internet.StreamConfig downloadSettings = 10;
|
||||||
string mode = 11;
|
string mode = 11;
|
||||||
|
bool noGRPCHeader = 12;
|
||||||
|
int64 keepAlivePeriod = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
message RandRangeConfig {
|
message RandRangeConfig {
|
||||||
|
@@ -3,6 +3,7 @@ package splithttp
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
gotls "crypto/tls"
|
gotls "crypto/tls"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -31,10 +32,10 @@ import (
|
|||||||
const connIdleTimeout = 300 * time.Second
|
const connIdleTimeout = 300 * time.Second
|
||||||
|
|
||||||
// consistent with quic-go
|
// consistent with quic-go
|
||||||
const h3KeepalivePeriod = 10 * time.Second
|
const quicgoH3KeepAlivePeriod = 10 * time.Second
|
||||||
|
|
||||||
// consistent with chrome
|
// consistent with chrome
|
||||||
const h2KeepalivePeriod = 45 * time.Second
|
const chromeH2KeepAlivePeriod = 45 * time.Second
|
||||||
|
|
||||||
type dialerConf struct {
|
type dialerConf struct {
|
||||||
net.Destination
|
net.Destination
|
||||||
@@ -132,9 +133,17 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keepAlivePeriod := time.Duration(streamSettings.ProtocolSettings.(*Config).KeepAlivePeriod) * time.Second
|
||||||
|
|
||||||
var transport http.RoundTripper
|
var transport http.RoundTripper
|
||||||
|
|
||||||
if isH3 {
|
if isH3 {
|
||||||
|
if keepAlivePeriod == 0 {
|
||||||
|
keepAlivePeriod = quicgoH3KeepAlivePeriod
|
||||||
|
}
|
||||||
|
if keepAlivePeriod < 0 {
|
||||||
|
keepAlivePeriod = 0
|
||||||
|
}
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
MaxIdleTimeout: connIdleTimeout,
|
MaxIdleTimeout: connIdleTimeout,
|
||||||
|
|
||||||
@@ -142,7 +151,7 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
// http3) is different, so it is hardcoded here for clarity.
|
// http3) is different, so it is hardcoded here for clarity.
|
||||||
// https://github.com/quic-go/quic-go/blob/b8ea5c798155950fb5bbfdd06cad1939c9355878/http3/client.go#L36-L39
|
// https://github.com/quic-go/quic-go/blob/b8ea5c798155950fb5bbfdd06cad1939c9355878/http3/client.go#L36-L39
|
||||||
MaxIncomingStreams: -1,
|
MaxIncomingStreams: -1,
|
||||||
KeepAlivePeriod: h3KeepalivePeriod,
|
KeepAlivePeriod: keepAlivePeriod,
|
||||||
}
|
}
|
||||||
transport = &http3.RoundTripper{
|
transport = &http3.RoundTripper{
|
||||||
QUICConfig: quicConfig,
|
QUICConfig: quicConfig,
|
||||||
@@ -185,12 +194,18 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else if isH2 {
|
} else if isH2 {
|
||||||
|
if keepAlivePeriod == 0 {
|
||||||
|
keepAlivePeriod = chromeH2KeepAlivePeriod
|
||||||
|
}
|
||||||
|
if keepAlivePeriod < 0 {
|
||||||
|
keepAlivePeriod = 0
|
||||||
|
}
|
||||||
transport = &http2.Transport{
|
transport = &http2.Transport{
|
||||||
DialTLSContext: func(ctxInner context.Context, network string, addr string, cfg *gotls.Config) (net.Conn, error) {
|
DialTLSContext: func(ctxInner context.Context, network string, addr string, cfg *gotls.Config) (net.Conn, error) {
|
||||||
return dialContext(ctxInner)
|
return dialContext(ctxInner)
|
||||||
},
|
},
|
||||||
IdleConnTimeout: connIdleTimeout,
|
IdleConnTimeout: connIdleTimeout,
|
||||||
ReadIdleTimeout: h2KeepalivePeriod,
|
ReadIdleTimeout: keepAlivePeriod,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
httpDialContext := func(ctxInner context.Context, network string, addr string) (net.Conn, error) {
|
httpDialContext := func(ctxInner context.Context, network string, addr string) (net.Conn, error) {
|
||||||
@@ -201,7 +216,7 @@ func createHTTPClient(dest net.Destination, streamSettings *internet.MemoryStrea
|
|||||||
DialTLSContext: httpDialContext,
|
DialTLSContext: httpDialContext,
|
||||||
DialContext: httpDialContext,
|
DialContext: httpDialContext,
|
||||||
IdleConnTimeout: connIdleTimeout,
|
IdleConnTimeout: connIdleTimeout,
|
||||||
// chunked transfer download with keepalives is buggy with
|
// chunked transfer download with KeepAlives is buggy with
|
||||||
// http.Client and our custom dial context.
|
// http.Client and our custom dial context.
|
||||||
DisableKeepAlives: true,
|
DisableKeepAlives: true,
|
||||||
}
|
}
|
||||||
@@ -279,9 +294,33 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
requestURL2.RawQuery = config2.GetNormalizedQuery()
|
requestURL2.RawQuery = config2.GetNormalizedQuery()
|
||||||
}
|
}
|
||||||
|
|
||||||
reader, remoteAddr, localAddr, err := httpClient2.OpenDownload(context.WithoutCancel(ctx), requestURL2.String())
|
mode := transportConfiguration.Mode
|
||||||
if err != nil {
|
if mode == "" || mode == "auto" {
|
||||||
return nil, err
|
mode = "packet-up"
|
||||||
|
if (tlsConfig != nil && (len(tlsConfig.NextProtocol) != 1 || tlsConfig.NextProtocol[0] == "h2")) || realityConfig != nil {
|
||||||
|
mode = "stream-up"
|
||||||
|
}
|
||||||
|
if realityConfig != nil && transportConfiguration.DownloadSettings == nil {
|
||||||
|
mode = "stream-one"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errors.LogInfo(ctx, "XHTTP is using mode: "+mode)
|
||||||
|
|
||||||
|
var writer io.WriteCloser
|
||||||
|
var reader io.ReadCloser
|
||||||
|
var remoteAddr, localAddr net.Addr
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if mode == "stream-one" {
|
||||||
|
requestURL.Path = transportConfiguration.GetNormalizedPath()
|
||||||
|
writer, reader = httpClient.Open(context.WithoutCancel(ctx), requestURL.String())
|
||||||
|
remoteAddr = &net.TCPAddr{}
|
||||||
|
localAddr = &net.TCPAddr{}
|
||||||
|
} else {
|
||||||
|
reader, remoteAddr, localAddr, err = httpClient2.OpenDownload(context.WithoutCancel(ctx), requestURL2.String())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if muxRes != nil {
|
if muxRes != nil {
|
||||||
@@ -293,7 +332,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
closed := false
|
closed := false
|
||||||
|
|
||||||
conn := splitConn{
|
conn := splitConn{
|
||||||
writer: nil,
|
writer: writer,
|
||||||
reader: reader,
|
reader: reader,
|
||||||
remoteAddr: remoteAddr,
|
remoteAddr: remoteAddr,
|
||||||
localAddr: localAddr,
|
localAddr: localAddr,
|
||||||
@@ -311,9 +350,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := transportConfiguration.Mode
|
if mode == "stream-one" {
|
||||||
if mode == "auto" && realityConfig != nil {
|
return stat.Connection(&conn), nil
|
||||||
mode = "stream-up"
|
|
||||||
}
|
}
|
||||||
if mode == "stream-up" {
|
if mode == "stream-up" {
|
||||||
conn.writer = httpClient.OpenUpload(ctx, requestURL.String())
|
conn.writer = httpClient.OpenUpload(ctx, requestURL.String())
|
||||||
@@ -324,7 +362,8 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
// WithSizeLimit(0) will still allow single bytes to pass, and a lot of
|
// WithSizeLimit(0) will still allow single bytes to pass, and a lot of
|
||||||
// code relies on this behavior. Subtract 1 so that together with
|
// code relies on this behavior. Subtract 1 so that together with
|
||||||
// uploadWriter wrapper, exact size limits can be enforced
|
// uploadWriter wrapper, exact size limits can be enforced
|
||||||
uploadPipeReader, uploadPipeWriter := pipe.New(pipe.WithSizeLimit(maxUploadSize - 1))
|
// uploadPipeReader, uploadPipeWriter := pipe.New(pipe.WithSizeLimit(maxUploadSize - 1))
|
||||||
|
uploadPipeReader, uploadPipeWriter := pipe.New(pipe.WithSizeLimit(maxUploadSize - buf.Size))
|
||||||
|
|
||||||
conn.writer = uploadWriter{
|
conn.writer = uploadWriter{
|
||||||
uploadPipeWriter,
|
uploadPipeWriter,
|
||||||
@@ -400,10 +439,12 @@ type uploadWriter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w uploadWriter) Write(b []byte) (int, error) {
|
func (w uploadWriter) Write(b []byte) (int, error) {
|
||||||
capacity := int(w.maxLen - w.Len())
|
/*
|
||||||
if capacity > 0 && capacity < len(b) {
|
capacity := int(w.maxLen - w.Len())
|
||||||
b = b[:capacity]
|
if capacity > 0 && capacity < len(b) {
|
||||||
}
|
b = b[:capacity]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
buffer := buf.New()
|
buffer := buf.New()
|
||||||
n, err := buffer.Write(b)
|
n, err := buffer.Write(b)
|
||||||
|
@@ -102,14 +102,22 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
|
|
||||||
h.config.WriteResponseHeader(writer)
|
h.config.WriteResponseHeader(writer)
|
||||||
|
|
||||||
|
validRange := h.config.GetNormalizedXPaddingBytes()
|
||||||
|
x_padding := int32(len(request.URL.Query().Get("x_padding")))
|
||||||
|
if validRange.To > 0 && (x_padding < validRange.From || x_padding > validRange.To) {
|
||||||
|
errors.LogInfo(context.Background(), "invalid x_padding length:", x_padding)
|
||||||
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sessionId := ""
|
sessionId := ""
|
||||||
subpath := strings.Split(request.URL.Path[len(h.path):], "/")
|
subpath := strings.Split(request.URL.Path[len(h.path):], "/")
|
||||||
if len(subpath) > 0 {
|
if len(subpath) > 0 {
|
||||||
sessionId = subpath[0]
|
sessionId = subpath[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if sessionId == "" {
|
if sessionId == "" && h.config.Mode != "" && h.config.Mode != "auto" && h.config.Mode != "stream-one" && h.config.Mode != "stream-up" {
|
||||||
errors.LogInfo(context.Background(), "no sessionid on request:", request.URL.Path)
|
errors.LogInfo(context.Background(), "stream-one mode is not allowed")
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -126,17 +134,20 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSession := h.upsertSession(sessionId)
|
var currentSession *httpSession
|
||||||
|
if sessionId != "" {
|
||||||
|
currentSession = h.upsertSession(sessionId)
|
||||||
|
}
|
||||||
scMaxEachPostBytes := int(h.ln.config.GetNormalizedScMaxEachPostBytes().To)
|
scMaxEachPostBytes := int(h.ln.config.GetNormalizedScMaxEachPostBytes().To)
|
||||||
|
|
||||||
if request.Method == "POST" {
|
if request.Method == "POST" && sessionId != "" {
|
||||||
seq := ""
|
seq := ""
|
||||||
if len(subpath) > 1 {
|
if len(subpath) > 1 {
|
||||||
seq = subpath[1]
|
seq = subpath[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if seq == "" {
|
if seq == "" {
|
||||||
if h.config.Mode == "packet-up" {
|
if h.config.Mode != "" && h.config.Mode != "auto" && h.config.Mode != "stream-up" {
|
||||||
errors.LogInfo(context.Background(), "stream-up mode is not allowed")
|
errors.LogInfo(context.Background(), "stream-up mode is not allowed")
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@@ -154,7 +165,7 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.config.Mode == "stream-up" {
|
if h.config.Mode != "" && h.config.Mode != "auto" && h.config.Mode != "packet-up" {
|
||||||
errors.LogInfo(context.Background(), "packet-up mode is not allowed")
|
errors.LogInfo(context.Background(), "packet-up mode is not allowed")
|
||||||
writer.WriteHeader(http.StatusBadRequest)
|
writer.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@@ -193,16 +204,18 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
}
|
}
|
||||||
|
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
} else if request.Method == "GET" {
|
} else if request.Method == "GET" || sessionId == "" {
|
||||||
responseFlusher, ok := writer.(http.Flusher)
|
responseFlusher, ok := writer.(http.Flusher)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("expected http.ResponseWriter to be an http.Flusher")
|
panic("expected http.ResponseWriter to be an http.Flusher")
|
||||||
}
|
}
|
||||||
|
|
||||||
// after GET is done, the connection is finished. disable automatic
|
if sessionId != "" {
|
||||||
// session reaping, and handle it in defer
|
// after GET is done, the connection is finished. disable automatic
|
||||||
currentSession.isFullyConnected.Close()
|
// session reaping, and handle it in defer
|
||||||
defer h.sessions.Delete(sessionId)
|
currentSession.isFullyConnected.Close()
|
||||||
|
defer h.sessions.Delete(sessionId)
|
||||||
|
}
|
||||||
|
|
||||||
// magic header instructs nginx + apache to not buffer response body
|
// magic header instructs nginx + apache to not buffer response body
|
||||||
writer.Header().Set("X-Accel-Buffering", "no")
|
writer.Header().Set("X-Accel-Buffering", "no")
|
||||||
@@ -210,6 +223,7 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
// Should be able to prevent overloading the cache, or stop CDNs from
|
// Should be able to prevent overloading the cache, or stop CDNs from
|
||||||
// teeing the response stream into their cache, causing slowdowns.
|
// teeing the response stream into their cache, causing slowdowns.
|
||||||
writer.Header().Set("Cache-Control", "no-store")
|
writer.Header().Set("Cache-Control", "no-store")
|
||||||
|
|
||||||
if !h.config.NoSSEHeader {
|
if !h.config.NoSSEHeader {
|
||||||
// magic header to make the HTTP middle box consider this as SSE to disable buffer
|
// magic header to make the HTTP middle box consider this as SSE to disable buffer
|
||||||
writer.Header().Set("Content-Type", "text/event-stream")
|
writer.Header().Set("Content-Type", "text/event-stream")
|
||||||
@@ -227,9 +241,12 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
downloadDone: downloadDone,
|
downloadDone: downloadDone,
|
||||||
responseFlusher: responseFlusher,
|
responseFlusher: responseFlusher,
|
||||||
},
|
},
|
||||||
reader: currentSession.uploadQueue,
|
reader: request.Body,
|
||||||
remoteAddr: remoteAddr,
|
remoteAddr: remoteAddr,
|
||||||
}
|
}
|
||||||
|
if sessionId != "" {
|
||||||
|
conn.reader = currentSession.uploadQueue
|
||||||
|
}
|
||||||
|
|
||||||
h.ln.addConn(stat.Connection(&conn))
|
h.ln.addConn(stat.Connection(&conn))
|
||||||
|
|
||||||
|
@@ -424,8 +424,8 @@ func Test_maxUpload(t *testing.T) {
|
|||||||
ProtocolSettings: &Config{
|
ProtocolSettings: &Config{
|
||||||
Path: "/sh",
|
Path: "/sh",
|
||||||
ScMaxEachPostBytes: &RandRangeConfig{
|
ScMaxEachPostBytes: &RandRangeConfig{
|
||||||
From: 100,
|
From: 10000,
|
||||||
To: 100,
|
To: 10000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -434,7 +434,7 @@ func Test_maxUpload(t *testing.T) {
|
|||||||
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) {
|
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) {
|
||||||
go func(c stat.Connection) {
|
go func(c stat.Connection) {
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
var b [1024]byte
|
var b [10240]byte
|
||||||
c.SetReadDeadline(time.Now().Add(2 * time.Second))
|
c.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||||
n, err := c.Read(b[:])
|
n, err := c.Read(b[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -452,11 +452,11 @@ func Test_maxUpload(t *testing.T) {
|
|||||||
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings)
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings)
|
||||||
|
|
||||||
// send a slightly too large upload
|
// send a slightly too large upload
|
||||||
var upload [101]byte
|
var upload [10001]byte
|
||||||
_, err = conn.Write(upload[:])
|
_, err = conn.Write(upload[:])
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
|
|
||||||
var b [1024]byte
|
var b [10240]byte
|
||||||
n, _ := io.ReadFull(conn, b[:])
|
n, _ := io.ReadFull(conn, b[:])
|
||||||
fmt.Println("string is", n)
|
fmt.Println("string is", n)
|
||||||
if string(b[:n]) != "Response" {
|
if string(b[:n]) != "Response" {
|
||||||
@@ -464,7 +464,7 @@ func Test_maxUpload(t *testing.T) {
|
|||||||
}
|
}
|
||||||
common.Must(conn.Close())
|
common.Must(conn.Close())
|
||||||
|
|
||||||
if uploadSize > 100 || uploadSize == 0 {
|
if uploadSize > 10000 || uploadSize == 0 {
|
||||||
t.Error("incorrect upload size: ", uploadSize)
|
t.Error("incorrect upload size: ", uploadSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -51,5 +51,5 @@ func (c *Config) getCertPool() (*x509.CertPool, error) {
|
|||||||
return nil, errors.New("append cert to root").AtWarning().Base(err)
|
return nil, errors.New("append cert to root").AtWarning().Base(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pool, err
|
return pool, nil
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ type Config struct {
|
|||||||
Header map[string]string `protobuf:"bytes,3,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
Header map[string]string `protobuf:"bytes,3,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
|
||||||
AcceptProxyProtocol bool `protobuf:"varint,4,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"`
|
AcceptProxyProtocol bool `protobuf:"varint,4,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"`
|
||||||
Ed uint32 `protobuf:"varint,5,opt,name=ed,proto3" json:"ed,omitempty"`
|
Ed uint32 `protobuf:"varint,5,opt,name=ed,proto3" json:"ed,omitempty"`
|
||||||
|
HeartbeatPeriod uint32 `protobuf:"varint,6,opt,name=heartbeatPeriod,proto3" json:"heartbeatPeriod,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *Config) Reset() {
|
func (x *Config) Reset() {
|
||||||
@@ -97,6 +98,13 @@ func (x *Config) GetEd() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Config) GetHeartbeatPeriod() uint32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.HeartbeatPeriod
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_transport_internet_websocket_config_proto protoreflect.FileDescriptor
|
var File_transport_internet_websocket_config_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_transport_internet_websocket_config_proto_rawDesc = []byte{
|
var file_transport_internet_websocket_config_proto_rawDesc = []byte{
|
||||||
@@ -104,8 +112,8 @@ var file_transport_internet_websocket_config_proto_rawDesc = []byte{
|
|||||||
0x72, 0x6e, 0x65, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2f, 0x63,
|
0x72, 0x6e, 0x65, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2f, 0x63,
|
||||||
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x78, 0x72, 0x61,
|
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x78, 0x72, 0x61,
|
||||||
0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65,
|
0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65,
|
||||||
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x22, 0xfe,
|
0x72, 0x6e, 0x65, 0x74, 0x2e, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x22, 0xa8,
|
||||||
0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73,
|
0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73,
|
||||||
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x12, 0x0a,
|
0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x12, 0x0a,
|
||||||
0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74,
|
0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74,
|
||||||
0x68, 0x12, 0x4d, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28,
|
0x68, 0x12, 0x4d, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28,
|
||||||
@@ -117,19 +125,22 @@ var file_transport_internet_websocket_config_proto_rawDesc = []byte{
|
|||||||
0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52,
|
0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||||
0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74,
|
0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x50, 0x72, 0x6f, 0x74,
|
||||||
0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d,
|
0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d,
|
||||||
0x52, 0x02, 0x65, 0x64, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e,
|
0x52, 0x02, 0x65, 0x64, 0x12, 0x28, 0x0a, 0x0f, 0x68, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61,
|
||||||
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x74, 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0f, 0x68,
|
||||||
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
|
0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x1a, 0x39,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42,
|
0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a,
|
||||||
0x85, 0x01, 0x0a, 0x25, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61,
|
0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12,
|
||||||
0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e,
|
0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
|
||||||
0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74,
|
0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x85, 0x01, 0x0a, 0x25, 0x63, 0x6f,
|
||||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61,
|
0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74,
|
||||||
0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74,
|
0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63,
|
||||||
0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63,
|
0x6b, 0x65, 0x74, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
|
||||||
0x6b, 0x65, 0x74, 0xaa, 0x02, 0x21, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73,
|
0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65,
|
||||||
0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x57, 0x65,
|
0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72,
|
||||||
0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x6e, 0x65, 0x74, 0x2f, 0x77, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0xaa, 0x02, 0x21,
|
||||||
|
0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x49,
|
||||||
|
0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x57, 0x65, 0x62, 0x73, 0x6f, 0x63, 0x6b, 0x65,
|
||||||
|
0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@@ -12,4 +12,5 @@ message Config {
|
|||||||
map<string, string> header = 3;
|
map<string, string> header = 3;
|
||||||
bool accept_proxy_protocol = 4;
|
bool accept_proxy_protocol = 4;
|
||||||
uint32 ed = 5;
|
uint32 ed = 5;
|
||||||
|
uint32 heartbeatPeriod = 6;
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,18 @@ type connection struct {
|
|||||||
remoteAddr net.Addr
|
remoteAddr net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConnection(conn *websocket.Conn, remoteAddr net.Addr, extraReader io.Reader) *connection {
|
func NewConnection(conn *websocket.Conn, remoteAddr net.Addr, extraReader io.Reader, heartbeatPeriod uint32) *connection {
|
||||||
|
if heartbeatPeriod != 0 {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(time.Duration(heartbeatPeriod) * time.Second)
|
||||||
|
if err := conn.WriteControl(websocket.PingMessage, []byte{}, time.Time{}); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
return &connection{
|
return &connection{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
remoteAddr: remoteAddr,
|
remoteAddr: remoteAddr,
|
||||||
|
@@ -99,7 +99,7 @@ func dialWebSocket(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewConnection(conn, conn.RemoteAddr(), nil), nil
|
return NewConnection(conn, conn.RemoteAddr(), nil, wsSettings.HeartbeatPeriod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
header := wsSettings.GetRequestHeader()
|
header := wsSettings.GetRequestHeader()
|
||||||
@@ -117,7 +117,7 @@ func dialWebSocket(ctx context.Context, dest net.Destination, streamSettings *in
|
|||||||
return nil, errors.New("failed to dial to (", uri, "): ", reason).Base(err)
|
return nil, errors.New("failed to dial to (", uri, "): ", reason).Base(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewConnection(conn, conn.RemoteAddr(), nil), nil
|
return NewConnection(conn, conn.RemoteAddr(), nil, wsSettings.HeartbeatPeriod), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type delayDialConn struct {
|
type delayDialConn struct {
|
||||||
|
@@ -73,7 +73,7 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
h.ln.addConn(NewConnection(conn, remoteAddr, extraReader))
|
h.ln.addConn(NewConnection(conn, remoteAddr, extraReader, h.ln.config.HeartbeatPeriod))
|
||||||
}
|
}
|
||||||
|
|
||||||
type Listener struct {
|
type Listener struct {
|
||||||
|
Reference in New Issue
Block a user