parameters.go 61 KB

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