Skip to content

Commit 006fba1

Browse files
committed
Merge remote-tracking branch 'origin/stable' into v2
2 parents 7fec309 + 7b333ed commit 006fba1

File tree

14 files changed

+644
-111
lines changed

14 files changed

+644
-111
lines changed

Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ FROM golang:1.26-alpine AS build
55

66
ENV CGO_ENABLED=0
77

8+
# this is done for backward compatibility: before that we mounted a config
9+
# into /config.toml. Some application allow mounting directories only,
10+
# so it makes problems. So, instead we are going to do 2 steps:
11+
# 1. Create /config/config.toml as a symlink to /config.toml
12+
# 2. Force /mtg to use /config/config.toml
13+
#
14+
# it helps in both ways: users with directories could use /config directory
15+
# and overlap a symlink by their bind mount. Old users could continue using
16+
# /config.toml as a real config.
17+
RUN set -x \
18+
&& mkdir -p /config \
19+
&& ln -sv /config.toml /config/config.toml
20+
821
RUN --mount=type=cache,target=/var/cache/apk \
922
set -x \
1023
&& apk --update add \
@@ -35,8 +48,9 @@ RUN set -x \
3548
FROM scratch
3649

3750
ENTRYPOINT ["/mtg"]
38-
CMD ["run", "/config.toml"]
51+
CMD ["run", "/config/config.toml"]
3952

