9seconds 5 лет назад
Родитель
Сommit
09f8233bc6
4 измененных файлов: 64 добавлений и 40 удалений
  1. 45
    29
      example.config.toml
  2. 3
    0
      go.sum
  3. 5
    3
      mtglib/network/network.go
  4. 11
    8
      raw_config.go

+ 45
- 29
example.config.toml Просмотреть файл

@@ -51,40 +51,26 @@ cloak-port = 443
51 51
 # Pass filepath here or '-' if you want to dump into stdout.
52 52
 access-file = "-"
53 53
 
54
-# FakeTLS can compare timestamps to prevent probes. Each message has
55
-# encrypted timestamp. So, mtg can compare this timestamp and decide if
56
-# we need to proceed with connection or not.
54
+# network defines different network-related settings
55
+[network]
56
+# please be aware that mtg needs to do some external requests. For
57
+# example, if you do not pass public ips, it will request your public ip
58
+# address from some external service.
57 59
 #
58
-# Please ensure that you have some ntp active on this host. Otherwise,
59
-# you can endup with badly performing proxy.
60
-[probes.time]
61
-# You can enable/disable that. A good idea is always enable.
62
-enabled = true
63
-# Time can be skewed by many reasons. So, this is a time interval
64
-# when message is cosidered as a good one.
65
-allow-skewness = "5s"
66
-
67
-# Some countries do active probing on Telegram connections. This technique
68
-# allows to protect from such effort.
60
+# As for 2.0, if you set a public-ip on your own, mtg won't issue any
61
+# network requests except of those required for Telegram.
69 62
 #
70
-# mtg has a cache of some connection fingerprints. Actually, first bytes
71
-# of each connection. So, it stores them in some in-memory LRU+TTL cache.
72
-# You can configure this cache here.
73
-[probes.anti-replay]
74
-# You can enable/disable this feature.
75
-enabled = true
76
-# max size of such a cache. Please be aware that this number is
77
-# approximate we try hard to store data quite dense but it is possible
78
-# that we can go over this limit for 10-20% under some conditions and
79
-# architectures.
80
-max-size = "16mb"
81
-# TTL for each cache record.
82
-ttl = "8h"
63
+# so, in order of doing them, it needs to do DNS lookup. mtg ignores DNS
64
+# resolver of the operating system and uses DOH instead. This is a host
65
+# it has to access.
66
+#
67
+# By default we use Quad9.
68
+doh-hostname = "9.9.9.9"
83 69
 
84 70
 # public ip addresses of the server. Actually, it is required only to
85 71
 # generate a correct access file. if you use default values here, mtg
86 72
 # will try to resolve these IPs on its own.
87
-[public-ip]
73
+[network.public-ip]
88 74
 ipv4 = ""
89 75
 ipv6 = ""
90 76
 
@@ -109,10 +95,40 @@ ipv6 = ""
109 95
 # ignored.
110 96
 #
111 97
 # If telegram dialer is not defined, a default one is going to be used.
112
-[dialers]
98
+[network.dialers]
113 99
 telegram = ""
114 100
 default = ""
115 101
 
102
+# FakeTLS can compare timestamps to prevent probes. Each message has
103
+# encrypted timestamp. So, mtg can compare this timestamp and decide if
104
+# we need to proceed with connection or not.
105
+#
106
+# Please ensure that you have some ntp active on this host. Otherwise,
107
+# you can endup with badly performing proxy.
108
+[probes.time]
109
+# You can enable/disable that. A good idea is always enable.
110
+enabled = true
111
+# Time can be skewed by many reasons. So, this is a time interval
112
+# when message is cosidered as a good one.
113
+allow-skewness = "5s"
114
+
115
+# Some countries do active probing on Telegram connections. This technique
116
+# allows to protect from such effort.
117
+#
118
+# mtg has a cache of some connection fingerprints. Actually, first bytes
119
+# of each connection. So, it stores them in some in-memory LRU+TTL cache.
120
+# You can configure this cache here.
121
+[probes.anti-replay]
122
+# You can enable/disable this feature.
123
+enabled = true
124
+# max size of such a cache. Please be aware that this number is
125
+# approximate we try hard to store data quite dense but it is possible
126
+# that we can go over this limit for 10-20% under some conditions and
127
+# architectures.
128
+max-size = "16mb"
129
+# TTL for each cache record.
130
+ttl = "8h"
131
+
116 132
 # statsd statistics integration.
