parameters.go 107 KB

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