Просмотр исходного кода

Update golangci-lint

tags/v1.0.6^2^2
9seconds 5 лет назад
Родитель
Сommit
7a6695f6c4
47 измененных файлов: 133 добавлений и 114 удалений
  1. 1
    1
      .golangci.toml
  2. 1
    1
      Makefile
  3. 1
    2
      antireplay/init.go
  4. 2
    3
      cli/proxy.go
  5. 2
    0
      config/config.go
  6. 1
    1
      config/global_ips.go
  7. 2
    0
      conntypes/protocol.go
  8. 3
    1
      conntypes/type.go
  9. 3
    2
      faketls/client_protocol.go
  10. 2
    0
      faketls/cloak.go
  11. 2
    2
      hub/connection.go
  12. 1
    0
      hub/connection_list.go
  13. 1
    2
      main.go
  14. 1
    1
      mtproto/protocol.go
  15. 1
    1
      mtproto/rpc/consts.go
  16. 4
    4
      mtproto/rpc/handshake_response.go
  17. 6
    6
      mtproto/rpc/nonce_response.go
  18. 3
    3
      ntp/ntp.go
  19. 1
    0
      obfuscated2/client_protocol.go
  20. 1
    1
      obfuscated2/frame.go
  21. 1
    2
      protocol/request.go
  22. 1
    2
      proxy/direct.go
  23. 6
    4
      proxy/middle.go
  24. 3
    3
      proxy/proxy.go
  25. 7
    4
      stats/stats_prometheus.go
  26. 5
    4
      stats/stats_statsd.go
  27. 5
    1
      telegram/api/api.go
  28. 4
    3
      telegram/base.go
  29. 1
    2
      telegram/middle.go
  30. 10
    6
      tlstypes/consts.go
  31. 3
    4
      tlstypes/server_hello.go
  32. 2
    1
      utils/stream_cipher.go
  33. 2
    3
      wrappers/packet/mtproto_frame.go
  34. 1
    2
      wrappers/packetack/client_abridged.go
  35. 1
    2
      wrappers/packetack/client_intermediate.go
  36. 2
    3
      wrappers/packetack/client_intermediate_secure.go
  37. 2
    1
      wrappers/packetack/proxy.go
  38. 1
    2
      wrappers/stream/blockcipher.go
  39. 5
    3
      wrappers/stream/conn.go
  40. 6
    2
      wrappers/stream/ctx.go
  41. 4
    2
      wrappers/stream/faketls.go
  42. 16
    17
      wrappers/stream/mtproto_cipher.go
  43. 1
    2
      wrappers/stream/obfuscated2.go
  44. 2
    2
      wrappers/stream/rewind.go
  45. 1
    2
      wrappers/stream/stats_telegram.go
  46. 1
    2
      wrappers/stream/stats_traffic.go
  47. 1
    2
      wrappers/stream/timeout.go

+ 1
- 1
.golangci.toml Просмотреть файл

10
 
10
 
11
 [linters]
11
 [linters]
12
 enable-all = true
12
 enable-all = true
13
-disable = ["gochecknoglobals", "gomnd"]
13
+disable = ["gochecknoglobals", "gas", "gomnd", "goerr113"]

+ 1
- 1
Makefile Просмотреть файл

71
 .PHONY: install-lint
71
 .PHONY: install-lint
72
 install-lint:
72
 install-lint:
73
 	@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
73
 	@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
74
-		| $(MOD_OFF) bash -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
74
+		| $(MOD_OFF) bash -s -- -b . $(GOLANGCI_LINT_VERSION)

+ 1
- 2
antireplay/init.go Просмотреть файл

3
 import (
3
 import (
4
 	"sync"
4
 	"sync"
5
 
5
 
6
-	"github.com/VictoriaMetrics/fastcache"
7
-
8
 	"github.com/9seconds/mtg/config"
6
 	"github.com/9seconds/mtg/config"
7
+	"github.com/VictoriaMetrics/fastcache"
9
 )
8
 )
10
 
9
 
11
 type CacheInterface interface {
10
 type CacheInterface interface {

+ 2
- 3
cli/proxy.go Просмотреть файл

5
 	"os"
5
 	"os"
6
 	"time"
6
 	"time"
7
 
7
 
8
-	"go.uber.org/zap"
9
-	"go.uber.org/zap/zapcore"
10
-
11
 	"github.com/9seconds/mtg/antireplay"
8
 	"github.com/9seconds/mtg/antireplay"
12
 	"github.com/9seconds/mtg/config"
9
 	"github.com/9seconds/mtg/config"
13
 	"github.com/9seconds/mtg/faketls"
10
 	"github.com/9seconds/mtg/faketls"
18
 	"github.com/9seconds/mtg/stats"
15
 	"github.com/9seconds/mtg/stats"
19
 	"github.com/9seconds/mtg/telegram"
16
 	"github.com/9seconds/mtg/telegram"
20
 	"github.com/9seconds/mtg/utils"
17
 	"github.com/9seconds/mtg/utils"
18
+	"go.uber.org/zap"
19
+	"go.uber.org/zap/zapcore"
21
 )
20
 )
22
 
21
 
23
 func Proxy() error { // nolint: funlen
22
 func Proxy() error { // nolint: funlen

+ 2
- 0
config/config.go Просмотреть файл

22
 		return "simple"
22
 		return "simple"
23
 	case SecretModeSecured:
23
 	case SecretModeSecured:
24
 		return "secured"
24
 		return "secured"
25
+	case SecretModeTLS:
26
+		return "tls"
25
 	}
27
 	}
26
 
28
 
27
 	return "tls"
29
 	return "tls"

+ 1
- 1
config/global_ips.go Просмотреть файл

60
 		return nil, fmt.Errorf("cannot perform a request: %w", err)
60
 		return nil, fmt.Errorf("cannot perform a request: %w", err)
61
 	}
61
 	}
62
 
62
 
63
-	defer resp.Body.Close() // nolint: errcheck
63
+	defer resp.Body.Close()
64
 
64
 
65
 	respDataBytes, err := ioutil.ReadAll(resp.Body)
65
 	respDataBytes, err := ioutil.ReadAll(resp.Body)
66
 	if err != nil {
66
 	if err != nil {

+ 2
- 0
conntypes/protocol.go Просмотреть файл

8
 		return "any"
8
 		return "any"
9
 	case ConnectionProtocolIPv4:
9
 	case ConnectionProtocolIPv4:
10
 		return "ipv4"
10
 		return "ipv4"
11
+	case ConnectionProtocolIPv6:
12
+		return "ipv6"
11
 	}
13
 	}
