소스 검색

Merge pull request #260 from 9seconds/go118-v1

Support of Go 1.18 for v1
tags/v1.0.11
Sergey Arkhipov 4 년 전
부모
커밋
b976e74fc0
No account linked to committer's email address

+ 3
- 6
.github/workflows/ci.yaml 파일 보기

@@ -30,10 +30,7 @@ jobs:
30 30
     strategy:
31 31
       matrix:
32 32
         go_version:
33
-          - ~1.14
34
-          - ~1.15
35
-          - ~1.16
36
-          - ^1.17
33
+          - ^1.18
37 34
     steps:
38 35
       - name: Checkout
39 36
         uses: actions/checkout@v2
@@ -73,12 +70,12 @@ jobs:
73 70
       - name: Run linter
74 71
         uses: golangci/golangci-lint-action@v2
75 72
         with:
76
-          version: v1.42.0
73
+          version: v1.45.0
77 74
 
78 75
   docker:
79 76
     name: Docker
80 77
     runs-on: ubuntu-latest
81
-    timeout-minutes: 15
78
+    timeout-minutes: 20
82 79
     steps:
83 80
       - name: Checkout
84 81
         uses: actions/checkout@v2

+ 1
- 2
.golangci.toml 파일 보기

@@ -3,11 +3,10 @@ concurrency = 4
3 3
 deadline = "2m"
4 4
 tests = true
5 5
 skip-dirs = ["vendor"]
6
-skip-files = ["version.go"]
7 6
 
8 7
 [output]
9 8
 format = "colored-line-number"
10 9
 
11 10
 [linters]
12 11
 enable-all = true
13
-disable = ["gochecknoglobals", "gas", "gomnd", "goerr113", "exhaustivestruct"]
12
+disable = ["thelper", "ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"]

+ 1
- 1
Dockerfile 파일 보기

@@ -1,7 +1,7 @@
1 1
 ###############################################################################
2 2
 # BUILD STAGE
3 3
 
4
-FROM golang:1.17-alpine AS build
4
+FROM golang:1.18-alpine AS build
5 5
 
6 6
 RUN set -x \
7 7
   && apk --no-cache --update add \

+ 10
- 2
Makefile 파일 보기

@@ -4,7 +4,7 @@ APP_NAME     := $(IMAGE_NAME)
4 4
 
5 5
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
6 6
 
7
-GOLANGCI_LINT_VERSION := v1.42.0
7
+GOLANGCI_LINT_VERSION := v1.45.0
8 8
 
9 9
 VERSION_GO         := $(shell go version)
10 10
 VERSION_DATE       := $(shell date -Ru)
@@ -73,8 +73,12 @@ docker:
73 73
 doc:
74 74
 	@$(GOTOOL) godoc -http 0.0.0.0:10000
75 75
 
76
+.PHONY: fmt
77
+fmt:
78
+	@$(GOTOOL) gofumpt -w -extra "$(ROOT_DIR)"
79
+
76 80
 .PHONY: install-tools
77
-install-tools: install-tools-lint install-tools-godoc
81
+install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt
78 82
 
79 83
 .PHONY: install-tools-lint
80 84
 install-tools-lint:
@@ -87,6 +91,10 @@ install-tools-godoc:
87 91
 	@mkdir -p "$(GOBIN)" || true && \
88 92
 		$(GOTOOL) go get -u golang.org/x/tools/cmd/godoc
89 93
 
94
+.PHONY: install-tools-gofumpt
95
+install-tools-gofumpt: .bin
96
+	@$(GOTOOL) go install mvdan.cc/gofumpt@latest
97
+
90 98
 .PHONY: update-deps
91 99
 upgrade-deps:
92 100
 	$go get -u && go mod tidy

+ 6
- 6
config/config.go 파일 보기

@@ -146,7 +146,7 @@ func (c *Config) adjustProxyValue(value int) int {
146 146
 
147 147
 	fvalue := float64(value)
148 148
 
149
-	newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection))
149
+	newValue := fvalue * 2 * math.Log(float64(c.MultiplexPerConnection)) // nolint: gomnd
150 150
 	newValue = math.Ceil(newValue)
151 151
 	newValue = math.Max(fvalue, newValue)
152 152
 
@@ -208,15 +208,15 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
208 208
 		case OptionTypeStatsdTags:
209 209
 			C.StatsdTags = opt.Value.(map[string]string) // nolint: forcetypeassert
210 210
 		case OptionTypeWriteBufferSize:
