Przeglądaj źródła

Merge remote-tracking branch 'origin/stable' into v2

tags/v2.2.4
9seconds 1 miesiąc temu
rodzic
commit
006fba1046

+ 15
- 1
Dockerfile Wyświetl plik

5
 
5
 
6
 ENV CGO_ENABLED=0
6
 ENV CGO_ENABLED=0
7
 
7
 
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
+
8
 RUN --mount=type=cache,target=/var/cache/apk \
21
 RUN --mount=type=cache,target=/var/cache/apk \
9
     set -x \
22
     set -x \
10
     && apk --update add \
23
     && apk --update add \
35
 FROM scratch
48
 FROM scratch
36
 
49
 
37
 ENTRYPOINT ["/mtg"]
50
 ENTRYPOINT ["/mtg"]
38
-CMD ["run", "/config.toml"]
51
+CMD ["run", "/config/config.toml"]
39
 
52
 
40
 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
53
 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
41
 COPY --from=build /app/mtg /mtg
54
 COPY --from=build /app/mtg /mtg
42
 COPY --from=build /app/example.config.toml /config.toml
55
 COPY --from=build /app/example.config.toml /config.toml
56
+COPY --from=build /config /config

+ 32
- 0
README.md Wyświetl plik

301
 Ocean](https://www.digitalocean.com/). Then it might be a good idea to
301
 Ocean](https://www.digitalocean.com/). Then it might be a good idea to
302
 generate a secret for _digitalocean.com_ then.
302
 generate a secret for _digitalocean.com_ then.
303
 
303
 
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.
304
 
336
 
305
 ### Simple run mode
337
 ### Simple run mode
306
 
338
 

+ 30
- 0
essentials/addresses.go Wyświetl plik

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
+}

+ 2
- 1
go.mod Wyświetl plik

11
 	github.com/d4l3k/messagediff v1.2.1 // indirect
11
 	github.com/d4l3k/messagediff v1.2.1 // indirect
12
 	github.com/jarcoal/httpmock v1.0.8
12
 	github.com/jarcoal/httpmock v1.0.8
13
 	github.com/mccutchen/go-httpbin v1.1.1
13
 	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
15
 	github.com/prometheus/client_golang v1.23.2
15
 	github.com/prometheus/client_golang v1.23.2
16
 	github.com/prometheus/common v0.67.5 // indirect
16
 	github.com/prometheus/common v0.67.5 // indirect
17
 	github.com/prometheus/procfs v0.20.1 // indirect
17
 	github.com/prometheus/procfs v0.20.1 // indirect
27
 )
27
 )
28
 
28
 
