parameters.go 98 KB

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