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. LoginEphemeral // set RegisterRequest.Ephemeral
  19. )
  20. // Client represents a client connection to the control server.
  21. // Currently this is done through a pair of polling https requests in
  22. // the Auto client, but that might change eventually.
  23. type Client interface {
  24. // Shutdown closes this session, which should not be used any further
  25. // afterwards.
  26. Shutdown()
  27. // Login begins an interactive or non-interactive login process.
  28. // Client will eventually call the Status callback with either a
  29. // LoginFinished flag (on success) or an auth URL (if further
  30. // interaction is needed).
  31. Login(*tailcfg.Oauth2Token, LoginFlags)
  32. // StartLogout starts an asynchronous logout process.
  33. // When it finishes, the Status callback will be called while
  34. // AuthCantContinue()==true.
  35. StartLogout()
  36. // Logout starts a synchronous logout process. It doesn't return
  37. // until the logout operation has been completed.
  38. Logout(context.Context) error
  39. // SetPaused pauses or unpauses the controlclient activity as much
  40. // as possible, without losing its internal state, to minimize
  41. // unnecessary network activity.
  42. // TODO: It might be better to simply shutdown the controlclient and
  43. // make a new one when it's time to unpause.
  44. SetPaused(bool)
  45. // AuthCantContinue returns whether authentication is blocked. If it
  46. // is, you either need to visit the auth URL (previously sent in a
  47. // Status callback) or call the Login function appropriately.
  48. // TODO: this probably belongs in the Status itself instead.
  49. AuthCantContinue() bool
  50. // SetHostinfo changes the Hostinfo structure that will be sent in
  51. // subsequent node registration requests.
  52. // TODO: a server-side change would let us simply upload this
  53. // in a separate http request. It has nothing to do with the rest of
  54. // the state machine.
  55. SetHostinfo(*tailcfg.Hostinfo)
  56. // SetNetinfo changes the NetIinfo 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. SetNetInfo(*tailcfg.NetInfo)
  62. // UpdateEndpoints changes the Endpoint structure that will be sent
  63. // in 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. UpdateEndpoints(endpoints []tailcfg.Endpoint)
  68. }
  69. // UserVisibleError is an error that should be shown to users.
  70. type UserVisibleError string
  71. func (e UserVisibleError) Error() string { return string(e) }
  72. func (e UserVisibleError) UserVisibleError() string { return string(e) }