12
 
14
 
13
 	return "ipv6"
15
 	return "ipv6"

+ 3
- 1
conntypes/type.go Просмотреть файл

21
 		return ConnectionTagAbridged
21
 		return ConnectionTagAbridged
22
 	case ConnectionTypeIntermediate:
22
 	case ConnectionTypeIntermediate:
23
 		return ConnectionTagIntermediate
23
 		return ConnectionTagIntermediate
24
-	default:
24
+	case ConnectionTypeSecure, ConnectionTypeUnknown:
25
 		return ConnectionTagSecure
25
 		return ConnectionTagSecure
26
 	}
26
 	}
27
+
28
+	return ConnectionTagSecure
27
 }
29
 }

+ 3
- 2
faketls/client_protocol.go Просмотреть файл

49
 	}
49
 	}
50
 
50
 
51
 	conn := stream.NewFakeTLS(socket)
51
 	conn := stream.NewFakeTLS(socket)
52
-	conn, err := c.ClientProtocol.Handshake(conn)
53
 
52
 
53
+	conn, err := c.ClientProtocol.Handshake(conn)
54
 	if err != nil {
54
 	if err != nil {
55
 		return nil, err
55
 		return nil, err
56
 	}
56
 	}
89
 
89
 
90
 	if antireplay.Cache.HasTLS(clientHello.Random[:]) {
90
 	if antireplay.Cache.HasTLS(clientHello.Random[:]) {
91
 		stats.Stats.ReplayDetected()
91
 		stats.Stats.ReplayDetected()
92
+
92
 		return errors.New("replay attack is detected")
93
 		return errors.New("replay attack is detected")
93
 	}
94
 	}
94
 
95
 
107
 	stats.Stats.CloakedRequest()
108
 	stats.Stats.CloakedRequest()
108
 
109
 
109
 	addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
110
 	addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
110
-	hostConn, err := net.Dial("tcp", addr)
111
 
111
 
112
+	hostConn, err := net.Dial("tcp", addr)
112
 	if err != nil {
113
 	if err != nil {
113
 		return
114
 		return
114
 	}
115
 	}

+ 2
- 0
faketls/cloak.go Просмотреть файл

53
 				return
53
 				return
54
 			case <-lastActivityTimer.C:
54
 			case <-lastActivityTimer.C:
55
 				cancel()
55
 				cancel()
56
+
56
 				return
57
 				return
57
 			case <-maxTimer.C:
58
 			case <-maxTimer.C:
58
 				cancel()
59
 				cancel()
60
+
59
 				return
61
 				return
60
 			}
62
 			}
61
 		}
63
 		}

+ 2
- 2
hub/connection.go Просмотреть файл

6
 	"sync"
6
 	"sync"
7
 	"time"
7
 	"time"
8
 
8
 
9
-	"go.uber.org/zap"
10
-
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
12
 	"github.com/9seconds/mtg/mtproto"
10
 	"github.com/9seconds/mtg/mtproto"
13
 	"github.com/9seconds/mtg/mtproto/rpc"
11
 	"github.com/9seconds/mtg/mtproto/rpc"
14
 	"github.com/9seconds/mtg/protocol"
12
 	"github.com/9seconds/mtg/protocol"
13
+	"go.uber.org/zap"
15
 )
14
 )
16
 
15
 
17
 const connectionTTL = time.Hour
16
 const connectionTTL = time.Hour
90
 		response, err := rpc.ParseProxyResponse(packet)
89
 		response, err := rpc.ParseProxyResponse(packet)
91
 		if err != nil {
90
 		if err != nil {
92
 			c.logger.Debugw("Failed response", "error", err)
91
 			c.logger.Debugw("Failed response", "error", err)
92
+
93
 			continue
93
 			continue
94
 		}
94
 		}
95
 
95
 

+ 1
- 0
hub/connection_list.go Просмотреть файл

25
 
25
 
26
 	if err = newConn.Attach(conn); err != nil {
26
 	if err = newConn.Attach(conn); err != nil {
27
 		newConn.Close()
27
 		newConn.Close()
28
+
28
 		return nil, fmt.Errorf("cannot attach to the newly created connection: %w", err)
29
 		return nil, fmt.Errorf("cannot attach to the newly created connection: %w", err)
29
 	}
30
 	}
30
 
31
 

+ 1
- 2
main.go Просмотреть файл

7
 	"strings"
7
 	"strings"
8
 	"time"
8
 	"time"
9
 
9
 
10
-	kingpin "gopkg.in/alecthomas/kingpin.v2"
11
-
12
 	"github.com/9seconds/mtg/cli"
10
 	"github.com/9seconds/mtg/cli"
13
 	"github.com/9seconds/mtg/config"
11
 	"github.com/9seconds/mtg/config"
14
 	"github.com/9seconds/mtg/utils"
12
 	"github.com/9seconds/mtg/utils"
13
+	kingpin "gopkg.in/alecthomas/kingpin.v2"
15
 )
14
 )
16
 
15
 
17
 var version = "dev" // has to be set by ldflags
16
 var version = "dev" // has to be set by ldflags

+ 1
- 1
mtproto/protocol.go Просмотреть файл

19
 	}
19
 	}
20
 
20
 
21
 	rpcNonceConn := packet.NewMtprotoFrame(conn, rpc.SeqNoNonce)
21
 	rpcNonceConn := packet.NewMtprotoFrame(conn, rpc.SeqNoNonce)
22
-	rpcNonceReq, err := doRPCNonceRequest(rpcNonceConn)
23
 
22
 
23
+	rpcNonceReq, err := doRPCNonceRequest(rpcNonceConn)
24
 	if err != nil {
24
 	if err != nil {
25
 		return nil, fmt.Errorf("cannot do nonce request: %w", err)
25
 		return nil, fmt.Errorf("cannot do nonce request: %w", err)
26
 	}
26
 	}

+ 1
- 1
mtproto/rpc/consts.go Просмотреть файл

7
 	SeqNoHandshake = -1
7
 	SeqNoHandshake = -1
8
 )
8
 )
9
 
9
 
