constants.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/types/key"
  12. "tailscale.com/types/logger"
  13. )
  14. const (
  15. // upgradeHeader is the value of the Upgrade HTTP header used to
  16. // indicate the Tailscale control protocol.
  17. upgradeHeaderValue = "tailscale-control-protocol"
  18. // handshakeHeaderName is the HTTP request header that can
  19. // optionally contain base64-encoded initial handshake
  20. // payload, to save an RTT.
  21. handshakeHeaderName = "X-Tailscale-Handshake"
  22. // serverUpgradePath is where the server-side HTTP handler to
  23. // to do the protocol switch is located.
  24. serverUpgradePath = "/ts2021"
  25. )
  26. // Dialer contains configuration on how to dial the Tailscale control server.
  27. type Dialer struct {
  28. // Hostname is the hostname to connect to, with no port number.
  29. //
  30. // This field is required.
  31. Hostname string
  32. // MachineKey contains the current machine's private key.
  33. //
  34. // This field is required.
  35. MachineKey key.MachinePrivate
  36. // ControlKey contains the expected public key for the control server.
  37. //
  38. // This field is required.
  39. ControlKey key.MachinePublic
  40. // ProtocolVersion is the expected protocol version to negotiate.
  41. //
  42. // This field is required.
  43. ProtocolVersion uint16
  44. // HTTPPort is the port number to use when making a HTTP connection.
  45. //
  46. // If not specified, this defaults to port 80.
  47. HTTPPort string
  48. // HTTPSPort is the port number to use when making a HTTPS connection.
  49. //
  50. // If not specified, this defaults to port 443.
  51. HTTPSPort string
  52. // Dialer is the dialer used to make outbound connections.
  53. //
  54. // If not specified, this defaults to net.Dialer.DialContext.
  55. Dialer dnscache.DialContextFunc
  56. // DNSCache is the caching Resolver used by this Dialer.
  57. //
  58. // If not specified, a new Resolver is created per attempt.
  59. DNSCache *dnscache.Resolver
  60. // Logf, if set, is a logging function to use; if unset, logs are
  61. // dropped.
  62. Logf logger.Logf
  63. NetMon *netmon.Monitor
  64. // DialPlan, if set, contains instructions from the control server on
  65. // how to connect to it. If present, we will try the methods in this
  66. // plan before falling back to DNS.
  67. DialPlan *tailcfg.ControlDialPlan
  68. proxyFunc func(*http.Request) (*url.URL, error) // or nil
  69. // For tests only
  70. drainFinished chan struct{}
  71. omitCertErrorLogging bool
  72. testFallbackDelay time.Duration
  73. }
  74. func strDef(v1, v2 string) string {
  75. if v1 != "" {
  76. return v1
  77. }
  78. return v2
  79. }