libp2p 0.42.2-c02e1bd4 → 0.42.2-e12202e9
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.
- package/dist/index.min.js +19 -19
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +18 -9
- package/dist/src/connection-manager/auto-dialler.js.map +1 -1
- package/package.json +1 -1
- package/src/connection-manager/auto-dialler.ts +32 -20
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auto-dialler.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAI7D,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;CACrB;AAQD,qBAAa,WAAY,YAAW,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAC,CAAqB;IAE7C;;;;OAIG;gBACU,UAAU,EAAE,qBAAqB,EAAE,IAAI,EAAE,eAAe;IASrE,SAAS;IAIT;;OAEG;IACG,KAAK;IAeX;;OAEG;IACG,IAAI;IAeJ,SAAS;CAyEhB"}
|
|
@@ -2,10 +2,6 @@ import { logger } from '@libp2p/logger';
|
|
|
2
2
|
import mergeOptions from 'merge-options';
|
|
3
3
|
// @ts-expect-error retimer does not have types
|
|
4
4
|
import retimer from 'retimer';
|
|
5
|
-
import all from 'it-all';
|
|
6
|
-
import { pipe } from 'it-pipe';
|
|
7
|
-
import filter from 'it-filter';
|
|
8
|
-
import sort from 'it-sort';
|
|
9
5
|
const log = logger('libp2p:connection-manager:auto-dialler');
|
|
10
6
|
const defaultOptions = {
|
|
11
7
|
enabled: true,
|
|
@@ -67,18 +63,31 @@ export class AutoDialler {
|
|
|
67
63
|
return;
|
|
68
64
|
}
|
|
69
65
|
// Sort peers on whether we know protocols or public keys for them
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
let peers = await this.components.peerStore.all();
|
|
67
|
+
peers = peers.filter((peer) => {
|
|
68
|
+
// do not dial ourselves
|
|
69
|
+
if (peer.id.equals(this.components.peerId)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
// do not dial peers without multiaddrs
|
|
73
|
+
if (peer.addresses.length === 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
72
78
|
// shuffle the peers
|
|
73
|
-
|
|
79
|
+
peers = peers.sort(() => Math.random() > 0.5 ? 1 : -1);
|
|
80
|
+
peers = peers.sort((a, b) => {
|
|
81
|
+
// dial peers with the most protocols first
|
|
74
82
|
if (b.protocols.length > a.protocols.length) {
|
|
75
83
|
return 1;
|
|
76
84
|
}
|
|
77
|
-
|
|
85
|
+
// dial peers with public keys first
|
|
86
|
+
if (b.id.publicKey != null && a.id.publicKey == null) {
|
|
78
87
|
return 1;
|
|
79
88
|
}
|
|
80
89
|
return -1;
|
|
81
|
-
})
|
|
90
|
+
});
|
|
82
91
|
for (let i = 0; this.running && i < peers.length && this.components.connectionManager.getConnections().length < minConnections; i++) {
|
|
83
92
|
// Connection Manager was stopped during async dial
|
|
84
93
|
if (!this.running) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-dialler.js","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,+CAA+C;AAC/C,OAAO,OAAO,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"auto-dialler.js","sourceRoot":"","sources":["../../../src/connection-manager/auto-dialler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,+CAA+C;AAC/C,OAAO,OAAO,MAAM,SAAS,CAAA;AAM7B,MAAM,GAAG,GAAG,MAAM,CAAC,wCAAwC,CAAC,CAAA;AAyB5D,MAAM,cAAc,GAA6B;IAC/C,OAAO,EAAE,IAAI;IACb,cAAc,EAAE,CAAC;IACjB,gBAAgB,EAAE,KAAK;CACxB,CAAA;AAED,MAAM,OAAO,WAAW;IAMtB;;;;OAIG;IACH,YAAa,UAAiC,EAAE,IAAqB;QACnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,CAAA;QACjF,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE1C,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,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,EAAE,EAAE;YACnI,mDAAmD;YACnD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACjB,OAAM;aACP;YAED,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;YAErB,IAAI,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1E,GAAG,CAAC,0CAA0C,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;gBACxD,IAAI;oBACF,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;iBAChE;gBAAC,OAAO,GAAQ,EAAE;oBACjB,GAAG,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAA;iBAC7D;aACF;SACF;QAED,iCAAiC;QACjC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,OAAM;SACP;QAED,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC/E,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.42.2-
|
|
3
|
+
"version": "0.42.2-e12202e9",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p#readme",
|
|
@@ -2,10 +2,6 @@ import { logger } from '@libp2p/logger'
|
|
|
2
2
|
import mergeOptions from 'merge-options'
|
|
3
3
|
// @ts-expect-error retimer does not have types
|
|
4
4
|
import retimer from 'retimer'
|
|
5
|
-
import all from 'it-all'
|
|
6
|
-
import { pipe } from 'it-pipe'
|
|
7
|
-
import filter from 'it-filter'
|
|
8
|
-
import sort from 'it-sort'
|
|
9
5
|
import type { Startable } from '@libp2p/interfaces/startable'
|
|
10
6
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
7
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
@@ -117,22 +113,38 @@ export class AutoDialler implements Startable {
|
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
// Sort peers on whether we know protocols or public keys for them
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
116
|
+
let peers = await this.components.peerStore.all()
|
|
117
|
+
|
|
118
|
+
peers = peers.filter((peer) => {
|
|
119
|
+
// do not dial ourselves
|
|
120
|
+
if (peer.id.equals(this.components.peerId)) {
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// do not dial peers without multiaddrs
|
|
125
|
+
if (peer.addresses.length === 0) {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return true
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
// shuffle the peers
|
|
133
|
+
peers = peers.sort(() => Math.random() > 0.5 ? 1 : -1)
|
|
134
|
+
|
|
135
|
+
peers = peers.sort((a, b) => {
|
|
136
|
+
// dial peers with the most protocols first
|
|
137
|
+
if (b.protocols.length > a.protocols.length) {
|
|
138
|
+
return 1
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// dial peers with public keys first
|
|
142
|
+
if (b.id.publicKey != null && a.id.publicKey == null) {
|
|
143
|
+
return 1
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return -1
|
|
147
|
+
})
|
|
136
148
|
|
|
137
149
|
for (let i = 0; this.running && i < peers.length && this.components.connectionManager.getConnections().length < minConnections; i++) {
|
|
138
150
|
// Connection Manager was stopped during async dial
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.42.2-
|
|
1
|
+
export const version = '0.42.2-e12202e9'
|
|
2
2
|
export const name = 'libp2p'
|