mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
client/tailscale: move/copy all package funcs to new LocalClient type
Remove all global variables, and clean up tsnet and cmd/tailscale's usage. This is in prep for using this package for the web API too (it has the best package name). RELNOTE=tailscale.com/client/tailscale package refactored w/ LocalClient type Change-Id: Iba9f162fff0c520a09d1d4bd8862f5c5acc9d7cd Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
373176ea54
commit
87ba528ae0
@@ -75,6 +75,7 @@ type Server struct {
|
||||
hostname string
|
||||
shutdownCtx context.Context
|
||||
shutdownCancel context.CancelFunc
|
||||
localClient *tailscale.LocalClient
|
||||
|
||||
mu sync.Mutex
|
||||
listeners map[listenKey]*listener
|
||||
@@ -90,6 +91,17 @@ func (s *Server) Dial(ctx context.Context, network, address string) (net.Conn, e
|
||||
return s.dialer.UserDial(ctx, network, address)
|
||||
}
|
||||
|
||||
// LocalClient returns a LocalClient that speaks to s.
|
||||
//
|
||||
// It will start the server if it has not been started yet. If the server's
|
||||
// already been started successfully, it doesn't return an error.
|
||||
func (s *Server) LocalClient() (*tailscale.LocalClient, error) {
|
||||
if err := s.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.localClient, nil
|
||||
}
|
||||
|
||||
// Start connects the server to the tailnet.
|
||||
// Optional: any calls to Dial/Listen will also call Start.
|
||||
func (s *Server) Start() error {
|
||||
@@ -261,9 +273,7 @@ func (s *Server) start() error {
|
||||
// TODO(maisem): Rename nettest package to remove "test".
|
||||
lal := nettest.Listen("local-tailscaled.sock:80")
|
||||
s.localAPIListener = lal
|
||||
|
||||
// Override the Tailscale client to use the in-process listener.
|
||||
tailscale.TailscaledDialer = lal.Dial
|
||||
s.localClient = &tailscale.LocalClient{Dial: lal.Dial}
|
||||
go func() {
|
||||
if err := http.Serve(lal, lah); err != nil {
|
||||
logf("localapi serve error: %v", err)
|
||||
|
Reference in New Issue
Block a user