29
 require (
29
 require (
30
+	github.com/beevik/ntp v1.5.0
30
 	github.com/ncruces/go-dns v1.3.2
31
 	github.com/ncruces/go-dns v1.3.2
31
 	github.com/pelletier/go-toml/v2 v2.2.4
32
 	github.com/pelletier/go-toml/v2 v2.2.4
32
 	github.com/pires/go-proxyproto v0.11.0
33
 	github.com/pires/go-proxyproto v0.11.0

+ 4
- 2
go.sum Wyświetl plik

12
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
12
 github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
13
 github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 h1:4NNbNM2Iq/k57qEu7WfL67UrbPq1uFWxW4qODCohi+0=
13
 github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6 h1:4NNbNM2Iq/k57qEu7WfL67UrbPq1uFWxW4qODCohi+0=
14
 github.com/babolivier/go-doh-client v0.0.0-20201028162107-a76cff4cb8b6/go.mod h1:J29hk+f9lJrblVIfiJOtTFk+OblBawmib4uz/VdKzlg=
14
 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=
15
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
17
 github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
16
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
18
 github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
17
 github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
19
 github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
53
 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
55
 github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
54
 github.com/ncruces/go-dns v1.3.2 h1:kBLuUZBgkQ4qF4WDXZRQ4rG0Gk6sLVJQ5tESkWrxUa0=
56
 github.com/ncruces/go-dns v1.3.2 h1:kBLuUZBgkQ4qF4WDXZRQ4rG0Gk6sLVJQ5tESkWrxUa0=
55
 github.com/ncruces/go-dns v1.3.2/go.mod h1:tuzixNY8PY/M7yUzcvRbUaeLs3ifIdydpi5H2bfRU+s=
57
 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=
58
 github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
60
 github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
59
 github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
61
 github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
60
 github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
62
 github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=

+ 2
- 47
internal/cli/access.go Wyświetl plik

1
 package cli
1
 package cli
2
 
2
 
3
 import (
3
 import (
4
-	"context"
5
 	"encoding/json"
4
 	"encoding/json"
6
 	"fmt"
5
 	"fmt"
7
-	"io"
8
 	"net"
6
 	"net"
9
-	"net/http"
10
 	"net/url"
7
 	"net/url"
11
 	"os"
8
 	"os"
12
 	"strconv"
9
 	"strconv"
13
-	"strings"
14
 	"sync"
10
 	"sync"
15
 
11
 
16
-	"github.com/9seconds/mtg/v2/essentials"
17
 	"github.com/9seconds/mtg/v2/internal/config"
12
 	"github.com/9seconds/mtg/v2/internal/config"
18
 	"github.com/9seconds/mtg/v2/internal/utils"
13
 	"github.com/9seconds/mtg/v2/internal/utils"
19
-	"github.com/9seconds/mtg/v2/mtglib"
20
 )
14
 )
21
 
15
 
22
 type accessResponse struct {
16
 type accessResponse struct {
65
 	wg.Go(func() {
59
 	wg.Go(func() {
66
 		ip := a.PublicIPv4
60
 		ip := a.PublicIPv4
67
 		if ip == nil {
61
 		if ip == nil {
68
-			ip = a.getIP(ntw, "tcp4")
62
+			ip = getIP(ntw, "tcp4")
69
 		}
63
 		}
70
 
64
 
71
 		if ip != nil {
65
 		if ip != nil {
77
 	wg.Go(func() {
71
 	wg.Go(func() {
78
 		ip := a.PublicIPv6
72
 		ip := a.PublicIPv6
79
 		if ip == nil {
73
 		if ip == nil {
80
-			ip = a.getIP(ntw, "tcp6")
74
+			ip = getIP(ntw, "tcp6")
81
 		}
75
 		}
82
 
76
 
83
 		if ip != nil {
77
 		if ip != nil {
100
 	return nil
94
 	return nil
101
 }
95
 }
102
 
96
 
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
-
142
 func (a *Access) makeURLs(conf *config.Config, ip net.IP) *accessResponseURLs {
97
 func (a *Access) makeURLs(conf *config.Config, ip net.IP) *accessResponseURLs {
143
 	if ip == nil {
98
 	if ip == nil {
144
 		return nil
99
 		return nil

+ 1
- 0
internal/cli/cli.go Wyświetl plik

4
 
4
 
5
 type CLI struct {
5
 type CLI struct {
6
 	GenerateSecret GenerateSecret   `kong:"cmd,help='Generate new proxy secret'"`
6
 	GenerateSecret GenerateSecret   `kong:"cmd,help='Generate new proxy secret'"`
7
+	Doctor         Doctor           `kong:"cmd,help='Check that proxy can run correctly'"`
7
 	Access         Access           `kong:"cmd,help='Print access information.'"`
8
 	Access         Access           `kong:"cmd,help='Print access information.'"`
8
 	Run            Run              `kong:"cmd,help='Run proxy.'"`
9
 	Run            Run              `kong:"cmd,help='Run proxy.'"`
9
 	SimpleRun      SimpleRun        `kong:"cmd,help='Run proxy without config file.'"`
10
 	SimpleRun      SimpleRun        `kong:"cmd,help='Run proxy without config file.'"`

+ 368
- 0
internal/cli/doctor.go Wyświetl plik

1
+package cli
2
+
3
+import (
4
+	"context"
5
+	"errors"
6
+	"fmt"
7
+	"maps"
8
+	"net"
9
+	"os"
10
+	"slices"
11
+	"strconv"
12
+	"strings"
13
+	"text/template"
14
+	"time"
15
+
16
+	"github.com/9seconds/mtg/v2/essentials"
17
+	"github.com/9seconds/mtg/v2/internal/config"
18
+	"github.com/9seconds/mtg/v2/internal/utils"
19
+	"github.com/9seconds/mtg/v2/mtglib"
20
+	"github.com/9seconds/mtg/v2/network/v2"
21
+	"github.com/beevik/ntp"
22
+)
23
+
24
+var (
25
+	tplError = template.Must(
26
+		template.New("").Parse("  ‼️ {{ .description }}: {{ .error }}\n"),
27
+	)
28
+
29
+	tplWDeprecatedConfig = template.Must(
30
+		template.New("").
31
+			Parse(`  ⚠️ Option {{ .old | printf "%q" }}{{ if .old_section }} from section [{{ .old_section }}]{{ end }} is deprecated and will be removed in v{{ .when }}. Please use {{ .new | printf "%q" }}{{ if .new_section }} in [{{ .new_section }}] section{{ end }} instead.` + "\n"),
32
+	)
33
+
34
+	tplOTimeSkewness = template.Must(
35
+		template.New("").
36
+			Parse("  ✅ Time drift is {{ .drift }}, but tolerate-time-skewness is {{ .value }}\n"),
37
+	)
38
+	tplWTimeSkewness = template.Must(
39
+		template.New("").
40
+			Parse("  ⚠️ Time drift is {{ .drift }}, but tolerate-time-skewness is {{ .value }}. Please check ntp.\n"),
41
+	)
42
+	tplETimeSkewness = template.Must(
43
+		template.New("").
44
+			Parse("  ❌ Time drift is {{ .drift }}, but tolerate-time-skewness is {{ .value }}. You will get many rejected connections!\n"),
45
+	)
46
+
47
+	tplODCConnect = template.Must(
48
+		template.New("").Parse("  ✅ DC {{ .dc }}\n"),
49
+	)
50
+	tplEDCConnect = template.Must(
51
+		template.New("").Parse("  ❌ DC {{ .dc }}: {{ .error }}\n"),
52
+	)
53
+
54
+	tplODNSSNIMatch = template.Must(
55
+		template.New("").Parse("  ✅ IP address {{ .ip }} matches secret hostname {{ .hostname }}\n"),
56
+	)
57
+	tplEDNSSNIMatch = template.Must(
58
+		template.New("").Parse("  ❌ Hostname {{ .hostname }} {{ if .resolved }}is resolved to {{ .resolved }} addresses, not {{ if .ip4 }}{{ .ip4 }}{{ else }}{{ .ip6 }}{{ end }}{{ else }}cannot be resolved to any host{{ end }}\n"),
59
+	)
60
+
61
+	tplOFrontingDomain = template.Must(
62
+		template.New("").Parse("  ✅ {{ .address }} is reachable\n"),
63
+	)
64
+	tplEFrontingDomain = template.Must(
65
+		template.New("").Parse("  ❌ {{ .address }}: {{ .error }}\n"),
66
+	)
67
+)
68
+
69
+type Doctor struct {
70
+	conf *config.Config
71
+
72
+	ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` //nolint: lll
73
+}
74
+
75
+func (d *Doctor) Run(cli *CLI, version string) error {
76
+	conf, err := utils.ReadConfig(d.ConfigPath)
77
+	if err != nil {
78
+		return fmt.Errorf("cannot init config: %w", err)
79
+	}
80
+
81
+	d.conf = conf
82
+
83
+	fmt.Println("Deprecated options")
84
+	everythingOK := d.checkDeprecatedConfig()
85
+
86
+	fmt.Println("Time skewness")
87
+	everythingOK = d.checkTimeSkewness() && everythingOK
88
+
89
+	resolver, err := network.GetDNS(conf.GetDNS())
90
+	if err != nil {
91
+		return fmt.Errorf("cannot create DNS resolver: %w", err)
92
+	}
93
+
94
+	base := network.New(
95
+		resolver,
96
+		"",
97
+		conf.Network.Timeout.TCP.Get(10*time.Second),
98
+		conf.Network.Timeout.HTTP.Get(0),
99
+		conf.Network.Timeout.Idle.Get(0),
100
+	)
101
+
102
+	fmt.Println("Validate native network connectivity")
103
+	everythingOK = d.checkNetwork(base) && everythingOK
104
+
105
+	for _, url := range conf.Network.Proxies {
106
+		value, err := network.NewProxyNetwork(base, url.Get(nil))
107
+		if err != nil {
108
+			return err
109
+		}
110
+
111
+		fmt.Printf("Validate network connectivity with proxy %s\n", url.Get(nil))
112
+		everythingOK = d.checkNetwork(value) && everythingOK
113
+	}
114
+
115
+	fmt.Println("Validate fronting domain connectivity")
116
+	everythingOK = d.checkFrontingDomain(base) && everythingOK
117
+
118
+	fmt.Println("Validate SNI-DNS match")
119
+	everythingOK = d.checkSecretHost(resolver, base) && everythingOK
120
+
121
+	if !everythingOK {
122
+		os.Exit(1)
123
+	}
124
+
125
+	return nil
126
+}
127
+
128
+func (d *Doctor) checkDeprecatedConfig() bool {
129
+	ok := true
130
+
131
+	if d.conf.DomainFrontingIP.Value != nil {
132
+		ok = false
133
+		tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
134
+			"when":        "2.3.0",
135
+			"old":         "domain-fronting-ip",
136
+			"old_section": "",
137
+			"new":         "ip",
138
+			"new_section": "domain-fronting",
139
+		})
140
+	}
141
+
142
+	if d.conf.DomainFrontingPort.Value != 0 {
143
+		ok = false
144
+		tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
145
+			"when":        "2.3.0",
146
+			"old":         "domain-fronting-port",
147
+			"old_section": "",
148
+			"new":         "port",
149
+			"new_section": "domain-fronting",
150
+		})
151
+	}
152
+
153
+	if d.conf.DomainFrontingProxyProtocol.Value {
154
+		ok = false
155
+		tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
156
+			"when":        "2.3.0",
157
+			"old":         "domain-fronting-proxy-protocol",
158
+			"old_section": "",
159
+			"new":         "proxy-protocol",
160
+			"new_section": "domain-fronting",
161
+		})
162
+	}
163
+
164
+	if d.conf.Network.DOHIP.Value != nil {
165
+		ok = false
166
+		tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
167
+			"when":        "2.3.0",
168
+			"old":         "doh-ip",
169
+			"old_section": "network",
170
+			"new":         "dns",
171
+			"new_section": "network",
172
+		})
173
+	}
174
+
175
+	if ok {
176
+		fmt.Println("  ✅ All good")
177
+	}
178
+
179
+	return ok
180
+}
181
+
182
+func (d *Doctor) checkTimeSkewness() bool {
183
+	response, err := ntp.Query("0.pool.ntp.org")
184
+	if err != nil {
185
+		tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
186
+			"description": "cannot access ntp pool",
187
+			"error":       err,
188
+		})
189
+		return false
190
+	}
191
+
192
+	skewness := response.ClockOffset.Abs()
193
+	confValue := d.conf.TolerateTimeSkewness.Get(mtglib.DefaultTolerateTimeSkewness)
194
+	diff := float64(skewness) / float64(confValue)
195
+	tplData := map[string]any{
196
+		"drift": response.ClockOffset,
197
+		"value": confValue,
198
+	}
199
+
200
+	switch {
201
+	case diff < 0.3:
202
+		tplOTimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
203
+		return true
204
+	case diff < 0.7:
205
+		tplWTimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
206
+	default:
207
+		tplETimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
208
+	}
209
+
210
+	return false
211
+}
212
+
213
+func (d *Doctor) checkNetwork(ntw mtglib.Network) bool {
214
+	dcs := slices.Collect(maps.Keys(essentials.TelegramCoreAddresses))
215
+	slices.Sort(dcs)
216
+
217
+	ok := true
218
+
219
+	for _, dc := range dcs {
220
+		err := d.checkNetworkAddresses(ntw, essentials.TelegramCoreAddresses[dc])
221
+		if err == nil {
222
+			tplODCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
223
+				"dc": dc,
224
+			})
225
+		} else {
226
+			tplEDCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
227
+				"dc":    dc,
228
+				"error": err,
229
+			})
230
+			ok = false
231
+		}
232
+	}
233
+
234
+	return ok
235
+}
236
+
237
+func (d *Doctor) checkNetworkAddresses(ntw mtglib.Network, addresses []string) error {
238
+	checkAddresses := []string{}
239
+
240
+	switch d.conf.PreferIP.Get("prefer-ip4") {
241
+	case "only-ipv4":
242
+		for _, addr := range addresses {
243
+			host, _, err := net.SplitHostPort(addr)
244
+			if err != nil {
245
+				panic(err)
246
+			}
247
+
248
+			if ip := net.ParseIP(host); ip != nil && ip.To4() != nil {
249
+				checkAddresses = append(checkAddresses, addr)
250
+			}
251
+		}
252
+	case "only-ipv6":
253
+		for _, addr := range addresses {
254
+			host, _, err := net.SplitHostPort(addr)
255
+			if err != nil {
256
+				panic(err)
257
+			}
258
+
259
+			if ip := net.ParseIP(host); ip != nil && ip.To4() == nil {
260
+				checkAddresses = append(checkAddresses, addr)
261
+			}
262
+		}
263
+	default:
264
+		checkAddresses = addresses
265
+	}
266
+
267
+	if len(checkAddresses) == 0 {
268
+		return fmt.Errorf("no suitable addresses after IP version filtering")
269
+	}
270
+
271
+	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
272
+	defer cancel()
273
+
274
+	var (
275
+		conn net.Conn
276
+		err  error
277
+	)
278
+
279
+	for _, addr := range checkAddresses {
280
+		conn, err = ntw.DialContext(ctx, "tcp", addr)
281
+		if err != nil {
282
+			continue
283
+		}
284
+
285
+		conn.Close() //nolint: errcheck
286
+
287
+		return nil
288
+	}
289
+
290
+	return err
291
+}
292
+
293
+func (d *Doctor) checkFrontingDomain(ntw mtglib.Network) bool {
294
+	host := d.conf.Secret.Host
295
+	if ip := d.conf.GetDomainFrontingIP(nil); ip != "" {
296
+		host = ip
297
+	}
298
+
299
+	port := d.conf.GetDomainFrontingPort(mtglib.DefaultDomainFrontingPort)
300
+	address := net.JoinHostPort(host, strconv.Itoa(int(port)))
301
+
302
+	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
303
+	defer cancel()
304
+
305
+	dialer := ntw.NativeDialer()
306
+
307
+	conn, err := dialer.DialContext(ctx, "tcp", address)
308
+	if err != nil {
309
+		tplEFrontingDomain.Execute(os.Stdout, map[string]any{ //nolint: errcheck
310
+			"address": address,
311
+			"error":   err,
312
+		})
313
+		return false
314
+	}
315
+
316
+	conn.Close() //nolint: errcheck
317
+
318
+	tplOFrontingDomain.Execute(os.Stdout, map[string]any{ //nolint: errcheck
319
+		"address": address,
320
+	})
321
+
322
+	return true
323
+}
324
+
325
+func (d *Doctor) checkSecretHost(resolver *net.Resolver, ntw mtglib.Network) bool {
326
+	addresses, err := resolver.LookupIPAddr(context.Background(), d.conf.Secret.Host)
327
+	if err != nil {
328
+		tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
329
+			"description": fmt.Sprintf("cannot resolve DNS name of %s", d.conf.Secret.Host),
330
+			"error":       err,
331
+		})
332
+		return false
333
+	}
334
+
335
+	ourIP4 := getIP(ntw, "tcp4")
336
+	ourIP6 := getIP(ntw, "tcp6")
337
+
338
+	if ourIP4 == nil && ourIP6 == nil {
339
+		tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
340
+			"description": "cannot detect public IP address",
341
+			"error":       errors.New("ifconfig.co is unreachable for both IPv4 and IPv6"),
342
+		})
343
+		return false
344
+	}
345
+
346
+	strAddresses := []string{}
347
+	for _, value := range addresses {
348
+		if (ourIP4 != nil && value.IP.String() == ourIP4.String()) ||
349
+			(ourIP6 != nil && value.IP.String() == ourIP6.String()) {
350
+			tplODNSSNIMatch.Execute(os.Stdout, map[string]any{ //nolint: errcheck
351
+				"ip":       value.IP,
352
+				"hostname": d.conf.Secret.Host,
353
+			})
354
+			return true
355
+		}
356
+
357
+		strAddresses = append(strAddresses, `"`+value.IP.String()+`"`)
358
+	}
359
+
360
+	tplEDNSSNIMatch.Execute(os.Stdout, map[string]any{ //nolint: errcheck
361
+		"hostname": d.conf.Secret.Host,
362
+		"resolved": strings.Join(strAddresses, ", "),
363
+		"ip4":      ourIP4,
364
+		"ip6":      ourIP6,
365
+	})
366
+
367
+	return false
368
+}

+ 1
- 0
internal/cli/run_proxy.go Wyświetl plik

253
 		EventStream:     eventStream,
253
 		EventStream:     eventStream,
254
 
254
 
255
 		Secret:                      conf.Secret,
255
 		Secret:                      conf.Secret,
256
+		Concurrency:                 conf.GetConcurrency(mtglib.DefaultConcurrency),
256
 		DomainFrontingPort:          conf.GetDomainFrontingPort(mtglib.DefaultDomainFrontingPort),
257
 		DomainFrontingPort:          conf.GetDomainFrontingPort(mtglib.DefaultDomainFrontingPort),
257
 		DomainFrontingIP:            conf.GetDomainFrontingIP(nil),
258
 		DomainFrontingIP:            conf.GetDomainFrontingIP(nil),
258
 		DomainFrontingProxyProtocol: conf.GetDomainFrontingProxyProtocol(false),
259
 		DomainFrontingProxyProtocol: conf.GetDomainFrontingProxyProtocol(false),

+ 51
- 0
internal/cli/utils.go Wyświetl plik

1
+package cli
2
+
3
+import (
4
+	"context"
5
+	"io"
6
+	"net"
7
+	"net/http"
8
+	"strings"
9
+
10
+	"github.com/9seconds/mtg/v2/essentials"
11
+	"github.com/9seconds/mtg/v2/mtglib"
12
+)
13
+
14
+func getIP(ntw mtglib.Network, protocol string) net.IP {
15
+	dialer := ntw.NativeDialer()
16
+	client := ntw.MakeHTTPClient(func(ctx context.Context, network, address string) (essentials.Conn, error) {
17
+		conn, err := dialer.DialContext(ctx, protocol, address)
18
+		if err != nil {
19
+			return nil, err
20
+		}
21
+		return essentials.WrapNetConn(conn), err
22
+	})
23
+
24
+	req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil) //nolint: noctx
25
+	if err != nil {
26
+		panic(err)
27
+	}
28
+
29
+	req.Header.Add("Accept", "text/plain")
30
+
31
+	resp, err := client.Do(req)
32
+	if err != nil {
33
+		return nil
34
+	}
35
+
36
+	if resp.StatusCode != http.StatusOK {
37
+		return nil
38
+	}
39
+
40
+	defer func() {
41
+		io.Copy(io.Discard, resp.Body) //nolint: errcheck
42
+		resp.Body.Close()              //nolint: errcheck
43
+	}()
44
+
45
+	data, err := io.ReadAll(resp.Body)
46
+	if err != nil {
47
+		return nil
48
+	}
49
+
50
+	return net.ParseIP(strings.TrimSpace(string(data)))
51
+}

+ 7
- 0
internal/config/config.go Wyświetl plik

84
 	} `json:"stats"`
84
 	} `json:"stats"`
85
 }
85
 }
86
 
86
 
87
+func (c *Config) GetConcurrency(defaultValue uint) uint {
88
+	if concurrency := c.Concurrency.Get(0); concurrency != 0 {
89
+		return concurrency
90
+	}
91
+	return c.Concurrency.Get(defaultValue)
92
+}
93
+
87
 func (c *Config) GetDNS() *url.URL {
94
 func (c *Config) GetDNS() *url.URL {
88
 	var dohURL *url.URL
95
 	var dohURL *url.URL
89
 
96
 

+ 95
- 16
mise.lock Wyświetl plik

1
+# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html
2
+
1
 [[tools.go]]
3
 [[tools.go]]
2
 version = "1.26.1"
4
 version = "1.26.1"
3
 backend = "core:go"
5
 backend = "core:go"
4
-"platforms.linux-arm64" = { checksum = "sha256:a290581cfe4fe28ddd737dde3095f3dbeb7f2e4065cab4eae44dfc53b760c2f7", url = "https://dl.google.com/go/go1.26.1.linux-arm64.tar.gz"}
5
-"platforms.linux-x64" = { checksum = "sha256:031f088e5d955bab8657ede27ad4e3bc5b7c1ba281f05f245bcc304f327c987a", url = "https://dl.google.com/go/go1.26.1.linux-amd64.tar.gz"}
6
-"platforms.macos-arm64" = { checksum = "sha256:353df43a7811ce284c8938b5f3c7df40b7bfb6f56cb165b150bc40b5e2dd541f", url = "https://dl.google.com/go/go1.26.1.darwin-arm64.tar.gz"}
7
-"platforms.macos-x64" = { checksum = "sha256:65773dab2f8cc4cd23d93ba6d0a805de150ca0b78378879292be0b903b8cdd08", url = "https://dl.google.com/go/go1.26.1.darwin-amd64.tar.gz"}
8
-"platforms.windows-x64" = { checksum = "sha256:9b68112c913f45b7aebbf13c036721264bbba7e03a642f8f7490c561eebd1ecc", url = "https://dl.google.com/go/go1.26.1.windows-amd64.zip"}
6
+
7
+[tools.go."platforms.linux-arm64"]
8
+checksum = "sha256:a290581cfe4fe28ddd737dde3095f3dbeb7f2e4065cab4eae44dfc53b760c2f7"
9
+url = "https://dl.google.com/go/go1.26.1.linux-arm64.tar.gz"
10
+
11
+[tools.go."platforms.linux-arm64-musl"]
12
+checksum = "sha256:a290581cfe4fe28ddd737dde3095f3dbeb7f2e4065cab4eae44dfc53b760c2f7"
13
+url = "https://dl.google.com/go/go1.26.1.linux-arm64.tar.gz"
14
+
15
+[tools.go."platforms.linux-x64"]
16
+checksum = "sha256:031f088e5d955bab8657ede27ad4e3bc5b7c1ba281f05f245bcc304f327c987a"
17
+url = "https://dl.google.com/go/go1.26.1.linux-amd64.tar.gz"
18
+
19
+[tools.go."platforms.linux-x64-musl"]
20
+checksum = "sha256:031f088e5d955bab8657ede27ad4e3bc5b7c1ba281f05f245bcc304f327c987a"
21
+url = "https://dl.google.com/go/go1.26.1.linux-amd64.tar.gz"
22
+
23
+[tools.go."platforms.macos-arm64"]
24
+checksum = "sha256:353df43a7811ce284c8938b5f3c7df40b7bfb6f56cb165b150bc40b5e2dd541f"
25
+url = "https://dl.google.com/go/go1.26.1.darwin-arm64.tar.gz"
26
+
27
+[tools.go."platforms.macos-x64"]
28
+checksum = "sha256:65773dab2f8cc4cd23d93ba6d0a805de150ca0b78378879292be0b903b8cdd08"
29
+url = "https://dl.google.com/go/go1.26.1.darwin-amd64.tar.gz"
30
+
31
+[tools.go."platforms.windows-x64"]
32
+checksum = "sha256:9b68112c913f45b7aebbf13c036721264bbba7e03a642f8f7490c561eebd1ecc"
33
+url = "https://dl.google.com/go/go1.26.1.windows-amd64.zip"
9
 
34
 
10
 [[tools."go:golang.org/x/pkgsite/cmd/pkgsite"]]
35
 [[tools."go:golang.org/x/pkgsite/cmd/pkgsite"]]
11
 version = "latest"
36
 version = "latest"
24
 backend = "go:mvdan.cc/gofumpt"
49
 backend = "go:mvdan.cc/gofumpt"
25
 
50
 
26
 [[tools.golangci-lint]]
51
 [[tools.golangci-lint]]
27
-version = "2.11.3"
52
+version = "2.11.4"
28
 backend = "aqua:golangci/golangci-lint"
53
 backend = "aqua:golangci/golangci-lint"
29
-"platforms.linux-arm64" = { checksum = "sha256:ee3d95f301359e7d578e6d99c8ad5aeadbabc5a13009a30b2b0df11c8058afe9", url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.3/golangci-lint-2.11.3-linux-arm64.tar.gz"}
30
-"platforms.linux-x64" = { checksum = "sha256:87bb8cddbcc825d5778b64e8a91b46c0526b247f4e2f2904dea74ec7450475d1", url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.3/golangci-lint-2.11.3-linux-amd64.tar.gz"}
31
-"platforms.macos-arm64" = { checksum = "sha256:30ee39979c516b9d1adca289a3f93429d130c4c0fda5e57d637850894221f6cc", url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.3/golangci-lint-2.11.3-darwin-arm64.tar.gz"}
32
-"platforms.macos-x64" = { checksum = "sha256:f93bda1f2cc981fd1326464020494be62f387bbf262706e1b3b644e5afacc440", url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.3/golangci-lint-2.11.3-darwin-amd64.tar.gz"}
33
-"platforms.windows-x64" = { checksum = "sha256:cd42e890176bc5cfeb36225a77e66b9410ddd3a59a03551e23f6b210d29e1f67", url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.3/golangci-lint-2.11.3-windows-amd64.zip"}
54
+
55
+[tools.golangci-lint."platforms.linux-arm64"]
56
+checksum = "sha256:3bcfa2e6f3d32b2bf5cd75eaa876447507025e0303698633f722a05331988db4"
57
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-linux-arm64.tar.gz"
58
+
59
+[tools.golangci-lint."platforms.linux-arm64-musl"]
60
+checksum = "sha256:3bcfa2e6f3d32b2bf5cd75eaa876447507025e0303698633f722a05331988db4"
61
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-linux-arm64.tar.gz"
62
+
63
+[tools.golangci-lint."platforms.linux-x64"]
64
+checksum = "sha256:200c5b7503f67b59a6743ccf32133026c174e272b930ee79aa2aa6f37aca7ef1"
65
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-linux-amd64.tar.gz"
66
+
67
+[tools.golangci-lint."platforms.linux-x64-musl"]
68
+checksum = "sha256:200c5b7503f67b59a6743ccf32133026c174e272b930ee79aa2aa6f37aca7ef1"
69
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-linux-amd64.tar.gz"
70
+
71
+[tools.golangci-lint."platforms.macos-arm64"]
72
+checksum = "sha256:02db2a2dae8b26812e53b0688a6f617e3ef1f489790e829ea22862cf76945675"
73
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-darwin-arm64.tar.gz"
74
+provenance = "github-attestations"
75
+
76
+[tools.golangci-lint."platforms.macos-x64"]
77
+checksum = "sha256:c900d4048db75d1edfd550fd11cf6a9b3008e7caa8e119fcddbc700412d63e60"
78
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-darwin-amd64.tar.gz"
79
+
80
+[tools.golangci-lint."platforms.windows-x64"]
81
+checksum = "sha256:4932cfca5e75bf60fe1c576edf459e5e809e6644664a068185d64b84af3fad9e"
82
+url = "https://github.com/golangci/golangci-lint/releases/download/v2.11.4/golangci-lint-2.11.4-windows-amd64.zip"
34
 
83
 
35
 [[tools.goreleaser]]
84
 [[tools.goreleaser]]
36
 version = "2.14.3"
85
 version = "2.14.3"
37
 backend = "aqua:goreleaser/goreleaser"
86
 backend = "aqua:goreleaser/goreleaser"
38
-"platforms.linux-arm64" = { checksum = "sha256:581a10e53c1176b3e81ee45cf531e02dbf899db0bc7b795669347df4276ce948", url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_arm64.tar.gz"}
39
-"platforms.linux-x64" = { checksum = "sha256:dc7faeeeb6da8bdfda788626263a4ae725892a8c7504b975c3234127d4a44579", url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_x86_64.tar.gz"}
40
-"platforms.macos-arm64" = { checksum = "sha256:3507798489e107a78aff36b169de48148a335ac26eb3161608d905f3f3a957bd", url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Darwin_all.tar.gz"}
41
-"platforms.macos-x64" = { checksum = "sha256:3507798489e107a78aff36b169de48148a335ac26eb3161608d905f3f3a957bd", url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Darwin_all.tar.gz"}
42
-"platforms.windows-x64" = { checksum = "sha256:3deea8ff471aa258a2d99f3e5302971d7028647ae8ddaf103257a8113e485a31", url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Windows_x86_64.zip"}
87
+
88
+[tools.goreleaser."platforms.linux-arm64"]
89
+checksum = "sha256:581a10e53c1176b3e81ee45cf531e02dbf899db0bc7b795669347df4276ce948"
90
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_arm64.tar.gz"
91
+provenance = "cosign"
92
+
93
+[tools.goreleaser."platforms.linux-arm64-musl"]
94
+checksum = "sha256:581a10e53c1176b3e81ee45cf531e02dbf899db0bc7b795669347df4276ce948"
95
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_arm64.tar.gz"
96
+provenance = "cosign"
97
+
98
+[tools.goreleaser."platforms.linux-x64"]
99
+checksum = "sha256:dc7faeeeb6da8bdfda788626263a4ae725892a8c7504b975c3234127d4a44579"
100
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_x86_64.tar.gz"
101
+provenance = "cosign"
102
+
103
+[tools.goreleaser."platforms.linux-x64-musl"]
104
+checksum = "sha256:dc7faeeeb6da8bdfda788626263a4ae725892a8c7504b975c3234127d4a44579"
105
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Linux_x86_64.tar.gz"
106
+provenance = "cosign"
107
+
108
+[tools.goreleaser."platforms.macos-arm64"]
109
+checksum = "sha256:3507798489e107a78aff36b169de48148a335ac26eb3161608d905f3f3a957bd"
110
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Darwin_all.tar.gz"
111
+provenance = "cosign"
112
+
113
+[tools.goreleaser."platforms.macos-x64"]
114
+checksum = "sha256:3507798489e107a78aff36b169de48148a335ac26eb3161608d905f3f3a957bd"
115
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Darwin_all.tar.gz"
116
+provenance = "cosign"
117
+
118
+[tools.goreleaser."platforms.windows-x64"]
119
+checksum = "sha256:3deea8ff471aa258a2d99f3e5302971d7028647ae8ddaf103257a8113e485a31"
120
+url = "https://github.com/goreleaser/goreleaser/releases/download/v2.14.3/goreleaser_Windows_x86_64.zip"
121
+provenance = "cosign"

+ 36
- 43
mtglib/internal/dc/init.go Wyświetl plik

2
 
2
 
3
 import (
3
 import (
4
 	"context"
4
 	"context"
5
+	"net"
5
 	"time"
6
 	"time"
7
+
8
+	"github.com/9seconds/mtg/v2/essentials"
6
 )
9
 )
7
 
10
 
8
 type preferIP uint8
11
 type preferIP uint8
39
 }
42
 }
40
 
43
 
41
 // https://github.com/telegramdesktop/tdesktop/blob/master/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp#L30
44
 // https://github.com/telegramdesktop/tdesktop/blob/master/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp#L30
42
-var defaultDCAddrSet = dcAddrSet{
43
-	v4: map[int][]Addr{
44
-		1: {
45
-			{Network: "tcp4", Address: "149.154.175.50:443"},
46
-		},
47
-		2: {
48
-			{Network: "tcp4", Address: "149.154.167.51:443"},
49
-			{Network: "tcp4", Address: "95.161.76.100:443"},
50
-		},
51
-		3: {
52
-			{Network: "tcp4", Address: "149.154.175.100:443"},
53
-		},
54
-		4: {
55
-			{Network: "tcp4", Address: "149.154.167.91:443"},
56
-		},
57
-		5: {
58
-			{Network: "tcp4", Address: "149.154.171.5:443"},
59
-		},
60
-		203: {
61
-			{Network: "tcp4", Address: "91.105.192.100:443"},
62
-		},
63
-	},
64
-	v6: map[int][]Addr{
65
-		1: {
66
-			{Network: "tcp6", Address: "[2001:b28:f23d:f001::a]:443"},
67
-		},
68
-		2: {
69
-			{Network: "tcp6", Address: "[2001:67c:04e8:f002::a]:443"},
70
-		},
71
-		3: {
72
-			{Network: "tcp6", Address: "[2001:b28:f23d:f003::a]:443"},
73
-		},
74
-		4: {
75
-			{Network: "tcp6", Address: "[2001:67c:04e8:f004::a]:443"},
76
-		},
77
-		5: {
78
-			{Network: "tcp6", Address: "[2001:b28:f23f:f005::a]:443"},
79
-		},
80
-		203: {
81
-			{Network: "tcp6", Address: "[2a0a:f280:0203:000a:5000:0000:0000:0100]:443"},
82
-		},
83
-	},
84
-}
45
+var defaultDCAddrSet = (func() dcAddrSet {
46
+	addrSet := dcAddrSet{
47
+		v4: make(map[int][]Addr),
48
+		v6: make(map[int][]Addr),
49
+	}
50
+
51
+	for dcid, ips := range essentials.TelegramCoreAddresses {
52
+		for _, addr := range ips {
53
+			host, _, err := net.SplitHostPort(addr)
54
+			if err != nil {
55
+				panic(err)
56
+			}
57
+
58
+			ip := net.ParseIP(host)
59
+			if ip == nil {
60
+				panic(addr)
61
+			}
62
+			if ip.To4() == nil {
63
+				addrSet.v6[dcid] = append(addrSet.v6[dcid], Addr{
64
+					Network: "tcp6",
65
+					Address: addr,
66
+				})
67
+			} else {
68
+				addrSet.v4[dcid] = append(addrSet.v4[dcid], Addr{
69
+					Network: "tcp4",
70
+					Address: addr,
71
+				})
72
+			}
73
+		}
74
+	}
75
+
76
+	return addrSet
77
+})()

+ 0
- 1
run_profile.go Wyświetl plik

3
 package main
3
 package main
4
 
4
 
5
 func runProfile() {
5
 func runProfile() {
6
-
7
 }
6
 }

Ładowanie…
Anuluj
Zapisz