From f0121468f4a2a9a652bad39a51961f301ff93c54 Mon Sep 17 00:00:00 2001 From: Simeng He Date: Tue, 8 Jun 2021 11:02:05 -0400 Subject: [PATCH] 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 --- control/controlclient/direct.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 23662f9ec..05d4086ea 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -32,6 +32,7 @@ import ( "golang.org/x/crypto/nacl/box" "inet.af/netaddr" "tailscale.com/health" + "tailscale.com/ipn/ipnstate" "tailscale.com/log/logheap" "tailscale.com/net/dnscache" "tailscale.com/net/dnsfallback" @@ -66,6 +67,7 @@ type Direct struct { debugFlags []string keepSharerAndUserSplit bool skipIPForwardingCheck bool + pinger Pinger mu sync.Mutex // mutex guards the following fields serverKey wgkey.Key @@ -103,6 +105,18 @@ type Options struct { // forwarding works and should not be double-checked by the // controlclient package. 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 { @@ -165,6 +179,7 @@ func NewDirect(opts Options) (*Direct, error) { keepSharerAndUserSplit: opts.KeepSharerAndUserSplit, linkMon: opts.LinkMonitor, skipIPForwardingCheck: opts.SkipIPForwardingCheck, + pinger: opts.Pinger, } if opts.Hostinfo == nil { c.SetHostinfo(NewHostinfo())