clientParameters.go 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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 behavior.
  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 to customized its parameters from
  25. both a config file and tactics data. Sane minimum values are enforced.
  26. Parameters may be read and updated concurrently. The read mechanism offers a
  27. snapshot so that related parameters, such as two Ints representing a range; or
  28. a more complex series of related parameters; may be read in an atomic and
  29. consistent way. For example:
  30. p := clientParameters.Get()
  31. min := p.Int("Min")
  32. max := p.Int("Max")
  33. p = nil
  34. For long-running operations, it is recommended to set any pointer to the
  35. snapshot to nil to allow garbage collection of old snaphots in cases where the
  36. parameters change.
  37. In general, client parameters should be read as close to the point of use as
  38. possible to ensure that dynamic changes to the parameter values take effect.
  39. For duration parameters, time.ParseDuration-compatible string values are
  40. supported when applying new values. This allows specifying durations as, for
  41. example, "100ms" or "24h".
  42. Values read from the parameters are not deep copies and must be treated as
  43. read-only.
  44. */
  45. package parameters
  46. import (
  47. "encoding/json"
  48. "fmt"
  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/obfuscator"
  55. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/prng"
  56. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
  57. )
  58. const (
  59. NetworkLatencyMultiplier = "NetworkLatencyMultiplier"
  60. TacticsWaitPeriod = "TacticsWaitPeriod"
  61. TacticsRetryPeriod = "TacticsRetryPeriod"
  62. TacticsRetryPeriodJitter = "TacticsRetryPeriodJitter"
  63. TacticsTimeout = "TacticsTimeout"
  64. ConnectionWorkerPoolSize = "ConnectionWorkerPoolSize"
  65. TunnelConnectTimeout = "TunnelConnectTimeout"
  66. EstablishTunnelTimeout = "EstablishTunnelTimeout"
  67. EstablishTunnelWorkTime = "EstablishTunnelWorkTime"
  68. EstablishTunnelPausePeriod = "EstablishTunnelPausePeriod"
  69. EstablishTunnelPausePeriodJitter = "EstablishTunnelPausePeriodJitter"
  70. EstablishTunnelServerAffinityGracePeriod = "EstablishTunnelServerAffinityGracePeriod"
  71. StaggerConnectionWorkersPeriod = "StaggerConnectionWorkersPeriod"
  72. StaggerConnectionWorkersJitter = "StaggerConnectionWorkersJitter"
  73. LimitIntensiveConnectionWorkers = "LimitIntensiveConnectionWorkers"
  74. IgnoreHandshakeStatsRegexps = "IgnoreHandshakeStatsRegexps"
  75. PrioritizeTunnelProtocolsProbability = "PrioritizeTunnelProtocolsProbability"
  76. PrioritizeTunnelProtocols = "PrioritizeTunnelProtocols"
  77. PrioritizeTunnelProtocolsCandidateCount = "PrioritizeTunnelProtocolsCandidateCount"
  78. InitialLimitTunnelProtocolsProbability = "InitialLimitTunnelProtocolsProbability"
  79. InitialLimitTunnelProtocols = "InitialLimitTunnelProtocols"
  80. InitialLimitTunnelProtocolsCandidateCount = "InitialLimitTunnelProtocolsCandidateCount"
  81. LimitTunnelProtocolsProbability = "LimitTunnelProtocolsProbability"
  82. LimitTunnelProtocols = "LimitTunnelProtocols"
  83. LimitTLSProfilesProbability = "LimitTLSProfilesProbability"
  84. LimitTLSProfiles = "LimitTLSProfiles"
  85. SelectRandomizedTLSProfileProbability = "SelectRandomizedTLSProfileProbability"
  86. LimitQUICVersionsProbability = "LimitQUICVersionsProbability"
  87. LimitQUICVersions = "LimitQUICVersions"
  88. FragmentorProbability = "FragmentorProbability"
  89. FragmentorLimitProtocols = "FragmentorLimitProtocols"
  90. FragmentorMinTotalBytes = "FragmentorMinTotalBytes"
  91. FragmentorMaxTotalBytes = "FragmentorMaxTotalBytes"
  92. FragmentorMinWriteBytes = "FragmentorMinWriteBytes"
  93. FragmentorMaxWriteBytes = "FragmentorMaxWriteBytes"
  94. FragmentorMinDelay = "FragmentorMinDelay"
  95. FragmentorMaxDelay = "FragmentorMaxDelay"
  96. FragmentorDownstreamProbability = "FragmentorDownstreamProbability"
  97. FragmentorDownstreamLimitProtocols = "FragmentorDownstreamLimitProtocols"
  98. FragmentorDownstreamMinTotalBytes = "FragmentorDownstreamMinTotalBytes"
  99. FragmentorDownstreamMaxTotalBytes = "FragmentorDownstreamMaxTotalBytes"
  100. FragmentorDownstreamMinWriteBytes = "FragmentorDownstreamMinWriteBytes"
  101. FragmentorDownstreamMaxWriteBytes = "FragmentorDownstreamMaxWriteBytes"
  102. FragmentorDownstreamMinDelay = "FragmentorDownstreamMinDelay"
  103. FragmentorDownstreamMaxDelay = "FragmentorDownstreamMaxDelay"
  104. ObfuscatedSSHMinPadding = "ObfuscatedSSHMinPadding"
  105. ObfuscatedSSHMaxPadding = "ObfuscatedSSHMaxPadding"
  106. TunnelOperateShutdownTimeout = "TunnelOperateShutdownTimeout"
  107. TunnelPortForwardDialTimeout = "TunnelPortForwardDialTimeout"
  108. TunnelRateLimits = "TunnelRateLimits"
  109. AdditionalCustomHeaders = "AdditionalCustomHeaders"
  110. SpeedTestPaddingMinBytes = "SpeedTestPaddingMinBytes"
  111. SpeedTestPaddingMaxBytes = "SpeedTestPaddingMaxBytes"
  112. SpeedTestMaxSampleCount = "SpeedTestMaxSampleCount"
  113. SSHKeepAliveSpeedTestSampleProbability = "SSHKeepAliveSpeedTestSampleProbability"
  114. SSHKeepAlivePaddingMinBytes = "SSHKeepAlivePaddingMinBytes"
  115. SSHKeepAlivePaddingMaxBytes = "SSHKeepAlivePaddingMaxBytes"
  116. SSHKeepAlivePeriodMin = "SSHKeepAlivePeriodMin"
  117. SSHKeepAlivePeriodMax = "SSHKeepAlivePeriodMax"
  118. SSHKeepAlivePeriodicTimeout = "SSHKeepAlivePeriodicTimeout"
  119. SSHKeepAlivePeriodicInactivePeriod = "SSHKeepAlivePeriodicInactivePeriod"
  120. SSHKeepAliveProbeTimeout = "SSHKeepAliveProbeTimeout"
  121. SSHKeepAliveProbeInactivePeriod = "SSHKeepAliveProbeInactivePeriod"
  122. HTTPProxyOriginServerTimeout = "HTTPProxyOriginServerTimeout"
  123. HTTPProxyMaxIdleConnectionsPerHost = "HTTPProxyMaxIdleConnectionsPerHost"
  124. FetchRemoteServerListTimeout = "FetchRemoteServerListTimeout"
  125. FetchRemoteServerListRetryPeriod = "FetchRemoteServerListRetryPeriod"
  126. FetchRemoteServerListStalePeriod = "FetchRemoteServerListStalePeriod"
  127. RemoteServerListSignaturePublicKey = "RemoteServerListSignaturePublicKey"
  128. RemoteServerListURLs = "RemoteServerListURLs"
  129. ObfuscatedServerListRootURLs = "ObfuscatedServerListRootURLs"
  130. PsiphonAPIRequestTimeout = "PsiphonAPIRequestTimeout"
  131. PsiphonAPIStatusRequestPeriodMin = "PsiphonAPIStatusRequestPeriodMin"
  132. PsiphonAPIStatusRequestPeriodMax = "PsiphonAPIStatusRequestPeriodMax"
  133. PsiphonAPIStatusRequestShortPeriodMin = "PsiphonAPIStatusRequestShortPeriodMin"
  134. PsiphonAPIStatusRequestShortPeriodMax = "PsiphonAPIStatusRequestShortPeriodMax"
  135. PsiphonAPIStatusRequestPaddingMinBytes = "PsiphonAPIStatusRequestPaddingMinBytes"
  136. PsiphonAPIStatusRequestPaddingMaxBytes = "PsiphonAPIStatusRequestPaddingMaxBytes"
  137. PsiphonAPIPersistentStatsMaxCount = "PsiphonAPIPersistentStatsMaxCount"
  138. PsiphonAPIConnectedRequestPeriod = "PsiphonAPIConnectedRequestPeriod"
  139. PsiphonAPIConnectedRequestRetryPeriod = "PsiphonAPIConnectedRequestRetryPeriod"
  140. FetchSplitTunnelRoutesTimeout = "FetchSplitTunnelRoutesTimeout"
  141. SplitTunnelRoutesURLFormat = "SplitTunnelRoutesURLFormat"
  142. SplitTunnelRoutesSignaturePublicKey = "SplitTunnelRoutesSignaturePublicKey"
  143. SplitTunnelDNSServer = "SplitTunnelDNSServer"
  144. FetchUpgradeTimeout = "FetchUpgradeTimeout"
  145. FetchUpgradeRetryPeriod = "FetchUpgradeRetryPeriod"
  146. FetchUpgradeStalePeriod = "FetchUpgradeStalePeriod"
  147. UpgradeDownloadURLs = "UpgradeDownloadURLs"
  148. UpgradeDownloadClientVersionHeader = "UpgradeDownloadClientVersionHeader"
  149. TotalBytesTransferredNoticePeriod = "TotalBytesTransferredNoticePeriod"
  150. MeekDialDomainsOnly = "MeekDialDomainsOnly"
  151. MeekLimitBufferSizes = "MeekLimitBufferSizes"
  152. MeekCookieMaxPadding = "MeekCookieMaxPadding"
  153. MeekFullReceiveBufferLength = "MeekFullReceiveBufferLength"
  154. MeekReadPayloadChunkLength = "MeekReadPayloadChunkLength"
  155. MeekLimitedFullReceiveBufferLength = "MeekLimitedFullReceiveBufferLength"
  156. MeekLimitedReadPayloadChunkLength = "MeekLimitedReadPayloadChunkLength"
  157. MeekMinPollInterval = "MeekMinPollInterval"
  158. MeekMinPollIntervalJitter = "MeekMinPollIntervalJitter"
  159. MeekMaxPollInterval = "MeekMaxPollInterval"
  160. MeekMaxPollIntervalJitter = "MeekMaxPollIntervalJitter"
  161. MeekPollIntervalMultiplier = "MeekPollIntervalMultiplier"
  162. MeekPollIntervalJitter = "MeekPollIntervalJitter"
  163. MeekApplyPollIntervalMultiplierProbability = "MeekApplyPollIntervalMultiplierProbability"
  164. MeekRoundTripRetryDeadline = "MeekRoundTripRetryDeadline"
  165. MeekRoundTripRetryMinDelay = "MeekRoundTripRetryMinDelay"
  166. MeekRoundTripRetryMaxDelay = "MeekRoundTripRetryMaxDelay"
  167. MeekRoundTripRetryMultiplier = "MeekRoundTripRetryMultiplier"
  168. MeekRoundTripTimeout = "MeekRoundTripTimeout"
  169. MeekTrafficShapingProbability = "MeekTrafficShapingProbability"
  170. MeekTrafficShapingLimitProtocols = "MeekTrafficShapingLimitProtocols"
  171. MeekMinLimitRequestPayloadLength = "MeekMinLimitRequestPayloadLength"
  172. MeekMaxLimitRequestPayloadLength = "MeekMaxLimitRequestPayloadLength"
  173. MeekRedialTLSProbability = "MeekRedialTLSProbability"
  174. TransformHostNameProbability = "TransformHostNameProbability"
  175. PickUserAgentProbability = "PickUserAgentProbability"
  176. LivenessTestMinUpstreamBytes = "LivenessTestMinUpstreamBytes"
  177. LivenessTestMaxUpstreamBytes = "LivenessTestMaxUpstreamBytes"
  178. LivenessTestMinDownstreamBytes = "LivenessTestMinDownstreamBytes"
  179. LivenessTestMaxDownstreamBytes = "LivenessTestMaxDownstreamBytes"
  180. ReplayCandidateCount = "ReplayCandidateCount"
  181. ReplayDialParametersTTL = "ReplayDialParametersTTL"
  182. ReplayTargetUpstreamBytes = "ReplayTargetUpstreamBytes"
  183. ReplayTargetDownstreamBytes = "ReplayTargetDownstreamBytes"
  184. ReplaySSH = "ReplaySSH"
  185. ReplayObfuscatorPadding = "ReplayObfuscatorPadding"
  186. ReplayFragmentor = "ReplayFragmentor"
  187. ReplayTLSProfile = "ReplayTLSProfile"
  188. ReplayRandomizedTLSProfile = "ReplayRandomizedTLSProfile"
  189. ReplayFronting = "ReplayFronting"
  190. ReplayHostname = "ReplayHostname"
  191. ReplayQUICVersion = "ReplayQUICVersion"
  192. ReplayObfuscatedQUIC = "ReplayObfuscatedQUIC"
  193. ReplayLivenessTest = "ReplayLivenessTest"
  194. ReplayUserAgent = "ReplayUserAgent"
  195. ReplayAPIRequestPadding = "ReplayAPIRequestPadding"
  196. ReplayLaterRoundMoveToFrontProbability = "ReplayLaterRoundMoveToFrontProbability"
  197. ReplayRetainFailedProbability = "ReplayRetainFailedProbability"
  198. APIRequestUpstreamPaddingMinBytes = "APIRequestUpstreamPaddingMinBytes"
  199. APIRequestUpstreamPaddingMaxBytes = "APIRequestUpstreamPaddingMaxBytes"
  200. APIRequestDownstreamPaddingMinBytes = "APIRequestDownstreamPaddingMinBytes"
  201. APIRequestDownstreamPaddingMaxBytes = "APIRequestDownstreamPaddingMaxBytes"
  202. PersistentStatsMaxStoreRecords = "PersistentStatsMaxStoreRecords"
  203. PersistentStatsMaxSendBytes = "PersistentStatsMaxSendBytes"
  204. RecordRemoteServerListPersistentStatsProbability = "RecordRemoteServerListPersistentStatsProbability"
  205. RecordFailedTunnelPersistentStatsProbability = "RecordFailedTunnelPersistentStatsProbability"
  206. ServerEntryMinimumAgeForPruning = "ServerEntryMinimumAgeForPruning"
  207. )
  208. const (
  209. useNetworkLatencyMultiplier = 1
  210. serverSideOnly = 2
  211. )
  212. // defaultClientParameters specifies the type, default value, and minimum
  213. // value for all dynamically configurable client parameters.
  214. //
  215. // Do not change the names or types of existing values, as that can break
  216. // client logic or cause parameters to not be applied.
  217. //
  218. // Minimum values are a fail-safe for cases where lower values would break the
  219. // client logic. For example, setting a ConnectionWorkerPoolSize of 0 would
  220. // make the client never connect.
  221. var defaultClientParameters = map[string]struct {
  222. value interface{}
  223. minimum interface{}
  224. flags int32
  225. }{
  226. // NetworkLatencyMultiplier defaults to 0, meaning off. But when set, it
  227. // must be a multiplier >= 1.
  228. NetworkLatencyMultiplier: {value: 0.0, minimum: 1.0},
  229. TacticsWaitPeriod: {value: 10 * time.Second, minimum: 0 * time.Second, flags: useNetworkLatencyMultiplier},
  230. TacticsRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  231. TacticsRetryPeriodJitter: {value: 0.3, minimum: 0.0},
  232. TacticsTimeout: {value: 2 * time.Minute, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  233. ConnectionWorkerPoolSize: {value: 10, minimum: 1},
  234. TunnelConnectTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  235. EstablishTunnelTimeout: {value: 300 * time.Second, minimum: time.Duration(0)},
  236. EstablishTunnelWorkTime: {value: 60 * time.Second, minimum: 1 * time.Second},
  237. EstablishTunnelPausePeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  238. EstablishTunnelPausePeriodJitter: {value: 0.1, minimum: 0.0},
  239. EstablishTunnelServerAffinityGracePeriod: {value: 1 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  240. StaggerConnectionWorkersPeriod: {value: time.Duration(0), minimum: time.Duration(0)},
  241. StaggerConnectionWorkersJitter: {value: 0.1, minimum: 0.0},
  242. LimitIntensiveConnectionWorkers: {value: 0, minimum: 0},
  243. IgnoreHandshakeStatsRegexps: {value: false},
  244. TunnelOperateShutdownTimeout: {value: 1 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  245. TunnelPortForwardDialTimeout: {value: 10 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  246. TunnelRateLimits: {value: common.RateLimits{}},
  247. // PrioritizeTunnelProtocols parameters are obsoleted by InitialLimitTunnelProtocols.
  248. // TODO: remove once no longer required for older clients.
  249. PrioritizeTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  250. PrioritizeTunnelProtocols: {value: protocol.TunnelProtocols{}},
  251. PrioritizeTunnelProtocolsCandidateCount: {value: 10, minimum: 0},
  252. InitialLimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  253. InitialLimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  254. InitialLimitTunnelProtocolsCandidateCount: {value: 0, minimum: 0},
  255. LimitTunnelProtocolsProbability: {value: 1.0, minimum: 0.0},
  256. LimitTunnelProtocols: {value: protocol.TunnelProtocols{}},
  257. LimitTLSProfilesProbability: {value: 1.0, minimum: 0.0},
  258. LimitTLSProfiles: {value: protocol.TLSProfiles{}},
  259. SelectRandomizedTLSProfileProbability: {value: 0.25, minimum: 0.0},
  260. LimitQUICVersionsProbability: {value: 1.0, minimum: 0.0},
  261. LimitQUICVersions: {value: protocol.QUICVersions{}},
  262. FragmentorProbability: {value: 0.5, minimum: 0.0},
  263. FragmentorLimitProtocols: {value: protocol.TunnelProtocols{}},
  264. FragmentorMinTotalBytes: {value: 0, minimum: 0},
  265. FragmentorMaxTotalBytes: {value: 0, minimum: 0},
  266. FragmentorMinWriteBytes: {value: 1, minimum: 1},
  267. FragmentorMaxWriteBytes: {value: 1500, minimum: 1},
  268. FragmentorMinDelay: {value: time.Duration(0), minimum: time.Duration(0)},
  269. FragmentorMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0)},
  270. FragmentorDownstreamProbability: {value: 0.5, minimum: 0.0, flags: serverSideOnly},
  271. FragmentorDownstreamLimitProtocols: {value: protocol.TunnelProtocols{}, flags: serverSideOnly},
  272. FragmentorDownstreamMinTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  273. FragmentorDownstreamMaxTotalBytes: {value: 0, minimum: 0, flags: serverSideOnly},
  274. FragmentorDownstreamMinWriteBytes: {value: 1, minimum: 1, flags: serverSideOnly},
  275. FragmentorDownstreamMaxWriteBytes: {value: 1500, minimum: 1, flags: serverSideOnly},
  276. FragmentorDownstreamMinDelay: {value: time.Duration(0), minimum: time.Duration(0), flags: serverSideOnly},
  277. FragmentorDownstreamMaxDelay: {value: 10 * time.Millisecond, minimum: time.Duration(0), flags: serverSideOnly},
  278. // The Psiphon server will reject obfuscated SSH seed messages with
  279. // padding greater than OBFUSCATE_MAX_PADDING.
  280. // obfuscator.NewClientObfuscator will ignore invalid min/max padding
  281. // configurations.
  282. ObfuscatedSSHMinPadding: {value: 0, minimum: 0},
  283. ObfuscatedSSHMaxPadding: {value: obfuscator.OBFUSCATE_MAX_PADDING, minimum: 0},
  284. AdditionalCustomHeaders: {value: make(http.Header)},
  285. // Speed test and SSH keep alive padding is intended to frustrate
  286. // fingerprinting and should not exceed ~1 IP packet size.
  287. //
  288. // Currently, each serialized speed test sample, populated with real
  289. // values, is approximately 100 bytes. All SpeedTestMaxSampleCount samples
  290. // are loaded into memory are sent as API inputs.
  291. SpeedTestPaddingMinBytes: {value: 0, minimum: 0},
  292. SpeedTestPaddingMaxBytes: {value: 256, minimum: 0},
  293. SpeedTestMaxSampleCount: {value: 25, minimum: 1},
  294. // The Psiphon server times out inactive tunnels after 5 minutes, so this
  295. // is a soft max for SSHKeepAlivePeriodMax.
  296. SSHKeepAliveSpeedTestSampleProbability: {value: 0.5, minimum: 0.0},
  297. SSHKeepAlivePaddingMinBytes: {value: 0, minimum: 0},
  298. SSHKeepAlivePaddingMaxBytes: {value: 256, minimum: 0},
  299. SSHKeepAlivePeriodMin: {value: 1 * time.Minute, minimum: 1 * time.Second},
  300. SSHKeepAlivePeriodMax: {value: 2 * time.Minute, minimum: 1 * time.Second},
  301. SSHKeepAlivePeriodicTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  302. SSHKeepAlivePeriodicInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  303. SSHKeepAliveProbeTimeout: {value: 5 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  304. SSHKeepAliveProbeInactivePeriod: {value: 10 * time.Second, minimum: 1 * time.Second},
  305. HTTPProxyOriginServerTimeout: {value: 15 * time.Second, minimum: time.Duration(0), flags: useNetworkLatencyMultiplier},
  306. HTTPProxyMaxIdleConnectionsPerHost: {value: 50, minimum: 0},
  307. FetchRemoteServerListTimeout: {value: 30 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  308. FetchRemoteServerListRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  309. FetchRemoteServerListStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  310. RemoteServerListSignaturePublicKey: {value: ""},
  311. RemoteServerListURLs: {value: DownloadURLs{}},
  312. ObfuscatedServerListRootURLs: {value: DownloadURLs{}},
  313. PsiphonAPIRequestTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  314. PsiphonAPIStatusRequestPeriodMin: {value: 5 * time.Minute, minimum: 1 * time.Second},
  315. PsiphonAPIStatusRequestPeriodMax: {value: 10 * time.Minute, minimum: 1 * time.Second},
  316. PsiphonAPIStatusRequestShortPeriodMin: {value: 5 * time.Second, minimum: 1 * time.Second},
  317. PsiphonAPIStatusRequestShortPeriodMax: {value: 10 * time.Second, minimum: 1 * time.Second},
  318. // PsiphonAPIPersistentStatsMaxCount parameter is obsoleted by PersistentStatsMaxSendBytes.
  319. // TODO: remove once no longer required for older clients.
  320. PsiphonAPIPersistentStatsMaxCount: {value: 100, minimum: 1},
  321. // PsiphonAPIStatusRequestPadding parameters are obsoleted by APIRequestUp/DownstreamPadding.
  322. // TODO: remove once no longer required for older clients.
  323. PsiphonAPIStatusRequestPaddingMinBytes: {value: 0, minimum: 0},
  324. PsiphonAPIStatusRequestPaddingMaxBytes: {value: 256, minimum: 0},
  325. PsiphonAPIConnectedRequestRetryPeriod: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  326. FetchSplitTunnelRoutesTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  327. SplitTunnelRoutesURLFormat: {value: ""},
  328. SplitTunnelRoutesSignaturePublicKey: {value: ""},
  329. SplitTunnelDNSServer: {value: ""},
  330. FetchUpgradeTimeout: {value: 60 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  331. FetchUpgradeRetryPeriod: {value: 30 * time.Second, minimum: 1 * time.Millisecond},
  332. FetchUpgradeStalePeriod: {value: 6 * time.Hour, minimum: 1 * time.Hour},
  333. UpgradeDownloadURLs: {value: DownloadURLs{}},
  334. UpgradeDownloadClientVersionHeader: {value: ""},
  335. TotalBytesTransferredNoticePeriod: {value: 5 * time.Minute, minimum: 1 * time.Second},
  336. // The meek server times out inactive sessions after 45 seconds, so this
  337. // is a soft max for MeekMaxPollInterval, MeekRoundTripTimeout, and
  338. // MeekRoundTripRetryDeadline.
  339. //
  340. // MeekCookieMaxPadding cannot exceed common.OBFUSCATE_SEED_LENGTH.
  341. //
  342. // MeekMinLimitRequestPayloadLength/MeekMaxLimitRequestPayloadLength
  343. // cannot exceed server.MEEK_MAX_REQUEST_PAYLOAD_LENGTH.
  344. MeekDialDomainsOnly: {value: false},
  345. MeekLimitBufferSizes: {value: false},
  346. MeekCookieMaxPadding: {value: 256, minimum: 0},
  347. MeekFullReceiveBufferLength: {value: 4194304, minimum: 1024},
  348. MeekReadPayloadChunkLength: {value: 65536, minimum: 1024},
  349. MeekLimitedFullReceiveBufferLength: {value: 131072, minimum: 1024},
  350. MeekLimitedReadPayloadChunkLength: {value: 4096, minimum: 1024},
  351. MeekMinPollInterval: {value: 100 * time.Millisecond, minimum: 1 * time.Millisecond},
  352. MeekMinPollIntervalJitter: {value: 0.3, minimum: 0.0},
  353. MeekMaxPollInterval: {value: 5 * time.Second, minimum: 1 * time.Millisecond},
  354. MeekMaxPollIntervalJitter: {value: 0.1, minimum: 0.0},
  355. MeekPollIntervalMultiplier: {value: 1.5, minimum: 0.0},
  356. MeekPollIntervalJitter: {value: 0.1, minimum: 0.0},
  357. MeekApplyPollIntervalMultiplierProbability: {value: 0.5},
  358. MeekRoundTripRetryDeadline: {value: 5 * time.Second, minimum: 1 * time.Millisecond, flags: useNetworkLatencyMultiplier},
  359. MeekRoundTripRetryMinDelay: {value: 50 * time.Millisecond, minimum: time.Duration(0)},
  360. MeekRoundTripRetryMaxDelay: {value: 1 * time.Second, minimum: time.Duration(0)},
  361. MeekRoundTripRetryMultiplier: {value: 2.0, minimum: 0.0},
  362. MeekRoundTripTimeout: {value: 20 * time.Second, minimum: 1 * time.Second, flags: useNetworkLatencyMultiplier},
  363. MeekTrafficShapingProbability: {value: 1.0, minimum: 0.0},
  364. MeekTrafficShapingLimitProtocols: {value: protocol.TunnelProtocols{}},
  365. MeekMinLimitRequestPayloadLength: {value: 65536, minimum: 1},
  366. MeekMaxLimitRequestPayloadLength: {value: 65536, minimum: 1},
  367. MeekRedialTLSProbability: {value: 0.0, minimum: 0.0},
  368. TransformHostNameProbability: {value: 0.5, minimum: 0.0},
  369. PickUserAgentProbability: {value: 0.5, minimum: 0.0},
  370. LivenessTestMinUpstreamBytes: {value: 0, minimum: 0},
  371. LivenessTestMaxUpstreamBytes: {value: 0, minimum: 0},
  372. LivenessTestMinDownstreamBytes: {value: 0, minimum: 0},
  373. LivenessTestMaxDownstreamBytes: {value: 0, minimum: 0},
  374. ReplayCandidateCount: {value: 10, minimum: -1},
  375. ReplayDialParametersTTL: {value: 24 * time.Hour, minimum: time.Duration(0)},
  376. ReplayTargetUpstreamBytes: {value: 0, minimum: 0},
  377. ReplayTargetDownstreamBytes: {value: 0, minimum: 0},
  378. ReplaySSH: {value: true},
  379. ReplayObfuscatorPadding: {value: true},
  380. ReplayFragmentor: {value: true},
  381. ReplayTLSProfile: {value: true},
  382. ReplayRandomizedTLSProfile: {value: true},
  383. ReplayFronting: {value: true},
  384. ReplayHostname: {value: true},
  385. ReplayQUICVersion: {value: true},
  386. ReplayObfuscatedQUIC: {value: true},
  387. ReplayLivenessTest: {value: true},
  388. ReplayUserAgent: {value: true},
  389. ReplayAPIRequestPadding: {value: true},
  390. ReplayLaterRoundMoveToFrontProbability: {value: 0.0, minimum: 0.0},
  391. ReplayRetainFailedProbability: {value: 0.5, minimum: 0.0},
  392. APIRequestUpstreamPaddingMinBytes: {value: 0, minimum: 0},
  393. APIRequestUpstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  394. APIRequestDownstreamPaddingMinBytes: {value: 0, minimum: 0},
  395. APIRequestDownstreamPaddingMaxBytes: {value: 1024, minimum: 0},
  396. PersistentStatsMaxStoreRecords: {value: 200, minimum: 1},
  397. PersistentStatsMaxSendBytes: {value: 65536, minimum: 1},
  398. RecordRemoteServerListPersistentStatsProbability: {value: 1.0, minimum: 0.0},
  399. RecordFailedTunnelPersistentStatsProbability: {value: 0.0, minimum: 0.0},
  400. ServerEntryMinimumAgeForPruning: {value: 7 * 24 * time.Hour, minimum: 24 * time.Hour},
  401. }
  402. // IsServerSideOnly indicates if the parameter specified by name is used
  403. // server-side only.
  404. func IsServerSideOnly(name string) bool {
  405. defaultParameter, ok := defaultClientParameters[name]
  406. return ok && (defaultParameter.flags&serverSideOnly) != 0
  407. }
  408. // ClientParameters is a set of client parameters. To use the parameters, call
  409. // Get. To apply new values to the parameters, call Set.
  410. type ClientParameters struct {
  411. getValueLogger func(error)
  412. snapshot atomic.Value
  413. }
  414. // ClientParametersSnapshot is an atomic snapshot of the client parameter
  415. // values. ClientParameters.Get will return a snapshot which may be used to
  416. // read multiple related values atomically and consistently while the current
  417. // snapshot in ClientParameters may change concurrently.
  418. type ClientParametersSnapshot struct {
  419. getValueLogger func(error)
  420. tag string
  421. parameters map[string]interface{}
  422. }
  423. // NewClientParameters initializes a new ClientParameters with the default
  424. // parameter values.
  425. //
  426. // getValueLogger is optional, and is used to report runtime errors with
  427. // getValue; see comment in getValue.
  428. func NewClientParameters(
  429. getValueLogger func(error)) (*ClientParameters, error) {
  430. clientParameters := &ClientParameters{
  431. getValueLogger: getValueLogger,
  432. }
  433. _, err := clientParameters.Set("", false)
  434. if err != nil {
  435. return nil, common.ContextError(err)
  436. }
  437. return clientParameters, nil
  438. }
  439. func makeDefaultParameters() (map[string]interface{}, error) {
  440. parameters := make(map[string]interface{})
  441. for name, defaults := range defaultClientParameters {
  442. if defaults.value == nil {
  443. return nil, common.ContextError(fmt.Errorf("default parameter missing value: %s", name))
  444. }
  445. if defaults.minimum != nil &&
  446. reflect.TypeOf(defaults.value) != reflect.TypeOf(defaults.minimum) {
  447. return nil, common.ContextError(fmt.Errorf("default parameter value and minimum type mismatch: %s", name))
  448. }
  449. _, isDuration := defaults.value.(time.Duration)
  450. if defaults.flags&useNetworkLatencyMultiplier != 0 && !isDuration {
  451. return nil, common.ContextError(fmt.Errorf("default non-duration parameter uses multipler: %s", name))
  452. }
  453. parameters[name] = defaults.value
  454. }
  455. return parameters, nil
  456. }
  457. // Set replaces the current parameters. First, a set of parameters are
  458. // initialized using the default values. Then, each applyParameters is applied
  459. // in turn, with the later instances having precedence.
  460. //
  461. // When skipOnError is true, unknown or invalid parameters in any
  462. // applyParameters are skipped instead of aborting with an error.
  463. //
  464. // For protocol.TunnelProtocols and protocol.TLSProfiles type values, when
  465. // skipOnError is true the values are filtered instead of validated, so
  466. // only known tunnel protocols and TLS profiles are retained.
  467. //
  468. // When an error is returned, the previous parameters remain completely
  469. // unmodified.
  470. //
  471. // For use in logging, Set returns a count of the number of parameters applied
  472. // from each applyParameters.
  473. func (p *ClientParameters) Set(
  474. tag string, skipOnError bool, applyParameters ...map[string]interface{}) ([]int, error) {
  475. var counts []int
  476. parameters, err := makeDefaultParameters()
  477. if err != nil {
  478. return nil, common.ContextError(err)
  479. }
  480. for i := 0; i < len(applyParameters); i++ {
  481. count := 0
  482. for name, value := range applyParameters[i] {
  483. existingValue, ok := parameters[name]
  484. if !ok {
  485. if skipOnError {
  486. continue
  487. }
  488. return nil, common.ContextError(fmt.Errorf("unknown parameter: %s", name))
  489. }
  490. // Accept strings such as "1h" for duration parameters.
  491. switch existingValue.(type) {
  492. case time.Duration:
  493. if s, ok := value.(string); ok {
  494. if d, err := time.ParseDuration(s); err == nil {
  495. value = d
  496. }
  497. }
  498. }
  499. // A JSON remarshal resolves cases where applyParameters is a
  500. // result of unmarshal-into-interface, in which case non-scalar
  501. // values will not have the expected types; see:
  502. // https://golang.org/pkg/encoding/json/#Unmarshal. This remarshal
  503. // also results in a deep copy.
  504. marshaledValue, err := json.Marshal(value)
  505. if err != nil {
  506. continue
  507. }
  508. newValuePtr := reflect.New(reflect.TypeOf(existingValue))
  509. err = json.Unmarshal(marshaledValue, newValuePtr.Interface())
  510. if err != nil {
  511. if skipOnError {
  512. continue
  513. }
  514. return nil, common.ContextError(fmt.Errorf("unmarshal parameter %s failed: %s", name, err))
  515. }
  516. newValue := newValuePtr.Elem().Interface()
  517. // Perform type-specific validation for some cases.
  518. // TODO: require RemoteServerListSignaturePublicKey when
  519. // RemoteServerListURLs is set?
  520. switch v := newValue.(type) {
  521. case DownloadURLs:
  522. err := v.DecodeAndValidate()
  523. if err != nil {
  524. if skipOnError {
  525. continue
  526. }
  527. return nil, common.ContextError(err)
  528. }
  529. case protocol.TunnelProtocols:
  530. if skipOnError {
  531. newValue = v.PruneInvalid()
  532. } else {
  533. err := v.Validate()
  534. if err != nil {
  535. return nil, common.ContextError(err)
  536. }
  537. }
  538. case protocol.TLSProfiles:
  539. if skipOnError {
  540. newValue = v.PruneInvalid()
  541. } else {
  542. err := v.Validate()
  543. if err != nil {
  544. return nil, common.ContextError(err)
  545. }
  546. }
  547. case protocol.QUICVersions:
  548. if skipOnError {
  549. newValue = v.PruneInvalid()
  550. } else {
  551. err := v.Validate()
  552. if err != nil {
  553. return nil, common.ContextError(err)
  554. }
  555. }
  556. }
  557. // Enforce any minimums. Assumes defaultClientParameters[name]
  558. // exists.
  559. if defaultClientParameters[name].minimum != nil {
  560. valid := true
  561. switch v := newValue.(type) {
  562. case int:
  563. m, ok := defaultClientParameters[name].minimum.(int)
  564. if !ok || v < m {
  565. valid = false
  566. }
  567. case float64:
  568. m, ok := defaultClientParameters[name].minimum.(float64)
  569. if !ok || v < m {
  570. valid = false
  571. }
  572. case time.Duration:
  573. m, ok := defaultClientParameters[name].minimum.(time.Duration)
  574. if !ok || v < m {
  575. valid = false
  576. }
  577. default:
  578. if skipOnError {
  579. continue
  580. }
  581. return nil, common.ContextError(fmt.Errorf("unexpected parameter with minimum: %s", name))
  582. }
  583. if !valid {
  584. if skipOnError {
  585. continue
  586. }
  587. return nil, common.ContextError(fmt.Errorf("parameter below minimum: %s", name))
  588. }
  589. }
  590. parameters[name] = newValue
  591. count++
  592. }
  593. counts = append(counts, count)
  594. }
  595. snapshot := &ClientParametersSnapshot{
  596. getValueLogger: p.getValueLogger,
  597. tag: tag,
  598. parameters: parameters,
  599. }
  600. p.snapshot.Store(snapshot)
  601. return counts, nil
  602. }
  603. // Get returns the current parameters. Values read from the current parameters
  604. // are not deep copies and must be treated read-only.
  605. func (p *ClientParameters) Get() *ClientParametersSnapshot {
  606. return p.snapshot.Load().(*ClientParametersSnapshot)
  607. }
  608. // Tag returns the tag associated with these parameters.
  609. func (p *ClientParametersSnapshot) Tag() string {
  610. return p.tag
  611. }
  612. // getValue sets target to the value of the named parameter.
  613. //
  614. // It is an error if the name is not found, target is not a pointer, or the
  615. // type of target points to does not match the value.
  616. //
  617. // Any of these conditions would be a bug in the caller. getValue does not
  618. // panic in these cases as the client is deployed as a library in various apps
  619. // and the failure of Psiphon may not be a failure for the app process.
  620. //
  621. // Instead, errors are logged to the getValueLogger and getValue leaves the
  622. // target unset, which will result in the caller getting and using a zero
  623. // value of the requested type.
  624. func (p *ClientParametersSnapshot) getValue(name string, target interface{}) {
  625. value, ok := p.parameters[name]
  626. if !ok {
  627. if p.getValueLogger != nil {
  628. p.getValueLogger(common.ContextError(fmt.Errorf(
  629. "value %s not found", name)))
  630. }
  631. return
  632. }
  633. valueType := reflect.TypeOf(value)
  634. if reflect.PtrTo(valueType) != reflect.TypeOf(target) {
  635. if p.getValueLogger != nil {
  636. p.getValueLogger(common.ContextError(fmt.Errorf(
  637. "value %s has unexpected type %s", name, valueType.Name())))
  638. }
  639. return
  640. }
  641. // Note: there is no deep copy of parameter values; the returned value may
  642. // share memory with the original and should not be modified.
  643. targetValue := reflect.ValueOf(target)
  644. if targetValue.Kind() != reflect.Ptr {
  645. p.getValueLogger(common.ContextError(fmt.Errorf(
  646. "target for value %s is not pointer", name)))
  647. return
  648. }
  649. targetValue.Elem().Set(reflect.ValueOf(value))
  650. }
  651. // String returns a string parameter value.
  652. func (p *ClientParametersSnapshot) String(name string) string {
  653. value := ""
  654. p.getValue(name, &value)
  655. return value
  656. }
  657. // Strings returns a []string parameter value.
  658. func (p *ClientParametersSnapshot) Strings(name string) []string {
  659. value := []string{}
  660. p.getValue(name, &value)
  661. return value
  662. }
  663. // Int returns an int parameter value.
  664. func (p *ClientParametersSnapshot) Int(name string) int {
  665. value := int(0)
  666. p.getValue(name, &value)
  667. return value
  668. }
  669. // Bool returns a bool parameter value.
  670. func (p *ClientParametersSnapshot) Bool(name string) bool {
  671. value := false
  672. p.getValue(name, &value)
  673. return value
  674. }
  675. // Float returns a float64 parameter value.
  676. func (p *ClientParametersSnapshot) Float(name string) float64 {
  677. value := float64(0.0)
  678. p.getValue(name, &value)
  679. return value
  680. }
  681. // WeightedCoinFlip returns the result of prng.FlipWeightedCoin using the
  682. // specified float parameter as the probability input.
  683. func (p *ClientParametersSnapshot) WeightedCoinFlip(name string) bool {
  684. var value float64
  685. p.getValue(name, &value)
  686. return prng.FlipWeightedCoin(value)
  687. }
  688. // Duration returns a time.Duration parameter value. When the duration
  689. // parameter has the useNetworkLatencyMultiplier flag, the
  690. // NetworkLatencyMultiplier is applied to the returned value.
  691. func (p *ClientParametersSnapshot) Duration(name string) time.Duration {
  692. value := time.Duration(0)
  693. p.getValue(name, &value)
  694. defaultParameter, ok := defaultClientParameters[name]
  695. if value > 0 && ok && defaultParameter.flags&useNetworkLatencyMultiplier != 0 {
  696. multiplier := float64(0.0)
  697. p.getValue(NetworkLatencyMultiplier, &multiplier)
  698. if multiplier > 0.0 {
  699. value = time.Duration(float64(value) * multiplier)
  700. }
  701. }
  702. return value
  703. }
  704. // TunnelProtocols returns a protocol.TunnelProtocols parameter value.
  705. // If there is a corresponding Probability value, a weighted coin flip
  706. // will be performed and, depending on the result, the value or the
  707. // parameter default will be returned.
  708. func (p *ClientParametersSnapshot) TunnelProtocols(name string) protocol.TunnelProtocols {
  709. probabilityName := name + "Probability"
  710. _, ok := p.parameters[probabilityName]
  711. if ok {
  712. probabilityValue := float64(1.0)
  713. p.getValue(probabilityName, &probabilityValue)
  714. if !prng.FlipWeightedCoin(probabilityValue) {
  715. defaultParameter, ok := defaultClientParameters[name]
  716. if ok {
  717. defaultValue, ok := defaultParameter.value.(protocol.TunnelProtocols)
  718. if ok {
  719. value := make(protocol.TunnelProtocols, len(defaultValue))
  720. copy(value, defaultValue)
  721. return value
  722. }
  723. }
  724. }
  725. }
  726. value := protocol.TunnelProtocols{}
  727. p.getValue(name, &value)
  728. return value
  729. }
  730. // TLSProfiles returns a protocol.TLSProfiles parameter value.
  731. // If there is a corresponding Probability value, a weighted coin flip
  732. // will be performed and, depending on the result, the value or the
  733. // parameter default will be returned.
  734. func (p *ClientParametersSnapshot) TLSProfiles(name string) protocol.TLSProfiles {
  735. probabilityName := name + "Probability"
  736. _, ok := p.parameters[probabilityName]
  737. if ok {
  738. probabilityValue := float64(1.0)
  739. p.getValue(probabilityName, &probabilityValue)
  740. if !prng.FlipWeightedCoin(probabilityValue) {
  741. defaultParameter, ok := defaultClientParameters[name]
  742. if ok {
  743. defaultValue, ok := defaultParameter.value.(protocol.TLSProfiles)
  744. if ok {
  745. value := make(protocol.TLSProfiles, len(defaultValue))
  746. copy(value, defaultValue)
  747. return value
  748. }
  749. }
  750. }
  751. }
  752. value := protocol.TLSProfiles{}
  753. p.getValue(name, &value)
  754. return value
  755. }
  756. // QUICVersions returns a protocol.QUICVersions parameter value.
  757. // If there is a corresponding Probability value, a weighted coin flip
  758. // will be performed and, depending on the result, the value or the
  759. // parameter default will be returned.
  760. func (p *ClientParametersSnapshot) QUICVersions(name string) protocol.QUICVersions {
  761. probabilityName := name + "Probability"
  762. _, ok := p.parameters[probabilityName]
  763. if ok {
  764. probabilityValue := float64(1.0)
  765. p.getValue(probabilityName, &probabilityValue)
  766. if !prng.FlipWeightedCoin(probabilityValue) {
  767. defaultParameter, ok := defaultClientParameters[name]
  768. if ok {
  769. defaultValue, ok := defaultParameter.value.(protocol.QUICVersions)
  770. if ok {
  771. value := make(protocol.QUICVersions, len(defaultValue))
  772. copy(value, defaultValue)
  773. return value
  774. }
  775. }
  776. }
  777. }
  778. value := protocol.QUICVersions{}
  779. p.getValue(name, &value)
  780. return value
  781. }
  782. // DownloadURLs returns a DownloadURLs parameter value.
  783. func (p *ClientParametersSnapshot) DownloadURLs(name string) DownloadURLs {
  784. value := DownloadURLs{}
  785. p.getValue(name, &value)
  786. return value
  787. }
  788. // RateLimits returns a common.RateLimits parameter value.
  789. func (p *ClientParametersSnapshot) RateLimits(name string) common.RateLimits {
  790. value := common.RateLimits{}
  791. p.getValue(name, &value)
  792. return value
  793. }
  794. // HTTPHeaders returns an http.Header parameter value.
  795. func (p *ClientParametersSnapshot) HTTPHeaders(name string) http.Header {
  796. value := make(http.Header)
  797. p.getValue(name, &value)
  798. return value
  799. }