Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/omengye/Xray-core into minimal
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	proxy/wireguard/server.go
  • Loading branch information
omengye committed Nov 22, 2024
2 parents 53a98e3 + 61df3b3 commit f3b5d0b
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 50 deletions.
1 change: 1 addition & 0 deletions common/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestFileLogger(t *testing.T) {
common.Must(err)
path := f.Name()
common.Must(f.Close())
defer os.Remove(path)

creator, err := CreateFileLogWriter(path)
common.Must(err)
Expand Down
2 changes: 1 addition & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var (
Version_x byte = 24
Version_y byte = 11
Version_z byte = 11
Version_z byte = 21
)

var (
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/pires/go-proxyproto v0.8.0
github.com/quic-go/quic-go v0.46.0
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/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771
github.com/stretchr/testify v1.9.0
Expand All @@ -26,7 +26,7 @@ require (
golang.org/x/sys v0.27.0
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
google.golang.org/protobuf v1.35.2
h12.io/socks v1.0.3
lukechampine.com/blake3 v1.3.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ 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/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/sagernet/sing v0.5.0 h1:soo2wVwLcieKWWKIksFNK6CCAojUgAppqQVwyRYGkEM=
github.com/sagernet/sing v0.5.0/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak=
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-shadowsocks v0.2.7 h1:zaopR1tbHEw5Nk6FAkM05wCslV6ahVegEZaKMv9ipx8=
github.com/sagernet/sing-shadowsocks v0.2.7/go.mod h1:0rIKJZBR65Qi0zwdKezt4s57y/Tl1ofkaq6NlkzVuyE=
github.com/seiflotfy/cuckoofilter v0.0.0-20240715131351-a2f2c23f1771 h1:emzAzMZ1L9iaKCTxdy3Em8Wv4ChIAGnfiz18Cda70g4=
Expand Down Expand Up @@ -120,8 +120,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/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
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.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
4 changes: 4 additions & 0 deletions infra/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ type Address struct {
net.Address
}

func (v Address) MarshalJSON() ([]byte, error) {
return json.Marshal(v.Address.String())
}

func (v *Address) UnmarshalJSON(data []byte) error {
var rawStr string
if err := json.Unmarshal(data, &rawStr); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type SplitHTTPConfig struct {
DownloadSettings *StreamConfig `json:"downloadSettings"`
Mode string `json:"mode"`
Extra json.RawMessage `json:"extra"`
NoGRPCHeader bool `json:"noGRPCHeader"`
}

type Xmux struct {
Expand Down Expand Up @@ -321,6 +322,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) {
XPaddingBytes: splithttpNewRandRangeConfig(c.XPaddingBytes),
Xmux: &muxProtobuf,
Mode: c.Mode,
NoGRPCHeader: c.NoGRPCHeader,
}
var err error
if c.DownloadSettings != nil {
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func (c *Config) getHosts() []string {
if len(c.Host) == 0 {
return []string{"www.example.com"}
return []string{""}
}
return c.Host
}
Expand Down
9 changes: 8 additions & 1 deletion transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Method: httpMethod,
Host: httpSettings.getRandomHost(),
Host: Host,
Body: breader,
URL: &url.URL{
Scheme: "https",
Expand Down
3 changes: 3 additions & 0 deletions transport/internet/splithttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (c *DefaultDialerClient) OpenUpload(ctx context.Context, baseURL string) io
reader, writer := io.Pipe()
req, _ := http.NewRequestWithContext(ctx, "POST", baseURL, reader)
req.Header = c.transportConfig.GetRequestHeader()
if !c.transportConfig.NoGRPCHeader {
req.Header.Set("Content-Type", "application/grpc")
}
go c.client.Do(req)
return writer
}
Expand Down
77 changes: 44 additions & 33 deletions transport/internet/splithttp/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions transport/internet/splithttp/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ message Config {
Multiplexing xmux = 9;
xray.transport.internet.StreamConfig downloadSettings = 10;
string mode = 11;
bool noGRPCHeader = 12;
}

message RandRangeConfig {
Expand Down
8 changes: 6 additions & 2 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
}

mode := transportConfiguration.Mode
if mode == "auto" && realityConfig != nil {
mode = "stream-up"
if mode == "auto" {
mode = "packet-up"
if (tlsConfig != nil && len(tlsConfig.NextProtocol) != 1) || realityConfig != nil {
mode = "stream-up"
}
}
errors.LogInfo(ctx, "XHTTP is using mode: "+mode)
if mode == "stream-up" {
conn.writer = httpClient.OpenUpload(ctx, requestURL.String())
return stat.Connection(&conn), nil
Expand Down
12 changes: 6 additions & 6 deletions transport/internet/splithttp/splithttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ func Test_maxUpload(t *testing.T) {
ProtocolSettings: &Config{
Path: "/sh",
ScMaxEachPostBytes: &RandRangeConfig{
From: 100,
To: 100,
From: 10000,
To: 10000,
},
},
}
Expand All @@ -434,7 +434,7 @@ func Test_maxUpload(t *testing.T) {
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) {
go func(c stat.Connection) {
defer c.Close()
var b [1024]byte
var b [10240]byte
c.SetReadDeadline(time.Now().Add(2 * time.Second))
n, err := c.Read(b[:])
if err != nil {
Expand All @@ -452,19 +452,19 @@ func Test_maxUpload(t *testing.T) {
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), listenPort), streamSettings)

// send a slightly too large upload
var upload [101]byte
var upload [10001]byte
_, err = conn.Write(upload[:])
common.Must(err)

var b [1024]byte
var b [10240]byte
n, _ := io.ReadFull(conn, b[:])
fmt.Println("string is", n)
if string(b[:n]) != "Response" {
t.Error("response: ", string(b[:n]))
}
common.Must(conn.Close())

if uploadSize > 100 || uploadSize == 0 {
if uploadSize > 10000 || uploadSize == 0 {
t.Error("incorrect upload size: ", uploadSize)
}

Expand Down

0 comments on commit f3b5d0b

Please sign in to comment.