client.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (c) Tailscale Inc & contributors
  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. "tailscale.com/types/key"
  13. )
  14. // LoginFlags is a bitmask of options to change the behavior of Client.Login
  15. // and LocalBackend.
  16. type LoginFlags int
  17. const (
  18. LoginDefault = LoginFlags(0)
  19. LoginInteractive = LoginFlags(1 << iota) // force user login and key refresh
  20. LoginEphemeral // set RegisterRequest.Ephemeral
  21. // LocalBackendStartKeyOSNeutral instructs NewLocalBackend to start the
  22. // LocalBackend without any OS-dependent StateStore StartKey behavior.
  23. //
  24. // See https://github.com/tailscale/tailscale/issues/6973.
  25. LocalBackendStartKeyOSNeutral
  26. )
  27. // Client represents a client connection to the control server.
  28. // Currently this is done through a pair of polling https requests in
  29. // the Auto client, but that might change eventually.
  30. //
  31. // The Client must be comparable as it is used by the Observer to detect stale
  32. // clients.
  33. type Client interface {
  34. // Shutdown closes this session, which should not be used any further
  35. // afterwards.
  36. Shutdown()
  37. // Login begins an interactive or non-interactive login process.
  38. // Client will eventually call the Status callback with either a
  39. // LoginFinished flag (on success) or an auth URL (if further
  40. // interaction is needed). It merely sets the process in motion,
  41. // and doesn't wait for it to complete.
  42. Login(LoginFlags)
  43. // Logout starts a synchronous logout process. It doesn't return
  44. // until the logout operation has been completed.
  45. Logout(context.Context) error
  46. // SetPaused pauses or unpauses the controlclient activity as much
  47. // as possible, without losing its internal state, to minimize
  48. // unnecessary network activity.
  49. // TODO: It might be better to simply shutdown the controlclient and
  50. // make a new one when it's time to unpause.
  51. SetPaused(bool)
  52. // AuthCantContinue returns whether authentication is blocked. If it
  53. // is, you either need to visit the auth URL (previously sent in a
  54. // Status callback) or call the Login function appropriately.
  55. // TODO: this probably belongs in the Status itself instead.
  56. AuthCantContinue() bool
  57. // SetHostinfo changes the Hostinfo structure that will be sent in
  58. // subsequent node registration requests.
  59. // TODO: a server-side change would let us simply upload this
  60. // in a separate http request. It has nothing to do with the rest of
  61. // the state machine.
  62. SetHostinfo(*tailcfg.Hostinfo)
  63. // SetNetinfo changes the NetIinfo structure that will be sent in
  64. // subsequent node registration requests.
  65. // TODO: a server-side change would let us simply upload this
  66. // in a separate http request. It has nothing to do with the rest of
  67. // the state machine.
  68. SetNetInfo(*tailcfg.NetInfo)
  69. // SetTKAHead changes the TKA head hash value that will be sent in
  70. // subsequent netmap requests.
  71. SetTKAHead(headHash string)
  72. // UpdateEndpoints changes the Endpoint structure that will be sent
  73. // in subsequent node registration requests.
  74. // TODO: a server-side change would let us simply upload this
  75. // in a separate http request. It has nothing to do with the rest of
  76. // the state machine.
  77. // Note: the auto client uploads the new endpoints to control immediately.
  78. UpdateEndpoints(endpoints []tailcfg.Endpoint)
  79. // SetDiscoPublicKey updates the disco public key that will be sent in
  80. // future map requests. This should be called after rotating the discovery key.
  81. // Note: the auto client uploads the new key to control immediately.
  82. SetDiscoPublicKey(key.DiscoPublic)
  83. // ClientID returns the ClientID of a client. This ID is meant to
  84. // distinguish one client from another.
  85. ClientID() int64
  86. }
  87. // UserVisibleError is an error that should be shown to users.
  88. type UserVisibleError string
  89. func (e UserVisibleError) Error() string { return string(e) }
  90. func (e UserVisibleError) UserVisibleError() string { return string(e) }