Kaynağa Gözat

Fix lint errors

tags/0.9
9seconds 8 yıl önce
ebeveyn
işleme
dd7a095947
5 değiştirilmiş dosya ile 32 ekleme ve 16 silme
  1. 1
    1
      Makefile
  2. 23
    10
      config/config.go
  3. 1
    1
      config/global_ips.go
  4. 1
    1
      config/urls.go
  5. 6
    3
      obfuscated2/obfuscated2_test.go

+ 1
- 1
Makefile Dosyayı Görüntüle

@@ -1,7 +1,7 @@
1 1
 ROOT_DIR     := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
2 2
 IMAGE_NAME   := mtg
3 3
 APP_NAME     := $(IMAGE_NAME)
4
-GOMETALINTER := gometalinter.v2
4
+GOMETALINTER := gometalinter
5 5
 
6 6
 VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor")
7 7
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")

+ 23
- 10
config/config.go Dosyayı Görüntüle

@@ -10,26 +10,28 @@ import (
10 10
 	"github.com/juju/errors"
11 11
 )
12 12
 
13
+// Config represents common configuration of mtg.
13 14
 type Config struct {
14
-	Debug    bool
15
-	Verbose  bool
16
-	BindIP   net.IP
17
-	BindPort uint16
15
+	Debug   bool
16
+	Verbose bool
18 17
 
19
-	PublicIPv4     net.IP
18
+	BindPort       uint16
20 19
 	PublicIPv4Port uint16
21
-	PublicIPv6     net.IP
22 20
 	PublicIPv6Port uint16
23
-
24
-	StatsIP   net.IP
25
-	StatsPort uint16
21
+	StatsPort      uint16
26 22
 
27 23
 	TimeoutRead  time.Duration
28 24
 	TimeoutWrite time.Duration
29 25
 
26
+	BindIP     net.IP
27
+	PublicIPv4 net.IP
28
+	PublicIPv6 net.IP
29
+	StatsIP    net.IP
30
+
30 31
 	Secret []byte
31 32
 }
32 33
 
