constants.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package controlhttp
  4. import (
  5. "net/http"
  6. "net/url"
  7. "time"
  8. "tailscale.com/health"
  9. "tailscale.com/net/dnscache"
  10. "tailscale.com/net/netmon"
  11. "tailscale.com/tailcfg"
  12. "tailscale.com/tstime"
  13. "tailscale.com/types/key"
  14. "tailscale.com/types/logger"
  15. )
  16. const (
  17. // serverUpgradePath is where the server-side HTTP handler to
  18. // to do the protocol switch is located.
  19. serverUpgradePath = "/ts2021"
  20. )
  21. // NoPort is a sentinel value for Dialer.HTTPSPort to indicate that HTTPS
  22. // should not be tried on any port. It exists primarily for some localhost
  23. // tests where the control plane only runs on HTTP.
  24. const NoPort = "none"
  25. // Dialer contains configuration on how to dial the Tailscale control server.
  26. type Dialer struct {
  27. // Hostname is the hostname to connect to, with no port number.
  28. //
  29. // This field is required.
  30. Hostname string
  31. // MachineKey contains the current machine's private key.
  32. //
  33. // This field is required.
  34. MachineKey key.MachinePrivate
  35. // ControlKey contains the expected public key for the control server.
  36. //
  37. // This field is required.
  38. ControlKey key.MachinePublic
  39. // ProtocolVersion is the expected protocol version to negotiate.
  40. //
  41. // This field is required.
  42. ProtocolVersion uint16
  43. // HTTPPort is the port number to use when making a HTTP connection.
  44. //
  45. // If not specified, this defaults to port 80.
  46. HTTPPort string
  47. // HTTPSPort is the port number to use when making a HTTPS connection.
  48. //
  49. // If not specified, this defaults to port 443.
  50. //
  51. // If "none" (NoPort), HTTPS is disabled.
  52. HTTPSPort string
  53. // Dialer is the dialer used to make outbound connections.
  54. //
  55. // If not specified, this defaults to net.Dialer.DialContext.
  56. Dialer dnscache.DialContextFunc
  57. // DNSCache is the caching Resolver used by this Dialer.
  58. //
  59. // If not specified, a new Resolver is created per attempt.
  60. DNSCache *dnscache.Resolver
  61. // Logf, if set, is a logging function to use; if unset, logs are
  62. // dropped.
  63. Logf logger.Logf
  64. NetMon *netmon.Monitor
  65. // HealthTracker, if non-nil, is the health tracker to use.
  66. HealthTracker *health.Tracker
  67. // DialPlan, if set, contains instructions from the control server on
  68. // how to connect to it. If present, we will try the methods in this
  69. // plan before falling back to DNS.
  70. DialPlan *tailcfg.ControlDialPlan
  71. proxyFunc func(*http.Request) (*url.URL, error) // or nil
  72. // For tests only
  73. drainFinished chan struct{}
  74. omitCertErrorLogging bool
  75. testFallbackDelay time.Duration
  76. // Clock, if non-nil, overrides the clock to use.
  77. // If nil, tstime.StdClock is used.
  78. // This exists primarily for tests.
  79. Clock tstime.Clock
  80. }
  81. func strDef(v1, v2 string) string {
  82. if v1 != "" {
  83. return v1
  84. }
  85. return v2
  86. }