parameters.go 102 KB

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