@@ -67,8 +67,9 @@ type Server struct {
67
67
}
68
68
69
69
// Dial connects to the address on the tailnet.
70
+ // It will start the server if it has not been started yet.
70
71
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 {
72
73
return nil , err
73
74
}
74
75
return s .dialer .UserDial (ctx , network , address )
@@ -80,7 +81,9 @@ func (s *Server) doInit() {
80
81
}
81
82
}
82
83
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 {
84
87
s .initOnce .Do (s .doInit )
85
88
return s .initErr
86
89
}
@@ -232,13 +235,14 @@ func (s *Server) forwardTCP(c net.Conn, port uint16) {
232
235
}
233
236
234
237
// Listen announces only on the Tailscale network.
238
+ // It will start the server if it has not been started yet.
235
239
func (s * Server ) Listen (network , addr string ) (net.Listener , error ) {
236
240
host , port , err := net .SplitHostPort (addr )
237
241
if err != nil {
238
242
return nil , fmt .Errorf ("tsnet: %w" , err )
239
243
}
240
244
241
- if err := s .init (); err != nil {
245
+ if err := s .Start (); err != nil {
242
246
return nil , err
243
247
}
244
248
0 commit comments