parameters.go 95 KB

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