parameters.go 103 KB

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