10
-// Different constants for RPC protocol
10
+// Different constants for RPC protocol.
11
 var (
11
 var (
12
 	TagCloseExt     = []byte{0xa2, 0x34, 0xb6, 0x5e}
12
 	TagCloseExt     = []byte{0xa2, 0x34, 0xb6, 0x5e}
13
 	TagProxyAns     = []byte{0x0d, 0xda, 0x03, 0x44}
13
 	TagProxyAns     = []byte{0x0d, 0xda, 0x03, 0x44}

+ 4
- 4
mtproto/rpc/handshake_response.go Просмотреть файл

17
 func (r *HandshakeResponse) Bytes() []byte {
17
 func (r *HandshakeResponse) Bytes() []byte {
18
 	buf := &bytes.Buffer{}
18
 	buf := &bytes.Buffer{}
19
 
19
 
20
-	buf.Write(r.Type)      // nolint: gosec
21
-	buf.Write(r.Flags)     // nolint: gosec
22
-	buf.Write(r.SenderPID) // nolint: gosec
23
-	buf.Write(r.PeerPID)   // nolint: gosec
20
+	buf.Write(r.Type)
21
+	buf.Write(r.Flags)
22
+	buf.Write(r.SenderPID)
23
+	buf.Write(r.PeerPID)
24
 
24
 
25
 	return buf.Bytes()
25
 	return buf.Bytes()
26
 }
26
 }

+ 6
- 6
mtproto/rpc/nonce_response.go Просмотреть файл

15
 
15
 
16
 // Bytes returns serialized form of the nonce response.
16
 // Bytes returns serialized form of the nonce response.
17
 func (r *NonceResponse) Bytes() []byte {
17
 func (r *NonceResponse) Bytes() []byte {
18
-	buf := &bytes.Buffer{}
18
+	buf := bytes.Buffer{}
19
 
19
 
20
-	buf.Write(r.Type)        // nolint: gosec
21
-	buf.Write(r.KeySelector) // nolint: gosec
22
-	buf.Write(r.Crypto)      // nolint: gosec
23
-	buf.Write(r.CryptoTS)    // nolint: gosec
24
-	buf.Write(r.Nonce)       // nolint: gosec
20
+	buf.Write(r.Type)
21
+	buf.Write(r.KeySelector)
22
+	buf.Write(r.Crypto)
23
+	buf.Write(r.CryptoTS)
24
+	buf.Write(r.Nonce)
25
 
25
 
26
 	return buf.Bytes()
26
 	return buf.Bytes()
27
 }
27
 }

+ 3
- 3
ntp/ntp.go Просмотреть файл

5
 	"math/rand"
5
 	"math/rand"
6
 	"time"
6
 	"time"
7
 
7
 
8
+	"github.com/9seconds/mtg/config"
8
 	"github.com/beevik/ntp"
9
 	"github.com/beevik/ntp"
9
 	"go.uber.org/zap"
10
 	"go.uber.org/zap"
10
-
11
-	"github.com/9seconds/mtg/config"
12
 )
11
 )
13
 
12
 
14
 const autoUpdatePeriod = time.Minute
13
 const autoUpdatePeriod = time.Minute
15
 
14
 
16
 // Fetch fetches the data on time drift.
15
 // Fetch fetches the data on time drift.