34
+// URLs contains links to the proxy (tg://, t.me) and their QR codes.
33 35
 type URLs struct {
34 36
 	TG        string `json:"tg_url"`
35 37
 	TMe       string `json:"tme_url"`
@@ -37,27 +39,33 @@ type URLs struct {
37 39
 	TMeQRCode string `json:"tme_qrcode"`
38 40
 }
39 41
 
42
+// IPURLs contains links to both ipv4 and ipv6 of the proxy.
40 43
 type IPURLs struct {
41 44
 	IPv4 URLs `json:"ipv4"`
42 45
 	IPv6 URLs `json:"ipv6"`
43 46
 }
44 47
 
48
+// BindAddr returns connection for this server to bind to.
45 49
 func (c *Config) BindAddr() string {
46 50
 	return getAddr(c.BindIP, c.BindPort)
47 51
 }
48 52
 
53
+// IPv4Addr returns connection string to ipv6 for mtproto proxy.
49 54
 func (c *Config) IPv4Addr() string {
50 55
 	return getAddr(c.PublicIPv4, c.PublicIPv4Port)
51 56
 }
52 57
 
58
+// IPv6Addr returns connection string to ipv6 for mtproto proxy.
53 59
 func (c *Config) IPv6Addr() string {
54 60
 	return getAddr(c.PublicIPv6, c.PublicIPv6Port)
55 61
 }
56 62
 
63
+// StatAddr returns connection string to the stats API.
57 64
 func (c *Config) StatAddr() string {
58 65
 	return getAddr(c.StatsIP, c.StatsPort)
59 66
 }
60 67
 
68
+// GetURLs returns configured IPURLs instance with links to this server.
61 69
 func (c *Config) GetURLs() IPURLs {
62 70
 	return IPURLs{
63 71
 		IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
@@ -69,7 +77,10 @@ func getAddr(host fmt.Stringer, port uint16) string {
69 77
 	return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
70 78
 }
71 79
 
72
-func NewConfig(debug, verbose bool,
80
+// NewConfig returns new configuration. If required, it manages and
81
+// fetches data from external sources. Parameters passed to this
82
+// function, should come from command line arguments.
83
+func NewConfig(debug, verbose bool, // nolint: gocyclo
73 84
 	bindIP net.IP, bindPort uint16,
74 85
 	publicIPv4 net.IP, PublicIPv4Port uint16,
75 86
 	publicIPv6 net.IP, publicIPv6Port uint16,
@@ -120,6 +131,8 @@ func NewConfig(debug, verbose bool,
120 131
 		PublicIPv4Port: PublicIPv4Port,
121 132
 		PublicIPv6:     publicIPv6,
122 133
 		PublicIPv6Port: publicIPv6Port,
134
+		StatsIP:        statsIP,
135
+		StatsPort:      statsPort,
123 136
 		TimeoutRead:    timeoutRead,
124 137
 		TimeoutWrite:   timeoutWrite,
125 138
 		Secret:         secretBytes,

+ 1
- 1
config/global_ips.go Dosyayı Görüntüle

@@ -22,7 +22,7 @@ func fetchIP(url string) (net.IP, error) {
22 22
 	if err != nil {
23 23
 		return nil, err
24 24
 	}
25
-	defer resp.Body.Close()
25
+	defer resp.Body.Close() // nolint: errcheck
26 26
 
27 27
 	respData, err := ioutil.ReadAll(resp.Body)
28 28
 	if err != nil {

+ 1
- 1
config/urls.go Dosyayı Görüntüle

@@ -14,7 +14,7 @@ func getURLs(addr net.IP, port uint16, secret []byte) (urls URLs) {
14 14
 	values.Set("secret", hex.EncodeToString(secret))
15 15
 
16 16
 	urls.TG = makeTGURL(values)
17
-	urls.TMe = makeTGURL(values)
17
+	urls.TMe = makeTMeURL(values)
18 18
 	urls.TGQRCode = makeQRCodeURL(urls.TG)
19 19
 	urls.TMeQRCode = makeQRCodeURL(urls.TG)
20 20
 

+ 6
- 3
obfuscated2/obfuscated2_test.go Dosyayı Görüntüle

@@ -25,7 +25,8 @@ func TestObfs2TelegramDecryptEncryptDecrypt(t *testing.T) {
25 25
 	data := []byte{1, 2, 3}
26 26
 	encrypted := make([]byte, 3)
27 27
 	encryptor.XORKeyStream(encrypted, data)
28
-	decrypted := obfs2.Decrypt(encrypted)
28
+	decrypted := make([]byte, 3)
29
+	obfs2.Decryptor.XORKeyStream(decrypted, encrypted)
29 30
 
30 31
 	assert.Equal(t, data, decrypted)
31 32
 }
@@ -67,10 +68,12 @@ func TestObfs2Full(t *testing.T) {
67 68
 	tgEncryptedMessage := make([]byte, len(message))
68 69
 	tgEncryptor.XORKeyStream(tgEncryptedMessage, message)
69 70
 
70
-	tgEncDecryptedMessage := tgObfs.Decrypt(tgEncryptedMessage)
71
+	tgEncDecryptedMessage := make([]byte, len(tgEncryptedMessage))
72
+	tgObfs.Decryptor.XORKeyStream(tgEncDecryptedMessage, tgEncryptedMessage)
71 73
 	assert.Equal(t, message, tgEncDecryptedMessage)
72 74
 
73
-	clientEncryptedMessage := clientObfs.Encrypt(tgEncDecryptedMessage)
75
+	clientEncryptedMessage := make([]byte, len(tgEncDecryptedMessage))
76
+	clientObfs.Encryptor.XORKeyStream(clientEncryptedMessage, tgEncDecryptedMessage)
74 77
 	finalMessage := make([]byte, len(clientEncryptedMessage))
75 78
 	clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)
76 79
 

Loading…
İptal
Kaydet