constants.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright (c) 2022 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 controlhttp
  5. import (
  6. "net/http"
  7. "net/url"
  8. "time"
  9. "tailscale.com/net/dnscache"
  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. // Logf, if set, is a logging function to use; if unset, logs are
  57. // dropped.
  58. Logf logger.Logf
  59. // DialPlan, if set, contains instructions from the control server on
  60. // how to connect to it. If present, we will try the methods in this
  61. // plan before falling back to DNS.
  62. DialPlan *tailcfg.ControlDialPlan
  63. proxyFunc func(*http.Request) (*url.URL, error) // or nil
  64. // For tests only
  65. drainFinished chan struct{}
  66. insecureTLS bool
  67. testFallbackDelay time.Duration
  68. }
  69. func strDef(v1, v2 string) string {
  70. if v1 != "" {
  71. return v1
  72. }
  73. return v2
  74. }