17
 func Fetch() (time.Duration, error) {
16
 func Fetch() (time.Duration, error) {
18
-	url := config.C.NTPServers[rand.Intn(len(config.C.NTPServers))]
17
+	url := config.C.NTPServers[rand.Intn(len(config.C.NTPServers))] // nolint: gosec
19
 
18
 
20
 	resp, err := ntp.Query(url)
19
 	resp, err := ntp.Query(url)
21
 	if err != nil {
20
 	if err != nil {
40
 		diff, err := Fetch()
39
 		diff, err := Fetch()
41
 		if err != nil {
40
 		if err != nil {
42
 			logger.Debugw("Cannot fetch time from NTP", "error", err)
41
 			logger.Debugw("Cannot fetch time from NTP", "error", err)
42
+
43
 			continue
43
 			continue
44
 		}
44
 		}
45
 
45
 

+ 1
- 0
obfuscated2/client_protocol.go Просмотреть файл

84
 	replayKey := decryptedFrame.Unique()
84
 	replayKey := decryptedFrame.Unique()
85
 	if antireplay.Cache.HasObfuscated2(replayKey) {
85
 	if antireplay.Cache.HasObfuscated2(replayKey) {
86
 		stats.Stats.ReplayDetected()
86
 		stats.Stats.ReplayDetected()
87
+
87
 		return nil, errors.New("replay attack is detected")
88
 		return nil, errors.New("replay attack is detected")
88
 	}
89
 	}
89
 
90
 

+ 1
- 1
obfuscated2/frame.go Просмотреть файл

15
 	frameLen = 64
15
 	frameLen = 64
16
 )
16
 )
17
 
17
 
18
-// [frameOffsetFirst:frameOffsetKey:frameOffsetIV:frameOffsetMagic:frameOffsetDC:frameOffsetEnd]
18
+// [frameOffsetFirst:frameOffsetKey:frameOffsetIV:frameOffsetMagic:frameOffsetDC:frameOffsetEnd].
19
 type Frame struct {
19
 type Frame struct {
20
 	data [frameLen]byte
20
 	data [frameLen]byte
21
 }
21
 }

+ 1
- 2
protocol/request.go Просмотреть файл

3
 import (
3
 import (
4
 	"context"
4
 	"context"
5
 
5
 
6
-	"go.uber.org/zap"
7
-
8
 	"github.com/9seconds/mtg/conntypes"
6
 	"github.com/9seconds/mtg/conntypes"
7
+	"go.uber.org/zap"
9
 )
8
 )
10
 
9
 
11
 type TelegramRequest struct {
10
 type TelegramRequest struct {

+ 1
- 2
proxy/direct.go Просмотреть файл

4
 	"io"
4
 	"io"
5
 	"sync"
5
 	"sync"
6
 
6
 
7
-	"go.uber.org/zap"
8
-
9
 	"github.com/9seconds/mtg/conntypes"
7
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/obfuscated2"
8
 	"github.com/9seconds/mtg/obfuscated2"
11
 	"github.com/9seconds/mtg/protocol"
9
 	"github.com/9seconds/mtg/protocol"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 const directPipeBufferSize = 1024
13
 const directPipeBufferSize = 1024

+ 6
- 4
proxy/middle.go Просмотреть файл

3
 import (
3
 import (
4
 	"sync"
4
 	"sync"
5
 
5
 
6
-	"go.uber.org/zap"
7
-
8
 	"github.com/9seconds/mtg/conntypes"
6
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/protocol"
7
 	"github.com/9seconds/mtg/protocol"
10
 	"github.com/9seconds/mtg/wrappers/packetack"
8
 	"github.com/9seconds/mtg/wrappers/packetack"
9
+	"go.uber.org/zap"
11
 )
10
 )
12
 
11
 
13
 func middleConnection(request *protocol.TelegramRequest) {
12
 func middleConnection(request *protocol.TelegramRequest) {
14
 	telegramConn, err := packetack.NewProxy(request)
13
 	telegramConn, err := packetack.NewProxy(request)
15
 	if err != nil {
14
 	if err != nil {
16
 		request.Logger.Debugw("Cannot dial to Telegram", "error", err)
15
 		request.Logger.Debugw("Cannot dial to Telegram", "error", err)
16
+
17
 		return
17
 		return
18
 	}
18
 	}
19
 	defer telegramConn.Close()
19
 	defer telegramConn.Close()
27
 		clientConn = packetack.NewClientIntermediate(request.ClientConn)
27
 		clientConn = packetack.NewClientIntermediate(request.ClientConn)
28
 	case conntypes.ConnectionTypeSecure:
28
 	case conntypes.ConnectionTypeSecure:
29
 		clientConn = packetack.NewClientIntermediateSecure(request.ClientConn)
29
 		clientConn = packetack.NewClientIntermediateSecure(request.ClientConn)
30
-	default:
30
+	case conntypes.ConnectionTypeUnknown:
31
 		panic("unknown connection type")
31
 		panic("unknown connection type")
32
 	}
32
 	}
33
 
33
 
53
 
53
 
54
 	for {
54
 	for {
55
 		acks := conntypes.ConnectionAcks{}
55
 		acks := conntypes.ConnectionAcks{}
56
-		packet, err := src.Read(&acks)
57
 
56
 
57
+		packet, err := src.Read(&acks)
58
 		if err != nil {
58
 		if err != nil {
59
 			logger.Debugw("Cannot read packet", "error", err)
59
 			logger.Debugw("Cannot read packet", "error", err)
60
+
60
 			return
61
 			return
61
 		}
62
 		}
62
 
63
 
63
 		if err = dst.Write(packet, &acks); err != nil {
64
 		if err = dst.Write(packet, &acks); err != nil {
64
 			logger.Debugw("Cannot send packet", "error", err)
65
 			logger.Debugw("Cannot send packet", "error", err)
66
+
65
 			return
67
 			return
66
 		}
68
 		}
67
 	}
69
 	}

+ 3
- 3
proxy/proxy.go Просмотреть файл

4
 	"context"
4
 	"context"
5
 	"net"
5
 	"net"
6
 
6
 
7
-	"go.uber.org/zap"
8
-
9
 	"github.com/9seconds/mtg/config"
7
 	"github.com/9seconds/mtg/config"
10
 	"github.com/9seconds/mtg/conntypes"
8
 	"github.com/9seconds/mtg/conntypes"
11
 	"github.com/9seconds/mtg/protocol"
9
 	"github.com/9seconds/mtg/protocol"
12
 	"github.com/9seconds/mtg/stats"
10
 	"github.com/9seconds/mtg/stats"
13
 	"github.com/9seconds/mtg/utils"
11
 	"github.com/9seconds/mtg/utils"
14
 	"github.com/9seconds/mtg/wrappers/stream"
12
 	"github.com/9seconds/mtg/wrappers/stream"
13
+	"go.uber.org/zap"
15
 )
14
 )
16
 
15
 
17
 type Proxy struct {
16
 type Proxy struct {
53
 
52
 
54
 	if err := utils.InitTCP(conn, config.C.ClientReadBuffer(), config.C.ClientWriteBuffer()); err != nil {
53
 	if err := utils.InitTCP(conn, config.C.ClientReadBuffer(), config.C.ClientWriteBuffer()); err != nil {
55
 		logger.Errorw("Cannot initialize client TCP connection", "error", err)
54
 		logger.Errorw("Cannot initialize client TCP connection", "error", err)
55
+
56
 		return
56
 		return
57
 	}
57
 	}
58
 
58
 
66
 	defer clientConn.Close()
66
 	defer clientConn.Close()
67
 
67
 
68
 	clientProtocol := p.ClientProtocolMaker()
68
 	clientProtocol := p.ClientProtocolMaker()
69
-	clientConn, err := clientProtocol.Handshake(clientConn)
70
 
69
 
70
+	clientConn, err := clientProtocol.Handshake(clientConn)
71
 	if err != nil {
71
 	if err != nil {
72
 		stats.Stats.AuthenticationFailed()
72
 		stats.Stats.AuthenticationFailed()
73
 		logger.Warnw("Cannot perform client handshake", "error", err)
73
 		logger.Warnw("Cannot perform client handshake", "error", err)

+ 7
- 4
stats/stats_prometheus.go Просмотреть файл

5
 	"net/http"
5
 	"net/http"
6
 	"strconv"
6
 	"strconv"
7
 
7
 
8
-	"github.com/prometheus/client_golang/prometheus"
9
-	"github.com/prometheus/client_golang/prometheus/promhttp"
10
-
11
 	"github.com/9seconds/mtg/config"
8
 	"github.com/9seconds/mtg/config"
12
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
10
+	"github.com/prometheus/client_golang/prometheus"
11
+	"github.com/prometheus/client_golang/prometheus/promhttp"
13
 )
12
 )
14
 
13
 
15
 type statsPrometheus struct {
14
 type statsPrometheus struct {
51
 		labels[0] = "abridged"
50
 		labels[0] = "abridged"
52
 	case conntypes.ConnectionTypeSecure:
51
 	case conntypes.ConnectionTypeSecure:
53
 		labels[0] = "secured"
52
 		labels[0] = "secured"
53
+	case conntypes.ConnectionTypeIntermediate:
54
+		labels[0] = "intermediate"
55
+	case conntypes.ConnectionTypeUnknown:
56
+		panic("unknown connection type")
54
 	}
57
 	}
55
 
58
 
56
 	if addr.IP.To4() == nil {
59
 	if addr.IP.To4() == nil {
57
-		labels[1] = "ipv6" // nolint: goconst
60
+		labels[1] = "ipv6"
58
 	}
61
 	}
59
 
62
 
60
 	s.connections.WithLabelValues(labels[:]...).Add(increment)
63
 	s.connections.WithLabelValues(labels[:]...).Add(increment)

+ 5
- 4
stats/stats_statsd.go Просмотреть файл

8
 	"sync"
8
 	"sync"
9
 	"time"
9
 	"time"
10
 
10
 
11
-	statsd "github.com/smira/go-statsd"
12
-	"go.uber.org/zap"
13
-
14
 	"github.com/9seconds/mtg/config"
11
 	"github.com/9seconds/mtg/config"
15
 	"github.com/9seconds/mtg/conntypes"
12
 	"github.com/9seconds/mtg/conntypes"
13
+	statsd "github.com/smira/go-statsd"
14
+	"go.uber.org/zap"
16
 )
15
 )
17
 
16
 
18
 var (
17
 var (
91
 		tags = append(tags, tagConnectionTypeAbridged)
90
 		tags = append(tags, tagConnectionTypeAbridged)
92
 	case conntypes.ConnectionTypeIntermediate:
91
 	case conntypes.ConnectionTypeIntermediate:
93
 		tags = append(tags, tagConnectionTypeIntermediate)
92
 		tags = append(tags, tagConnectionTypeIntermediate)
94
-	default:
93
+	case conntypes.ConnectionTypeSecure:
95
 		tags = append(tags, tagConnectionTypeSecured)
94
 		tags = append(tags, tagConnectionTypeSecured)
95
+	case conntypes.ConnectionTypeUnknown:
96
+		panic("Unknown connection type")
96
 	}
97
 	}
97
 
98
 
98
 	if addr.IP.To4() == nil {
99
 	if addr.IP.To4() == nil {

+ 5
- 1
telegram/api/api.go Просмотреть файл

1
 package api
1
 package api
2
 
2
 
3
 import (
3
 import (
4
+	"context"
4
 	"fmt"
5
 	"fmt"
5
 	"io"
6
 	"io"
6
 	"io/ioutil"
7
 	"io/ioutil"
18
 }
19
 }
19
 
20
 
20
 func request(url string) (io.ReadCloser, error) {
21
 func request(url string) (io.ReadCloser, error) {
21
-	req, err := http.NewRequest("GET", url, nil)
22
+	ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout)
23
+	defer cancel()
24
+
25
+	req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
22
 	if err != nil {
26
 	if err != nil {
23
 		panic(err)
27
 		panic(err)
24
 	}
28
 	}

+ 4
- 3
telegram/base.go Просмотреть файл

5
 	"math/rand"
5
 	"math/rand"
6
 	"net"
6
 	"net"
7
 
7
 
8
-	"go.uber.org/zap"
9
-
10
 	"github.com/9seconds/mtg/config"
8
 	"github.com/9seconds/mtg/config"
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
12
 	"github.com/9seconds/mtg/utils"
10
 	"github.com/9seconds/mtg/utils"
13
 	"github.com/9seconds/mtg/wrappers/stream"
11
 	"github.com/9seconds/mtg/wrappers/stream"
12
+	"go.uber.org/zap"
14
 )
13
 )
15
 
14
 
16
 type baseTelegram struct {
15
 type baseTelegram struct {
34
 		conn, err := b.dialer.Dial("tcp", addr)
33
 		conn, err := b.dialer.Dial("tcp", addr)
35
 		if err != nil {
34
 		if err != nil {
36
 			b.logger.Infow("Cannot dial to Telegram", "address", addr, "error", err)
35
 			b.logger.Infow("Cannot dial to Telegram", "address", addr, "error", err)
36
+
37
 			continue
37
 			continue
38
 		}
38
 		}
39
 
39
 
40
 		if err := utils.InitTCP(conn, config.C.ProxyReadBuffer(), config.C.ProxyWriteBuffer()); err != nil {
40
 		if err := utils.InitTCP(conn, config.C.ProxyReadBuffer(), config.C.ProxyWriteBuffer()); err != nil {
41
 			b.logger.Infow("Cannot initialize TCP socket", "address", addr, "error", err)
41
 			b.logger.Infow("Cannot initialize TCP socket", "address", addr, "error", err)
42
+
42
 			continue
43
 			continue
43
 		}
44
 		}
44
 
45
 
83
 	case len(addrs) == 1:
84
 	case len(addrs) == 1:
84
 		return addrs[0]
85
 		return addrs[0]
85
 	case len(addrs) > 1:
86
 	case len(addrs) > 1:
86
-		return addrs[rand.Intn(len(addrs))]
87
+		return addrs[rand.Intn(len(addrs))] // nolint: gosec
87
 	}
88
 	}
88
 
89
 
89
 	return ""
90
 	return ""

+ 1
- 2
telegram/middle.go Просмотреть файл

5
 	"sync"
5
 	"sync"
6
 	"time"
6
 	"time"
7
 
7
 
8
-	"go.uber.org/zap"
9
-
10
 	"github.com/9seconds/mtg/conntypes"
8
 	"github.com/9seconds/mtg/conntypes"
11
 	"github.com/9seconds/mtg/telegram/api"
9
 	"github.com/9seconds/mtg/telegram/api"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 const middleTelegramBackgroundUpdateEvery = time.Hour
13
 const middleTelegramBackgroundUpdateEvery = time.Hour

+ 10
- 6
tlstypes/consts.go Просмотреть файл

20
 type CipherSuiteType uint8
20
 type CipherSuiteType uint8
21
 
21
 
22
 const (
22
 const (
23
-	CipherSuiteType_TLS_AES_128_GCM_SHA256       CipherSuiteType = iota // nolint: stylecheck, golint
24
-	CipherSuiteType_TLS_AES_256_GCM_SHA384                              // nolint: stylecheck, golint
25
-	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256                        // nolint: stylecheck, golint
23
+	CipherSuiteType_TLS_AES_128_GCM_SHA256       CipherSuiteType = iota // nolint: stylecheck,golint
24
+	CipherSuiteType_TLS_AES_256_GCM_SHA384                              // nolint: stylecheck,golint
25
+	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256                        // nolint: stylecheck,golint
26
 )
26
 )
27
 
27
 
28
 func (c CipherSuiteType) Bytes() []byte {
28
 func (c CipherSuiteType) Bytes() []byte {
31
 		return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes
31
 		return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes
32
 	case CipherSuiteType_TLS_AES_256_GCM_SHA384:
32
 	case CipherSuiteType_TLS_AES_256_GCM_SHA384:
33
 		return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes
33
 		return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes
34
+	case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256:
35
+		return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes
34
 	}
36
 	}
35
 
37
 
36
 	return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes
38
 	return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes
46
 		return Version12Bytes
48
 		return Version12Bytes
47
 	case Version11:
49
 	case Version11:
48
 		return Version11Bytes
50
 		return Version11Bytes
51
+	case Version10, VersionUnknown:
52
+		return Version10Bytes
49
 	}
53
 	}
50
 
54
 
51
 	return Version10Bytes
55
 	return Version10Bytes
65
 	Version12Bytes = []byte{0x03, 0x03}
69
 	Version12Bytes = []byte{0x03, 0x03}
66
 	Version13Bytes = []byte{0x03, 0x04}
70
 	Version13Bytes = []byte{0x03, 0x04}
67
 
71
 
68
-	CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes       = []byte{0x13, 0x01} // nolint: stylecheck, golint
69
-	CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes       = []byte{0x13, 0x02} // nolint: stylecheck, golint
70
-	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint; stylecheck, golint
72
+	CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes       = []byte{0x13, 0x01} // nolint: stylecheck,golint
73
+	CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes       = []byte{0x13, 0x02} // nolint: stylecheck,golint
74
+	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint
71
 )
