@ -16,10 +16,14 @@ import (
"strconv"
"strconv"
"tailscale.com/ipn/ipnstate"
"tailscale.com/ipn/ipnstate"
"tailscale.com/paths"
"tailscale.com/safesocket"
"tailscale.com/safesocket"
"tailscale.com/tailcfg"
"tailscale.com/tailcfg"
)
)
// TailscaledSocket is the tailscaled Unix socket.
var TailscaledSocket = paths . DefaultTailscaledSocket ( )
// tsClient does HTTP requests to the local Tailscale daemon.
// tsClient does HTTP requests to the local Tailscale daemon.
var tsClient = & http . Client {
var tsClient = & http . Client {
Transport : & http . Transport {
Transport : & http . Transport {
@ -27,6 +31,7 @@ var tsClient = &http.Client{
if addr != "local-tailscaled.sock:80" {
if addr != "local-tailscaled.sock:80" {
return nil , fmt . Errorf ( "unexpected URL address %q" , addr )
return nil , fmt . Errorf ( "unexpected URL address %q" , addr )
}
}
if TailscaledSocket == paths . DefaultTailscaledSocket ( ) {
// On macOS, when dialing from non-sandboxed program to sandboxed GUI running
// On macOS, when dialing from non-sandboxed program to sandboxed GUI running
// a TCP server on a random port, find the random port. For HTTP connections,
// a TCP server on a random port, find the random port. For HTTP connections,
// we don't send the token. It gets added in an HTTP Basic-Auth header.
// we don't send the token. It gets added in an HTTP Basic-Auth header.
@ -34,7 +39,8 @@ var tsClient = &http.Client{
var d net . Dialer
var d net . Dialer
return d . DialContext ( ctx , "tcp" , "localhost:" + strconv . Itoa ( port ) )
return d . DialContext ( ctx , "tcp" , "localhost:" + strconv . Itoa ( port ) )
}
}
return safesocket . ConnectDefault ( )
}
return safesocket . Connect ( TailscaledSocket , 41112 )
} ,
} ,
} ,
} ,
}
}