mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:34:02 +03:00
Fix lint errors
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
IMAGE_NAME := mtg
|
IMAGE_NAME := mtg
|
||||||
APP_NAME := $(IMAGE_NAME)
|
APP_NAME := $(IMAGE_NAME)
|
||||||
GOMETALINTER := gometalinter.v2
|
GOMETALINTER := gometalinter
|
||||||
|
|
||||||
VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor")
|
VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor")
|
||||||
CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
|
CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
|
||||||
|
|||||||
+20
-7
@@ -10,26 +10,28 @@ import (
|
|||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config represents common configuration of mtg.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
BindIP net.IP
|
|
||||||
BindPort uint16
|
BindPort uint16
|
||||||
|
|
||||||
PublicIPv4 net.IP
|
|
||||||
PublicIPv4Port uint16
|
PublicIPv4Port uint16
|
||||||
PublicIPv6 net.IP
|
|
||||||
PublicIPv6Port uint16
|
PublicIPv6Port uint16
|
||||||
|
|
||||||
StatsIP net.IP
|
|
||||||
StatsPort uint16
|
StatsPort uint16
|
||||||
|
|
||||||
TimeoutRead time.Duration
|
TimeoutRead time.Duration
|
||||||
TimeoutWrite time.Duration
|
TimeoutWrite time.Duration
|
||||||
|
|
||||||
|
BindIP net.IP
|
||||||
|
PublicIPv4 net.IP
|
||||||
|
PublicIPv6 net.IP
|
||||||
|
StatsIP net.IP
|
||||||
|
|
||||||
Secret []byte
|
Secret []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// URLs contains links to the proxy (tg://, t.me) and their QR codes.
|
||||||
type URLs struct {
|
type URLs struct {
|
||||||
TG string `json:"tg_url"`
|
TG string `json:"tg_url"`
|
||||||
TMe string `json:"tme_url"`
|
TMe string `json:"tme_url"`
|
||||||
@@ -37,27 +39,33 @@ type URLs struct {
|
|||||||
TMeQRCode string `json:"tme_qrcode"`
|
TMeQRCode string `json:"tme_qrcode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPURLs contains links to both ipv4 and ipv6 of the proxy.
|
||||||
type IPURLs struct {
|
type IPURLs struct {
|
||||||
IPv4 URLs `json:"ipv4"`
|
IPv4 URLs `json:"ipv4"`
|
||||||
IPv6 URLs `json:"ipv6"`
|
IPv6 URLs `json:"ipv6"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BindAddr returns connection for this server to bind to.
|
||||||
func (c *Config) BindAddr() string {
|
func (c *Config) BindAddr() string {
|
||||||
return getAddr(c.BindIP, c.BindPort)
|
return getAddr(c.BindIP, c.BindPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPv4Addr returns connection string to ipv6 for mtproto proxy.
|
||||||
func (c *Config) IPv4Addr() string {
|
func (c *Config) IPv4Addr() string {
|
||||||
return getAddr(c.PublicIPv4, c.PublicIPv4Port)
|
return getAddr(c.PublicIPv4, c.PublicIPv4Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPv6Addr returns connection string to ipv6 for mtproto proxy.
|
||||||
func (c *Config) IPv6Addr() string {
|
func (c *Config) IPv6Addr() string {
|
||||||
return getAddr(c.PublicIPv6, c.PublicIPv6Port)
|
return getAddr(c.PublicIPv6, c.PublicIPv6Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatAddr returns connection string to the stats API.
|
||||||
func (c *Config) StatAddr() string {
|
func (c *Config) StatAddr() string {
|
||||||
return getAddr(c.StatsIP, c.StatsPort)
|
return getAddr(c.StatsIP, c.StatsPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetURLs returns configured IPURLs instance with links to this server.
|
||||||
func (c *Config) GetURLs() IPURLs {
|
func (c *Config) GetURLs() IPURLs {
|
||||||
return IPURLs{
|
return IPURLs{
|
||||||
IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
|
IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
|
||||||
@@ -69,7 +77,10 @@ func getAddr(host fmt.Stringer, port uint16) string {
|
|||||||
return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
|
return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(debug, verbose bool,
|
// NewConfig returns new configuration. If required, it manages and
|
||||||
|
// fetches data from external sources. Parameters passed to this
|
||||||
|
// function, should come from command line arguments.
|
||||||
|
func NewConfig(debug, verbose bool, // nolint: gocyclo
|
||||||
bindIP net.IP, bindPort uint16,
|
bindIP net.IP, bindPort uint16,
|
||||||
publicIPv4 net.IP, PublicIPv4Port uint16,
|
publicIPv4 net.IP, PublicIPv4Port uint16,
|
||||||
publicIPv6 net.IP, publicIPv6Port uint16,
|
publicIPv6 net.IP, publicIPv6Port uint16,
|
||||||
@@ -120,6 +131,8 @@ func NewConfig(debug, verbose bool,
|
|||||||
PublicIPv4Port: PublicIPv4Port,
|
PublicIPv4Port: PublicIPv4Port,
|
||||||
PublicIPv6: publicIPv6,
|
PublicIPv6: publicIPv6,
|
||||||
PublicIPv6Port: publicIPv6Port,
|
PublicIPv6Port: publicIPv6Port,
|
||||||
|
StatsIP: statsIP,
|
||||||
|
StatsPort: statsPort,
|
||||||
TimeoutRead: timeoutRead,
|
TimeoutRead: timeoutRead,
|
||||||
TimeoutWrite: timeoutWrite,
|
TimeoutWrite: timeoutWrite,
|
||||||
Secret: secretBytes,
|
Secret: secretBytes,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func fetchIP(url string) (net.IP, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close() // nolint: errcheck
|
||||||
|
|
||||||
respData, err := ioutil.ReadAll(resp.Body)
|
respData, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ func getURLs(addr net.IP, port uint16, secret []byte) (urls URLs) {
|
|||||||
values.Set("secret", hex.EncodeToString(secret))
|
values.Set("secret", hex.EncodeToString(secret))
|
||||||
|
|
||||||
urls.TG = makeTGURL(values)
|
urls.TG = makeTGURL(values)
|
||||||
urls.TMe = makeTGURL(values)
|
urls.TMe = makeTMeURL(values)
|
||||||
urls.TGQRCode = makeQRCodeURL(urls.TG)
|
urls.TGQRCode = makeQRCodeURL(urls.TG)
|
||||||
urls.TMeQRCode = makeQRCodeURL(urls.TG)
|
urls.TMeQRCode = makeQRCodeURL(urls.TG)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ func TestObfs2TelegramDecryptEncryptDecrypt(t *testing.T) {
|
|||||||
data := []byte{1, 2, 3}
|
data := []byte{1, 2, 3}
|
||||||
encrypted := make([]byte, 3)
|
encrypted := make([]byte, 3)
|
||||||
encryptor.XORKeyStream(encrypted, data)
|
encryptor.XORKeyStream(encrypted, data)
|
||||||
decrypted := obfs2.Decrypt(encrypted)
|
decrypted := make([]byte, 3)
|
||||||
|
obfs2.Decryptor.XORKeyStream(decrypted, encrypted)
|
||||||
|
|
||||||
assert.Equal(t, data, decrypted)
|
assert.Equal(t, data, decrypted)
|
||||||
}
|
}
|
||||||
@@ -67,10 +68,12 @@ func TestObfs2Full(t *testing.T) {
|
|||||||
tgEncryptedMessage := make([]byte, len(message))
|
tgEncryptedMessage := make([]byte, len(message))
|
||||||
tgEncryptor.XORKeyStream(tgEncryptedMessage, message)
|
tgEncryptor.XORKeyStream(tgEncryptedMessage, message)
|
||||||
|
|
||||||
tgEncDecryptedMessage := tgObfs.Decrypt(tgEncryptedMessage)
|
tgEncDecryptedMessage := make([]byte, len(tgEncryptedMessage))
|
||||||
|
tgObfs.Decryptor.XORKeyStream(tgEncDecryptedMessage, tgEncryptedMessage)
|
||||||
assert.Equal(t, message, tgEncDecryptedMessage)
|
assert.Equal(t, message, tgEncDecryptedMessage)
|
||||||
|
|
||||||
clientEncryptedMessage := clientObfs.Encrypt(tgEncDecryptedMessage)
|
clientEncryptedMessage := make([]byte, len(tgEncDecryptedMessage))
|
||||||
|
clientObfs.Encryptor.XORKeyStream(clientEncryptedMessage, tgEncDecryptedMessage)
|
||||||
finalMessage := make([]byte, len(clientEncryptedMessage))
|
finalMessage := make([]byte, len(clientEncryptedMessage))
|
||||||
clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)
|
clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user