libp2p 0.43.4 → 0.44.0-17eb162a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/index.min.js +29 -29
  2. package/dist/src/address-manager/index.d.ts +4 -4
  3. package/dist/src/address-manager/index.d.ts.map +1 -1
  4. package/dist/src/address-manager/index.js +9 -6
  5. package/dist/src/address-manager/index.js.map +1 -1
  6. package/dist/src/autonat/index.d.ts +1 -2
  7. package/dist/src/autonat/index.d.ts.map +1 -1
  8. package/dist/src/autonat/index.js +4 -6
  9. package/dist/src/autonat/index.js.map +1 -1
  10. package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
  11. package/dist/src/circuit-relay/server/advert-service.js +2 -2
  12. package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
  13. package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
  14. package/dist/src/circuit-relay/server/index.js +7 -3
  15. package/dist/src/circuit-relay/server/index.js.map +1 -1
  16. package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
  17. package/dist/src/circuit-relay/transport/discovery.js +3 -1
  18. package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
  19. package/dist/src/circuit-relay/transport/index.d.ts +3 -0
  20. package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
  21. package/dist/src/circuit-relay/transport/index.js +6 -2
  22. package/dist/src/circuit-relay/transport/index.js.map +1 -1
  23. package/dist/src/circuit-relay/transport/listener.d.ts +3 -0
  24. package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
  25. package/dist/src/circuit-relay/transport/listener.js +5 -4
  26. package/dist/src/circuit-relay/transport/listener.js.map +1 -1
  27. package/dist/src/circuit-relay/transport/reservation-store.d.ts +4 -1
  28. package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
  29. package/dist/src/circuit-relay/transport/reservation-store.js +11 -6
  30. package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
  31. package/dist/src/circuit-relay/utils.d.ts.map +1 -1
  32. package/dist/src/circuit-relay/utils.js +3 -1
  33. package/dist/src/circuit-relay/utils.js.map +1 -1
  34. package/dist/src/components.d.ts +8 -6
  35. package/dist/src/components.d.ts.map +1 -1
  36. package/dist/src/components.js +10 -10
  37. package/dist/src/components.js.map +1 -1
  38. package/dist/src/config.d.ts.map +1 -1
  39. package/dist/src/config.js +0 -9
  40. package/dist/src/config.js.map +1 -1
  41. package/dist/src/connection-manager/auto-dial.d.ts +39 -0
  42. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -0
  43. package/dist/src/connection-manager/auto-dial.js +131 -0
  44. package/dist/src/connection-manager/auto-dial.js.map +1 -0
  45. package/dist/src/connection-manager/connection-pruner.d.ts +32 -0
  46. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -0
  47. package/dist/src/connection-manager/connection-pruner.js +111 -0
  48. package/dist/src/connection-manager/connection-pruner.js.map +1 -0
  49. package/dist/src/connection-manager/constants.d.ts +49 -0
  50. package/dist/src/connection-manager/constants.d.ts.map +1 -0
  51. package/dist/src/connection-manager/constants.js +49 -0
  52. package/dist/src/connection-manager/constants.js.map +1 -0
  53. package/dist/src/connection-manager/dial-queue.d.ts +78 -0
  54. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -0
  55. package/dist/src/connection-manager/dial-queue.js +374 -0
  56. package/dist/src/connection-manager/dial-queue.js.map +1 -0
  57. package/dist/src/connection-manager/index.d.ts +70 -73
  58. package/dist/src/connection-manager/index.d.ts.map +1 -1
  59. package/dist/src/connection-manager/index.js +116 -248
  60. package/dist/src/connection-manager/index.js.map +1 -1
  61. package/dist/src/connection-manager/utils.d.ts +9 -0
  62. package/dist/src/connection-manager/utils.d.ts.map +1 -0
  63. package/dist/src/connection-manager/utils.js +66 -0
  64. package/dist/src/connection-manager/utils.js.map +1 -0
  65. package/dist/src/content-routing/index.js +1 -1
  66. package/dist/src/content-routing/index.js.map +1 -1
  67. package/dist/src/content-routing/utils.d.ts.map +1 -1
  68. package/dist/src/content-routing/utils.js +3 -1
  69. package/dist/src/content-routing/utils.js.map +1 -1
  70. package/dist/src/fetch/index.js +3 -3
  71. package/dist/src/fetch/index.js.map +1 -1
  72. package/dist/src/identify/index.d.ts +4 -0
  73. package/dist/src/identify/index.d.ts.map +1 -1
  74. package/dist/src/identify/index.js +104 -128
  75. package/dist/src/identify/index.js.map +1 -1
  76. package/dist/src/index.d.ts +2 -19
  77. package/dist/src/index.d.ts.map +1 -1
  78. package/dist/src/index.js.map +1 -1
  79. package/dist/src/insecure/index.d.ts.map +1 -1
  80. package/dist/src/insecure/index.js +3 -1
  81. package/dist/src/insecure/index.js.map +1 -1
  82. package/dist/src/libp2p.d.ts +5 -3
  83. package/dist/src/libp2p.d.ts.map +1 -1
  84. package/dist/src/libp2p.js +47 -50
  85. package/dist/src/libp2p.js.map +1 -1
  86. package/dist/src/registrar.d.ts +5 -2
  87. package/dist/src/registrar.d.ts.map +1 -1
  88. package/dist/src/registrar.js +25 -23
  89. package/dist/src/registrar.js.map +1 -1
  90. package/dist/src/transport-manager.d.ts +9 -3
  91. package/dist/src/transport-manager.d.ts.map +1 -1
  92. package/dist/src/transport-manager.js +23 -9
  93. package/dist/src/transport-manager.js.map +1 -1
  94. package/dist/src/upgrader.d.ts +14 -11
  95. package/dist/src/upgrader.d.ts.map +1 -1
  96. package/dist/src/upgrader.js +14 -10
  97. package/dist/src/upgrader.js.map +1 -1
  98. package/package.json +46 -45
  99. package/src/address-manager/index.ts +12 -8
  100. package/src/autonat/index.ts +6 -9
  101. package/src/circuit-relay/server/advert-service.ts +2 -2
  102. package/src/circuit-relay/server/index.ts +7 -3
  103. package/src/circuit-relay/transport/discovery.ts +3 -1
  104. package/src/circuit-relay/transport/index.ts +10 -2
  105. package/src/circuit-relay/transport/listener.ts +8 -4
  106. package/src/circuit-relay/transport/reservation-store.ts +15 -7
  107. package/src/circuit-relay/utils.ts +3 -1
  108. package/src/components.ts +19 -17
  109. package/src/config.ts +0 -9
  110. package/src/connection-manager/auto-dial.ts +183 -0
  111. package/src/connection-manager/connection-pruner.ts +157 -0
  112. package/src/connection-manager/constants.ts +60 -0
  113. package/src/connection-manager/dial-queue.ts +512 -0
  114. package/src/connection-manager/index.ts +191 -340
  115. package/src/connection-manager/utils.ts +76 -0
  116. package/src/content-routing/index.ts +1 -1
  117. package/src/content-routing/utils.ts +3 -1
  118. package/src/fetch/index.ts +4 -4
  119. package/src/identify/index.ts +100 -140
  120. package/src/index.ts +2 -20
  121. package/src/insecure/index.ts +9 -5
  122. package/src/libp2p.ts +54 -60
  123. package/src/registrar.ts +29 -25
  124. package/src/transport-manager.ts +31 -11
  125. package/src/upgrader.ts +31 -22
  126. package/src/version.ts +1 -1
  127. package/dist/src/connection-manager/auto-dialler.d.ts +0 -42
  128. package/dist/src/connection-manager/auto-dialler.d.ts.map +0 -1
  129. package/dist/src/connection-manager/auto-dialler.js +0 -105
  130. package/dist/src/connection-manager/auto-dialler.js.map +0 -1
  131. package/dist/src/connection-manager/dialer/dial-request.d.ts +0 -27
  132. package/dist/src/connection-manager/dialer/dial-request.d.ts.map +0 -1
  133. package/dist/src/connection-manager/dialer/dial-request.js +0 -114
  134. package/dist/src/connection-manager/dialer/dial-request.js.map +0 -1
  135. package/dist/src/connection-manager/dialer/index.d.ts +0 -121
  136. package/dist/src/connection-manager/dialer/index.d.ts.map +0 -1
  137. package/dist/src/connection-manager/dialer/index.js +0 -324
  138. package/dist/src/connection-manager/dialer/index.js.map +0 -1
  139. package/dist/src/connection-manager/latency-monitor.d.ts +0 -120
  140. package/dist/src/connection-manager/latency-monitor.d.ts.map +0 -1
  141. package/dist/src/connection-manager/latency-monitor.js +0 -220
  142. package/dist/src/connection-manager/latency-monitor.js.map +0 -1
  143. package/dist/src/connection-manager/visibility-change-emitter.d.ts +0 -66
  144. package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +0 -1
  145. package/dist/src/connection-manager/visibility-change-emitter.js +0 -118
  146. package/dist/src/connection-manager/visibility-change-emitter.js.map +0 -1
  147. package/dist/src/constants.d.ts +0 -27
  148. package/dist/src/constants.d.ts.map +0 -1
  149. package/dist/src/constants.js +0 -31
  150. package/dist/src/constants.js.map +0 -1
  151. package/dist/src/peer-record-updater.d.ts +0 -24
  152. package/dist/src/peer-record-updater.d.ts.map +0 -1
  153. package/dist/src/peer-record-updater.js +0 -44
  154. package/dist/src/peer-record-updater.js.map +0 -1
  155. package/dist/typedoc-urls.json +0 -41
  156. package/src/connection-manager/auto-dialler.ts +0 -158
  157. package/src/connection-manager/dialer/dial-request.ts +0 -144
  158. package/src/connection-manager/dialer/index.ts +0 -461
  159. package/src/connection-manager/latency-monitor.ts +0 -319
  160. package/src/connection-manager/visibility-change-emitter.ts +0 -135
  161. package/src/constants.ts +0 -36
  162. package/src/peer-record-updater.ts +0 -65
