Skip to content

Commit dd45bba

Browse files
Maisem Alimaisem
authored andcommitted
tsnet: add Start method to allow connecting to the tailnet without
requiring a call to Dial/Listen. Signed-off-by: Maisem Ali <maisem@tailscale.com>
1 parent ebdd259 commit dd45bba

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tsnet/tsnet.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ type Server struct {
6767
}
6868

6969
// Dial connects to the address on the tailnet.
70+
// It will start the server if it has not been started yet.
7071
func (s *Server) Dial(ctx context.Context, network, address string) (net.Conn, error) {
71-
if err := s.init(); err != nil {
72+
if err := s.Start(); err != nil {
7273
return nil, err
7374
}
7475
return s.dialer.UserDial(ctx, network, address)
@@ -80,7 +81,9 @@ func (s *Server) doInit() {
8081
}
8182
}
8283

83-
func (s *Server) init() error {
84+
// Start connects the server to the tailnet.
85+
// Optional: any calls to Dial/Listen will also call Start.
86+
func (s *Server) Start() error {
8487
s.initOnce.Do(s.doInit)
8588
return s.initErr
8689
}
@@ -232,13 +235,14 @@ func (s *Server) forwardTCP(c net.Conn, port uint16) {
232235
}
233236

234237
// Listen announces only on the Tailscale network.
238+
// It will start the server if it has not been started yet.
235239
func (s *Server) Listen(network, addr string) (net.Listener, error) {
236240
host, port, err := net.SplitHostPort(addr)
237241
if err != nil {
238242
return nil, fmt.Errorf("tsnet: %w", err)
239243
}
240244

241-
if err := s.init(); err != nil {
245+
if err := s.Start(); err != nil {
242246
return nil, err
243247
}
244248

0 commit comments

Comments
 (0)