211
-			C.WriteBuffer = int(opt.Value.(units.Base2Bytes))
211
+			C.WriteBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
212 212
 		case OptionTypeReadBufferSize:
213
-			C.ReadBuffer = int(opt.Value.(units.Base2Bytes))
213
+			C.ReadBuffer = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
214 214
 		case OptionTypeCloakPort:
215
-			C.CloakPort = int(opt.Value.(uint16))
215
+			C.CloakPort = int(opt.Value.(uint16)) // nolint: forcetypeassert
216 216
 		case OptionTypeAntiReplayMaxSize:
217
-			C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes))
217
+			C.AntiReplayMaxSize = int(opt.Value.(units.Base2Bytes)) // nolint: forcetypeassert
218 218
 		case OptionTypeMultiplexPerConnection:
219
-			C.MultiplexPerConnection = int(opt.Value.(uint))
219
+			C.MultiplexPerConnection = int(opt.Value.(uint)) // nolint: forcetypeassert
220 220
 		case OptionTypeNTPServers:
221 221
 			C.NTPServers = opt.Value.([]string) // nolint: forcetypeassert
222 222
 			if len(C.NTPServers) == 0 {

+ 1
- 1
faketls/cloak.go 파일 보기

@@ -26,7 +26,7 @@ func cloak(one, another io.ReadWriteCloser) {
26 26
 	another = rwc.NewPing(ctx, another, channelPing)
27 27
 	wg := &sync.WaitGroup{}
28 28
 
29
-	wg.Add(2)
29
+	wg.Add(2) // nolint: gomnd
30 30
 
31 31
 	go cloakPipe(one, another, wg)
32 32
 

+ 7
- 4
go.mod 파일 보기

@@ -13,10 +13,10 @@ require (
13 13
 	github.com/smira/go-statsd v1.3.2
14 14
 	go.uber.org/multierr v1.7.0 // indirect
15 15
 	go.uber.org/zap v1.19.0
16
-	golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
17
-	golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
18
-	golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
19
-	golang.org/x/tools v0.1.0 // indirect
16
+	golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
17
+	golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
18
+	golang.org/x/sys v0.0.0-20220318055525-2edf467146b5
19
+	golang.org/x/tools v0.1.10 // indirect
20 20
 	google.golang.org/protobuf v1.27.1 // indirect
21 21
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6
22 22
 )
@@ -28,5 +28,8 @@ require (
28 28
 	github.com/golang/protobuf v1.5.2 // indirect
29 29
 	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
30 30
 	github.com/prometheus/client_model v0.2.0 // indirect
31
+	github.com/yuin/goldmark v1.4.10 // indirect
31 32
 	go.uber.org/atomic v1.9.0 // indirect
33
+	golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
34
+	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
32 35
 )

+ 12
- 0
go.sum 파일 보기

@@ -206,6 +206,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
206 206
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
207 207
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
208 208
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
209
+github.com/yuin/goldmark v1.4.10 h1:+WgKGo8CQrlMTRJpGCFCyNddOhW801TKC2QijVV9QVg=
210
+github.com/yuin/goldmark v1.4.10/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg=
209 211
 go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
210 212
 go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
211 213
 go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -229,6 +231,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
229 231
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
230 232
 golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
231 233
 golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
234
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
235
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
232 236
 golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
233 237
 golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
234 238
 golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -260,6 +264,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
260 264
 golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
261 265
 golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
262 266
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
267
+golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
268
+golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
263 269
 golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
264 270
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
265 271
 golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -291,6 +297,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
291 297
 golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
292 298
 golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo=
293 299
 golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
300
+golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
301
+golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
294 302
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
295 303
 golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
296 304
 golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -347,6 +355,8 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w
347 355
 golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
348 356
 golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q=
349 357
 golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
358
+golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4=
359
+golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
350 360
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
351 361
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
352 362
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -401,6 +411,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
401 411
 golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
402 412
 golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
403 413
 golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
414
+golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
415
+golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
404 416
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
405 417
 golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
406 418
 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

+ 1
- 1
hub/hub.go 파일 보기

@@ -18,7 +18,7 @@ func (h *hub) Register(req *protocol.TelegramRequest) (*ProxyConn, error) {
18 18
 }
19 19
 
20 20
 func (h *hub) getMux(req *protocol.TelegramRequest) *mux {
21
-	key := 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol())
21
+	key := 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol()) // nolint: gomnd
22 22
 
23 23
 	h.mutex.RLock()
24 24
 	m, ok := h.muxes[key]

+ 1
- 1
mtproto/rpc/handshake_response.go 파일 보기

@@ -41,7 +41,7 @@ func (r *HandshakeResponse) Valid() error {
41 41
 // NewHandshakeResponse constructs new handshake response from the given
42 42
 // data.
43 43
 func NewHandshakeResponse(data []byte) (*HandshakeResponse, error) {
44
-	if len(data) != 32 {
44
+	if len(data) != 32 { // nolint: gomnd
45 45
 		return nil, fmt.Errorf("incorrect handshake response length %d", len(data))
46 46
 	}
47 47
 

+ 5
- 5
mtproto/rpc/nonce_request.go 파일 보기

@@ -29,17 +29,17 @@ func (r *NonceRequest) Bytes() []byte {
29 29
 
30 30
 // NewNonceRequest builds new none request based on proxy secret.
31 31
 func NewNonceRequest(proxySecret []byte) (*NonceRequest, error) {
32
-	nonce := make([]byte, 16)
33
-	keySelector := make([]byte, 4)
34
-	cryptoTS := make([]byte, 4)
32
+	nonce := make([]byte, 16)      // nolint: gomnd
33
+	keySelector := make([]byte, 4) // nolint: gomnd
34
+	cryptoTS := make([]byte, 4)    // nolint: gomnd
35 35
 
36 36
 	if _, err := rand.Read(nonce); err != nil {
37 37
 		return nil, fmt.Errorf("cannot generate nonce: %w", err)
38 38
 	}
39 39
 
40 40
 	copy(keySelector, proxySecret)
41
-
42
-	timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 // 256 ^ 4 - do not know how to name
41
+	// 256 ^ 4 - do not know how to name
42
+	timestamp := time.Now().Truncate(time.Second).Unix() % 4294967296 // nolint: gomnd
43 43
 	binary.LittleEndian.PutUint32(cryptoTS, uint32(timestamp))
44 44
 
45 45
 	return &NonceRequest{

+ 1
- 1
mtproto/rpc/nonce_response.go 파일 보기

@@ -44,7 +44,7 @@ func (r *NonceResponse) Valid(req *NonceRequest) error {
44 44
 
45 45
 // NewNonceResponse build new nonce response based on the given data.
46 46
 func NewNonceResponse(data []byte) (*NonceResponse, error) {
47
-	if len(data) != 32 {
47
+	if len(data) != 32 { // nolint: gomnd
48 48
 		return nil, fmt.Errorf("unexpected message length %d", len(data))
49 49
 	}
50 50
 

+ 2
- 2
mtproto/rpc/proxy_flags.go 파일 보기

@@ -21,14 +21,14 @@ const (
21 21
 var ProxyRequestFlagsEncryptedPrefix [8]byte
22 22
 
23 23
 func (r ProxyRequestFlags) Bytes() []byte {
24
-	converted := make([]byte, 4)
24
+	converted := make([]byte, 4) // nolint: gomnd
25 25
 	binary.LittleEndian.PutUint32(converted, uint32(r))
26 26
 
27 27
 	return converted
28 28
 }
29 29
 
30 30
 func (r ProxyRequestFlags) String() string {
31
-	flags := make([]string, 0, 7)
31
+	flags := make([]string, 0, 7) // nolint: gomnd
32 32
 
33 33
 	if r&ProxyRequestFlagsHasAdTag != 0 {
34 34
 		flags = append(flags, "HAS_AD_TAG")

+ 1
- 1
mtproto/rpc/proxy_response.go 파일 보기

@@ -24,7 +24,7 @@ type ProxyResponse struct {
24 24
 func ParseProxyResponse(packet conntypes.Packet) (*ProxyResponse, error) {
25 25
 	var response ProxyResponse
26 26
 
27
-	if len(packet) < 4 {
27
+	if len(packet) < 4 { // nolint: gomnd
28 28
 		return nil, fmt.Errorf("incorrect packet length: %d", len(packet))
29 29
 	}
30 30
 

+ 5
- 5
obfuscated2/telegram_protocol.go 파일 보기

@@ -47,17 +47,17 @@ func generateFrame(cp protocol.ClientProtocol) (fm Frame) {
47 47
 			continue
48 48
 		}
49 49
 
50
-		if data[0] == 0xef {
50
+		if data[0] == 0xef { // nolint: gomnd
51 51
 			continue
52 52
 		}
53 53
 
54
-		val := (uint32(data[3]) << 24) | (uint32(data[2]) << 16) | (uint32(data[1]) << 8) | uint32(data[0])
55
-		if val == 0x44414548 || val == 0x54534f50 || val == 0x20544547 || val == 0x4954504f || val == 0xeeeeeeee {
54
+		val := (uint32(data[3]) << 24) | (uint32(data[2]) << 16) | (uint32(data[1]) << 8) | uint32(data[0])        // nolint: gomnd, lll
55
+		if val == 0x44414548 || val == 0x54534f50 || val == 0x20544547 || val == 0x4954504f || val == 0xeeeeeeee { // nolint: lll
56 56
 			continue
57 57
 		}
58 58
 
59
-		val = (uint32(data[7]) << 24) | (uint32(data[6]) << 16) | (uint32(data[5]) << 8) | uint32(data[4])
60
-		if val == 0x00000000 {
59
+		val = (uint32(data[7]) << 24) | (uint32(data[6]) << 16) | (uint32(data[5]) << 8) | uint32(data[4]) // nolint: gomnd
60
+		if val == 0x00000000 {                                                                             // nolint: gomnd
61 61
 			continue
62 62
 		}
63 63
 

+ 1
- 1
proxy/direct.go 파일 보기

@@ -20,7 +20,7 @@ func directConnection(request *protocol.TelegramRequest) error {
20 20
 	defer telegramConnRaw.Close()
21 21
 
22 22
 	wg := &sync.WaitGroup{}
23
-	wg.Add(2)
23
+	wg.Add(2) // nolint: gomnd
24 24
 
25 25
 	go directPipe(telegramConnRaw, request.ClientConn, wg, request.Logger)
26 26
 

+ 3
- 2
proxy/middle.go 파일 보기

@@ -32,7 +32,7 @@ func middleConnection(request *protocol.TelegramRequest) {
32 32
 	}
33 33
 
34 34
 	wg := &sync.WaitGroup{}
35
-	wg.Add(2)
35
+	wg.Add(2) // nolint: gomnd
36 36
 
37 37
 	go middlePipe(telegramConn, clientConn, wg, request.Logger)
38 38
 
@@ -44,7 +44,8 @@ func middleConnection(request *protocol.TelegramRequest) {
44 44
 func middlePipe(dst conntypes.PacketAckWriteCloser,
45 45
 	src conntypes.PacketAckReadCloser,
46 46
 	wg *sync.WaitGroup,
47
-	logger *zap.SugaredLogger) {
47
+	logger *zap.SugaredLogger,
48
+) {
48 49
 	defer func() {
49 50
 		dst.Close()
50 51
 		src.Close()

+ 1
- 1
stats/stats.go 파일 보기

@@ -32,7 +32,7 @@ func Init(ctx context.Context) error {
32 32
 
33 33
 	go func() {
34 34
 		<-ctx.Done()
35
-		srv.Shutdown(context.Background()) // nolint: errcheck
35
+		srv.Shutdown(context.Background()) // nolint: errcheck, contextcheck
36 36
 	}()
37 37
 
38 38
 	Stats = multiStats(stats)

+ 2
- 1
stats/stats_prometheus.go 파일 보기

@@ -39,7 +39,8 @@ func (s *statsPrometheus) ClientDisconnected(connectionType conntypes.Connection
39 39
 
40 40
 func (s *statsPrometheus) changeConnections(connectionType conntypes.ConnectionType,
41 41
 	addr *net.TCPAddr,
42
-	increment float64) {
42
+	increment float64,
43
+) {
43 44
 	labels := [...]string{
44 45
 		"intermediate",
45 46
 		"ipv4",

+ 3
- 3
stats/stats_statsd.go 파일 보기

@@ -83,7 +83,7 @@ func (s *statsStatsd) ClientDisconnected(connectionType conntypes.ConnectionType
83 83
 }
84 84
 
85 85
 func (s *statsStatsd) changeConnections(connectionType conntypes.ConnectionType, addr *net.TCPAddr, increment int64) {
86
-	tags := make([]*statsStatsdTag, 0, 2)
86
+	tags := make([]*statsStatsdTag, 0, 2) // nolint: gomnd
87 87
 
88 88
 	switch connectionType {
89 89
 	case conntypes.ConnectionTypeAbridged:
@@ -194,8 +194,8 @@ func newStatsStatsd() Interface {
194 194
 	return &statsStatsd{
195 195
 		seen: make(map[string]struct{}),
196 196
 		client: statsd.NewClient(config.C.StatsdAddr.String(),
197
-			statsd.SendLoopCount(2),
198
-			statsd.ReconnectInterval(10*time.Second),
197
+			statsd.SendLoopCount(2),                  // nolint: gomnd
198
+			statsd.ReconnectInterval(10*time.Second), // nolint: gomnd
199 199
 			statsd.Logger(logger),
200 200
 			statsd.MetricPrefix(prefix),
201 201
 			statsd.TagStyle(config.C.StatsdTagsFormat),

+ 4
- 4
telegram/api/addresses.go 파일 보기

@@ -74,12 +74,12 @@ func getAddresses(url string) (map[conntypes.DC][]string, conntypes.DC, error) {
74 74
 }
75 75
 
76 76
 func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
77
-	chunks := addressesProxyForSplitter.Split(text, 3)
77
+	chunks := addressesProxyForSplitter.Split(text, 3) // nolint: gomnd
78 78
 	if len(chunks) != 3 || chunks[0] != "proxy_for" {
79 79
 		return "", 0, fmt.Errorf("incorrect config %s", text)
80 80
 	}
81 81
 
82
-	dc, err := strconv.ParseInt(chunks[1], 10, 16)
82
+	dc, err := strconv.ParseInt(chunks[1], 10, 16) // nolint: gomnd
83 83
 	if err != nil {
84 84
 		return "", 0, fmt.Errorf("incorrect config '%s': %w", text, err)
85 85
 	}
@@ -93,14 +93,14 @@ func addressesParseProxyFor(text string) (string, conntypes.DC, error) {
93 93
 }
94 94
 
95 95
 func addressesParseDefault(text string) (conntypes.DC, error) {
96
-	chunks := addressesProxyForSplitter.Split(text, 2)
96
+	chunks := addressesProxyForSplitter.Split(text, 2) // nolint: gomnd
97 97
 	if len(chunks) != 2 || chunks[0] != "default" {
98 98
 		return 0, fmt.Errorf("incorrect config '%s'", text)
99 99
 	}
100 100
 
101 101
 	dcString := strings.TrimRight(chunks[1], ";")
102 102
 
103
-	dc, err := strconv.ParseInt(dcString, 10, 16)
103
+	dc, err := strconv.ParseInt(dcString, 10, 16) // nolint: gomnd
104 104
 	if err != nil {
105 105
 		return 0, fmt.Errorf("incorrect config '%s': %w", text, err)
106 106
 	}

+ 5
- 3
telegram/base.go 파일 보기

@@ -28,7 +28,8 @@ func (b *baseTelegram) Secret() []byte {
28 28
 }
29 29
 
30 30
 func (b *baseTelegram) dial(dc conntypes.DC,
31
-	protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) {
31
+	protocol conntypes.ConnectionProtocol,
32
+) (conntypes.StreamReadWriteCloser, error) {
32 33
 	for _, addr := range b.getAddresses(dc, protocol) {
33 34
 		conn, err := b.dialer.Dial("tcp", addr)
34 35
 		if err != nil {
@@ -50,7 +51,7 @@ func (b *baseTelegram) dial(dc conntypes.DC,
50 51
 }
51 52
 
52 53
 func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.ConnectionProtocol) []string {
53
-	addresses := make([]string, 0, 2)
54
+	addresses := make([]string, 0, 2) // nolint: gomnd
54 55
 	protos := []conntypes.ConnectionProtocol{
55 56
 		conntypes.ConnectionProtocolIPv6,
56 57
 		conntypes.ConnectionProtocolIPv4,
@@ -74,7 +75,8 @@ func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.Connecti
74 75
 }
75 76
 
76 77
 func (b *baseTelegram) chooseAddress(addresses map[conntypes.DC][]string,
77
-	dc, defaultDC conntypes.DC) string {
78
+	dc, defaultDC conntypes.DC,
79
+) string {
78 80
 	addrs, ok := addresses[dc]
79 81
 	if !ok {
80 82
 		addrs = addresses[defaultDC]

+ 2
- 1
telegram/direct.go 파일 보기

@@ -29,7 +29,8 @@ type directTelegram struct {
29 29
 }
30 30
 
31 31
 func (d *directTelegram) Dial(dc conntypes.DC,
32
-	protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) {
32
+	protocol conntypes.ConnectionProtocol,
33
+) (conntypes.StreamReadWriteCloser, error) {
33 34
 	switch {
34 35
 	case dc < 0:
35 36
 		dc = -dc

+ 2
- 1
telegram/middle.go 파일 보기

@@ -63,7 +63,8 @@ func (m *middleTelegram) backgroundUpdate() {
63 63
 }
64 64
 
65 65
 func (m *middleTelegram) Dial(dc conntypes.DC,
66
-	protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) {
66
+	protocol conntypes.ConnectionProtocol,
67
+) (conntypes.StreamReadWriteCloser, error) {
67 68
 	if dc == 0 {
68 69
 		dc = conntypes.DCDefaultIdx
69 70
 	}

+ 2
- 2
tlstypes/server_hello.go 파일 보기

@@ -36,7 +36,7 @@ func (s ServerHello) WelcomePacket() []byte {
36 36
 	}
37 37
 	recChangeCipher.WriteBytes(buf)
38 38
 
39
-	hostCert := make([]byte, 1024+mrand.Intn(3092)) // nolint: gosec
39
+	hostCert := make([]byte, 1024+mrand.Intn(3092)) // nolint: gosec, gomnd
40 40
 	rand.Read(hostCert)                             // nolint: errcheck
41 41
 
42 42
 	recData := Record{
@@ -67,7 +67,7 @@ func NewServerHello(clientHello *ClientHello) *ServerHello {
67 67
 	copy(rv.SessionID, clientHello.SessionID)
68 68
 
69 69
 	tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes)
70
-	tail.WriteByte(0x00) // no compression
70
+	tail.WriteByte(0x00) // nolint: gomnd // no compression
71 71
 	makeTLSExtensions(tail)
72 72
 	rv.Tail = RawBytes(tail.Bytes())
73 73
 

+ 1
- 1
utils/init_tcp.go 파일 보기

@@ -5,7 +5,7 @@ import (
5 5
 	"net"
6 6
 )
7 7
 
8
-func InitTCP(conn net.Conn, readBufferSize int, writeBufferSize int) error {
8
+func InitTCP(conn net.Conn, readBufferSize, writeBufferSize int) error {
9 9
 	tcpConn := conn.(*net.TCPConn) // nolint: forcetypeassert
10 10
 
11 11
 	if err := tcpConn.SetNoDelay(true); err != nil {

+ 1
- 1
utils/reverse_bytes.go 파일 보기

@@ -6,7 +6,7 @@ func ReverseBytes(data []byte) []byte {
6 6
 	rv := make([]byte, dataLen)
7 7
 	rv[dataLen/2] = data[dataLen/2]
8 8
 
9
-	for i := dataLen/2 - 1; i >= 0; i-- {
9
+	for i := dataLen/2 - 1; i >= 0; i-- { // nolint: gomnd
10 10
 		opp := dataLen - i - 1
11 11
 		rv[i], rv[opp] = data[opp], data[i]
12 12
 	}

+ 2
- 2
utils/uint24.go 파일 보기

@@ -3,9 +3,9 @@ package utils
3 3
 type Uint24 [3]byte
4 4
 
5 5
 func ToUint24(number uint32) Uint24 {
6
-	return Uint24{byte(number), byte(number >> 8), byte(number >> 16)}
6
+	return Uint24{byte(number), byte(number >> 8), byte(number >> 16)} // nolint: gomnd
7 7
 }
8 8
 
9 9
 func FromUint24(number Uint24) uint32 {
10
-	return uint32(number[0]) + (uint32(number[1]) << 8) + (uint32(number[2]) << 16)
10
+	return uint32(number[0]) + (uint32(number[1]) << 8) + (uint32(number[2]) << 16) // nolint: gomnd
11 11
 }

+ 6
- 6
wrappers/packet/mtproto_frame.go 파일 보기

@@ -50,7 +50,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
50 50
 		buf.Reset()
51 51
 		sum.Reset()
52 52
 
53
-		if _, err := io.CopyN(writer, w.parent, 4); err != nil {
53
+		if _, err := io.CopyN(writer, w.parent, 4); err != nil { // nolint: gomnd
54 54
 			return nil, fmt.Errorf("cannot read frame padding: %w", err)
55 55
 		}
56 56
 
@@ -72,7 +72,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
72 72
 
73 73
 	buf.Reset()
74 74
 
75
-	if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil {
75
+	if _, err := io.CopyN(writer, w.parent, int64(messageLength)-4-4); err != nil { // nolint: gomnd
76 76
 		return nil, fmt.Errorf("cannot read the message frame: %w", err)
77 77
 	}
78 78
 
@@ -88,7 +88,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
88 88
 	buf.Reset()
89 89
 	// write to buf, not to writer. This is because we are going to fetch
90 90
 	// crc32 checksum.
91
-	if _, err := io.CopyN(buf, w.parent, 4); err != nil {
91
+	if _, err := io.CopyN(buf, w.parent, 4); err != nil { // nolint: gomnd
92 92
 		return nil, fmt.Errorf("cannot read checksum: %w", err)
93 93
 	}
94 94
 
@@ -109,7 +109,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
109 109
 }
110 110
 
111 111
 func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
112
-	messageLength := 4 + 4 + len(p) + 4
112
+	messageLength := 4 + 4 + len(p) + 4 // nolint: gomnd
113 113
 	paddingLength := (aes.BlockSize - messageLength%aes.BlockSize) % aes.BlockSize
114 114
 
115 115
 	buf := &bytes.Buffer{}
@@ -119,8 +119,8 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
119 119
 	buf.Write(p)
120 120
 
121 121
 	checksum := crc32.ChecksumIEEE(buf.Bytes())
122
-	binary.Write(buf, binary.LittleEndian, checksum) // nolint: errcheck
123
-	buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4))
122
+	binary.Write(buf, binary.LittleEndian, checksum)              // nolint: errcheck
123
+	buf.Write(bytes.Repeat(mtprotoFramePadding, paddingLength/4)) // nolint: gomnd
124 124
 
125 125
 	w.logger.Debugw("Write MTProto frame",
126 126
 		"length", len(p),

+ 3
- 3
wrappers/packetack/client_abridged.go 파일 보기

@@ -39,9 +39,9 @@ func (w *wrapperClientAbridged) Read(acks *conntypes.ConnectionAcks) (conntypes.
39 39
 	}
40 40
 
41 41
 	if msgLength == clientAbridgedSmallPacketLength {
42
-		buf.Grow(3)
42
+		buf.Grow(3) // nolint: gomnd
43 43
 
44
-		if _, err := io.CopyN(&buf, w.parent, 3); err != nil {
44
+		if _, err := io.CopyN(&buf, w.parent, 3); err != nil { // nolint: gomnd
45 45
 			return nil, fmt.Errorf("cannot read correct message length: %w", err)
46 46
 		}
47 47
 
@@ -75,7 +75,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
75 75
 		return nil
76 76
 	}
77 77
 
78
-	packetLength := len(packet) / 4
78
+	packetLength := len(packet) / 4 // nolint: gomnd
79 79
 
80 80
 	switch {
81 81
 	case packetLength < clientAbridgedSmallPacketLength:

+ 2
- 2
wrappers/packetack/client_intermediate.go 파일 보기

@@ -20,9 +20,9 @@ type wrapperClientIntermediate struct {
20 20
 func (w *wrapperClientIntermediate) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) {
21 21
 	buf := bytes.Buffer{}
22 22
 
23
-	buf.Grow(4)
23
+	buf.Grow(4) // nolint: gomnd
24 24
 
25
-	if _, err := io.CopyN(&buf, w.parent, 4); err != nil {
25
+	if _, err := io.CopyN(&buf, w.parent, 4); err != nil { // nolint: gomnd
26 26
 		return nil, fmt.Errorf("cannot read message length: %w", err)
27 27
 	}
28 28
 

+ 2
- 2
wrappers/packetack/client_intermediate_secure.go 파일 보기

@@ -20,7 +20,7 @@ func (w *wrapperClientIntermediateSecure) Read(acks *conntypes.ConnectionAcks) (
20 20
 		return nil, err
21 21
 	}
22 22
 
23
-	length := len(data) - (len(data) % 4)
23
+	length := len(data) - (len(data) % 4) // nolint: gomnd
24 24
 
25 25
 	return data[:length], nil
26 26
 }
@@ -35,7 +35,7 @@ func (w *wrapperClientIntermediateSecure) Write(packet conntypes.Packet, acks *c
35 35
 	}
36 36
 
37 37
 	buf := &bytes.Buffer{}
38
-	paddingLength := rand.Intn(4) // nolint: gosec
38
+	paddingLength := rand.Intn(4) // nolint: gosec, gomnd
39 39
 
40 40
 	buf.Grow(4 + len(packet) + paddingLength)
41 41
 

+ 1
- 1
wrappers/packetack/proxy.go 파일 보기

@@ -42,7 +42,7 @@ func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.Connection
42 42
 	buf.Write(rpc.ProxyRequestProxyTag)
43 43
 	buf.WriteByte(byte(len(config.C.AdTag)))
44 44
 	buf.Write(config.C.AdTag)
45
-	buf.Write(make([]byte, (4-buf.Len()%4)%4))
45
+	buf.Write(make([]byte, (4-buf.Len()%4)%4)) // nolint: gomnd
46 46
 	buf.Grow(len(packet))
47 47
 	buf.Write(packet)
48 48
 

+ 2
- 1
wrappers/stream/blockcipher.go 파일 보기

@@ -70,7 +70,8 @@ func (w *wrapperBlockCipher) RemoteAddr() *net.TCPAddr {
70 70
 }
71 71
 
72 72
 func newBlockCipher(parent conntypes.StreamReadWriteCloser,
73
-	encryptor, decryptor cipher.BlockMode) conntypes.StreamReadWriteCloser {
73
+	encryptor, decryptor cipher.BlockMode,
74
+) conntypes.StreamReadWriteCloser {
74 75
 	cipher := &wrapperBlockCipher{
75 76
 		parent:    parent,
76 77
 		encryptor: encryptor,

+ 5
- 4
wrappers/stream/conn.go 파일 보기

@@ -91,10 +91,11 @@ func (w *wrapperConn) RemoteAddr() *net.TCPAddr {
91 91
 
92 92
 func newConn(parent net.Conn,
93 93
 	connID conntypes.ConnID,
94
-	purpose connPurpose) conntypes.StreamReadWriteCloser {
95
-	localAddr := *parent.LocalAddr().(*net.TCPAddr)
94
+	purpose connPurpose,
95
+) conntypes.StreamReadWriteCloser {
96
+	localAddr := *parent.LocalAddr().(*net.TCPAddr) // nolint: forcetypeassert
96 97
 
97
-	if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil {
98
+	if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil { // nolint: forcetypeassert
98 99
 		if config.C.PublicIPv4.IP != nil {
99 100
 			localAddr.IP = config.C.PublicIPv4.IP
100 101
 		}
@@ -117,7 +118,7 @@ func newConn(parent net.Conn,
117 118
 		parent:     parent,
118 119
 		connID:     connID,
119 120
 		logger:     logger,
120
-		remoteAddr: parent.RemoteAddr().(*net.TCPAddr),
121
+		remoteAddr: parent.RemoteAddr().(*net.TCPAddr), // nolint: forcetypeassert
121 122
 		localAddr:  &localAddr,
122 123
 	}
123 124
 }

+ 2
- 1
wrappers/stream/ctx.go 파일 보기

@@ -84,7 +84,8 @@ func (w *wrapperCtx) RemoteAddr() *net.TCPAddr {
84 84
 
85 85
 func NewCtx(ctx context.Context,
86 86
 	cancel context.CancelFunc,
87
-	parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
87
+	parent conntypes.StreamReadWriteCloser,
88
+) conntypes.StreamReadWriteCloser {
88 89
 	return &wrapperCtx{
89 90
 		parent: parent,
90 91
 		ctx:    ctx,

+ 4
- 2
wrappers/stream/mtproto_cipher.go 파일 보기

@@ -26,7 +26,8 @@ var mtprotoEmptyIP = [4]byte{0x00, 0x00, 0x00, 0x00}
26 26
 func NewMiddleProxyCipher(parent conntypes.StreamReadWriteCloser,
27 27
 	req *rpc.NonceRequest,
28 28
 	resp *rpc.NonceResponse,
29
-	secret []byte) conntypes.StreamReadWriteCloser {
29
+	secret []byte,
30
+) conntypes.StreamReadWriteCloser {
30 31
 	localAddr := parent.LocalAddr()
31 32
 	remoteAddr := parent.RemoteAddr()
32 33
 
@@ -53,7 +54,8 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose,
53 54
 	req *rpc.NonceRequest,
54 55
 	resp *rpc.NonceResponse,
55 56
 	client, remote *net.TCPAddr,
56
-	secret []byte) ([]byte, []byte) {
57
+	secret []byte,
58
+) ([]byte, []byte) {
57 59
 	message := bytes.Buffer{}
58 60
 
59 61
 	message.Write(resp.Nonce)

+ 2
- 1
wrappers/stream/obfuscated2.go 파일 보기

@@ -84,7 +84,8 @@ func (w *wrapperObfuscated2) Close() error {
84 84
 }
85 85
 
86 86
 func NewObfuscated2(socket conntypes.StreamReadWriteCloser,
87
-	encryptor, decryptor cipher.Stream) conntypes.StreamReadWriteCloser {
87
+	encryptor, decryptor cipher.Stream,
88
+) conntypes.StreamReadWriteCloser {
88 89
 	return &wrapperObfuscated2{
89 90
 		parent:    socket,
90 91
 		encryptor: encryptor,

Loading…
취소
저장