client.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. type LoginFlags int
  14. const (
  15. LoginDefault = LoginFlags(0)
  16. LoginInteractive = LoginFlags(1 << iota) // force user login and key refresh
  17. LoginEphemeral // set RegisterRequest.Ephemeral
  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. //
  23. // The Client must be comparable as it is used by the Observer to detect stale
  24. // clients.
  25. type Client interface {
  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. // Logout starts a synchronous logout process. It doesn't return
  35. // until the logout operation has been completed.
  36. Logout(context.Context) error
  37. // SetPaused pauses or unpauses the controlclient activity as much
  38. // as possible, without losing its internal state, to minimize
  39. // unnecessary network activity.
  40. // TODO: It might be better to simply shutdown the controlclient and
  41. // make a new one when it's time to unpause.
  42. SetPaused(bool)
  43. // AuthCantContinue returns whether authentication is blocked. If it
  44. // is, you either need to visit the auth URL (previously sent in a
  45. // Status callback) or call the Login function appropriately.
  46. // TODO: this probably belongs in the Status itself instead.
  47. AuthCantContinue() bool
  48. // SetHostinfo changes the Hostinfo structure that will be sent in
  49. // subsequent node registration requests.
  50. // TODO: a server-side change would let us simply upload this
  51. // in a separate http request. It has nothing to do with the rest of
  52. // the state machine.
  53. SetHostinfo(*tailcfg.Hostinfo)
  54. // SetNetinfo changes the NetIinfo structure that will be sent in
  55. // subsequent node registration requests.
  56. // TODO: a server-side change would let us simply upload this
  57. // in a separate http request. It has nothing to do with the rest of
  58. // the state machine.
  59. SetNetInfo(*tailcfg.NetInfo)
  60. // SetTKAHead changes the TKA head hash value that will be sent in
  61. // subsequent netmap requests.
  62. SetTKAHead(headHash string)
  63. // UpdateEndpoints changes the Endpoint structure that will be sent
  64. // in 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. UpdateEndpoints(endpoints []tailcfg.Endpoint)
  69. }
  70. // UserVisibleError is an error that should be shown to users.
  71. type UserVisibleError string
  72. func (e UserVisibleError) Error() string { return string(e) }
  73. func (e UserVisibleError) UserVisibleError() string { return string(e) }