4053
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
4154
COPY --from=build /app/mtg /mtg
4255
COPY --from=build /app/example.config.toml /config.toml
56+
COPY --from=build /config /config

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,38 @@ For example, you've bought a VPS from [Digital
301301
Ocean](https://www.digitalocean.com/). Then it might be a good idea to
302302
generate a secret for _digitalocean.com_ then.
303303

304+
### Check configuration
305+
306+
There is a special command for secret verification:
307+
308+
```
309+
$ mtg doctor /path/to/my/config.toml
310+
Deprecated options
311+
✅ All good
312+
Time skewness
313+
✅ Time drift is -607.048µs, but tolerate-time-skewness is 5s
314+
Validate native network connectivity
315+
✅ DC 1
316+
✅ DC 2
317+
✅ DC 3
318+
✅ DC 4
319+
✅ DC 5
320+
✅ DC 203
321+
Validate network connectivity with proxy socks5://127.0.0.1:1080
322+
✅ DC 1
323+
✅ DC 2
324+
✅ DC 3
325+
✅ DC 4
326+
✅ DC 5
327+
✅ DC 203
328+
Validate fronting domain connectivity
329+
✅ xx.xx.xx.xx:yyy is reachable
330+
Validate SNI-DNS match
331+
✅ IP address xx.xx.xx.xx matches secret hostname <REDACTED>
332+
```
333+
334+
It aims to find out possible inconsistencies and problems with your
335+
configuration. It makes sense to run it before executing any relevant commands.
304336

305337
### Simple run mode
306338

essentials/addresses.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package essentials
2+
3+
// TelegramCoreAddresses are publicly known addresses of Telegram core network.
4+
var TelegramCoreAddresses = map[int][]string{
5+
1: {
6+
"149.154.175.50:443",
7+
"[2001:b28:f23d:f001::a]:443",
8+
},
9+
2: {
10+
"149.154.167.51:443",
11+
"95.161.76.100:443",
12+
"[2001:67c:04e8:f002::a]:443",
13+
},
14+
3: {
15+
"149.154.175.100:443",
16+
"[2001:b28:f23d:f003::a]:443",
17+
},
18+
4: {
19+
"149.154.167.91:443",
20+
"[2001:67c:04e8:f004::a]:443",
21+
},
22+
5: {
23+
"149.154.171.5:443",
24+
"[2001:b28:f23f:f005::a]:443",
25+
},
26+
203: {
27+
"91.105.192.100:443",
28+
"[2a0a:f280:0203:000a:5000:0000:0000:0100]:443",
29+
},
30+
}

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/d4l3k/messagediff v1.2.1 // indirect
1212
github.com/jarcoal/httpmock v1.0.8
1313
github.com/mccutchen/go-httpbin v1.1.1
14-
github.com/panjf2000/ants/v2 v2.11.6
14+
github.com/panjf2000/ants/v2 v2.12.0
1515
github.com/prometheus/client_golang v1.23.2
1616
github.com/prometheus/common v0.67.5 // indirect
1717
github.com/prometheus/procfs v0.20.1 // indirect
@@ -27,6 +27,7 @@ require (
2727
)
2828

2929
require (
30+
github.com/beevik/ntp v1.5.0
3031
github.com/ncruces/go-dns v1.3.2
3132
github.com/pelletier/go-toml/v2 v2.2.4
3233
github.com/pires/go-proxyproto v0.11.0

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
1212
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
1313
github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 h1:4NNbNM2Iq/k57qEu7WfL67UrbPq1uFWxW4qODCohi+0=
1414
github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6/go.mod h1:J29hk+f9lJrblVIfiJOtTFk+OblBawmib4uz/VdKzlg=
15+
github.com/beevik/ntp v1.5.0 h1:y+uj/JjNwlY2JahivxYvtmv4ehfi3h74fAuABB9ZSM4=
16+
github.com/beevik/ntp v1.5.0/go.mod h1:mJEhBrwT76w9D+IfOEGvuzyuudiW9E52U2BaTrMOYow=
1517
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1618
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
1719
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -53,8 +55,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
5355
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
5456
github.com/ncruces/go-dns v1.3.2 h1:kBLuUZBgkQ4qF4WDXZRQ4rG0Gk6sLVJQ5tESkWrxUa0=
5557
github.com/ncruces/go-dns v1.3.2/go.mod h1:tuzixNY8PY/M7yUzcvRbUaeLs3ifIdydpi5H2bfRU+s=
56-
github.com/panjf2000/ants/v2 v2.11.6 h1:JKsoIUukIoCO0sP0gcOqdyoXmpyKXuU6fC57rODtpug=
57-
github.com/panjf2000/ants/v2 v2.11.6/go.mod h1:8u92CYMUc6gyvTIw8Ru7Mt7+/ESnJahz5EVtqfrilek=
58+
github.com/panjf2000/ants/v2 v2.12.0 h1:u9JhESo83i/GkZnhfTNuFMMWcNt7mnV1bGJ6FT4wXH8=
59+
github.com/panjf2000/ants/v2 v2.12.0/go.mod h1:tSQuaNQ6r6NRhPt+IZVUevvDyFMTs+eS4ztZc52uJTY=
5860
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
5961
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
6062
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=

internal/cli/access.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package cli
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
7-
"io"
86
"net"
9-
"net/http"
107
"net/url"
118
"os"
129
"strconv"
13-
"strings"
1410
"sync"
1511

16-
"github.com/9seconds/mtg/v2/essentials"
1712
"github.com/9seconds/mtg/v2/internal/config"
1813
"github.com/9seconds/mtg/v2/internal/utils"
19-
"github.com/9seconds/mtg/v2/mtglib"
2014
)
2115

2216
type accessResponse struct {
@@ -65,7 +59,7 @@ func (a *Access) Run(cli *CLI, version string) error {
6559
wg.Go(func() {
6660
ip := a.PublicIPv4
6761
if ip == nil {
68-
ip = a.getIP(ntw, "tcp4")
62+
ip = getIP(ntw, "tcp4")
6963
}
7064

7165
if ip != nil {
@@ -77,7 +71,7 @@ func (a *Access) Run(cli *CLI, version string) error {
7771
wg.Go(func() {
7872
ip := a.PublicIPv6
7973
if ip == nil {
80-
ip = a.getIP(ntw, "tcp6")
74+
ip = getIP(ntw, "tcp6")
8175
}
8276

8377
if ip != nil {
@@ -100,45 +94,6 @@ func (a *Access) Run(cli *CLI, version string) error {
10094
return nil
10195
}
10296

103-
func (a *Access) getIP(ntw mtglib.Network, protocol string) net.IP {
104-
dialer := ntw.NativeDialer()
105-
client := ntw.MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error) {
106-
conn, err := dialer.DialContext(ctx, protocol, address)
107-
if err != nil {
108-
return nil, err
109-
}
110-
return essentials.WrapNetConn(conn), err
111-
})
112-
113-
req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil) //nolint: noctx
114-
if err != nil {
115-
panic(err)
116-
}
117-
118-
req.Header.Add("Accept", "text/plain")
119-
120-
resp, err := client.Do(req)
121-
if err != nil {
122-
return nil
123-
}
124-
125-
if resp.StatusCode != http.StatusOK {
126-
return nil
127-
}
128-
129-
defer func() {
130-
io.Copy(io.Discard, resp.Body) //nolint: errcheck
131-
resp.Body.Close() //nolint: errcheck
132-
}()
133-
134-
data, err := io.ReadAll(resp.Body)
135-
if err != nil {
136-
return nil
137-
}
138-
139-
return net.ParseIP(strings.TrimSpace(string(data)))
140-
}
141-
14297
func (a *Access) makeURLs(conf *config.Config, ip net.IP) *accessResponseURLs {
14398
if ip == nil {
14499
return nil

internal/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "github.com/alecthomas/kong"
44

55
type CLI struct {
66
GenerateSecret GenerateSecret `kong:"cmd,help='Generate new proxy secret'"`
7+
Doctor Doctor `kong:"cmd,help='Check that proxy can run correctly'"`
78
Access Access `kong:"cmd,help='Print access information.'"`
89
Run Run `kong:"cmd,help='Run proxy.'"`
910
SimpleRun SimpleRun `kong:"cmd,help='Run proxy without config file.'"`

0 commit comments

Comments
 (0)