diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index f32a78d49ad..9c7b623185f 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "net/url" "sync" @@ -284,11 +283,11 @@ func (s *DoHNameServer) dohHTTPSContext(ctx context.Context, b []byte) ([]byte, defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - io.Copy(ioutil.Discard, resp.Body) // flush resp.Body so that the conn is reusable + io.Copy(io.Discard, resp.Body) // flush resp.Body so that the conn is reusable return nil, fmt.Errorf("DOH server returned code %d", resp.StatusCode) } - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } func (s *DoHNameServer) findIPsForDomain(domain string, option dns_feature.IPOption) ([]net.IP, error) { diff --git a/common/buf/multi_buffer_test.go b/common/buf/multi_buffer_test.go index cfd35523505..866462c4ff8 100644 --- a/common/buf/multi_buffer_test.go +++ b/common/buf/multi_buffer_test.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/rand" "io" - "io/ioutil" "os" "testing" @@ -120,7 +119,7 @@ func TestMultiBufferReadAllToByte(t *testing.T) { common.Must(err) f.Close() - cnt, err := ioutil.ReadFile(dat) + cnt, err := os.ReadFile(dat) common.Must(err) if d := cmp.Diff(buf2, cnt); d != "" { diff --git a/common/common.go b/common/common.go index c73d8f14527..edb9e74a6d7 100644 --- a/common/common.go +++ b/common/common.go @@ -5,7 +5,7 @@ package common import ( "fmt" "go/build" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -70,7 +70,7 @@ func GetRuntimeEnv(key string) (string, error) { } var data []byte var runtimeEnv string - data, readErr := ioutil.ReadFile(file) + data, readErr := os.ReadFile(file) if readErr != nil { return "", readErr } @@ -153,7 +153,7 @@ func FetchHTTPContent(target string) ([]byte, error) { return nil, newError("unexpected HTTP status code: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { return nil, newError("failed to read HTTP response").Base(err) } diff --git a/common/drain/drainer.go b/common/drain/drainer.go index 5ed887abc6b..e92c4363d12 100644 --- a/common/drain/drainer.go +++ b/common/drain/drainer.go @@ -2,7 +2,6 @@ package drain import ( "io" - "io/ioutil" "github.com/v2fly/v2ray-core/v4/common/dice" ) @@ -36,7 +35,7 @@ func (d *BehaviorSeedLimitedDrainer) Drain(reader io.Reader) error { } func drainReadN(reader io.Reader, n int) error { - _, err := io.CopyN(ioutil.Discard, reader, int64(n)) + _, err := io.CopyN(io.Discard, reader, int64(n)) return err } diff --git a/common/log/logger_test.go b/common/log/logger_test.go index fcb91ad6c5d..87b08006c08 100644 --- a/common/log/logger_test.go +++ b/common/log/logger_test.go @@ -1,7 +1,6 @@ package log_test import ( - "io/ioutil" "os" "strings" "testing" @@ -13,7 +12,7 @@ import ( ) func TestFileLogger(t *testing.T) { - f, err := ioutil.TempFile("", "vtest") + f, err := os.CreateTemp("", "vtest") common.Must(err) path := f.Name() common.Must(f.Close()) diff --git a/go.mod b/go.mod index 4f8d180065c..2711cb7399c 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20210903071746-97244b99971b - google.golang.org/grpc v1.40.0 + google.golang.org/grpc v1.41.0 google.golang.org/protobuf v1.27.1 h12.io/socks v1.0.3 inet.af/netaddr v0.0.0-20210903134321-85fa6c94624e diff --git a/go.sum b/go.sum index b74aca4b7de..47a3a1a30b2 100644 --- a/go.sum +++ b/go.sum @@ -36,6 +36,7 @@ github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBT github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -44,7 +45,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -67,7 +68,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= -github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -556,8 +557,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= -google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/grpc v1.41.0 h1:f+PlOh7QV4iIJkPrx5NQ7qaNGFQ3OTse67yaDHfju4E= +google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/infra/conf/geodata/memconservative/cache.go b/infra/conf/geodata/memconservative/cache.go index 0632c0ad401..5fd7fb35a28 100644 --- a/infra/conf/geodata/memconservative/cache.go +++ b/infra/conf/geodata/memconservative/cache.go @@ -1,7 +1,7 @@ package memconservative import ( - "io/ioutil" + "os" "strings" "google.golang.org/protobuf/proto" @@ -53,7 +53,7 @@ func (g GeoIPCache) Unmarshal(filename, code string) (*router.GeoIP, error) { case errFailedToReadBytes, errFailedToReadExpectedLenBytes, errInvalidGeodataFile, errInvalidGeodataVarintLength: newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method") - geoipBytes, err = ioutil.ReadFile(asset) + geoipBytes, err = os.ReadFile(asset) if err != nil { return nil, err } @@ -118,7 +118,7 @@ func (g GeoSiteCache) Unmarshal(filename, code string) (*router.GeoSite, error) case errFailedToReadBytes, errFailedToReadExpectedLenBytes, errInvalidGeodataFile, errInvalidGeodataVarintLength: newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method") - geositeBytes, err = ioutil.ReadFile(asset) + geositeBytes, err = os.ReadFile(asset) if err != nil { return nil, err } diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 26b03c03035..542557a160a 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -387,6 +387,7 @@ func (p TransportProtocol) Build() (string, error) { type SocketConfig struct { Mark uint32 `json:"mark"` TFO *bool `json:"tcpFastOpen"` + TFOQueueLength uint32 `json:"tcpFastOpenQueueLength"` TProxy string `json:"tproxy"` AcceptProxyProtocol bool `json:"acceptProxyProtocol"` TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"` @@ -402,6 +403,12 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) { tfoSettings = internet.SocketConfig_Disable } } + + tfoQueueLength := c.TFOQueueLength + if tfoQueueLength == 0 { + tfoQueueLength = 4096 + } + var tproxy internet.SocketConfig_TProxyMode switch strings.ToLower(c.TProxy) { case "tproxy": @@ -415,6 +422,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) { return &internet.SocketConfig{ Mark: c.Mark, Tfo: tfoSettings, + TfoQueueLength: tfoQueueLength, Tproxy: tproxy, AcceptProxyProtocol: c.AcceptProxyProtocol, TcpKeepAliveInterval: c.TCPKeepAliveInterval, diff --git a/infra/conf/transport_test.go b/infra/conf/transport_test.go index 7cb3cdb3d80..ef8ad9259e0 100644 --- a/infra/conf/transport_test.go +++ b/infra/conf/transport_test.go @@ -35,12 +35,14 @@ func TestSocketConfig(t *testing.T) { { Input: `{ "mark": 1, - "tcpFastOpen": true + "tcpFastOpen": true, + "tcpFastOpenQueueLength": 1024 }`, Parser: createParser(), Output: &internet.SocketConfig{ - Mark: 1, - Tfo: internet.SocketConfig_Enable, + Mark: 1, + Tfo: internet.SocketConfig_Enable, + TfoQueueLength: 1024, }, }, }) diff --git a/infra/control/certchainhash.go b/infra/control/certchainhash.go index 1726ecc2841..b195455ad74 100644 --- a/infra/control/certchainhash.go +++ b/infra/control/certchainhash.go @@ -3,7 +3,7 @@ package control import ( "flag" "fmt" - "io/ioutil" + "os" v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls" ) @@ -30,7 +30,7 @@ func (c CertificateChainHashCommand) Execute(args []string) error { if err := fs.Parse(args); err != nil { return err } - certContent, err := ioutil.ReadFile(*cert) + certContent, err := os.ReadFile(*cert) if err != nil { return err } diff --git a/infra/control/config.go b/infra/control/config.go index 6a1f9b50d0f..395bda8fcaf 100644 --- a/infra/control/config.go +++ b/infra/control/config.go @@ -3,7 +3,6 @@ package control import ( "bytes" "io" - "io/ioutil" "os" "strings" @@ -73,10 +72,10 @@ func (c *ConfigCommand) LoadArg(arg string) (out io.Reader, err error) { data, err = FetchHTTPContent(arg) case arg == "stdin:": - data, err = ioutil.ReadAll(os.Stdin) + data, err = io.ReadAll(os.Stdin) default: - data, err = ioutil.ReadFile(arg) + data, err = os.ReadFile(arg) } if err != nil { diff --git a/infra/vprotogen/main.go b/infra/vprotogen/main.go index 08ea8569092..04437b5c0c3 100644 --- a/infra/vprotogen/main.go +++ b/infra/vprotogen/main.go @@ -4,7 +4,6 @@ import ( "fmt" "go/build" "io" - "io/ioutil" "net/http" "os" "os/exec" @@ -46,7 +45,7 @@ func GetRuntimeEnv(key string) (string, error) { } var data []byte var runtimeEnv string - data, readErr := ioutil.ReadFile(file) + data, readErr := os.ReadFile(file) if readErr != nil { return "", readErr } diff --git a/main/confloader/external/external.go b/main/confloader/external/external.go index 7e543b1e276..246a32e2d26 100644 --- a/main/confloader/external/external.go +++ b/main/confloader/external/external.go @@ -5,7 +5,6 @@ package external import ( "bytes" "io" - "io/ioutil" "net/http" "net/url" "os" @@ -24,10 +23,10 @@ func ConfigLoader(arg string) (out io.Reader, err error) { data, err = FetchHTTPContent(arg) case arg == "stdin:": - data, err = ioutil.ReadAll(os.Stdin) + data, err = io.ReadAll(os.Stdin) default: - data, err = ioutil.ReadFile(arg) + data, err = os.ReadFile(arg) } if err != nil { diff --git a/main/main.go b/main/main.go index c2ff3d3fc62..b33827996e0 100644 --- a/main/main.go +++ b/main/main.go @@ -5,7 +5,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "os" "os/signal" @@ -54,7 +53,7 @@ func dirExists(file string) bool { } func readConfDir(dirPath string) { - confs, err := ioutil.ReadDir(dirPath) + confs, err := os.ReadDir(dirPath) if err != nil { log.Fatalln(err) } diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index 66bf9e37fab..af3f40dc205 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -5,7 +5,7 @@ import ( "crypto/rand" "fmt" "io" - "io/ioutil" + "os" "os/exec" "path/filepath" "runtime" @@ -102,7 +102,7 @@ func genTestBinaryPath() { testBinaryPathGen.Do(func() { var tempDir string common.Must(retry.Timed(5, 100).On(func() error { - dir, err := ioutil.TempDir("", "v2ray") + dir, err := os.MkdirTemp("", "v2ray") if err != nil { return err } diff --git a/testing/scenarios/feature_test.go b/testing/scenarios/feature_test.go index 2e49df3ebd7..5e822bd3deb 100644 --- a/testing/scenarios/feature_test.go +++ b/testing/scenarios/feature_test.go @@ -2,7 +2,7 @@ package scenarios import ( "context" - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -643,7 +643,7 @@ func TestDomainSniffing(t *testing.T) { if resp.StatusCode != 200 { t.Error("unexpected status code: ", resp.StatusCode) } - common.Must(resp.Write(ioutil.Discard)) + common.Must(resp.Write(io.Discard)) } } diff --git a/testing/scenarios/http_test.go b/testing/scenarios/http_test.go index 99af84210bc..d2f4f3bb0ad 100644 --- a/testing/scenarios/http_test.go +++ b/testing/scenarios/http_test.go @@ -5,7 +5,6 @@ import ( "context" "crypto/rand" "io" - "io/ioutil" "net/http" "net/url" "testing" @@ -75,7 +74,7 @@ func TestHttpConformance(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if string(content) != "Home" { t.Fatal("body: ", string(content)) @@ -271,7 +270,7 @@ func TestHttpPost(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if r := cmp.Diff(content, xor(payload)); r != "" { t.Fatal(r) @@ -368,7 +367,7 @@ func TestHttpBasicAuth(t *testing.T) { t.Fatal("status: ", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) common.Must(err) if string(content) != "Home" { t.Fatal("body: ", string(content)) diff --git a/transport/internet/config.proto b/transport/internet/config.proto index 7aa76b6f2bb..f0d384f1c5a 100644 --- a/transport/internet/config.proto +++ b/transport/internet/config.proto @@ -93,4 +93,6 @@ message SocketConfig { bool accept_proxy_protocol = 7; int32 tcp_keep_alive_interval = 8; + + uint32 tfo_queue_length = 9; } diff --git a/transport/internet/sockopt_linux.go b/transport/internet/sockopt_linux.go index 9020afd7556..dc2f36e1aef 100644 --- a/transport/internet/sockopt_linux.go +++ b/transport/internet/sockopt_linux.go @@ -84,8 +84,8 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) if isTCPSocket(network) { switch config.Tfo { case SocketConfig_Enable: - if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 1); err != nil { - return newError("failed to set TCP_FASTOPEN=1").Base(err) + if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, int(config.TfoQueueLength)); err != nil { + return newError("failed to set TCP_FASTOPEN=", config.TfoQueueLength).Base(err) } case SocketConfig_Disable: if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, 0); err != nil {