mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-06-03 14:23:52 -04:00
Fixing all the lint errors (#3288)
* Fixing all the lint errors! * update lint settings
This commit is contained in:
parent
efec9ea0dc
commit
442581d897
3
.github/linters/.golangci.yml
vendored
3
.github/linters/.golangci.yml
vendored
@ -32,15 +32,12 @@ linters:
|
|||||||
- revive
|
- revive
|
||||||
- rowserrcheck
|
- rowserrcheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- structcheck
|
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
- varcheck
|
|
||||||
- whitespace
|
- whitespace
|
||||||
disable:
|
disable:
|
||||||
- deadcode
|
|
||||||
- errcheck
|
- errcheck
|
||||||
- unused
|
- unused
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ package commander
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/v2fly/v2ray-core/v5/features"
|
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -14,6 +13,7 @@ import (
|
|||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/signal/done"
|
"github.com/v2fly/v2ray-core/v5/common/signal/done"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/features"
|
||||||
"github.com/v2fly/v2ray-core/v5/features/outbound"
|
"github.com/v2fly/v2ray-core/v5/features/outbound"
|
||||||
"github.com/v2fly/v2ray-core/v5/infra/conf/v5cfg"
|
"github.com/v2fly/v2ray-core/v5/infra/conf/v5cfg"
|
||||||
)
|
)
|
||||||
|
@ -38,7 +38,6 @@ func newWebCommander(ctx context.Context, config *Config) (*WebCommander, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &WebCommander{ctx: ctx, config: config, webRootfs: webRootfs}, nil
|
return &WebCommander{ctx: ctx, config: config, webRootfs: webRootfs}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebCommander struct {
|
type WebCommander struct {
|
||||||
@ -56,9 +55,9 @@ type WebCommander struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebCommander) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
func (w *WebCommander) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
api_path := w.config.ApiMountpoint
|
apiPath := w.config.ApiMountpoint
|
||||||
if strings.HasPrefix(request.URL.Path, api_path) {
|
if strings.HasPrefix(request.URL.Path, apiPath) {
|
||||||
request.URL.Path = strings.TrimPrefix(request.URL.Path, api_path)
|
request.URL.Path = strings.TrimPrefix(request.URL.Path, apiPath)
|
||||||
if w.wrappedGrpc.IsGrpcWebRequest(request) {
|
if w.wrappedGrpc.IsGrpcWebRequest(request) {
|
||||||
w.wrappedGrpc.ServeHTTP(writer, request)
|
w.wrappedGrpc.ServeHTTP(writer, request)
|
||||||
return
|
return
|
||||||
@ -109,7 +108,6 @@ func (w *WebCommander) Type() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebCommander) Start() error {
|
func (w *WebCommander) Start() error {
|
||||||
|
|
||||||
if err := core.RequireFeatures(w.ctx, func(cm commander.CommanderIfce, om outbound.Manager) {
|
if err := core.RequireFeatures(w.ctx, func(cm commander.CommanderIfce, om outbound.Manager) {
|
||||||
w.Lock()
|
w.Lock()
|
||||||
defer w.Unlock()
|
defer w.Unlock()
|
||||||
@ -118,7 +116,6 @@ func (w *WebCommander) Start() error {
|
|||||||
w.ohm = om
|
w.ohm = om
|
||||||
|
|
||||||
go w.asyncStart()
|
go w.asyncStart()
|
||||||
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func Test_parseResponse(t *testing.T) {
|
|||||||
got.Expire = time.Time{}
|
got.Expire = time.Time{}
|
||||||
}
|
}
|
||||||
if cmp.Diff(got, tt.want) != "" {
|
if cmp.Diff(got, tt.want) != "" {
|
||||||
t.Errorf(cmp.Diff(got, tt.want))
|
t.Errorf("%v", cmp.Diff(got, tt.want))
|
||||||
// t.Errorf("handleResponse() = %#v, want %#v", got, tt.want)
|
// t.Errorf("handleResponse() = %#v, want %#v", got, tt.want)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -97,7 +97,6 @@ func TestServiceSubscribeRoutingStats(t *testing.T) {
|
|||||||
grpc.WithContextDialer(bufDialer),
|
grpc.WithContextDialer(bufDialer),
|
||||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
return
|
return
|
||||||
|
@ -3,10 +3,11 @@ package urlline
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newURLLineParser() containers.SubscriptionContainerDocumentParser {
|
func newURLLineParser() containers.SubscriptionContainerDocumentParser {
|
||||||
|
@ -77,7 +77,7 @@ type materializedServer struct {
|
|||||||
serverConfig *specs.SubscriptionServerConfig
|
serverConfig *specs.SubscriptionServerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error {
|
func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error { //nolint: unparam
|
||||||
status.ImportSource = s.importSource
|
status.ImportSource = s.importSource
|
||||||
if s.currentDocument == nil {
|
if s.currentDocument == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -2,10 +2,10 @@ package packetaddr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/errors"
|
|
||||||
gonet "net"
|
gonet "net"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/common/errors"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
"github.com/v2fly/v2ray-core/v5/common/protocol"
|
||||||
)
|
)
|
||||||
|
@ -57,7 +57,7 @@ func TestWrongErrorCheckOnOSStat(t *testing.T) {
|
|||||||
// be discovered by the Go runtime, which will lead to failure to
|
// be discovered by the Go runtime, which will lead to failure to
|
||||||
// find & read geoip & geosite files.
|
// find & read geoip & geosite files.
|
||||||
// The correct code is `errors.Is(err, fs.ErrNotExist)`
|
// The correct code is `errors.Is(err, fs.ErrNotExist)`
|
||||||
if _, err := os.Stat(p); err != nil && errors.Is(fs.ErrNotExist, err) {
|
if _, err := os.Stat(p); err != nil && errors.Is(fs.ErrNotExist, err) { //nolint: staticcheck
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// asset found
|
// asset found
|
||||||
|
@ -147,19 +147,20 @@ type Hy2ConfigCongestion struct {
|
|||||||
type Hy2Config struct {
|
type Hy2Config struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Congestion Hy2ConfigCongestion `json:"congestion"`
|
Congestion Hy2ConfigCongestion `json:"congestion"`
|
||||||
UseUdpExtension bool `json:"use_udp_extension"`
|
UseUDPExtension bool `json:"use_udp_extension"`
|
||||||
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth"`
|
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
func (c *Hy2Config) Build() (proto.Message, error) {
|
func (c *Hy2Config) Build() (proto.Message, error) {
|
||||||
return &hysteria2.Config{Password: c.Password,
|
return &hysteria2.Config{
|
||||||
|
Password: c.Password,
|
||||||
Congestion: &hysteria2.Congestion{
|
Congestion: &hysteria2.Congestion{
|
||||||
Type: c.Congestion.Type,
|
Type: c.Congestion.Type,
|
||||||
DownMbps: c.Congestion.DownMbps,
|
DownMbps: c.Congestion.DownMbps,
|
||||||
UpMbps: c.Congestion.UpMbps,
|
UpMbps: c.Congestion.UpMbps,
|
||||||
},
|
},
|
||||||
UseUdpExtension: c.UseUdpExtension,
|
UseUdpExtension: c.UseUDPExtension,
|
||||||
IgnoreClientBandwidth: c.IgnoreClientBandwidth,
|
IgnoreClientBandwidth: c.IgnoreClientBandwidth,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ Command "%s" not found.
|
|||||||
Make sure that %s is in your system path or current path.
|
Make sure that %s is in your system path or current path.
|
||||||
Download %s v%s or later from https://github.com/protocolbuffers/protobuf/releases
|
Download %s v%s or later from https://github.com/protocolbuffers/protobuf/releases
|
||||||
`, protoc, protoc, protoc, targetedVersion)
|
`, protoc, protoc, protoc, targetedVersion)
|
||||||
return "", fmt.Errorf(errStr)
|
return "", fmt.Errorf("%v", errStr)
|
||||||
}
|
}
|
||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ func getInstalledProtocVersion(protocPath string) (string, error) {
|
|||||||
matched := versionRegexp.FindStringSubmatch(string(output))
|
matched := versionRegexp.FindStringSubmatch(string(output))
|
||||||
installedVersion := ""
|
installedVersion := ""
|
||||||
if len(matched) == 0 {
|
if len(matched) == 0 {
|
||||||
return "", errors.New("Can not parse protoc version.")
|
return "", errors.New("can not parse protoc version")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(matched) == 2 {
|
if len(matched) == 2 {
|
||||||
|
@ -119,7 +119,7 @@ func executeConvert(cmd *base.Command, args []string) {
|
|||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
pbConfig, err := core.LoadConfig(inputFormat, r)
|
pbConfig, err := core.LoadConfig(inputFormat, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
out, err = proto.Marshal(pbConfig)
|
out, err = proto.Marshal(pbConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -133,12 +133,12 @@ func executeConvert(cmd *base.Command, args []string) {
|
|||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
pbConfig, err := core.LoadConfig(inputFormat, r)
|
pbConfig, err := core.LoadConfig(inputFormat, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
w := bytes.NewBuffer(nil)
|
w := bytes.NewBuffer(nil)
|
||||||
err = jsonpb.DumpJSONPb(pbConfig, w)
|
err = jsonpb.DumpJSONPb(pbConfig, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
out = w.Bytes()
|
out = w.Bytes()
|
||||||
case v2jsonpb.FormatProtobufV2JSONPB:
|
case v2jsonpb.FormatProtobufV2JSONPB:
|
||||||
@ -149,11 +149,11 @@ func executeConvert(cmd *base.Command, args []string) {
|
|||||||
r := bytes.NewReader(data)
|
r := bytes.NewReader(data)
|
||||||
pbConfig, err := core.LoadConfig(inputFormat, r)
|
pbConfig, err := core.LoadConfig(inputFormat, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
out, err = v2jsonpb.DumpV2JsonPb(pbConfig)
|
out, err = v2jsonpb.DumpV2JsonPb(pbConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
base.Errorf("invalid output format: %s", outputFormat)
|
base.Errorf("invalid output format: %s", outputFormat)
|
||||||
|
@ -166,7 +166,7 @@ func readConfDirRecursively(dirPath string, extension []string) cmdarg.Arg {
|
|||||||
func getConfigFilePath() cmdarg.Arg {
|
func getConfigFilePath() cmdarg.Arg {
|
||||||
extension, err := core.GetLoaderExtensions(*configFormat)
|
extension, err := core.GetLoaderExtensions(*configFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf(err.Error())
|
base.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
dirReader := readConfDir
|
dirReader := readConfDir
|
||||||
if *configDirRecursively {
|
if *configDirRecursively {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package plugin_pprof
|
package plugin_pprof //nolint: stylecheck
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/v2fly/v2ray-core/v5/main/plugins"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
"net/http/pprof"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/main/commands/base"
|
"github.com/v2fly/v2ray-core/v5/main/commands/base"
|
||||||
|
"github.com/v2fly/v2ray-core/v5/main/plugins"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {
|
var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {
|
||||||
|
@ -88,7 +88,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||||||
|
|
||||||
if !IsHy2Transport && network == net.Network_UDP {
|
if !IsHy2Transport && network == net.Network_UDP {
|
||||||
// hysteria2 need to use udp extension to proxy UDP.
|
// hysteria2 need to use udp extension to proxy UDP.
|
||||||
return newError(hyTransport.CanNotUseUdpExtension)
|
return newError(hyTransport.CanNotUseUDPExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
user := server.PickUser()
|
user := server.PickUser()
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
|
|
||||||
"github.com/apernet/quic-go/quicvarint"
|
"github.com/apernet/quic-go/quicvarint"
|
||||||
|
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
@ -59,7 +59,7 @@ func (c *ConnWriter) WriteTCPHeader() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func QuicLen(s int) int {
|
func QuicLen(s int) int {
|
||||||
return int(quicvarint.Len(uint64(s)))
|
return quicvarint.Len(uint64(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnWriter) writeTCPHeader() error {
|
func (c *ConnWriter) writeTCPHeader() error {
|
||||||
|
@ -67,7 +67,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !IsHy2Transport && network == net.Network_UDP {
|
if !IsHy2Transport && network == net.Network_UDP {
|
||||||
return newError(hyTransport.CanNotUseUdpExtension)
|
return newError(hyTransport.CanNotUseUDPExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionPolicy := s.policyManager.ForLevel(0)
|
sessionPolicy := s.policyManager.ForLevel(0)
|
||||||
|
@ -146,7 +146,7 @@ func createStatusFromConfig(config *UDPProtocolConfig) (*status, error) { //noli
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableInterface(s *status) error {
|
func enableInterface(s *status) error { //nolint: unparam
|
||||||
s.transport = s
|
s.transport = s
|
||||||
if s.config.EnableStabilization {
|
if s.config.EnableStabilization {
|
||||||
s.transport = uniserver.NewUnifiedConnectionTransportHub(s, s.ctx)
|
s.transport = uniserver.NewUnifiedConnectionTransportHub(s, s.ctx)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/net/proxy"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -14,6 +13,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
core "github.com/v2fly/v2ray-core/v5"
|
core "github.com/v2fly/v2ray-core/v5"
|
||||||
@ -169,7 +170,7 @@ func withDefaultApps(config *core.Config) *core.Config {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error {
|
func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error { //nolint: unparam
|
||||||
return func() error {
|
return func() error {
|
||||||
socksDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:"+socksPort.String(), nil, nil)
|
socksDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:"+socksPort.String(), nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,11 +2,12 @@ package httpupgrade
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/serial"
|
"github.com/v2fly/v2ray-core/v5/common/serial"
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type connection struct {
|
type connection struct {
|
||||||
|
@ -43,7 +43,7 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
|
|||||||
earlyDataSize = int(transportConfiguration.MaxEarlyData)
|
earlyDataSize = int(transportConfiguration.MaxEarlyData)
|
||||||
}
|
}
|
||||||
|
|
||||||
if earlyData != nil && len(earlyData) > 0 {
|
if len(earlyData) > 0 {
|
||||||
if transportConfiguration.EarlyDataHeaderName == "" {
|
if transportConfiguration.EarlyDataHeaderName == "" {
|
||||||
return nil, nil, newError("EarlyDataHeaderName is not set")
|
return nil, nil, newError("EarlyDataHeaderName is not set")
|
||||||
}
|
}
|
||||||
@ -71,7 +71,6 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
|
|||||||
if resp.Status == "101 Switching Protocols" &&
|
if resp.Status == "101 Switching Protocols" &&
|
||||||
strings.ToLower(resp.Header.Get("Upgrade")) == "websocket" &&
|
strings.ToLower(resp.Header.Get("Upgrade")) == "websocket" &&
|
||||||
strings.ToLower(resp.Header.Get("Connection")) == "upgrade" {
|
strings.ToLower(resp.Header.Get("Connection")) == "upgrade" {
|
||||||
|
|
||||||
earlyReplyReader := io.LimitReader(bufferedConn, int64(bufferedConn.Buffered()))
|
earlyReplyReader := io.LimitReader(bufferedConn, int64(bufferedConn.Buffered()))
|
||||||
return conn, earlyReplyReader, nil
|
return conn, earlyReplyReader, nil
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,18 @@ package hysteria2
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/apernet/quic-go"
|
||||||
hyClient "github.com/v2fly/hysteria/core/v2/client"
|
hyClient "github.com/v2fly/hysteria/core/v2/client"
|
||||||
"github.com/v2fly/hysteria/core/v2/international/protocol"
|
"github.com/v2fly/hysteria/core/v2/international/protocol"
|
||||||
hyServer "github.com/v2fly/hysteria/core/v2/server"
|
hyServer "github.com/v2fly/hysteria/core/v2/server"
|
||||||
"github.com/apernet/quic-go"
|
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CanNotUseUdpExtension = "Only hysteria2 proxy protocol can use udpExtension."
|
const (
|
||||||
const Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
|
CanNotUseUDPExtension = "Only hysteria2 proxy protocol can use udpExtension."
|
||||||
|
Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
|
||||||
|
)
|
||||||
|
|
||||||
type HyConn struct {
|
type HyConn struct {
|
||||||
IsUDPExtension bool
|
IsUDPExtension bool
|
||||||
@ -44,7 +46,7 @@ func (c *HyConn) Write(b []byte) (int, error) {
|
|||||||
|
|
||||||
func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
|
func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
|
||||||
if !c.IsUDPExtension {
|
if !c.IsUDPExtension {
|
||||||
return 0, newError(CanNotUseUdpExtension)
|
return 0, newError(CanNotUseUDPExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.IsServer {
|
if c.IsServer {
|
||||||
@ -64,7 +66,7 @@ func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
|
|||||||
|
|
||||||
func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
|
func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
|
||||||
if !c.IsUDPExtension {
|
if !c.IsUDPExtension {
|
||||||
return 0, nil, nil, newError(CanNotUseUdpExtension)
|
return 0, nil, nil, newError(CanNotUseUDPExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.IsServer {
|
if c.IsServer {
|
||||||
@ -89,7 +91,7 @@ func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
|
|||||||
func (c *HyConn) Close() error {
|
func (c *HyConn) Close() error {
|
||||||
if c.IsUDPExtension {
|
if c.IsUDPExtension {
|
||||||
if !c.IsServer && c.ClientUDPSession == nil || (c.IsServer && c.ServerUDPSession == nil) {
|
if !c.IsServer && c.ClientUDPSession == nil || (c.IsServer && c.ServerUDPSession == nil) {
|
||||||
return newError(CanNotUseUdpExtension)
|
return newError(CanNotUseUDPExtension)
|
||||||
}
|
}
|
||||||
if c.IsServer {
|
if c.IsServer {
|
||||||
c.ServerUDPSession.CloseWithErr(nil)
|
c.ServerUDPSession.CloseWithErr(nil)
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/apernet/quic-go/quicvarint"
|
||||||
hyClient "github.com/v2fly/hysteria/core/v2/client"
|
hyClient "github.com/v2fly/hysteria/core/v2/client"
|
||||||
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
|
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
|
||||||
"github.com/apernet/quic-go/quicvarint"
|
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
@ -20,9 +20,11 @@ type dialerConf struct {
|
|||||||
*internet.MemoryStreamConfig
|
*internet.MemoryStreamConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
var RunningClient map[dialerConf](hyClient.Client)
|
var (
|
||||||
var ClientMutex sync.Mutex
|
RunningClient map[dialerConf](hyClient.Client)
|
||||||
var MBps uint64 = 1000000 / 8 // MByte
|
ClientMutex sync.Mutex
|
||||||
|
MBps uint64 = 1000000 / 8 // MByte
|
||||||
|
)
|
||||||
|
|
||||||
func GetClientTLSConfig(dest net.Destination, streamSettings *internet.MemoryStreamConfig) (*hyClient.TLSConfig, error) {
|
func GetClientTLSConfig(dest net.Destination, streamSettings *internet.MemoryStreamConfig) (*hyClient.TLSConfig, error) {
|
||||||
config := tls.ConfigFromStreamSettings(streamSettings)
|
config := tls.ConfigFromStreamSettings(streamSettings)
|
||||||
@ -190,7 +192,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write TCP frame type
|
// write TCP frame type
|
||||||
frameSize := int(quicvarint.Len(hyProtocol.FrameTypeTCPRequest))
|
frameSize := quicvarint.Len(hyProtocol.FrameTypeTCPRequest)
|
||||||
buf := make([]byte, frameSize)
|
buf := make([]byte, frameSize)
|
||||||
hyProtocol.VarintPut(buf, hyProtocol.FrameTypeTCPRequest)
|
hyProtocol.VarintPut(buf, hyProtocol.FrameTypeTCPRequest)
|
||||||
_, err = conn.stream.Write(buf)
|
_, err = conn.stream.Write(buf)
|
||||||
|
@ -3,9 +3,9 @@ package hysteria2
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
hyServer "github.com/v2fly/hysteria/core/v2/server"
|
|
||||||
"github.com/apernet/quic-go"
|
"github.com/apernet/quic-go"
|
||||||
"github.com/apernet/quic-go/http3"
|
"github.com/apernet/quic-go/http3"
|
||||||
|
hyServer "github.com/v2fly/hysteria/core/v2/server"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common"
|
"github.com/v2fly/v2ray-core/v5/common"
|
||||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||||
@ -42,7 +42,7 @@ func (l *Listener) StreamHijacker(ft http3.FrameType, conn quic.Connection, stre
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Listener) UdpHijacker(entry *hyServer.UdpSessionEntry, originalAddr string) {
|
func (l *Listener) UDPHijacker(entry *hyServer.UdpSessionEntry, originalAddr string) {
|
||||||
addr, err := net.ResolveUDPAddr("udp", originalAddr)
|
addr, err := net.ResolveUDPAddr("udp", originalAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -90,7 +90,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||||||
Authenticator: &Authenticator{Password: config.GetPassword()},
|
Authenticator: &Authenticator{Password: config.GetPassword()},
|
||||||
StreamHijacker: listener.StreamHijacker, // acceptStreams
|
StreamHijacker: listener.StreamHijacker, // acceptStreams
|
||||||
BandwidthConfig: hyServer.BandwidthConfig{MaxTx: config.Congestion.GetUpMbps() * MBps, MaxRx: config.GetCongestion().GetDownMbps() * MBps},
|
BandwidthConfig: hyServer.BandwidthConfig{MaxTx: config.Congestion.GetUpMbps() * MBps, MaxRx: config.GetCongestion().GetDownMbps() * MBps},
|
||||||
UdpSessionHijacker: listener.UdpHijacker, // acceptUDPSession
|
UdpSessionHijacker: listener.UDPHijacker, // acceptUDPSession
|
||||||
IgnoreClientBandwidth: config.GetIgnoreClientBandwidth(),
|
IgnoreClientBandwidth: config.GetIgnoreClientBandwidth(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -127,6 +127,7 @@ func TestUDP(t *testing.T) {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
address, err := net.ParseDestination("udp:127.0.0.1:1180")
|
address, err := net.ParseDestination("udp:127.0.0.1:1180")
|
||||||
|
common.Must(err)
|
||||||
dctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: address})
|
dctx := session.ContextWithOutbound(context.Background(), &session.Outbound{Target: address})
|
||||||
|
|
||||||
conn, err := hysteria2.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{
|
conn, err := hysteria2.Dial(dctx, net.TCPDestination(net.LocalHostIP, port), &internet.MemoryStreamConfig{
|
||||||
|
@ -122,7 +122,7 @@ copyFromChan:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resp.Data != nil && len(resp.Data) != 0 {
|
if len(resp.Data) != 0 {
|
||||||
respReader := bytes.NewReader(resp.Data)
|
respReader := bytes.NewReader(resp.Data)
|
||||||
for respReader.Len() != 0 {
|
for respReader.Len() != 0 {
|
||||||
packet, err := packetBundler.ReadFromBundle(respReader)
|
packet, err := packetBundler.ReadFromBundle(respReader)
|
||||||
|
@ -104,7 +104,7 @@ func (s *simpleAssemblerServerSession) Close() error {
|
|||||||
|
|
||||||
func (s *simpleAssemblerServerSession) OnRoundTrip(ctx context.Context, req request.Request, opts ...request.RoundTripperOption,
|
func (s *simpleAssemblerServerSession) OnRoundTrip(ctx context.Context, req request.Request, opts ...request.RoundTripperOption,
|
||||||
) (resp request.Response, err error) {
|
) (resp request.Response, err error) {
|
||||||
if req.Data != nil && len(req.Data) > 0 {
|
if len(req.Data) > 0 {
|
||||||
select {
|
select {
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
return request.Response{}, s.ctx.Err()
|
return request.Response{}, s.ctx.Err()
|
||||||
|
@ -56,6 +56,7 @@ func mekyaDial(ctx context.Context, dest net.Destination, streamSettings *intern
|
|||||||
|
|
||||||
return internet.Dial(ctx, dest, constructedSetting)
|
return internet.Dial(ctx, dest, constructedSetting)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mekyaListen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, callback internet.ConnHandler) (internet.Listener, error) {
|
func mekyaListen(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig, callback internet.ConnHandler) (internet.Listener, error) {
|
||||||
mekyaSetting := streamSettings.ProtocolSettings.(*Config)
|
mekyaSetting := streamSettings.ProtocolSettings.(*Config)
|
||||||
packetConnAssembler := &packetconn.ServerConfig{}
|
packetConnAssembler := &packetconn.ServerConfig{}
|
||||||
|
@ -91,7 +91,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
|
|||||||
lc.Control = nil
|
lc.Control = nil
|
||||||
network = addr.Network()
|
network = addr.Network()
|
||||||
address = addr.Name
|
address = addr.Name
|
||||||
if (runtime.GOOS == "linux" || runtime.GOOS == "android") && address[0] == '@' {
|
if (runtime.GOOS == "linux" || runtime.GOOS == "android") && address[0] == '@' { //nolint: gocritic
|
||||||
// linux abstract unix domain socket is lockfree
|
// linux abstract unix domain socket is lockfree
|
||||||
if len(address) > 1 && address[1] == '@' {
|
if len(address) > 1 && address[1] == '@' {
|
||||||
// but may need padding to work with haproxy
|
// but may need padding to work with haproxy
|
||||||
|
@ -288,8 +288,8 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(c.EchConfig) > 0 || len(c.Ech_DOHserver) > 0 {
|
if len(c.EchConfig) > 0 || len(c.Ech_DOHserver) > 0 {
|
||||||
err := ApplyECH(c, config)
|
err := ApplyECH(c, config) //nolint: staticcheck
|
||||||
if err != nil {
|
if err != nil { //nolint: staticcheck
|
||||||
newError("unable to set ECH").AtError().Base(err).WriteToLog()
|
newError("unable to set ECH").AtError().Base(err).WriteToLog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ApplyECH(c *Config, config *tls.Config) error {
|
func ApplyECH(c *Config, config *tls.Config) error { //nolint: staticcheck
|
||||||
return newError("using ECH require go 1.23 or higher")
|
return newError("using ECH require go 1.23 or higher")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user