libp2p 3.2.4 → 3.3.0-5692f3f16
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 +7 -7
- package/dist/index.min.js.map +4 -4
- package/dist/src/connection-manager/address-sorter.d.ts +0 -22
- package/dist/src/connection-manager/address-sorter.d.ts.map +1 -1
- package/dist/src/connection-manager/address-sorter.js +6 -112
- package/dist/src/connection-manager/address-sorter.js.map +1 -1
- package/dist/src/connection-monitor.d.ts.map +1 -1
- package/dist/src/connection-monitor.js +3 -1
- package/dist/src/connection-monitor.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +10 -10
- package/src/connection-manager/address-sorter.ts +13 -137
- package/src/connection-monitor.ts +5 -2
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -24
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
import type { Address } from '@libp2p/interface';
|
|
2
|
-
/**
|
|
3
|
-
* Sorts addresses by order of reliability, where they have presented the fewest
|
|
4
|
-
* problems:
|
|
5
|
-
*
|
|
6
|
-
* TCP -> WebSockets/Secure -> WebRTC -> WebRTCDirect -> WebTransport
|
|
7
|
-
*/
|
|
8
|
-
export declare function reliableTransportsFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
9
|
-
/**
|
|
10
|
-
* Compare function for array.sort() that moves loopback addresses to the end
|
|
11
|
-
* of the array.
|
|
12
|
-
*/
|
|
13
|
-
export declare function loopbackAddressLast(a: Address, b: Address): -1 | 0 | 1;
|
|
14
|
-
/**
|
|
15
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
16
|
-
* of the array.
|
|
17
|
-
*/
|
|
18
|
-
export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
19
2
|
/**
|
|
20
3
|
* Compare function for array.sort() that moves certified addresses to the start
|
|
21
4
|
* of the array.
|
|
22
5
|
*/
|
|
23
6
|
export declare function certifiedAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
|
|
24
|
-
/**
|
|
25
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
26
|
-
* end of the array.
|
|
27
|
-
*/
|
|
28
|
-
export declare function circuitRelayAddressesLast(a: Address, b: Address): -1 | 0 | 1;
|
|
29
7
|
export declare function defaultAddressSorter(addresses: Address[]): Address[];
|
|
30
8
|
//# sourceMappingURL=address-sorter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sorter.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/address-sorter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"address-sorter.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/address-sorter.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQ3E;AAED,wBAAgB,oBAAoB,CAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAQrE"}
|
|
@@ -1,94 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Circuit, WebSockets, WebSocketsSecure, WebRTC, WebRTCDirect, WebTransport, TCP } from '@multiformats/multiaddr-matcher';
|
|
3
|
-
/**
|
|
4
|
-
* Sorts addresses by order of reliability, where they have presented the fewest
|
|
5
|
-
* problems:
|
|
6
|
-
*
|
|
7
|
-
* TCP -> WebSockets/Secure -> WebRTC -> WebRTCDirect -> WebTransport
|
|
8
|
-
*/
|
|
9
|
-
// eslint-disable-next-line complexity
|
|
10
|
-
export function reliableTransportsFirst(a, b) {
|
|
11
|
-
const isATcp = TCP.exactMatch(a.multiaddr);
|
|
12
|
-
const isBTcp = TCP.exactMatch(b.multiaddr);
|
|
13
|
-
if (isATcp && !isBTcp) {
|
|
14
|
-
return -1;
|
|
15
|
-
}
|
|
16
|
-
if (!isATcp && isBTcp) {
|
|
17
|
-
return 1;
|
|
18
|
-
}
|
|
19
|
-
const isAWebSocketSecure = WebSocketsSecure.exactMatch(a.multiaddr);
|
|
20
|
-
const isBWebSocketSecure = WebSocketsSecure.exactMatch(b.multiaddr);
|
|
21
|
-
if (isAWebSocketSecure && !isBWebSocketSecure) {
|
|
22
|
-
return -1;
|
|
23
|
-
}
|
|
24
|
-
if (!isAWebSocketSecure && isBWebSocketSecure) {
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
27
|
-
const isAWebSocket = WebSockets.exactMatch(a.multiaddr);
|
|
28
|
-
const isBWebSocket = WebSockets.exactMatch(b.multiaddr);
|
|
29
|
-
if (isAWebSocket && !isBWebSocket) {
|
|
30
|
-
return -1;
|
|
31
|
-
}
|
|
32
|
-
if (!isAWebSocket && isBWebSocket) {
|
|
33
|
-
return 1;
|
|
34
|
-
}
|
|
35
|
-
const isAWebRTC = WebRTC.exactMatch(a.multiaddr);
|
|
36
|
-
const isBWebRTC = WebRTC.exactMatch(b.multiaddr);
|
|
37
|
-
if (isAWebRTC && !isBWebRTC) {
|
|
38
|
-
return -1;
|
|
39
|
-
}
|
|
40
|
-
if (!isAWebRTC && isBWebRTC) {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
const isAWebRTCDirect = WebRTCDirect.exactMatch(a.multiaddr);
|
|
44
|
-
const isBWebRTCDirect = WebRTCDirect.exactMatch(b.multiaddr);
|
|
45
|
-
if (isAWebRTCDirect && !isBWebRTCDirect) {
|
|
46
|
-
return -1;
|
|
47
|
-
}
|
|
48
|
-
if (!isAWebRTCDirect && isBWebRTCDirect) {
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
51
|
-
const isAWebTransport = WebTransport.exactMatch(a.multiaddr);
|
|
52
|
-
const isBWebTransport = WebTransport.exactMatch(b.multiaddr);
|
|
53
|
-
if (isAWebTransport && !isBWebTransport) {
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
if (!isAWebTransport && isBWebTransport) {
|
|
57
|
-
return 1;
|
|
58
|
-
}
|
|
59
|
-
// ... everything else
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Compare function for array.sort() that moves loopback addresses to the end
|
|
64
|
-
* of the array.
|
|
65
|
-
*/
|
|
66
|
-
export function loopbackAddressLast(a, b) {
|
|
67
|
-
const isALoopback = isLoopback(a.multiaddr);
|
|
68
|
-
const isBLoopback = isLoopback(b.multiaddr);
|
|
69
|
-
if (isALoopback && !isBLoopback) {
|
|
70
|
-
return 1;
|
|
71
|
-
}
|
|
72
|
-
else if (!isALoopback && isBLoopback) {
|
|
73
|
-
return -1;
|
|
74
|
-
}
|
|
75
|
-
return 0;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
79
|
-
* of the array.
|
|
80
|
-
*/
|
|
81
|
-
export function publicAddressesFirst(a, b) {
|
|
82
|
-
const isAPrivate = isPrivate(a.multiaddr);
|
|
83
|
-
const isBPrivate = isPrivate(b.multiaddr);
|
|
84
|
-
if (isAPrivate && !isBPrivate) {
|
|
85
|
-
return 1;
|
|
86
|
-
}
|
|
87
|
-
else if (!isAPrivate && isBPrivate) {
|
|
88
|
-
return -1;
|
|
89
|
-
}
|
|
90
|
-
return 0;
|
|
91
|
-
}
|
|
1
|
+
import { reliableTransportsFirst, loopbackAddressLast, publicAddressesFirst, circuitRelayAddressesLast } from '@libp2p/utils';
|
|
92
2
|
/**
|
|
93
3
|
* Compare function for array.sort() that moves certified addresses to the start
|
|
94
4
|
* of the array.
|
|
@@ -102,27 +12,11 @@ export function certifiedAddressesFirst(a, b) {
|
|
|
102
12
|
}
|
|
103
13
|
return 0;
|
|
104
14
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
107
|
-
* end of the array.
|
|
108
|
-
*/
|
|
109
|
-
export function circuitRelayAddressesLast(a, b) {
|
|
110
|
-
const isACircuit = Circuit.exactMatch(a.multiaddr);
|
|
111
|
-
const isBCircuit = Circuit.exactMatch(b.multiaddr);
|
|
112
|
-
if (isACircuit && !isBCircuit) {
|
|
113
|
-
return 1;
|
|
114
|
-
}
|
|
115
|
-
else if (!isACircuit && isBCircuit) {
|
|
116
|
-
return -1;
|
|
117
|
-
}
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
15
|
export function defaultAddressSorter(addresses) {
|
|
121
|
-
return addresses
|
|
122
|
-
.
|
|
123
|
-
.
|
|
124
|
-
|
|
125
|
-
.
|
|
126
|
-
.sort(loopbackAddressLast);
|
|
16
|
+
return addresses.sort((a, b) => loopbackAddressLast(a.multiaddr, b.multiaddr) ||
|
|
17
|
+
publicAddressesFirst(a.multiaddr, b.multiaddr) ||
|
|
18
|
+
circuitRelayAddressesLast(a.multiaddr, b.multiaddr) ||
|
|
19
|
+
certifiedAddressesFirst(a, b) ||
|
|
20
|
+
reliableTransportsFirst(a.multiaddr, b.multiaddr));
|
|
127
21
|
}
|
|
128
22
|
//# sourceMappingURL=address-sorter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-sorter.js","sourceRoot":"","sources":["../../../src/connection-manager/address-sorter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"address-sorter.js","sourceRoot":"","sources":["../../../src/connection-manager/address-sorter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,eAAe,CAAA;AAGtB;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAE,CAAU,EAAE,CAAU;IAC7D,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,CAAC,CAAC,CAAA;IACX,CAAC;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAE,SAAoB;IACxD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC7B,mBAAmB,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC;QAC7C,oBAAoB,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC;QAC9C,yBAAyB,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC;QACnD,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7B,uBAAuB,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAClD,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-monitor.d.ts","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGvD,OAAO,KAAK,EAAE,eAAe,EAAU,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"connection-monitor.d.ts","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGvD,OAAO,KAAK,EAAE,eAAe,EAAU,OAAO,EAAE,SAAS,EAAU,MAAM,mBAAmB,CAAA;AAC5F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AASxD,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,CAAC,CAAA;IAElE;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAA;IAEtC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,eAAe,CAAA;IACvB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,qBAAa,iBAAkB,YAAW,SAAS;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,iBAAiB,CAAC,CAAgC;IAC1D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAQ;IACvC,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAS;gBAEzC,UAAU,EAAE,2BAA2B,EAAE,IAAI,GAAE,qBAA0B;IActF,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,gCAA+B;IAE5D,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAED,KAAK,IAAK,IAAI;IAkEd,IAAI,IAAK,IAAI;CAOd"}
|
|
@@ -43,8 +43,9 @@ export class ConnectionMonitor {
|
|
|
43
43
|
const signal = this.timeout.getTimeoutSignal({
|
|
44
44
|
signal: this.abortController?.signal
|
|
45
45
|
});
|
|
46
|
+
let stream;
|
|
46
47
|
try {
|
|
47
|
-
|
|
48
|
+
stream = await conn.newStream(this.protocol, {
|
|
48
49
|
signal,
|
|
49
50
|
runOnLimitedConnection: true
|
|
50
51
|
});
|
|
@@ -65,6 +66,7 @@ export class ConnectionMonitor {
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
catch (err) {
|
|
69
|
+
stream?.abort(err);
|
|
68
70
|
if (err.name !== 'UnsupportedProtocolError') {
|
|
69
71
|
throw err;
|
|
70
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-monitor.js","sourceRoot":"","sources":["../../src/connection-monitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK5C,MAAM,wBAAwB,GAAG,KAAK,CAAA;AACtC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAChC,MAAM,aAAa,GAAG,MAAM,CAAA;AAC5B,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,WAAW,GAAG,EAAE,CAAA;AACtB,MAAM,wCAAwC,GAAG,IAAI,CAAA;AA+CrD,MAAM,OAAO,iBAAiB;IACX,QAAQ,CAAQ;IAChB,UAAU,CAA6B;IACvC,GAAG,CAAQ;IACpB,iBAAiB,CAAiC;IACzC,cAAc,CAAQ;IAC/B,eAAe,CAAkB;IACxB,OAAO,CAAiB;IACxB,4BAA4B,CAAS;IAEtD,YAAa,UAAuC,EAAE,OAA8B,EAAE;QACpF,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,cAAc,IAAI,eAAe,IAAI,aAAa,IAAI,gBAAgB,EAAE,CAAA;QAEjG,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CA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[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAA;AACxC,eAAO,MAAM,IAAI,cAAc,CAAA"}
|
package/dist/src/version.js
CHANGED
package/dist/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA;AACxC,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0-5692f3f16",
|
|
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/tree/main/packages/libp2p#readme",
|
|
@@ -83,15 +83,15 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@chainsafe/is-ip": "^2.1.0",
|
|
85
85
|
"@chainsafe/netmask": "^2.0.0",
|
|
86
|
-
"@libp2p/crypto": "
|
|
87
|
-
"@libp2p/interface": "
|
|
88
|
-
"@libp2p/interface-internal": "
|
|
89
|
-
"@libp2p/logger": "
|
|
90
|
-
"@libp2p/multistream-select": "
|
|
91
|
-
"@libp2p/peer-collections": "
|
|
92
|
-
"@libp2p/peer-id": "
|
|
93
|
-
"@libp2p/peer-store": "
|
|
94
|
-
"@libp2p/utils": "
|
|
86
|
+
"@libp2p/crypto": "5.1.18-5692f3f16",
|
|
87
|
+
"@libp2p/interface": "3.2.2-5692f3f16",
|
|
88
|
+
"@libp2p/interface-internal": "3.1.4-5692f3f16",
|
|
89
|
+
"@libp2p/logger": "6.2.7-5692f3f16",
|
|
90
|
+
"@libp2p/multistream-select": "7.0.19-5692f3f16",
|
|
91
|
+
"@libp2p/peer-collections": "7.0.19-5692f3f16",
|
|
92
|
+
"@libp2p/peer-id": "6.0.9-5692f3f16",
|
|
93
|
+
"@libp2p/peer-store": "12.0.19-5692f3f16",
|
|
94
|
+
"@libp2p/utils": "7.2.0-5692f3f16",
|
|
95
95
|
"@multiformats/dns": "^1.0.6",
|
|
96
96
|
"@multiformats/multiaddr": "^13.0.1",
|
|
97
97
|
"@multiformats/multiaddr-matcher": "^3.0.1",
|
|
@@ -1,119 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
reliableTransportsFirst,
|
|
3
|
+
loopbackAddressLast,
|
|
4
|
+
publicAddressesFirst,
|
|
5
|
+
circuitRelayAddressesLast
|
|
6
|
+
} from '@libp2p/utils'
|
|
3
7
|
import type { Address } from '@libp2p/interface'
|
|
4
8
|
|
|
5
|
-
/**
|
|
6
|
-
* Sorts addresses by order of reliability, where they have presented the fewest
|
|
7
|
-
* problems:
|
|
8
|
-
*
|
|
9
|
-
* TCP -> WebSockets/Secure -> WebRTC -> WebRTCDirect -> WebTransport
|
|
10
|
-
*/
|
|
11
|
-
// eslint-disable-next-line complexity
|
|
12
|
-
export function reliableTransportsFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
13
|
-
const isATcp = TCP.exactMatch(a.multiaddr)
|
|
14
|
-
const isBTcp = TCP.exactMatch(b.multiaddr)
|
|
15
|
-
|
|
16
|
-
if (isATcp && !isBTcp) {
|
|
17
|
-
return -1
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!isATcp && isBTcp) {
|
|
21
|
-
return 1
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const isAWebSocketSecure = WebSocketsSecure.exactMatch(a.multiaddr)
|
|
25
|
-
const isBWebSocketSecure = WebSocketsSecure.exactMatch(b.multiaddr)
|
|
26
|
-
|
|
27
|
-
if (isAWebSocketSecure && !isBWebSocketSecure) {
|
|
28
|
-
return -1
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!isAWebSocketSecure && isBWebSocketSecure) {
|
|
32
|
-
return 1
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const isAWebSocket = WebSockets.exactMatch(a.multiaddr)
|
|
36
|
-
const isBWebSocket = WebSockets.exactMatch(b.multiaddr)
|
|
37
|
-
|
|
38
|
-
if (isAWebSocket && !isBWebSocket) {
|
|
39
|
-
return -1
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!isAWebSocket && isBWebSocket) {
|
|
43
|
-
return 1
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const isAWebRTC = WebRTC.exactMatch(a.multiaddr)
|
|
47
|
-
const isBWebRTC = WebRTC.exactMatch(b.multiaddr)
|
|
48
|
-
|
|
49
|
-
if (isAWebRTC && !isBWebRTC) {
|
|
50
|
-
return -1
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!isAWebRTC && isBWebRTC) {
|
|
54
|
-
return 1
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const isAWebRTCDirect = WebRTCDirect.exactMatch(a.multiaddr)
|
|
58
|
-
const isBWebRTCDirect = WebRTCDirect.exactMatch(b.multiaddr)
|
|
59
|
-
|
|
60
|
-
if (isAWebRTCDirect && !isBWebRTCDirect) {
|
|
61
|
-
return -1
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (!isAWebRTCDirect && isBWebRTCDirect) {
|
|
65
|
-
return 1
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const isAWebTransport = WebTransport.exactMatch(a.multiaddr)
|
|
69
|
-
const isBWebTransport = WebTransport.exactMatch(b.multiaddr)
|
|
70
|
-
|
|
71
|
-
if (isAWebTransport && !isBWebTransport) {
|
|
72
|
-
return -1
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (!isAWebTransport && isBWebTransport) {
|
|
76
|
-
return 1
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ... everything else
|
|
80
|
-
return 0
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Compare function for array.sort() that moves loopback addresses to the end
|
|
85
|
-
* of the array.
|
|
86
|
-
*/
|
|
87
|
-
export function loopbackAddressLast (a: Address, b: Address): -1 | 0 | 1 {
|
|
88
|
-
const isALoopback = isLoopback(a.multiaddr)
|
|
89
|
-
const isBLoopback = isLoopback(b.multiaddr)
|
|
90
|
-
|
|
91
|
-
if (isALoopback && !isBLoopback) {
|
|
92
|
-
return 1
|
|
93
|
-
} else if (!isALoopback && isBLoopback) {
|
|
94
|
-
return -1
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return 0
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Compare function for array.sort() that moves public addresses to the start
|
|
102
|
-
* of the array.
|
|
103
|
-
*/
|
|
104
|
-
export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
105
|
-
const isAPrivate = isPrivate(a.multiaddr)
|
|
106
|
-
const isBPrivate = isPrivate(b.multiaddr)
|
|
107
|
-
|
|
108
|
-
if (isAPrivate && !isBPrivate) {
|
|
109
|
-
return 1
|
|
110
|
-
} else if (!isAPrivate && isBPrivate) {
|
|
111
|
-
return -1
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return 0
|
|
115
|
-
}
|
|
116
|
-
|
|
117
9
|
/**
|
|
118
10
|
* Compare function for array.sort() that moves certified addresses to the start
|
|
119
11
|
* of the array.
|
|
@@ -128,28 +20,12 @@ export function certifiedAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
|
|
|
128
20
|
return 0
|
|
129
21
|
}
|
|
130
22
|
|
|
131
|
-
/**
|
|
132
|
-
* Compare function for array.sort() that moves circuit relay addresses to the
|
|
133
|
-
* end of the array.
|
|
134
|
-
*/
|
|
135
|
-
export function circuitRelayAddressesLast (a: Address, b: Address): -1 | 0 | 1 {
|
|
136
|
-
const isACircuit = Circuit.exactMatch(a.multiaddr)
|
|
137
|
-
const isBCircuit = Circuit.exactMatch(b.multiaddr)
|
|
138
|
-
|
|
139
|
-
if (isACircuit && !isBCircuit) {
|
|
140
|
-
return 1
|
|
141
|
-
} else if (!isACircuit && isBCircuit) {
|
|
142
|
-
return -1
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return 0
|
|
146
|
-
}
|
|
147
|
-
|
|
148
23
|
export function defaultAddressSorter (addresses: Address[]): Address[] {
|
|
149
|
-
return addresses
|
|
150
|
-
.
|
|
151
|
-
.
|
|
152
|
-
.
|
|
153
|
-
|
|
154
|
-
.
|
|
24
|
+
return addresses.sort((a, b) =>
|
|
25
|
+
loopbackAddressLast(a.multiaddr, b.multiaddr) ||
|
|
26
|
+
publicAddressesFirst(a.multiaddr, b.multiaddr) ||
|
|
27
|
+
circuitRelayAddressesLast(a.multiaddr, b.multiaddr) ||
|
|
28
|
+
certifiedAddressesFirst(a, b) ||
|
|
29
|
+
reliableTransportsFirst(a.multiaddr, b.multiaddr)
|
|
30
|
+
)
|
|
155
31
|
}
|
|
@@ -2,7 +2,7 @@ import { randomBytes } from '@libp2p/crypto'
|
|
|
2
2
|
import { serviceCapabilities } from '@libp2p/interface'
|
|
3
3
|
import { AdaptiveTimeout, byteStream } from '@libp2p/utils'
|
|
4
4
|
import { setMaxListeners } from 'main-event'
|
|
5
|
-
import type { ComponentLogger, Logger, Metrics, Startable } from '@libp2p/interface'
|
|
5
|
+
import type { ComponentLogger, Logger, Metrics, Startable, Stream } from '@libp2p/interface'
|
|
6
6
|
import type { ConnectionManager } from '@libp2p/interface-internal'
|
|
7
7
|
import type { AdaptiveTimeoutInit } from '@libp2p/utils'
|
|
8
8
|
|
|
@@ -99,9 +99,10 @@ export class ConnectionMonitor implements Startable {
|
|
|
99
99
|
const signal = this.timeout.getTimeoutSignal({
|
|
100
100
|
signal: this.abortController?.signal
|
|
101
101
|
})
|
|
102
|
+
let stream: Stream | undefined
|
|
102
103
|
|
|
103
104
|
try {
|
|
104
|
-
|
|
105
|
+
stream = await conn.newStream(this.protocol, {
|
|
105
106
|
signal,
|
|
106
107
|
runOnLimitedConnection: true
|
|
107
108
|
})
|
|
@@ -124,6 +125,8 @@ export class ConnectionMonitor implements Startable {
|
|
|
124
125
|
signal
|
|
125
126
|
})
|
|
126
127
|
} catch (err: any) {
|
|
128
|
+
stream?.abort(err)
|
|
129
|
+
|
|
127
130
|
if (err.name !== 'UnsupportedProtocolError') {
|
|
128
131
|
throw err
|
|
129
132
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '3.
|
|
1
|
+
export const version = '3.3.0-5692f3f16'
|
|
2
2
|
export const name = 'js-libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AddressFilter": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressFilter.html",
|
|
3
|
-
"AddressManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressManagerInit.html",
|
|
4
|
-
"ConnectionManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html",
|
|
5
|
-
"ConnectionMonitorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionMonitorInit.html",
|
|
6
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
7
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
8
|
-
"TransportManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.TransportManagerInit.html",
|
|
9
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
10
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
11
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
12
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
13
|
-
"dnsaddrResolver": "https://libp2p.github.io/js-libp2p/variables/libp2p.index.dnsaddrResolver.html",
|
|
14
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
15
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
16
|
-
"isLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.isLibp2p.html",
|
|
17
|
-
".:isLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.isLibp2p.html",
|
|
18
|
-
"userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
19
|
-
"./user-agent:userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
20
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
21
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
22
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
23
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
24
|
-
}
|