parameters.go 62 KB

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