Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Sep 29, 2021
2 parents 17ae058 + deb9d08 commit 6aa81d6
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 45 deletions.
5 changes: 2 additions & 3 deletions app/dns/nameserver_doh.go
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"sync"
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions common/buf/multi_buffer_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -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 != "" {
Expand Down
6 changes: 3 additions & 3 deletions common/common.go
Expand Up @@ -5,7 +5,7 @@ package common
import (
"fmt"
"go/build"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions common/drain/drainer.go
Expand Up @@ -2,7 +2,6 @@ package drain

import (
"io"
"io/ioutil"

"github.com/v2fly/v2ray-core/v4/common/dice"
)
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions common/log/logger_test.go
@@ -1,7 +1,6 @@
package log_test

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
6 changes: 3 additions & 3 deletions infra/conf/geodata/memconservative/cache.go
@@ -1,7 +1,7 @@
package memconservative

import (
"io/ioutil"
"os"
"strings"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions infra/conf/transport_internet.go
Expand Up @@ -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"`
Expand All @@ -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":
Expand All @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions infra/conf/transport_test.go
Expand Up @@ -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,
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions infra/control/certchainhash.go
Expand Up @@ -3,7 +3,7 @@ package control
import (
"flag"
"fmt"
"io/ioutil"
"os"

v2tls "github.com/v2fly/v2ray-core/v4/transport/internet/tls"
)
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions infra/control/config.go
Expand Up @@ -3,7 +3,6 @@ package control
import (
"bytes"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions infra/vprotogen/main.go
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions main/confloader/external/external.go
Expand Up @@ -5,7 +5,6 @@ package external
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions main/main.go
Expand Up @@ -5,7 +5,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions testing/scenarios/common.go
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/rand"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions testing/scenarios/feature_test.go
Expand Up @@ -2,7 +2,7 @@ package scenarios

import (
"context"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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))
}
}

Expand Down
7 changes: 3 additions & 4 deletions testing/scenarios/http_test.go
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"net/http"
"net/url"
"testing"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions transport/internet/config.proto
Expand Up @@ -93,4 +93,6 @@ message SocketConfig {
bool accept_proxy_protocol = 7;

int32 tcp_keep_alive_interval = 8;

uint32 tfo_queue_length = 9;
}

0 comments on commit 6aa81d6

Please sign in to comment.