safesocket: add WindowsLocalPort const

Remove all the 41112 references.

Change-Id: I2d7ed330d457e3bb91b7e6416cfb2667611e50c4
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-11-05 14:05:13 -07:00
parent 1ec99e99f4
commit 2b082959db
6 changed files with 10 additions and 5 deletions

View File

@ -56,7 +56,7 @@ func defaultDialer(ctx context.Context, network, addr string) (net.Conn, error)
return d.DialContext(ctx, "tcp", "localhost:"+strconv.Itoa(port)) return d.DialContext(ctx, "tcp", "localhost:"+strconv.Itoa(port))
} }
} }
return safesocket.Connect(TailscaledSocket, 41112) return safesocket.Connect(TailscaledSocket, safesocket.WindowsLocalPort)
} }
var ( var (

View File

@ -191,7 +191,7 @@ func fatalf(format string, a ...interface{}) {
var gotSignal syncs.AtomicBool var gotSignal syncs.AtomicBool
func connect(ctx context.Context) (net.Conn, *ipn.BackendClient, context.Context, context.CancelFunc) { func connect(ctx context.Context) (net.Conn, *ipn.BackendClient, context.Context, context.CancelFunc) {
c, err := safesocket.Connect(rootArgs.socket, 41112) c, err := safesocket.Connect(rootArgs.socket, safesocket.WindowsLocalPort)
if err != nil { if err != nil {
if runtime.GOOS != "windows" && rootArgs.socket == "" { if runtime.GOOS != "windows" && rootArgs.socket == "" {
fatalf("--socket cannot be empty") fatalf("--socket cannot be empty")

View File

@ -94,7 +94,7 @@ func runDebug(ctx context.Context, args []string) error {
return nil return nil
} }
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
printf("curl http://localhost:41112/localapi/v0/status\n") printf("curl http://localhost:%v/localapi/v0/status\n", safesocket.WindowsLocalPort)
return nil return nil
} }
printf("curl --unix-socket %s http://foo/localapi/v0/status\n", paths.DefaultTailscaledSocket()) printf("curl --unix-socket %s http://foo/localapi/v0/status\n", paths.DefaultTailscaledSocket())

View File

@ -36,6 +36,7 @@
"tailscale.com/net/socks5/tssocks" "tailscale.com/net/socks5/tssocks"
"tailscale.com/net/tstun" "tailscale.com/net/tstun"
"tailscale.com/paths" "tailscale.com/paths"
"tailscale.com/safesocket"
"tailscale.com/types/flagtype" "tailscale.com/types/flagtype"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/util/multierr" "tailscale.com/util/multierr"
@ -223,7 +224,7 @@ func ipnServerOpts() (o ipnserver.Options) {
goos = runtime.GOOS goos = runtime.GOOS
} }
o.Port = 41112 o.Port = safesocket.WindowsLocalPort
o.StatePath = statePathOrDefault() o.StatePath = statePathOrDefault()
o.SocketPath = args.socketpath // even for goos=="windows", for tests o.SocketPath = args.socketpath // even for goos=="windows", for tests
o.VarRoot = args.statedir o.VarRoot = args.statedir

View File

@ -13,6 +13,10 @@
"time" "time"
) )
// WindowsLocalPort is the default localhost TCP port
// used by safesocket on Windows.
const WindowsLocalPort = 41112
type closeable interface { type closeable interface {
CloseRead() error CloseRead() error
CloseWrite() error CloseWrite() error

View File

@ -755,7 +755,7 @@ func (n *testNode) MustDown() {
// over its localhost IPC mechanism. (Unix socket, etc) // over its localhost IPC mechanism. (Unix socket, etc)
func (n *testNode) AwaitListening(t testing.TB) { func (n *testNode) AwaitListening(t testing.TB) {
if err := tstest.WaitFor(20*time.Second, func() (err error) { if err := tstest.WaitFor(20*time.Second, func() (err error) {
c, err := safesocket.Connect(n.sockFile, 41112) c, err := safesocket.Connect(n.sockFile, safesocket.WindowsLocalPort)
if err != nil { if err != nil {
return err return err
} }