75
 )
72
 
76
 
73
 type Byter interface {
77
 type Byter interface {

+ 3
- 4
tlstypes/server_hello.go Просмотреть файл

8
 	"io"
8
 	"io"
9
 	mrand "math/rand"
9
 	mrand "math/rand"
10
 
10
 
11
-	"golang.org/x/crypto/curve25519"
12
-
13
 	"github.com/9seconds/mtg/config"
11
 	"github.com/9seconds/mtg/config"
12
+	"golang.org/x/crypto/curve25519"
14
 )
13
 )
15
 
14
 
16
 type ServerHello struct {
15
 type ServerHello struct {
37
 	}
36
 	}
38
 	recChangeCipher.WriteBytes(buf)
37
 	recChangeCipher.WriteBytes(buf)
39
 
38
 
40
-	hostCert := make([]byte, 1024+mrand.Intn(3092))
41
-	rand.Read(hostCert) // nolint: errcheck
39
+	hostCert := make([]byte, 1024+mrand.Intn(3092)) // nolint: gosec
40
+	rand.Read(hostCert)                             // nolint: errcheck
42
 
41
 
43
 	recData := Record{
42
 	recData := Record{
44
 		Type:    RecordTypeApplicationData,
43
 		Type:    RecordTypeApplicationData,

+ 2
- 1
utils/stream_cipher.go Просмотреть файл

6
 )
6
 )
