@ -447,8 +447,8 @@ func tryFixLogStateLocation(dir, cmdname string, logf logger.Logf) {
// New returns a new log policy (a logger and its instance ID) for a given
// New returns a new log policy (a logger and its instance ID) for a given
// collection name.
// collection name.
//
//
// The netMon parameter is optional ; if non-nil it's used to do faster
// The netMon parameter is optional . It should be specified in environments where
// interface lookups .
// Tailscaled is manipulating the routing table .
//
//
// The logf parameter is optional; if non-nil, information logs (e.g. when
// The logf parameter is optional; if non-nil, information logs (e.g. when
// migrating state) are sent to that logger, and global changes to the log
// migrating state) are sent to that logger, and global changes to the log
@ -459,6 +459,9 @@ func New(collection string, netMon *netmon.Monitor, health *health.Tracker, logf
// NewWithConfigPath is identical to New, but uses the specified directory and
// NewWithConfigPath is identical to New, but uses the specified directory and
// command name. If either is empty, it derives them automatically.
// command name. If either is empty, it derives them automatically.
//
// The netMon parameter is optional. It should be specified in environments where
// Tailscaled is manipulating the routing table.
func NewWithConfigPath ( collection , dir , cmdName string , netMon * netmon . Monitor , health * health . Tracker , logf logger . Logf ) * Policy {
func NewWithConfigPath ( collection , dir , cmdName string , netMon * netmon . Monitor , health * health . Tracker , logf logger . Logf ) * Policy {
var lflags int
var lflags int
if term . IsTerminal ( 2 ) || runtime . GOOS == "windows" {
if term . IsTerminal ( 2 ) || runtime . GOOS == "windows" {
@ -681,8 +684,12 @@ func (p *Policy) Shutdown(ctx context.Context) error {
// - If TLS connection fails, try again using LetsEncrypt's built-in root certificate,
// - If TLS connection fails, try again using LetsEncrypt's built-in root certificate,
// for the benefit of older OS platforms which might not include it.
// for the benefit of older OS platforms which might not include it.
//
//
// The netMon parameter is optional; if non-nil it's used to do faster interface lookups.
// The netMon parameter is optional. It should be specified in environments where
// Tailscaled is manipulating the routing table.
func MakeDialFunc ( netMon * netmon . Monitor , logf logger . Logf ) func ( ctx context . Context , netw , addr string ) ( net . Conn , error ) {
func MakeDialFunc ( netMon * netmon . Monitor , logf logger . Logf ) func ( ctx context . Context , netw , addr string ) ( net . Conn , error ) {
if netMon == nil {
netMon = netmon . NewStatic ( )
}
return func ( ctx context . Context , netw , addr string ) ( net . Conn , error ) {
return func ( ctx context . Context , netw , addr string ) ( net . Conn , error ) {
return dialContext ( ctx , netw , addr , netMon , logf )
return dialContext ( ctx , netw , addr , netMon , logf )
}
}
@ -725,7 +732,6 @@ func dialContext(ctx context.Context, netw, addr string, netMon *netmon.Monitor,
Forward : dnscache . Get ( ) . Forward , // use default cache's forwarder
Forward : dnscache . Get ( ) . Forward , // use default cache's forwarder
UseLastGood : true ,
UseLastGood : true ,
LookupIPFallback : dnsfallback . MakeLookupFunc ( logf , netMon ) ,
LookupIPFallback : dnsfallback . MakeLookupFunc ( logf , netMon ) ,
NetMon : netMon ,
}
}
dialer := dnscache . Dialer ( nd . DialContext , dnsCache )
dialer := dnscache . Dialer ( nd . DialContext , dnsCache )
c , err = dialer ( ctx , netw , addr )
c , err = dialer ( ctx , netw , addr )
@ -738,7 +744,8 @@ func dialContext(ctx context.Context, netw, addr string, netMon *netmon.Monitor,
// NewLogtailTransport returns an HTTP Transport particularly suited to uploading
// NewLogtailTransport returns an HTTP Transport particularly suited to uploading
// logs to the given host name. See DialContext for details on how it works.
// logs to the given host name. See DialContext for details on how it works.
//
//
// The netMon parameter is optional; if non-nil it's used to do faster interface lookups.
// The netMon parameter is optional. It should be specified in environments where
// Tailscaled is manipulating the routing table.
//
//
// The logf parameter is optional; if non-nil, logs are printed using the
// The logf parameter is optional; if non-nil, logs are printed using the
// provided function; if nil, log.Printf will be used instead.
// provided function; if nil, log.Printf will be used instead.
@ -746,6 +753,9 @@ func NewLogtailTransport(host string, netMon *netmon.Monitor, health *health.Tra
if testenv . InTest ( ) {
if testenv . InTest ( ) {
return noopPretendSuccessTransport { }
return noopPretendSuccessTransport { }
}
}
if netMon == nil {
netMon = netmon . NewStatic ( )
}
// Start with a copy of http.DefaultTransport and tweak it a bit.
// Start with a copy of http.DefaultTransport and tweak it a bit.
tr := http . DefaultTransport . ( * http . Transport ) . Clone ( )
tr := http . DefaultTransport . ( * http . Transport ) . Clone ( )