mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Update to go 1.19
This commit is contained in:
@@ -30,7 +30,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go_version:
|
go_version:
|
||||||
- ^1.18
|
- ^1.19
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@@ -70,7 +70,7 @@ jobs:
|
|||||||
- name: Run linter
|
- name: Run linter
|
||||||
uses: golangci/golangci-lint-action@v2
|
uses: golangci/golangci-lint-action@v2
|
||||||
with:
|
with:
|
||||||
version: v1.45.0
|
version: v1.48.0
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
name: Docker
|
name: Docker
|
||||||
|
|||||||
+11
-1
@@ -9,4 +9,14 @@ format = "colored-line-number"
|
|||||||
|
|
||||||
[linters]
|
[linters]
|
||||||
enable-all = true
|
enable-all = true
|
||||||
disable = ["thelper", "ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"]
|
disable = [
|
||||||
|
"containedctx",
|
||||||
|
"exhaustivestruct",
|
||||||
|
"exhaustruct",
|
||||||
|
"gas",
|
||||||
|
"gochecknoglobals",
|
||||||
|
"goerr113",
|
||||||
|
"ireturn",
|
||||||
|
"thelper",
|
||||||
|
"varnamelen",
|
||||||
|
]
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# BUILD STAGE
|
# BUILD STAGE
|
||||||
|
|
||||||
FROM golang:1.18-alpine AS build
|
FROM golang:1.19-alpine AS build
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& apk --no-cache --update add \
|
&& apk --no-cache --update add \
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|||||||
IMAGE_NAME := mtg
|
IMAGE_NAME := mtg
|
||||||
APP_NAME := $(IMAGE_NAME)
|
APP_NAME := $(IMAGE_NAME)
|
||||||
|
|
||||||
GOLANGCI_LINT_VERSION := v1.45.0
|
GOLANGCI_LINT_VERSION := v1.48.0
|
||||||
|
|
||||||
VERSION_GO := $(shell go version)
|
VERSION_GO := $(shell go version)
|
||||||
VERSION_DATE := $(shell date -Ru)
|
VERSION_DATE := $(shell date -Ru)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -46,7 +45,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", ifconfigAddress, nil)
|
req, err := http.NewRequest(http.MethodGet, ifconfigAddress, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot create a request: %w", err)
|
return nil, fmt.Errorf("cannot create a request: %w", err)
|
||||||
}
|
}
|
||||||
@@ -54,7 +53,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
|
|||||||
resp, err := client.Do(req.WithContext(ctx))
|
resp, err := client.Do(req.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
|
io.Copy(io.Discard, resp.Body) //nolint: errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("cannot perform a request: %w", err)
|
return nil, fmt.Errorf("cannot perform a request: %w", err)
|
||||||
@@ -62,7 +61,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
respDataBytes, err := ioutil.ReadAll(resp.Body)
|
respDataBytes, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot read response body: %w", err)
|
return nil, fmt.Errorf("cannot read response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -20,8 +20,9 @@ type IPURLs struct {
|
|||||||
BotSecret string `json:"secret_for_mtproxybot"` //nolint: tagliatelle
|
BotSecret string `json:"secret_for_mtproxybot"` //nolint: tagliatelle
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetURLs() (urls IPURLs) {
|
func GetURLs() IPURLs {
|
||||||
secret := ""
|
secret := ""
|
||||||
|
urls := IPURLs{}
|
||||||
|
|
||||||
switch C.SecretMode {
|
switch C.SecretMode {
|
||||||
case SecretModeSimple:
|
case SecretModeSimple:
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ require (
|
|||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
go.uber.org/zap v1.21.0
|
go.uber.org/zap v1.21.0
|
||||||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
|
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
|
||||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
|
golang.org/x/net v0.0.0-20220809012201-f428fae20770 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
|
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664
|
||||||
google.golang.org/protobuf v1.27.1 // indirect
|
google.golang.org/protobuf v1.27.1 // indirect
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||||
)
|
)
|
||||||
@@ -27,5 +27,8 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.2 // indirect
|
github.com/golang/protobuf v1.5.2 // indirect
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
github.com/prometheus/client_model v0.2.0 // indirect
|
github.com/prometheus/client_model v0.2.0 // indirect
|
||||||
|
github.com/yuin/goldmark v1.4.13 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||||
|
golang.org/x/tools v0.1.12 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
|||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
|
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
@@ -262,6 +264,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
|
|||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@@ -294,6 +298,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
|
|||||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||||
|
golang.org/x/net v0.0.0-20220809012201-f428fae20770 h1:dIi4qVdvjZEjiMDv7vhokAZNGnz3kepwuXqFKYDdDMs=
|
||||||
|
golang.org/x/net v0.0.0-20220809012201-f428fae20770/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -351,6 +357,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
|
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
|
||||||
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664 h1:v1W7bwXHsnLLloWYTVEdvGvA7BHMeBYsPcF0GLDxIRs=
|
||||||
|
golang.org/x/sys v0.0.0-20220808155132-1c4a2a72c664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
@@ -402,6 +410,8 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
|
|||||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
|
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/9seconds/mtg/cli"
|
"github.com/9seconds/mtg/cli"
|
||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
"github.com/9seconds/mtg/utils"
|
|
||||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -128,10 +127,6 @@ func main() {
|
|||||||
app.Version(getVersion())
|
app.Version(getVersion())
|
||||||
app.HelpFlag.Short('h')
|
app.HelpFlag.Short('h')
|
||||||
|
|
||||||
if err := utils.SetLimits(); err != nil {
|
|
||||||
cli.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
|
||||||
case generateSecretCommand.FullCommand():
|
case generateSecretCommand.FullCommand():
|
||||||
cli.Generate(*generateSecretType, *generateCloakHost)
|
cli.Generate(*generateSecretType, *generateCloakHost)
|
||||||
|
|||||||
@@ -93,12 +93,14 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
|
|||||||
return stream.NewObfuscated2(socket, encryptor, decryptor), nil
|
return stream.NewObfuscated2(socket, encryptor, decryptor), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (fm Frame, err error) {
|
func (c *ClientProtocol) ReadFrame(socket conntypes.StreamReader) (Frame, error) {
|
||||||
if _, err = io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil {
|
fm := Frame{}
|
||||||
err = fmt.Errorf("cannot extract obfuscated2 frame: %w", err)
|
|
||||||
|
if _, err := io.ReadFull(handshakeReader{socket}, fm.Bytes()); err != nil {
|
||||||
|
return fm, fmt.Errorf("cannot extract obfuscated2 frame: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return fm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type handshakeReader struct {
|
type handshakeReader struct {
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ func (f *Frame) Unique() []byte {
|
|||||||
return f.data[frameOffsetFirst:frameOffsetDC]
|
return f.data[frameOffsetFirst:frameOffsetDC]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Frame) Invert() (nf Frame) {
|
func (f *Frame) Invert() Frame {
|
||||||
nf = *f
|
nf := *f
|
||||||
for i := 0; i < frameLenKey+frameLenIV; i++ {
|
for i := 0; i < frameLenKey+frameLenIV; i++ {
|
||||||
nf.data[frameOffsetFirst+i] = f.data[frameOffsetIV-1-i]
|
nf.data[frameOffsetFirst+i] = f.data[frameOffsetIV-1-i]
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return nf
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ func TelegramProtocol(req *protocol.TelegramRequest) (conntypes.StreamReadWriteC
|
|||||||
return stream.NewObfuscated2(conn, encryptor, decryptor), nil
|
return stream.NewObfuscated2(conn, encryptor, decryptor), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateFrame(cp protocol.ClientProtocol) (fm Frame) {
|
func generateFrame(cp protocol.ClientProtocol) Frame {
|
||||||
|
fm := Frame{}
|
||||||
data := fm.Bytes()
|
data := fm.Bytes()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -63,6 +64,6 @@ func generateFrame(cp protocol.ClientProtocol) (fm Frame) {
|
|||||||
|
|
||||||
copy(fm.Magic(), cp.ConnectionType().Tag())
|
copy(fm.Magic(), cp.ConnectionType().Tag())
|
||||||
|
|
||||||
return
|
return fm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ func Init(ctx context.Context) error {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
srv.Shutdown(context.Background()) // nolint: errcheck, contextcheck
|
srv.Shutdown(context.Background()) //nolint: errcheck
|
||||||
}()
|
}()
|
||||||
|
|
||||||
Stats = multiStats(stats)
|
Stats = multiStats(stats)
|
||||||
|
|||||||
+2
-3
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -22,7 +21,7 @@ func request(url string) (io.ReadCloser, error) {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), apiHTTPTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -33,7 +32,7 @@ func request(url string) (io.ReadCloser, error) {
|
|||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
io.Copy(ioutil.Discard, resp.Body) // nolint: errcheck
|
io.Copy(io.Discard, resp.Body) //nolint: errcheck
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
const secretURL = "https://core.telegram.org/getProxySecret" //nolint: gas
|
const secretURL = "https://core.telegram.org/getProxySecret" //nolint: gas
|
||||||
@@ -15,7 +15,7 @@ func Secret() ([]byte, error) {
|
|||||||
|
|
||||||
defer resp.Close()
|
defer resp.Close()
|
||||||
|
|
||||||
secret, err := ioutil.ReadAll(resp)
|
secret, err := io.ReadAll(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot read response: %w", err)
|
return nil, fmt.Errorf("cannot read response: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-13
@@ -20,22 +20,22 @@ const (
|
|||||||
type CipherSuiteType uint8
|
type CipherSuiteType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_AES_256_GCM_SHA384 //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c CipherSuiteType) Bytes() []byte {
|
func (c CipherSuiteType) Bytes() []byte {
|
||||||
switch c {
|
switch c {
|
||||||
case CipherSuiteType_TLS_AES_128_GCM_SHA256:
|
case CipherSuiteType_TLS_AES_128_GCM_SHA256: //nolint: nosnakecase
|
||||||
return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes
|
return CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes //nolint: nosnakecase
|
||||||
case CipherSuiteType_TLS_AES_256_GCM_SHA384:
|
case CipherSuiteType_TLS_AES_256_GCM_SHA384: //nolint: nosnakecase
|
||||||
return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes
|
return CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes //nolint: nosnakecase
|
||||||
case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256:
|
case CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256: //nolint: nosnakecase
|
||||||
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes
|
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes //nolint: nosnakecase
|
||||||
}
|
}
|
||||||
|
|
||||||
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes
|
return CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes //nolint: nosnakecase
|
||||||
}
|
}
|
||||||
|
|
||||||
type Version uint8
|
type Version uint8
|
||||||
@@ -69,9 +69,9 @@ var (
|
|||||||
Version12Bytes = []byte{0x03, 0x03}
|
Version12Bytes = []byte{0x03, 0x03}
|
||||||
Version13Bytes = []byte{0x03, 0x04}
|
Version13Bytes = []byte{0x03, 0x04}
|
||||||
|
|
||||||
CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint,revive
|
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} //nolint: stylecheck,golint,revive,nosnakecase
|
||||||
)
|
)
|
||||||
|
|
||||||
type Byter interface {
|
type Byter interface {
|
||||||
|
|||||||
+4
-2
@@ -65,7 +65,9 @@ func ReadRecord(reader io.Reader) (Record, error) {
|
|||||||
return rec, nil
|
return rec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeRecords(raw []byte) (arr []Record) {
|
func MakeRecords(raw []byte) []Record {
|
||||||
|
var arr []Record
|
||||||
|
|
||||||
for len(raw) > 0 {
|
for len(raw) > 0 {
|
||||||
chunkSize := recordMaxChunkSize
|
chunkSize := recordMaxChunkSize
|
||||||
if chunkSize > len(raw) {
|
if chunkSize > len(raw) {
|
||||||
@@ -80,5 +82,5 @@ func MakeRecords(raw []byte) (arr []Record) {
|
|||||||
raw = raw[chunkSize:]
|
raw = raw[chunkSize:]
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return arr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func NewServerHello(clientHello *ClientHello) *ServerHello {
|
|||||||
rv.SessionID = make([]byte, len(clientHello.SessionID))
|
rv.SessionID = make([]byte, len(clientHello.SessionID))
|
||||||
copy(rv.SessionID, clientHello.SessionID)
|
copy(rv.SessionID, clientHello.SessionID)
|
||||||
|
|
||||||
tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes)
|
tail := bytes.NewBuffer(CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes) //nolint: nosnakecase
|
||||||
tail.WriteByte(0x00) //nolint: gomnd // no compression
|
tail.WriteByte(0x00) //nolint: gomnd // no compression
|
||||||
makeTLSExtensions(tail)
|
makeTLSExtensions(tail)
|
||||||
rv.Tail = RawBytes(tail.Bytes())
|
rv.Tail = RawBytes(tail.Bytes())
|
||||||
|
|||||||
+3
-2
@@ -4,12 +4,13 @@ import "io"
|
|||||||
|
|
||||||
const readFullBufferSize = 1024 + 1 // +1 because telegram opreates with blocks mod 4
|
const readFullBufferSize = 1024 + 1 // +1 because telegram opreates with blocks mod 4
|
||||||
|
|
||||||
func ReadFull(src io.Reader) (rv []byte, err error) {
|
func ReadFull(src io.Reader) ([]byte, error) {
|
||||||
buf := make([]byte, readFullBufferSize)
|
buf := make([]byte, readFullBufferSize)
|
||||||
n := readFullBufferSize
|
n := readFullBufferSize
|
||||||
|
rv := []byte{}
|
||||||
|
|
||||||
for n == len(buf) {
|
for n == len(buf) {
|
||||||
n, err = src.Read(buf)
|
n, err := src.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err //nolint: wrapcheck
|
return nil, err //nolint: wrapcheck
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
//go:build !windows
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetLimits() error {
|
|
||||||
rLimit := unix.Rlimit{}
|
|
||||||
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
|
|
||||||
return fmt.Errorf("cannot get rlimit: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
rLimit.Cur = rLimit.Max
|
|
||||||
|
|
||||||
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
|
|
||||||
return fmt.Errorf("cannot set rlimit: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/conntypes"
|
"github.com/9seconds/mtg/conntypes"
|
||||||
@@ -28,10 +27,13 @@ var mtprotoFramePadding = []byte{0x04, 0x00, 0x00, 0x00}
|
|||||||
//
|
//
|
||||||
// MSGLEN is the length of the message + len of seqno and msglen.
|
// MSGLEN is the length of the message + len of seqno and msglen.
|
||||||
// SEQNO is the number of frame in the receive/send sequence. If client
|
// SEQNO is the number of frame in the receive/send sequence. If client
|
||||||
|
//
|
||||||
// sends a message with SeqNo 18, it has to receive message with SeqNo 18.
|
// sends a message with SeqNo 18, it has to receive message with SeqNo 18.
|
||||||
|
//
|
||||||
// MSG is the data which has to be written
|
// MSG is the data which has to be written
|
||||||
// CRC32 is the CRC32 checksum of MSGLEN + SEQNO + MSG
|
// CRC32 is the CRC32 checksum of MSGLEN + SEQNO + MSG
|
||||||
// PADDING is custom padding schema to complete frame length to such that
|
// PADDING is custom padding schema to complete frame length to such that
|
||||||
|
//
|
||||||
// len(frame) % 16 == 0
|
// len(frame) % 16 == 0
|
||||||
type wrapperMtprotoFrame struct {
|
type wrapperMtprotoFrame struct {
|
||||||
parent conntypes.StreamReadWriteCloser
|
parent conntypes.StreamReadWriteCloser
|
||||||
@@ -84,7 +86,7 @@ func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funl
|
|||||||
return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo)
|
return nil, fmt.Errorf("unexpected sequence number %d (wait for %d)", seqNo, w.readSeqNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, _ := ioutil.ReadAll(buf)
|
data, _ := io.ReadAll(buf)
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
// write to buf, not to writer. This is because we are going to fetch
|
// write to buf, not to writer. This is because we are going to fetch
|
||||||
// crc32 checksum.
|
// crc32 checksum.
|
||||||
|
|||||||
Reference in New Issue
Block a user