7
 
7
 
8
 func MakeStreamCipher(key, iv []byte) cipher.Stream {
8
 func MakeStreamCipher(key, iv []byte) cipher.Stream {
9
-	block, _ := aes.NewCipher(key) // nolint: gosec
9
+	block, _ := aes.NewCipher(key)
10
+
10
 	return cipher.NewCTR(block, iv)
11
 	return cipher.NewCTR(block, iv)
11
 }
12
 }

+ 2
- 3
wrappers/packet/mtproto_frame.go Просмотреть файл

10
 	"io/ioutil"
10
 	"io/ioutil"
11
 	"net"
11
 	"net"
12
 
12
 
13
-	"go.uber.org/zap"
14
-
15
 	"github.com/9seconds/mtg/conntypes"
13
 	"github.com/9seconds/mtg/conntypes"
14
+	"go.uber.org/zap"
16
 )
15
 )
17
 
16
 
18
 const (
17
 const (
85
 		return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo)
84
 		return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo)
86
 	}
85
 	}
87
 
86
 
88
-	data, _ := ioutil.ReadAll(buf) // nolint: gosec
87
+	data, _ := ioutil.ReadAll(buf)
89
 	buf.Reset()
88
 	buf.Reset()
90
 	// write to buf, not to writer. This is because we are going to fetch
89
 	// write to buf, not to writer. This is because we are going to fetch
91
 	// crc32 checksum.
90
 	// crc32 checksum.

+ 1
- 2
wrappers/packetack/client_abridged.go Просмотреть файл

6
 	"io"
6
 	"io"
7
 	"net"
7
 	"net"
8
 
8
 
9
-	"go.uber.org/zap"
10
-
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
12
 	"github.com/9seconds/mtg/utils"
10
 	"github.com/9seconds/mtg/utils"
11
+	"go.uber.org/zap"
13
 )
12
 )
14
 
13
 
15
 const (
14
 const (

+ 1
- 2
wrappers/packetack/client_intermediate.go Просмотреть файл

7
 	"io"
7
 	"io"
8
 	"net"
8
 	"net"
9
 
9
 
10
-	"go.uber.org/zap"
11
-
12
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/conntypes"
11
+	"go.uber.org/zap"
13
 )
12
 )
14
 
13
 
15
 const clientIntermediateQuickAckLength = 0x80000000
14
 const clientIntermediateQuickAckLength = 0x80000000

+ 2
- 3
wrappers/packetack/client_intermediate_secure.go Просмотреть файл

6
 	"fmt"
6
 	"fmt"
7
 	"math/rand"
7
 	"math/rand"
8
 
8
 
9
-	"go.uber.org/zap"
10
-
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 type wrapperClientIntermediateSecure struct {
13
 type wrapperClientIntermediateSecure struct {
36
 	}
35
 	}
37
 
36
 
38
 	buf := &bytes.Buffer{}
37
 	buf := &bytes.Buffer{}
39
-	paddingLength := rand.Intn(4)
38
+	paddingLength := rand.Intn(4) // nolint: gosec
40
 
39
 
41
 	buf.Grow(4 + len(packet) + paddingLength)
40
 	buf.Grow(4 + len(packet) + paddingLength)
42
 
41
 

+ 2
- 1
wrappers/packetack/proxy.go Просмотреть файл

64
 
64
 
65
 func (w *wrapperProxy) Close() error {
65
 func (w *wrapperProxy) Close() error {
66
 	w.proxy.Close()
66
 	w.proxy.Close()
67
+
67
 	return nil
68
 	return nil
68
 }
69
 }
69
 
70
 
77
 		flags |= rpc.ProxyRequestFlagsIntermediate
78
 		flags |= rpc.ProxyRequestFlagsIntermediate
78
 	case conntypes.ConnectionTypeSecure:
79
 	case conntypes.ConnectionTypeSecure:
79
 		flags |= rpc.ProxyRequestFlagsIntermediate | rpc.ProxyRequestFlagsPad
80
 		flags |= rpc.ProxyRequestFlagsIntermediate | rpc.ProxyRequestFlagsPad
80
-	default:
81
+	case conntypes.ConnectionTypeUnknown:
81
 		panic("unknown connection type")
82
 		panic("unknown connection type")
82
 	}
83
 	}
83
 
84
 

+ 1
- 2
wrappers/stream/blockcipher.go Просмотреть файл

7
 	"net"
7
 	"net"
8
 	"time"
8
 	"time"
9
 
9
 
10
-	"go.uber.org/zap"
11
-
12
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/conntypes"
13
 	"github.com/9seconds/mtg/utils"
11
 	"github.com/9seconds/mtg/utils"
12
+	"go.uber.org/zap"
14
 )
