parameters.go 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019
  1. /*
  2. * Copyright (c) 2018, 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. /*
  20. Package parameters implements dynamic, concurrency-safe parameters that
  21. determine Psiphon client and server behaviors.
  22. Parameters include network timeouts, probabilities for actions, lists of
  23. protocols, etc. Parameters are initialized with reasonable defaults. New
  24. values may be applied, allowing the client or server to customize its
  25. parameters from both a config file and tactics data. Sane minimum values are
  26. enforced.
  27. Parameters may be read and updated concurrently. The read mechanism offers a
  28. snapshot so that related parameters, such as two Ints representing a range; or
  29. a more complex series of related parameters; may be read in an atomic and
  30. consistent way. For example:
  31. p := params.Get()
  32. min := p.Int("Min")
  33. max := p.Int("Max")
  34. p = nil
  35. For long-running operations, it is recommended to set any pointer to the
  36. snapshot to nil to allow garbage collection of old snaphots in cases where the
  37. parameters change.
  38. In general, parameters should be read as close to the point of use as possible
  39. to ensure that dynamic changes to the parameter values take effect.
  40. For duration parameters, time.ParseDuration-compatible string values are
  41. supported when applying new values. This allows specifying durations as, for
  42. example, "100ms" or "24h".
  43. Values read from the parameters are not deep copies and must be treated as
  44. read-only.
  45. */
  46. package parameters
  47. import (
  48. "encoding/json"
  49. "net/http"
  50. "reflect"
  51. "sync/atomic"
  52. "time"
  53. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  54. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  55. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/obfuscator"
  56. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/prng"
  57. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
  58. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/transforms"
  59. "golang.org/x/net/bpf"
  60. )
  61. const (
  62. NetworkLatencyMultiplier = "NetworkLatencyMultiplier"
  63. NetworkLatencyMultiplierMin = "NetworkLatencyMultiplierMin"
  64. NetworkLatencyMultiplierMax = "NetworkLatencyMultiplierMax"
  65. NetworkLatencyMultiplierLambda = "NetworkLatencyMultiplierLambda"
  66. TacticsWaitPeriod = "TacticsWaitPeriod"
  67. TacticsRetryPeriod = "TacticsRetryPeriod"
  68. TacticsRetryPeriodJitter = "TacticsRetryPeriodJitter"
  69. TacticsTimeout = "TacticsTimeout"
  70. ConnectionWorkerPoolSize = "ConnectionWorkerPoolSize"
  71. TunnelPoolSize = "TunnelPoolSize"
  72. TunnelConnectTimeout = "TunnelConnectTimeout"
  73. EstablishTunnelTimeout = "EstablishTunnelTimeout"
  74. EstablishTunnelWorkTime = "EstablishTunnelWorkTime"
  75. EstablishTunnelPausePeriod = "EstablishTunnelPausePeriod"
  76. EstablishTunnelPausePeriodJitter = "EstablishTunnelPausePeriodJitter"
  77. EstablishTunnelServerAffinityGracePeriod = "EstablishTunnelServerAffinityGracePeriod"
  78. StaggerConnectionWorkersPeriod = "StaggerConnectionWorkersPeriod"
  79. StaggerConnectionWorkersJitter = "StaggerConnectionWorkersJitter"
  80. LimitIntensiveConnectionWorkers = "LimitIntensiveConnectionWorkers"
  81. UpstreamProxyErrorMinWaitDuration = "UpstreamProxyErrorMinWaitDuration"
  82. UpstreamProxyErrorMaxWaitDuration = "UpstreamProxyErrorMaxWaitDuration"
  83. IgnoreHandshakeStatsRegexps = "IgnoreHandshakeStatsRegexps"
  84. PrioritizeTunnelProtocolsProbability = "PrioritizeTunnelProtocolsProbability"
  85. PrioritizeTunnelProtocols = "PrioritizeTunnelProtocols"
  86. PrioritizeTunnelProtocolsCandidateCount = "PrioritizeTunnelProtocolsCandidateCount"
  87. InitialLimitTunnelProtocolsProbability = "InitialLimitTunnelProtocolsProbability"
  88. InitialLimitTunnelProtocols = "InitialLimitTunnelProtocols"
  89. InitialLimitTunnelProtocolsCandidateCount = "InitialLimitTunnelProtocolsCandidateCount"
  90. LimitTunnelProtocolsProbability = "LimitTunnelProtocolsProbability"
  91. LimitTunnelProtocols = "LimitTunnelProtocols"
  92. LimitTunnelDialPortNumbersProbability = "LimitTunnelDialPortNumbersProbability"
  93. LimitTunnelDialPortNumbers = "LimitTunnelDialPortNumbers"
  94. LimitTLSProfilesProbability = "LimitTLSProfilesProbability"
  95. LimitTLSProfiles = "LimitTLSProfiles"
  96. UseOnlyCustomTLSProfiles = "UseOnlyCustomTLSProfiles"
  97. CustomTLSProfiles = "CustomTLSProfiles"
  98. SelectRandomizedTLSProfileProbability = "SelectRandomizedTLSProfileProbability"
  99. NoDefaultTLSSessionIDProbability = "NoDefaultTLSSessionIDProbability"
  100. DisableFrontingProviderTLSProfiles = "DisableFrontingProviderTLSProfiles"
  101. LimitQUICVersionsProbability = "LimitQUICVersionsProbability"
  102. LimitQUICVersions = "LimitQUICVersions"
  103. DisableFrontingProviderQUICVersions = "DisableFrontingProviderQUICVersions"
  104. QUICDisableClientPathMTUDiscoveryProbability = "QUICDisableClientPathMTUDiscoveryProbability"
  105. FragmentorProbability = "FragmentorProbability"
  106. FragmentorLimitProtocols = "FragmentorLimitProtocols"
  107. FragmentorMinTotalBytes = "FragmentorMinTotalBytes"
  108. FragmentorMaxTotalBytes = "FragmentorMaxTotalBytes"
  109. FragmentorMinWriteBytes = "FragmentorMinWriteBytes"
  110. FragmentorMaxWriteBytes = "FragmentorMaxWriteBytes"
  111. FragmentorMinDelay = "FragmentorMinDelay"
  112. FragmentorMaxDelay = "FragmentorMaxDelay"
  113. FragmentorDownstreamProbability = "FragmentorDownstreamProbability"
  114. FragmentorDownstreamLimitProtocols = "FragmentorDownstreamLimitProtocols"
  115. FragmentorDownstreamMinTotalBytes = "FragmentorDownstreamMinTotalBytes"
  116. FragmentorDownstreamMaxTotalBytes = "FragmentorDownstreamMaxTotalBytes"
  117. FragmentorDownstreamMinWriteBytes = "FragmentorDownstreamMinWriteBytes"
  118. FragmentorDownstreamMaxWriteBytes = "FragmentorDownstreamMaxWriteBytes"
  119. FragmentorDownstreamMinDelay = "FragmentorDownstreamMinDelay"
  120. FragmentorDownstreamMaxDelay = "FragmentorDownstreamMaxDelay"
  121. ObfuscatedSSHMinPadding = "ObfuscatedSSHMinPadding"
  122. ObfuscatedSSHMaxPadding = "ObfuscatedSSHMaxPadding"
  123. TunnelOperateShutdownTimeout = "TunnelOperateShutdownTimeout"
  124. TunnelPortForwardDialTimeout = "TunnelPortForwardDialTimeout"
  125. PacketTunnelReadTimeout = "PacketTunnelReadTimeout"
  126. TunnelRateLimits = "TunnelRateLimits"
  127. AdditionalCustomHeaders = "AdditionalCustomHeaders"
  128. SpeedTestPaddingMinBytes = "SpeedTestPaddingMinBytes"
  129. SpeedTestPaddingMaxBytes = "SpeedTestPaddingMaxBytes"
  130. SpeedTestMaxSampleCount = "SpeedTestMaxSampleCount"
  131. SSHKeepAliveSpeedTestSampleProbability = "SSHKeepAliveSpeedTestSampleProbability"
  132. SSHKeepAlivePaddingMinBytes = "SSHKeepAlivePaddingMinBytes"
  133. SSHKeepAlivePaddingMaxBytes = "SSHKeepAlivePaddingMaxBytes"
  134. SSHKeepAlivePeriodMin = "SSHKeepAlivePeriodMin"
  135. SSHKeepAlivePeriodMax = "SSHKeepAlivePeriodMax"
  136. SSHKeepAlivePeriodicTimeout = "SSHKeepAlivePeriodicTimeout"
  137. SSHKeepAlivePeriodicInactivePeriod = "SSHKeepAlivePeriodicInactivePeriod"
  138. SSHKeepAliveProbeTimeout = "SSHKeepAliveProbeTimeout"
  139. SSHKeepAliveProbeInactivePeriod = "SSHKeepAliveProbeInactivePeriod"
  140. SSHKeepAliveNetworkConnectivityPollingPeriod = "SSHKeepAliveNetworkConnectivityPollingPeriod"
  141. SSHKeepAliveResetOnFailureProbability = "SSHKeepAliveResetOnFailureProbability"
  142. HTTPProxyOriginServerTimeout = "HTTPProxyOriginServerTimeout"
  143. HTTPProxyMaxIdleConnectionsPerHost = "HTTPProxyMaxIdleConnectionsPerHost"
  144. FetchRemoteServerListTimeout = "FetchRemoteServerListTimeout"
  145. FetchRemoteServerListRetryPeriod = "FetchRemoteServerListRetryPeriod"
  146. FetchRemoteServerListStalePeriod = "FetchRemoteServerListStalePeriod"
  147. RemoteServerListSignaturePublicKey = "RemoteServerListSignaturePublicKey"
  148. RemoteServerListURLs = "RemoteServerListURLs"
  149. ObfuscatedServerListRootURLs = "ObfuscatedServerListRootURLs"
  150. PsiphonAPIRequestTimeout = "PsiphonAPIRequestTimeout"
  151. PsiphonAPIStatusRequestPeriodMin = "PsiphonAPIStatusRequestPeriodMin"
  152. PsiphonAPIStatusRequestPeriodMax = "PsiphonAPIStatusRequestPeriodMax"
  153. PsiphonAPIStatusRequestShortPeriodMin = "PsiphonAPIStatusRequestShortPeriodMin"
  154. PsiphonAPIStatusRequestShortPeriodMax = "PsiphonAPIStatusRequestShortPeriodMax"
  155. PsiphonAPIStatusRequestPaddingMinBytes = "PsiphonAPIStatusRequestPaddingMinBytes"
  156. PsiphonAPIStatusRequestPaddingMaxBytes = "PsiphonAPIStatusRequestPaddingMaxBytes"
  157. PsiphonAPIPersistentStatsMaxCount = "PsiphonAPIPersistentStatsMaxCount"
  158. PsiphonAPIConnectedRequestPeriod = "PsiphonAPIConnectedRequestPeriod"
  159. PsiphonAPIConnectedRequestRetryPeriod = "PsiphonAPIConnectedRequestRetryPeriod"
  160. FetchSplitTunnelRoutesTimeout = "FetchSplitTunnelRoutesTimeout"
  161. SplitTunnelRoutesURLFormat = "SplitTunnelRoutesURLFormat"
  162. SplitTunnelRoutesSignaturePublicKey = "SplitTunnelRoutesSignaturePublicKey"
  163. SplitTunnelDNSServer = "SplitTunnelDNSServer"
  164. SplitTunnelClassificationTTL = "SplitTunnelClassificationTTL"
  165. SplitTunnelClassificationMaxEntries = "SplitTunnelClassificationMaxEntries"
  166. FetchUpgradeTimeout = "FetchUpgradeTimeout"
  167. FetchUpgradeRetryPeriod = "FetchUpgradeRetryPeriod"
  168. FetchUpgradeStalePeriod = "FetchUpgradeStalePeriod"
  169. UpgradeDownloadURLs = "UpgradeDownloadURLs"
  170. UpgradeDownloadClientVersionHeader = "UpgradeDownloadClientVersionHeader"
  171. TotalBytesTransferredNoticePeriod = "TotalBytesTransferredNoticePeriod"
  172. TotalBytesTransferredEmitMemoryMetrics = "TotalBytesTransferredEmitMemoryMetrics"
  173. MeekDialDomainsOnly = "MeekDialDomainsOnly"
  174. MeekLimitBufferSizes = "MeekLimitBufferSizes"
  175. MeekCookieMaxPadding = "MeekCookieMaxPadding"
  176. MeekFullReceiveBufferLength = "MeekFullReceiveBufferLength"
  177. MeekReadPayloadChunkLength = "MeekReadPayloadChunkLength"
  178. MeekLimitedFullReceiveBufferLength = "MeekLimitedFullReceiveBufferLength"
  179. MeekLimitedReadPayloadChunkLength = "MeekLimitedReadPayloadChunkLength"
  180. MeekMinPollInterval = "MeekMinPollInterval"
  181. MeekMinPollIntervalJitter = "MeekMinPollIntervalJitter"
  182. MeekMaxPollInterval = "MeekMaxPollInterval"
  183. MeekMaxPollIntervalJitter = "MeekMaxPollIntervalJitter"
  184. MeekPollIntervalMultiplier = "MeekPollIntervalMultiplier"
  185. MeekPollIntervalJitter = "MeekPollIntervalJitter"
  186. MeekApplyPollIntervalMultiplierProbability = "MeekApplyPollIntervalMultiplierProbability"
  187. MeekRoundTripRetryDeadline = "MeekRoundTripRetryDeadline"
  188. MeekRoundTripRetryMinDelay = "MeekRoundTripRetryMinDelay"
  189. MeekRoundTripRetryMaxDelay = "MeekRoundTripRetryMaxDelay"
  190. MeekRoundTripRetryMultiplier = "MeekRoundTripRetryMultiplier"
  191. MeekRoundTripTimeout = "MeekRoundTripTimeout"
  192. MeekTrafficShapingProbability = "MeekTrafficShapingProbability"
  193. MeekTrafficShapingLimitProtocols = "MeekTrafficShapingLimitProtocols"
  194. MeekMinTLSPadding = "MeekMinTLSPadding"
  195. MeekMaxTLSPadding = "MeekMaxTLSPadding"
  196. MeekMinLimitRequestPayloadLength = "MeekMinLimitRequestPayloadLength"
  197. MeekMaxLimitRequestPayloadLength = "MeekMaxLimitRequestPayloadLength"
  198. MeekRedialTLSProbability = "MeekRedialTLSProbability"
  199. MeekAlternateCookieNameProbability = "MeekAlternateCookieNameProbability"
  200. MeekAlternateContentTypeProbability = "MeekAlternateContentTypeProbability"
  201. TransformHostNameProbability = "TransformHostNameProbability"
  202. PickUserAgentProbability = "PickUserAgentProbability"
  203. LivenessTestMinUpstreamBytes = "LivenessTestMinUpstreamBytes"
  204. LivenessTestMaxUpstreamBytes = "LivenessTestMaxUpstreamBytes"
  205. LivenessTestMinDownstreamBytes = "LivenessTestMinDownstreamBytes"
  206. LivenessTestMaxDownstreamBytes = "LivenessTestMaxDownstreamBytes"
  207. ReplayCandidateCount = "ReplayCandidateCount"
  208. ReplayDialParametersTTL = "ReplayDialParametersTTL"
  209. ReplayTargetUpstreamBytes = "ReplayTargetUpstreamBytes"
  210. ReplayTargetDownstreamBytes = "ReplayTargetDownstreamBytes"
  211. ReplayTargetTunnelDuration = "ReplayTargetTunnelDuration"
  212. ReplayLaterRoundMoveToFrontProbability = "ReplayLaterRoundMoveToFrontProbability"
  213. ReplayRetainFailedProbability = "ReplayRetainFailedProbability"
  214. ReplayIgnoreChangedConfigState = "ReplayIgnoreChangedConfigState"
  215. ReplayBPF = "ReplayBPF"
  216. ReplaySSH = "ReplaySSH"
  217. ReplayObfuscatorPadding = "ReplayObfuscatorPadding"
  218. ReplayFragmentor = "ReplayFragmentor"
  219. ReplayTLSProfile = "ReplayTLSProfile"
  220. ReplayFronting = "ReplayFronting"
  221. ReplayHostname = "ReplayHostname"
  222. ReplayQUICVersion = "ReplayQUICVersion"
  223. ReplayObfuscatedQUIC = "ReplayObfuscatedQUIC"
  224. ReplayObfuscatedQUICNonceTransformer = "ReplayObfuscatedQUICNonceTransformer"
  225. ReplayConjureRegistration = "ReplayConjureRegistration"
  226. ReplayConjureTransport = "ReplayConjureTransport"
  227. ReplayLivenessTest = "ReplayLivenessTest"
  228. ReplayUserAgent = "ReplayUserAgent"
  229. ReplayAPIRequestPadding = "ReplayAPIRequestPadding"
  230. ReplayHoldOffTunnel = "ReplayHoldOffTunnel"
  231. ReplayResolveParameters = "ReplayResolveParameters"
  232. ReplayHTTPTransformerParameters = "ReplayHTTPTransformerParameters"
  233. ReplayOSSHSeedTransformerParameters = "ReplayOSSHSeedTransformerParameters"
  234. ReplayOSSHPrefix = "ReplayOSSHPrefix"
  235. ReplayTLSFragmentClientHello = "ReplayTLSFragmentClientHello"
  236. ReplayInproxyWebRTC = "ReplayInproxyWebRTC"
  237. ReplayInproxySTUN = "ReplayInproxySTUN"
  238. APIRequestUpstreamPaddingMinBytes = "APIRequestUpstreamPaddingMinBytes"
  239. APIRequestUpstreamPaddingMaxBytes = "APIRequestUpstreamPaddingMaxBytes"
  240. APIRequestDownstreamPaddingMinBytes = "APIRequestDownstreamPaddingMinBytes"
  241. APIRequestDownstreamPaddingMaxBytes = "APIRequestDownstreamPaddingMaxBytes"
  242. PersistentStatsMaxStoreRecords = "PersistentStatsMaxStoreRecords"
  243. PersistentStatsMaxSendBytes = "PersistentStatsMaxSendBytes"
  244. RecordRemoteServerListPersistentStatsProbability = "RecordRemoteServerListPersistentStatsProbability"
  245. RecordFailedTunnelPersistentStatsProbability = "RecordFailedTunnelPersistentStatsProbability"
  246. ServerEntryMinimumAgeForPruning = "ServerEntryMinimumAgeForPruning"
  247. ApplicationParametersProbability = "ApplicationParametersProbability"
  248. ApplicationParameters = "ApplicationParameters"
  249. BPFServerTCPProgram = "BPFServerTCPProgram"
  250. BPFServerTCPProbability = "BPFServerTCPProbability"
  251. BPFClientTCPProgram = "BPFClientTCPProgram"
  252. BPFClientTCPProbability = "BPFClientTCPProbability"
  253. ServerPacketManipulationSpecs = "ServerPacketManipulationSpecs"
  254. ServerProtocolPacketManipulations = "ServerProtocolPacketManipulations"
  255. ServerPacketManipulationProbability = "ServerPacketManipulationProbability"
  256. FeedbackUploadURLs = "FeedbackUploadURLs"
  257. FeedbackEncryptionPublicKey = "FeedbackEncryptionPublicKey"
  258. FeedbackTacticsWaitPeriod = "FeedbackTacticsWaitPeriod"
  259. FeedbackUploadMaxAttempts = "FeedbackUploadMaxAttempts"
  260. FeedbackUploadRetryMinDelaySeconds = "FeedbackUploadRetryMinDelaySeconds"
  261. FeedbackUploadRetryMaxDelaySeconds = "FeedbackUploadRetryMaxDelaySeconds"
  262. FeedbackUploadTimeoutSeconds = "FeedbackUploadTimeoutSeconds"
  263. ServerReplayPacketManipulation = "ServerReplayPacketManipulation"
  264. ServerReplayFragmentor = "ServerReplayFragmentor"
  265. ServerReplayUnknownGeoIP = "ServerReplayUnknownGeoIP"
  266. ServerReplayTTL = "ServerReplayTTL"
  267. ServerReplayTargetWaitDuration = "ServerReplayTargetWaitDuration"
  268. ServerReplayTargetTunnelDuration = "ServerReplayTargetTunnelDuration"
  269. ServerReplayTargetUpstreamBytes = "ServerReplayTargetUpstreamBytes"
  270. ServerReplayTargetDownstreamBytes = "ServerReplayTargetDownstreamBytes"
  271. ServerReplayFailedCountThreshold = "ServerReplayFailedCountThreshold"
  272. ServerBurstUpstreamDeadline = "ServerBurstUpstreamDeadline"
  273. ServerBurstUpstreamTargetBytes = "ServerBurstUpstreamTargetBytes"
  274. ServerBurstDownstreamDeadline = "ServerBurstDownstreamDeadline"
  275. ServerBurstDownstreamTargetBytes = "ServerBurstDownstreamTargetBytes"
  276. ClientBurstUpstreamDeadline = "ClientBurstUpstreamDeadline"
  277. ClientBurstUpstreamTargetBytes = "ClientBurstUpstreamTargetBytes"
  278. ClientBurstDownstreamDeadline = "ClientBurstDownstreamDeadline"
  279. ClientBurstDownstreamTargetBytes = "ClientBurstDownstreamTargetBytes"
  280. ConjureCachedRegistrationTTL = "ConjureCachedRegistrationTTL"
  281. ConjureAPIRegistrarURL = "ConjureAPIRegistrarURL"
  282. ConjureAPIRegistrarBidirectionalURL = "ConjureAPIRegistrarBidirectionalURL"
  283. ConjureAPIRegistrarFrontingSpecs = "ConjureAPIRegistrarFrontingSpecs"
  284. ConjureAPIRegistrarMinDelay = "ConjureAPIRegistrarMinDelay"
  285. ConjureAPIRegistrarMaxDelay = "ConjureAPIRegistrarMaxDelay"
  286. ConjureDecoyRegistrarProbability = "ConjureDecoyRegistrarProbability"
  287. ConjureDecoyRegistrarWidth = "ConjureDecoyRegistrarWidth"
  288. ConjureDecoyRegistrarMinDelay = "ConjureDecoyRegistrarMinDelay"
  289. ConjureDecoyRegistrarMaxDelay = "ConjureDecoyRegistrarMaxDelay"
  290. ConjureEnableIPv6Dials = "ConjureEnableIPv6Dials"
  291. ConjureEnablePortRandomization = "ConjureEnablePortRandomization"
  292. ConjureEnableRegistrationOverrides = "ConjureEnableRegistrationOverrides"
  293. ConjureLimitTransportsProbability = "ConjureLimitTransportsProbability"
  294. ConjureLimitTransports = "ConjureLimitTransports"
  295. ConjureSTUNServerAddresses = "ConjureSTUNServerAddresses"
  296. ConjureDTLSEmptyInitialPacketProbability = "ConjureDTLSEmptyInitialPacketProbability"
  297. CustomHostNameRegexes = "CustomHostNameRegexes"
  298. CustomHostNameProbability = "CustomHostNameProbability"
  299. CustomHostNameLimitProtocols = "CustomHostNameLimitProtocols"
  300. HoldOffTunnelMinDuration = "HoldOffTunnelMinDuration"
  301. HoldOffTunnelMaxDuration = "HoldOffTunnelMaxDuration"
  302. HoldOffTunnelProtocols = "HoldOffTunnelProtocols"
  303. HoldOffTunnelFrontingProviderIDs = "HoldOffTunnelFrontingProviderIDs"
  304. HoldOffTunnelProbability = "HoldOffTunnelProbability"
  305. RestrictFrontingProviderIDs = "RestrictFrontingProviderIDs"
  306. RestrictFrontingProviderIDsServerProbability = "RestrictFrontingProviderIDsServerProbability"
  307. RestrictFrontingProviderIDsClientProbability = "RestrictFrontingProviderIDsClientProbability"
  308. HoldOffDirectTunnelMinDuration = "HoldOffDirectTunnelMinDuration"
  309. HoldOffDirectTunnelMaxDuration = "HoldOffDirectTunnelMaxDuration"
  310. HoldOffDirectTunnelProviderRegions = "HoldOffDirectTunnelProviderRegions"
  311. HoldOffDirectTunnelProbability = "HoldOffDirectTunnelProbability"
  312. RestrictDirectProviderRegions = "RestrictDirectProviderRegions"
  313. RestrictDirectProviderIDsServerProbability = "RestrictDirectProviderIDsServerProbability"
  314. RestrictDirectProviderIDsClientProbability = "RestrictDirectProviderIDsClientProbability"
  315. UpstreamProxyAllowAllServerEntrySources = "UpstreamProxyAllowAllServerEntrySources"
  316. DestinationBytesMetricsASN = "DestinationBytesMetricsASN"
  317. DNSResolverAttemptsPerServer = "DNSResolverAttemptsPerServer"
  318. DNSResolverAttemptsPerPreferredServer = "DNSResolverAttemptsPerPreferredServer"
  319. DNSResolverRequestTimeout = "DNSResolverRequestTimeout"
  320. DNSResolverAwaitTimeout = "DNSResolverAwaitTimeout"
  321. DNSResolverPreresolvedIPAddressCIDRs = "DNSResolverPreresolvedIPAddressCIDRs"
  322. DNSResolverPreresolvedIPAddressProbability = "DNSResolverPreresolvedIPAddressProbability"
  323. DNSResolverAlternateServers = "DNSResolverAlternateServers"
  324. DNSResolverPreferredAlternateServers = "DNSResolverPreferredAlternateServers"
  325. DNSResolverPreferAlternateServerProbability = "DNSResolverPreferAlternateServerProbability"
  326. DNSResolverProtocolTransformSpecs = "DNSResolverProtocolTransformSpecs"
  327. DNSResolverProtocolTransformScopedSpecNames = "DNSResolverProtocolTransformScopedSpecNames"
  328. DNSResolverProtocolTransformProbability = "DNSResolverProtocolTransformProbability"
  329. DNSResolverIncludeEDNS0Probability = "DNSResolverIncludeEDNS0Probability"
  330. DNSResolverCacheExtensionInitialTTL = "DNSResolverCacheExtensionInitialTTL"
  331. DNSResolverCacheExtensionVerifiedTTL = "DNSResolverCacheExtensionVerifiedTTL"
  332. AddFrontingProviderPsiphonFrontingHeader = "AddFrontingProviderPsiphonFrontingHeader"
  333. DirectHTTPProtocolTransformSpecs = "DirectHTTPProtocolTransformSpecs"
  334. DirectHTTPProtocolTransformScopedSpecNames = "DirectHTTPProtocolTransformScopedSpecNames"
  335. DirectHTTPProtocolTransformProbability = "DirectHTTPProtocolTransformProbability"
  336. FrontedHTTPProtocolTransformSpecs = "FrontedHTTPProtocolTransformSpecs"
  337. FrontedHTTPProtocolTransformScopedSpecNames = "FrontedHTTPProtocolTransformScopedSpecNames"
  338. FrontedHTTPProtocolTransformProbability = "FrontedHTTPProtocolTransformProbability"
  339. OSSHObfuscatorSeedTransformSpecs = "OSSHObfuscatorSeedTransformSpecs"
  340. OSSHObfuscatorSeedTransformScopedSpecNames = "OSSHObfuscatorSeedTransformScopedSpecNames"
  341. OSSHObfuscatorSeedTransformProbability = "OSSHObfuscatorSeedTransformProbability"
  342. ObfuscatedQUICNonceTransformSpecs = "ObfuscatedQUICNonceTransformSpecs"
  343. ObfuscatedQUICNonceTransformScopedSpecNames = "ObfuscatedQUICNonceTransformScopedSpecNames"
  344. ObfuscatedQUICNonceTransformProbability = "ObfuscatedQUICNonceTransformProbability"
  345. OSSHPrefixSpecs = "OSSHPrefixSpecs"
  346. OSSHPrefixScopedSpecNames = "OSSHPrefixScopedSpecNames"
  347. OSSHPrefixProbability = "OSSHPrefixProbability"
  348. OSSHPrefixSplitMinDelay = "OSSHPrefixSplitMinDelay"
  349. OSSHPrefixSplitMaxDelay = "OSSHPrefixSplitMaxDelay"
  350. OSSHPrefixEnableFragmentor = "OSSHPrefixEnableFragmentor"
  351. ServerOSSHPrefixSpecs = "ServerOSSHPrefixSpecs"
  352. TLSTunnelTrafficShapingProbability = "TLSTunnelTrafficShapingProbability"
  353. TLSTunnelMinTLSPadding = "TLSTunnelMinTLSPadding"
  354. TLSTunnelMaxTLSPadding = "TLSTunnelMaxTLSPadding"
  355. TLSFragmentClientHelloProbability = "TLSFragmentClientHelloProbability"
  356. TLSFragmentClientHelloLimitProtocols = "TLSFragmentClientHelloLimitProtocols"
  357. SteeringIPCacheTTL = "SteeringIPCacheTTL"
  358. SteeringIPCacheMaxEntries = "SteeringIPCacheMaxEntries"
  359. SteeringIPProbability = "SteeringIPProbability"
  360. ServerDiscoveryStrategy = "ServerDiscoveryStrategy"
  361. InproxyAllowProxy = "InproxyAllowProxy"
  362. InproxyAllowClient = "InproxyAllowClient"
  363. InproxyAllowDomainFrontedDestinations = "InproxyAllowDomainFrontedDestinations"
  364. InproxyTunnelProtocolSelectionProbability = "InproxyTunnelProtocolSelectionProbability"
  365. InproxyAllBrokerPublicKeys = "InproxyAllBrokerPublicKeys"
  366. InproxyBrokerSpecs = "InproxyBrokerSpecs"
  367. InproxyProxyBrokerSpecs = "InproxyProxyBrokerSpecs"
  368. InproxyClientBrokerSpecs = "InproxyClientBrokerSpecs"
  369. InproxyReplayBrokerDialParametersTTL = "InproxyReplayBrokerDialParametersTTL"
  370. InproxyReplayBrokerUpdateFrequency = "InproxyReplayBrokerUpdateFrequency"
  371. InproxyReplayBrokerDialParametersProbability = "InproxyReplayBrokerDialParametersProbability"
  372. InproxyReplayBrokerRetainFailedProbability = "InproxyReplayBrokerRetainFailedProbability"
  373. InproxyAllCommonCompartmentIDs = "InproxyAllCommonCompartmentIDs"
  374. InproxyCommonCompartmentIDs = "InproxyCommonCompartmentIDs"
  375. InproxyMaxCompartmentIDListLength = "InproxyMaxCompartmentIDListLength"
  376. InproxyBrokerMatcherAnnouncementLimitEntryCount = "InproxyBrokerMatcherAnnouncementLimitEntryCount"
  377. InproxyBrokerMatcherAnnouncementRateLimitQuantity = "InproxyBrokerMatcherAnnouncementRateLimitQuantity"
  378. InproxyBrokerMatcherAnnouncementRateLimitInterval = "InproxyBrokerMatcherAnnouncementRateLimitInterval"
  379. InproxyBrokerMatcherAnnouncementNonlimitedProxyIDs = "InproxyBrokerMatcherAnnouncementNonlimitedProxyIDs"
  380. InproxyBrokerMatcherOfferLimitEntryCount = "InproxyBrokerMatcherOfferLimitEntryCount"
  381. InproxyBrokerMatcherOfferRateLimitQuantity = "InproxyBrokerMatcherOfferRateLimitQuantity"
  382. InproxyBrokerMatcherOfferRateLimitInterval = "InproxyBrokerMatcherOfferRateLimitInterval"
  383. InproxyBrokerProxyAnnounceTimeout = "InproxyBrokerProxyAnnounceTimeout"
  384. InproxyBrokerClientOfferTimeout = "InproxyBrokerClientOfferTimeout"
  385. InproxyBrokerPendingServerRequestsTTL = "InproxyBrokerPendingServerRequestsTTL"
  386. InproxySessionHandshakeRoundTripTimeout = "InproxySessionHandshakeRoundTripTimeout"
  387. InproxyProxyAnnounceRequestTimeout = "InproxyProxyAnnounceRequestTimeout"
  388. InproxyProxyAnnounceDelay = "InproxyProxyAnnounceDelay"
  389. InproxyProxyAnnounceDelayJitter = "InproxyProxyAnnounceDelayJitter"
  390. InproxyProxyAnswerRequestTimeout = "InproxyProxyAnswerRequestTimeout"
  391. InproxyClientOfferRequestTimeout = "InproxyClientOfferRequestTimeout"
  392. InproxyClientOfferRetryDelay = "InproxyClientOfferRetryDelay"
  393. InproxyClientOfferRetryJitter = "InproxyClientOfferRetryJitter"
  394. InproxyClientRelayedPacketRequestTimeout = "InproxyCloientRelayedPacketRequestTimeout"
  395. InproxyBrokerRoundTripStatusCodeFailureThreshold = "InproxyBrokerRoundTripStatusCodeFailureThreshold"
  396. InproxyDTLSRandomizationProbability = "InproxyDTLSRandomizationProbability"
  397. InproxyDataChannelTrafficShapingProbability = "InproxyDataChannelTrafficShapingProbability"
  398. InproxyDataChannelTrafficShapingParameters = "InproxyDataChannelTrafficShapingParameters"
  399. InproxySTUNServerAddresses = "InproxySTUNServerAddresses"
  400. InproxySTUNServerAddressesRFC5780 = "InproxySTUNServerAddressesRFC5780"
  401. InproxyProxySTUNServerAddresses = "InproxyProxySTUNServerAddresses"
  402. InproxyProxySTUNServerAddressesRFC5780 = "InproxyProxySTUNServerAddressesRFC5780"
  403. InproxyClientSTUNServerAddresses = "InproxyClientSTUNServerAddresses"
  404. InproxyClientSTUNServerAddressesRFC5780 = "InproxyClientSTUNServerAddressesRFC5780"
  405. InproxyClientDiscoverNATProbability = "InproxyClientDiscoverNATProbability"
  406. InproxyDisableSTUN = "InproxyDisableSTUN"
  407. InproxyDisablePortMapping = "InproxyDisablePortMapping"
  408. InproxyDisableInboundForMobileNetworks = "InproxyDisableInboundForMobileNetworks"
  409. InproxyDisableIPv6ICECandidates = "InproxyDisableIPv6ICECandidates"
  410. InproxyDiscoverNATTimeout = "InproxyDiscoverNATTimeout"
  411. InproxyWebRTCAnswerTimeout = "InproxyWebRTCAnswerTimeout"
  412. InproxyProxyWebRTCAwaitDataChannelTimeout = "InproxyProxyWebRTCAwaitDataChannelTimeout"
  413. InproxyClientWebRTCAwaitDataChannelTimeout = "InproxyClientWebRTCAwaitDataChannelTimeout"
  414. InproxyProxyDestinationDialTimeout = "InproxyProxyDestinationDialTimeout"
  415. InproxyPsiphonAPIRequestTimeout = "InproxyPsiphonAPIRequestTimeout"
  416. InproxyProxyTotalActivityNoticePeriod = "InproxyProxyTotalActivityNoticePeriod"
  417. // Retired parameters
  418. ReplayRandomizedTLSProfile = "ReplayRandomizedTLSProfile"
  419. )
  420. const (
  421. useNetworkLatencyMultiplier = 1
  422. serverSideOnly = 2
  423. )
  424. // defaultParameters specifies the type, default value, and minimum value for
  425. // all dynamically configurable client and server parameters.
  426. //
  427. // Do not change the names or types of existing values, as that can break
  428. // client logic or cause parameters to not be applied.
  429. //
  430. // Minimum values are a fail-safe for cases where lower values would break the
  431. // client logic. For example, setting a ConnectionWorkerPoolSize of 0 would
  432. // make the client never connect.
  433. var defaultParameters = map[string]struct {
  434. value interface{}
  435. minimum interface{}
  436. flags int32
  437. }{
  438. // NetworkLatencyMultiplier defaults to 0, meaning off. But when set, it
  439. // must be a multiplier >= 1.
  440. NetworkLatencyMultiplier: {value: 0.0, minimum: 1.0},
  441. NetworkLatencyMultiplierMin: {value: 1.0, minimum: 1.0},
  442. NetworkLatencyMultiplierMax: {value: 3.0, minimum: 1.0},
  443. NetworkLatencyMultiplierLambda: {value: 2.0, minimum: 0.001},
  444. TacticsWaitPeriod: {value: 10 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  445. TacticsRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  446. TacticsRetryPeriodJitter: {value: 0.3, minimum: 0.0},
  447. TacticsTimeout: {value: 2 * time.Minute, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  448. ConnectionWorkerPoolSize: {value: 10, minimum: 1},
  449. TunnelPoolSize: {value: 1, minimum: 1},
  450. TunnelConnectTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  451. EstablishTunnelTimeout: {value: 300 * time.Second, minimum: time.Duration(0)},
  452. EstablishTunnelWorkTime: {value: 60 * time.Second, minimum: 1 * time.Second},
  453. EstablishTunnelPausePeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  454. EstablishTunnelPausePeriodJitter: {value: 0.1, minimum: 0.0},
  455. EstablishTunnelServerAffinityGracePeriod: {value: 1 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  456. StaggerConnectionWorkersPeriod: {value: time.Duration(0), minimum: time.Duration(0)},
  457. StaggerConnectionWorkersJitter: {value: 0.1, minimum: 0.0},
  458. LimitIntensiveConnectionWorkers: {value: 0, minimum: 0},
  459. UpstreamProxyErrorMinWaitDuration: {value: 10 * time.Second, minimum: time.Duration(0)},
  460. UpstreamProxyErrorMaxWaitDuration: {value: 30 * time.Second, minimum: time.Duration(0)},
  461. IgnoreHandshakeStatsRegexps: {value: false},
  462. TunnelOperateShutdownTimeout: {value: 1 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  463. TunnelPortForwardDialTimeout: {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  464. PacketTunnelReadTimeout: {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  465. TunnelRateLimits: {value: common.RateLimits{}},
  466. // PrioritizeTunnelProtocols parameters are obsoleted by InitialLimitTunnelProtocols.
  467. // TODO: remove once no longer required for older clients.
  468. PrioritizeTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  469. PrioritizeTunnelProtocols: {value: protocol.TunnelProtocols{}},
  470. PrioritizeTunnelProtocolsCandidateCount: {value: 10, minimum: 0},
  471. InitialLimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  472. InitialLimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  473. InitialLimitTunnelProtocolsCandidateCount: {value: 0, minimum: 0},
  474. LimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  475. LimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  476. LimitTunnelDialPortNumbersProbability: {value: 1.0, minimum: 0.0},
  477. LimitTunnelDialPortNumbers: {value: TunnelProtocolPortLists{}},
  478. LimitTLSProfilesProbability: {value: 1.0, minimum: 0.0},
  479. LimitTLSProfiles: {value: protocol.TLSProfiles{}},
  480. UseOnlyCustomTLSProfiles: {value: false},
  481. CustomTLSProfiles: {value: protocol.CustomTLSProfiles{}},
  482. SelectRandomizedTLSProfileProbability: {value: 0.25, minimum: 0.0},
  483. NoDefaultTLSSessionIDProbability: {value: 0.5, minimum: 0.0},
  484. DisableFrontingProviderTLSProfiles: {value: protocol.LabeledTLSProfiles{}},
  485. LimitQUICVersionsProbability: {value: 1.0, minimum: 0.0},
  486. LimitQUICVersions: {value: protocol.QUICVersions{}},
  487. DisableFrontingProviderQUICVersions: {value: protocol.LabeledQUICVersions{}},
  488. QUICDisableClientPathMTUDiscoveryProbability: {value: 0.0, minimum: 0.0},
  489. FragmentorProbability: {value: 0.5, minimum: 0.0},
  490. FragmentorLimitProtocols: {value: protocol.TunnelProtocols{}},
  491. FragmentorMinTotalBytes: {value: 0, minimum: 0},
  492. FragmentorMaxTotalBytes: {value: 0, minimum: 0},
  493. FragmentorMinWriteBytes: {value: 1, minimum: 1},
  494. FragmentorMaxWriteBytes: {value: 1500, minimum: 1},
  495. FragmentorMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  496. FragmentorMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0)},
  497. FragmentorDownstreamProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  498. FragmentorDownstreamLimitProtocols: {value: protocol.TunnelProtocols{}, flags: serverSideOnly},
  499. FragmentorDownstreamMinTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  500. FragmentorDownstreamMaxTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  501. FragmentorDownstreamMinWriteBytes: {value: 1, minimum: 1, flags: serverSideOnly},
  502. FragmentorDownstreamMaxWriteBytes: {value: 1500, minimum: 1, flags: serverSideOnly},
  503. FragmentorDownstreamMinDelay: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  504. FragmentorDownstreamMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0), flags: serverSideOnly},
  505. // The Psiphon server will reject obfuscated SSH seed messages with
  506. // padding greater than OBFUSCATE_MAX_PADDING.
  507. // obfuscator.NewClientObfuscator will ignore invalid min/max padding
  508. // configurations.
  509. ObfuscatedSSHMinPadding: {value: 0, minimum: 0},
  510. ObfuscatedSSHMaxPadding: {value: obfuscator.OBFUSCATE_MAX_PADDING, minimum: 0},
  511. AdditionalCustomHeaders: {value: make(http.Header)},
  512. // Speed test and SSH keep alive padding is intended to frustrate
  513. // fingerprinting and should not exceed ~1 IP packet size.
  514. //
  515. // Currently, each serialized speed test sample, populated with real
  516. // values, is approximately 100 bytes. All SpeedTestMaxSampleCount samples
  517. // are loaded into memory are sent as API inputs.
  518. SpeedTestPaddingMinBytes: {value: 0, minimum: 0},
  519. SpeedTestPaddingMaxBytes: {value: 256, minimum: 0},
  520. SpeedTestMaxSampleCount: {value: 5, minimum: 1},
  521. // The Psiphon server times out inactive tunnels after 5 minutes, so this
  522. // is a soft max for SSHKeepAlivePeriodMax.
  523. SSHKeepAliveSpeedTestSampleProbability: {value: 0.5, minimum: 0.0},
  524. SSHKeepAlivePaddingMinBytes: {value: 0, minimum: 0},
  525. SSHKeepAlivePaddingMaxBytes: {value: 256, minimum: 0},
  526. SSHKeepAlivePeriodMin: {value: 1 * time.Minute, minimum: 1 * time.Second},
  527. SSHKeepAlivePeriodMax: {value: 2 * time.Minute, minimum: 1 * time.Second},
  528. SSHKeepAlivePeriodicTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  529. SSHKeepAlivePeriodicInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  530. SSHKeepAliveProbeTimeout: {value: 5 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  531. SSHKeepAliveProbeInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  532. SSHKeepAliveNetworkConnectivityPollingPeriod: {value: 500 * time.Millisecond, minimum: 1 * time.Millisecond},
  533. SSHKeepAliveResetOnFailureProbability: {value: 0.0, minimum: 0.0},
  534. HTTPProxyOriginServerTimeout: {value: 15 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  535. HTTPProxyMaxIdleConnectionsPerHost: {value: 50, minimum: 0},
  536. FetchRemoteServerListTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  537. FetchRemoteServerListRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  538. FetchRemoteServerListStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  539. RemoteServerListSignaturePublicKey: {value: ""},
  540. RemoteServerListURLs: {value: TransferURLs{}},
  541. ObfuscatedServerListRootURLs: {value: TransferURLs{}},
  542. PsiphonAPIRequestTimeout: {value: 10 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  543. PsiphonAPIStatusRequestPeriodMin: {value: 5 * time.Minute, minimum: 1 * time.Second},
  544. PsiphonAPIStatusRequestPeriodMax: {value: 10 * time.Minute, minimum: 1 * time.Second},
  545. PsiphonAPIStatusRequestShortPeriodMin: {value: 5 * time.Second, minimum: 1 * time.Second},
  546. PsiphonAPIStatusRequestShortPeriodMax: {value: 10 * time.Second, minimum: 1 * time.Second},
  547. // PsiphonAPIPersistentStatsMaxCount parameter is obsoleted by PersistentStatsMaxSendBytes.
  548. // TODO: remove once no longer required for older clients.
  549. PsiphonAPIPersistentStatsMaxCount: {value: 100, minimum: 1},
  550. // PsiphonAPIStatusRequestPadding parameters are obsoleted by APIRequestUp/DownstreamPadding.
  551. // TODO: remove once no longer required for older clients.
  552. PsiphonAPIStatusRequestPaddingMinBytes: {value: 0, minimum: 0},
  553. PsiphonAPIStatusRequestPaddingMaxBytes: {value: 256, minimum: 0},
  554. PsiphonAPIConnectedRequestRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  555. // FetchSplitTunnelRoutesTimeout, SplitTunnelRoutesURLFormat,
  556. // SplitTunnelRoutesSignaturePublicKey and SplitTunnelDNSServer are obsoleted
  557. // by the server-assisted split tunnel implementation.
  558. // TODO: remove once no longer required for older clients.
  559. FetchSplitTunnelRoutesTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  560. SplitTunnelRoutesURLFormat: {value: ""},
  561. SplitTunnelRoutesSignaturePublicKey: {value: ""},
  562. SplitTunnelDNSServer: {value: ""},
  563. SplitTunnelClassificationTTL: {value: 24 * time.Hour, minimum: 0 * time.Second},
  564. SplitTunnelClassificationMaxEntries: {value: 65536, minimum: 0},
  565. FetchUpgradeTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  566. FetchUpgradeRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  567. FetchUpgradeStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  568. UpgradeDownloadURLs: {value: TransferURLs{}},
  569. UpgradeDownloadClientVersionHeader: {value: ""},
  570. TotalBytesTransferredNoticePeriod: {value: 5 * time.Minute, minimum: 1 * time.Second},
  571. TotalBytesTransferredEmitMemoryMetrics: {value: true},
  572. // The meek server times out inactive sessions after 45 seconds, so this
  573. // is a soft max for MeekMaxPollInterval, MeekRoundTripTimeout, and
  574. // MeekRoundTripRetryDeadline.
  575. //
  576. // MeekCookieMaxPadding cannot exceed common.OBFUSCATE_SEED_LENGTH.
  577. //
  578. // MeekMinTLSPadding/MeekMaxTLSPadding are subject to TLS server limitations.
  579. //
  580. // MeekMinLimitRequestPayloadLength/MeekMaxLimitRequestPayloadLength
  581. // cannot exceed server.MEEK_MAX_REQUEST_PAYLOAD_LENGTH.
  582. MeekDialDomainsOnly: {value: false},
  583. MeekLimitBufferSizes: {value: false},
  584. MeekCookieMaxPadding: {value: 256, minimum: 0},
  585. MeekFullReceiveBufferLength: {value: 4194304, minimum: 1024},
  586. MeekReadPayloadChunkLength: {value: 65536, minimum: 1024},
  587. MeekLimitedFullReceiveBufferLength: {value: 131072, minimum: 1024},
  588. MeekLimitedReadPayloadChunkLength: {value: 4096, minimum: 1024},
  589. MeekMinPollInterval: {value: 100 * time.Millisecond, minimum: 1 * time.Millisecond},
  590. MeekMinPollIntervalJitter: {value: 0.3, minimum: 0.0},
  591. MeekMaxPollInterval: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  592. MeekMaxPollIntervalJitter: {value: 0.1, minimum: 0.0},
  593. MeekPollIntervalMultiplier: {value: 1.5, minimum: 0.0},
  594. MeekPollIntervalJitter: {value: 0.1, minimum: 0.0},
  595. MeekApplyPollIntervalMultiplierProbability: {value: 0.5},
  596. MeekRoundTripRetryDeadline: {value: 5 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  597. MeekRoundTripRetryMinDelay: {value: 50 * time.Millisecond, minimum: time.Duration(0)},
  598. MeekRoundTripRetryMaxDelay: {value: 1 * time.Second, minimum: time.Duration(0)},
  599. MeekRoundTripRetryMultiplier: {value: 2.0, minimum: 0.0},
  600. MeekRoundTripTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  601. MeekTrafficShapingProbability: {value: 1.0, minimum: 0.0},
  602. MeekTrafficShapingLimitProtocols: {value: protocol.TunnelProtocols{}},
  603. MeekMinTLSPadding: {value: 0, minimum: 0},
  604. MeekMaxTLSPadding: {value: 0, minimum: 0},
  605. MeekMinLimitRequestPayloadLength: {value: 65536, minimum: 1},
  606. MeekMaxLimitRequestPayloadLength: {value: 65536, minimum: 1},
  607. MeekRedialTLSProbability: {value: 0.0, minimum: 0.0},
  608. MeekAlternateCookieNameProbability: {value: 0.5, minimum: 0.0},
  609. MeekAlternateContentTypeProbability: {value: 0.5, minimum: 0.0},
  610. TransformHostNameProbability: {value: 0.5, minimum: 0.0},
  611. PickUserAgentProbability: {value: 0.5, minimum: 0.0},
  612. LivenessTestMinUpstreamBytes: {value: 0, minimum: 0},
  613. LivenessTestMaxUpstreamBytes: {value: 0, minimum: 0},
  614. LivenessTestMinDownstreamBytes: {value: 0, minimum: 0},
  615. LivenessTestMaxDownstreamBytes: {value: 0, minimum: 0},
  616. ReplayCandidateCount: {value: 10, minimum: -1},
  617. ReplayDialParametersTTL: {value: 24 * time.Hour, minimum: time.Duration(0)},
  618. ReplayTargetUpstreamBytes: {value: 0, minimum: 0},
  619. ReplayTargetDownstreamBytes: {value: 0, minimum: 0},
  620. ReplayTargetTunnelDuration: {value: 1 * time.Second, minimum: time.Duration(0)},
  621. ReplayLaterRoundMoveToFrontProbability: {value: 0.0, minimum: 0.0},
  622. ReplayRetainFailedProbability: {value: 0.5, minimum: 0.0},
  623. ReplayIgnoreChangedConfigState: {value: false},
  624. ReplayBPF: {value: true},
  625. ReplaySSH: {value: true},
  626. ReplayObfuscatorPadding: {value: true},
  627. ReplayFragmentor: {value: true},
  628. ReplayTLSProfile: {value: true},
  629. ReplayFronting: {value: true},
  630. ReplayHostname: {value: true},
  631. ReplayQUICVersion: {value: true},
  632. ReplayObfuscatedQUIC: {value: true},
  633. ReplayObfuscatedQUICNonceTransformer: {value: true},
  634. ReplayConjureRegistration: {value: true},
  635. ReplayConjureTransport: {value: true},
  636. ReplayLivenessTest: {value: true},
  637. ReplayUserAgent: {value: true},
  638. ReplayAPIRequestPadding: {value: true},
  639. ReplayHoldOffTunnel: {value: true},
  640. ReplayResolveParameters: {value: true},
  641. ReplayHTTPTransformerParameters: {value: true},
  642. ReplayOSSHSeedTransformerParameters: {value: true},
  643. ReplayOSSHPrefix: {value: true},
  644. ReplayTLSFragmentClientHello: {value: true},
  645. ReplayInproxyWebRTC: {value: true},
  646. ReplayInproxySTUN: {value: true},
  647. APIRequestUpstreamPaddingMinBytes: {value: 0, minimum: 0},
  648. APIRequestUpstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  649. APIRequestDownstreamPaddingMinBytes: {value: 0, minimum: 0},
  650. APIRequestDownstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  651. PersistentStatsMaxStoreRecords: {value: 200, minimum: 1},
  652. PersistentStatsMaxSendBytes: {value: 65536, minimum: 1},
  653. RecordRemoteServerListPersistentStatsProbability: {value: 1.0, minimum: 0.0},
  654. RecordFailedTunnelPersistentStatsProbability: {value: 0.0, minimum: 0.0},
  655. ServerEntryMinimumAgeForPruning: {value: 7 * 24 * time.Hour, minimum: 24 * time.Hour},
  656. ApplicationParametersProbability: {value: 1.0, minimum: 0.0},
  657. ApplicationParameters: {value: KeyValues{}},
  658. BPFServerTCPProgram: {value: (*BPFProgramSpec)(nil), flags: serverSideOnly},
  659. BPFServerTCPProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  660. BPFClientTCPProgram: {value: (*BPFProgramSpec)(nil)},
  661. BPFClientTCPProbability: {value: 0.5, minimum: 0.0},
  662. ServerPacketManipulationSpecs: {value: PacketManipulationSpecs{}, flags: serverSideOnly},
  663. ServerProtocolPacketManipulations: {value: make(ProtocolPacketManipulations), flags: serverSideOnly},
  664. ServerPacketManipulationProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  665. FeedbackUploadURLs: {value: TransferURLs{}},
  666. FeedbackEncryptionPublicKey: {value: ""},
  667. FeedbackTacticsWaitPeriod: {value: 5 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  668. FeedbackUploadMaxAttempts: {value: 5, minimum: 0},
  669. // TODO: rename -- remove "Seconds" suffix
  670. FeedbackUploadRetryMinDelaySeconds: {value: 1 * time.Minute, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  671. FeedbackUploadRetryMaxDelaySeconds: {value: 5 * time.Minute, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  672. FeedbackUploadTimeoutSeconds: {value: 30 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  673. ServerReplayPacketManipulation: {value: true, flags: serverSideOnly},
  674. ServerReplayFragmentor: {value: true, flags: serverSideOnly},
  675. ServerReplayUnknownGeoIP: {value: false, flags: serverSideOnly},
  676. ServerReplayTTL: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  677. ServerReplayTargetWaitDuration: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  678. ServerReplayTargetTunnelDuration: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  679. ServerReplayTargetUpstreamBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  680. ServerReplayTargetDownstreamBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  681. ServerReplayFailedCountThreshold: {value: 0, minimum: 0, flags: serverSideOnly},
  682. ServerBurstUpstreamTargetBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  683. ServerBurstUpstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  684. ServerBurstDownstreamTargetBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  685. ServerBurstDownstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  686. ClientBurstUpstreamTargetBytes: {value: 0, minimum: 0},
  687. ClientBurstUpstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0)},
  688. ClientBurstDownstreamTargetBytes: {value: 0, minimum: 0},
  689. ClientBurstDownstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0)},
  690. ConjureCachedRegistrationTTL: {value: time.Duration(0), minimum: time.Duration(0)},
  691. // ConjureAPIRegistrarURL parameter is obsoleted by ConjureAPIRegistrarBidirectionalURL.
  692. // TODO: remove once no longer required for older clients.
  693. ConjureAPIRegistrarURL: {value: ""},
  694. ConjureAPIRegistrarBidirectionalURL: {value: ""},
  695. ConjureAPIRegistrarFrontingSpecs: {value: FrontingSpecs{}},
  696. ConjureAPIRegistrarMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  697. ConjureAPIRegistrarMaxDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  698. ConjureDecoyRegistrarProbability: {value: 0.0, minimum: 0.0},
  699. ConjureDecoyRegistrarWidth: {value: 5, minimum: 0},
  700. ConjureDecoyRegistrarMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  701. ConjureDecoyRegistrarMaxDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  702. ConjureEnableIPv6Dials: {value: true},
  703. ConjureEnablePortRandomization: {value: true},
  704. ConjureEnableRegistrationOverrides: {value: false},
  705. ConjureLimitTransportsProbability: {value: 1.0, minimum: 0.0},
  706. ConjureLimitTransports: {value: protocol.ConjureTransports{}},
  707. ConjureSTUNServerAddresses: {value: []string{}},
  708. ConjureDTLSEmptyInitialPacketProbability: {value: 0.0, minimum: 0.0},
  709. CustomHostNameRegexes: {value: RegexStrings{}},
  710. CustomHostNameProbability: {value: 0.0, minimum: 0.0},
  711. CustomHostNameLimitProtocols: {value: protocol.TunnelProtocols{}},
  712. HoldOffTunnelMinDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  713. HoldOffTunnelMaxDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  714. HoldOffTunnelProtocols: {value: protocol.TunnelProtocols{}},
  715. HoldOffTunnelFrontingProviderIDs: {value: []string{}},
  716. HoldOffTunnelProbability: {value: 0.0, minimum: 0.0},
  717. RestrictFrontingProviderIDs: {value: []string{}},
  718. RestrictFrontingProviderIDsServerProbability: {value: 0.0, minimum: 0.0, flags: serverSideOnly},
  719. RestrictFrontingProviderIDsClientProbability: {value: 0.0, minimum: 0.0},
  720. HoldOffDirectTunnelMinDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  721. HoldOffDirectTunnelMaxDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  722. HoldOffDirectTunnelProviderRegions: {value: KeyStrings{}},
  723. HoldOffDirectTunnelProbability: {value: 0.0, minimum: 0.0},
  724. RestrictDirectProviderRegions: {value: KeyStrings{}},
  725. RestrictDirectProviderIDsServerProbability: {value: 0.0, minimum: 0.0, flags: serverSideOnly},
  726. RestrictDirectProviderIDsClientProbability: {value: 0.0, minimum: 0.0},
  727. UpstreamProxyAllowAllServerEntrySources: {value: false},
  728. DestinationBytesMetricsASN: {value: "", flags: serverSideOnly},
  729. DNSResolverAttemptsPerServer: {value: 2, minimum: 1},
  730. DNSResolverAttemptsPerPreferredServer: {value: 1, minimum: 1},
  731. DNSResolverRequestTimeout: {value: 5 * time.Second, minimum: 100 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  732. DNSResolverAwaitTimeout: {value: 10 * time.Millisecond, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  733. DNSResolverPreresolvedIPAddressCIDRs: {value: LabeledCIDRs{}},
  734. DNSResolverPreresolvedIPAddressProbability: {value: 0.0, minimum: 0.0},
  735. DNSResolverAlternateServers: {value: []string{}},
  736. DNSResolverPreferredAlternateServers: {value: []string{}},
  737. DNSResolverPreferAlternateServerProbability: {value: 0.0, minimum: 0.0},
  738. DNSResolverProtocolTransformSpecs: {value: transforms.Specs{}},
  739. DNSResolverProtocolTransformScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  740. DNSResolverProtocolTransformProbability: {value: 0.0, minimum: 0.0},
  741. DNSResolverIncludeEDNS0Probability: {value: 0.0, minimum: 0.0},
  742. DNSResolverCacheExtensionInitialTTL: {value: time.Duration(0), minimum: time.Duration(0)},
  743. DNSResolverCacheExtensionVerifiedTTL: {value: time.Duration(0), minimum: time.Duration(0)},
  744. AddFrontingProviderPsiphonFrontingHeader: {value: protocol.LabeledTunnelProtocols{}},
  745. DirectHTTPProtocolTransformSpecs: {value: transforms.Specs{}},
  746. DirectHTTPProtocolTransformScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  747. DirectHTTPProtocolTransformProbability: {value: 0.0, minimum: 0.0},
  748. FrontedHTTPProtocolTransformSpecs: {value: transforms.Specs{}},
  749. FrontedHTTPProtocolTransformScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  750. FrontedHTTPProtocolTransformProbability: {value: 0.0, minimum: 0.0},
  751. OSSHObfuscatorSeedTransformSpecs: {value: transforms.Specs{}},
  752. OSSHObfuscatorSeedTransformScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  753. OSSHObfuscatorSeedTransformProbability: {value: 0.0, minimum: 0.0},
  754. ObfuscatedQUICNonceTransformSpecs: {value: transforms.Specs{}},
  755. ObfuscatedQUICNonceTransformScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  756. ObfuscatedQUICNonceTransformProbability: {value: 0.0, minimum: 0.0},
  757. OSSHPrefixSpecs: {value: transforms.Specs{}},
  758. OSSHPrefixScopedSpecNames: {value: transforms.ScopedSpecNames{}},
  759. OSSHPrefixProbability: {value: 0.0, minimum: 0.0},
  760. OSSHPrefixSplitMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  761. OSSHPrefixSplitMaxDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  762. OSSHPrefixEnableFragmentor: {value: false},
  763. ServerOSSHPrefixSpecs: {value: transforms.Specs{}, flags: serverSideOnly},
  764. // TLSTunnelMinTLSPadding/TLSTunnelMaxTLSPadding are subject to TLS server limitations.
  765. TLSTunnelTrafficShapingProbability: {value: 1.0, minimum: 0.0},
  766. TLSTunnelMinTLSPadding: {value: 0, minimum: 0},
  767. TLSTunnelMaxTLSPadding: {value: 0, minimum: 0},
  768. TLSFragmentClientHelloProbability: {value: 0.0, minimum: 0.0},
  769. TLSFragmentClientHelloLimitProtocols: {value: protocol.TunnelProtocols{}},
  770. SteeringIPCacheTTL: {value: 1 * time.Hour, minimum: time.Duration(0)},
  771. SteeringIPCacheMaxEntries: {value: 65536, minimum: 0},
  772. SteeringIPProbability: {value: 1.0, minimum: 0.0},
  773. ServerDiscoveryStrategy: {value: "", flags: serverSideOnly},
  774. // For inproxy tactics, there is no proxyOnly flag, since Psiphon apps may
  775. // run both clients and inproxy proxies.
  776. //
  777. // Note: useNetworkLatencyMultiplier is not applied to request timeouts
  778. // since timeouts are strictly enforced on the broker server-side.
  779. InproxyAllowProxy: {value: false},
  780. InproxyAllowClient: {value: false, flags: serverSideOnly},
  781. InproxyAllowDomainFrontedDestinations: {value: false, flags: serverSideOnly},
  782. InproxyTunnelProtocolSelectionProbability: {value: 0.5, minimum: 0.0},
  783. InproxyAllBrokerPublicKeys: {value: []string{}, flags: serverSideOnly},
  784. InproxyBrokerSpecs: {value: InproxyBrokerSpecsValue{}},
  785. InproxyProxyBrokerSpecs: {value: InproxyBrokerSpecsValue{}},
  786. InproxyClientBrokerSpecs: {value: InproxyBrokerSpecsValue{}},
  787. InproxyReplayBrokerDialParametersTTL: {value: 24 * time.Hour, minimum: time.Duration(0)},
  788. InproxyReplayBrokerUpdateFrequency: {value: 5 * time.Minute, minimum: time.Duration(0)},
  789. InproxyReplayBrokerDialParametersProbability: {value: 1.0, minimum: 0.0},
  790. InproxyReplayBrokerRetainFailedProbability: {value: 0.5, minimum: 0.0},
  791. InproxyAllCommonCompartmentIDs: {value: []string{}, flags: serverSideOnly},
  792. InproxyCommonCompartmentIDs: {value: InproxyCompartmentIDsValue{}},
  793. InproxyMaxCompartmentIDListLength: {value: 50, minimum: 0},
  794. InproxyBrokerMatcherAnnouncementLimitEntryCount: {value: 50, minimum: 0, flags: serverSideOnly},
  795. InproxyBrokerMatcherAnnouncementRateLimitQuantity: {value: 50, minimum: 0, flags: serverSideOnly},
  796. InproxyBrokerMatcherAnnouncementRateLimitInterval: {value: 1 * time.Minute, minimum: time.Duration(0), flags: serverSideOnly},
  797. InproxyBrokerMatcherAnnouncementNonlimitedProxyIDs: {value: []string{}, flags: serverSideOnly},
  798. InproxyBrokerMatcherOfferLimitEntryCount: {value: 10, minimum: 0, flags: serverSideOnly},
  799. InproxyBrokerMatcherOfferRateLimitQuantity: {value: 50, minimum: 0, flags: serverSideOnly},
  800. InproxyBrokerMatcherOfferRateLimitInterval: {value: 1 * time.Minute, minimum: time.Duration(0)},
  801. InproxyBrokerProxyAnnounceTimeout: {value: 2 * time.Minute, minimum: time.Duration(0), flags: serverSideOnly},
  802. InproxyBrokerClientOfferTimeout: {value: 10 * time.Second, minimum: time.Duration(0), flags: serverSideOnly},
  803. InproxyBrokerPendingServerRequestsTTL: {value: 60 * time.Second, minimum: time.Duration(0), flags: serverSideOnly},
  804. InproxySessionHandshakeRoundTripTimeout: {value: 10 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  805. InproxyProxyAnnounceRequestTimeout: {value: 2*time.Minute + 10*time.Second, minimum: time.Duration(0)},
  806. InproxyProxyAnnounceDelay: {value: 100 * time.Millisecond, minimum: time.Duration(0)},
  807. InproxyProxyAnnounceDelayJitter: {value: 0.5, minimum: 0.0},
  808. InproxyProxyAnswerRequestTimeout: {value: 10*time.Second + 10*time.Second, minimum: time.Duration(0)},
  809. InproxyClientOfferRequestTimeout: {value: 10*time.Second + 10*time.Second, minimum: time.Duration(0)},
  810. InproxyClientOfferRetryDelay: {value: 100 * time.Millisecond, minimum: time.Duration(0)},
  811. InproxyClientOfferRetryJitter: {value: 0.5, minimum: 0.0},
  812. InproxyClientRelayedPacketRequestTimeout: {value: 10 * time.Second, minimum: time.Duration(0)},
  813. InproxyBrokerRoundTripStatusCodeFailureThreshold: {value: 2 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  814. InproxyDTLSRandomizationProbability: {value: 0.5, minimum: 0.0},
  815. InproxyDataChannelTrafficShapingProbability: {value: 0.5, minimum: 0.0},
  816. InproxyDataChannelTrafficShapingParameters: {value: InproxyDataChannelTrafficShapingParametersValue{0, 10, 0, 1500, 0, 10, 1, 1500, 0.5}},
  817. InproxySTUNServerAddresses: {value: []string{}},
  818. InproxySTUNServerAddressesRFC5780: {value: []string{}},
  819. InproxyProxySTUNServerAddresses: {value: []string{}},
  820. InproxyProxySTUNServerAddressesRFC5780: {value: []string{}},
  821. InproxyClientSTUNServerAddresses: {value: []string{}},
  822. InproxyClientSTUNServerAddressesRFC5780: {value: []string{}},
  823. InproxyClientDiscoverNATProbability: {value: 0.0, minimum: 0.0},
  824. InproxyDisableSTUN: {value: false},
  825. InproxyDisablePortMapping: {value: false},
  826. InproxyDisableInboundForMobileNetworks: {value: false},
  827. InproxyDisableIPv6ICECandidates: {value: false},
  828. InproxyDiscoverNATTimeout: {value: 10 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  829. InproxyWebRTCAnswerTimeout: {value: 20 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  830. InproxyProxyWebRTCAwaitDataChannelTimeout: {value: 30 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  831. InproxyClientWebRTCAwaitDataChannelTimeout: {value: 20 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  832. InproxyProxyDestinationDialTimeout: {value: 20 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  833. InproxyPsiphonAPIRequestTimeout: {value: 10 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  834. InproxyProxyTotalActivityNoticePeriod: {value: 5 * time.Minute, minimum: 1 * time.Second},
  835. }
  836. // IsServerSideOnly indicates if the parameter specified by name is used
  837. // server-side only.
  838. func IsServerSideOnly(name string) bool {
  839. defaultParameter, ok := defaultParameters[name]
  840. return ok && (defaultParameter.flags&serverSideOnly) != 0
  841. }
  842. // Parameters is a set of parameters. To use the parameters, call Get. To
  843. // apply new values to the parameters, call Set.
  844. type Parameters struct {
  845. getValueLogger func(error)
  846. snapshot atomic.Value
  847. }
  848. // NewParameters initializes a new Parameters with the default parameter
  849. // values.
  850. //
  851. // getValueLogger is optional, and is used to report runtime errors with
  852. // getValue; see comment in getValue.
  853. func NewParameters(
  854. getValueLogger func(error)) (*Parameters, error) {
  855. parameters := &Parameters{
  856. getValueLogger: getValueLogger,
  857. }
  858. // Note: validationFlags excludes ValidationServerSide, so the
  859. // Parameters.Set checkInproxyLists logic is not invoked; however, all
  860. // the relevent lists currently default to empty values.
  861. _, err := parameters.Set("", 0)
  862. if err != nil {
  863. return nil, errors.Trace(err)
  864. }
  865. return parameters, nil
  866. }
  867. func makeDefaultParameters() (map[string]interface{}, error) {
  868. parameters := make(map[string]interface{})
  869. for name, defaults := range defaultParameters {
  870. if defaults.value == nil {
  871. return nil, errors.Tracef("default parameter missing value: %s", name)
  872. }
  873. if defaults.minimum != nil &&
  874. reflect.TypeOf(defaults.value) != reflect.TypeOf(defaults.minimum) {
  875. return nil, errors.Tracef("default parameter value and minimum type mismatch: %s", name)
  876. }
  877. _, isDuration := defaults.value.(time.Duration)
  878. if defaults.flags&useNetworkLatencyMultiplier != 0 && !isDuration {
  879. return nil, errors.Tracef("default non-duration parameter uses multipler: %s", name)
  880. }
  881. parameters[name] = defaults.value
  882. }
  883. return parameters, nil
  884. }
  885. const (
  886. // ValidationSkipOnError indicates whether invalid tactics are to be
  887. // skipped/omitted, or if Set should fail on invalid tactics. In some
  888. // cases, clients set ValidationSkipOnError as older client code may
  889. // download newer tactics which do not validate; while servers perform
  890. // strict validation.
  891. ValidationSkipOnError = 1
  892. // ValidationServerSide indicates whether the validation is server-side,
  893. // in which case additonal checks referencing serverSideOnly parameters
  894. // are performed.
  895. ValidationServerSide = 2
  896. )
  897. // Set replaces the current parameters. First, a set of parameters are
  898. // initialized using the default values. Then, each applyParameters is applied
  899. // in turn, with the later instances having precedence.
  900. //
  901. // When skipOnError is true, unknown or invalid parameters in any
  902. // applyParameters are skipped instead of aborting with an error.
  903. //
  904. // For protocol.TunnelProtocols and protocol.TLSProfiles type values, when
  905. // skipOnError is true the values are filtered instead of validated, so
  906. // only known tunnel protocols and TLS profiles are retained.
  907. //
  908. // When an error is returned, the previous parameters remain completely
  909. // unmodified.
  910. //
  911. // For use in logging, Set returns a count of the number of parameters applied
  912. // from each applyParameters.
  913. func (p *Parameters) Set(
  914. tag string,
  915. validationFlags int,
  916. applyParameters ...map[string]interface{}) ([]int, error) {
  917. skipOnError := (validationFlags & ValidationSkipOnError) != 0
  918. serverSide := (validationFlags & ValidationServerSide) != 0
  919. makeTypedValue := func(templateValue, value interface{}) (interface{}, error) {
  920. // Accept strings such as "1h" for duration parameters.
  921. switch templateValue.(type) {
  922. case time.Duration:
  923. if s, ok := value.(string); ok {
  924. if d, err := time.ParseDuration(s); err == nil {
  925. value = d
  926. }
  927. }
  928. }
  929. // A JSON remarshal resolves cases where applyParameters is a
  930. // result of unmarshal-into-interface, in which case non-scalar
  931. // values will not have the expected types; see:
  932. // https://golang.org/pkg/encoding/json/#Unmarshal. This remarshal
  933. // also results in a deep copy.
  934. marshaledValue, err := json.Marshal(value)
  935. if err != nil {
  936. return nil, errors.Trace(err)
  937. }
  938. newValuePtr := reflect.New(reflect.TypeOf(templateValue))
  939. err = json.Unmarshal(marshaledValue, newValuePtr.Interface())
  940. if err != nil {
  941. return nil, errors.Trace(err)
  942. }
  943. return newValuePtr.Elem().Interface(), nil
  944. }
  945. getAppliedValue := func(
  946. name string,
  947. parameters map[string]interface{},
  948. applyParameters []map[string]interface{}) (interface{}, error) {
  949. templateValue := parameters[name]
  950. if templateValue == nil {
  951. return nil, errors.Tracef("unknown parameter: %s", name)
  952. }
  953. value := templateValue
  954. for i := len(applyParameters) - 1; i >= 0; i-- {
  955. if v := applyParameters[i][name]; v != nil {
  956. value = v
  957. break
  958. }
  959. }
  960. return makeTypedValue(templateValue, value)
  961. }
  962. var counts []int
  963. parameters, err := makeDefaultParameters()
  964. if err != nil {
  965. return nil, errors.Trace(err)
  966. }
  967. // Special case: TLSProfiles/LabeledTLSProfiles may reference
  968. // CustomTLSProfiles names. Inspect the CustomTLSProfiles parameter and
  969. // extract its names. Do not call Get().CustomTLSProfilesNames() as
  970. // CustomTLSProfiles may not yet be validated.
  971. customTLSProfilesValue, err := getAppliedValue(
  972. CustomTLSProfiles, parameters, applyParameters)
  973. if err != nil {
  974. return nil, errors.Trace(err)
  975. }
  976. customTLSProfiles, _ := customTLSProfilesValue.(protocol.CustomTLSProfiles)
  977. customTLSProfileNames := make([]string, len(customTLSProfiles))
  978. for i, profile := range customTLSProfiles {
  979. customTLSProfileNames[i] = profile.Name
  980. }
  981. // Special case: PacketManipulations will reference PacketManipulationSpecs.
  982. serverPacketManipulationSpecsValue, err := getAppliedValue(
  983. ServerPacketManipulationSpecs, parameters, applyParameters)
  984. if err != nil {
  985. return nil, errors.Trace(err)
  986. }
  987. serverPacketManipulationSpecs, _ :=
  988. serverPacketManipulationSpecsValue.(PacketManipulationSpecs)
  989. // Special case: ProtocolTransformScopedSpecNames will reference
  990. // ProtocolTransformSpecs.
  991. dnsResolverProtocolTransformSpecsValue, err := getAppliedValue(
  992. DNSResolverProtocolTransformSpecs, parameters, applyParameters)
  993. if err != nil {
  994. return nil, errors.Trace(err)
  995. }
  996. dnsResolverProtocolTransformSpecs, _ :=
  997. dnsResolverProtocolTransformSpecsValue.(transforms.Specs)
  998. directHttpProtocolTransformSpecsValue, err := getAppliedValue(
  999. DirectHTTPProtocolTransformSpecs, parameters, applyParameters)
  1000. if err != nil {
  1001. return nil, errors.Trace(err)
  1002. }
  1003. directHttpProtocolTransformSpecs, _ :=
  1004. directHttpProtocolTransformSpecsValue.(transforms.Specs)
  1005. frontedHttpProtocolTransformSpecsValue, err := getAppliedValue(
  1006. FrontedHTTPProtocolTransformSpecs, parameters, applyParameters)
  1007. if err != nil {
  1008. return nil, errors.Trace(err)
  1009. }
  1010. frontedHttpProtocolTransformSpecs, _ :=
  1011. frontedHttpProtocolTransformSpecsValue.(transforms.Specs)
  1012. osshObfuscatorSeedTransformSpecsValue, err := getAppliedValue(
  1013. OSSHObfuscatorSeedTransformSpecs, parameters, applyParameters)
  1014. if err != nil {
  1015. return nil, errors.Trace(err)
  1016. }
  1017. osshObfuscatorSeedTransformSpecs, _ :=
  1018. osshObfuscatorSeedTransformSpecsValue.(transforms.Specs)
  1019. obfuscatedQuicNonceTransformSpecsValue, err := getAppliedValue(
  1020. ObfuscatedQUICNonceTransformSpecs, parameters, applyParameters)
  1021. if err != nil {
  1022. return nil, errors.Trace(err)
  1023. }
  1024. obfuscatedQuicNonceTransformSpecs, _ :=
  1025. obfuscatedQuicNonceTransformSpecsValue.(transforms.Specs)
  1026. osshPrefixSpecsValue, err := getAppliedValue(
  1027. OSSHPrefixSpecs, parameters, applyParameters)
  1028. if err != nil {
  1029. return nil, errors.Trace(err)
  1030. }
  1031. osshPrefixSpecs, _ := osshPrefixSpecsValue.(transforms.Specs)
  1032. // Special case: in-proxy broker public keys in InproxyBrokerSpecs must
  1033. // appear in InproxyAllBrokerPublicKeys; and inproxy common compartment
  1034. // IDs must appear in InproxyAllCommonCompartmentIDs. This check is
  1035. // server-side only as the "All" parameters are serverSideOnly.
  1036. checkInproxyLists := !skipOnError && serverSide
  1037. inproxyAllBrokerPublicKeysValue, err := getAppliedValue(
  1038. InproxyAllBrokerPublicKeys, parameters, applyParameters)
  1039. if err != nil {
  1040. return nil, errors.Trace(err)
  1041. }
  1042. inproxyAllBrokerPublicKeys, _ := inproxyAllBrokerPublicKeysValue.([]string)
  1043. inproxyAllCommonCompartmentIDsValue, err := getAppliedValue(
  1044. InproxyAllCommonCompartmentIDs, parameters, applyParameters)
  1045. if err != nil {
  1046. return nil, errors.Trace(err)
  1047. }
  1048. inproxyAllCommonCompartmentIDs, _ := inproxyAllCommonCompartmentIDsValue.([]string)
  1049. for i := 0; i < len(applyParameters); i++ {
  1050. count := 0
  1051. for name, value := range applyParameters[i] {
  1052. templateValue, ok := parameters[name]
  1053. if !ok {
  1054. if skipOnError {
  1055. continue
  1056. }
  1057. return nil, errors.Tracef("unknown parameter: %s", name)
  1058. }
  1059. newValue, err := makeTypedValue(templateValue, value)
  1060. if err != nil {
  1061. if skipOnError {
  1062. continue
  1063. }
  1064. return nil, errors.Tracef(
  1065. "unmarshal parameter %s failed: %v", name, err)
  1066. }
  1067. // Perform type-specific validation for some cases.
  1068. // TODO: require RemoteServerListSignaturePublicKey when
  1069. // RemoteServerListURLs is set?
  1070. switch v := newValue.(type) {
  1071. case TransferURLs:
  1072. err := v.DecodeAndValidate()
  1073. if err != nil {
  1074. if skipOnError {
  1075. continue
  1076. }
  1077. return nil, errors.Trace(err)
  1078. }
  1079. case protocol.TunnelProtocols:
  1080. if skipOnError {
  1081. newValue = v.PruneInvalid()
  1082. } else {
  1083. err := v.Validate()
  1084. if err != nil {
  1085. return nil, errors.Trace(err)
  1086. }
  1087. }
  1088. case protocol.LabeledTunnelProtocols:
  1089. if skipOnError {
  1090. newValue = v.PruneInvalid()
  1091. } else {
  1092. err := v.Validate()
  1093. if err != nil {
  1094. return nil, errors.Trace(err)
  1095. }
  1096. }
  1097. case protocol.TLSProfiles:
  1098. if skipOnError {
  1099. newValue = v.PruneInvalid(customTLSProfileNames)
  1100. } else {
  1101. err := v.Validate(customTLSProfileNames)
  1102. if err != nil {
  1103. return nil, errors.Trace(err)
  1104. }
  1105. }
  1106. case protocol.LabeledTLSProfiles:
  1107. if skipOnError {
  1108. newValue = v.PruneInvalid(customTLSProfileNames)
  1109. } else {
  1110. err := v.Validate(customTLSProfileNames)
  1111. if err != nil {
  1112. return nil, errors.Trace(err)
  1113. }
  1114. }
  1115. case protocol.QUICVersions:
  1116. if skipOnError {
  1117. newValue = v.PruneInvalid()
  1118. } else {
  1119. err := v.Validate()
  1120. if err != nil {
  1121. return nil, errors.Trace(err)
  1122. }
  1123. }
  1124. case protocol.LabeledQUICVersions:
  1125. if skipOnError {
  1126. newValue = v.PruneInvalid()
  1127. } else {
  1128. err := v.Validate()
  1129. if err != nil {
  1130. return nil, errors.Trace(err)
  1131. }
  1132. }
  1133. case protocol.CustomTLSProfiles:
  1134. err := v.Validate()
  1135. if err != nil {
  1136. if skipOnError {
  1137. continue
  1138. }
  1139. return nil, errors.Trace(err)
  1140. }
  1141. case KeyValues:
  1142. err := v.Validate()
  1143. if err != nil {
  1144. if skipOnError {
  1145. continue
  1146. }
  1147. return nil, errors.Trace(err)
  1148. }
  1149. case KeyStrings:
  1150. err := v.Validate()
  1151. if err != nil {
  1152. if skipOnError {
  1153. continue
  1154. }
  1155. return nil, errors.Trace(err)
  1156. }
  1157. case *BPFProgramSpec:
  1158. if v != nil {
  1159. err := v.Validate()
  1160. if err != nil {
  1161. if skipOnError {
  1162. continue
  1163. }
  1164. return nil, errors.Trace(err)
  1165. }
  1166. }
  1167. case PacketManipulationSpecs:
  1168. err := v.Validate()
  1169. if err != nil {
  1170. if skipOnError {
  1171. continue
  1172. }
  1173. return nil, errors.Trace(err)
  1174. }
  1175. case ProtocolPacketManipulations:
  1176. var packetManipulationSpecs PacketManipulationSpecs
  1177. if name == ServerProtocolPacketManipulations {
  1178. packetManipulationSpecs = serverPacketManipulationSpecs
  1179. }
  1180. err := v.Validate(packetManipulationSpecs)
  1181. if err != nil {
  1182. if skipOnError {
  1183. continue
  1184. }
  1185. return nil, errors.Trace(err)
  1186. }
  1187. case RegexStrings:
  1188. err := v.Validate()
  1189. if err != nil {
  1190. if skipOnError {
  1191. continue
  1192. }
  1193. return nil, errors.Trace(err)
  1194. }
  1195. case FrontingSpecs:
  1196. err := v.Validate()
  1197. if err != nil {
  1198. if skipOnError {
  1199. continue
  1200. }
  1201. return nil, errors.Trace(err)
  1202. }
  1203. case TunnelProtocolPortLists:
  1204. err := v.Validate()
  1205. if err != nil {
  1206. if skipOnError {
  1207. continue
  1208. }
  1209. return nil, errors.Trace(err)
  1210. }
  1211. case LabeledCIDRs:
  1212. err := v.Validate()
  1213. if err != nil {
  1214. if skipOnError {
  1215. continue
  1216. }
  1217. return nil, errors.Trace(err)
  1218. }
  1219. case transforms.Specs:
  1220. prefixMode := false
  1221. if name == OSSHPrefixSpecs || name == ServerOSSHPrefixSpecs {
  1222. prefixMode = true
  1223. }
  1224. err := v.Validate(prefixMode)
  1225. if err != nil {
  1226. if skipOnError {
  1227. continue
  1228. }
  1229. return nil, errors.Trace(err)
  1230. }
  1231. case transforms.ScopedSpecNames:
  1232. var specs transforms.Specs
  1233. if name == DNSResolverProtocolTransformScopedSpecNames {
  1234. specs = dnsResolverProtocolTransformSpecs
  1235. } else if name == DirectHTTPProtocolTransformScopedSpecNames {
  1236. specs = directHttpProtocolTransformSpecs
  1237. } else if name == FrontedHTTPProtocolTransformScopedSpecNames {
  1238. specs = frontedHttpProtocolTransformSpecs
  1239. } else if name == OSSHObfuscatorSeedTransformScopedSpecNames {
  1240. specs = osshObfuscatorSeedTransformSpecs
  1241. } else if name == ObfuscatedQUICNonceTransformScopedSpecNames {
  1242. specs = obfuscatedQuicNonceTransformSpecs
  1243. } else if name == OSSHPrefixScopedSpecNames {
  1244. specs = osshPrefixSpecs
  1245. }
  1246. err := v.Validate(specs)
  1247. if err != nil {
  1248. if skipOnError {
  1249. continue
  1250. }
  1251. return nil, errors.Trace(err)
  1252. }
  1253. case protocol.ConjureTransports:
  1254. if skipOnError {
  1255. newValue = v.PruneInvalid()
  1256. } else {
  1257. err := v.Validate()
  1258. if err != nil {
  1259. return nil, errors.Trace(err)
  1260. }
  1261. }
  1262. case InproxyBrokerSpecsValue:
  1263. var checkList *[]string
  1264. if checkInproxyLists && name == InproxyBrokerSpecs {
  1265. checkList = &inproxyAllBrokerPublicKeys
  1266. }
  1267. err := v.Validate(checkList)
  1268. if err != nil {
  1269. if skipOnError {
  1270. continue
  1271. }
  1272. return nil, errors.Trace(err)
  1273. }
  1274. case InproxyCompartmentIDsValue:
  1275. var checkList *[]string
  1276. if checkInproxyLists && name == InproxyCommonCompartmentIDs {
  1277. checkList = &inproxyAllCommonCompartmentIDs
  1278. }
  1279. err := v.Validate(checkList)
  1280. if err != nil {
  1281. if skipOnError {
  1282. continue
  1283. }
  1284. return nil, errors.Trace(err)
  1285. }
  1286. case InproxyDataChannelTrafficShapingParametersValue:
  1287. err := v.Validate()
  1288. if err != nil {
  1289. if skipOnError {
  1290. continue
  1291. }
  1292. return nil, errors.Trace(err)
  1293. }
  1294. }
  1295. // Enforce any minimums. Assumes defaultParameters[name]
  1296. // exists.
  1297. if defaultParameters[name].minimum != nil {
  1298. valid := true
  1299. switch v := newValue.(type) {
  1300. case int:
  1301. m, ok := defaultParameters[name].minimum.(int)
  1302. if !ok || v < m {
  1303. valid = false
  1304. }
  1305. case float64:
  1306. m, ok := defaultParameters[name].minimum.(float64)
  1307. if !ok || v < m {
  1308. valid = false
  1309. }
  1310. case time.Duration:
  1311. m, ok := defaultParameters[name].minimum.(time.Duration)
  1312. if !ok || v < m {
  1313. valid = false
  1314. }
  1315. default:
  1316. if skipOnError {
  1317. continue
  1318. }
  1319. return nil, errors.Tracef("unexpected parameter with minimum: %s", name)
  1320. }
  1321. if !valid {
  1322. if skipOnError {
  1323. continue
  1324. }
  1325. return nil, errors.Tracef("parameter below minimum: %s", name)
  1326. }
  1327. }
  1328. parameters[name] = newValue
  1329. count++
  1330. }
  1331. counts = append(counts, count)
  1332. }
  1333. snapshot := &parametersSnapshot{
  1334. getValueLogger: p.getValueLogger,
  1335. tag: tag,
  1336. parameters: parameters,
  1337. }
  1338. p.snapshot.Store(snapshot)
  1339. return counts, nil
  1340. }
  1341. // Get returns the current parameters.
  1342. //
  1343. // Values read from the current parameters are not deep copies and must be
  1344. // treated read-only.
  1345. //
  1346. // The returned ParametersAccessor may be used to read multiple related values
  1347. // atomically and consistently while the current set of values in Parameters
  1348. // may change concurrently.
  1349. //
  1350. // Get does not perform any heap allocations and is intended for repeated,
  1351. // direct, low-overhead invocations.
  1352. func (p *Parameters) Get() ParametersAccessor {
  1353. return ParametersAccessor{
  1354. snapshot: p.snapshot.Load().(*parametersSnapshot)}
  1355. }
  1356. // GetCustom returns the current parameters while also setting customizations
  1357. // for this instance.
  1358. //
  1359. // The properties of Get also apply to GetCustom: must be read-only; atomic
  1360. // and consisent view; no heap allocations.
  1361. //
  1362. // Customizations include:
  1363. //
  1364. // - customNetworkLatencyMultiplier, which overrides NetworkLatencyMultiplier
  1365. // for this instance only.
  1366. func (p *Parameters) GetCustom(
  1367. customNetworkLatencyMultiplier float64) ParametersAccessor {
  1368. return ParametersAccessor{
  1369. snapshot: p.snapshot.Load().(*parametersSnapshot),
  1370. customNetworkLatencyMultiplier: customNetworkLatencyMultiplier,
  1371. }
  1372. }
  1373. // parametersSnapshot is an atomic snapshot of the parameter values.
  1374. // Parameters.Get will return a snapshot which may be used to read multiple
  1375. // related values atomically and consistently while the current snapshot in
  1376. // Parameters may change concurrently.
  1377. type parametersSnapshot struct {
  1378. getValueLogger func(error)
  1379. tag string
  1380. parameters map[string]interface{}
  1381. }
  1382. // getValue sets target to the value of the named parameter.
  1383. //
  1384. // It is an error if the name is not found, target is not a pointer, or the
  1385. // type of target points to does not match the value.
  1386. //
  1387. // Any of these conditions would be a bug in the caller. getValue does not
  1388. // panic in these cases as clients are deployed as a library in various apps
  1389. // and the failure of Psiphon may not be a failure for the app process.
  1390. //
  1391. // Instead, errors are logged to the getValueLogger and getValue leaves the
  1392. // target unset, which will result in the caller getting and using a zero
  1393. // value of the requested type.
  1394. func (p *parametersSnapshot) getValue(name string, target interface{}) {
  1395. value, ok := p.parameters[name]
  1396. if !ok {
  1397. if p.getValueLogger != nil {
  1398. p.getValueLogger(errors.Tracef(
  1399. "value %s not found", name))
  1400. }
  1401. return
  1402. }
  1403. valueType := reflect.TypeOf(value)
  1404. if reflect.PtrTo(valueType) != reflect.TypeOf(target) {
  1405. if p.getValueLogger != nil {
  1406. p.getValueLogger(errors.Tracef(
  1407. "value %s has unexpected type %s", name, valueType.Name()))
  1408. }
  1409. return
  1410. }
  1411. // Note: there is no deep copy of parameter values; the returned value may
  1412. // share memory with the original and should not be modified.
  1413. targetValue := reflect.ValueOf(target)
  1414. if targetValue.Kind() != reflect.Ptr {
  1415. p.getValueLogger(errors.Tracef(
  1416. "target for value %s is not pointer", name))
  1417. return
  1418. }
  1419. targetValue.Elem().Set(reflect.ValueOf(value))
  1420. }
  1421. // ParametersAccessor provides consistent, atomic access to parameter values.
  1422. // Any customizations are applied transparently.
  1423. type ParametersAccessor struct {
  1424. snapshot *parametersSnapshot
  1425. customNetworkLatencyMultiplier float64
  1426. }
  1427. // MakeNilParametersAccessor produces a stub ParametersAccessor which returns
  1428. // true for IsNil. This may be used where a ParametersAccessor value is
  1429. // required, but Parameters.Get may not succeed. In contexts where
  1430. // MakeNilParametersAccessor may be used, calls to ParametersAccessor must
  1431. // first check IsNil before calling accessor functions.
  1432. func MakeNilParametersAccessor() ParametersAccessor {
  1433. return ParametersAccessor{}
  1434. }
  1435. // IsNil indicates that this ParametersAccessor is a stub and its accessor
  1436. // functions may not be called. A ParametersAccessor produced by
  1437. // Parameters.Get will never return true for IsNil and IsNil guards are not
  1438. // required for ParametersAccessors known to be produced by Parameters.Get.
  1439. func (p ParametersAccessor) IsNil() bool {
  1440. return p.snapshot == nil
  1441. }
  1442. // Close clears internal references to large memory objects, allowing them to
  1443. // be garbage collected. Call Close when done using a ParametersAccessor,
  1444. // where memory footprint is a concern, and where the ParametersAccessor is
  1445. // not immediately going out of scope. After Close is called, all other
  1446. // ParametersAccessor functions will panic if called.
  1447. func (p ParametersAccessor) Close() {
  1448. p.snapshot = nil
  1449. }
  1450. // Tag returns the tag associated with these parameters.
  1451. func (p ParametersAccessor) Tag() string {
  1452. return p.snapshot.tag
  1453. }
  1454. // String returns a string parameter value.
  1455. func (p ParametersAccessor) String(name string) string {
  1456. value := ""
  1457. p.snapshot.getValue(name, &value)
  1458. return value
  1459. }
  1460. // Strings returns a []string parameter value. If multiple parameter names are
  1461. // specified, the first name with a non-empty value is used.
  1462. func (p ParametersAccessor) Strings(names ...string) []string {
  1463. for _, name := range names {
  1464. value := []string{}
  1465. p.snapshot.getValue(name, &value)
  1466. if len(value) > 0 {
  1467. return value
  1468. }
  1469. }
  1470. return []string{}
  1471. }
  1472. // Int returns an int parameter value.
  1473. func (p ParametersAccessor) Int(name string) int {
  1474. value := int(0)
  1475. p.snapshot.getValue(name, &value)
  1476. return value
  1477. }
  1478. // Bool returns a bool parameter value.
  1479. func (p ParametersAccessor) Bool(name string) bool {
  1480. value := false
  1481. p.snapshot.getValue(name, &value)
  1482. return value
  1483. }
  1484. // Float returns a float64 parameter value.
  1485. func (p ParametersAccessor) Float(name string) float64 {
  1486. value := float64(0.0)
  1487. p.snapshot.getValue(name, &value)
  1488. return value
  1489. }
  1490. // WeightedCoinFlip returns the result of prng.FlipWeightedCoin using the
  1491. // specified float parameter as the probability input.
  1492. func (p ParametersAccessor) WeightedCoinFlip(name string) bool {
  1493. var value float64
  1494. p.snapshot.getValue(name, &value)
  1495. return prng.FlipWeightedCoin(value)
  1496. }
  1497. // Duration returns a time.Duration parameter value. When the duration
  1498. // parameter has the useNetworkLatencyMultiplier flag, the
  1499. // NetworkLatencyMultiplier is applied to the returned value.
  1500. func (p ParametersAccessor) Duration(name string) time.Duration {
  1501. value := time.Duration(0)
  1502. p.snapshot.getValue(name, &value)
  1503. defaultParameter, ok := defaultParameters[name]
  1504. if value > 0 && ok && defaultParameter.flags&useNetworkLatencyMultiplier != 0 {
  1505. multiplier := float64(0.0)
  1506. if p.customNetworkLatencyMultiplier != 0.0 {
  1507. multiplier = p.customNetworkLatencyMultiplier
  1508. } else {
  1509. p.snapshot.getValue(NetworkLatencyMultiplier, &multiplier)
  1510. }
  1511. if multiplier > 0.0 {
  1512. value = time.Duration(float64(value) * multiplier)
  1513. }
  1514. }
  1515. return value
  1516. }
  1517. // TunnelProtocols returns a protocol.TunnelProtocols parameter value.
  1518. // If there is a corresponding Probability value, a weighted coin flip
  1519. // will be performed and, depending on the result, the value or the
  1520. // parameter default will be returned.
  1521. func (p ParametersAccessor) TunnelProtocols(name string) protocol.TunnelProtocols {
  1522. probabilityName := name + "Probability"
  1523. _, ok := p.snapshot.parameters[probabilityName]
  1524. if ok {
  1525. probabilityValue := float64(1.0)
  1526. p.snapshot.getValue(probabilityName, &probabilityValue)
  1527. if !prng.FlipWeightedCoin(probabilityValue) {
  1528. defaultParameter, ok := defaultParameters[name]
  1529. if ok {
  1530. defaultValue, ok := defaultParameter.value.(protocol.TunnelProtocols)
  1531. if ok {
  1532. value := make(protocol.TunnelProtocols, len(defaultValue))
  1533. copy(value, defaultValue)
  1534. return value
  1535. }
  1536. }
  1537. }
  1538. }
  1539. value := protocol.TunnelProtocols{}
  1540. p.snapshot.getValue(name, &value)
  1541. return value
  1542. }
  1543. // LabeledTunnelProtocols returns a protocol.TunnelProtocols parameter value
  1544. // corresponding to the specified labeled set and label value. The return
  1545. // value is nil when no set is found.
  1546. func (p ParametersAccessor) LabeledTunnelProtocols(name, label string) protocol.TunnelProtocols {
  1547. var value protocol.LabeledTunnelProtocols
  1548. p.snapshot.getValue(name, &value)
  1549. return value[label]
  1550. }
  1551. // TLSProfiles returns a protocol.TLSProfiles parameter value.
  1552. // If there is a corresponding Probability value, a weighted coin flip
  1553. // will be performed and, depending on the result, the value or the
  1554. // parameter default will be returned.
  1555. func (p ParametersAccessor) TLSProfiles(name string) protocol.TLSProfiles {
  1556. probabilityName := name + "Probability"
  1557. _, ok := p.snapshot.parameters[probabilityName]
  1558. if ok {
  1559. probabilityValue := float64(1.0)
  1560. p.snapshot.getValue(probabilityName, &probabilityValue)
  1561. if !prng.FlipWeightedCoin(probabilityValue) {
  1562. defaultParameter, ok := defaultParameters[name]
  1563. if ok {
  1564. defaultValue, ok := defaultParameter.value.(protocol.TLSProfiles)
  1565. if ok {
  1566. value := make(protocol.TLSProfiles, len(defaultValue))
  1567. copy(value, defaultValue)
  1568. return value
  1569. }
  1570. }
  1571. }
  1572. }
  1573. value := protocol.TLSProfiles{}
  1574. p.snapshot.getValue(name, &value)
  1575. return value
  1576. }
  1577. // LabeledTLSProfiles returns a protocol.TLSProfiles parameter value
  1578. // corresponding to the specified labeled set and label value. The return
  1579. // value is nil when no set is found.
  1580. func (p ParametersAccessor) LabeledTLSProfiles(name, label string) protocol.TLSProfiles {
  1581. var value protocol.LabeledTLSProfiles
  1582. p.snapshot.getValue(name, &value)
  1583. return value[label]
  1584. }
  1585. // QUICVersions returns a protocol.QUICVersions parameter value.
  1586. // If there is a corresponding Probability value, a weighted coin flip
  1587. // will be performed and, depending on the result, the value or the
  1588. // parameter default will be returned.
  1589. func (p ParametersAccessor) QUICVersions(name string) protocol.QUICVersions {
  1590. probabilityName := name + "Probability"
  1591. _, ok := p.snapshot.parameters[probabilityName]
  1592. if ok {
  1593. probabilityValue := float64(1.0)
  1594. p.snapshot.getValue(probabilityName, &probabilityValue)
  1595. if !prng.FlipWeightedCoin(probabilityValue) {
  1596. defaultParameter, ok := defaultParameters[name]
  1597. if ok {
  1598. defaultValue, ok := defaultParameter.value.(protocol.QUICVersions)
  1599. if ok {
  1600. value := make(protocol.QUICVersions, len(defaultValue))
  1601. copy(value, defaultValue)
  1602. return value
  1603. }
  1604. }
  1605. }
  1606. }
  1607. value := protocol.QUICVersions{}
  1608. p.snapshot.getValue(name, &value)
  1609. return value
  1610. }
  1611. // LabeledQUICVersions returns a protocol.QUICVersions parameter value
  1612. // corresponding to the specified labeled set and label value. The return
  1613. // value is nil when no set is found.
  1614. func (p ParametersAccessor) LabeledQUICVersions(name, label string) protocol.QUICVersions {
  1615. value := protocol.LabeledQUICVersions{}
  1616. p.snapshot.getValue(name, &value)
  1617. return value[label]
  1618. }
  1619. // TransferURLs returns a TransferURLs parameter value.
  1620. func (p ParametersAccessor) TransferURLs(name string) TransferURLs {
  1621. value := TransferURLs{}
  1622. p.snapshot.getValue(name, &value)
  1623. return value
  1624. }
  1625. // RateLimits returns a common.RateLimits parameter value.
  1626. func (p ParametersAccessor) RateLimits(name string) common.RateLimits {
  1627. value := common.RateLimits{}
  1628. p.snapshot.getValue(name, &value)
  1629. return value
  1630. }
  1631. // HTTPHeaders returns an http.Header parameter value.
  1632. func (p ParametersAccessor) HTTPHeaders(name string) http.Header {
  1633. value := make(http.Header)
  1634. p.snapshot.getValue(name, &value)
  1635. return value
  1636. }
  1637. // CustomTLSProfileNames returns the CustomTLSProfile.Name fields for
  1638. // each profile in the CustomTLSProfiles parameter value.
  1639. func (p ParametersAccessor) CustomTLSProfileNames() []string {
  1640. value := protocol.CustomTLSProfiles{}
  1641. p.snapshot.getValue(CustomTLSProfiles, &value)
  1642. names := make([]string, len(value))
  1643. for i := 0; i < len(value); i++ {
  1644. names[i] = value[i].Name
  1645. }
  1646. return names
  1647. }
  1648. // CustomTLSProfile returns the CustomTLSProfile fields with the specified
  1649. // Name field if it exists in the CustomTLSProfiles parameter value.
  1650. // Returns nil if not found.
  1651. func (p ParametersAccessor) CustomTLSProfile(name string) *protocol.CustomTLSProfile {
  1652. value := protocol.CustomTLSProfiles{}
  1653. p.snapshot.getValue(CustomTLSProfiles, &value)
  1654. // Note: linear lookup -- assumes a short list
  1655. for i := 0; i < len(value); i++ {
  1656. if value[i].Name == name {
  1657. return value[i]
  1658. }
  1659. }
  1660. return nil
  1661. }
  1662. // KeyValues returns a KeyValues parameter value.
  1663. func (p ParametersAccessor) KeyValues(name string) KeyValues {
  1664. value := KeyValues{}
  1665. p.snapshot.getValue(name, &value)
  1666. return value
  1667. }
  1668. // BPFProgram returns an assembled BPF program corresponding to a
  1669. // BPFProgramSpec parameter value. Returns nil in the case of any empty
  1670. // program.
  1671. func (p ParametersAccessor) BPFProgram(name string) (bool, string, []bpf.RawInstruction) {
  1672. var value *BPFProgramSpec
  1673. p.snapshot.getValue(name, &value)
  1674. if value == nil {
  1675. return false, "", nil
  1676. }
  1677. // Validation checks that Assemble is successful.
  1678. rawInstructions, _ := value.Assemble()
  1679. return true, value.Name, rawInstructions
  1680. }
  1681. // PacketManipulationSpecs returns a PacketManipulationSpecs parameter value.
  1682. func (p ParametersAccessor) PacketManipulationSpecs(name string) PacketManipulationSpecs {
  1683. value := PacketManipulationSpecs{}
  1684. p.snapshot.getValue(name, &value)
  1685. return value
  1686. }
  1687. // ProtocolPacketManipulations returns a ProtocolPacketManipulations parameter value.
  1688. func (p ParametersAccessor) ProtocolPacketManipulations(name string) ProtocolPacketManipulations {
  1689. value := make(ProtocolPacketManipulations)
  1690. p.snapshot.getValue(name, &value)
  1691. return value
  1692. }
  1693. // RegexStrings returns a RegexStrings parameter value.
  1694. func (p ParametersAccessor) RegexStrings(name string) RegexStrings {
  1695. value := RegexStrings{}
  1696. p.snapshot.getValue(name, &value)
  1697. return value
  1698. }
  1699. // FrontingSpecs returns a FrontingSpecs parameter value.
  1700. func (p ParametersAccessor) FrontingSpecs(name string) FrontingSpecs {
  1701. value := FrontingSpecs{}
  1702. p.snapshot.getValue(name, &value)
  1703. return value
  1704. }
  1705. // TunnelProtocolPortLists returns a TunnelProtocolPortLists parameter value.
  1706. func (p ParametersAccessor) TunnelProtocolPortLists(name string) TunnelProtocolPortLists {
  1707. probabilityName := name + "Probability"
  1708. _, ok := p.snapshot.parameters[probabilityName]
  1709. if ok {
  1710. probabilityValue := float64(1.0)
  1711. p.snapshot.getValue(probabilityName, &probabilityValue)
  1712. if !prng.FlipWeightedCoin(probabilityValue) {
  1713. defaultParameter, ok := defaultParameters[name]
  1714. if ok {
  1715. defaultValue, ok := defaultParameter.value.(TunnelProtocolPortLists)
  1716. if ok {
  1717. value := make(TunnelProtocolPortLists)
  1718. for tunnelProtocol, portLists := range defaultValue {
  1719. value[tunnelProtocol] = portLists
  1720. }
  1721. return value
  1722. }
  1723. }
  1724. }
  1725. }
  1726. value := make(TunnelProtocolPortLists)
  1727. p.snapshot.getValue(name, &value)
  1728. return value
  1729. }
  1730. // LabeledCIDRs returns a CIDR string list parameter value corresponding to
  1731. // the specified labeled set and label value. The return value is nil when no
  1732. // set is found.
  1733. func (p ParametersAccessor) LabeledCIDRs(name, label string) []string {
  1734. value := LabeledCIDRs{}
  1735. p.snapshot.getValue(name, &value)
  1736. return value[label]
  1737. }
  1738. // ProtocolTransformSpecs returns a transforms.Specs parameter value.
  1739. func (p ParametersAccessor) ProtocolTransformSpecs(name string) transforms.Specs {
  1740. value := transforms.Specs{}
  1741. p.snapshot.getValue(name, &value)
  1742. return value
  1743. }
  1744. // ProtocolTransformScopedSpecNames returns a transforms.ScopedSpecNames
  1745. // parameter value.
  1746. func (p ParametersAccessor) ProtocolTransformScopedSpecNames(name string) transforms.ScopedSpecNames {
  1747. value := transforms.ScopedSpecNames{}
  1748. p.snapshot.getValue(name, &value)
  1749. return value
  1750. }
  1751. // ConjureTransports returns a protocol.ConjureTransports parameter value. If
  1752. // there is a corresponding Probability value, a weighted coin flip will be
  1753. // performed and, depending on the result, the value or the parameter default
  1754. // will be returned.
  1755. func (p ParametersAccessor) ConjureTransports(name string) protocol.ConjureTransports {
  1756. probabilityName := name + "Probability"
  1757. _, ok := p.snapshot.parameters[probabilityName]
  1758. if ok {
  1759. probabilityValue := float64(1.0)
  1760. p.snapshot.getValue(probabilityName, &probabilityValue)
  1761. if !prng.FlipWeightedCoin(probabilityValue) {
  1762. defaultParameter, ok := defaultParameters[name]
  1763. if ok {
  1764. defaultValue, ok := defaultParameter.value.(protocol.ConjureTransports)
  1765. if ok {
  1766. value := make(protocol.ConjureTransports, len(defaultValue))
  1767. copy(value, defaultValue)
  1768. return value
  1769. }
  1770. }
  1771. }
  1772. }
  1773. value := protocol.ConjureTransports{}
  1774. p.snapshot.getValue(name, &value)
  1775. return value
  1776. }
  1777. // InproxyBrokerSpecs returns a InproxyBrokerSpecs parameter value. If
  1778. // multiple parameter names are specified, the first name with a non-empty
  1779. // value is used.
  1780. func (p ParametersAccessor) InproxyBrokerSpecs(names ...string) InproxyBrokerSpecsValue {
  1781. for _, name := range names {
  1782. value := InproxyBrokerSpecsValue{}
  1783. p.snapshot.getValue(name, &value)
  1784. if len(value) > 0 {
  1785. return value
  1786. }
  1787. }
  1788. return InproxyBrokerSpecsValue{}
  1789. }
  1790. // InproxyBrokerSpecs returns a InproxyBrokerSpecs parameter value.
  1791. func (p ParametersAccessor) InproxyCompartmentIDs(name string) InproxyCompartmentIDsValue {
  1792. value := InproxyCompartmentIDsValue{}
  1793. p.snapshot.getValue(name, &value)
  1794. return value
  1795. }
  1796. // InproxyDataChannelTrafficShapingParameters returns a
  1797. // InproxyDataChannelTrafficShapingParameters parameter value.
  1798. func (p ParametersAccessor) InproxyDataChannelTrafficShapingParameters(
  1799. name string) InproxyDataChannelTrafficShapingParametersValue {
  1800. value := InproxyDataChannelTrafficShapingParametersValue{}
  1801. p.snapshot.getValue(name, &value)
  1802. return value
  1803. }