Merge pull request #115 from 9seconds/gogettable

Make mtg go-gettable
This commit is contained in:
Sergey Arkhipov
2019-11-19 11:55:33 +03:00
committed by GitHub
53 changed files with 145 additions and 125 deletions
+1 -4
View File
@@ -6,10 +6,7 @@ CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{38
GOLANGCI_LINT_VERSION := v1.21.0 GOLANGCI_LINT_VERSION := v1.21.0
VERSION_GO := $(shell go version) COMMON_BUILD_FLAGS := -ldflags="-s -w"
VERSION_DATE := $(shell date -Ru)
VERSION_TAG := $(shell git describe --tags --always)
COMMON_BUILD_FLAGS := -ldflags="-s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
MOD_ON := env GO111MODULE=on MOD_ON := env GO111MODULE=on
MOD_OFF := env GO111MODULE=auto MOD_OFF := env GO111MODULE=auto
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"github.com/VictoriaMetrics/fastcache" "github.com/VictoriaMetrics/fastcache"
"mtg/config" "github.com/9seconds/mtg/config"
) )
var ( var (
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"mtg/config" "github.com/9seconds/mtg/config"
) )
func Generate(secretType, hostname string) { func Generate(secretType, hostname string) {
+10 -10
View File
@@ -8,16 +8,16 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
"mtg/antireplay" "github.com/9seconds/mtg/antireplay"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/faketls" "github.com/9seconds/mtg/faketls"
"mtg/hub" "github.com/9seconds/mtg/hub"
"mtg/ntp" "github.com/9seconds/mtg/ntp"
"mtg/obfuscated2" "github.com/9seconds/mtg/obfuscated2"
"mtg/proxy" "github.com/9seconds/mtg/proxy"
"mtg/stats" "github.com/9seconds/mtg/stats"
"mtg/telegram" "github.com/9seconds/mtg/telegram"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
func Proxy() error { // nolint: funlen func Proxy() error { // nolint: funlen
+8 -8
View File
@@ -11,14 +11,14 @@ import (
"sync" "sync"
"time" "time"
"mtg/antireplay" "github.com/9seconds/mtg/antireplay"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/obfuscated2" "github.com/9seconds/mtg/obfuscated2"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/stats" "github.com/9seconds/mtg/stats"
"mtg/tlstypes" "github.com/9seconds/mtg/tlstypes"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
type ClientProtocol struct { type ClientProtocol struct {
+1 -1
View File
@@ -1,4 +1,4 @@
module mtg module github.com/9seconds/mtg
go 1.13 go 1.13
+4 -4
View File
@@ -7,10 +7,10 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/mtproto" "github.com/9seconds/mtg/mtproto"
"mtg/mtproto/rpc" "github.com/9seconds/mtg/mtproto/rpc"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
type connection struct { type connection struct {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"sort" "sort"
"mtg/config" "github.com/9seconds/mtg/config"
) )
type connectionList struct { type connectionList struct {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"context" "context"
"sync" "sync"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
type hub struct { type hub struct {
+1 -1
View File
@@ -1,6 +1,6 @@
package hub package hub
import "mtg/protocol" import "github.com/9seconds/mtg/protocol"
type Interface interface { type Interface interface {
Register(*protocol.TelegramRequest) (*ProxyConn, error) Register(*protocol.TelegramRequest) (*ProxyConn, error)
+2 -2
View File
@@ -4,8 +4,8 @@ import (
"context" "context"
"time" "time"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
const muxGCEvery = time.Minute const muxGCEvery = time.Minute
+3 -3
View File
@@ -4,9 +4,9 @@ import (
"sync" "sync"
"time" "time"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/mtproto/rpc" "github.com/9seconds/mtg/mtproto/rpc"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
const ( const (
+29 -6
View File
@@ -3,17 +3,17 @@ package main
import ( import (
"math/rand" "math/rand"
"os" "os"
"runtime/debug"
"strings"
"time" "time"
kingpin "gopkg.in/alecthomas/kingpin.v2" kingpin "gopkg.in/alecthomas/kingpin.v2"
"mtg/cli" "github.com/9seconds/mtg/cli"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
var version = "dev" // this has to be set by build ld flags
var ( var (
app = kingpin.New("mtg", "Simple MTPROTO proxy.") app = kingpin.New("mtg", "Simple MTPROTO proxy.")
@@ -114,7 +114,7 @@ var (
func main() { func main() {
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
app.Version(version) app.Version(getVersion())
app.HelpFlag.Short('h') app.HelpFlag.Short('h')
if err := utils.SetLimits(); err != nil { if err := utils.SetLimits(); err != nil {
@@ -153,3 +153,26 @@ func main() {
} }
} }
} }
func getVersion() string {
if info, ok := debug.ReadBuildInfo(); ok {
builder := strings.Builder{}
version := info.Main.Version
if version == "(devel)" {
version = "dev"
}
builder.WriteString(version)
if info.Main.Sum != "" {
builder.WriteString(" (checksum: ")
builder.WriteString(info.Main.Sum)
builder.WriteRune(')')
}
return builder.String()
}
return "dev"
}
+6 -6
View File
@@ -3,12 +3,12 @@ package mtproto
import ( import (
"fmt" "fmt"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/mtproto/rpc" "github.com/9seconds/mtg/mtproto/rpc"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/telegram" "github.com/9seconds/mtg/telegram"
"mtg/wrappers/packet" "github.com/9seconds/mtg/wrappers/packet"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.PacketReadWriteCloser, error) { func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.PacketReadWriteCloser, error) {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type ProxyResponseType uint8 type ProxyResponseType uint8
+7 -7
View File
@@ -9,13 +9,13 @@ import (
"io" "io"
"time" "time"
"mtg/antireplay" "github.com/9seconds/mtg/antireplay"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/stats" "github.com/9seconds/mtg/stats"
"mtg/utils" "github.com/9seconds/mtg/utils"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
const clientProtocolHandshakeTimeout = 10 * time.Second const clientProtocolHandshakeTimeout = 10 * time.Second
+5 -5
View File
@@ -4,11 +4,11 @@ import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/telegram" "github.com/9seconds/mtg/telegram"
"mtg/utils" "github.com/9seconds/mtg/utils"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteCloser, error) { func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteCloser, error) {
+1 -1
View File
@@ -1,6 +1,6 @@
package protocol package protocol
import "mtg/conntypes" import "github.com/9seconds/mtg/conntypes"
type ClientProtocol interface { type ClientProtocol interface {
Handshake(conntypes.StreamReadWriteCloser) (conntypes.StreamReadWriteCloser, error) Handshake(conntypes.StreamReadWriteCloser) (conntypes.StreamReadWriteCloser, error)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type TelegramRequest struct { type TelegramRequest struct {
+3 -3
View File
@@ -6,9 +6,9 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/obfuscated2" "github.com/9seconds/mtg/obfuscated2"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
const directPipeBufferSize = 1024 * 1024 const directPipeBufferSize = 1024 * 1024
+3 -3
View File
@@ -5,9 +5,9 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/wrappers/packetack" "github.com/9seconds/mtg/wrappers/packetack"
) )
func middleConnection(request *protocol.TelegramRequest) { func middleConnection(request *protocol.TelegramRequest) {
+6 -6
View File
@@ -6,12 +6,12 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
"mtg/stats" "github.com/9seconds/mtg/stats"
"mtg/utils" "github.com/9seconds/mtg/utils"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
type Proxy struct { type Proxy struct {
+1 -1
View File
@@ -3,7 +3,7 @@ package stats
import ( import (
"net" "net"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type IngressTrafficInterface interface { type IngressTrafficInterface interface {
+1 -1
View File
@@ -3,7 +3,7 @@ package stats
import ( import (
"net" "net"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type multiStats []Interface type multiStats []Interface
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"net" "net"
"net/http" "net/http"
"mtg/config" "github.com/9seconds/mtg/config"
) )
var Stats Interface var Stats Interface
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type statsPrometheus struct { type statsPrometheus struct {
+2 -2
View File
@@ -11,8 +11,8 @@ import (
statsd "github.com/smira/go-statsd" statsd "github.com/smira/go-statsd"
"go.uber.org/zap" "go.uber.org/zap"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
var ( var (
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
const ( const (
+1 -1
View File
@@ -9,7 +9,7 @@ import (
) )
const ( const (
apiUserAgent = "mtg" apiUserAgent = "github.com/9seconds/mtg"
apiHTTPTimeout = 30 * time.Second apiHTTPTimeout = 30 * time.Second
) )
+3 -3
View File
@@ -5,9 +5,9 @@ import (
"math/rand" "math/rand"
"net" "net"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/utils" "github.com/9seconds/mtg/utils"
"mtg/wrappers/stream" "github.com/9seconds/mtg/wrappers/stream"
) )
type baseTelegram struct { type baseTelegram struct {
+1 -1
View File
@@ -1,6 +1,6 @@
package telegram package telegram
import "mtg/conntypes" import "github.com/9seconds/mtg/conntypes"
const ( const (
directV4DefaultIdx conntypes.DC = 1 directV4DefaultIdx conntypes.DC = 1
+1 -1
View File
@@ -1,6 +1,6 @@
package telegram package telegram
import "mtg/conntypes" import "github.com/9seconds/mtg/conntypes"
type Telegram interface { type Telegram interface {
Dial(conntypes.DC, conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) Dial(conntypes.DC, conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error)
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/telegram/api" "github.com/9seconds/mtg/telegram/api"
) )
const middleTelegramBackgroundUpdateEvery = time.Hour const middleTelegramBackgroundUpdateEvery = time.Hour
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"crypto/sha256" "crypto/sha256"
"fmt" "fmt"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
type ClientHello struct { type ClientHello struct {
+1 -1
View File
@@ -3,7 +3,7 @@ package tlstypes
import ( import (
"bytes" "bytes"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
type Handshake struct { type Handshake struct {
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"golang.org/x/crypto/curve25519" "golang.org/x/crypto/curve25519"
"mtg/config" "github.com/9seconds/mtg/config"
) )
type ServerHello struct { type ServerHello struct {
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"net" "net"
"mtg/config" "github.com/9seconds/mtg/config"
) )
func InitTCP(conn net.Conn) error { func InitTCP(conn net.Conn) error {
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
const ( const (
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
const ( const (
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
const clientIntermediateQuickAckLength = 0x80000000 const clientIntermediateQuickAckLength = 0x80000000
@@ -8,7 +8,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type wrapperClientIntermediateSecure struct { type wrapperClientIntermediateSecure struct {
+5 -5
View File
@@ -6,11 +6,11 @@ import (
"fmt" "fmt"
"net" "net"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/hub" "github.com/9seconds/mtg/hub"
"mtg/mtproto/rpc" "github.com/9seconds/mtg/mtproto/rpc"
"mtg/protocol" "github.com/9seconds/mtg/protocol"
) )
type wrapperProxy struct { type wrapperProxy struct {
+1 -1
View File
@@ -3,7 +3,7 @@ package stream
import ( import (
"net" "net"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
func NewClientConn(parent net.Conn, connID conntypes.ConnID) conntypes.StreamReadWriteCloser { func NewClientConn(parent net.Conn, connID conntypes.ConnID) conntypes.StreamReadWriteCloser {
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
type wrapperBlockCipher struct { type wrapperBlockCipher struct {
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/config" "github.com/9seconds/mtg/config"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type connPurpose uint8 type connPurpose uint8
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type wrapperCtx struct { type wrapperCtx struct {
+2 -2
View File
@@ -8,8 +8,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/tlstypes" "github.com/9seconds/mtg/tlstypes"
) )
type wrapperFakeTLS struct { type wrapperFakeTLS struct {
+3 -3
View File
@@ -9,9 +9,9 @@ import (
"encoding/binary" "encoding/binary"
"net" "net"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/mtproto/rpc" "github.com/9seconds/mtg/mtproto/rpc"
"mtg/utils" "github.com/9seconds/mtg/utils"
) )
type mtprotoCipherPurpose uint8 type mtprotoCipherPurpose uint8
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type wrapperObfuscated2 struct { type wrapperObfuscated2 struct {
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
type ReadWriteCloseRewinder interface { type ReadWriteCloseRewinder interface {
+2 -2
View File
@@ -7,8 +7,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/stats" "github.com/9seconds/mtg/stats"
) )
type wrapperTelegramStats struct { type wrapperTelegramStats struct {
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
"mtg/stats" "github.com/9seconds/mtg/stats"
) )
type wrapperTrafficStats struct { type wrapperTrafficStats struct {
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"mtg/conntypes" "github.com/9seconds/mtg/conntypes"
) )
const ( const (