control/controlclient: add Pinger interface, Options.Pinger

Plumbs down a pinger to the direct to enable client to client Ping
functionality from control.

Signed-off-by: Simeng He <simeng@tailscale.com>
bradfitz/acme
Simeng He 4 years ago committed by simenghe
parent 6956645ec8
commit f0121468f4

@ -32,6 +32,7 @@ import (
"golang.org/x/crypto/nacl/box" "golang.org/x/crypto/nacl/box"
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/health" "tailscale.com/health"
"tailscale.com/ipn/ipnstate"
"tailscale.com/log/logheap" "tailscale.com/log/logheap"
"tailscale.com/net/dnscache" "tailscale.com/net/dnscache"
"tailscale.com/net/dnsfallback" "tailscale.com/net/dnsfallback"
@ -66,6 +67,7 @@ type Direct struct {
debugFlags []string debugFlags []string
keepSharerAndUserSplit bool keepSharerAndUserSplit bool
skipIPForwardingCheck bool skipIPForwardingCheck bool
pinger Pinger
mu sync.Mutex // mutex guards the following fields mu sync.Mutex // mutex guards the following fields
serverKey wgkey.Key serverKey wgkey.Key
@ -103,6 +105,18 @@ type Options struct {
// forwarding works and should not be double-checked by the // forwarding works and should not be double-checked by the
// controlclient package. // controlclient package.
SkipIPForwardingCheck bool SkipIPForwardingCheck bool
// Pinger optionally specifies the Pinger to use to satisfy
// MapResponse.PingRequest queries from the control plane.
// If nil, PingRequest queries are not answered.
Pinger Pinger
}
// Pinger is a subset of the wgengine.Engine interface, containing just the Ping method.
type Pinger interface {
// Ping is a request to start a discovery or TSMP ping with the peer handling
// the given IP and then call cb with its ping latency & method.
Ping(ip netaddr.IP, useTSMP bool, cb func(*ipnstate.PingResult))
} }
type Decompressor interface { type Decompressor interface {
@ -165,6 +179,7 @@ func NewDirect(opts Options) (*Direct, error) {
keepSharerAndUserSplit: opts.KeepSharerAndUserSplit, keepSharerAndUserSplit: opts.KeepSharerAndUserSplit,
linkMon: opts.LinkMonitor, linkMon: opts.LinkMonitor,
skipIPForwardingCheck: opts.SkipIPForwardingCheck, skipIPForwardingCheck: opts.SkipIPForwardingCheck,
pinger: opts.Pinger,
} }
if opts.Hostinfo == nil { if opts.Hostinfo == nil {
c.SetHostinfo(NewHostinfo()) c.SetHostinfo(NewHostinfo())

Loading…
Cancel
Save