client.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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). It merely sets the process in motion,
  40. // and doesn't wait for it to complete.
  41. Login(LoginFlags)
  42. // Logout starts a synchronous logout process. It doesn't return
  43. // until the logout operation has been completed.
  44. Logout(context.Context) error
  45. // SetPaused pauses or unpauses the controlclient activity as much
  46. // as possible, without losing its internal state, to minimize
  47. // unnecessary network activity.
  48. // TODO: It might be better to simply shutdown the controlclient and
  49. // make a new one when it's time to unpause.
  50. SetPaused(bool)
  51. // AuthCantContinue returns whether authentication is blocked. If it
  52. // is, you either need to visit the auth URL (previously sent in a
  53. // Status callback) or call the Login function appropriately.
  54. // TODO: this probably belongs in the Status itself instead.
  55. AuthCantContinue() bool
  56. // SetHostinfo changes the Hostinfo structure that will be sent in
  57. // subsequent node registration requests.
  58. // TODO: a server-side change would let us simply upload this
  59. // in a separate http request. It has nothing to do with the rest of
  60. // the state machine.
  61. SetHostinfo(*tailcfg.Hostinfo)
  62. // SetNetinfo changes the NetIinfo structure that will be sent in
  63. // subsequent node registration requests.
  64. // TODO: a server-side change would let us simply upload this
  65. // in a separate http request. It has nothing to do with the rest of
  66. // the state machine.
  67. SetNetInfo(*tailcfg.NetInfo)
  68. // SetTKAHead changes the TKA head hash value that will be sent in
  69. // subsequent netmap requests.
  70. SetTKAHead(headHash string)
  71. // UpdateEndpoints changes the Endpoint structure that will be sent
  72. // in subsequent node registration requests.
  73. // TODO: a server-side change would let us simply upload this
  74. // in a separate http request. It has nothing to do with the rest of
  75. // the state machine.
  76. UpdateEndpoints(endpoints []tailcfg.Endpoint)
  77. }
  78. // UserVisibleError is an error that should be shown to users.
  79. type UserVisibleError string
  80. func (e UserVisibleError) Error() string { return string(e) }
  81. func (e UserVisibleError) UserVisibleError() string { return string(e) }