constants.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/net/dnscache"
  9. "tailscale.com/net/netmon"
  10. "tailscale.com/tailcfg"
  11. "tailscale.com/tstime"
  12. "tailscale.com/types/key"
  13. "tailscale.com/types/logger"
  14. )
  15. const (
  16. // upgradeHeader is the value of the Upgrade HTTP header used to
  17. // indicate the Tailscale control protocol.
  18. upgradeHeaderValue = "tailscale-control-protocol"
  19. // handshakeHeaderName is the HTTP request header that can
  20. // optionally contain base64-encoded initial handshake
  21. // payload, to save an RTT.
  22. handshakeHeaderName = "X-Tailscale-Handshake"
  23. // serverUpgradePath is where the server-side HTTP handler to
  24. // to do the protocol switch is located.
  25. serverUpgradePath = "/ts2021"
  26. )
  27. // Dialer contains configuration on how to dial the Tailscale control server.
  28. type Dialer struct {
  29. // Hostname is the hostname to connect to, with no port number.
  30. //
  31. // This field is required.
  32. Hostname string
  33. // MachineKey contains the current machine's private key.
  34. //
  35. // This field is required.
  36. MachineKey key.MachinePrivate
  37. // ControlKey contains the expected public key for the control server.
  38. //
  39. // This field is required.
  40. ControlKey key.MachinePublic
  41. // ProtocolVersion is the expected protocol version to negotiate.
  42. //
  43. // This field is required.
  44. ProtocolVersion uint16
  45. // HTTPPort is the port number to use when making a HTTP connection.
  46. //
  47. // If not specified, this defaults to port 80.
  48. HTTPPort string
  49. // HTTPSPort is the port number to use when making a HTTPS connection.
  50. //
  51. // If not specified, this defaults to port 443.
  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. // DialPlan, if set, contains instructions from the control server on
  66. // how to connect to it. If present, we will try the methods in this
  67. // plan before falling back to DNS.
  68. DialPlan *tailcfg.ControlDialPlan
  69. proxyFunc func(*http.Request) (*url.URL, error) // or nil
  70. // For tests only
  71. drainFinished chan struct{}
  72. omitCertErrorLogging bool
  73. testFallbackDelay time.Duration
  74. // tstime.Clock is used instead of time package for methods such as time.Now.
  75. // If not specified, will default to tstime.StdClock{}.
  76. Clock tstime.Clock
  77. }
  78. func strDef(v1, v2 string) string {
  79. if v1 != "" {
  80. return v1
  81. }
  82. return v2
  83. }