13
 )
15
 
14
 
16
 type wrapperBlockCipher struct {
15
 type wrapperBlockCipher struct {

+ 5
- 3
wrappers/stream/conn.go Просмотреть файл

5
 	"net"
5
 	"net"
6
 	"time"
6
 	"time"
7
 
7
 
8
-	"go.uber.org/zap"
9
-
10
 	"github.com/9seconds/mtg/config"
8
 	"github.com/9seconds/mtg/config"
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 type connPurpose uint8
13
 type connPurpose uint8
29
 func (w *wrapperConn) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
28
 func (w *wrapperConn) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
30
 	if err := w.parent.SetWriteDeadline(time.Now().Add(timeout)); err != nil {
29
 	if err := w.parent.SetWriteDeadline(time.Now().Add(timeout)); err != nil {
31
 		w.Close()
30
 		w.Close()
31
+
32
 		return 0, fmt.Errorf("cannot set write deadline to the socket: %w", err)
32
 		return 0, fmt.Errorf("cannot set write deadline to the socket: %w", err)
33
 	}
33
 	}
34
 
34
 
40
 	w.logger.Debugw("write to stream", "bytes", n, "error", err)
40
 	w.logger.Debugw("write to stream", "bytes", n, "error", err)
41
 
41
 
42
 	if err != nil {
42
 	if err != nil {
43
-		w.Close() // nolint: gosec
43
+		w.Close()
44
 	}
44
 	}
45
 
45
 
46
 	return n, err
46
 	return n, err
49
 func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
49
 func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
50
 	if err := w.parent.SetReadDeadline(time.Now().Add(timeout)); err != nil {
50
 	if err := w.parent.SetReadDeadline(time.Now().Add(timeout)); err != nil {
51
 		w.Close()
51
 		w.Close()
52
+
52
 		return 0, fmt.Errorf("cannot set read deadline to the socket: %w", err)
53
 		return 0, fmt.Errorf("cannot set read deadline to the socket: %w", err)
53
 	}
54
 	}
54
 
55
 
68
 
69
 
69
 func (w *wrapperConn) Close() error {
70
 func (w *wrapperConn) Close() error {
70
 	w.logger.Debugw("Close connection")
71
 	w.logger.Debugw("Close connection")
72
+
71
 	return w.parent.Close()
73
 	return w.parent.Close()
72
 }
74
 }
73
 
75
 

+ 6
- 2
wrappers/stream/ctx.go Просмотреть файл

6
 	"net"
6
 	"net"
7
 	"time"
7
 	"time"
8
 
8
 
9
-	"go.uber.org/zap"
10
-
11
 	"github.com/9seconds/mtg/conntypes"
9
 	"github.com/9seconds/mtg/conntypes"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 type wrapperCtx struct {
13
 type wrapperCtx struct {
21
 	select {
20
 	select {
22
 	case <-w.ctx.Done():
21
 	case <-w.ctx.Done():
23
 		w.Close()
22
 		w.Close()
23
+
24
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
24
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
25
 	default:
25
 	default:
26
 		return w.parent.WriteTimeout(p, timeout)
26
 		return w.parent.WriteTimeout(p, timeout)
31
 	select {
31
 	select {
32
 	case <-w.ctx.Done():
32
 	case <-w.ctx.Done():
33
 		w.Close()
33
 		w.Close()
34
+
34
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
35
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
35
 	default:
36
 	default:
36
 		return w.parent.Write(p)
37
 		return w.parent.Write(p)
41
 	select {
42
 	select {
42
 	case <-w.ctx.Done():
43
 	case <-w.ctx.Done():
43
 		w.Close()
44
 		w.Close()
45
+
44
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
46
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
45
 	default:
47
 	default:
46
 		return w.parent.ReadTimeout(p, timeout)
48
 		return w.parent.ReadTimeout(p, timeout)
51
 	select {
53
 	select {
52
 	case <-w.ctx.Done():
54
 	case <-w.ctx.Done():
53
 		w.Close()
55
 		w.Close()
56
+
54
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
57
 		return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
55
 	default:
58
 	default:
56
 		return w.parent.Read(p)
59
 		return w.parent.Read(p)
59
 
62
 
60
 func (w *wrapperCtx) Close() error {
63
 func (w *wrapperCtx) Close() error {
61
 	w.cancel()
64
 	w.cancel()
65
+
62
 	return w.parent.Close()
66
 	return w.parent.Close()
63
 }
67
 }
64
 
68
 

+ 4
- 2
wrappers/stream/faketls.go Просмотреть файл

7
 	"net"
7
 	"net"
8
 	"time"
8
 	"time"
9
 
9
 
10
-	"go.uber.org/zap"
11
-
12
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/conntypes"
13
 	"github.com/9seconds/mtg/tlstypes"
11
 	"github.com/9seconds/mtg/tlstypes"
12
+	"go.uber.org/zap"
14
 )
13
 )
15
 
14
 
16
 type wrapperFakeTLS struct {
15
 type wrapperFakeTLS struct {
33
 		if elapsed > timeout {
32
 		if elapsed > timeout {
34
 			return w.parent.WriteTimeout(b, timeout-elapsed)
33
 			return w.parent.WriteTimeout(b, timeout-elapsed)
35
 		}
34
 		}
35
+
36
 		return 0, errors.New("timeout")
36
 		return 0, errors.New("timeout")
37
 	})
37
 	})
38
 }
38
 }
95
 				rec.Data.WriteBytes(buf)
95
 				rec.Data.WriteBytes(buf)
96
 
96
 
97
 				return buf.Bytes(), nil
97
 				return buf.Bytes(), nil
98
+			case tlstypes.RecordTypeHandshake:
99
+				return nil, errors.New("unsupported record type handshake")
98
 			default:
100
 			default:
99
 				return nil, fmt.Errorf("unsupported record type %v", rec.Type)
101
 				return nil, fmt.Errorf("unsupported record type %v", rec.Type)
100
 			}
102
 			}

+ 16
- 17
wrappers/stream/mtproto_cipher.go Просмотреть файл

4
 	"bytes"
4
 	"bytes"
5
 	"crypto/aes"
5
 	"crypto/aes"
6
 	"crypto/cipher"
6
 	"crypto/cipher"
7
-	"crypto/md5"  // nolint: gosec
8
-	"crypto/sha1" // nolint: gosec
7
+	"crypto/md5"
8
+	"crypto/sha1"
9
 	"encoding/binary"
9
 	"encoding/binary"
10
 	"net"
10
 	"net"
11
 
11
 
54
 	resp *rpc.NonceResponse,
54
 	resp *rpc.NonceResponse,
55
 	client, remote *net.TCPAddr,
55
 	client, remote *net.TCPAddr,
56
 	secret []byte) ([]byte, []byte) {
56
 	secret []byte) ([]byte, []byte) {
57
-
58
 	message := bytes.Buffer{}
57
 	message := bytes.Buffer{}
59
 
58
 
60
-	message.Write(resp.Nonce)   // nolint: gosec
61
-	message.Write(req.Nonce)    // nolint: gosec
62
-	message.Write(req.CryptoTS) // nolint: gosec
59
+	message.Write(resp.Nonce)
60
+	message.Write(req.Nonce)
61
+	message.Write(req.CryptoTS)
63
 
62
 
64
 	clientIPv4 := mtprotoEmptyIP[:]
63
 	clientIPv4 := mtprotoEmptyIP[:]
65
 	serverIPv4 := mtprotoEmptyIP[:]
64
 	serverIPv4 := mtprotoEmptyIP[:]
69
 		serverIPv4 = utils.ReverseBytes(remote.IP.To4())
68
 		serverIPv4 = utils.ReverseBytes(remote.IP.To4())
70
 	}
69
 	}
71
 
70
 
72
-	message.Write(serverIPv4) // nolint: gosec
71
+	message.Write(serverIPv4)
73
 
72
 
74
 	var port [2]byte
73
 	var port [2]byte
75
 
74
 
76
 	binary.LittleEndian.PutUint16(port[:], uint16(client.Port))
75
 	binary.LittleEndian.PutUint16(port[:], uint16(client.Port))
77
-	message.Write(port[:]) // nolint: gosec
76
+	message.Write(port[:])
78
 
77
 
79
 	switch purpose {
78
 	switch purpose {
80
 	case mtprotoCipherPurposeClient:
79
 	case mtprotoCipherPurposeClient:
81
-		message.WriteString("CLIENT") // nolint: gosec
80
+		message.WriteString("CLIENT")
82
 	case mtprotoCipherPurposeServer:
81
 	case mtprotoCipherPurposeServer:
83
-		message.WriteString("SERVER") // nolint: gosec
82
+		message.WriteString("SERVER")
84
 	default:
83
 	default:
85
 		panic("Unexpected cipher purpose")
84
 		panic("Unexpected cipher purpose")
86
 	}
85
 	}
87
 
86
 
88
-	message.Write(clientIPv4) // nolint: gosec
87
+	message.Write(clientIPv4)
89
 	binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
88
 	binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
90
-	message.Write(port[:])    // nolint: gosec
91
-	message.Write(secret)     // nolint: gosec
92
-	message.Write(resp.Nonce) // nolint: gosec
89
+	message.Write(port[:])
90
+	message.Write(secret)
91
+	message.Write(resp.Nonce)
93
 
92
 
94
 	if client.IP.To4() == nil {
93
 	if client.IP.To4() == nil {
95
-		message.Write(client.IP.To16()) // nolint: gosec
96
-		message.Write(remote.IP.To16()) // nolint: gosec
94
+		message.Write(client.IP.To16())
95
+		message.Write(remote.IP.To16())
97
 	}
96
 	}
98
 
97
 
99
-	message.Write(req.Nonce) // nolint: gosec
98
+	message.Write(req.Nonce)
100
 
99
 
101
 	data := message.Bytes()
100
 	data := message.Bytes()
102
 	md5sum := md5.Sum(data[1:]) // nolint: gas
101
 	md5sum := md5.Sum(data[1:]) // nolint: gas

+ 1
- 2
wrappers/stream/obfuscated2.go Просмотреть файл

7
 	"net"
7
 	"net"
8
 	"time"
8
 	"time"
9
 
9
 
10
-	"go.uber.org/zap"
11
-
12
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/conntypes"
11
+	"go.uber.org/zap"
13
 )
12
 )
