parameters.go 98 KB

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