config.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2021, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package refraction
  20. import (
  21. "context"
  22. "net"
  23. "net/http"
  24. "time"
  25. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  26. )
  27. // ConjureConfig specifies the additional configuration for a Conjure dial.
  28. type ConjureConfig struct {
  29. // RegistrationCacheTTL specifies how long to retain a successful Conjure
  30. // registration for reuse in a subsequent dial. This value should be
  31. // synchronized with the Conjure station configuration. When
  32. // RegistrationCacheTTL is 0, registrations are not cached.
  33. RegistrationCacheTTL time.Duration
  34. // RegistrationCacheKey defines a scope or affinity for cached Conjure
  35. // registrations. For example, the key can reflect the target Psiphon server
  36. // as well as the current network ID. This ensures that any replay will
  37. // always use the same cached registration, including its phantom IP(s). And
  38. // ensures that the cache scope is restricted to the current network: when
  39. // the network changes, the client's public IP changes, and previous
  40. // registrations will become invalid. When the client returns to the original
  41. // network, the previous registrations may be valid once again (assuming
  42. // the client reverts back to its original public IP).
  43. RegistrationCacheKey string
  44. // APIRegistrarBidirectionalURL specifies the bidirectional API
  45. // registration endpoint. Setting APIRegistrarBidirectionalURL enables
  46. // API registration. The domain fronting configuration provided by
  47. // APIRegistrarHTTPClient may ignore the host portion of this URL,
  48. // implicitly providing another value; the path portion is always used in
  49. // the request. Only one of API registration or decoy registration can be
  50. // enabled for a single dial.
  51. APIRegistrarBidirectionalURL string
  52. // APIRegistrarHTTPClient specifies a custom HTTP client (and underlying
  53. // dialers) to be used for Conjure API registration. The
  54. // APIRegistrarHTTPClient enables domain fronting of API registration web
  55. // requests. This parameter is required when API registration is enabled.
  56. APIRegistrarHTTPClient *http.Client
  57. // APIRegistrarDelay specifies how long to wait after a successful API
  58. // registration before initiating the phantom dial(s), as required by the
  59. // Conjure protocol. This value depends on Conjure station operations and
  60. // should be synchronized with the Conjure station configuration.
  61. APIRegistrarDelay time.Duration
  62. // DoDecoyRegistration indicates to use decoy registration instead of API
  63. // registration. Only one of API registration or decoy registration can
  64. // be enabled for a single dial.
  65. DoDecoyRegistration bool
  66. // DecoyRegistrarWidth specifies how many decoys to use per registration.
  67. DecoyRegistrarWidth int
  68. // DecoyRegistrarDelay specifies how long to wait after a successful API
  69. // registration before initiating the phantom dial(s), as required by the
  70. // Conjure protocol.
  71. //
  72. // Limitation: this value is not exposed by gotapdance and is currently
  73. // ignored.
  74. DecoyRegistrarDelay time.Duration
  75. // EnableIPv6Dials specifies whether to attempt to dial an IPv6 phantom in
  76. // addition to and concurrent with an IPv4 phantom dial.
  77. EnableIPv6Dials bool
  78. // EnablePortRandomization specifies whether to enable destination port
  79. // randomization.
  80. EnablePortRandomization bool
  81. // EnableRegistrationOverrides specifies whether to allow the Conjure
  82. // system to provide parameter overrides, such as alternative prefixes,
  83. // in the registration response.
  84. EnableRegistrationOverrides bool
  85. // Transport may be protocol.CONJURE_TRANSPORT_MIN_OSSH,
  86. // protocol.CONJURE_TRANSPORT_PREFIX_OSSH, or
  87. // protocol.CONJURE_TRANSPORT_DTLS_OSSH.
  88. Transport string
  89. // STUNServerAddress specifies the STUN server to use with
  90. // protcol.CONJURE_TRANSPORT_DTLS_OSSH.
  91. STUNServerAddress string
  92. // DTLSEmptyInitialPacket specifies whether to prefix the DTLS flow with
  93. // an initial empty packet. Used only for
  94. // protocol.CONJURE_TRANSPORT_DTLS_OSSH.
  95. DTLSEmptyInitialPacket bool
  96. // DiagnosticID identifies this dial in diagnostics.
  97. DiagnosticID string
  98. // Logger is used for logging diagnostics.
  99. Logger common.Logger
  100. }
  101. // Dialer is the dialer function type expected by gotapdance.
  102. type Dialer func(ctx context.Context, network, laddr, raddr string) (net.Conn, error)