parameters.go 107 KB

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