Update to go 1.19

This commit is contained in:
9seconds
2022-08-09 17:41:59 +03:00
parent 9d67414db6
commit f48156814b
60 changed files with 260 additions and 260 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go_version: go_version:
- ^1.18 - ^1.19
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -70,7 +70,7 @@ jobs:
- name: Run linter - name: Run linter
uses: golangci/golangci-lint-action@v2 uses: golangci/golangci-lint-action@v2
with: with:
version: v1.45.0 version: v1.48.0
docker: docker:
name: Docker name: Docker
+11 -1
View File
@@ -9,4 +9,14 @@ format = "colored-line-number"
[linters] [linters]
enable-all = true enable-all = true
disable = ["thelper", "ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"] disable = [
"containedctx",
"exhaustivestruct",
"exhaustruct",
"gas",
"gochecknoglobals",
"goerr113",
"ireturn",
"thelper",
"varnamelen",
]
+1 -1
View File
@@ -1,7 +1,7 @@
############################################################################### ###############################################################################
# BUILD STAGE # BUILD STAGE
FROM golang:1.18-alpine AS build FROM golang:1.19-alpine AS build
RUN set -x \ RUN set -x \
&& apk --no-cache --update add \ && apk --no-cache --update add \
+1 -1
View File
@@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
IMAGE_NAME := mtg IMAGE_NAME := mtg
APP_NAME := $(IMAGE_NAME) APP_NAME := $(IMAGE_NAME)
GOLANGCI_LINT_VERSION := v1.45.0 GOLANGCI_LINT_VERSION := v1.48.0
VERSION_GO := $(shell go version) VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru) VERSION_DATE := $(shell date -Ru)
+2 -2
View File
@@ -19,7 +19,7 @@ import (
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
func Proxy() error { // nolint: funlen,cyclop func Proxy() error { //nolint: funlen,cyclop
ctx := utils.GetSignalContext() ctx := utils.GetSignalContext()
atom := zap.NewAtomicLevel() atom := zap.NewAtomicLevel()
@@ -41,7 +41,7 @@ func Proxy() error { // nolint: funlen,cyclop
)) ))
zap.ReplaceGlobals(logger) zap.ReplaceGlobals(logger)
defer logger.Sync() // nolint: errcheck defer logger.Sync() //nolint: errcheck
if err := config.InitPublicAddress(ctx); err != nil { if err := config.InitPublicAddress(ctx); err != nil {
Fatal(err) Fatal(err)
+2 -2
View File
@@ -9,7 +9,7 @@ import (
func Fatal(arg interface{}) { func Fatal(arg interface{}) {
if value, ok := arg.(error); ok { if value, ok := arg.(error); ok {
arg = fmt.Errorf("fatal error: %+v", value) // nolint: errorlint arg = fmt.Errorf("fatal error: %+v", value) //nolint: errorlint
} }
PrintStderr(arg) PrintStderr(arg)
@@ -21,7 +21,7 @@ func PrintStderr(args ...interface{}) {
} }
func PrintStdout(args ...interface{}) { func PrintStdout(args ...interface{}) {
fmt.Println(args...) // nolint: forbidigo fmt.Println(args...) //nolint: forbidigo
} }
func PrintJSONStderr(data interface{}) { func PrintJSONStderr(data interface{}) {
+37 -37
View File
@@ -79,29 +79,29 @@ const (
type Config struct { type Config struct {
Bind *net.TCPAddr `json:"bind"` Bind *net.TCPAddr `json:"bind"`
PublicIPv4 *net.TCPAddr `json:"public_ipv4"` // nolint: tagliatelle PublicIPv4 *net.TCPAddr `json:"public_ipv4"` //nolint: tagliatelle
PublicIPv6 *net.TCPAddr `json:"public_ipv6"` // nolint: tagliatelle PublicIPv6 *net.TCPAddr `json:"public_ipv6"` //nolint: tagliatelle
StatsBind *net.TCPAddr `json:"stats_bind"` // nolint: tagliatelle StatsBind *net.TCPAddr `json:"stats_bind"` //nolint: tagliatelle
StatsdAddr *net.TCPAddr `json:"stats_addr"` // nolint: tagliatelle StatsdAddr *net.TCPAddr `json:"stats_addr"` //nolint: tagliatelle
StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` // nolint: tagliatelle StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` //nolint: tagliatelle
StatsNamespace string `json:"stats_namespace"` // nolint: tagliatelle StatsNamespace string `json:"stats_namespace"` //nolint: tagliatelle
CloakHost string `json:"cloak_host"` // nolint: tagliatelle CloakHost string `json:"cloak_host"` //nolint: tagliatelle
StatsdTags map[string]string `json:"statsd_tags"` // nolint: tagliatelle StatsdTags map[string]string `json:"statsd_tags"` //nolint: tagliatelle
WriteBuffer int `json:"write_buffer"` // nolint: tagliatelle WriteBuffer int `json:"write_buffer"` //nolint: tagliatelle
ReadBuffer int `json:"read_buffer"` // nolint: tagliatelle ReadBuffer int `json:"read_buffer"` //nolint: tagliatelle
CloakPort int `json:"cloak_port"` // nolint: tagliatelle CloakPort int `json:"cloak_port"` //nolint: tagliatelle
AntiReplayMaxSize int `json:"anti_replay_max_size"` // nolint: tagliatelle AntiReplayMaxSize int `json:"anti_replay_max_size"` //nolint: tagliatelle
MultiplexPerConnection int `json:"multiplex_per_connection"` // nolint: tagliatelle MultiplexPerConnection int `json:"multiplex_per_connection"` //nolint: tagliatelle
Debug bool `json:"debug"` Debug bool `json:"debug"`
Verbose bool `json:"verbose"` Verbose bool `json:"verbose"`
SecretMode SecretMode `json:"secret_mode"` // nolint: tagliatelle SecretMode SecretMode `json:"secret_mode"` //nolint: tagliatelle
PreferIP PreferIP `json:"prefer_ip"` // nolint: tagliatelle PreferIP PreferIP `json:"prefer_ip"` //nolint: tagliatelle
NTPServers []string `json:"ntp_servers"` // nolint: tagliatelle NTPServers []string `json:"ntp_servers"` //nolint: tagliatelle
Secret []byte `json:"secret"` Secret []byte `json:"secret"`
AdTag []byte `json:"adtag"` AdTag []byte `json:"adtag"`
@@ -146,7 +146,7 @@ func (c *Config) adjustProxyValue(value int) int {
fvalue := float64(value) fvalue := float64(value)
newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection)) // nolint: gomnd newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection)) //nolint: gomnd
newValue = math.Ceil(newValue) newValue = math.Ceil(newValue)
newValue = math.Max(fvalue, newValue) newValue = math.Max(fvalue, newValue)
@@ -160,15 +160,15 @@ type Opt struct {
var C = Config{} var C = Config{}
func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop func Init(options ...Opt) error { //nolint: gocyclo, funlen, cyclop
for _, opt := range options { for _, opt := range options {
switch opt.Option { switch opt.Option {
case OptionTypeDebug: case OptionTypeDebug:
C.Debug = opt.Value.(bool) // nolint: forcetypeassert C.Debug = opt.Value.(bool) //nolint: forcetypeassert
case OptionTypeVerbose: case OptionTypeVerbose:
C.Verbose = opt.Value.(bool) // nolint: forcetypeassert C.Verbose = opt.Value.(bool) //nolint: forcetypeassert
case OptionTypePreferIP: case OptionTypePreferIP:
value := opt.Value.(string) // nolint: forcetypeassert value := opt.Value.(string) //nolint: forcetypeassert
switch value { switch value {
case "ipv4": case "ipv4":
C.PreferIP = PreferIPv4 C.PreferIP = PreferIPv4
@@ -178,25 +178,25 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect direct IP mode %s", value) return fmt.Errorf("incorrect direct IP mode %s", value)
} }
case OptionTypeBind: case OptionTypeBind:
C.Bind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert C.Bind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypePublicIPv4: case OptionTypePublicIPv4:
C.PublicIPv4 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert C.PublicIPv4 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
if C.PublicIPv4 == nil { if C.PublicIPv4 == nil {
C.PublicIPv4 = &net.TCPAddr{} C.PublicIPv4 = &net.TCPAddr{}
} }
case OptionTypePublicIPv6: case OptionTypePublicIPv6:
C.PublicIPv6 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert C.PublicIPv6 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
if C.PublicIPv6 == nil { if C.PublicIPv6 == nil {
C.PublicIPv6 = &net.TCPAddr{} C.PublicIPv6 = &net.TCPAddr{}
} }
case OptionTypeStatsBind: case OptionTypeStatsBind:
C.StatsBind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert C.StatsBind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypeStatsNamespace: case OptionTypeStatsNamespace:
C.StatsNamespace = opt.Value.(string) // nolint: forcetypeassert C.StatsNamespace = opt.Value.(string) //nolint: forcetypeassert
case OptionTypeStatsdAddress: case OptionTypeStatsdAddress:
C.StatsdAddr = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert C.StatsdAddr = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert
case OptionTypeStatsdTagsFormat: case OptionTypeStatsdTagsFormat:
value := opt.Value.(string) // nolint: forcetypeassert value := opt.Value.(string) //nolint: forcetypeassert
switch value { switch value {
case "datadog": case "datadog":
C.StatsdTagsFormat = statsd.TagFormatDatadog C.StatsdTagsFormat = statsd.TagFormatDatadog
@@ -206,26 +206,26 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect statsd tag %s", value) return fmt.Errorf("incorrect statsd tag %s", value)
} }
case OptionTypeStatsdTags: case OptionTypeStatsdTags:
C.StatsdTags = opt.Value.(map[string]string) // nolint: forcetypeassert C.StatsdTags = opt.Value.(map[string]string) //nolint: forcetypeassert
case OptionTypeWriteBufferSize: case OptionTypeWriteBufferSize:
C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeReadBufferSize: case OptionTypeReadBufferSize:
C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeCloakPort: case OptionTypeCloakPort:
C.CloakPort = int(opt.Value.(uint16)) // nolint: forcetypeassert C.CloakPort = int(opt.Value.(uint16)) //nolint: forcetypeassert
case OptionTypeAntiReplayMaxSize: case OptionTypeAntiReplayMaxSize:
C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert
case OptionTypeMultiplexPerConnection: case OptionTypeMultiplexPerConnection:
C.MultiplexPerConnection = int(opt.Value.(uint)) // nolint: forcetypeassert C.MultiplexPerConnection = int(opt.Value.(uint)) //nolint: forcetypeassert
case OptionTypeNTPServers: case OptionTypeNTPServers:
C.NTPServers = opt.Value.([]string) // nolint: forcetypeassert C.NTPServers = opt.Value.([]string) //nolint: forcetypeassert
if len(C.NTPServers) == 0 { if len(C.NTPServers) == 0 {
return errors.New("ntp server list is empty") return errors.New("ntp server list is empty")
} }
case OptionTypeSecret: case OptionTypeSecret:
C.Secret = opt.Value.([]byte) // nolint: forcetypeassert C.Secret = opt.Value.([]byte) //nolint: forcetypeassert
case OptionTypeAdtag: case OptionTypeAdtag:
C.AdTag = opt.Value.([]byte) // nolint: forcetypeassert C.AdTag = opt.Value.([]byte) //nolint: forcetypeassert
default: default:
return fmt.Errorf("unknown tag %v", opt.Option) return fmt.Errorf("unknown tag %v", opt.Option)
} }
+4 -5
View File
@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"strings" "strings"
@@ -41,12 +40,12 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
Timeout: ifconfigTimeout, Timeout: ifconfigTimeout,
Transport: &http.Transport{ Transport: &http.Transport{
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) { DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, network, addr) // nolint: wrapcheck return dialer.DialContext(ctx, network, addr) //nolint: wrapcheck
}, },
}, },
} }
req, err := http.NewRequest("GET", ifconfigAddress, nil) req, err := http.NewRequest(http.MethodGet, ifconfigAddress, nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot create a request: %w", err) return nil, fmt.Errorf("cannot create a request: %w", err)
} }
@@ -54,7 +53,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
resp, err := client.Do(req.WithContext(ctx)) resp, err := client.Do(req.WithContext(ctx))
if err != nil { if err != nil {
if resp != nil { if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck io.Copy(io.Discard, resp.Body) //nolint: errcheck
} }
return nil, fmt.Errorf("cannot perform a request: %w", err) return nil, fmt.Errorf("cannot perform a request: %w", err)
@@ -62,7 +61,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
defer resp.Body.Close() defer resp.Body.Close()
respDataBytes, err := ioutil.ReadAll(resp.Body) respDataBytes, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot read response body: %w", err) return nil, fmt.Errorf("cannot read response body: %w", err)
} }
+7 -6
View File
@@ -8,20 +8,21 @@ import (
) )
type URLs struct { type URLs struct {
TG string `json:"tg_url"` // nolint: tagliatelle TG string `json:"tg_url"` //nolint: tagliatelle
TMe string `json:"tme_url"` // nolint: tagliatelle TMe string `json:"tme_url"` //nolint: tagliatelle
TGQRCode string `json:"tg_qrcode"` // nolint: tagliatelle TGQRCode string `json:"tg_qrcode"` //nolint: tagliatelle
TMeQRCode string `json:"tme_qrcode"` // nolint: tagliatelle TMeQRCode string `json:"tme_qrcode"` //nolint: tagliatelle
} }
type IPURLs struct { type IPURLs struct {
IPv4 *URLs `json:"ipv4,omitempty"` IPv4 *URLs `json:"ipv4,omitempty"`
IPv6 *URLs `json:"ipv6,omitempty"` IPv6 *URLs `json:"ipv6,omitempty"`
BotSecret string `json:"secret_for_mtproxybot"` // nolint: tagliatelle BotSecret string `json:"secret_for_mtproxybot"` //nolint: tagliatelle
} }
func GetURLs() (urls IPURLs) { func GetURLs() IPURLs {
secret := "" secret := ""
urls := IPURLs{}
switch C.SecretMode { switch C.SecretMode {
case SecretModeSimple: case SecretModeSimple:
+2 -2
View File
@@ -52,10 +52,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
conn, err := c.ClientProtocol.Handshake(conn) conn, err := c.ClientProtocol.Handshake(conn)
if err != nil { if err != nil {
return nil, err // nolint: wrapcheck return nil, err //nolint: wrapcheck
} }
return conn, err // nolint: wrapcheck return conn, err //nolint: wrapcheck
} }
func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error { func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
+2 -2
View File
@@ -26,7 +26,7 @@ func cloak(one, another io.ReadWriteCloser) {
another = rwc.NewPing(ctx, another, channelPing) another = rwc.NewPing(ctx, another, channelPing)
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(2) // nolint: gomnd wg.Add(2) //nolint: gomnd
go cloakPipe(one, another, wg) go cloakPipe(one, another, wg)
@@ -69,5 +69,5 @@ func cloak(one, another io.ReadWriteCloser) {
func cloakPipe(one io.Writer, another io.Reader, wg *sync.WaitGroup) { func cloakPipe(one io.Writer, another io.Reader, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
io.Copy(one, another) // nolint: errcheck io.Copy(one, another) //nolint: errcheck
} }
+5 -2
View File
@@ -14,8 +14,8 @@ require (
go.uber.org/multierr v1.8.0 // indirect go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect golang.org/x/net v0.0.0-20220809012201-f428fae20770 // indirect
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664
google.golang.org/protobuf v1.27.1 // indirect google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/alecthomas/kingpin.v2 v2.2.6
) )
@@ -27,5 +27,8 @@ require (
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
go.uber.org/atomic v1.9.0 // indirect go.uber.org/atomic v1.9.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/tools v0.1.12 // indirect
) )
+10
View File
@@ -208,6 +208,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -262,6 +264,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -294,6 +298,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220809012201-f428fae20770 h1:dIi4qVdvjZEjiMDv7vhokAZNGnz3kepwuXqFKYDdDMs=
golang.org/x/net v0.0.0-20220809012201-f428fae20770/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -351,6 +357,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -402,6 +410,8 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+2 -2
View File
@@ -30,7 +30,7 @@ type connection struct {
channelConnDetach chan conntypes.ConnID channelConnDetach chan conntypes.ConnID
} }
func (c *connection) run() { // nolint: cyclop func (c *connection) run() { //nolint: cyclop
defer c.Close() defer c.Close()
ttl := time.NewTimer(connectionTTL) ttl := time.NewTimer(connectionTTL)
@@ -148,7 +148,7 @@ func newConnection(req *protocol.TelegramRequest) (*connection, error) {
return nil, fmt.Errorf("cannot create a new connection: %w", err) return nil, fmt.Errorf("cannot create a new connection: %w", err)
} }
id := rand.Int() // nolint: gosec id := rand.Int() //nolint: gosec
rv := &connection{ rv := &connection{
conn: conn, conn: conn,
id: id, id: id,
+1 -1
View File
@@ -18,7 +18,7 @@ func (h *hub) Register(req *protocol.TelegramRequest) (*ProxyConn, error) {
} }
func (h *hub) getMux(req *protocol.TelegramRequest) *mux { func (h *hub) getMux(req *protocol.TelegramRequest) *mux {
key := 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol()) // nolint: gomnd key := 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol()) //nolint: gomnd
h.mutex.RLock() h.mutex.RLock()
m, ok := h.muxes[key] m, ok := h.muxes[key]
-5
View File
@@ -9,7 +9,6 @@ import (
"github.com/9seconds/mtg/cli" "github.com/9seconds/mtg/cli"
"github.com/9seconds/mtg/config" "github.com/9seconds/mtg/config"
"github.com/9seconds/mtg/utils"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
) )
@@ -128,10 +127,6 @@ func main() {
app.Version(getVersion()) app.Version(getVersion())
app.HelpFlag.Short('h') app.HelpFlag.Short('h')
if err := utils.SetLimits(); err != nil {
cli.Fatal(err)
}
switch kingpin.MustParse(app.Parse(os.Args[1:])) { switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case generateSecretCommand.FullCommand(): case generateSecretCommand.FullCommand():
cli.Generate(*generateSecretType, *generateCloakHost) cli.Generate(*generateSecretType, *generateCloakHost)
+1 -1
View File
@@ -51,7 +51,7 @@ func doRPCNonceRequest(conn conntypes.BasePacketWriter) (*rpc.NonceRequest, erro
} }
if err := conn.Write(rpcNonceReq.Bytes()); err != nil { if err := conn.Write(rpcNonceReq.Bytes()); err != nil {
return nil, err // nolint: wrapcheck return nil, err //nolint: wrapcheck
} }
return rpcNonceReq, nil return rpcNonceReq, nil
+1 -1
View File
@@ -41,7 +41,7 @@ func (r *HandshakeResponse) Valid() error {
// NewHandshakeResponse constructs new handshake response from the given // NewHandshakeResponse constructs new handshake response from the given
// data. // data.
func NewHandshakeResponse(data []byte) (*HandshakeResponse, error) { func NewHandshakeResponse(data []byte) (*HandshakeResponse, error) {
if len(data) != 32 { // nolint: gomnd if len(data) != 32 { //nolint: gomnd
return nil, fmt.Errorf("incorrect handshake response length %d", len(data)) return nil, fmt.Errorf("incorrect handshake response length %d", len(data))
} }
+4 -4
View File
@@ -29,9 +29,9 @@ func (r *NonceRequest) Bytes() []byte {
// NewNonceRequest builds new none request based on proxy secret. // NewNonceRequest builds new none request based on proxy secret.
func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) { func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) {
nonce := make([]byte, 16) // nolint: gomnd nonce := make([]byte, 16) //nolint: gomnd
keySelector := make([]byte, 4) // nolint: gomnd keySelector := make([]byte, 4) //nolint: gomnd
cryptoTS := make([]byte, 4) // nolint: gomnd cryptoTS := make([]byte, 4) //nolint: gomnd
if _, err := rand.Read(nonce); err != nil { if _, err := rand.Read(nonce); err != nil {
return nil, fmt.Errorf("cannot generate nonce: %w", err) return nil, fmt.Errorf("cannot generate nonce: %w", err)
@@ -39,7 +39,7 @@ func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) {
copy(keySelector, proxySecret) copy(keySelector, proxySecret)
// 256 ^ 4 - do not know how to name // 256 ^ 4 - do not know how to name
timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 // nolint: gomnd timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 //nolint: gomnd
binary.LittleEndian.PutUint32(cryptoTS, uint32(timestamp)) binary.LittleEndian.PutUint32(cryptoTS, uint32(timestamp))
return &NonceRequest{ return &NonceRequest{
+1 -1
View File
@@ -44,7 +44,7 @@ func (r *NonceResponse) Valid(req *NonceRequest) error {
// NewNonceResponse build new nonce response based on the given data. // NewNonceResponse build new nonce response based on the given data.
func NewNonceResponse(data []byte) (*NonceResponse, error) { func NewNonceResponse(data []byte) (*NonceResponse, error) {
if len(data) != 32 { // nolint: gomnd if len(data) != 32 { //nolint: gomnd
return nil, fmt.Errorf("unexpected message length %d", len(data)) return nil, fmt.Errorf("unexpected message length %d", len(data))
} }
+2 -2
View File
@@ -21,14 +21,14 @@ const (
var ProxyRequestFlagsEncryptedPrefix [8]byte var ProxyRequestFlagsEncryptedPrefix [8]byte
func (r ProxyRequestFlags) Bytes() []byte { func (r ProxyRequestFlags) Bytes() []byte {
converted := make([]byte, 4) // nolint: gomnd converted := make([]byte, 4) //nolint: gomnd
binary.LittleEndian.PutUint32(converted, uint32(r)) binary.LittleEndian.PutUint32(converted, uint32(r))
return converted return converted
} }
func (r ProxyRequestFlags) String() string { func (r ProxyRequestFlags) String() string {
flags := make([]string, 0, 7) // nolint: gomnd flags := make([]string, 0, 7) //nolint: gomnd
if r&ProxyRequestFlagsHasAdTag != 0 { if r&ProxyRequestFlagsHasAdTag != 0 {
flags = append(flags, "HAS_AD_TAG") flags = append(flags, "HAS_AD_TAG")
+1 -1
View File
@@ -24,7 +24,7 @@ type ProxyResponse struct {
func ParseProxyResponse(packet conntypes.Packet) (*ProxyResponse, error) { func ParseProxyResponse(packet conntypes.Packet) (*ProxyResponse, error) {
var response ProxyResponse var response ProxyResponse
if len(packet) < 4 { // nolint: gomnd if len(packet) < 4 { //nolint: gomnd
return nil, fmt.Errorf("incorrect packet length: %d", len(packet)) return nil, fmt.Errorf("incorrect packet length: %d", len(packet))
} }
+1 -1
View File
@@ -14,7 +14,7 @@ const autoUpdatePeriod = time.Minute
// Fetch fetches the data on time drift. // Fetch fetches the data on time drift.
func Fetch() (time.Duration, error) { func Fetch() (time.Duration, error) {
url := config.C.NTPServers[rand.Intn(len(config.C.NTPServers))] // nolint: gosec url := config.C.NTPServers[rand.Intn(len(config.C.NTPServers))] //nolint: gosec
resp, err := ntp.Query(url) resp, err := ntp.Query(url)
if err != nil { if err != nil {
+7 -5
View File
@@ -93,12 +93,14 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
return stream.NewObfuscated2(socket, encryptor, decryptor), nil return stream.NewObfuscated2(socket, encryptor, decryptor), nil
} }
func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (fm Frame, err error) { func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (Frame, error) {
if _, err = io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil { fm := Frame{}
err = fmt.Errorf("cannot extract obfuscated2 frame: %w", err)
if _, err := io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil {
return fm, fmt.Errorf("cannot extract obfuscated2 frame: %w", err)
} }
return return fm, nil
} }
type handshakeReader struct { type handshakeReader struct {
@@ -106,7 +108,7 @@ type handshakeReader struct {
} }
func (h handshakeReader) Read(p []byte) (int, error) { func (h handshakeReader) Read(p []byte) (int, error) {
return h.parent.ReadTimeout(p, clientProtocolHandshakeTimeout) // nolint: wrapcheck return h.parent.ReadTimeout(p, clientProtocolHandshakeTimeout) //nolint: wrapcheck
} }
func MakeClientProtocol() protocol.ClientProtocol { func MakeClientProtocol() protocol.ClientProtocol {
+3 -3
View File
@@ -44,11 +44,11 @@ func (f *Frame) Unique() []byte {
return f.data[frameOffsetFirst:frameOffsetDC] return f.data[frameOffsetFirst:frameOffsetDC]
} }
func (f *Frame) Invert() (nf Frame) { func (f *Frame) Invert() Frame {
nf = *f nf := *f
for i := 0; i < frameLenKey+frameLenIV; i++ { for i := 0; i < frameLenKey+frameLenIV; i++ {
nf.data[frameOffsetFirst+i] = f.data[frameOffsetIV-1-i] nf.data[frameOffsetFirst+i] = f.data[frameOffsetIV-1-i]
} }
return return nf
} }
+8 -7
View File
@@ -39,7 +39,8 @@ func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteC
return stream.NewObfuscated2(conn, encryptor, decryptor), nil return stream.NewObfuscated2(conn, encryptor, decryptor), nil
} }
func generateFrame(cp protocol.ClientProtocol) (fm Frame) { func generateFrame(cp protocol.ClientProtocol) Frame {
fm := Frame{}
data := fm.Bytes() data := fm.Bytes()
for { for {
@@ -47,22 +48,22 @@ func generateFrame(cp protocol.ClientProtocol) (fm Frame) {
continue continue
} }
if data[0] == 0xef { // nolint: gomnd if data[0] == 0xef { //nolint: gomnd
continue continue
} }
val := (uint32(data[3]) << 24) | (uint32(data[2]) << 16) | (uint32(data[1]) << 8) | uint32(data[0]) // nolint: gomnd, lll val := (uint32(data[3]) << 24) | (uint32(data[2]) << 16) | (uint32(data[1]) << 8) | uint32(data[0]) //nolint: gomnd, lll
if val == 0x44414548 || val == 0x54534f50 || val == 0x20544547 || val == 0x4954504f || val == 0xeeeeeeee { // nolint: lll if val == 0x44414548 || val == 0x54534f50 || val == 0x20544547 || val == 0x4954504f || val == 0xeeeeeeee { //nolint: lll
continue continue
} }
val = (uint32(data[7]) << 24) | (uint32(data[6]) << 16) | (uint32(data[5]) << 8) | uint32(data[4]) // nolint: gomnd val = (uint32(data[7]) << 24) | (uint32(data[6]) << 16) | (uint32(data[5]) << 8) | uint32(data[4]) //nolint: gomnd
if val == 0x00000000 { // nolint: gomnd if val == 0x00000000 { //nolint: gomnd
continue continue
} }
copy(fm.Magic(), cp.ConnectionType().Tag()) copy(fm.Magic(), cp.ConnectionType().Tag())
return return fm
} }
} }
+2 -2
View File
@@ -14,13 +14,13 @@ const directPipeBufferSize = 1024
func directConnection(request *protocol.TelegramRequest) error { func directConnection(request *protocol.TelegramRequest) error {
telegramConnRaw, err := obfuscated2.TelegramProtocol(request) telegramConnRaw, err := obfuscated2.TelegramProtocol(request)
if err != nil { if err != nil {
return err // nolint: wrapcheck return err //nolint: wrapcheck
} }
defer telegramConnRaw.Close() defer telegramConnRaw.Close()
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(2) // nolint: gomnd wg.Add(2) //nolint: gomnd
go directPipe(telegramConnRaw, request.ClientConn, wg, request.Logger) go directPipe(telegramConnRaw, request.ClientConn, wg, request.Logger)
+1 -1
View File
@@ -32,7 +32,7 @@ func middleConnection(request *protocol.TelegramRequest) {
} }
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(2) // nolint: gomnd wg.Add(2) //nolint: gomnd
go middlePipe(telegramConn, clientConn, wg, request.Logger) go middlePipe(telegramConn, clientConn, wg, request.Logger)
+2 -2
View File
@@ -28,11 +28,11 @@ func Init(ctx context.Context) error {
Handler: mux, Handler: mux,
} }
go srv.Serve(listener) // nolint: errcheck go srv.Serve(listener) //nolint: errcheck
go func() { go func() {
<-ctx.Done() <-ctx.Done()
srv.Shutdown(context.Background()) // nolint: errcheck, contextcheck srv.Shutdown(context.Background()) //nolint: errcheck
}() }()
Stats = multiStats(stats) Stats = multiStats(stats)
+4 -4
View File
@@ -83,7 +83,7 @@ func (s *statsStatsd) ClientDisconnected(connectionType conntypes.ConnectionType
} }
func (s *statsStatsd) changeConnections(connectionType conntypes.ConnectionType, addr *net.TCPAddr, increment int64) { func (s *statsStatsd) changeConnections(connectionType conntypes.ConnectionType, addr *net.TCPAddr, increment int64) {
tags := make([]*statsStatsdTag, 0, 2) // nolint: gomnd tags := make([]*statsStatsdTag, 0, 2) //nolint: gomnd
switch connectionType { switch connectionType {
case conntypes.ConnectionTypeAbridged: case conntypes.ConnectionTypeAbridged:
@@ -172,7 +172,7 @@ func (s *statsStatsd) initGauge(metric, key string, tags []statsd.Tag) {
s.seenMutex.RUnlock() s.seenMutex.RUnlock()
return return
} else { // nolint: golint,revive } else { //nolint: golint,revive
s.seenMutex.RUnlock() s.seenMutex.RUnlock()
} }
@@ -194,8 +194,8 @@ func newStatsStatsd() Interface {
return &statsStatsd{ return &statsStatsd{
seen: make(map[string]struct{}), seen: make(map[string]struct{}),
client: statsd.NewClient(config.C.StatsdAddr.String(), client: statsd.NewClient(config.C.StatsdAddr.String(),
statsd.SendLoopCount(2), // nolint: gomnd statsd.SendLoopCount(2), //nolint: gomnd
statsd.ReconnectInterval(10*time.Second), // nolint: gomnd statsd.ReconnectInterval(10*time.Second), //nolint: gomnd
statsd.Logger(logger), statsd.Logger(logger),
statsd.MetricPrefix(prefix), statsd.MetricPrefix(prefix),
statsd.TagStyle(config.C.StatsdTagsFormat), statsd.TagStyle(config.C.StatsdTagsFormat),
+6 -6
View File
@@ -12,8 +12,8 @@ import (
) )
const ( const (
addressesURLV4 = "https://core.telegram.org/getProxyConfig" // nolint: gas addressesURLV4 = "https://core.telegram.org/getProxyConfig" //nolint: gas
addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" // nolint: gas addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" //nolint: gas
) )
var addressesProxyForSplitter = regexp.MustCompile(`\s+`) var addressesProxyForSplitter = regexp.MustCompile(`\s+`)
@@ -74,12 +74,12 @@ func getAddresses(url string) (map[conntypes.DC][]string, conntypes.DC, error) {
} }
func addressesParseProxyFor(text string) (string, conntypes.DC, error) { func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
chunks := addressesProxyForSplitter.Split(text, 3) // nolint: gomnd chunks := addressesProxyForSplitter.Split(text, 3) //nolint: gomnd
if len(chunks) != 3 || chunks[0] != "proxy_for" { if len(chunks) != 3 || chunks[0] != "proxy_for" {
return "", 0, fmt.Errorf("incorrect config %s", text) return "", 0, fmt.Errorf("incorrect config %s", text)
} }
dc, err := strconv.ParseInt(chunks[1], 10, 16) // nolint: gomnd dc, err := strconv.ParseInt(chunks[1], 10, 16) //nolint: gomnd
if err != nil { if err != nil {
return "", 0, fmt.Errorf("incorrect config '%s': %w", text, err) return "", 0, fmt.Errorf("incorrect config '%s': %w", text, err)
} }
@@ -93,14 +93,14 @@ func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
} }
func addressesParseDefault(text string) (conntypes.DC, error) { func addressesParseDefault(text string) (conntypes.DC, error) {
chunks := addressesProxyForSplitter.Split(text, 2) // nolint: gomnd chunks := addressesProxyForSplitter.Split(text, 2) //nolint: gomnd
if len(chunks) != 2 || chunks[0] != "default" { if len(chunks) != 2 || chunks[0] != "default" {
return 0, fmt.Errorf("incorrect config '%s'", text) return 0, fmt.Errorf("incorrect config '%s'", text)
} }
dcString := strings.TrimRight(chunks[1], ";") dcString := strings.TrimRight(chunks[1], ";")
dc, err := strconv.ParseInt(dcString, 10, 16) // nolint: gomnd dc, err := strconv.ParseInt(dcString, 10, 16) //nolint: gomnd
if err != nil { if err != nil {
return 0, fmt.Errorf("incorrect config '%s': %w", text, err) return 0, fmt.Errorf("incorrect config '%s': %w", text, err)
} }
+3 -4
View File
@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"time" "time"
) )
@@ -22,7 +21,7 @@ func request(url string) (io.ReadCloser, error) {
ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout) ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout)
defer cancel() defer cancel()
req, err := http.NewRequestWithContext(ctx, "GET", url, nil) req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -33,12 +32,12 @@ func request(url string) (io.ReadCloser, error) {
resp, err := httpClient.Do(req) resp, err := httpClient.Do(req)
if err != nil { if err != nil {
if resp != nil { if resp != nil {
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck io.Copy(io.Discard, resp.Body) //nolint: errcheck
resp.Body.Close() resp.Body.Close()
} }
return nil, fmt.Errorf("cannot perform a request: %w", err) return nil, fmt.Errorf("cannot perform a request: %w", err)
} }
return resp.Body, err // nolint: wrapcheck return resp.Body, err //nolint: wrapcheck
} }
+3 -3
View File
@@ -2,10 +2,10 @@ package api
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
) )
const secretURL = "https://core.telegram.org/getProxySecret" // nolint: gas const secretURL = "https://core.telegram.org/getProxySecret" //nolint: gas
func Secret() ([]byte, error) { func Secret() ([]byte, error) {
resp, err := request(secretURL) resp, err := request(secretURL)
@@ -15,7 +15,7 @@ func Secret() ([]byte, error) {
defer resp.Close() defer resp.Close()
secret, err := ioutil.ReadAll(resp) secret, err := io.ReadAll(resp)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot read response: %w", err) return nil, fmt.Errorf("cannot read response: %w", err)
} }
+2 -2
View File
@@ -51,7 +51,7 @@ func (b *baseTelegram) dial(dc conntypes.DC,
} }
func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.ConnectionProtocol) []string { func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.ConnectionProtocol) []string {
addresses := make([]string, 0, 2) // nolint: gomnd addresses := make([]string, 0, 2) //nolint: gomnd
protos := []conntypes.ConnectionProtocol{ protos := []conntypes.ConnectionProtocol{
conntypes.ConnectionProtocolIPv6, conntypes.ConnectionProtocolIPv6,
conntypes.ConnectionProtocolIPv4, conntypes.ConnectionProtocolIPv4,
@@ -86,7 +86,7 @@ func (b *baseTelegram) chooseAddress(addresses map[conntypes.DC][]string,
case len(addrs) == 1: case len(addrs) == 1:
return addrs[0] return addrs[0]
case len(addrs) > 1: case len(addrs) > 1:
return addrs[rand.Intn(len(addrs))] // nolint: gosec return addrs[rand.Intn(len(addrs))] //nolint: gosec
} }
return "" return ""
+14 -14
View File
@@ -20,22 +20,22 @@ const (
type CipherSuiteType uint8 type CipherSuiteType uint8
const ( const (
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint,revive CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota //nolint: stylecheck,golint,revive,nosnakecase
CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint,revive CipherSuiteType_TLS_AES_256_GCM_SHA384 //nolint: stylecheck,golint,revive,nosnakecase
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint,revive CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 //nolint: stylecheck,golint,revive,nosnakecase
) )
func (c CipherSuiteType) Bytes() []byte { func (c CipherSuiteType) Bytes() []byte {
switch c { switch c {
case CipherSuiteType_TLS_AES_128_GCM_SHA256: case CipherSuiteType_TLS_AES_128_GCM_SHA256: //nolint: nosnakecase
return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes //nolint: nosnakecase
case CipherSuiteType_TLS_AES_256_GCM_SHA384: case CipherSuiteType_TLS_AES_256_GCM_SHA384: //nolint: nosnakecase
return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes //nolint: nosnakecase
case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256: case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256: //nolint: nosnakecase
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes //nolint: nosnakecase
} }
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes //nolint: nosnakecase
} }
type Version uint8 type Version uint8
@@ -69,9 +69,9 @@ var (
Version12Bytes = []byte{0x03, 0x03} Version12Bytes = []byte{0x03, 0x03}
Version13Bytes = []byte{0x03, 0x04} Version13Bytes = []byte{0x03, 0x04}
CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint,revive CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} //nolint: stylecheck,golint,revive,nosnakecase
CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint,revive CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} //nolint: stylecheck,golint,revive,nosnakecase
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint,revive CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} //nolint: stylecheck,golint,revive,nosnakecase
) )
type Byter interface { type Byter interface {
@@ -82,7 +82,7 @@ type Byter interface {
type RawBytes []byte type RawBytes []byte
func (r RawBytes) WriteBytes(writer io.Writer) { func (r RawBytes) WriteBytes(writer io.Writer) {
writer.Write(r) // nolint: errcheck writer.Write(r) //nolint: errcheck
} }
func (r RawBytes) Len() int { func (r RawBytes) Len() int {
+3 -3
View File
@@ -18,7 +18,7 @@ type Handshake struct {
func (h *Handshake) WriteBytes(writer io.Writer) { func (h *Handshake) WriteBytes(writer io.Writer) {
packetBuf := bytes.Buffer{} packetBuf := bytes.Buffer{}
writer.Write([]byte{byte(h.Type)}) // nolint: errcheck writer.Write([]byte{byte(h.Type)}) //nolint: errcheck
packetBuf.Write(h.Version.Bytes()) packetBuf.Write(h.Version.Bytes())
packetBuf.Write(h.Random[:]) packetBuf.Write(h.Random[:])
@@ -30,8 +30,8 @@ func (h *Handshake) WriteBytes(writer io.Writer) {
sizeUint24Bytes := sizeUint24[:] sizeUint24Bytes := sizeUint24[:]
sizeUint24Bytes[0], sizeUint24Bytes[2] = sizeUint24Bytes[2], sizeUint24Bytes[0] sizeUint24Bytes[0], sizeUint24Bytes[2] = sizeUint24Bytes[2], sizeUint24Bytes[0]
writer.Write(sizeUint24Bytes) // nolint: errcheck writer.Write(sizeUint24Bytes) //nolint: errcheck
packetBuf.WriteTo(writer) // nolint: errcheck packetBuf.WriteTo(writer) //nolint: errcheck
} }
func (h *Handshake) Len() int { func (h *Handshake) Len() int {
+7 -5
View File
@@ -16,9 +16,9 @@ type Record struct {
} }
func (r Record) WriteBytes(writer io.Writer) { func (r Record) WriteBytes(writer io.Writer) {
writer.Write([]byte{byte(r.Type)}) // nolint: errcheck writer.Write([]byte{byte(r.Type)}) //nolint: errcheck
writer.Write(r.Version.Bytes()) // nolint: errcheck writer.Write(r.Version.Bytes()) //nolint: errcheck
binary.Write(writer, binary.BigEndian, uint16(r.Data.Len())) // nolint: errcheck binary.Write(writer, binary.BigEndian, uint16(r.Data.Len())) //nolint: errcheck
r.Data.WriteBytes(writer) r.Data.WriteBytes(writer)
} }
@@ -65,7 +65,9 @@ func ReadRecord(reader io.Reader) (Record, error) {
return rec, nil return rec, nil
} }
func MakeRecords(raw []byte) (arr []Record) { func MakeRecords(raw []byte) []Record {
var arr []Record
for len(raw) > 0 { for len(raw) > 0 {
chunkSize := recordMaxChunkSize chunkSize := recordMaxChunkSize
if chunkSize > len(raw) { if chunkSize > len(raw) {
@@ -80,5 +82,5 @@ func MakeRecords(raw []byte) (arr []Record) {
raw = raw[chunkSize:] raw = raw[chunkSize:]
} }
return return arr
} }
+8 -8
View File
@@ -36,8 +36,8 @@ func (s ServerHello) WelcomePacket() []byte {
} }
recChangeCipher.WriteBytes(buf) recChangeCipher.WriteBytes(buf)
hostCert := make([]byte, 1024+mrand.Intn(3092)) // nolint: gosec, gomnd hostCert := make([]byte, 1024+mrand.Intn(3092)) //nolint: gosec, gomnd
rand.Read(hostCert) // nolint: errcheck rand.Read(hostCert) //nolint: errcheck
recData := Record{ recData := Record{
Type: RecordTypeApplicationData, Type: RecordTypeApplicationData,
@@ -66,8 +66,8 @@ func NewServerHello(clientHello *ClientHello) *ServerHello {
rv.SessionID = make([]byte, len(clientHello.SessionID)) rv.SessionID = make([]byte, len(clientHello.SessionID))
copy(rv.SessionID, clientHello.SessionID) copy(rv.SessionID, clientHello.SessionID)
tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes) tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes) //nolint: nosnakecase
tail.WriteByte(0x00) // nolint: gomnd // no compression tail.WriteByte(0x00) //nolint: gomnd // no compression
makeTLSExtensions(tail) makeTLSExtensions(tail)
rv.Tail = RawBytes(tail.Bytes()) rv.Tail = RawBytes(tail.Bytes())
@@ -75,7 +75,7 @@ func NewServerHello(clientHello *ClientHello) *ServerHello {
} }
func makeTLSExtensions(buf io.Writer) { func makeTLSExtensions(buf io.Writer) {
buf.Write([]byte{ // nolint: errcheck buf.Write([]byte{ //nolint: errcheck
0x00, 0x2e, // 46 bytes of data 0x00, 0x2e, // 46 bytes of data
0x00, 0x33, // Extension - Key Share 0x00, 0x33, // Extension - Key Share
0x00, 0x24, // 36 bytes 0x00, 0x24, // 36 bytes
@@ -85,11 +85,11 @@ func makeTLSExtensions(buf io.Writer) {
var scalar [32]byte var scalar [32]byte
rand.Read(scalar[:]) // nolint: errcheck rand.Read(scalar[:]) //nolint: errcheck
curve, _ := curve25519.X25519(scalar[:], curve25519.Basepoint) curve, _ := curve25519.X25519(scalar[:], curve25519.Basepoint)
buf.Write(curve) // nolint: errcheck buf.Write(curve) //nolint: errcheck
buf.Write([]byte{ // nolint: errcheck buf.Write([]byte{ //nolint: errcheck
0x00, 0x2b, // Extension - Supported Versions 0x00, 0x2b, // Extension - Supported Versions
0x00, 0x02, // 2 bytes are following 0x00, 0x02, // 2 bytes are following
0x03, 0x04, // TLS 1.3 0x03, 0x04, // TLS 1.3
+1 -1
View File
@@ -6,7 +6,7 @@ import (
) )
func InitTCP(conn net.Conn, readBufferSize, writeBufferSize int) error { func InitTCP(conn net.Conn, readBufferSize, writeBufferSize int) error {
tcpConn := conn.(*net.TCPConn) // nolint: forcetypeassert tcpConn := conn.(*net.TCPConn) //nolint: forcetypeassert
if err := tcpConn.SetNoDelay(true); err != nil { if err := tcpConn.SetNoDelay(true); err != nil {
return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err) return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err)
+4 -3
View File
@@ -4,14 +4,15 @@ import "io"
const readFullBufferSize = 1024 + 1 // +1 because telegram opreates with blocks mod 4 const readFullBufferSize = 1024 + 1 // +1 because telegram opreates with blocks mod 4
func ReadFull(src io.Reader) (rv []byte, err error) { func ReadFull(src io.Reader) ([]byte, error) {
buf := make([]byte, readFullBufferSize) buf := make([]byte, readFullBufferSize)
n := readFullBufferSize n := readFullBufferSize
rv := []byte{}
for n == len(buf) { for n == len(buf) {
n, err = src.Read(buf) n, err := src.Read(buf)
if err != nil { if err != nil {
return nil, err // nolint: wrapcheck return nil, err //nolint: wrapcheck
} }
rv = append(rv, buf[:n]...) rv = append(rv, buf[:n]...)
+1 -1
View File
@@ -6,7 +6,7 @@ func ReverseBytes(data []byte) []byte {
rv := make([]byte, dataLen) rv := make([]byte, dataLen)
rv[dataLen/2] = data[dataLen/2] rv[dataLen/2] = data[dataLen/2]
for i := dataLen/2 - 1; i >= 0; i-- { // nolint: gomnd for i := dataLen/2 - 1; i >= 0; i-- { //nolint: gomnd
opp := dataLen - i - 1 opp := dataLen - i - 1
rv[i], rv[opp] = data[opp], data[i] rv[i], rv[opp] = data[opp], data[i]
} }
-25
View File
@@ -1,25 +0,0 @@
//go:build !windows
// +build !windows
package utils
import (
"fmt"
"golang.org/x/sys/unix"
)
func SetLimits() error {
rLimit := unix.Rlimit{}
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
return fmt.Errorf("cannot get rlimit: %w", err)
}
rLimit.Cur = rLimit.Max
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
return fmt.Errorf("cannot set rlimit: %w", err)
}
return nil
}
+2 -2
View File
@@ -3,9 +3,9 @@ package utils
type Uint24 [3]byte type Uint24 [3]byte
func ToUint24(number uint32) Uint24 { func ToUint24(number uint32) Uint24 {
return Uint24{byte(number), byte(number >> 8), byte(number >> 16)} // nolint: gomnd return Uint24{byte(number), byte(number >> 8), byte(number >> 16)} //nolint: gomnd
} }
func FromUint24(number Uint24) uint32 { func FromUint24(number Uint24) uint32 {
return uint32(number[0]) + (uint32(number[1]) << 8) + (uint32(number[2]) << 16) // nolint: gomnd return uint32(number[0]) + (uint32(number[1]) << 8) + (uint32(number[2]) << 16) //nolint: gomnd
} }
+18 -16
View File
@@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"io" "io"
"io/ioutil"
"net" "net"
"github.com/9seconds/mtg/conntypes" "github.com/9seconds/mtg/conntypes"
@@ -28,11 +27,14 @@ var mtprotoFramePadding = []byte{0x04, 0x00, 0x00, 0x00}
// //
// MSGLEN is the length of the message + len of seqno and msglen. // MSGLEN is the length of the message + len of seqno and msglen.
// SEQNO is the number of frame in the receive/send sequence. If client // SEQNO is the number of frame in the receive/send sequence. If client
// sends a message with SeqNo 18, it has to receive message with SeqNo 18. //
// sends a message with SeqNo 18, it has to receive message with SeqNo 18.
//
// MSG is the data which has to be written // MSG is the data which has to be written
// CRC32 is the CRC32 checksum of MSGLEN + SEQNO + MSG // CRC32 is the CRC32 checksum of MSGLEN + SEQNO + MSG
// PADDING is custom padding schema to complete frame length to such that // PADDING is custom padding schema to complete frame length to such that
// len(frame) % 16 == 0 //
// len(frame) % 16 == 0
type wrapperMtprotoFrame struct { type wrapperMtprotoFrame struct {
parent conntypes.StreamReadWriteCloser parent conntypes.StreamReadWriteCloser
logger *zap.SugaredLogger logger *zap.SugaredLogger
@@ -40,7 +42,7 @@ type wrapperMtprotoFrame struct {
writeSeqNo int32 writeSeqNo int32
} }
func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen, cyclop func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { //nolint: funlen, cyclop
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
sum := crc32.NewIEEE() sum := crc32.NewIEEE()
@@ -50,7 +52,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
buf.Reset() buf.Reset()
sum.Reset() sum.Reset()
if _, err := io.CopyN(writer, w.parent, 4); err != nil { // nolint: gomnd if _, err := io.CopyN(writer, w.parent, 4); err != nil { //nolint: gomnd
return nil, fmt.Errorf("cannot read frame padding: %w", err) return nil, fmt.Errorf("cannot read frame padding: %w", err)
} }
@@ -72,23 +74,23 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
buf.Reset() buf.Reset()
if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil { // nolint: gomnd if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil { //nolint: gomnd
return nil, fmt.Errorf("cannot read the message frame: %w", err) return nil, fmt.Errorf("cannot read the message frame: %w", err)
} }
var seqNo int32 var seqNo int32
binary.Read(buf, binary.LittleEndian, &seqNo) // nolint: errcheck binary.Read(buf, binary.LittleEndian, &seqNo) //nolint: errcheck
if seqNo != w.readSeqNo { if seqNo != w.readSeqNo {
return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo) return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo)
} }
data, _ := ioutil.ReadAll(buf) data, _ := io.ReadAll(buf)
buf.Reset() buf.Reset()
// write to buf, not to writer. This is because we are going to fetch // write to buf, not to writer. This is because we are going to fetch
// crc32 checksum. // crc32 checksum.
if _, err := io.CopyN(buf, w.parent, 4); err != nil { // nolint: gomnd if _, err := io.CopyN(buf, w.parent, 4); err != nil { //nolint: gomnd
return nil, fmt.Errorf("cannot read checksum: %w", err) return nil, fmt.Errorf("cannot read checksum: %w", err)
} }
@@ -109,18 +111,18 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
} }
func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error { func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
messageLength := 4 + 4 + len(p) + 4 // nolint: gomnd messageLength := 4 + 4 + len(p) + 4 //nolint: gomnd
paddingLength := (aes.BlockSize - messageLength%aes.BlockSize) % aes.BlockSize paddingLength := (aes.BlockSize - messageLength%aes.BlockSize) % aes.BlockSize
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
binary.Write(buf, binary.LittleEndian, uint32(messageLength)) // nolint: errcheck binary.Write(buf, binary.LittleEndian, uint32(messageLength)) //nolint: errcheck
binary.Write(buf, binary.LittleEndian, w.writeSeqNo) // nolint: errcheck binary.Write(buf, binary.LittleEndian, w.writeSeqNo) //nolint: errcheck
buf.Write(p) buf.Write(p)
checksum := crc32.ChecksumIEEE(buf.Bytes()) checksum := crc32.ChecksumIEEE(buf.Bytes())
binary.Write(buf, binary.LittleEndian, checksum) // nolint: errcheck binary.Write(buf, binary.LittleEndian, checksum) //nolint: errcheck
buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) // nolint: gomnd buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) //nolint: gomnd
w.logger.Debugw("Write MTProto frame", w.logger.Debugw("Write MTProto frame",
"length", len(p), "length", len(p),
@@ -132,11 +134,11 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
_, err := w.parent.Write(buf.Bytes()) _, err := w.parent.Write(buf.Bytes())
return err // nolint: wrapcheck return err //nolint: wrapcheck
} }
func (w *wrapperMtprotoFrame) Close() error { func (w *wrapperMtprotoFrame) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperMtprotoFrame) Conn() net.Conn { func (w *wrapperMtprotoFrame) Conn() net.Conn {
+4 -4
View File
@@ -39,9 +39,9 @@ func (w *wrapperClientAbridged) Read(acks *conntypes.ConnectionAcks) (conntypes.
} }
if msgLength == clientAbridgedSmallPacketLength { if msgLength == clientAbridgedSmallPacketLength {
buf.Grow(3) // nolint: gomnd buf.Grow(3) //nolint: gomnd
if _, err := io.CopyN(&buf, w.parent, 3); err != nil { // nolint: gomnd if _, err := io.CopyN(&buf, w.parent, 3); err != nil { //nolint: gomnd
return nil, fmt.Errorf("cannot read correct message length: %w", err) return nil, fmt.Errorf("cannot read correct message length: %w", err)
} }
@@ -75,7 +75,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
return nil return nil
} }
packetLength := len(packet) / 4 // nolint: gomnd packetLength := len(packet) / 4 //nolint: gomnd
switch { switch {
case packetLength < clientAbridgedSmallPacketLength: case packetLength < clientAbridgedSmallPacketLength:
@@ -104,7 +104,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
} }
func (w *wrapperClientAbridged) Close() error { func (w *wrapperClientAbridged) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperClientAbridged) Conn() net.Conn { func (w *wrapperClientAbridged) Conn() net.Conn {
+3 -3
View File
@@ -20,9 +20,9 @@ type wrapperClientIntermediate struct {
func (w *wrapperClientIntermediate) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) { func (w *wrapperClientIntermediate) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) {
buf := bytes.Buffer{} buf := bytes.Buffer{}
buf.Grow(4) // nolint: gomnd buf.Grow(4) //nolint: gomnd
if _, err := io.CopyN(&buf, w.parent, 4); err != nil { // nolint: gomnd if _, err := io.CopyN(&buf, w.parent, 4); err != nil { //nolint: gomnd
return nil, fmt.Errorf("cannot read message length: %w", err) return nil, fmt.Errorf("cannot read message length: %w", err)
} }
@@ -63,7 +63,7 @@ func (w *wrapperClientIntermediate) Write(packet conntypes.Packet, acks *conntyp
} }
func (w *wrapperClientIntermediate) Close() error { func (w *wrapperClientIntermediate) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperClientIntermediate) Conn() net.Conn { func (w *wrapperClientIntermediate) Conn() net.Conn {
@@ -20,7 +20,7 @@ func (w *wrapperClientIntermediateSecure) Read(acks *conntypes.ConnectionAcks) (
return nil, err return nil, err
} }
length := len(data) - (len(data) % 4) // nolint: gomnd length := len(data) - (len(data) % 4) //nolint: gomnd
return data[:length], nil return data[:length], nil
} }
@@ -35,11 +35,11 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c
} }
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
paddingLength := rand.Intn(4) // nolint: gosec, gomnd paddingLength := rand.Intn(4) //nolint: gosec, gomnd
buf.Grow(4 + len(packet) + paddingLength) buf.Grow(4 + len(packet) + paddingLength)
binary.Write(buf, binary.LittleEndian, uint32(len(packet)+paddingLength)) // nolint: errcheck binary.Write(buf, binary.LittleEndian, uint32(len(packet)+paddingLength)) //nolint: errcheck
buf.Write(packet) buf.Write(packet)
buf.Write(make([]byte, paddingLength)) buf.Write(make([]byte, paddingLength))
+2 -2
View File
@@ -42,11 +42,11 @@ func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.Connection
buf.Write(rpc.ProxyRequestProxyTag) buf.Write(rpc.ProxyRequestProxyTag)
buf.WriteByte(byte(len(config.C.AdTag))) buf.WriteByte(byte(len(config.C.AdTag)))
buf.Write(config.C.AdTag) buf.Write(config.C.AdTag)
buf.Write(make([]byte, (4-buf.Len()%4)%4)) // nolint: gomnd buf.Write(make([]byte, (4-buf.Len()%4)%4)) //nolint: gomnd
buf.Grow(len(packet)) buf.Grow(len(packet))
buf.Write(packet) buf.Write(packet)
return w.proxy.Write(buf.Bytes()) // nolint: wrapcheck return w.proxy.Write(buf.Bytes()) //nolint: wrapcheck
} }
func (w *wrapperProxy) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) { func (w *wrapperProxy) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) {
+3 -3
View File
@@ -20,7 +20,7 @@ func (w *wrapperPing) Read(p []byte) (int, error) {
} }
} }
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperPing) Write(p []byte) (int, error) { func (w *wrapperPing) Write(p []byte) (int, error) {
@@ -32,11 +32,11 @@ func (w *wrapperPing) Write(p []byte) (int, error) {
} }
} }
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperPing) Close() error { func (w *wrapperPing) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func NewPing(ctx context.Context, parent io.ReadWriteCloser, channelPing chan<- struct{}) io.ReadWriteCloser { func NewPing(ctx context.Context, parent io.ReadWriteCloser, channelPing chan<- struct{}) io.ReadWriteCloser {
+3 -3
View File
@@ -26,7 +26,7 @@ func (w *wrapperBlockCipher) Write(p []byte) (int, error) {
return 0, err return 0, err
} }
return w.parent.Write(encrypted) // nolint: wrapcheck return w.parent.Write(encrypted) //nolint: wrapcheck
} }
func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -35,7 +35,7 @@ func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int,
return 0, err return 0, err
} }
return w.parent.WriteTimeout(encrypted, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(encrypted, timeout) //nolint: wrapcheck
} }
func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) { func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) {
@@ -50,7 +50,7 @@ func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) {
} }
func (w *wrapperBlockCipher) Close() error { func (w *wrapperBlockCipher) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperBlockCipher) Conn() net.Conn { func (w *wrapperBlockCipher) Conn() net.Conn {
+1 -1
View File
@@ -33,7 +33,7 @@ func (b *bufferedReader) ReadTimeout(p []byte, _ time.Duration) (int, error) {
func (b *bufferedReader) flush(p []byte) (int, error) { func (b *bufferedReader) flush(p []byte) (int, error) {
if b.buf.Len() > len(p) { if b.buf.Len() > len(p) {
return b.buf.Read(p) // nolint: wrapcheck return b.buf.Read(p) //nolint: wrapcheck
} }
sizeToReturn := b.buf.Len() sizeToReturn := b.buf.Len()
+6 -6
View File
@@ -43,7 +43,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
w.Close() w.Close()
} }
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -64,13 +64,13 @@ func (w *wrapperConn) Read(p []byte) (int, error) {
w.Close() w.Close()
} }
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperConn) Close() error { func (w *wrapperConn) Close() error {
w.logger.Debugw("Close connection") w.logger.Debugw("Close connection")
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperConn) Conn() net.Conn { func (w *wrapperConn) Conn() net.Conn {
@@ -93,9 +93,9 @@ func newConn(parent net.Conn,
connID conntypes.ConnID, connID conntypes.ConnID,
purpose connPurpose, purpose connPurpose,
) conntypes.StreamReadWriteCloser { ) conntypes.StreamReadWriteCloser {
localAddr := *parent.LocalAddr().(*net.TCPAddr) // nolint: forcetypeassert localAddr := *parent.LocalAddr().(*net.TCPAddr) //nolint: forcetypeassert
if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil { // nolint: forcetypeassert if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil { //nolint: forcetypeassert
if config.C.PublicIPv4.IP != nil { if config.C.PublicIPv4.IP != nil {
localAddr.IP = config.C.PublicIPv4.IP localAddr.IP = config.C.PublicIPv4.IP
} }
@@ -118,7 +118,7 @@ func newConn(parent net.Conn,
parent: parent, parent: parent,
connID: connID, connID: connID,
logger: logger, logger: logger,
remoteAddr: parent.RemoteAddr().(*net.TCPAddr), // nolint: forcetypeassert remoteAddr: parent.RemoteAddr().(*net.TCPAddr), //nolint: forcetypeassert
localAddr: &localAddr, localAddr: &localAddr,
} }
} }
+5 -5
View File
@@ -23,7 +23,7 @@ func (w *wrapperCtx) WriteTimeout(p []byte, timeout time.Duration) (int, error)
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err()) return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default: default:
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck
} }
} }
@@ -34,7 +34,7 @@ func (w *wrapperCtx) Write(p []byte) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err()) return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default: default:
return w.parent.Write(p) // nolint: wrapcheck return w.parent.Write(p) //nolint: wrapcheck
} }
} }
@@ -45,7 +45,7 @@ func (w *wrapperCtx) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err()) return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default: default:
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck return w.parent.ReadTimeout(p, timeout) //nolint: wrapcheck
} }
} }
@@ -56,14 +56,14 @@ func (w *wrapperCtx) Read(p []byte) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err()) return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default: default:
return w.parent.Read(p) // nolint: wrapcheck return w.parent.Read(p) //nolint: wrapcheck
} }
} }
func (w *wrapperCtx) Close() error { func (w *wrapperCtx) Close() error {
w.cancel() w.cancel()
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperCtx) Conn() net.Conn { func (w *wrapperCtx) Conn() net.Conn {
+4 -4
View File
@@ -20,7 +20,7 @@ type wrapperFakeTLS struct {
func (w *wrapperFakeTLS) Write(p []byte) (int, error) { func (w *wrapperFakeTLS) Write(p []byte) (int, error) {
return w.write(p, func(b []byte) (int, error) { return w.write(p, func(b []byte) (int, error) {
return w.parent.Write(b) // nolint: wrapcheck return w.parent.Write(b) //nolint: wrapcheck
}) })
} }
@@ -30,7 +30,7 @@ func (w *wrapperFakeTLS) WriteTimeout(p []byte, timeout time.Duration) (int, err
return w.write(p, func(b []byte) (int, error) { return w.write(p, func(b []byte) (int, error) {
elapsed := time.Since(startTime) elapsed := time.Since(startTime)
if elapsed > timeout { if elapsed > timeout {
return w.parent.WriteTimeout(b, timeout-elapsed) // nolint: wrapcheck return w.parent.WriteTimeout(b, timeout-elapsed) //nolint: wrapcheck
} }
return 0, errors.New("timeout") return 0, errors.New("timeout")
@@ -73,7 +73,7 @@ func (w *wrapperFakeTLS) RemoteAddr() *net.TCPAddr {
} }
func (w *wrapperFakeTLS) Close() error { func (w *wrapperFakeTLS) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
@@ -85,7 +85,7 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit
for { for {
rec, err := tlstypes.ReadRecord(faketls.parent) rec, err := tlstypes.ReadRecord(faketls.parent)
if err != nil { if err != nil {
return nil, err // nolint: wrapcheck return nil, err //nolint: wrapcheck
} }
switch rec.Type { switch rec.Type {
+3 -3
View File
@@ -100,11 +100,11 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose,
message.Write(req.Nonce) message.Write(req.Nonce)
data := message.Bytes() data := message.Bytes()
md5sum := md5.Sum(data[1:]) // nolint: gas md5sum := md5.Sum(data[1:]) //nolint: gas
sha1sum := sha1.Sum(data) // nolint: gosec sha1sum := sha1.Sum(data) //nolint: gosec
key := append(md5sum[:12], sha1sum[:]...) key := append(md5sum[:12], sha1sum[:]...)
iv := md5.Sum(data[2:]) // nolint: gas iv := md5.Sum(data[2:]) //nolint: gas
return key, iv[:] return key, iv[:]
} }
+4 -4
View File
@@ -31,7 +31,7 @@ func (w *wrapperObfuscated2) ReadTimeout(p []byte, timeout time.Duration) (int,
func (w *wrapperObfuscated2) Read(p []byte) (int, error) { func (w *wrapperObfuscated2) Read(p []byte) (int, error) {
n, err := w.parent.Read(p) n, err := w.parent.Read(p)
if err != nil { if err != nil {
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
w.decryptor.XORKeyStream(p, p[:n]) w.decryptor.XORKeyStream(p, p[:n])
@@ -48,7 +48,7 @@ func (w *wrapperObfuscated2) WriteTimeout(p []byte, timeout time.Duration) (int,
w.encryptor.XORKeyStream(buf, buf) w.encryptor.XORKeyStream(buf, buf)
return w.parent.WriteTimeout(buf, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(buf, timeout) //nolint: wrapcheck
} }
func (w *wrapperObfuscated2) Write(p []byte) (int, error) { func (w *wrapperObfuscated2) Write(p []byte) (int, error) {
@@ -60,7 +60,7 @@ func (w *wrapperObfuscated2) Write(p []byte) (int, error) {
w.encryptor.XORKeyStream(buf, buf) w.encryptor.XORKeyStream(buf, buf)
return w.parent.Write(buf) // nolint: wrapcheck return w.parent.Write(buf) //nolint: wrapcheck
} }
func (w *wrapperObfuscated2) Conn() net.Conn { func (w *wrapperObfuscated2) Conn() net.Conn {
@@ -80,7 +80,7 @@ func (w *wrapperObfuscated2) RemoteAddr() *net.TCPAddr {
} }
func (w *wrapperObfuscated2) Close() error { func (w *wrapperObfuscated2) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func NewObfuscated2(socket conntypes.StreamReadWriteCloser, func NewObfuscated2(socket conntypes.StreamReadWriteCloser,
+5 -5
View File
@@ -24,25 +24,25 @@ type wrapperRewind struct {
} }
func (w *wrapperRewind) Write(p []byte) (int, error) { func (w *wrapperRewind) Write(p []byte) (int, error) {
return w.parent.Write(p) // nolint: wrapcheck return w.parent.Write(p) //nolint: wrapcheck
} }
func (w *wrapperRewind) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperRewind) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck
} }
func (w *wrapperRewind) Read(p []byte) (int, error) { func (w *wrapperRewind) Read(p []byte) (int, error) {
w.mutex.Lock() w.mutex.Lock()
defer w.mutex.Unlock() defer w.mutex.Unlock()
return w.activeReader.Read(p) // nolint: wrapcheck return w.activeReader.Read(p) //nolint: wrapcheck
} }
func (w *wrapperRewind) ReadTimeout(p []byte, _ time.Duration) (int, error) { func (w *wrapperRewind) ReadTimeout(p []byte, _ time.Duration) (int, error) {
w.mutex.Lock() w.mutex.Lock()
defer w.mutex.Unlock() defer w.mutex.Unlock()
return w.activeReader.Read(p) // nolint: wrapcheck return w.activeReader.Read(p) //nolint: wrapcheck
} }
func (w *wrapperRewind) Conn() net.Conn { func (w *wrapperRewind) Conn() net.Conn {
@@ -64,7 +64,7 @@ func (w *wrapperRewind) RemoteAddr() *net.TCPAddr {
func (w *wrapperRewind) Close() error { func (w *wrapperRewind) Close() error {
w.buf.Reset() w.buf.Reset()
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperRewind) Rewind() { func (w *wrapperRewind) Rewind() {
+5 -5
View File
@@ -17,19 +17,19 @@ type wrapperTelegramStats struct {
} }
func (w *wrapperTelegramStats) Write(p []byte) (int, error) { func (w *wrapperTelegramStats) Write(p []byte) (int, error) {
return w.parent.Write(p) // nolint: wrapcheck return w.parent.Write(p) //nolint: wrapcheck
} }
func (w *wrapperTelegramStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTelegramStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck
} }
func (w *wrapperTelegramStats) Read(p []byte) (int, error) { func (w *wrapperTelegramStats) Read(p []byte) (int, error) {
return w.parent.Read(p) // nolint: wrapcheck return w.parent.Read(p) //nolint: wrapcheck
} }
func (w *wrapperTelegramStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTelegramStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck return w.parent.ReadTimeout(p, timeout) //nolint: wrapcheck
} }
func (w *wrapperTelegramStats) Conn() net.Conn { func (w *wrapperTelegramStats) Conn() net.Conn {
@@ -56,7 +56,7 @@ func (w *wrapperTelegramStats) Close() error {
stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr()) stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
}) })
return err // nolint: wrapcheck return err //nolint: wrapcheck
} }
func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
+5 -5
View File
@@ -17,28 +17,28 @@ func (w *wrapperTrafficStats) Write(p []byte) (int, error) {
n, err := w.parent.Write(p) n, err := w.parent.Write(p)
stats.Stats.EgressTraffic(n) stats.Stats.EgressTraffic(n)
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.WriteTimeout(p, timeout) n, err := w.parent.WriteTimeout(p, timeout)
stats.Stats.EgressTraffic(n) stats.Stats.EgressTraffic(n)
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperTrafficStats) Read(p []byte) (int, error) { func (w *wrapperTrafficStats) Read(p []byte) (int, error) {
n, err := w.parent.Read(p) n, err := w.parent.Read(p)
stats.Stats.IngressTraffic(n) stats.Stats.IngressTraffic(n)
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.ReadTimeout(p, timeout) n, err := w.parent.ReadTimeout(p, timeout)
stats.Stats.IngressTraffic(n) stats.Stats.IngressTraffic(n)
return n, err // nolint: wrapcheck return n, err //nolint: wrapcheck
} }
func (w *wrapperTrafficStats) Conn() net.Conn { func (w *wrapperTrafficStats) Conn() net.Conn {
@@ -58,7 +58,7 @@ func (w *wrapperTrafficStats) RemoteAddr() *net.TCPAddr {
} }
func (w *wrapperTrafficStats) Close() error { func (w *wrapperTrafficStats) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func NewTrafficStats(parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { func NewTrafficStats(parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
+5 -5
View File
@@ -18,23 +18,23 @@ type wrapperTimeout struct {
} }
func (w *wrapperTimeout) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTimeout) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck
} }
func (w *wrapperTimeout) Write(p []byte) (int, error) { func (w *wrapperTimeout) Write(p []byte) (int, error) {
return w.parent.WriteTimeout(p, timeoutWrite) // nolint: wrapcheck return w.parent.WriteTimeout(p, timeoutWrite) //nolint: wrapcheck
} }
func (w *wrapperTimeout) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTimeout) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck return w.parent.ReadTimeout(p, timeout) //nolint: wrapcheck
} }
func (w *wrapperTimeout) Read(p []byte) (int, error) { func (w *wrapperTimeout) Read(p []byte) (int, error) {
return w.parent.ReadTimeout(p, timeoutRead) // nolint: wrapcheck return w.parent.ReadTimeout(p, timeoutRead) //nolint: wrapcheck
} }
func (w *wrapperTimeout) Close() error { func (w *wrapperTimeout) Close() error {
return w.parent.Close() // nolint: wrapcheck return w.parent.Close() //nolint: wrapcheck
} }
func (w *wrapperTimeout) Conn() net.Conn { func (w *wrapperTimeout) Conn() net.Conn {