14
 
13
 
15
 type wrapperObfuscated2 struct {
14
 type wrapperObfuscated2 struct {

+ 2
- 2
wrappers/stream/rewind.go Просмотреть файл

7
 	"sync"
7
 	"sync"
8
 	"time"
8
 	"time"
9
 
9
 
10
-	"go.uber.org/zap"
11
-
12
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/conntypes"
11
+	"go.uber.org/zap"
13
 )
12
 )
14
 
13
 
15
 type ReadWriteCloseRewinder interface {
14
 type ReadWriteCloseRewinder interface {
88
 
87
 
89
 func (w *wrapperRewind) Close() error {
88
 func (w *wrapperRewind) Close() error {
90
 	w.buf.Reset()
89
 	w.buf.Reset()
90
+
91
 	return w.parent.Close()
91
 	return w.parent.Close()
92
 }
92
 }
93
 
93
 

+ 1
- 2
wrappers/stream/stats_telegram.go Просмотреть файл

5
 	"sync"
5
 	"sync"
6
 	"time"
6
 	"time"
7
 
7
 
8
-	"go.uber.org/zap"
9
-
10
 	"github.com/9seconds/mtg/conntypes"
8
 	"github.com/9seconds/mtg/conntypes"
11
 	"github.com/9seconds/mtg/stats"
9
 	"github.com/9seconds/mtg/stats"
10
+	"go.uber.org/zap"
12
 )
11
 )
13
 
12
 
14
 type wrapperTelegramStats struct {
13
 type wrapperTelegramStats struct {

+ 1
- 2
wrappers/stream/stats_traffic.go Просмотреть файл

4
 	"net"
4
 	"net"
5
 	"time"
5
 	"time"
6
 
6
 
7
-	"go.uber.org/zap"
8
-
9
 	"github.com/9seconds/mtg/conntypes"
7
 	"github.com/9seconds/mtg/conntypes"
10
 	"github.com/9seconds/mtg/stats"
8
 	"github.com/9seconds/mtg/stats"
9
+	"go.uber.org/zap"
11
 )
10
 )
12
 
11
 
13
 type wrapperTrafficStats struct {
12
 type wrapperTrafficStats struct {

+ 1
- 2
wrappers/stream/timeout.go Просмотреть файл

4
 	"net"
4
 	"net"
5
 	"time"
5
 	"time"
6
 
6
 
7
-	"go.uber.org/zap"
8
-
9
 	"github.com/9seconds/mtg/conntypes"
7
 	"github.com/9seconds/mtg/conntypes"
8
+	"go.uber.org/zap"
10
 )
9
 )
11
 
10
 
12
 const (
11
 const (

Загрузка…
Отмена
Сохранить