@@ -0,0 +1,111 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import { PeerMap } from '@libp2p/peer-collections';
3
+ import { MAX_CONNECTIONS } from './constants.js';
4
+ const log = logger('libp2p:connection-manager:connection-pruner');
5
+ const defaultOptions = {
6
+ maxConnections: MAX_CONNECTIONS,
7
+ allow: []
8
+ };
9
+ /**
10
+ * If we go over the max connections limit, choose some connections to close
11
+ */
12
+ export class ConnectionPruner {
13
+ constructor(components, init = {}) {
14
+ this.maxConnections = init.maxConnections ?? defaultOptions.maxConnections;
15
+ this.allow = init.allow ?? defaultOptions.allow;
16
+ this.connectionManager = components.connectionManager;
17
+ this.peerStore = components.peerStore;
18
+ this.events = components.events;
19
+ // check the max connection limit whenever a peer connects
20
+ components.events.addEventListener('connection:open', () => {
21
+ this.maybePruneConnections()
22
+ .catch(err => {
23
+ log.error(err);
24
+ });
25
+ });
26
+ }
27
+ /**
28
+ * If we have more connections than our maximum, select some excess connections
29
+ * to prune based on peer value
30
+ */
31
+ async maybePruneConnections() {
32
+ const connections = this.connectionManager.getConnections();
33
+ const numConnections = connections.length;
34
+ const toPrune = Math.max(numConnections - this.maxConnections, 0);
35
+ log('checking max connections limit %d/%d', numConnections, this.maxConnections);
36
+ if (numConnections <= this.maxConnections) {
37
+ return;
38
+ }
39
+ log('max connections limit exceeded %d/%d, pruning %d connection(s)', numConnections, this.maxConnections, toPrune);
40
+ const peerValues = new PeerMap();
41
+ // work out peer values
42
+ for (const connection of connections) {
43
+ const remotePeer = connection.remotePeer;
44
+ if (peerValues.has(remotePeer)) {
45
+ continue;
46
+ }
47
+ peerValues.set(remotePeer, 0);
48
+ try {
49
+ const peer = await this.peerStore.get(remotePeer);
50
+ // sum all tag values
51
+ peerValues.set(remotePeer, [...peer.tags.values()].reduce((acc, curr) => {
52
+ return acc + curr.value;
53
+ }, 0));
54
+ }
55
+ catch (err) {
56
+ if (err.code !== 'ERR_NOT_FOUND') {
57
+ log.error('error loading peer tags', err);
58
+ }
59
+ }
60
+ }
61
+ // sort by value, lowest to highest
62
+ const sortedConnections = connections.sort((a, b) => {
63
+ const peerAValue = peerValues.get(a.remotePeer) ?? 0;
64
+ const peerBValue = peerValues.get(b.remotePeer) ?? 0;
65
+ if (peerAValue > peerBValue) {
66
+ return 1;
67
+ }
68
+ if (peerAValue < peerBValue) {
69
+ return -1;
70
+ }
71
+ // if the peers have an equal tag value then we want to close short-lived connections first
72
+ const connectionALifespan = a.stat.timeline.open;
73
+ const connectionBLifespan = b.stat.timeline.open;
74
+ if (connectionALifespan < connectionBLifespan) {
75
+ return 1;
76
+ }
77
+ if (connectionALifespan > connectionBLifespan) {
78
+ return -1;
79
+ }
80
+ return 0;
81
+ });
82
+ // close some connections
83
+ const toClose = [];
84
+ for (const connection of sortedConnections) {
85
+ log('too many connections open - closing a connection to %p', connection.remotePeer);
86
+ // check allow list
87
+ const connectionInAllowList = this.allow.some((ma) => {
88
+ return connection.remoteAddr.toString().startsWith(ma.toString());
89
+ });
90
+ // Connections in the allow list should be excluded from pruning
91
+ if (!connectionInAllowList) {
92
+ toClose.push(connection);
93
+ }
94
+ if (toClose.length === toPrune) {
95
+ break;
96
+ }
97
+ }
98
+ // close connections
99
+ await Promise.all(toClose.map(async (connection) => {
100
+ try {
101
+ await connection.close();
102
+ }
103
+ catch (err) {
104
+ log.error(err);
105
+ }
106
+ }));
107
+ // despatch prune event
108
+ this.events.safeDispatchEvent('connection:prune', { detail: toClose });
109
+ }
110
+ }
111
+ //# sourceMappingURL=connection-pruner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-pruner.js","sourceRoot":"","sources":["../../../src/connection-manager/connection-pruner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIhD,MAAM,GAAG,GAAG,MAAM,CAAC,6CAA6C,CAAC,CAAA;AAajE,MAAM,cAAc,GAAG;IACrB,cAAc,EAAE,eAAe;IAC/B,KAAK,EAAE,EAAE;CACV,CAAA;AAED;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAO3B,YAAa,UAAsC,EAAE,OAA6B,EAAE;QAClF,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,cAAc,CAAA;QAC1E,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,cAAc,CAAC,KAAK,CAAA;QAC/C,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAA;QACrD,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAA;QACrC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAE/B,0DAA0D;QAC1D,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,GAAG,EAAE;YACzD,IAAI,CAAC,qBAAqB,EAAE;iBACzB,KAAK,CAAC,GAAG,CAAC,EAAE;gBACX,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAChB,C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C,QAAQ,EAAE,CAAC,CAAA;YACnE,CAAC,CAAC,CAAA;YAEF,gEAAgE;YAChE,IAAI,CAAC,qBAAqB,EAAE;gBAC1B,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;aACzB;YAED,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE;gBAC9B,MAAK;aACN;SACF;QAED,oBAAoB;QACpB,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAC,UAAU,EAAC,EAAE;YAC7B,IAAI;gBACF,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;aACzB;YAAC,OAAO,GAAG,EAAE;gBACZ,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACf;QACH,CAAC,CAAC,CACH,CAAA;QAED,uBAAuB;QACvB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IACxE,CAAC;CACF"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
3
+ */
4
+ export declare const DIAL_TIMEOUT = 30000;
5
+ /**
6
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
7
+ */
8
+ export declare const INBOUND_UPGRADE_TIMEOUT = 30000;
9
+ /**
10
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials
11
+ */
12
+ export declare const MAX_PARALLEL_DIALS = 100;
13
+ /**
14
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
15
+ */
16
+ export declare const MAX_PEER_ADDRS_TO_DIAL = 25;
17
+ /**
18
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
19
+ */
20
+ export declare const MAX_PARALLEL_DIALS_PER_PEER = 10;
21
+ /**
22
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
23
+ */
24
+ export declare const MIN_CONNECTIONS = 50;
25
+ /**
26
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections
27
+ */
28
+ export declare const MAX_CONNECTIONS = 300;
29
+ /**
30
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
31
+ */
32
+ export declare const AUTO_DIAL_INTERVAL = 5000;
33
+ /**
34
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
35
+ */
36
+ export declare const AUTO_DIAL_CONCURRENCY = 25;
37
+ /**
38
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
39
+ */
40
+ export declare const AUTO_DIAL_PRIORITY = 0;
41
+ /**
42
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
43
+ */
44
+ export declare const INBOUND_CONNECTION_THRESHOLD = 5;
45
+ /**
46
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
47
+ */
48
+ export declare const MAX_INCOMING_PENDING_CONNECTIONS = 10;
49
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/constants.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,eAAO,MAAM,YAAY,QAAO,CAAA;AAEhC;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAO,CAAA;AAE3C;;GAEG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC;;GAEG;AACH,eAAO,MAAM,2BAA2B,KAAK,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,eAAe,KAAK,CAAA;AAEjC;;GAEG;AACH,eAAO,MAAM,eAAe,MAAM,CAAA;AAElC;;GAEG;AACH,eAAO,MAAM,kBAAkB,OAAO,CAAA;AAEtC;;GAEG;AACH,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC;;GAEG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,gCAAgC,KAAK,CAAA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#dialTimeout
3
+ */
4
+ export const DIAL_TIMEOUT = 30e3;
5
+ /**
6
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundUpgradeTimeout
7
+ */
8
+ export const INBOUND_UPGRADE_TIMEOUT = 30e3;
9
+ /**
10
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDials
11
+ */
12
+ export const MAX_PARALLEL_DIALS = 100;
13
+ /**
14
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxPeerAddrsToDial
15
+ */
16
+ export const MAX_PEER_ADDRS_TO_DIAL = 25;
17
+ /**
18
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxParallelDialsPerPeer
19
+ */
20
+ export const MAX_PARALLEL_DIALS_PER_PEER = 10;
21
+ /**
22
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#minConnections
23
+ */
24
+ export const MIN_CONNECTIONS = 50;
25
+ /**
26
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxConnections
27
+ */
28
+ export const MAX_CONNECTIONS = 300;
29
+ /**
30
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialInterval
31
+ */
32
+ export const AUTO_DIAL_INTERVAL = 5000;
33
+ /**
34
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialConcurrency
35
+ */
36
+ export const AUTO_DIAL_CONCURRENCY = 25;
37
+ /**
38
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialPriority
39
+ */
40
+ export const AUTO_DIAL_PRIORITY = 0;
41
+ /**
42
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
43
+ */
44
+ export const INBOUND_CONNECTION_THRESHOLD = 5;
45
+ /**
46
+ * @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#maxIncomingPendingConnections
47
+ */
48
+ export const MAX_INCOMING_PENDING_CONNECTIONS = 10;
49
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/connection-manager/constants.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAA;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAA;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAA;AAEjC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAA;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAA;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,CAAA"}
@@ -0,0 +1,78 @@
1
+ import { Multiaddr, Resolver } from '@multiformats/multiaddr';
2
+ import type { Connection } from '@libp2p/interface-connection';
3
+ import type { AbortOptions } from '@libp2p/interfaces';
4
+ import type { PeerId } from '@libp2p/interface-peer-id';
5
+ import type { PeerStore } from '@libp2p/interface-peer-store';
6
+ import type { Metrics } from '@libp2p/interface-metrics';
7
+ import type { TransportManager } from '@libp2p/interface-transport';
8
+ import type { ConnectionGater } from '@libp2p/interface-connection-gater';
9
+ import PQueue from 'p-queue';
10
+ import type { AddressSorter } from '@libp2p/interface-libp2p';
11
+ export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success';
12
+ export interface PendingDial {
13
+ id: string;
14
+ status: PendingDialStatus;
15
+ peerId?: PeerId;
16
+ multiaddrs: Multiaddr[];
17
+ promise: Promise<Connection>;
18
+ }
19
+ export interface PendingDialTarget {
20
+ resolve: (value: any) => void;
21
+ reject: (err: Error) => void;
22
+ }
23
+ export interface DialOptions extends AbortOptions {
24
+ priority?: number;
25
+ }
26
+ interface DialerInit {
27
+ addressSorter?: AddressSorter;
28
+ maxParallelDials?: number;
29
+ maxPeerAddrsToDial?: number;
30
+ maxParallelDialsPerPeer?: number;
31
+ dialTimeout?: number;
32
+ resolvers?: Record<string, Resolver>;
33
+ }
34
+ interface DialQueueComponents {
35
+ peerId: PeerId;
36
+ metrics?: Metrics;
37
+ peerStore: PeerStore;
38
+ transportManager: TransportManager;
39
+ connectionGater: ConnectionGater;
40
+ }
41
+ export declare class DialQueue {
42
+ pendingDials: PendingDial[];
43
+ queue: PQueue;
44
+ private readonly peerId;
45
+ private readonly peerStore;
46
+ private readonly connectionGater;
47
+ private readonly transportManager;
48
+ private readonly addressSorter;
49
+ private readonly maxPeerAddrsToDial;
50
+ private readonly maxParallelDialsPerPeer;
51
+ private readonly dialTimeout;
52
+ private readonly inProgressDialCount?;
53
+ private readonly pendingDialCount?;
54
+ private readonly shutDownController;
55
+ constructor(components: DialQueueComponents, init?: DialerInit);
56
+ /**
57
+ * Clears any pending dials
58
+ */
59
+ stop(): void;
60
+ /**
61
+ * Connects to a given peer, multiaddr or list of multiaddrs.
62
+ *
63
+ * If a peer is passed, all known multiaddrs will be tried. If a multiaddr or
64
+ * multiaddrs are passed only those will be dialled.
65
+ *
66
+ * Where a list of multiaddrs is passed, if any contain a peer id then all
67
+ * multiaddrs in the list must contain the same peer id.
68
+ *
69
+ * The dial to the first address that is successfully able to upgrade a connection
70
+ * will be used, all other dials will be aborted when that happens.
71
+ */
72
+ dial(peerIdOrMultiaddr: PeerId | Multiaddr | Multiaddr[], options?: DialOptions): Promise<Connection>;
73
+ private createDialAbortControllers;
74
+ private calculateMultiaddrs;
75
+ private performDial;
76
+ }
77
+ export {};
78
+ //# sourceMappingURL=dial-queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dial-queue.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/dial-queue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAa,MAAM,yBAAyB,CAAA;AAUxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,OAAO,KAAK,EAAW,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAU,OAAO,EAAE,MAAM,2BAA2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