|
|
@@ -2,6 +2,7 @@ package cli
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
4
|
4
|
"context"
|
|
|
5
|
+ "errors"
|
|
5
|
6
|
"fmt"
|
|
6
|
7
|
"maps"
|
|
7
|
8
|
"net"
|
|
|
@@ -63,28 +64,6 @@ type Doctor struct {
|
|
63
|
64
|
ConfigPath string `kong:"arg,required,type='existingfile',help='Path to the configuration file.',name='config-path'"` //nolint: lll
|
|
64
|
65
|
}
|
|
65
|
66
|
|
|
66
|
|
-type wrappedNetwork struct {
|
|
67
|
|
- mtglib.Network
|
|
68
|
|
-}
|
|
69
|
|
-
|
|
70
|
|
-func (w wrappedNetwork) Dial(network, address string) (net.Conn, error) {
|
|
71
|
|
- rv, err := w.Network.Dial(network, address)
|
|
72
|
|
- if err != nil {
|
|
73
|
|
- return nil, err
|
|
74
|
|
- }
|
|
75
|
|
-
|
|
76
|
|
- return rv.(net.Conn), nil
|
|
77
|
|
-}
|
|
78
|
|
-
|
|
79
|
|
-func (w wrappedNetwork) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
80
|
|
- rv, err := w.Network.DialContext(ctx, network, address)
|
|
81
|
|
- if err != nil {
|
|
82
|
|
- return nil, err
|
|
83
|
|
- }
|
|
84
|
|
-
|
|
85
|
|
- return rv.(net.Conn), nil
|
|
86
|
|
-}
|
|
87
|
|
-
|
|
88
|
67
|
func (d *Doctor) Run(cli *CLI, version string) error {
|
|
89
|
68
|
conf, err := utils.ReadConfig(d.ConfigPath)
|
|
90
|
69
|
if err != nil {
|
|
|
@@ -140,7 +119,7 @@ func (d *Doctor) checkDeprecatedConfig() bool {
|
|
140
|
119
|
|
|
141
|
120
|
if d.conf.DomainFrontingIP.Value != nil {
|
|
142
|
121
|
ok = false
|
|
143
|
|
- tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{
|
|
|
122
|
+ tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
|
|
144
|
123
|
"when": "2.3.0",
|
|
145
|
124
|
"old": "domain-fronting-ip",
|
|
146
|
125
|
"old_section": "",
|
|
|
@@ -151,7 +130,7 @@ func (d *Doctor) checkDeprecatedConfig() bool {
|
|
151
|
130
|
|
|
152
|
131
|
if d.conf.DomainFrontingPort.Value != 0 {
|
|
153
|
132
|
ok = false
|
|
154
|
|
- tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{
|
|
|
133
|
+ tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
|
|
155
|
134
|
"when": "2.3.0",
|
|
156
|
135
|
"old": "domain-fronting-port",
|
|
157
|
136
|
"old_section": "",
|
|
|
@@ -162,7 +141,7 @@ func (d *Doctor) checkDeprecatedConfig() bool {
|
|
162
|
141
|
|
|
163
|
142
|
if d.conf.DomainFrontingProxyProtocol.Value {
|
|
164
|
143
|
ok = false
|
|
165
|
|
- tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{
|
|
|
144
|
+ tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
|
|
166
|
145
|
"when": "2.3.0",
|
|
167
|
146
|
"old": "domain-fronting-proxy-protocol",
|
|
168
|
147
|
"old_section": "",
|
|
|
@@ -173,7 +152,7 @@ func (d *Doctor) checkDeprecatedConfig() bool {
|
|
173
|
152
|
|
|
174
|
153
|
if d.conf.Network.DOHIP.Value != nil {
|
|
175
|
154
|
ok = false
|
|
176
|
|
- tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{
|
|
|
155
|
+ tplWDeprecatedConfig.Execute(os.Stdout, map[string]string{ //nolint: errcheck
|
|
177
|
156
|
"when": "2.3.0",
|
|
178
|
157
|
"old": "doh-ip",
|
|
179
|
158
|
"old_section": "network",
|
|
|
@@ -192,7 +171,7 @@ func (d *Doctor) checkDeprecatedConfig() bool {
|
|
192
|
171
|
func (d *Doctor) checkTimeSkewness() bool {
|
|
193
|
172
|
response, err := ntp.Query("0.pool.ntp.org")
|
|
194
|
173
|
if err != nil {
|
|
195
|
|
- tplError.Execute(os.Stdout, map[string]any{
|
|
|
174
|
+ tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
196
|
175
|
"description": "cannot access ntp pool",
|
|
197
|
176
|
"error": err,
|
|
198
|
177
|
})
|
|
|
@@ -202,19 +181,19 @@ func (d *Doctor) checkTimeSkewness() bool {
|
|
202
|
181
|
skewness := response.ClockOffset.Abs()
|
|
203
|
182
|
confValue := d.conf.TolerateTimeSkewness.Get(mtglib.DefaultTolerateTimeSkewness)
|
|
204
|
183
|
diff := float64(skewness) / float64(confValue)
|
|
205
|
|
- context := map[string]any{
|
|
|
184
|
+ tplData := map[string]any{
|
|
206
|
185
|
"drift": response.ClockOffset,
|
|
207
|
186
|
"value": confValue,
|
|
208
|
187
|
}
|
|
209
|
188
|
|
|
210
|
189
|
switch {
|
|
211
|
190
|
case diff < 0.3:
|
|
212
|
|
- tplOTimeSkewness.Execute(os.Stdout, context)
|
|
|
191
|
+ tplOTimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
|
|
213
|
192
|
return true
|
|
214
|
193
|
case diff < 0.7:
|
|
215
|
|
- tplWTimeSkewness.Execute(os.Stdout, context)
|
|
|
194
|
+ tplWTimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
|
|
216
|
195
|
default:
|
|
217
|
|
- tplETimeSkewness.Execute(os.Stdout, context)
|
|
|
196
|
+ tplETimeSkewness.Execute(os.Stdout, tplData) //nolint: errcheck
|
|
218
|
197
|
}
|
|
219
|
198
|
|
|
220
|
199
|
return false
|
|
|
@@ -229,11 +208,11 @@ func (d *Doctor) checkNetwork(ntw mtglib.Network) bool {
|
|
229
|
208
|
for _, dc := range dcs {
|
|
230
|
209
|
err := d.checkNetworkAddresses(ntw, essentials.TelegramCoreAddresses[dc])
|
|
231
|
210
|
if err == nil {
|
|
232
|
|
- tplODCConnect.Execute(os.Stdout, map[string]any{
|
|
|
211
|
+ tplODCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
233
|
212
|
"dc": dc,
|
|
234
|
213
|
})
|
|
235
|
214
|
} else {
|
|
236
|
|
- tplEDCConnect.Execute(os.Stdout, map[string]any{
|
|
|
215
|
+ tplEDCConnect.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
237
|
216
|
"dc": dc,
|
|
238
|
217
|
"error": err,
|
|
239
|
218
|
})
|
|
|
@@ -274,6 +253,10 @@ func (d *Doctor) checkNetworkAddresses(ntw mtglib.Network, addresses []string) e
|
|
274
|
253
|
checkAddresses = addresses
|
|
275
|
254
|
}
|
|
276
|
255
|
|
|
|
256
|
+ if len(checkAddresses) == 0 {
|
|
|
257
|
+ return fmt.Errorf("no suitable addresses after IP version filtering")
|
|
|
258
|
+ }
|
|
|
259
|
+
|
|
277
|
260
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
278
|
261
|
defer cancel()
|
|
279
|
262
|
|
|
|
@@ -288,7 +271,7 @@ func (d *Doctor) checkNetworkAddresses(ntw mtglib.Network, addresses []string) e
|
|
288
|
271
|
continue
|
|
289
|
272
|
}
|
|
290
|
273
|
|
|
291
|
|
- conn.Close()
|
|
|
274
|
+ conn.Close() //nolint: errcheck
|
|
292
|
275
|
|
|
293
|
276
|
return nil
|
|
294
|
277
|
}
|
|
|
@@ -299,18 +282,29 @@ func (d *Doctor) checkNetworkAddresses(ntw mtglib.Network, addresses []string) e
|
|
299
|
282
|
func (d *Doctor) checkSecretHost(resolver *net.Resolver, ntw mtglib.Network) bool {
|
|
300
|
283
|
addresses, err := resolver.LookupIPAddr(context.Background(), d.conf.Secret.Host)
|
|
301
|
284
|
if err != nil {
|
|
302
|
|
- // TODO
|
|
|
285
|
+ tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
|
286
|
+ "description": fmt.Sprintf("cannot resolve DNS name of %s", d.conf.Secret.Host),
|
|
|
287
|
+ "error": err,
|
|
|
288
|
+ })
|
|
303
|
289
|
return false
|
|
304
|
290
|
}
|
|
305
|
291
|
|
|
306
|
|
- access := &Access{}
|
|
307
|
|
- ourIP4 := access.getIP(ntw, "tcp4")
|
|
308
|
|
- ourIP6 := access.getIP(ntw, "tcp6")
|
|
|
292
|
+ ourIP4 := getIP(ntw, "tcp4")
|
|
|
293
|
+ ourIP6 := getIP(ntw, "tcp6")
|
|
|
294
|
+
|
|
|
295
|
+ if ourIP4 == nil && ourIP6 == nil {
|
|
|
296
|
+ tplError.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
|
297
|
+ "description": "cannot detect public IP address",
|
|
|
298
|
+ "error": errors.New("ifconfig.co is unreachable for both IPv4 and IPv6"),
|
|
|
299
|
+ })
|
|
|
300
|
+ return false
|
|
|
301
|
+ }
|
|
309
|
302
|
|
|
310
|
303
|
strAddresses := []string{}
|
|
311
|
304
|
for _, value := range addresses {
|
|
312
|
|
- if value.IP.String() == ourIP4.String() || value.IP.String() == ourIP6.String() {
|
|
313
|
|
- tplODNSSNIMatch.Execute(os.Stdout, map[string]any{
|
|
|
305
|
+ if (ourIP4 != nil && value.IP.String() == ourIP4.String()) ||
|
|
|
306
|
+ (ourIP6 != nil && value.IP.String() == ourIP6.String()) {
|
|
|
307
|
+ tplODNSSNIMatch.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
314
|
308
|
"ip": value.IP,
|
|
315
|
309
|
"hostname": d.conf.Secret.Host,
|
|
316
|
310
|
})
|
|
|
@@ -320,7 +314,7 @@ func (d *Doctor) checkSecretHost(resolver *net.Resolver, ntw mtglib.Network) boo
|
|
320
|
314
|
strAddresses = append(strAddresses, `"`+value.IP.String()+`"`)
|
|
321
|
315
|
}
|
|
322
|
316
|
|
|
323
|
|
- tplEDNSSNIMatch.Execute(os.Stdout, map[string]any{
|
|
|
317
|
+ tplEDNSSNIMatch.Execute(os.Stdout, map[string]any{ //nolint: errcheck
|
|
324
|
318
|
"hostname": d.conf.Secret.Host,
|
|
325
|
319
|
"resolved": strings.Join(strAddresses, ", "),
|
|
326
|
320
|
"ip4": ourIP4,
|