client.go 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package controlclient implements the client for the Tailscale
  4. // control plane.
  5. //
  6. // It handles authentication, port picking, and collects the local
  7. // network configuration.
  8. package controlclient
  9. import (
  10. "context"
  11. "tailscale.com/tailcfg"
  12. )
  13. // LoginFlags is a bitmask of options to change the behavior of Client.Login
  14. // and LocalBackend.
  15. type LoginFlags int
  16. const (
  17. LoginDefault = LoginFlags(0)
  18. LoginInteractive = LoginFlags(1 << iota) // force user login and key refresh
  19. LoginEphemeral // set RegisterRequest.Ephemeral
  20. // LocalBackendStartKeyOSNeutral instructs NewLocalBackend to start the
  21. // LocalBackend without any OS-dependent StateStore StartKey behavior.
  22. //
  23. // See https://github.com/tailscale/tailscale/issues/6973.
  24. LocalBackendStartKeyOSNeutral
  25. )
  26. // Client represents a client connection to the control server.
  27. // Currently this is done through a pair of polling https requests in
  28. // the Auto client, but that might change eventually.
  29. //
  30. // The Client must be comparable as it is used by the Observer to detect stale
  31. // clients.
  32. type Client interface {
  33. // Shutdown closes this session, which should not be used any further
  34. // afterwards.
  35. Shutdown()
  36. // Login begins an interactive or non-interactive login process.
  37. // Client will eventually call the Status callback with either a
  38. // LoginFinished flag (on success) or an auth URL (if further
  39. // interaction is needed).
  40. Login(*tailcfg.Oauth2Token, LoginFlags)
  41. // Logout starts a synchronous logout process. It doesn't return
  42. // until the logout operation has been completed.
  43. Logout(context.Context) error
  44. // SetPaused pauses or unpauses the controlclient activity as much
  45. // as possible, without losing its internal state, to minimize
  46. // unnecessary network activity.
  47. // TODO: It might be better to simply shutdown the controlclient and
  48. // make a new one when it's time to unpause.
  49. SetPaused(bool)
  50. // AuthCantContinue returns whether authentication is blocked. If it
  51. // is, you either need to visit the auth URL (previously sent in a
  52. // Status callback) or call the Login function appropriately.
  53. // TODO: this probably belongs in the Status itself instead.
  54. AuthCantContinue() bool
  55. // SetHostinfo changes the Hostinfo structure that will be sent in
  56. // subsequent node registration requests.
  57. // TODO: a server-side change would let us simply upload this
  58. // in a separate http request. It has nothing to do with the rest of
  59. // the state machine.
  60. SetHostinfo(*tailcfg.Hostinfo)
  61. // SetNetinfo changes the NetIinfo structure that will be sent in
  62. // subsequent node registration requests.
  63. // TODO: a server-side change would let us simply upload this
  64. // in a separate http request. It has nothing to do with the rest of
  65. // the state machine.
  66. SetNetInfo(*tailcfg.NetInfo)
  67. // SetTKAHead changes the TKA head hash value that will be sent in
  68. // subsequent netmap requests.
  69. SetTKAHead(headHash string)
  70. // UpdateEndpoints changes the Endpoint structure that will be sent
  71. // in subsequent node registration requests.
  72. // TODO: a server-side change would let us simply upload this
  73. // in a separate http request. It has nothing to do with the rest of
  74. // the state machine.
  75. UpdateEndpoints(endpoints []tailcfg.Endpoint)
  76. }
  77. // UserVisibleError is an error that should be shown to users.
  78. type UserVisibleError string
  79. func (e UserVisibleError) Error() string { return string(e) }
  80. func (e UserVisibleError) UserVisibleError() string { return string(e) }