client.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package controlclient implements the client for the Tailscale
  5. // control plane.
  6. //
  7. // It handles authentication, port picking, and collects the local
  8. // network configuration.
  9. package controlclient
  10. import (
  11. "context"
  12. "tailscale.com/tailcfg"
  13. )
  14. type LoginFlags int
  15. const (
  16. LoginDefault = LoginFlags(0)
  17. LoginInteractive = LoginFlags(1 << iota) // force user login and key refresh
  18. )
  19. // Client represents a client connection to the control server.
  20. // Currently this is done through a pair of polling https requests in
  21. // the Auto client, but that might change eventually.
  22. type Client interface {
  23. // SetStatusFunc provides a callback to call when control sends us
  24. // a message.
  25. SetStatusFunc(func(Status))
  26. // Shutdown closes this session, which should not be used any further
  27. // afterwards.
  28. Shutdown()
  29. // Login begins an interactive or non-interactive login process.
  30. // Client will eventually call the Status callback with either a
  31. // LoginFinished flag (on success) or an auth URL (if further
  32. // interaction is needed).
  33. Login(*tailcfg.Oauth2Token, LoginFlags)
  34. // StartLogout starts an asynchronous logout process.
  35. // When it finishes, the Status callback will be called while
  36. // AuthCantContinue()==true.
  37. StartLogout()
  38. // Logout starts a synchronous logout process. It doesn't return
  39. // until the logout operation has been completed.
  40. Logout(context.Context) error
  41. // SetPaused pauses or unpauses the controlclient activity as much
  42. // as possible, without losing its internal state, to minimize
  43. // unnecessary network activity.
  44. // TODO: It might be better to simply shutdown the controlclient and
  45. // make a new one when it's time to unpause.
  46. SetPaused(bool)
  47. // AuthCantContinue returns whether authentication is blocked. If it
  48. // is, you either need to visit the auth URL (previously sent in a
  49. // Status callback) or call the Login function appropriately.
  50. // TODO: this probably belongs in the Status itself instead.
  51. AuthCantContinue() bool
  52. // SetHostinfo changes the Hostinfo structure that will be sent in
  53. // subsequent node registration requests.
  54. // TODO: a server-side change would let us simply upload this
  55. // in a separate http request. It has nothing to do with the rest of
  56. // the state machine.
  57. SetHostinfo(*tailcfg.Hostinfo)
  58. // SetNetinfo changes the NetIinfo structure that will be sent in
  59. // subsequent node registration requests.
  60. // TODO: a server-side change would let us simply upload this
  61. // in a separate http request. It has nothing to do with the rest of
  62. // the state machine.
  63. SetNetInfo(*tailcfg.NetInfo)
  64. // UpdateEndpoints changes the Endpoint structure that will be sent
  65. // in subsequent node registration requests.
  66. // TODO: localPort seems to be obsolete, remove it.
  67. // TODO: a server-side change would let us simply upload this
  68. // in a separate http request. It has nothing to do with the rest of
  69. // the state machine.
  70. UpdateEndpoints(localPort uint16, endpoints []tailcfg.Endpoint)
  71. // SetDNS sends the SetDNSRequest request to the control plane server,
  72. // requesting a DNS record be created or updated.
  73. SetDNS(context.Context, *tailcfg.SetDNSRequest) error
  74. }