@ -61,23 +61,24 @@ import (
// Direct is the client that connects to a tailcontrol server for a node.
// Direct is the client that connects to a tailcontrol server for a node.
type Direct struct {
type Direct struct {
httpc * http . Client // HTTP client used to talk to tailcontrol
httpc * http . Client // HTTP client used to talk to tailcontrol
dialer * tsdial . Dialer
dialer * tsdial . Dialer
dnsCache * dnscache . Resolver
dnsCache * dnscache . Resolver
controlKnobs * controlknobs . Knobs // always non-nil
controlKnobs * controlknobs . Knobs // always non-nil
serverURL string // URL of the tailcontrol server
serverURL string // URL of the tailcontrol server
clock tstime . Clock
clock tstime . Clock
logf logger . Logf
logf logger . Logf
netMon * netmon . Monitor // or nil
netMon * netmon . Monitor // or nil
discoPubKey key . DiscoPublic
discoPubKey key . DiscoPublic
getMachinePrivKey func ( ) ( key . MachinePrivate , error )
getMachinePrivKey func ( ) ( key . MachinePrivate , error )
debugFlags [ ] string
debugFlags [ ] string
skipIPForwardingCheck bool
skipIPForwardingCheck bool
pinger Pinger
pinger Pinger
popBrowser func ( url string ) // or nil
popBrowser func ( url string ) // or nil
c2nHandler http . Handler // or nil
c2nHandler http . Handler // or nil
onClientVersion func ( * tailcfg . ClientVersion ) // or nil
onClientVersion func ( * tailcfg . ClientVersion ) // or nil
onControlTime func ( time . Time ) // or nil
onControlTime func ( time . Time ) // or nil
onTailnetDefaultAutoUpdate func ( bool ) // or nil
dialPlan ControlDialPlanner // can be nil
dialPlan ControlDialPlanner // can be nil
@ -110,24 +111,25 @@ type Observer interface {
}
}
type Options struct {
type Options struct {
Persist persist . Persist // initial persistent data
Persist persist . Persist // initial persistent data
GetMachinePrivateKey func ( ) ( key . MachinePrivate , error ) // returns the machine key to use
GetMachinePrivateKey func ( ) ( key . MachinePrivate , error ) // returns the machine key to use
ServerURL string // URL of the tailcontrol server
ServerURL string // URL of the tailcontrol server
AuthKey string // optional node auth key for auto registration
AuthKey string // optional node auth key for auto registration
Clock tstime . Clock
Clock tstime . Clock
Hostinfo * tailcfg . Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc
Hostinfo * tailcfg . Hostinfo // non-nil passes ownership, nil means to use default using os.Hostname, etc
DiscoPublicKey key . DiscoPublic
DiscoPublicKey key . DiscoPublic
Logf logger . Logf
Logf logger . Logf
HTTPTestClient * http . Client // optional HTTP client to use (for tests only)
HTTPTestClient * http . Client // optional HTTP client to use (for tests only)
NoiseTestClient * http . Client // optional HTTP client to use for noise RPCs (tests only)
NoiseTestClient * http . Client // optional HTTP client to use for noise RPCs (tests only)
DebugFlags [ ] string // debug settings to send to control
DebugFlags [ ] string // debug settings to send to control
NetMon * netmon . Monitor // optional network monitor
NetMon * netmon . Monitor // optional network monitor
PopBrowserURL func ( url string ) // optional func to open browser
PopBrowserURL func ( url string ) // optional func to open browser
OnClientVersion func ( * tailcfg . ClientVersion ) // optional func to inform GUI of client version status
OnClientVersion func ( * tailcfg . ClientVersion ) // optional func to inform GUI of client version status
OnControlTime func ( time . Time ) // optional func to notify callers of new time from control
OnControlTime func ( time . Time ) // optional func to notify callers of new time from control
Dialer * tsdial . Dialer // non-nil
OnTailnetDefaultAutoUpdate func ( bool ) // optional func to inform GUI of default auto-update setting for the tailnet
C2NHandler http . Handler // or nil
Dialer * tsdial . Dialer // non-nil
ControlKnobs * controlknobs . Knobs // or nil to ignore
C2NHandler http . Handler // or nil
ControlKnobs * controlknobs . Knobs // or nil to ignore
// Observer is called when there's a change in status to report
// Observer is called when there's a change in status to report
// from the control client.
// from the control client.
@ -263,26 +265,27 @@ func NewDirect(opts Options) (*Direct, error) {
}
}
c := & Direct {
c := & Direct {
httpc : httpc ,
httpc : httpc ,
controlKnobs : opts . ControlKnobs ,
controlKnobs : opts . ControlKnobs ,
getMachinePrivKey : opts . GetMachinePrivateKey ,
getMachinePrivKey : opts . GetMachinePrivateKey ,
serverURL : opts . ServerURL ,
serverURL : opts . ServerURL ,
clock : opts . Clock ,
clock : opts . Clock ,
logf : opts . Logf ,
logf : opts . Logf ,
persist : opts . Persist . View ( ) ,
persist : opts . Persist . View ( ) ,
authKey : opts . AuthKey ,
authKey : opts . AuthKey ,
discoPubKey : opts . DiscoPublicKey ,
discoPubKey : opts . DiscoPublicKey ,
debugFlags : opts . DebugFlags ,
debugFlags : opts . DebugFlags ,
netMon : opts . NetMon ,
netMon : opts . NetMon ,
skipIPForwardingCheck : opts . SkipIPForwardingCheck ,
skipIPForwardingCheck : opts . SkipIPForwardingCheck ,
pinger : opts . Pinger ,
pinger : opts . Pinger ,
popBrowser : opts . PopBrowserURL ,
popBrowser : opts . PopBrowserURL ,
onClientVersion : opts . OnClientVersion ,
onClientVersion : opts . OnClientVersion ,
onControlTime : opts . OnControlTime ,
onTailnetDefaultAutoUpdate : opts . OnTailnetDefaultAutoUpdate ,
c2nHandler : opts . C2NHandler ,
onControlTime : opts . OnControlTime ,
dialer : opts . Dialer ,
c2nHandler : opts . C2NHandler ,
dnsCache : dnsCache ,
dialer : opts . Dialer ,
dialPlan : opts . DialPlan ,
dnsCache : dnsCache ,
dialPlan : opts . DialPlan ,
}
}
if opts . Hostinfo == nil {
if opts . Hostinfo == nil {
c . SetHostinfo ( hostinfo . New ( ) )
c . SetHostinfo ( hostinfo . New ( ) )
@ -1091,6 +1094,11 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
metricMapResponseKeepAlives . Add ( 1 )
metricMapResponseKeepAlives . Add ( 1 )
continue
continue
}
}
if au , ok := resp . DefaultAutoUpdate . Get ( ) ; ok {
if c . onTailnetDefaultAutoUpdate != nil {
c . onTailnetDefaultAutoUpdate ( au )
}
}
metricMapResponseMap . Add ( 1 )
metricMapResponseMap . Add ( 1 )
if gotNonKeepAliveMessage {
if gotNonKeepAliveMessage {