mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-11 15:17:18 +00:00
Start of netcheck package & including network state in Hostinfo.
* adds new packet "netcheck" to do the checking of UDP, IPv6, and nearest DERP server, and the Report type for all that (and more in the future, probably pulling in danderson's natprobe) * new tailcfg.NetInfo type * cmd/tailscale netcheck subcommand (tentative name, likely to change/move) to print out the netcheck.Report. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
a07af762e4
commit
14559340ee
34
ipn/local.go
34
ipn/local.go
@@ -5,6 +5,7 @@
|
||||
package ipn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
|
||||
"github.com/tailscale/wireguard-go/wgcfg"
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/netcheck"
|
||||
"tailscale.com/portlist"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/empty"
|
||||
@@ -134,6 +136,7 @@ func (b *LocalBackend) Start(opts Options) error {
|
||||
hi := controlclient.NewHostinfo()
|
||||
hi.BackendLogID = b.backendLogID
|
||||
hi.FrontendLogID = opts.FrontendLogID
|
||||
b.populateNetworkConditions(hi)
|
||||
|
||||
b.mu.Lock()
|
||||
|
||||
@@ -360,6 +363,7 @@ func (b *LocalBackend) popBrowserAuthNow() {
|
||||
b.interact = 0
|
||||
b.authURL = ""
|
||||
b.mu.Unlock()
|
||||
|
||||
b.logf("popBrowserAuthNow: url=%v\n", url != "")
|
||||
|
||||
b.blockEngineUpdates(true)
|
||||
@@ -749,3 +753,33 @@ func (b *LocalBackend) assertClientLocked() {
|
||||
panic("LocalBackend.assertClient: b.c == nil")
|
||||
}
|
||||
}
|
||||
|
||||
// populateNetworkConditions spends up to 2 seconds populating hi's
|
||||
// network condition fields.
|
||||
//
|
||||
// TODO: this is currently just done once at start-up, not regularly on
|
||||
// link changes. This will probably need to be moved & rethought. For now
|
||||
// we're just gathering some data.
|
||||
func (b *LocalBackend) populateNetworkConditions(hi *tailcfg.Hostinfo) {
|
||||
logf := logger.WithPrefix(b.logf, "populateNetworkConditions: ")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
report, err := netcheck.GetReport(ctx, logf)
|
||||
if err != nil {
|
||||
logf("GetReport: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
ni := &tailcfg.NetInfo{
|
||||
DERPLatency: map[string]float64{},
|
||||
MappingVariesByDestIP: report.MappingVariesByDestIP,
|
||||
}
|
||||
for server, d := range report.DERPLatency {
|
||||
ni.DERPLatency[server] = d.Seconds()
|
||||
}
|
||||
ni.WorkingIPv6.Set(report.IPv6)
|
||||
ni.WorkingUDP.Set(report.UDP)
|
||||
|
||||
hi.NetInfo = ni
|
||||
}
|
||||
|
25
ipn/local_test.go
Normal file
25
ipn/local_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ipn
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
var external = flag.Bool("external", false, "run external network tests")
|
||||
|
||||
func TestPopulateNetworkConditions(t *testing.T) {
|
||||
if !*external {
|
||||
t.Skip("skipping network test without -external flag")
|
||||
}
|
||||
b := &LocalBackend{logf: t.Logf}
|
||||
hi := new(tailcfg.Hostinfo)
|
||||
b.populateNetworkConditions(hi)
|
||||
t.Logf("Got: %+v", hi)
|
||||
|
||||
}
|
Reference in New Issue
Block a user