117 133
 [stats.statsd]
118 134
 # enabled/disabled

+ 3
- 0
go.sum Просмотреть файл

@@ -9,12 +9,14 @@ github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNC
9 9
 github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc=
10 10
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
11 11
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
12
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
12 13
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
13 14
 github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 h1:f/FNXud6gA3MNr8meMVVGxhp+QBTqY91tM8HjEuMjGg=
14 15
 github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3/go.mod h1:HgjTstvQsPGkxUsCd2KWxErBblirPizecHcpD3ffK+s=
15 16
 github.com/shadowsocks/go-shadowsocks2 v0.1.4 h1:4VzajPL7RwwmImysBSvI+lm/UaegDGQq3hr42dYo3gs=
16 17
 github.com/shadowsocks/go-shadowsocks2 v0.1.4/go.mod h1:AGGpIoek4HRno4xzyFiAtLHkOpcoznZEkAccaI/rplM=
17 18
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19
+github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
18 20
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
19 21
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
20 22
 golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 h1:/ZScEX8SfEmUGRHs0gxpqteO5nfNW6axyZbBdw9A12g=
@@ -33,4 +35,5 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
33 35
 golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
34 36
 golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
35 37
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
36 39
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 5
- 3
mtglib/network/network.go Просмотреть файл

@@ -30,9 +30,11 @@ func (d *Network) DialContext(ctx context.Context, network, address string) (net
30 30
 		return nil, fmt.Errorf("cannot resolve dns names: %w", err)
31 31
 	}
32 32
 
33
-	rand.Shuffle(len(ips), func(i, j int) {
34
-		ips[i], ips[j] = ips[j], ips[i]
35
-	})
33
+	if len(ips) > 1 {
34
+		rand.Shuffle(len(ips), func(i, j int) {
35
+			ips[i], ips[j] = ips[j], ips[i]
36
+		})
37
+	}
36 38
 
37 39
 	for _, v := range ips {
38 40
 		if conn, err := d.dialer.DialContext(ctx, network, net.JoinHostPort(v, port)); err == nil {

+ 11
- 8
raw_config.go Просмотреть файл

@@ -26,14 +26,17 @@ type rawConfig struct {
26 26
 			TTL     string `toml:"ttl"`
27 27
 		} `toml:"anti-replay"`
28 28
 	} `toml:"probes"`
29
-	PublicIP struct {
30
-		IPv4 string `toml:"ipv4"`
31
-		IPv6 string `toml:"ipv6"`
32
-	} `toml:"public-ip"`
33
-	Dialers struct {
34
-		Telegram string `toml:"telegram"`
35
-		Default  string `toml:"default"`
36
-	} `toml:"dialers"`
29
+	Network struct {
30
+		PublicIP struct {
31
+			IPv4 string `toml:"ipv4"`
32
+			IPv6 string `toml:"ipv6"`
33
+		} `toml:"public-ip"`
34
+		Dialers struct {
35
+			Telegram string `toml:"telegram"`
36
+			Default  string `toml:"default"`
37
+		} `toml:"dialers"`
38
+		DOHHostname string `toml:"doh-hostname"`
39
+	} `toml:"network"`
37 40
 	Stats struct {
38 41
 		StatsD struct {
39 42
 			Enabled      bool   `toml:"enabled"`

Загрузка…
Отмена
Сохранить