Parcourir la source

Modify config

tags/v2.0.0-rc1
9seconds il y a 5 ans
Parent
révision
09f8233bc6
4 fichiers modifiés avec 64 ajouts et 40 suppressions
  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 Voir le fichier

51
 # Pass filepath here or '-' if you want to dump into stdout.
51
 # Pass filepath here or '-' if you want to dump into stdout.
52
 access-file = "-"
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
 # public ip addresses of the server. Actually, it is required only to
70
 # public ip addresses of the server. Actually, it is required only to
85
 # generate a correct access file. if you use default values here, mtg
71
 # generate a correct access file. if you use default values here, mtg
86
 # will try to resolve these IPs on its own.
72
 # will try to resolve these IPs on its own.
87
-[public-ip]
73
+[network.public-ip]
88
 ipv4 = ""
74
 ipv4 = ""
89
 ipv6 = ""
75
 ipv6 = ""
90
 
76
 
109
 # ignored.
95
 # ignored.
110
 #
96
 #
111
 # If telegram dialer is not defined, a default one is going to be used.
97
 # If telegram dialer is not defined, a default one is going to be used.
112
-[dialers]
98
+[network.dialers]
113
 telegram = ""
99
 telegram = ""
114
 default = ""
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
 # statsd statistics integration.
132
 # statsd statistics integration.
117
 [stats.statsd]
133
 [stats.statsd]
118
 # enabled/disabled
134
 # enabled/disabled

+ 3
- 0
go.sum Voir le fichier

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

+ 5
- 3
mtglib/network/network.go Voir le fichier

30
 		return nil, fmt.Errorf("cannot resolve dns names: %w", err)
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
 	for _, v := range ips {
39
 	for _, v := range ips {
38
 		if conn, err := d.dialer.DialContext(ctx, network, net.JoinHostPort(v, port)); err == nil {
40
 		if conn, err := d.dialer.DialContext(ctx, network, net.JoinHostPort(v, port)); err == nil {

+ 11
- 8
raw_config.go Voir le fichier

26
 			TTL     string `toml:"ttl"`
26
 			TTL     string `toml:"ttl"`
27
 		} `toml:"anti-replay"`
27
 		} `toml:"anti-replay"`
28
 	} `toml:"probes"`
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
 	Stats struct {
40
 	Stats struct {
38
 		StatsD struct {
41
 		StatsD struct {
39
 			Enabled      bool   `toml:"enabled"`
42
 			Enabled      bool   `toml:"enabled"`

Chargement…
Annuler
Enregistrer