You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @property {number} [maxConnections = Infinity] - The maximum number of connections allowed.
41
+
* @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning.
42
+
* @property {number} [maxData = Infinity] - The max data (in and out), per average interval to allow.
43
+
* @property {number} [maxSentData = Infinity] - The max outgoing data, per average interval to allow.
44
+
* @property {number} [maxReceivedData = Infinity] - The max incoming data, per average interval to allow.
45
+
* @property {number} [maxEventLoopDelay = Infinity] - The upper limit the event loop can take to run.
46
+
* @property {number} [pollInterval = 2000] - How often, in milliseconds, metrics and latency should be checked.
47
+
* @property {number} [movingAverageInterval = 60000] - How often, in milliseconds, to compute averages.
48
+
* @property {number} [defaultPeerValue = 1] - The value of the peer.
49
+
* @property {boolean} [autoDial = true] - Should preemptively guarantee connections are above the low watermark.
50
+
* @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark.
51
+
*/
52
+
53
+
/**
54
+
* @extends {EventEmitter}
35
55
*
36
56
* @fires ConnectionManager#peer:connect Emitted when a new peer is connected.
37
57
* @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected.
38
58
*/
39
59
classConnectionManagerextendsEventEmitter{
40
60
/**
61
+
* Responsible for managing known connections.
62
+
*
41
63
* @class
42
64
* @param {Libp2p} libp2p
43
-
* @param {object} options
44
-
* @param {number} options.maxConnections - The maximum number of connections allowed. Default=Infinity
45
-
* @param {number} options.minConnections - The minimum number of connections to avoid pruning. Default=0
46
-
* @param {number} options.maxData - The max data (in and out), per average interval to allow. Default=Infinity
47
-
* @param {number} options.maxSentData - The max outgoing data, per average interval to allow. Default=Infinity
48
-
* @param {number} options.maxReceivedData - The max incoming data, per average interval to allow.. Default=Infinity
49
-
* @param {number} options.maxEventLoopDelay - The upper limit the event loop can take to run. Default=Infinity
50
-
* @param {number} options.pollInterval - How often, in milliseconds, metrics and latency should be checked. Default=2000
51
-
* @param {number} options.movingAverageInterval - How often, in milliseconds, to compute averages. Default=60000
52
-
* @param {number} options.defaultPeerValue - The value of the peer. Default=1
53
-
* @param {boolean} options.autoDial - Should preemptively guarantee connections are above the low watermark. Default=true
54
-
* @param {number} options.autoDialInterval - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark. Default=10000
65
+
* @param {ConnectionManagerOptions} options
55
66
*/
56
-
constructor(libp2p,options){
67
+
constructor(libp2p,options={}){
57
68
super()
58
69
59
70
this._libp2p=libp2p
@@ -66,8 +77,6 @@ class ConnectionManager extends EventEmitter {
66
77
67
78
log('options: %j',this._options)
68
79
69
-
this._libp2p=libp2p
70
-
71
80
/**
72
81
* Map of peer identifiers to their peer value for pruning connections.
73
82
*
@@ -78,7 +87,7 @@ class ConnectionManager extends EventEmitter {
* @property {number} maxMS What was the max time for a cb to be called
18
18
* @property {number} avgMs What was the average time for a cb to be called
19
19
* @property {number} lengthMs How long this interval was in ms
20
+
*
21
+
* @typedef {Object} LatencyMonitorOptions
22
+
* @property {number} [latencyCheckIntervalMs=500] - How often to add a latency check event (ms)
23
+
* @property {number} [dataEmitIntervalMs=5000] - How often to summarize latency check events. null or 0 disables event firing
24
+
* @property {Function} [asyncTestFn] - What cb-style async function to use
25
+
* @property {number} [latencyRandomPercentage=5] - What percent (+/-) of latencyCheckIntervalMs should we randomly use? This helps avoid alignment to other events.
20
26
*/
21
27
22
28
/**
23
29
* A class to monitor latency of any async function which works in a browser or node. This works by periodically calling
24
30
* the asyncTestFn and timing how long it takes the callback to be called. It can also periodically emit stats about this.
25
31
* This can be disabled and stats can be pulled via setting dataEmitIntervalMs = 0.
26
32
*
33
+
* @extends {EventEmitter}
34
+
*
27
35
* The default implementation is an event loop latency monitor. This works by firing periodic events into the event loop
* @param {number} [options.latencyCheckIntervalMs=500] - How often to add a latency check event (ms)
42
-
* @param {number} [options.dataEmitIntervalMs=5000] - How often to summarize latency check events. null or 0 disables event firing
43
-
* @param {Function} [options.asyncTestFn] - What cb-style async function to use
44
-
* @param {number} [options.latencyRandomPercentage=5] - What percent (+/-) of latencyCheckIntervalMs should we randomly use? This helps avoid alignment to other events.
Copy file name to clipboardExpand all lines: src/connection-manager/visibility-change-emitter.js
+9-4
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,16 @@
4
4
* This code is based on `latency-monitor` (https://github.com/mlucool/latency-monitor) by `mlucool` (https://github.com/mlucool), available under Apache License 2.0 (https://github.com/mlucool/latency-monitor/blob/master/LICENSE)
0 commit comments