diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 075e662..b2fdfbf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,7 +30,7 @@ jobs: strategy: matrix: go_version: - - ^1.18 + - ^1.19 steps: - name: Checkout uses: actions/checkout@v2 @@ -70,7 +70,7 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.45.0 + version: v1.48.0 docker: name: Docker diff --git a/.golangci.toml b/.golangci.toml index a595c75..e10d80f 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -9,4 +9,14 @@ format = "colored-line-number" [linters] enable-all = true -disable = ["thelper", "ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"] +disable = [ + "containedctx", + "exhaustivestruct", + "exhaustruct", + "gas", + "gochecknoglobals", + "goerr113", + "ireturn", + "thelper", + "varnamelen", +] diff --git a/Dockerfile b/Dockerfile index 93fe091..9ac41a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ############################################################################### # BUILD STAGE -FROM golang:1.18-alpine AS build +FROM golang:1.19-alpine AS build RUN set -x \ && apk --no-cache --update add \ diff --git a/Makefile b/Makefile index 4b5491e..ee19ee5 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) IMAGE_NAME := mtg APP_NAME := $(IMAGE_NAME) -GOLANGCI_LINT_VERSION := v1.45.0 +GOLANGCI_LINT_VERSION := v1.48.0 VERSION_GO := $(shell go version) VERSION_DATE := $(shell date -Ru) diff --git a/cli/proxy.go b/cli/proxy.go index 038239e..fea8a82 100644 --- a/cli/proxy.go +++ b/cli/proxy.go @@ -19,7 +19,7 @@ import ( "go.uber.org/zap/zapcore" ) -func Proxy() error { // nolint: funlen,cyclop +func Proxy() error { //nolint: funlen,cyclop ctx := utils.GetSignalContext() atom := zap.NewAtomicLevel() @@ -41,7 +41,7 @@ func Proxy() error { // nolint: funlen,cyclop )) zap.ReplaceGlobals(logger) - defer logger.Sync() // nolint: errcheck + defer logger.Sync() //nolint: errcheck if err := config.InitPublicAddress(ctx); err != nil { Fatal(err) diff --git a/cli/utils.go b/cli/utils.go index 948d875..59e5368 100644 --- a/cli/utils.go +++ b/cli/utils.go @@ -9,7 +9,7 @@ import ( func Fatal(arg interface{}) { 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) @@ -21,7 +21,7 @@ func PrintStderr(args ...interface{}) { } func PrintStdout(args ...interface{}) { - fmt.Println(args...) // nolint: forbidigo + fmt.Println(args...) //nolint: forbidigo } func PrintJSONStderr(data interface{}) { diff --git a/config/config.go b/config/config.go index ab8c2f2..8f9d6ed 100644 --- a/config/config.go +++ b/config/config.go @@ -79,29 +79,29 @@ const ( type Config struct { Bind *net.TCPAddr `json:"bind"` - PublicIPv4 *net.TCPAddr `json:"public_ipv4"` // nolint: tagliatelle - PublicIPv6 *net.TCPAddr `json:"public_ipv6"` // nolint: tagliatelle - StatsBind *net.TCPAddr `json:"stats_bind"` // nolint: tagliatelle - StatsdAddr *net.TCPAddr `json:"stats_addr"` // nolint: tagliatelle - StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` // nolint: tagliatelle + PublicIPv4 *net.TCPAddr `json:"public_ipv4"` //nolint: tagliatelle + PublicIPv6 *net.TCPAddr `json:"public_ipv6"` //nolint: tagliatelle + StatsBind *net.TCPAddr `json:"stats_bind"` //nolint: tagliatelle + StatsdAddr *net.TCPAddr `json:"stats_addr"` //nolint: tagliatelle + StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` //nolint: tagliatelle - StatsNamespace string `json:"stats_namespace"` // nolint: tagliatelle - CloakHost string `json:"cloak_host"` // nolint: tagliatelle - StatsdTags map[string]string `json:"statsd_tags"` // nolint: tagliatelle + StatsNamespace string `json:"stats_namespace"` //nolint: tagliatelle + CloakHost string `json:"cloak_host"` //nolint: tagliatelle + StatsdTags map[string]string `json:"statsd_tags"` //nolint: tagliatelle - WriteBuffer int `json:"write_buffer"` // nolint: tagliatelle - ReadBuffer int `json:"read_buffer"` // nolint: tagliatelle - CloakPort int `json:"cloak_port"` // nolint: tagliatelle + WriteBuffer int `json:"write_buffer"` //nolint: tagliatelle + ReadBuffer int `json:"read_buffer"` //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"` Verbose bool `json:"verbose"` - SecretMode SecretMode `json:"secret_mode"` // nolint: tagliatelle - PreferIP PreferIP `json:"prefer_ip"` // nolint: tagliatelle - NTPServers []string `json:"ntp_servers"` // nolint: tagliatelle + SecretMode SecretMode `json:"secret_mode"` //nolint: tagliatelle + PreferIP PreferIP `json:"prefer_ip"` //nolint: tagliatelle + NTPServers []string `json:"ntp_servers"` //nolint: tagliatelle Secret []byte `json:"secret"` AdTag []byte `json:"adtag"` @@ -146,7 +146,7 @@ func (c *Config) adjustProxyValue(value int) int { 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.Max(fvalue, newValue) @@ -160,15 +160,15 @@ type Opt struct { 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 { switch opt.Option { case OptionTypeDebug: - C.Debug = opt.Value.(bool) // nolint: forcetypeassert + C.Debug = opt.Value.(bool) //nolint: forcetypeassert case OptionTypeVerbose: - C.Verbose = opt.Value.(bool) // nolint: forcetypeassert + C.Verbose = opt.Value.(bool) //nolint: forcetypeassert case OptionTypePreferIP: - value := opt.Value.(string) // nolint: forcetypeassert + value := opt.Value.(string) //nolint: forcetypeassert switch value { case "ipv4": 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) } case OptionTypeBind: - C.Bind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert + C.Bind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert case OptionTypePublicIPv4: - C.PublicIPv4 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert + C.PublicIPv4 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert if C.PublicIPv4 == nil { C.PublicIPv4 = &net.TCPAddr{} } case OptionTypePublicIPv6: - C.PublicIPv6 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert + C.PublicIPv6 = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert if C.PublicIPv6 == nil { C.PublicIPv6 = &net.TCPAddr{} } case OptionTypeStatsBind: - C.StatsBind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert + C.StatsBind = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert case OptionTypeStatsNamespace: - C.StatsNamespace = opt.Value.(string) // nolint: forcetypeassert + C.StatsNamespace = opt.Value.(string) //nolint: forcetypeassert case OptionTypeStatsdAddress: - C.StatsdAddr = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert + C.StatsdAddr = opt.Value.(*net.TCPAddr) //nolint: forcetypeassert case OptionTypeStatsdTagsFormat: - value := opt.Value.(string) // nolint: forcetypeassert + value := opt.Value.(string) //nolint: forcetypeassert switch value { case "datadog": 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) } case OptionTypeStatsdTags: - C.StatsdTags = opt.Value.(map[string]string) // nolint: forcetypeassert + C.StatsdTags = opt.Value.(map[string]string) //nolint: forcetypeassert case OptionTypeWriteBufferSize: - C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert + C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert case OptionTypeReadBufferSize: - C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert + C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert case OptionTypeCloakPort: - C.CloakPort = int(opt.Value.(uint16)) // nolint: forcetypeassert + C.CloakPort = int(opt.Value.(uint16)) //nolint: forcetypeassert case OptionTypeAntiReplayMaxSize: - C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert + C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) //nolint: forcetypeassert case OptionTypeMultiplexPerConnection: - C.MultiplexPerConnection = int(opt.Value.(uint)) // nolint: forcetypeassert + C.MultiplexPerConnection = int(opt.Value.(uint)) //nolint: forcetypeassert case OptionTypeNTPServers: - C.NTPServers = opt.Value.([]string) // nolint: forcetypeassert + C.NTPServers = opt.Value.([]string) //nolint: forcetypeassert if len(C.NTPServers) == 0 { return errors.New("ntp server list is empty") } case OptionTypeSecret: - C.Secret = opt.Value.([]byte) // nolint: forcetypeassert + C.Secret = opt.Value.([]byte) //nolint: forcetypeassert case OptionTypeAdtag: - C.AdTag = opt.Value.([]byte) // nolint: forcetypeassert + C.AdTag = opt.Value.([]byte) //nolint: forcetypeassert default: return fmt.Errorf("unknown tag %v", opt.Option) } diff --git a/config/global_ips.go b/config/global_ips.go index c5564ea..089073d 100644 --- a/config/global_ips.go +++ b/config/global_ips.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "strings" @@ -41,12 +40,12 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) { Timeout: ifconfigTimeout, Transport: &http.Transport{ 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 { 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)) if err != 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) @@ -62,7 +61,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) { defer resp.Body.Close() - respDataBytes, err := ioutil.ReadAll(resp.Body) + respDataBytes, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("cannot read response body: %w", err) } diff --git a/config/urls.go b/config/urls.go index c5a9a58..01d46c0 100644 --- a/config/urls.go +++ b/config/urls.go @@ -8,20 +8,21 @@ import ( ) type URLs struct { - TG string `json:"tg_url"` // nolint: tagliatelle - TMe string `json:"tme_url"` // nolint: tagliatelle - TGQRCode string `json:"tg_qrcode"` // nolint: tagliatelle - TMeQRCode string `json:"tme_qrcode"` // nolint: tagliatelle + TG string `json:"tg_url"` //nolint: tagliatelle + TMe string `json:"tme_url"` //nolint: tagliatelle + TGQRCode string `json:"tg_qrcode"` //nolint: tagliatelle + TMeQRCode string `json:"tme_qrcode"` //nolint: tagliatelle } type IPURLs struct { IPv4 *URLs `json:"ipv4,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 := "" + urls := IPURLs{} switch C.SecretMode { case SecretModeSimple: diff --git a/faketls/client_protocol.go b/faketls/client_protocol.go index 8208ac0..5b2aa3d 100644 --- a/faketls/client_protocol.go +++ b/faketls/client_protocol.go @@ -52,10 +52,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn conn, err := c.ClientProtocol.Handshake(conn) 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 { diff --git a/faketls/cloak.go b/faketls/cloak.go index fb9f5e4..4ec9e57 100644 --- a/faketls/cloak.go +++ b/faketls/cloak.go @@ -26,7 +26,7 @@ func cloak(one, another io.ReadWriteCloser) { another = rwc.NewPing(ctx, another, channelPing) wg := &sync.WaitGroup{} - wg.Add(2) // nolint: gomnd + wg.Add(2) //nolint: gomnd 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) { defer wg.Done() - io.Copy(one, another) // nolint: errcheck + io.Copy(one, another) //nolint: errcheck } diff --git a/go.mod b/go.mod index 6ccc39b..f024c3f 100644 --- a/go.mod +++ b/go.mod @@ -14,8 +14,8 @@ require ( go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.21.0 golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd - golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect - golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 + golang.org/x/net v0.0.0-20220809012201-f428fae20770 // indirect + golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 google.golang.org/protobuf v1.27.1 // indirect gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) @@ -27,5 +27,8 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // 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 + golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/tools v0.1.12 // indirect ) diff --git a/go.sum b/go.sum index 4fb6cc2..bee1449 100644 --- a/go.sum +++ b/go.sum @@ -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.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 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.3.0/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-20180826012351-8a410e7b638d/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-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= 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-20190226205417-e64efc72b421/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-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-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/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= @@ -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-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 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-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/hub/connection.go b/hub/connection.go index e96cae9..6813724 100644 --- a/hub/connection.go +++ b/hub/connection.go @@ -30,7 +30,7 @@ type connection struct { channelConnDetach chan conntypes.ConnID } -func (c *connection) run() { // nolint: cyclop +func (c *connection) run() { //nolint: cyclop defer c.Close() 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) } - id := rand.Int() // nolint: gosec + id := rand.Int() //nolint: gosec rv := &connection{ conn: conn, id: id, diff --git a/hub/hub.go b/hub/hub.go index 3be2560..692d07f 100644 --- a/hub/hub.go +++ b/hub/hub.go @@ -18,7 +18,7 @@ func (h *hub) Register(req *protocol.TelegramRequest) (*ProxyConn, error) { } 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() m, ok := h.muxes[key] diff --git a/main.go b/main.go index b16f040..8415567 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "github.com/9seconds/mtg/cli" "github.com/9seconds/mtg/config" - "github.com/9seconds/mtg/utils" kingpin "gopkg.in/alecthomas/kingpin.v2" ) @@ -128,10 +127,6 @@ func main() { app.Version(getVersion()) app.HelpFlag.Short('h') - if err := utils.SetLimits(); err != nil { - cli.Fatal(err) - } - switch kingpin.MustParse(app.Parse(os.Args[1:])) { case generateSecretCommand.FullCommand(): cli.Generate(*generateSecretType, *generateCloakHost) diff --git a/mtproto/protocol.go b/mtproto/protocol.go index a880d10..4dda520 100644 --- a/mtproto/protocol.go +++ b/mtproto/protocol.go @@ -51,7 +51,7 @@ func doRPCNonceRequest(conn conntypes.BasePacketWriter) (*rpc.NonceRequest, erro } if err := conn.Write(rpcNonceReq.Bytes()); err != nil { - return nil, err // nolint: wrapcheck + return nil, err //nolint: wrapcheck } return rpcNonceReq, nil diff --git a/mtproto/rpc/handshake_response.go b/mtproto/rpc/handshake_response.go index 8eed5c5..e256534 100644 --- a/mtproto/rpc/handshake_response.go +++ b/mtproto/rpc/handshake_response.go @@ -41,7 +41,7 @@ func (r *HandshakeResponse) Valid() error { // NewHandshakeResponse constructs new handshake response from the given // data. 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)) } diff --git a/mtproto/rpc/nonce_request.go b/mtproto/rpc/nonce_request.go index 393b30c..99024b3 100644 --- a/mtproto/rpc/nonce_request.go +++ b/mtproto/rpc/nonce_request.go @@ -29,9 +29,9 @@ func (r *NonceRequest) Bytes() []byte { // NewNonceRequest builds new none request based on proxy secret. func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) { - nonce := make([]byte, 16) // nolint: gomnd - keySelector := make([]byte, 4) // nolint: gomnd - cryptoTS := make([]byte, 4) // nolint: gomnd + nonce := make([]byte, 16) //nolint: gomnd + keySelector := make([]byte, 4) //nolint: gomnd + cryptoTS := make([]byte, 4) //nolint: gomnd if _, err := rand.Read(nonce); err != nil { return nil, fmt.Errorf("cannot generate nonce: %w", err) @@ -39,7 +39,7 @@ func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) { copy(keySelector, proxySecret) // 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)) return &NonceRequest{ diff --git a/mtproto/rpc/nonce_response.go b/mtproto/rpc/nonce_response.go index 2b0a96c..f98291e 100644 --- a/mtproto/rpc/nonce_response.go +++ b/mtproto/rpc/nonce_response.go @@ -44,7 +44,7 @@ func (r *NonceResponse) Valid(req *NonceRequest) error { // NewNonceResponse build new nonce response based on the given data. 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)) } diff --git a/mtproto/rpc/proxy_flags.go b/mtproto/rpc/proxy_flags.go index 995d55e..1ec70a1 100644 --- a/mtproto/rpc/proxy_flags.go +++ b/mtproto/rpc/proxy_flags.go @@ -21,14 +21,14 @@ const ( var ProxyRequestFlagsEncryptedPrefix [8]byte func (r ProxyRequestFlags) Bytes() []byte { - converted := make([]byte, 4) // nolint: gomnd + converted := make([]byte, 4) //nolint: gomnd binary.LittleEndian.PutUint32(converted, uint32(r)) return converted } func (r ProxyRequestFlags) String() string { - flags := make([]string, 0, 7) // nolint: gomnd + flags := make([]string, 0, 7) //nolint: gomnd if r&ProxyRequestFlagsHasAdTag != 0 { flags = append(flags, "HAS_AD_TAG") diff --git a/mtproto/rpc/proxy_response.go b/mtproto/rpc/proxy_response.go index f00361c..3638ae6 100644 --- a/mtproto/rpc/proxy_response.go +++ b/mtproto/rpc/proxy_response.go @@ -24,7 +24,7 @@ type ProxyResponse struct { func ParseProxyResponse(packet conntypes.Packet) (*ProxyResponse, error) { 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)) } diff --git a/ntp/ntp.go b/ntp/ntp.go index 97d5d63..0703be5 100644 --- a/ntp/ntp.go +++ b/ntp/ntp.go @@ -14,7 +14,7 @@ const autoUpdatePeriod = time.Minute // Fetch fetches the data on time drift. 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) if err != nil { diff --git a/obfuscated2/client_protocol.go b/obfuscated2/client_protocol.go index e7a6ff6..50aa11a 100644 --- a/obfuscated2/client_protocol.go +++ b/obfuscated2/client_protocol.go @@ -93,12 +93,14 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn return stream.NewObfuscated2(socket, encryptor, decryptor), nil } -func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (fm Frame, err error) { - if _, err = io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil { - err = fmt.Errorf("cannot extract obfuscated2 frame: %w", err) +func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (Frame, error) { + fm := Frame{} + + 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 { @@ -106,7 +108,7 @@ type handshakeReader struct { } 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 { diff --git a/obfuscated2/frame.go b/obfuscated2/frame.go index e05cbd0..a83ae98 100644 --- a/obfuscated2/frame.go +++ b/obfuscated2/frame.go @@ -44,11 +44,11 @@ func (f *Frame) Unique() []byte { return f.data[frameOffsetFirst:frameOffsetDC] } -func (f *Frame) Invert() (nf Frame) { - nf = *f +func (f *Frame) Invert() Frame { + nf := *f for i := 0; i < frameLenKey+frameLenIV; i++ { nf.data[frameOffsetFirst+i] = f.data[frameOffsetIV-1-i] } - return + return nf } diff --git a/obfuscated2/telegram_protocol.go b/obfuscated2/telegram_protocol.go index ce25730..6bb99ab 100644 --- a/obfuscated2/telegram_protocol.go +++ b/obfuscated2/telegram_protocol.go @@ -39,7 +39,8 @@ func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteC 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() for { @@ -47,22 +48,22 @@ func generateFrame(cp protocol.ClientProtocol) (fm Frame) { continue } - if data[0] == 0xef { // nolint: gomnd + if data[0] == 0xef { //nolint: gomnd continue } - 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 + 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 continue } - val = (uint32(data[7]) << 24) | (uint32(data[6]) << 16) | (uint32(data[5]) << 8) | uint32(data[4]) // nolint: gomnd - if val == 0x00000000 { // 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 continue } copy(fm.Magic(), cp.ConnectionType().Tag()) - return + return fm } } diff --git a/proxy/direct.go b/proxy/direct.go index 981ad2a..18bc4a8 100644 --- a/proxy/direct.go +++ b/proxy/direct.go @@ -14,13 +14,13 @@ const directPipeBufferSize = 1024 func directConnection(request *protocol.TelegramRequest) error { telegramConnRaw, err := obfuscated2.TelegramProtocol(request) if err != nil { - return err // nolint: wrapcheck + return err //nolint: wrapcheck } defer telegramConnRaw.Close() wg := &sync.WaitGroup{} - wg.Add(2) // nolint: gomnd + wg.Add(2) //nolint: gomnd go directPipe(telegramConnRaw, request.ClientConn, wg, request.Logger) diff --git a/proxy/middle.go b/proxy/middle.go index ce83238..5c4d715 100644 --- a/proxy/middle.go +++ b/proxy/middle.go @@ -32,7 +32,7 @@ func middleConnection(request *protocol.TelegramRequest) { } wg := &sync.WaitGroup{} - wg.Add(2) // nolint: gomnd + wg.Add(2) //nolint: gomnd go middlePipe(telegramConn, clientConn, wg, request.Logger) diff --git a/stats/stats.go b/stats/stats.go index f856148..7f54320 100644 --- a/stats/stats.go +++ b/stats/stats.go @@ -28,11 +28,11 @@ func Init(ctx context.Context) error { Handler: mux, } - go srv.Serve(listener) // nolint: errcheck + go srv.Serve(listener) //nolint: errcheck go func() { <-ctx.Done() - srv.Shutdown(context.Background()) // nolint: errcheck, contextcheck + srv.Shutdown(context.Background()) //nolint: errcheck }() Stats = multiStats(stats) diff --git a/stats/stats_statsd.go b/stats/stats_statsd.go index 9f12153..70009aa 100644 --- a/stats/stats_statsd.go +++ b/stats/stats_statsd.go @@ -83,7 +83,7 @@ func (s *statsStatsd) ClientDisconnected(connectionType conntypes.ConnectionType } 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 { case conntypes.ConnectionTypeAbridged: @@ -172,7 +172,7 @@ func (s *statsStatsd) initGauge(metric, key string, tags []statsd.Tag) { s.seenMutex.RUnlock() return - } else { // nolint: golint,revive + } else { //nolint: golint,revive s.seenMutex.RUnlock() } @@ -194,8 +194,8 @@ func newStatsStatsd() Interface { return &statsStatsd{ seen: make(map[string]struct{}), client: statsd.NewClient(config.C.StatsdAddr.String(), - statsd.SendLoopCount(2), // nolint: gomnd - statsd.ReconnectInterval(10*time.Second), // nolint: gomnd + statsd.SendLoopCount(2), //nolint: gomnd + statsd.ReconnectInterval(10*time.Second), //nolint: gomnd statsd.Logger(logger), statsd.MetricPrefix(prefix), statsd.TagStyle(config.C.StatsdTagsFormat), diff --git a/telegram/api/addresses.go b/telegram/api/addresses.go index a6737e3..8a56518 100644 --- a/telegram/api/addresses.go +++ b/telegram/api/addresses.go @@ -12,8 +12,8 @@ import ( ) const ( - addressesURLV4 = "https://core.telegram.org/getProxyConfig" // nolint: gas - addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" // nolint: gas + addressesURLV4 = "https://core.telegram.org/getProxyConfig" //nolint: gas + addressesURLV6 = "https://core.telegram.org/getProxyConfigV6" //nolint: gas ) 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) { - chunks := addressesProxyForSplitter.Split(text, 3) // nolint: gomnd + chunks := addressesProxyForSplitter.Split(text, 3) //nolint: gomnd if len(chunks) != 3 || chunks[0] != "proxy_for" { 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 { 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) { - chunks := addressesProxyForSplitter.Split(text, 2) // nolint: gomnd + chunks := addressesProxyForSplitter.Split(text, 2) //nolint: gomnd if len(chunks) != 2 || chunks[0] != "default" { return 0, fmt.Errorf("incorrect config '%s'", text) } 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 { return 0, fmt.Errorf("incorrect config '%s': %w", text, err) } diff --git a/telegram/api/api.go b/telegram/api/api.go index 7cdef71..e68a532 100644 --- a/telegram/api/api.go +++ b/telegram/api/api.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net/http" "time" ) @@ -22,7 +21,7 @@ func request(url string) (io.ReadCloser, error) { ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout) defer cancel() - req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { panic(err) } @@ -33,12 +32,12 @@ func request(url string) (io.ReadCloser, error) { resp, err := httpClient.Do(req) if err != nil { if resp != nil { - io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck + io.Copy(io.Discard, resp.Body) //nolint: errcheck resp.Body.Close() } return nil, fmt.Errorf("cannot perform a request: %w", err) } - return resp.Body, err // nolint: wrapcheck + return resp.Body, err //nolint: wrapcheck } diff --git a/telegram/api/secret.go b/telegram/api/secret.go index c5a1137..ed574e4 100644 --- a/telegram/api/secret.go +++ b/telegram/api/secret.go @@ -2,10 +2,10 @@ package api import ( "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) { resp, err := request(secretURL) @@ -15,7 +15,7 @@ func Secret() ([]byte, error) { defer resp.Close() - secret, err := ioutil.ReadAll(resp) + secret, err := io.ReadAll(resp) if err != nil { return nil, fmt.Errorf("cannot read response: %w", err) } diff --git a/telegram/base.go b/telegram/base.go index f741c9a..7f508e7 100644 --- a/telegram/base.go +++ b/telegram/base.go @@ -51,7 +51,7 @@ func (b *baseTelegram) dial(dc conntypes.DC, } 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{ conntypes.ConnectionProtocolIPv6, conntypes.ConnectionProtocolIPv4, @@ -86,7 +86,7 @@ func (b *baseTelegram) chooseAddress(addresses map[conntypes.DC][]string, case len(addrs) == 1: return addrs[0] case len(addrs) > 1: - return addrs[rand.Intn(len(addrs))] // nolint: gosec + return addrs[rand.Intn(len(addrs))] //nolint: gosec } return "" diff --git a/tlstypes/consts.go b/tlstypes/consts.go index 79d5a10..7ee8f29 100644 --- a/tlstypes/consts.go +++ b/tlstypes/consts.go @@ -20,22 +20,22 @@ const ( type CipherSuiteType uint8 const ( - CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint,revive - CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint,revive - CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // 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,nosnakecase + CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 //nolint: stylecheck,golint,revive,nosnakecase ) func (c CipherSuiteType) Bytes() []byte { switch c { - case CipherSuiteType_TLS_AES_128_GCM_SHA256: - return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes - case CipherSuiteType_TLS_AES_256_GCM_SHA384: - return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes - case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256: - return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes + case CipherSuiteType_TLS_AES_128_GCM_SHA256: //nolint: nosnakecase + return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes //nolint: nosnakecase + case CipherSuiteType_TLS_AES_256_GCM_SHA384: //nolint: nosnakecase + return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes //nolint: nosnakecase + case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256: //nolint: nosnakecase + 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 @@ -69,9 +69,9 @@ var ( Version12Bytes = []byte{0x03, 0x03} Version13Bytes = []byte{0x03, 0x04} - CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint,revive - CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint,revive - CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // 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,nosnakecase + CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} //nolint: stylecheck,golint,revive,nosnakecase ) type Byter interface { @@ -82,7 +82,7 @@ type Byter interface { type RawBytes []byte func (r RawBytes) WriteBytes(writer io.Writer) { - writer.Write(r) // nolint: errcheck + writer.Write(r) //nolint: errcheck } func (r RawBytes) Len() int { diff --git a/tlstypes/handshake.go b/tlstypes/handshake.go index 3775b45..a91e251 100644 --- a/tlstypes/handshake.go +++ b/tlstypes/handshake.go @@ -18,7 +18,7 @@ type Handshake struct { func (h *Handshake) WriteBytes(writer io.Writer) { 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.Random[:]) @@ -30,8 +30,8 @@ func (h *Handshake) WriteBytes(writer io.Writer) { sizeUint24Bytes := sizeUint24[:] sizeUint24Bytes[0], sizeUint24Bytes[2] = sizeUint24Bytes[2], sizeUint24Bytes[0] - writer.Write(sizeUint24Bytes) // nolint: errcheck - packetBuf.WriteTo(writer) // nolint: errcheck + writer.Write(sizeUint24Bytes) //nolint: errcheck + packetBuf.WriteTo(writer) //nolint: errcheck } func (h *Handshake) Len() int { diff --git a/tlstypes/record.go b/tlstypes/record.go index 5dae77e..c84d647 100644 --- a/tlstypes/record.go +++ b/tlstypes/record.go @@ -16,9 +16,9 @@ type Record struct { } func (r Record) WriteBytes(writer io.Writer) { - writer.Write([]byte{byte(r.Type)}) // nolint: errcheck - writer.Write(r.Version.Bytes()) // nolint: errcheck - binary.Write(writer, binary.BigEndian, uint16(r.Data.Len())) // nolint: errcheck + writer.Write([]byte{byte(r.Type)}) //nolint: errcheck + writer.Write(r.Version.Bytes()) //nolint: errcheck + binary.Write(writer, binary.BigEndian, uint16(r.Data.Len())) //nolint: errcheck r.Data.WriteBytes(writer) } @@ -65,7 +65,9 @@ func ReadRecord(reader io.Reader) (Record, error) { return rec, nil } -func MakeRecords(raw []byte) (arr []Record) { +func MakeRecords(raw []byte) []Record { + var arr []Record + for len(raw) > 0 { chunkSize := recordMaxChunkSize if chunkSize > len(raw) { @@ -80,5 +82,5 @@ func MakeRecords(raw []byte) (arr []Record) { raw = raw[chunkSize:] } - return + return arr } diff --git a/tlstypes/server_hello.go b/tlstypes/server_hello.go index be5cca1..4f17154 100644 --- a/tlstypes/server_hello.go +++ b/tlstypes/server_hello.go @@ -36,8 +36,8 @@ func (s ServerHello) WelcomePacket() []byte { } recChangeCipher.WriteBytes(buf) - hostCert := make([]byte, 1024+mrand.Intn(3092)) // nolint: gosec, gomnd - rand.Read(hostCert) // nolint: errcheck + hostCert := make([]byte, 1024+mrand.Intn(3092)) //nolint: gosec, gomnd + rand.Read(hostCert) //nolint: errcheck recData := Record{ Type: RecordTypeApplicationData, @@ -66,8 +66,8 @@ func NewServerHello(clientHello *ClientHello) *ServerHello { rv.SessionID = make([]byte, len(clientHello.SessionID)) copy(rv.SessionID, clientHello.SessionID) - tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes) - tail.WriteByte(0x00) // nolint: gomnd // no compression + tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes) //nolint: nosnakecase + tail.WriteByte(0x00) //nolint: gomnd // no compression makeTLSExtensions(tail) rv.Tail = RawBytes(tail.Bytes()) @@ -75,7 +75,7 @@ func NewServerHello(clientHello *ClientHello) *ServerHello { } func makeTLSExtensions(buf io.Writer) { - buf.Write([]byte{ // nolint: errcheck + buf.Write([]byte{ //nolint: errcheck 0x00, 0x2e, // 46 bytes of data 0x00, 0x33, // Extension - Key Share 0x00, 0x24, // 36 bytes @@ -85,11 +85,11 @@ func makeTLSExtensions(buf io.Writer) { var scalar [32]byte - rand.Read(scalar[:]) // nolint: errcheck + rand.Read(scalar[:]) //nolint: errcheck 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, 0x02, // 2 bytes are following 0x03, 0x04, // TLS 1.3 diff --git a/utils/init_tcp.go b/utils/init_tcp.go index 69dc67d..63be798 100644 --- a/utils/init_tcp.go +++ b/utils/init_tcp.go @@ -6,7 +6,7 @@ import ( ) 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 { return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err) diff --git a/utils/read_full.go b/utils/read_full.go index 1a86ab1..41cbdcf 100644 --- a/utils/read_full.go +++ b/utils/read_full.go @@ -4,14 +4,15 @@ import "io" 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) n := readFullBufferSize + rv := []byte{} for n == len(buf) { - n, err = src.Read(buf) + n, err := src.Read(buf) if err != nil { - return nil, err // nolint: wrapcheck + return nil, err //nolint: wrapcheck } rv = append(rv, buf[:n]...) diff --git a/utils/reverse_bytes.go b/utils/reverse_bytes.go index d1a9496..d770fc3 100644 --- a/utils/reverse_bytes.go +++ b/utils/reverse_bytes.go @@ -6,7 +6,7 @@ func ReverseBytes(data []byte) []byte { rv := make([]byte, dataLen) 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 rv[i], rv[opp] = data[opp], data[i] } diff --git a/utils/rlimit.go b/utils/rlimit.go deleted file mode 100644 index 82fbb1e..0000000 --- a/utils/rlimit.go +++ /dev/null @@ -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 -} diff --git a/utils/uint24.go b/utils/uint24.go index cf7516c..cb12ece 100644 --- a/utils/uint24.go +++ b/utils/uint24.go @@ -3,9 +3,9 @@ package utils type Uint24 [3]byte 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 { - 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 } diff --git a/wrappers/packet/mtproto_frame.go b/wrappers/packet/mtproto_frame.go index 79050b3..308f29f 100644 --- a/wrappers/packet/mtproto_frame.go +++ b/wrappers/packet/mtproto_frame.go @@ -7,7 +7,6 @@ import ( "fmt" "hash/crc32" "io" - "io/ioutil" "net" "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. // 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 // CRC32 is the CRC32 checksum of MSGLEN + SEQNO + MSG // PADDING is custom padding schema to complete frame length to such that -// len(frame) % 16 == 0 +// +// len(frame) % 16 == 0 type wrapperMtprotoFrame struct { parent conntypes.StreamReadWriteCloser logger *zap.SugaredLogger @@ -40,7 +42,7 @@ type wrapperMtprotoFrame struct { 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{} sum := crc32.NewIEEE() @@ -50,7 +52,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl buf.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) } @@ -72,23 +74,23 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl 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) } var seqNo int32 - binary.Read(buf, binary.LittleEndian, &seqNo) // nolint: errcheck + binary.Read(buf, binary.LittleEndian, &seqNo) //nolint: errcheck if 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() // write to buf, not to writer. This is because we are going to fetch // 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) } @@ -109,18 +111,18 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl } 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 buf := &bytes.Buffer{} - binary.Write(buf, binary.LittleEndian, uint32(messageLength)) // nolint: errcheck - binary.Write(buf, binary.LittleEndian, w.writeSeqNo) // nolint: errcheck + binary.Write(buf, binary.LittleEndian, uint32(messageLength)) //nolint: errcheck + binary.Write(buf, binary.LittleEndian, w.writeSeqNo) //nolint: errcheck buf.Write(p) checksum := crc32.ChecksumIEEE(buf.Bytes()) - binary.Write(buf, binary.LittleEndian, checksum) // nolint: errcheck - buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) // nolint: gomnd + binary.Write(buf, binary.LittleEndian, checksum) //nolint: errcheck + buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) //nolint: gomnd w.logger.Debugw("Write MTProto frame", "length", len(p), @@ -132,11 +134,11 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error { _, err := w.parent.Write(buf.Bytes()) - return err // nolint: wrapcheck + return err //nolint: wrapcheck } func (w *wrapperMtprotoFrame) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperMtprotoFrame) Conn() net.Conn { diff --git a/wrappers/packetack/client_abridged.go b/wrappers/packetack/client_abridged.go index 054a559..10c034e 100644 --- a/wrappers/packetack/client_abridged.go +++ b/wrappers/packetack/client_abridged.go @@ -39,9 +39,9 @@ func (w *wrapperClientAbridged) Read(acks *conntypes.ConnectionAcks) (conntypes. } 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) } @@ -75,7 +75,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C return nil } - packetLength := len(packet) / 4 // nolint: gomnd + packetLength := len(packet) / 4 //nolint: gomnd switch { case packetLength < clientAbridgedSmallPacketLength: @@ -104,7 +104,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C } func (w *wrapperClientAbridged) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperClientAbridged) Conn() net.Conn { diff --git a/wrappers/packetack/client_intermediate.go b/wrappers/packetack/client_intermediate.go index fb51ad1..ea7b615 100644 --- a/wrappers/packetack/client_intermediate.go +++ b/wrappers/packetack/client_intermediate.go @@ -20,9 +20,9 @@ type wrapperClientIntermediate struct { func (w *wrapperClientIntermediate) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) { 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) } @@ -63,7 +63,7 @@ func (w *wrapperClientIntermediate) Write(packet conntypes.Packet, acks *conntyp } func (w *wrapperClientIntermediate) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperClientIntermediate) Conn() net.Conn { diff --git a/wrappers/packetack/client_intermediate_secure.go b/wrappers/packetack/client_intermediate_secure.go index aa7085a..d9f2729 100644 --- a/wrappers/packetack/client_intermediate_secure.go +++ b/wrappers/packetack/client_intermediate_secure.go @@ -20,7 +20,7 @@ func (w *wrapperClientIntermediateSecure) Read(acks *conntypes.ConnectionAcks) ( return nil, err } - length := len(data) - (len(data) % 4) // nolint: gomnd + length := len(data) - (len(data) % 4) //nolint: gomnd return data[:length], nil } @@ -35,11 +35,11 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c } buf := &bytes.Buffer{} - paddingLength := rand.Intn(4) // nolint: gosec, gomnd + paddingLength := rand.Intn(4) //nolint: gosec, gomnd 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(make([]byte, paddingLength)) diff --git a/wrappers/packetack/proxy.go b/wrappers/packetack/proxy.go index 9426fd8..3850eda 100644 --- a/wrappers/packetack/proxy.go +++ b/wrappers/packetack/proxy.go @@ -42,11 +42,11 @@ func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.Connection buf.Write(rpc.ProxyRequestProxyTag) buf.WriteByte(byte(len(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.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) { diff --git a/wrappers/rwc/ping.go b/wrappers/rwc/ping.go index 6ac5fc8..2f0f22e 100644 --- a/wrappers/rwc/ping.go +++ b/wrappers/rwc/ping.go @@ -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) { @@ -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 { - 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 { diff --git a/wrappers/stream/blockcipher.go b/wrappers/stream/blockcipher.go index 19582c8..9d46efe 100644 --- a/wrappers/stream/blockcipher.go +++ b/wrappers/stream/blockcipher.go @@ -26,7 +26,7 @@ func (w *wrapperBlockCipher) Write(p []byte) (int, error) { 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) { @@ -35,7 +35,7 @@ func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int, 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) { @@ -50,7 +50,7 @@ func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) { } func (w *wrapperBlockCipher) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperBlockCipher) Conn() net.Conn { diff --git a/wrappers/stream/buffered_reader.go b/wrappers/stream/buffered_reader.go index 834c1e3..1e1ea9e 100644 --- a/wrappers/stream/buffered_reader.go +++ b/wrappers/stream/buffered_reader.go @@ -33,7 +33,7 @@ func (b *bufferedReader) ReadTimeout(p []byte, _ time.Duration) (int, error) { func (b *bufferedReader) flush(p []byte) (int, error) { if b.buf.Len() > len(p) { - return b.buf.Read(p) // nolint: wrapcheck + return b.buf.Read(p) //nolint: wrapcheck } sizeToReturn := b.buf.Len() diff --git a/wrappers/stream/conn.go b/wrappers/stream/conn.go index ba6bcd4..6e80a83 100644 --- a/wrappers/stream/conn.go +++ b/wrappers/stream/conn.go @@ -43,7 +43,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) { w.Close() } - return n, err // nolint: wrapcheck + return n, err //nolint: wrapcheck } 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() } - return n, err // nolint: wrapcheck + return n, err //nolint: wrapcheck } func (w *wrapperConn) Close() error { w.logger.Debugw("Close connection") - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperConn) Conn() net.Conn { @@ -93,9 +93,9 @@ func newConn(parent net.Conn, connID conntypes.ConnID, purpose connPurpose, ) 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 { localAddr.IP = config.C.PublicIPv4.IP } @@ -118,7 +118,7 @@ func newConn(parent net.Conn, parent: parent, connID: connID, logger: logger, - remoteAddr: parent.RemoteAddr().(*net.TCPAddr), // nolint: forcetypeassert + remoteAddr: parent.RemoteAddr().(*net.TCPAddr), //nolint: forcetypeassert localAddr: &localAddr, } } diff --git a/wrappers/stream/ctx.go b/wrappers/stream/ctx.go index 9a6bb5b..748af67 100644 --- a/wrappers/stream/ctx.go +++ b/wrappers/stream/ctx.go @@ -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()) 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()) 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()) 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()) default: - return w.parent.Read(p) // nolint: wrapcheck + return w.parent.Read(p) //nolint: wrapcheck } } func (w *wrapperCtx) Close() error { w.cancel() - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperCtx) Conn() net.Conn { diff --git a/wrappers/stream/faketls.go b/wrappers/stream/faketls.go index 74608d6..bfa2629 100644 --- a/wrappers/stream/faketls.go +++ b/wrappers/stream/faketls.go @@ -20,7 +20,7 @@ type wrapperFakeTLS struct { func (w *wrapperFakeTLS) Write(p []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) { elapsed := time.Since(startTime) 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") @@ -73,7 +73,7 @@ func (w *wrapperFakeTLS) RemoteAddr() *net.TCPAddr { } func (w *wrapperFakeTLS) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { @@ -85,7 +85,7 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit for { rec, err := tlstypes.ReadRecord(faketls.parent) if err != nil { - return nil, err // nolint: wrapcheck + return nil, err //nolint: wrapcheck } switch rec.Type { diff --git a/wrappers/stream/mtproto_cipher.go b/wrappers/stream/mtproto_cipher.go index 7e28ba8..5726f27 100644 --- a/wrappers/stream/mtproto_cipher.go +++ b/wrappers/stream/mtproto_cipher.go @@ -100,11 +100,11 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose, message.Write(req.Nonce) data := message.Bytes() - md5sum := md5.Sum(data[1:]) // nolint: gas - sha1sum := sha1.Sum(data) // nolint: gosec + md5sum := md5.Sum(data[1:]) //nolint: gas + sha1sum := sha1.Sum(data) //nolint: gosec key := append(md5sum[:12], sha1sum[:]...) - iv := md5.Sum(data[2:]) // nolint: gas + iv := md5.Sum(data[2:]) //nolint: gas return key, iv[:] } diff --git a/wrappers/stream/obfuscated2.go b/wrappers/stream/obfuscated2.go index 690cef9..06aaf5a 100644 --- a/wrappers/stream/obfuscated2.go +++ b/wrappers/stream/obfuscated2.go @@ -31,7 +31,7 @@ func (w *wrapperObfuscated2) ReadTimeout(p []byte, timeout time.Duration) (int, func (w *wrapperObfuscated2) Read(p []byte) (int, error) { n, err := w.parent.Read(p) if err != nil { - return n, err // nolint: wrapcheck + return n, err //nolint: wrapcheck } 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) - return w.parent.WriteTimeout(buf, timeout) // nolint: wrapcheck + return w.parent.WriteTimeout(buf, timeout) //nolint: wrapcheck } 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) - return w.parent.Write(buf) // nolint: wrapcheck + return w.parent.Write(buf) //nolint: wrapcheck } func (w *wrapperObfuscated2) Conn() net.Conn { @@ -80,7 +80,7 @@ func (w *wrapperObfuscated2) RemoteAddr() *net.TCPAddr { } func (w *wrapperObfuscated2) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func NewObfuscated2(socket conntypes.StreamReadWriteCloser, diff --git a/wrappers/stream/rewind.go b/wrappers/stream/rewind.go index 071db72..1061c02 100644 --- a/wrappers/stream/rewind.go +++ b/wrappers/stream/rewind.go @@ -24,25 +24,25 @@ type wrapperRewind struct { } 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) { - return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck + return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck } func (w *wrapperRewind) Read(p []byte) (int, error) { w.mutex.Lock() 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) { w.mutex.Lock() defer w.mutex.Unlock() - return w.activeReader.Read(p) // nolint: wrapcheck + return w.activeReader.Read(p) //nolint: wrapcheck } func (w *wrapperRewind) Conn() net.Conn { @@ -64,7 +64,7 @@ func (w *wrapperRewind) RemoteAddr() *net.TCPAddr { func (w *wrapperRewind) Close() error { w.buf.Reset() - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperRewind) Rewind() { diff --git a/wrappers/stream/stats_telegram.go b/wrappers/stream/stats_telegram.go index eee6dfd..f26f81a 100644 --- a/wrappers/stream/stats_telegram.go +++ b/wrappers/stream/stats_telegram.go @@ -17,19 +17,19 @@ type wrapperTelegramStats struct { } 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) { - return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck + return w.parent.WriteTimeout(p, timeout) //nolint: wrapcheck } 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) { - return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck + return w.parent.ReadTimeout(p, timeout) //nolint: wrapcheck } func (w *wrapperTelegramStats) Conn() net.Conn { @@ -56,7 +56,7 @@ func (w *wrapperTelegramStats) Close() error { 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 { diff --git a/wrappers/stream/stats_traffic.go b/wrappers/stream/stats_traffic.go index 8e9f101..219a323 100644 --- a/wrappers/stream/stats_traffic.go +++ b/wrappers/stream/stats_traffic.go @@ -17,28 +17,28 @@ func (w *wrapperTrafficStats) Write(p []byte) (int, error) { n, err := w.parent.Write(p) 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) { n, err := w.parent.WriteTimeout(p, timeout) stats.Stats.EgressTraffic(n) - return n, err // nolint: wrapcheck + return n, err //nolint: wrapcheck } func (w *wrapperTrafficStats) Read(p []byte) (int, error) { n, err := w.parent.Read(p) 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) { n, err := w.parent.ReadTimeout(p, timeout) stats.Stats.IngressTraffic(n) - return n, err // nolint: wrapcheck + return n, err //nolint: wrapcheck } func (w *wrapperTrafficStats) Conn() net.Conn { @@ -58,7 +58,7 @@ func (w *wrapperTrafficStats) RemoteAddr() *net.TCPAddr { } func (w *wrapperTrafficStats) Close() error { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func NewTrafficStats(parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { diff --git a/wrappers/stream/timeout.go b/wrappers/stream/timeout.go index a51a5b3..1745f0a 100644 --- a/wrappers/stream/timeout.go +++ b/wrappers/stream/timeout.go @@ -18,23 +18,23 @@ type wrapperTimeout struct { } 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) { - 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) { - return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck + return w.parent.ReadTimeout(p, timeout) //nolint: wrapcheck } 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 { - return w.parent.Close() // nolint: wrapcheck + return w.parent.Close() //nolint: wrapcheck } func (w *wrapperTimeout) Conn() net.Conn {