parameters.go 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  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. "golang.org/x/net/bpf"
  59. )
  60. const (
  61. NetworkLatencyMultiplier = "NetworkLatencyMultiplier"
  62. NetworkLatencyMultiplierMin = "NetworkLatencyMultiplierMin"
  63. NetworkLatencyMultiplierMax = "NetworkLatencyMultiplierMax"
  64. NetworkLatencyMultiplierLambda = "NetworkLatencyMultiplierLambda"
  65. TacticsWaitPeriod = "TacticsWaitPeriod"
  66. TacticsRetryPeriod = "TacticsRetryPeriod"
  67. TacticsRetryPeriodJitter = "TacticsRetryPeriodJitter"
  68. TacticsTimeout = "TacticsTimeout"
  69. ConnectionWorkerPoolSize = "ConnectionWorkerPoolSize"
  70. TunnelPoolSize = "TunnelPoolSize"
  71. TunnelConnectTimeout = "TunnelConnectTimeout"
  72. EstablishTunnelTimeout = "EstablishTunnelTimeout"
  73. EstablishTunnelWorkTime = "EstablishTunnelWorkTime"
  74. EstablishTunnelPausePeriod = "EstablishTunnelPausePeriod"
  75. EstablishTunnelPausePeriodJitter = "EstablishTunnelPausePeriodJitter"
  76. EstablishTunnelServerAffinityGracePeriod = "EstablishTunnelServerAffinityGracePeriod"
  77. StaggerConnectionWorkersPeriod = "StaggerConnectionWorkersPeriod"
  78. StaggerConnectionWorkersJitter = "StaggerConnectionWorkersJitter"
  79. LimitIntensiveConnectionWorkers = "LimitIntensiveConnectionWorkers"
  80. UpstreamProxyErrorMinWaitDuration = "UpstreamProxyErrorMinWaitDuration"
  81. UpstreamProxyErrorMaxWaitDuration = "UpstreamProxyErrorMaxWaitDuration"
  82. IgnoreHandshakeStatsRegexps = "IgnoreHandshakeStatsRegexps"
  83. PrioritizeTunnelProtocolsProbability = "PrioritizeTunnelProtocolsProbability"
  84. PrioritizeTunnelProtocols = "PrioritizeTunnelProtocols"
  85. PrioritizeTunnelProtocolsCandidateCount = "PrioritizeTunnelProtocolsCandidateCount"
  86. InitialLimitTunnelProtocolsProbability = "InitialLimitTunnelProtocolsProbability"
  87. InitialLimitTunnelProtocols = "InitialLimitTunnelProtocols"
  88. InitialLimitTunnelProtocolsCandidateCount = "InitialLimitTunnelProtocolsCandidateCount"
  89. LimitTunnelProtocolsProbability = "LimitTunnelProtocolsProbability"
  90. LimitTunnelProtocols = "LimitTunnelProtocols"
  91. LimitTunnelDialPortNumbersProbability = "LimitTunnelDialPortNumbersProbability"
  92. LimitTunnelDialPortNumbers = "LimitTunnelDialPortNumbers"
  93. LimitTLSProfilesProbability = "LimitTLSProfilesProbability"
  94. LimitTLSProfiles = "LimitTLSProfiles"
  95. UseOnlyCustomTLSProfiles = "UseOnlyCustomTLSProfiles"
  96. CustomTLSProfiles = "CustomTLSProfiles"
  97. SelectRandomizedTLSProfileProbability = "SelectRandomizedTLSProfileProbability"
  98. NoDefaultTLSSessionIDProbability = "NoDefaultTLSSessionIDProbability"
  99. DisableFrontingProviderTLSProfiles = "DisableFrontingProviderTLSProfiles"
  100. LimitQUICVersionsProbability = "LimitQUICVersionsProbability"
  101. LimitQUICVersions = "LimitQUICVersions"
  102. DisableFrontingProviderQUICVersions = "DisableFrontingProviderQUICVersions"
  103. QUICDisableClientPathMTUDiscoveryProbability = "QUICDisableClientPathMTUDiscoveryProbability"
  104. FragmentorProbability = "FragmentorProbability"
  105. FragmentorLimitProtocols = "FragmentorLimitProtocols"
  106. FragmentorMinTotalBytes = "FragmentorMinTotalBytes"
  107. FragmentorMaxTotalBytes = "FragmentorMaxTotalBytes"
  108. FragmentorMinWriteBytes = "FragmentorMinWriteBytes"
  109. FragmentorMaxWriteBytes = "FragmentorMaxWriteBytes"
  110. FragmentorMinDelay = "FragmentorMinDelay"
  111. FragmentorMaxDelay = "FragmentorMaxDelay"
  112. FragmentorDownstreamProbability = "FragmentorDownstreamProbability"
  113. FragmentorDownstreamLimitProtocols = "FragmentorDownstreamLimitProtocols"
  114. FragmentorDownstreamMinTotalBytes = "FragmentorDownstreamMinTotalBytes"
  115. FragmentorDownstreamMaxTotalBytes = "FragmentorDownstreamMaxTotalBytes"
  116. FragmentorDownstreamMinWriteBytes = "FragmentorDownstreamMinWriteBytes"
  117. FragmentorDownstreamMaxWriteBytes = "FragmentorDownstreamMaxWriteBytes"
  118. FragmentorDownstreamMinDelay = "FragmentorDownstreamMinDelay"
  119. FragmentorDownstreamMaxDelay = "FragmentorDownstreamMaxDelay"
  120. ObfuscatedSSHMinPadding = "ObfuscatedSSHMinPadding"
  121. ObfuscatedSSHMaxPadding = "ObfuscatedSSHMaxPadding"
  122. TunnelOperateShutdownTimeout = "TunnelOperateShutdownTimeout"
  123. TunnelPortForwardDialTimeout = "TunnelPortForwardDialTimeout"
  124. PacketTunnelReadTimeout = "PacketTunnelReadTimeout"
  125. TunnelRateLimits = "TunnelRateLimits"
  126. AdditionalCustomHeaders = "AdditionalCustomHeaders"
  127. SpeedTestPaddingMinBytes = "SpeedTestPaddingMinBytes"
  128. SpeedTestPaddingMaxBytes = "SpeedTestPaddingMaxBytes"
  129. SpeedTestMaxSampleCount = "SpeedTestMaxSampleCount"
  130. SSHKeepAliveSpeedTestSampleProbability = "SSHKeepAliveSpeedTestSampleProbability"
  131. SSHKeepAlivePaddingMinBytes = "SSHKeepAlivePaddingMinBytes"
  132. SSHKeepAlivePaddingMaxBytes = "SSHKeepAlivePaddingMaxBytes"
  133. SSHKeepAlivePeriodMin = "SSHKeepAlivePeriodMin"
  134. SSHKeepAlivePeriodMax = "SSHKeepAlivePeriodMax"
  135. SSHKeepAlivePeriodicTimeout = "SSHKeepAlivePeriodicTimeout"
  136. SSHKeepAlivePeriodicInactivePeriod = "SSHKeepAlivePeriodicInactivePeriod"
  137. SSHKeepAliveProbeTimeout = "SSHKeepAliveProbeTimeout"
  138. SSHKeepAliveProbeInactivePeriod = "SSHKeepAliveProbeInactivePeriod"
  139. SSHKeepAliveNetworkConnectivityPollingPeriod = "SSHKeepAliveNetworkConnectivityPollingPeriod"
  140. SSHKeepAliveResetOnFailureProbability = "SSHKeepAliveResetOnFailureProbability"
  141. HTTPProxyOriginServerTimeout = "HTTPProxyOriginServerTimeout"
  142. HTTPProxyMaxIdleConnectionsPerHost = "HTTPProxyMaxIdleConnectionsPerHost"
  143. FetchRemoteServerListTimeout = "FetchRemoteServerListTimeout"
  144. FetchRemoteServerListRetryPeriod = "FetchRemoteServerListRetryPeriod"
  145. FetchRemoteServerListStalePeriod = "FetchRemoteServerListStalePeriod"
  146. RemoteServerListSignaturePublicKey = "RemoteServerListSignaturePublicKey"
  147. RemoteServerListURLs = "RemoteServerListURLs"
  148. ObfuscatedServerListRootURLs = "ObfuscatedServerListRootURLs"
  149. PsiphonAPIRequestTimeout = "PsiphonAPIRequestTimeout"
  150. PsiphonAPIStatusRequestPeriodMin = "PsiphonAPIStatusRequestPeriodMin"
  151. PsiphonAPIStatusRequestPeriodMax = "PsiphonAPIStatusRequestPeriodMax"
  152. PsiphonAPIStatusRequestShortPeriodMin = "PsiphonAPIStatusRequestShortPeriodMin"
  153. PsiphonAPIStatusRequestShortPeriodMax = "PsiphonAPIStatusRequestShortPeriodMax"
  154. PsiphonAPIStatusRequestPaddingMinBytes = "PsiphonAPIStatusRequestPaddingMinBytes"
  155. PsiphonAPIStatusRequestPaddingMaxBytes = "PsiphonAPIStatusRequestPaddingMaxBytes"
  156. PsiphonAPIPersistentStatsMaxCount = "PsiphonAPIPersistentStatsMaxCount"
  157. PsiphonAPIConnectedRequestPeriod = "PsiphonAPIConnectedRequestPeriod"
  158. PsiphonAPIConnectedRequestRetryPeriod = "PsiphonAPIConnectedRequestRetryPeriod"
  159. FetchSplitTunnelRoutesTimeout = "FetchSplitTunnelRoutesTimeout"
  160. SplitTunnelRoutesURLFormat = "SplitTunnelRoutesURLFormat"
  161. SplitTunnelRoutesSignaturePublicKey = "SplitTunnelRoutesSignaturePublicKey"
  162. SplitTunnelDNSServer = "SplitTunnelDNSServer"
  163. SplitTunnelClassificationTTL = "SplitTunnelClassificationTTL"
  164. SplitTunnelClassificationMaxEntries = "SplitTunnelClassificationMaxEntries"
  165. FetchUpgradeTimeout = "FetchUpgradeTimeout"
  166. FetchUpgradeRetryPeriod = "FetchUpgradeRetryPeriod"
  167. FetchUpgradeStalePeriod = "FetchUpgradeStalePeriod"
  168. UpgradeDownloadURLs = "UpgradeDownloadURLs"
  169. UpgradeDownloadClientVersionHeader = "UpgradeDownloadClientVersionHeader"
  170. TotalBytesTransferredNoticePeriod = "TotalBytesTransferredNoticePeriod"
  171. TotalBytesTransferredEmitMemoryMetrics = "TotalBytesTransferredEmitMemoryMetrics"
  172. MeekDialDomainsOnly = "MeekDialDomainsOnly"
  173. MeekLimitBufferSizes = "MeekLimitBufferSizes"
  174. MeekCookieMaxPadding = "MeekCookieMaxPadding"
  175. MeekFullReceiveBufferLength = "MeekFullReceiveBufferLength"
  176. MeekReadPayloadChunkLength = "MeekReadPayloadChunkLength"
  177. MeekLimitedFullReceiveBufferLength = "MeekLimitedFullReceiveBufferLength"
  178. MeekLimitedReadPayloadChunkLength = "MeekLimitedReadPayloadChunkLength"
  179. MeekMinPollInterval = "MeekMinPollInterval"
  180. MeekMinPollIntervalJitter = "MeekMinPollIntervalJitter"
  181. MeekMaxPollInterval = "MeekMaxPollInterval"
  182. MeekMaxPollIntervalJitter = "MeekMaxPollIntervalJitter"
  183. MeekPollIntervalMultiplier = "MeekPollIntervalMultiplier"
  184. MeekPollIntervalJitter = "MeekPollIntervalJitter"
  185. MeekApplyPollIntervalMultiplierProbability = "MeekApplyPollIntervalMultiplierProbability"
  186. MeekRoundTripRetryDeadline = "MeekRoundTripRetryDeadline"
  187. MeekRoundTripRetryMinDelay = "MeekRoundTripRetryMinDelay"
  188. MeekRoundTripRetryMaxDelay = "MeekRoundTripRetryMaxDelay"
  189. MeekRoundTripRetryMultiplier = "MeekRoundTripRetryMultiplier"
  190. MeekRoundTripTimeout = "MeekRoundTripTimeout"
  191. MeekTrafficShapingProbability = "MeekTrafficShapingProbability"
  192. MeekTrafficShapingLimitProtocols = "MeekTrafficShapingLimitProtocols"
  193. MeekMinTLSPadding = "MeekMinTLSPadding"
  194. MeekMaxTLSPadding = "MeekMaxTLSPadding"
  195. MeekMinLimitRequestPayloadLength = "MeekMinLimitRequestPayloadLength"
  196. MeekMaxLimitRequestPayloadLength = "MeekMaxLimitRequestPayloadLength"
  197. MeekRedialTLSProbability = "MeekRedialTLSProbability"
  198. TransformHostNameProbability = "TransformHostNameProbability"
  199. PickUserAgentProbability = "PickUserAgentProbability"
  200. LivenessTestMinUpstreamBytes = "LivenessTestMinUpstreamBytes"
  201. LivenessTestMaxUpstreamBytes = "LivenessTestMaxUpstreamBytes"
  202. LivenessTestMinDownstreamBytes = "LivenessTestMinDownstreamBytes"
  203. LivenessTestMaxDownstreamBytes = "LivenessTestMaxDownstreamBytes"
  204. ReplayCandidateCount = "ReplayCandidateCount"
  205. ReplayDialParametersTTL = "ReplayDialParametersTTL"
  206. ReplayTargetUpstreamBytes = "ReplayTargetUpstreamBytes"
  207. ReplayTargetDownstreamBytes = "ReplayTargetDownstreamBytes"
  208. ReplayTargetTunnelDuration = "ReplayTargetTunnelDuration"
  209. ReplayBPF = "ReplayBPF"
  210. ReplaySSH = "ReplaySSH"
  211. ReplayObfuscatorPadding = "ReplayObfuscatorPadding"
  212. ReplayFragmentor = "ReplayFragmentor"
  213. ReplayTLSProfile = "ReplayTLSProfile"
  214. ReplayRandomizedTLSProfile = "ReplayRandomizedTLSProfile"
  215. ReplayFronting = "ReplayFronting"
  216. ReplayHostname = "ReplayHostname"
  217. ReplayQUICVersion = "ReplayQUICVersion"
  218. ReplayObfuscatedQUIC = "ReplayObfuscatedQUIC"
  219. ReplayConjureRegistration = "ReplayConjureRegistration"
  220. ReplayConjureTransport = "ReplayConjureTransport"
  221. ReplayLivenessTest = "ReplayLivenessTest"
  222. ReplayUserAgent = "ReplayUserAgent"
  223. ReplayAPIRequestPadding = "ReplayAPIRequestPadding"
  224. ReplayLaterRoundMoveToFrontProbability = "ReplayLaterRoundMoveToFrontProbability"
  225. ReplayRetainFailedProbability = "ReplayRetainFailedProbability"
  226. ReplayHoldOffTunnel = "ReplayHoldOffTunnel"
  227. APIRequestUpstreamPaddingMinBytes = "APIRequestUpstreamPaddingMinBytes"
  228. APIRequestUpstreamPaddingMaxBytes = "APIRequestUpstreamPaddingMaxBytes"
  229. APIRequestDownstreamPaddingMinBytes = "APIRequestDownstreamPaddingMinBytes"
  230. APIRequestDownstreamPaddingMaxBytes = "APIRequestDownstreamPaddingMaxBytes"
  231. PersistentStatsMaxStoreRecords = "PersistentStatsMaxStoreRecords"
  232. PersistentStatsMaxSendBytes = "PersistentStatsMaxSendBytes"
  233. RecordRemoteServerListPersistentStatsProbability = "RecordRemoteServerListPersistentStatsProbability"
  234. RecordFailedTunnelPersistentStatsProbability = "RecordFailedTunnelPersistentStatsProbability"
  235. ServerEntryMinimumAgeForPruning = "ServerEntryMinimumAgeForPruning"
  236. ApplicationParametersProbability = "ApplicationParametersProbability"
  237. ApplicationParameters = "ApplicationParameters"
  238. BPFServerTCPProgram = "BPFServerTCPProgram"
  239. BPFServerTCPProbability = "BPFServerTCPProbability"
  240. BPFClientTCPProgram = "BPFClientTCPProgram"
  241. BPFClientTCPProbability = "BPFClientTCPProbability"
  242. ServerPacketManipulationSpecs = "ServerPacketManipulationSpecs"
  243. ServerProtocolPacketManipulations = "ServerProtocolPacketManipulations"
  244. ServerPacketManipulationProbability = "ServerPacketManipulationProbability"
  245. FeedbackUploadURLs = "FeedbackUploadURLs"
  246. FeedbackEncryptionPublicKey = "FeedbackEncryptionPublicKey"
  247. FeedbackTacticsWaitPeriod = "FeedbackTacticsWaitPeriod"
  248. FeedbackUploadMaxAttempts = "FeedbackUploadMaxAttempts"
  249. FeedbackUploadRetryMinDelaySeconds = "FeedbackUploadRetryMinDelaySeconds"
  250. FeedbackUploadRetryMaxDelaySeconds = "FeedbackUploadRetryMaxDelaySeconds"
  251. FeedbackUploadTimeoutSeconds = "FeedbackUploadTimeoutSeconds"
  252. ServerReplayPacketManipulation = "ServerReplayPacketManipulation"
  253. ServerReplayFragmentor = "ServerReplayFragmentor"
  254. ServerReplayUnknownGeoIP = "ServerReplayUnknownGeoIP"
  255. ServerReplayTTL = "ServerReplayTTL"
  256. ServerReplayTargetWaitDuration = "ServerReplayTargetWaitDuration"
  257. ServerReplayTargetTunnelDuration = "ServerReplayTargetTunnelDuration"
  258. ServerReplayTargetUpstreamBytes = "ServerReplayTargetUpstreamBytes"
  259. ServerReplayTargetDownstreamBytes = "ServerReplayTargetDownstreamBytes"
  260. ServerReplayFailedCountThreshold = "ServerReplayFailedCountThreshold"
  261. ServerBurstUpstreamDeadline = "ServerBurstUpstreamDeadline"
  262. ServerBurstUpstreamTargetBytes = "ServerBurstUpstreamTargetBytes"
  263. ServerBurstDownstreamDeadline = "ServerBurstDownstreamDeadline"
  264. ServerBurstDownstreamTargetBytes = "ServerBurstDownstreamTargetBytes"
  265. ClientBurstUpstreamDeadline = "ClientBurstUpstreamDeadline"
  266. ClientBurstUpstreamTargetBytes = "ClientBurstUpstreamTargetBytes"
  267. ClientBurstDownstreamDeadline = "ClientBurstDownstreamDeadline"
  268. ClientBurstDownstreamTargetBytes = "ClientBurstDownstreamTargetBytes"
  269. ConjureCachedRegistrationTTL = "ConjureCachedRegistrationTTL"
  270. ConjureAPIRegistrarURL = "ConjureAPIRegistrarURL"
  271. ConjureAPIRegistrarBidirectionalURL = "ConjureAPIRegistrarBidirectionalURL"
  272. ConjureAPIRegistrarFrontingSpecs = "ConjureAPIRegistrarFrontingSpecs"
  273. ConjureAPIRegistrarMinDelay = "ConjureAPIRegistrarMinDelay"
  274. ConjureAPIRegistrarMaxDelay = "ConjureAPIRegistrarMaxDelay"
  275. ConjureDecoyRegistrarProbability = "ConjureDecoyRegistrarProbability"
  276. ConjureDecoyRegistrarWidth = "ConjureDecoyRegistrarWidth"
  277. ConjureDecoyRegistrarMinDelay = "ConjureDecoyRegistrarMinDelay"
  278. ConjureDecoyRegistrarMaxDelay = "ConjureDecoyRegistrarMaxDelay"
  279. ConjureTransportObfs4Probability = "ConjureTransportObfs4Probability"
  280. CustomHostNameRegexes = "CustomHostNameRegexes"
  281. CustomHostNameProbability = "CustomHostNameProbability"
  282. CustomHostNameLimitProtocols = "CustomHostNameLimitProtocols"
  283. HoldOffTunnelMinDuration = "HoldOffTunnelMinDuration"
  284. HoldOffTunnelMaxDuration = "HoldOffTunnelMaxDuration"
  285. HoldOffTunnelProtocols = "HoldOffTunnelProtocols"
  286. HoldOffTunnelFrontingProviderIDs = "HoldOffTunnelFrontingProviderIDs"
  287. HoldOffTunnelProbability = "HoldOffTunnelProbability"
  288. RestrictFrontingProviderIDs = "RestrictFrontingProviderIDs"
  289. RestrictFrontingProviderIDsServerProbability = "RestrictFrontingProviderIDsServerProbability"
  290. RestrictFrontingProviderIDsClientProbability = "RestrictFrontingProviderIDsClientProbability"
  291. UpstreamProxyAllowAllServerEntrySources = "UpstreamProxyAllowAllServerEntrySources"
  292. )
  293. const (
  294. useNetworkLatencyMultiplier = 1
  295. serverSideOnly = 2
  296. )
  297. // defaultParameters specifies the type, default value, and minimum value for
  298. // all dynamically configurable client and server parameters.
  299. //
  300. // Do not change the names or types of existing values, as that can break
  301. // client logic or cause parameters to not be applied.
  302. //
  303. // Minimum values are a fail-safe for cases where lower values would break the
  304. // client logic. For example, setting a ConnectionWorkerPoolSize of 0 would
  305. // make the client never connect.
  306. var defaultParameters = map[string]struct {
  307. value interface{}
  308. minimum interface{}
  309. flags int32
  310. }{
  311. // NetworkLatencyMultiplier defaults to 0, meaning off. But when set, it
  312. // must be a multiplier >= 1.
  313. NetworkLatencyMultiplier: {value: 0.0, minimum: 1.0},
  314. NetworkLatencyMultiplierMin: {value: 1.0, minimum: 1.0},
  315. NetworkLatencyMultiplierMax: {value: 3.0, minimum: 1.0},
  316. NetworkLatencyMultiplierLambda: {value: 2.0, minimum: 0.001},
  317. TacticsWaitPeriod: {value: 10 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  318. TacticsRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  319. TacticsRetryPeriodJitter: {value: 0.3, minimum: 0.0},
  320. TacticsTimeout: {value: 2 * time.Minute, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  321. ConnectionWorkerPoolSize: {value: 10, minimum: 1},
  322. TunnelPoolSize: {value: 1, minimum: 1},
  323. TunnelConnectTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  324. EstablishTunnelTimeout: {value: 300 * time.Second, minimum: time.Duration(0)},
  325. EstablishTunnelWorkTime: {value: 60 * time.Second, minimum: 1 * time.Second},
  326. EstablishTunnelPausePeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  327. EstablishTunnelPausePeriodJitter: {value: 0.1, minimum: 0.0},
  328. EstablishTunnelServerAffinityGracePeriod: {value: 1 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  329. StaggerConnectionWorkersPeriod: {value: time.Duration(0), minimum: time.Duration(0)},
  330. StaggerConnectionWorkersJitter: {value: 0.1, minimum: 0.0},
  331. LimitIntensiveConnectionWorkers: {value: 0, minimum: 0},
  332. UpstreamProxyErrorMinWaitDuration: {value: 10 * time.Second, minimum: time.Duration(0)},
  333. UpstreamProxyErrorMaxWaitDuration: {value: 30 * time.Second, minimum: time.Duration(0)},
  334. IgnoreHandshakeStatsRegexps: {value: false},
  335. TunnelOperateShutdownTimeout: {value: 1 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  336. TunnelPortForwardDialTimeout: {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  337. PacketTunnelReadTimeout: {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  338. TunnelRateLimits: {value: common.RateLimits{}},
  339. // PrioritizeTunnelProtocols parameters are obsoleted by InitialLimitTunnelProtocols.
  340. // TODO: remove once no longer required for older clients.
  341. PrioritizeTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  342. PrioritizeTunnelProtocols: {value: protocol.TunnelProtocols{}},
  343. PrioritizeTunnelProtocolsCandidateCount: {value: 10, minimum: 0},
  344. InitialLimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  345. InitialLimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  346. InitialLimitTunnelProtocolsCandidateCount: {value: 0, minimum: 0},
  347. LimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  348. LimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  349. LimitTunnelDialPortNumbersProbability: {value: 1.0, minimum: 0.0},
  350. LimitTunnelDialPortNumbers: {value: TunnelProtocolPortLists{}},
  351. LimitTLSProfilesProbability: {value: 1.0, minimum: 0.0},
  352. LimitTLSProfiles: {value: protocol.TLSProfiles{}},
  353. UseOnlyCustomTLSProfiles: {value: false},
  354. CustomTLSProfiles: {value: protocol.CustomTLSProfiles{}},
  355. SelectRandomizedTLSProfileProbability: {value: 0.25, minimum: 0.0},
  356. NoDefaultTLSSessionIDProbability: {value: 0.5, minimum: 0.0},
  357. DisableFrontingProviderTLSProfiles: {value: protocol.LabeledTLSProfiles{}},
  358. LimitQUICVersionsProbability: {value: 1.0, minimum: 0.0},
  359. LimitQUICVersions: {value: protocol.QUICVersions{}},
  360. DisableFrontingProviderQUICVersions: {value: protocol.LabeledQUICVersions{}},
  361. QUICDisableClientPathMTUDiscoveryProbability: {value: 0.0, minimum: 0.0},
  362. FragmentorProbability: {value: 0.5, minimum: 0.0},
  363. FragmentorLimitProtocols: {value: protocol.TunnelProtocols{}},
  364. FragmentorMinTotalBytes: {value: 0, minimum: 0},
  365. FragmentorMaxTotalBytes: {value: 0, minimum: 0},
  366. FragmentorMinWriteBytes: {value: 1, minimum: 1},
  367. FragmentorMaxWriteBytes: {value: 1500, minimum: 1},
  368. FragmentorMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  369. FragmentorMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0)},
  370. FragmentorDownstreamProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  371. FragmentorDownstreamLimitProtocols: {value: protocol.TunnelProtocols{}, flags: serverSideOnly},
  372. FragmentorDownstreamMinTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  373. FragmentorDownstreamMaxTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  374. FragmentorDownstreamMinWriteBytes: {value: 1, minimum: 1, flags: serverSideOnly},
  375. FragmentorDownstreamMaxWriteBytes: {value: 1500, minimum: 1, flags: serverSideOnly},
  376. FragmentorDownstreamMinDelay: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  377. FragmentorDownstreamMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0), flags: serverSideOnly},
  378. // The Psiphon server will reject obfuscated SSH seed messages with
  379. // padding greater than OBFUSCATE_MAX_PADDING.
  380. // obfuscator.NewClientObfuscator will ignore invalid min/max padding
  381. // configurations.
  382. ObfuscatedSSHMinPadding: {value: 0, minimum: 0},
  383. ObfuscatedSSHMaxPadding: {value: obfuscator.OBFUSCATE_MAX_PADDING, minimum: 0},
  384. AdditionalCustomHeaders: {value: make(http.Header)},
  385. // Speed test and SSH keep alive padding is intended to frustrate
  386. // fingerprinting and should not exceed ~1 IP packet size.
  387. //
  388. // Currently, each serialized speed test sample, populated with real
  389. // values, is approximately 100 bytes. All SpeedTestMaxSampleCount samples
  390. // are loaded into memory are sent as API inputs.
  391. SpeedTestPaddingMinBytes: {value: 0, minimum: 0},
  392. SpeedTestPaddingMaxBytes: {value: 256, minimum: 0},
  393. SpeedTestMaxSampleCount: {value: 25, minimum: 1},
  394. // The Psiphon server times out inactive tunnels after 5 minutes, so this
  395. // is a soft max for SSHKeepAlivePeriodMax.
  396. SSHKeepAliveSpeedTestSampleProbability: {value: 0.5, minimum: 0.0},
  397. SSHKeepAlivePaddingMinBytes: {value: 0, minimum: 0},
  398. SSHKeepAlivePaddingMaxBytes: {value: 256, minimum: 0},
  399. SSHKeepAlivePeriodMin: {value: 1 * time.Minute, minimum: 1 * time.Second},
  400. SSHKeepAlivePeriodMax: {value: 2 * time.Minute, minimum: 1 * time.Second},
  401. SSHKeepAlivePeriodicTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  402. SSHKeepAlivePeriodicInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  403. SSHKeepAliveProbeTimeout: {value: 5 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  404. SSHKeepAliveProbeInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  405. SSHKeepAliveNetworkConnectivityPollingPeriod: {value: 500 * time.Millisecond, minimum: 1 * time.Millisecond},
  406. SSHKeepAliveResetOnFailureProbability: {value: 0.0, minimum: 0.0},
  407. HTTPProxyOriginServerTimeout: {value: 15 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  408. HTTPProxyMaxIdleConnectionsPerHost: {value: 50, minimum: 0},
  409. FetchRemoteServerListTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  410. FetchRemoteServerListRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  411. FetchRemoteServerListStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  412. RemoteServerListSignaturePublicKey: {value: ""},
  413. RemoteServerListURLs: {value: TransferURLs{}},
  414. ObfuscatedServerListRootURLs: {value: TransferURLs{}},
  415. PsiphonAPIRequestTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  416. PsiphonAPIStatusRequestPeriodMin: {value: 5 * time.Minute, minimum: 1 * time.Second},
  417. PsiphonAPIStatusRequestPeriodMax: {value: 10 * time.Minute, minimum: 1 * time.Second},
  418. PsiphonAPIStatusRequestShortPeriodMin: {value: 5 * time.Second, minimum: 1 * time.Second},
  419. PsiphonAPIStatusRequestShortPeriodMax: {value: 10 * time.Second, minimum: 1 * time.Second},
  420. // PsiphonAPIPersistentStatsMaxCount parameter is obsoleted by PersistentStatsMaxSendBytes.
  421. // TODO: remove once no longer required for older clients.
  422. PsiphonAPIPersistentStatsMaxCount: {value: 100, minimum: 1},
  423. // PsiphonAPIStatusRequestPadding parameters are obsoleted by APIRequestUp/DownstreamPadding.
  424. // TODO: remove once no longer required for older clients.
  425. PsiphonAPIStatusRequestPaddingMinBytes: {value: 0, minimum: 0},
  426. PsiphonAPIStatusRequestPaddingMaxBytes: {value: 256, minimum: 0},
  427. PsiphonAPIConnectedRequestRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  428. // FetchSplitTunnelRoutesTimeout, SplitTunnelRoutesURLFormat,
  429. // SplitTunnelRoutesSignaturePublicKey and SplitTunnelDNSServer are obsoleted
  430. // by the server-assisted split tunnel implementation.
  431. // TODO: remove once no longer required for older clients.
  432. FetchSplitTunnelRoutesTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  433. SplitTunnelRoutesURLFormat: {value: ""},
  434. SplitTunnelRoutesSignaturePublicKey: {value: ""},
  435. SplitTunnelDNSServer: {value: ""},
  436. SplitTunnelClassificationTTL: {value: 24 * time.Hour, minimum: 0 * time.Second},
  437. SplitTunnelClassificationMaxEntries: {value: 65536, minimum: 0},
  438. FetchUpgradeTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  439. FetchUpgradeRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  440. FetchUpgradeStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  441. UpgradeDownloadURLs: {value: TransferURLs{}},
  442. UpgradeDownloadClientVersionHeader: {value: ""},
  443. TotalBytesTransferredNoticePeriod: {value: 5 * time.Minute, minimum: 1 * time.Second},
  444. TotalBytesTransferredEmitMemoryMetrics: {value: true},
  445. // The meek server times out inactive sessions after 45 seconds, so this
  446. // is a soft max for MeekMaxPollInterval, MeekRoundTripTimeout, and
  447. // MeekRoundTripRetryDeadline.
  448. //
  449. // MeekCookieMaxPadding cannot exceed common.OBFUSCATE_SEED_LENGTH.
  450. //
  451. // MeekMinTLSPadding/MeekMinTLSPadding are subject to TLS server limitations.
  452. //
  453. // MeekMinLimitRequestPayloadLength/MeekMaxLimitRequestPayloadLength
  454. // cannot exceed server.MEEK_MAX_REQUEST_PAYLOAD_LENGTH.
  455. MeekDialDomainsOnly: {value: false},
  456. MeekLimitBufferSizes: {value: false},
  457. MeekCookieMaxPadding: {value: 256, minimum: 0},
  458. MeekFullReceiveBufferLength: {value: 4194304, minimum: 1024},
  459. MeekReadPayloadChunkLength: {value: 65536, minimum: 1024},
  460. MeekLimitedFullReceiveBufferLength: {value: 131072, minimum: 1024},
  461. MeekLimitedReadPayloadChunkLength: {value: 4096, minimum: 1024},
  462. MeekMinPollInterval: {value: 100 * time.Millisecond, minimum: 1 * time.Millisecond},
  463. MeekMinPollIntervalJitter: {value: 0.3, minimum: 0.0},
  464. MeekMaxPollInterval: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  465. MeekMaxPollIntervalJitter: {value: 0.1, minimum: 0.0},
  466. MeekPollIntervalMultiplier: {value: 1.5, minimum: 0.0},
  467. MeekPollIntervalJitter: {value: 0.1, minimum: 0.0},
  468. MeekApplyPollIntervalMultiplierProbability: {value: 0.5},
  469. MeekRoundTripRetryDeadline: {value: 5 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  470. MeekRoundTripRetryMinDelay: {value: 50 * time.Millisecond, minimum: time.Duration(0)},
  471. MeekRoundTripRetryMaxDelay: {value: 1 * time.Second, minimum: time.Duration(0)},
  472. MeekRoundTripRetryMultiplier: {value: 2.0, minimum: 0.0},
  473. MeekRoundTripTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  474. MeekTrafficShapingProbability: {value: 1.0, minimum: 0.0},
  475. MeekTrafficShapingLimitProtocols: {value: protocol.TunnelProtocols{}},
  476. MeekMinTLSPadding: {value: 0, minimum: 0},
  477. MeekMaxTLSPadding: {value: 0, minimum: 0},
  478. MeekMinLimitRequestPayloadLength: {value: 65536, minimum: 1},
  479. MeekMaxLimitRequestPayloadLength: {value: 65536, minimum: 1},
  480. MeekRedialTLSProbability: {value: 0.0, minimum: 0.0},
  481. TransformHostNameProbability: {value: 0.5, minimum: 0.0},
  482. PickUserAgentProbability: {value: 0.5, minimum: 0.0},
  483. LivenessTestMinUpstreamBytes: {value: 0, minimum: 0},
  484. LivenessTestMaxUpstreamBytes: {value: 0, minimum: 0},
  485. LivenessTestMinDownstreamBytes: {value: 0, minimum: 0},
  486. LivenessTestMaxDownstreamBytes: {value: 0, minimum: 0},
  487. ReplayCandidateCount: {value: 10, minimum: -1},
  488. ReplayDialParametersTTL: {value: 24 * time.Hour, minimum: time.Duration(0)},
  489. ReplayTargetUpstreamBytes: {value: 0, minimum: 0},
  490. ReplayTargetDownstreamBytes: {value: 0, minimum: 0},
  491. ReplayTargetTunnelDuration: {value: 1 * time.Second, minimum: time.Duration(0)},
  492. ReplayBPF: {value: true},
  493. ReplaySSH: {value: true},
  494. ReplayObfuscatorPadding: {value: true},
  495. ReplayFragmentor: {value: true},
  496. ReplayTLSProfile: {value: true},
  497. ReplayRandomizedTLSProfile: {value: true},
  498. ReplayFronting: {value: true},
  499. ReplayHostname: {value: true},
  500. ReplayQUICVersion: {value: true},
  501. ReplayObfuscatedQUIC: {value: true},
  502. ReplayConjureRegistration: {value: true},
  503. ReplayConjureTransport: {value: true},
  504. ReplayLivenessTest: {value: true},
  505. ReplayUserAgent: {value: true},
  506. ReplayAPIRequestPadding: {value: true},
  507. ReplayLaterRoundMoveToFrontProbability: {value: 0.0, minimum: 0.0},
  508. ReplayRetainFailedProbability: {value: 0.5, minimum: 0.0},
  509. ReplayHoldOffTunnel: {value: true},
  510. APIRequestUpstreamPaddingMinBytes: {value: 0, minimum: 0},
  511. APIRequestUpstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  512. APIRequestDownstreamPaddingMinBytes: {value: 0, minimum: 0},
  513. APIRequestDownstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  514. PersistentStatsMaxStoreRecords: {value: 200, minimum: 1},
  515. PersistentStatsMaxSendBytes: {value: 65536, minimum: 1},
  516. RecordRemoteServerListPersistentStatsProbability: {value: 1.0, minimum: 0.0},
  517. RecordFailedTunnelPersistentStatsProbability: {value: 0.0, minimum: 0.0},
  518. ServerEntryMinimumAgeForPruning: {value: 7 * 24 * time.Hour, minimum: 24 * time.Hour},
  519. ApplicationParametersProbability: {value: 1.0, minimum: 0.0},
  520. ApplicationParameters: {value: KeyValues{}},
  521. BPFServerTCPProgram: {value: (*BPFProgramSpec)(nil), flags: serverSideOnly},
  522. BPFServerTCPProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  523. BPFClientTCPProgram: {value: (*BPFProgramSpec)(nil)},
  524. BPFClientTCPProbability: {value: 0.5, minimum: 0.0},
  525. ServerPacketManipulationSpecs: {value: PacketManipulationSpecs{}, flags: serverSideOnly},
  526. ServerProtocolPacketManipulations: {value: make(ProtocolPacketManipulations), flags: serverSideOnly},
  527. ServerPacketManipulationProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  528. FeedbackUploadURLs: {value: TransferURLs{}},
  529. FeedbackEncryptionPublicKey: {value: ""},
  530. FeedbackTacticsWaitPeriod: {value: 5 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  531. FeedbackUploadMaxAttempts: {value: 5, minimum: 0},
  532. FeedbackUploadRetryMinDelaySeconds: {value: 1 * time.Minute, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  533. FeedbackUploadRetryMaxDelaySeconds: {value: 5 * time.Minute, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  534. FeedbackUploadTimeoutSeconds: {value: 30 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  535. ServerReplayPacketManipulation: {value: true, flags: serverSideOnly},
  536. ServerReplayFragmentor: {value: true, flags: serverSideOnly},
  537. ServerReplayUnknownGeoIP: {value: false, flags: serverSideOnly},
  538. ServerReplayTTL: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  539. ServerReplayTargetWaitDuration: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  540. ServerReplayTargetTunnelDuration: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  541. ServerReplayTargetUpstreamBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  542. ServerReplayTargetDownstreamBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  543. ServerReplayFailedCountThreshold: {value: 0, minimum: 0, flags: serverSideOnly},
  544. ServerBurstUpstreamTargetBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  545. ServerBurstUpstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  546. ServerBurstDownstreamTargetBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  547. ServerBurstDownstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  548. ClientBurstUpstreamTargetBytes: {value: 0, minimum: 0},
  549. ClientBurstUpstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0)},
  550. ClientBurstDownstreamTargetBytes: {value: 0, minimum: 0},
  551. ClientBurstDownstreamDeadline: {value: time.Duration(0), minimum: time.Duration(0)},
  552. ConjureCachedRegistrationTTL: {value: time.Duration(0), minimum: time.Duration(0)},
  553. // ConjureAPIRegistrarURL parameter is obsoleted by ConjureAPIRegistrarBidirectionalURL.
  554. // TODO: remove once no longer required for older clients.
  555. ConjureAPIRegistrarURL: {value: ""},
  556. ConjureAPIRegistrarBidirectionalURL: {value: ""},
  557. ConjureAPIRegistrarFrontingSpecs: {value: FrontingSpecs{}},
  558. ConjureAPIRegistrarMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  559. ConjureAPIRegistrarMaxDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  560. ConjureDecoyRegistrarProbability: {value: 0.0, minimum: 0.0},
  561. ConjureDecoyRegistrarWidth: {value: 5, minimum: 0},
  562. ConjureDecoyRegistrarMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  563. ConjureDecoyRegistrarMaxDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  564. ConjureTransportObfs4Probability: {value: 0.0, minimum: 0.0},
  565. CustomHostNameRegexes: {value: RegexStrings{}},
  566. CustomHostNameProbability: {value: 0.0, minimum: 0.0},
  567. CustomHostNameLimitProtocols: {value: protocol.TunnelProtocols{}},
  568. HoldOffTunnelMinDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  569. HoldOffTunnelMaxDuration: {value: time.Duration(0), minimum: time.Duration(0)},
  570. HoldOffTunnelProtocols: {value: protocol.TunnelProtocols{}},
  571. HoldOffTunnelFrontingProviderIDs: {value: []string{}},
  572. HoldOffTunnelProbability: {value: 0.0, minimum: 0.0},
  573. RestrictFrontingProviderIDs: {value: []string{}},
  574. RestrictFrontingProviderIDsServerProbability: {value: 0.0, minimum: 0.0, flags: serverSideOnly},
  575. RestrictFrontingProviderIDsClientProbability: {value: 0.0, minimum: 0.0},
  576. UpstreamProxyAllowAllServerEntrySources: {value: false},
  577. }
  578. // IsServerSideOnly indicates if the parameter specified by name is used
  579. // server-side only.
  580. func IsServerSideOnly(name string) bool {
  581. defaultParameter, ok := defaultParameters[name]
  582. return ok && (defaultParameter.flags&serverSideOnly) != 0
  583. }
  584. // Parameters is a set of parameters. To use the parameters, call Get. To
  585. // apply new values to the parameters, call Set.
  586. type Parameters struct {
  587. getValueLogger func(error)
  588. snapshot atomic.Value
  589. }
  590. // NewParameters initializes a new Parameters with the default parameter
  591. // values.
  592. //
  593. // getValueLogger is optional, and is used to report runtime errors with
  594. // getValue; see comment in getValue.
  595. func NewParameters(
  596. getValueLogger func(error)) (*Parameters, error) {
  597. parameters := &Parameters{
  598. getValueLogger: getValueLogger,
  599. }
  600. _, err := parameters.Set("", false)
  601. if err != nil {
  602. return nil, errors.Trace(err)
  603. }
  604. return parameters, nil
  605. }
  606. func makeDefaultParameters() (map[string]interface{}, error) {
  607. parameters := make(map[string]interface{})
  608. for name, defaults := range defaultParameters {
  609. if defaults.value == nil {
  610. return nil, errors.Tracef("default parameter missing value: %s", name)
  611. }
  612. if defaults.minimum != nil &&
  613. reflect.TypeOf(defaults.value) != reflect.TypeOf(defaults.minimum) {
  614. return nil, errors.Tracef("default parameter value and minimum type mismatch: %s", name)
  615. }
  616. _, isDuration := defaults.value.(time.Duration)
  617. if defaults.flags&useNetworkLatencyMultiplier != 0 && !isDuration {
  618. return nil, errors.Tracef("default non-duration parameter uses multipler: %s", name)
  619. }
  620. parameters[name] = defaults.value
  621. }
  622. return parameters, nil
  623. }
  624. // Set replaces the current parameters. First, a set of parameters are
  625. // initialized using the default values. Then, each applyParameters is applied
  626. // in turn, with the later instances having precedence.
  627. //
  628. // When skipOnError is true, unknown or invalid parameters in any
  629. // applyParameters are skipped instead of aborting with an error.
  630. //
  631. // For protocol.TunnelProtocols and protocol.TLSProfiles type values, when
  632. // skipOnError is true the values are filtered instead of validated, so
  633. // only known tunnel protocols and TLS profiles are retained.
  634. //
  635. // When an error is returned, the previous parameters remain completely
  636. // unmodified.
  637. //
  638. // For use in logging, Set returns a count of the number of parameters applied
  639. // from each applyParameters.
  640. func (p *Parameters) Set(
  641. tag string, skipOnError bool, applyParameters ...map[string]interface{}) ([]int, error) {
  642. makeTypedValue := func(templateValue, value interface{}) (interface{}, error) {
  643. // Accept strings such as "1h" for duration parameters.
  644. switch templateValue.(type) {
  645. case time.Duration:
  646. if s, ok := value.(string); ok {
  647. if d, err := time.ParseDuration(s); err == nil {
  648. value = d
  649. }
  650. }
  651. }
  652. // A JSON remarshal resolves cases where applyParameters is a
  653. // result of unmarshal-into-interface, in which case non-scalar
  654. // values will not have the expected types; see:
  655. // https://golang.org/pkg/encoding/json/#Unmarshal. This remarshal
  656. // also results in a deep copy.
  657. marshaledValue, err := json.Marshal(value)
  658. if err != nil {
  659. return nil, errors.Trace(err)
  660. }
  661. newValuePtr := reflect.New(reflect.TypeOf(templateValue))
  662. err = json.Unmarshal(marshaledValue, newValuePtr.Interface())
  663. if err != nil {
  664. return nil, errors.Trace(err)
  665. }
  666. return newValuePtr.Elem().Interface(), nil
  667. }
  668. getAppliedValue := func(
  669. name string,
  670. parameters map[string]interface{},
  671. applyParameters []map[string]interface{}) (interface{}, error) {
  672. templateValue := parameters[name]
  673. if templateValue == nil {
  674. return nil, errors.Tracef("unknown parameter: %s", name)
  675. }
  676. value := templateValue
  677. for i := len(applyParameters) - 1; i >= 0; i-- {
  678. if v := applyParameters[i][name]; v != nil {
  679. value = v
  680. break
  681. }
  682. }
  683. return makeTypedValue(templateValue, value)
  684. }
  685. var counts []int
  686. parameters, err := makeDefaultParameters()
  687. if err != nil {
  688. return nil, errors.Trace(err)
  689. }
  690. // Special case: TLSProfiles/LabeledTLSProfiles may reference
  691. // CustomTLSProfiles names. Inspect the CustomTLSProfiles parameter and
  692. // extract its names. Do not call Get().CustomTLSProfilesNames() as
  693. // CustomTLSProfiles may not yet be validated.
  694. customTLSProfilesValue, err := getAppliedValue(
  695. CustomTLSProfiles, parameters, applyParameters)
  696. if err != nil {
  697. return nil, errors.Trace(err)
  698. }
  699. customTLSProfiles, _ := customTLSProfilesValue.(protocol.CustomTLSProfiles)
  700. customTLSProfileNames := make([]string, len(customTLSProfiles))
  701. for i, profile := range customTLSProfiles {
  702. customTLSProfileNames[i] = profile.Name
  703. }
  704. // Special case: PacketManipulations will reference PacketManipulationSpecs.
  705. serverPacketManipulationSpecsValue, err := getAppliedValue(
  706. ServerPacketManipulationSpecs, parameters, applyParameters)
  707. if err != nil {
  708. return nil, errors.Trace(err)
  709. }
  710. serverPacketManipulationSpecs, _ :=
  711. serverPacketManipulationSpecsValue.(PacketManipulationSpecs)
  712. for i := 0; i < len(applyParameters); i++ {
  713. count := 0
  714. for name, value := range applyParameters[i] {
  715. templateValue, ok := parameters[name]
  716. if !ok {
  717. if skipOnError {
  718. continue
  719. }
  720. return nil, errors.Tracef("unknown parameter: %s", name)
  721. }
  722. newValue, err := makeTypedValue(templateValue, value)
  723. if err != nil {
  724. if skipOnError {
  725. continue
  726. }
  727. return nil, errors.Tracef(
  728. "unmarshal parameter %s failed: %v", name, err)
  729. }
  730. // Perform type-specific validation for some cases.
  731. // TODO: require RemoteServerListSignaturePublicKey when
  732. // RemoteServerListURLs is set?
  733. switch v := newValue.(type) {
  734. case TransferURLs:
  735. err := v.DecodeAndValidate()
  736. if err != nil {
  737. if skipOnError {
  738. continue
  739. }
  740. return nil, errors.Trace(err)
  741. }
  742. case protocol.TunnelProtocols:
  743. if skipOnError {
  744. newValue = v.PruneInvalid()
  745. } else {
  746. err := v.Validate()
  747. if err != nil {
  748. return nil, errors.Trace(err)
  749. }
  750. }
  751. case protocol.TLSProfiles:
  752. if skipOnError {
  753. newValue = v.PruneInvalid(customTLSProfileNames)
  754. } else {
  755. err := v.Validate(customTLSProfileNames)
  756. if err != nil {
  757. return nil, errors.Trace(err)
  758. }
  759. }
  760. case protocol.LabeledTLSProfiles:
  761. if skipOnError {
  762. newValue = v.PruneInvalid(customTLSProfileNames)
  763. } else {
  764. err := v.Validate(customTLSProfileNames)
  765. if err != nil {
  766. return nil, errors.Trace(err)
  767. }
  768. }
  769. case protocol.QUICVersions:
  770. if skipOnError {
  771. newValue = v.PruneInvalid()
  772. } else {
  773. err := v.Validate()
  774. if err != nil {
  775. return nil, errors.Trace(err)
  776. }
  777. }
  778. case protocol.LabeledQUICVersions:
  779. if skipOnError {
  780. newValue = v.PruneInvalid()
  781. } else {
  782. err := v.Validate()
  783. if err != nil {
  784. return nil, errors.Trace(err)
  785. }
  786. }
  787. case protocol.CustomTLSProfiles:
  788. err := v.Validate()
  789. if err != nil {
  790. if skipOnError {
  791. continue
  792. }
  793. return nil, errors.Trace(err)
  794. }
  795. case KeyValues:
  796. err := v.Validate()
  797. if err != nil {
  798. if skipOnError {
  799. continue
  800. }
  801. return nil, errors.Trace(err)
  802. }
  803. case *BPFProgramSpec:
  804. if v != nil {
  805. err := v.Validate()
  806. if err != nil {
  807. if skipOnError {
  808. continue
  809. }
  810. return nil, errors.Trace(err)
  811. }
  812. }
  813. case PacketManipulationSpecs:
  814. err := v.Validate()
  815. if err != nil {
  816. if skipOnError {
  817. continue
  818. }
  819. return nil, errors.Trace(err)
  820. }
  821. case ProtocolPacketManipulations:
  822. var packetManipulationSpecs PacketManipulationSpecs
  823. if name == ServerProtocolPacketManipulations {
  824. packetManipulationSpecs = serverPacketManipulationSpecs
  825. }
  826. err := v.Validate(packetManipulationSpecs)
  827. if err != nil {
  828. if skipOnError {
  829. continue
  830. }
  831. return nil, errors.Trace(err)
  832. }
  833. case RegexStrings:
  834. err := v.Validate()
  835. if err != nil {
  836. if skipOnError {
  837. continue
  838. }
  839. return nil, errors.Trace(err)
  840. }
  841. case FrontingSpecs:
  842. err := v.Validate()
  843. if err != nil {
  844. if skipOnError {
  845. continue
  846. }
  847. return nil, errors.Trace(err)
  848. }
  849. case TunnelProtocolPortLists:
  850. err := v.Validate()
  851. if err != nil {
  852. if skipOnError {
  853. continue
  854. }
  855. return nil, errors.Trace(err)
  856. }
  857. }
  858. // Enforce any minimums. Assumes defaultParameters[name]
  859. // exists.
  860. if defaultParameters[name].minimum != nil {
  861. valid := true
  862. switch v := newValue.(type) {
  863. case int:
  864. m, ok := defaultParameters[name].minimum.(int)
  865. if !ok || v < m {
  866. valid = false
  867. }
  868. case float64:
  869. m, ok := defaultParameters[name].minimum.(float64)
  870. if !ok || v < m {
  871. valid = false
  872. }
  873. case time.Duration:
  874. m, ok := defaultParameters[name].minimum.(time.Duration)
  875. if !ok || v < m {
  876. valid = false
  877. }
  878. default:
  879. if skipOnError {
  880. continue
  881. }
  882. return nil, errors.Tracef("unexpected parameter with minimum: %s", name)
  883. }
  884. if !valid {
  885. if skipOnError {
  886. continue
  887. }
  888. return nil, errors.Tracef("parameter below minimum: %s", name)
  889. }
  890. }
  891. parameters[name] = newValue
  892. count++
  893. }
  894. counts = append(counts, count)
  895. }
  896. snapshot := &parametersSnapshot{
  897. getValueLogger: p.getValueLogger,
  898. tag: tag,
  899. parameters: parameters,
  900. }
  901. p.snapshot.Store(snapshot)
  902. return counts, nil
  903. }
  904. // Get returns the current parameters.
  905. //
  906. // Values read from the current parameters are not deep copies and must be
  907. // treated read-only.
  908. //
  909. // The returned ParametersAccessor may be used to read multiple related values
  910. // atomically and consistently while the current set of values in Parameters
  911. // may change concurrently.
  912. //
  913. // Get does not perform any heap allocations and is intended for repeated,
  914. // direct, low-overhead invocations.
  915. func (p *Parameters) Get() ParametersAccessor {
  916. return ParametersAccessor{
  917. snapshot: p.snapshot.Load().(*parametersSnapshot)}
  918. }
  919. // GetCustom returns the current parameters while also setting customizations
  920. // for this instance.
  921. //
  922. // The properties of Get also apply to GetCustom: must be read-only; atomic
  923. // and consisent view; no heap allocations.
  924. //
  925. // Customizations include:
  926. //
  927. // - customNetworkLatencyMultiplier, which overrides NetworkLatencyMultiplier
  928. // for this instance only.
  929. //
  930. func (p *Parameters) GetCustom(
  931. customNetworkLatencyMultiplier float64) ParametersAccessor {
  932. return ParametersAccessor{
  933. snapshot: p.snapshot.Load().(*parametersSnapshot),
  934. customNetworkLatencyMultiplier: customNetworkLatencyMultiplier,
  935. }
  936. }
  937. // parametersSnapshot is an atomic snapshot of the parameter values.
  938. // Parameters.Get will return a snapshot which may be used to read multiple
  939. // related values atomically and consistently while the current snapshot in
  940. // Parameters may change concurrently.
  941. type parametersSnapshot struct {
  942. getValueLogger func(error)
  943. tag string
  944. parameters map[string]interface{}
  945. }
  946. // getValue sets target to the value of the named parameter.
  947. //
  948. // It is an error if the name is not found, target is not a pointer, or the
  949. // type of target points to does not match the value.
  950. //
  951. // Any of these conditions would be a bug in the caller. getValue does not
  952. // panic in these cases as clients are deployed as a library in various apps
  953. // and the failure of Psiphon may not be a failure for the app process.
  954. //
  955. // Instead, errors are logged to the getValueLogger and getValue leaves the
  956. // target unset, which will result in the caller getting and using a zero
  957. // value of the requested type.
  958. func (p *parametersSnapshot) getValue(name string, target interface{}) {
  959. value, ok := p.parameters[name]
  960. if !ok {
  961. if p.getValueLogger != nil {
  962. p.getValueLogger(errors.Tracef(
  963. "value %s not found", name))
  964. }
  965. return
  966. }
  967. valueType := reflect.TypeOf(value)
  968. if reflect.PtrTo(valueType) != reflect.TypeOf(target) {
  969. if p.getValueLogger != nil {
  970. p.getValueLogger(errors.Tracef(
  971. "value %s has unexpected type %s", name, valueType.Name()))
  972. }
  973. return
  974. }
  975. // Note: there is no deep copy of parameter values; the returned value may
  976. // share memory with the original and should not be modified.
  977. targetValue := reflect.ValueOf(target)
  978. if targetValue.Kind() != reflect.Ptr {
  979. p.getValueLogger(errors.Tracef(
  980. "target for value %s is not pointer", name))
  981. return
  982. }
  983. targetValue.Elem().Set(reflect.ValueOf(value))
  984. }
  985. // ParametersAccessor provides consistent, atomic access to parameter values.
  986. // Any customizations are applied transparently.
  987. type ParametersAccessor struct {
  988. snapshot *parametersSnapshot
  989. customNetworkLatencyMultiplier float64
  990. }
  991. // MakeNilParametersAccessor produces a stub ParametersAccessor which returns
  992. // true for IsNil. This may be used where a ParametersAccessor value is
  993. // required, but Parameters.Get may not succeed. In contexts where
  994. // MakeNilParametersAccessor may be used, calls to ParametersAccessor must
  995. // first check IsNil before calling accessor functions.
  996. func MakeNilParametersAccessor() ParametersAccessor {
  997. return ParametersAccessor{}
  998. }
  999. // IsNil indicates that this ParametersAccessor is a stub and its accessor
  1000. // functions may not be called. A ParametersAccessor produced by
  1001. // Parameters.Get will never return true for IsNil and IsNil guards are not
  1002. // required for ParametersAccessors known to be produced by Parameters.Get.
  1003. func (p ParametersAccessor) IsNil() bool {
  1004. return p.snapshot == nil
  1005. }
  1006. // Close clears internal references to large memory objects, allowing them to
  1007. // be garbage collected. Call Close when done using a ParametersAccessor,
  1008. // where memory footprint is a concern, and where the ParametersAccessor is
  1009. // not immediately going out of scope. After Close is called, all other
  1010. // ParametersAccessor functions will panic if called.
  1011. func (p ParametersAccessor) Close() {
  1012. p.snapshot = nil
  1013. }
  1014. // Tag returns the tag associated with these parameters.
  1015. func (p ParametersAccessor) Tag() string {
  1016. return p.snapshot.tag
  1017. }
  1018. // String returns a string parameter value.
  1019. func (p ParametersAccessor) String(name string) string {
  1020. value := ""
  1021. p.snapshot.getValue(name, &value)
  1022. return value
  1023. }
  1024. func (p ParametersAccessor) Strings(name string) []string {
  1025. value := []string{}
  1026. p.snapshot.getValue(name, &value)
  1027. return value
  1028. }
  1029. // Int returns an int parameter value.
  1030. func (p ParametersAccessor) Int(name string) int {
  1031. value := int(0)
  1032. p.snapshot.getValue(name, &value)
  1033. return value
  1034. }
  1035. // Bool returns a bool parameter value.
  1036. func (p ParametersAccessor) Bool(name string) bool {
  1037. value := false
  1038. p.snapshot.getValue(name, &value)
  1039. return value
  1040. }
  1041. // Float returns a float64 parameter value.
  1042. func (p ParametersAccessor) Float(name string) float64 {
  1043. value := float64(0.0)
  1044. p.snapshot.getValue(name, &value)
  1045. return value
  1046. }
  1047. // WeightedCoinFlip returns the result of prng.FlipWeightedCoin using the
  1048. // specified float parameter as the probability input.
  1049. func (p ParametersAccessor) WeightedCoinFlip(name string) bool {
  1050. var value float64
  1051. p.snapshot.getValue(name, &value)
  1052. return prng.FlipWeightedCoin(value)
  1053. }
  1054. // Duration returns a time.Duration parameter value. When the duration
  1055. // parameter has the useNetworkLatencyMultiplier flag, the
  1056. // NetworkLatencyMultiplier is applied to the returned value.
  1057. func (p ParametersAccessor) Duration(name string) time.Duration {
  1058. value := time.Duration(0)
  1059. p.snapshot.getValue(name, &value)
  1060. defaultParameter, ok := defaultParameters[name]
  1061. if value > 0 && ok && defaultParameter.flags&useNetworkLatencyMultiplier != 0 {
  1062. multiplier := float64(0.0)
  1063. if p.customNetworkLatencyMultiplier != 0.0 {
  1064. multiplier = p.customNetworkLatencyMultiplier
  1065. } else {
  1066. p.snapshot.getValue(NetworkLatencyMultiplier, &multiplier)
  1067. }
  1068. if multiplier > 0.0 {
  1069. value = time.Duration(float64(value) * multiplier)
  1070. }
  1071. }
  1072. return value
  1073. }
  1074. // TunnelProtocols returns a protocol.TunnelProtocols parameter value.
  1075. // If there is a corresponding Probability value, a weighted coin flip
  1076. // will be performed and, depending on the result, the value or the
  1077. // parameter default will be returned.
  1078. func (p ParametersAccessor) TunnelProtocols(name string) protocol.TunnelProtocols {
  1079. probabilityName := name + "Probability"
  1080. _, ok := p.snapshot.parameters[probabilityName]
  1081. if ok {
  1082. probabilityValue := float64(1.0)
  1083. p.snapshot.getValue(probabilityName, &probabilityValue)
  1084. if !prng.FlipWeightedCoin(probabilityValue) {
  1085. defaultParameter, ok := defaultParameters[name]
  1086. if ok {
  1087. defaultValue, ok := defaultParameter.value.(protocol.TunnelProtocols)
  1088. if ok {
  1089. value := make(protocol.TunnelProtocols, len(defaultValue))
  1090. copy(value, defaultValue)
  1091. return value
  1092. }
  1093. }
  1094. }
  1095. }
  1096. value := protocol.TunnelProtocols{}
  1097. p.snapshot.getValue(name, &value)
  1098. return value
  1099. }
  1100. // TLSProfiles returns a protocol.TLSProfiles parameter value.
  1101. // If there is a corresponding Probability value, a weighted coin flip
  1102. // will be performed and, depending on the result, the value or the
  1103. // parameter default will be returned.
  1104. func (p ParametersAccessor) TLSProfiles(name string) protocol.TLSProfiles {
  1105. probabilityName := name + "Probability"
  1106. _, ok := p.snapshot.parameters[probabilityName]
  1107. if ok {
  1108. probabilityValue := float64(1.0)
  1109. p.snapshot.getValue(probabilityName, &probabilityValue)
  1110. if !prng.FlipWeightedCoin(probabilityValue) {
  1111. defaultParameter, ok := defaultParameters[name]
  1112. if ok {
  1113. defaultValue, ok := defaultParameter.value.(protocol.TLSProfiles)
  1114. if ok {
  1115. value := make(protocol.TLSProfiles, len(defaultValue))
  1116. copy(value, defaultValue)
  1117. return value
  1118. }
  1119. }
  1120. }
  1121. }
  1122. value := protocol.TLSProfiles{}
  1123. p.snapshot.getValue(name, &value)
  1124. return value
  1125. }
  1126. // LabeledTLSProfiles returns a protocol.TLSProfiles parameter value
  1127. // corresponding to the specified labeled set and label value. The return
  1128. // value is nil when no set is found.
  1129. func (p ParametersAccessor) LabeledTLSProfiles(name, label string) protocol.TLSProfiles {
  1130. var value protocol.LabeledTLSProfiles
  1131. p.snapshot.getValue(name, &value)
  1132. return value[label]
  1133. }
  1134. // QUICVersions returns a protocol.QUICVersions parameter value.
  1135. // If there is a corresponding Probability value, a weighted coin flip
  1136. // will be performed and, depending on the result, the value or the
  1137. // parameter default will be returned.
  1138. func (p ParametersAccessor) QUICVersions(name string) protocol.QUICVersions {
  1139. probabilityName := name + "Probability"
  1140. _, ok := p.snapshot.parameters[probabilityName]
  1141. if ok {
  1142. probabilityValue := float64(1.0)
  1143. p.snapshot.getValue(probabilityName, &probabilityValue)
  1144. if !prng.FlipWeightedCoin(probabilityValue) {
  1145. defaultParameter, ok := defaultParameters[name]
  1146. if ok {
  1147. defaultValue, ok := defaultParameter.value.(protocol.QUICVersions)
  1148. if ok {
  1149. value := make(protocol.QUICVersions, len(defaultValue))
  1150. copy(value, defaultValue)
  1151. return value
  1152. }
  1153. }
  1154. }
  1155. }
  1156. value := protocol.QUICVersions{}
  1157. p.snapshot.getValue(name, &value)
  1158. return value
  1159. }
  1160. // LabeledQUICVersions returns a protocol.QUICVersions parameter value
  1161. // corresponding to the specified labeled set and label value. The return
  1162. // value is nil when no set is found.
  1163. func (p ParametersAccessor) LabeledQUICVersions(name, label string) protocol.QUICVersions {
  1164. value := protocol.LabeledQUICVersions{}
  1165. p.snapshot.getValue(name, &value)
  1166. return value[label]
  1167. }
  1168. // TransferURLs returns a TransferURLs parameter value.
  1169. func (p ParametersAccessor) TransferURLs(name string) TransferURLs {
  1170. value := TransferURLs{}
  1171. p.snapshot.getValue(name, &value)
  1172. return value
  1173. }
  1174. // RateLimits returns a common.RateLimits parameter value.
  1175. func (p ParametersAccessor) RateLimits(name string) common.RateLimits {
  1176. value := common.RateLimits{}
  1177. p.snapshot.getValue(name, &value)
  1178. return value
  1179. }
  1180. // HTTPHeaders returns an http.Header parameter value.
  1181. func (p ParametersAccessor) HTTPHeaders(name string) http.Header {
  1182. value := make(http.Header)
  1183. p.snapshot.getValue(name, &value)
  1184. return value
  1185. }
  1186. // CustomTLSProfileNames returns the CustomTLSProfile.Name fields for
  1187. // each profile in the CustomTLSProfiles parameter value.
  1188. func (p ParametersAccessor) CustomTLSProfileNames() []string {
  1189. value := protocol.CustomTLSProfiles{}
  1190. p.snapshot.getValue(CustomTLSProfiles, &value)
  1191. names := make([]string, len(value))
  1192. for i := 0; i < len(value); i++ {
  1193. names[i] = value[i].Name
  1194. }
  1195. return names
  1196. }
  1197. // CustomTLSProfile returns the CustomTLSProfile fields with the specified
  1198. // Name field if it exists in the CustomTLSProfiles parameter value.
  1199. // Returns nil if not found.
  1200. func (p ParametersAccessor) CustomTLSProfile(name string) *protocol.CustomTLSProfile {
  1201. value := protocol.CustomTLSProfiles{}
  1202. p.snapshot.getValue(CustomTLSProfiles, &value)
  1203. // Note: linear lookup -- assumes a short list
  1204. for i := 0; i < len(value); i++ {
  1205. if value[i].Name == name {
  1206. return value[i]
  1207. }
  1208. }
  1209. return nil
  1210. }
  1211. // KeyValues returns a KeyValues parameter value.
  1212. func (p ParametersAccessor) KeyValues(name string) KeyValues {
  1213. value := KeyValues{}
  1214. p.snapshot.getValue(name, &value)
  1215. return value
  1216. }
  1217. // BPFProgram returns an assembled BPF program corresponding to a
  1218. // BPFProgramSpec parameter value. Returns nil in the case of any empty
  1219. // program.
  1220. func (p ParametersAccessor) BPFProgram(name string) (bool, string, []bpf.RawInstruction) {
  1221. var value *BPFProgramSpec
  1222. p.snapshot.getValue(name, &value)
  1223. if value == nil {
  1224. return false, "", nil
  1225. }
  1226. // Validation checks that Assemble is successful.
  1227. rawInstructions, _ := value.Assemble()
  1228. return true, value.Name, rawInstructions
  1229. }
  1230. // PacketManipulationSpecs returns a PacketManipulationSpecs parameter value.
  1231. func (p ParametersAccessor) PacketManipulationSpecs(name string) PacketManipulationSpecs {
  1232. value := PacketManipulationSpecs{}
  1233. p.snapshot.getValue(name, &value)
  1234. return value
  1235. }
  1236. // ProtocolPacketManipulations returns a ProtocolPacketManipulations parameter value.
  1237. func (p ParametersAccessor) ProtocolPacketManipulations(name string) ProtocolPacketManipulations {
  1238. value := make(ProtocolPacketManipulations)
  1239. p.snapshot.getValue(name, &value)
  1240. return value
  1241. }
  1242. // RegexStrings returns a RegexStrings parameter value.
  1243. func (p ParametersAccessor) RegexStrings(name string) RegexStrings {
  1244. value := RegexStrings{}
  1245. p.snapshot.getValue(name, &value)
  1246. return value
  1247. }
  1248. // FrontingSpecs returns a FrontingSpecs parameter value.
  1249. func (p ParametersAccessor) FrontingSpecs(name string) FrontingSpecs {
  1250. value := FrontingSpecs{}
  1251. p.snapshot.getValue(name, &value)
  1252. return value
  1253. }
  1254. // TunnelProtocolPortLists returns a TunnelProtocolPortLists parameter value.
  1255. func (p ParametersAccessor) TunnelProtocolPortLists(name string) TunnelProtocolPortLists {
  1256. probabilityName := name + "Probability"
  1257. _, ok := p.snapshot.parameters[probabilityName]
  1258. if ok {
  1259. probabilityValue := float64(1.0)
  1260. p.snapshot.getValue(probabilityName, &probabilityValue)
  1261. if !prng.FlipWeightedCoin(probabilityValue) {
  1262. defaultParameter, ok := defaultParameters[name]
  1263. if ok {
  1264. defaultValue, ok := defaultParameter.value.(TunnelProtocolPortLists)
  1265. if ok {
  1266. value := make(TunnelProtocolPortLists)
  1267. for tunnelProtocol, portLists := range defaultValue {
  1268. value[tunnelProtocol] = portLists
  1269. }
  1270. return value
  1271. }
  1272. }
  1273. }
  1274. }
  1275. value := make(TunnelProtocolPortLists)
  1276. p.snapshot.getValue(name, &value)
  1277. return value
  1278. }