libp2p 0.45.5 → 0.45.6-de61ddb4
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 +21 -21
- package/dist/src/autonat/index.js +4 -4
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +11 -4
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +5 -0
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +14 -2
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +64 -27
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/constants.d.ts +4 -0
- package/dist/src/connection-manager/constants.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.js +4 -0
- package/dist/src/connection-manager/constants.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +5 -0
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +11 -10
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +1 -1
- package/dist/src/upnp-nat/index.d.ts.map +1 -1
- package/dist/src/upnp-nat/index.js +3 -3
- package/dist/src/upnp-nat/index.js.map +1 -1
- package/dist/src/utils/peer-job-queue.d.ts +33 -0
- package/dist/src/utils/peer-job-queue.d.ts.map +1 -0
- package/dist/src/utils/peer-job-queue.js +82 -0
- package/dist/src/utils/peer-job-queue.js.map +1 -0
- 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 -8
- package/src/autonat/index.ts +4 -4
- package/src/circuit-relay/transport/discovery.ts +11 -4
- package/src/circuit-relay/transport/reservation-store.ts +22 -3
- package/src/connection-manager/auto-dial.ts +75 -31
- package/src/connection-manager/constants.ts +5 -0
- package/src/connection-manager/index.ts +18 -12
- package/src/upnp-nat/index.ts +3 -3
- package/src/utils/peer-job-queue.ts +119 -0
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/upnp-nat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAA;AASnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAS7D,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,cAAM,OAAQ,YAAW,SAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC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AAE,OAAO,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,cAAM,OAAQ,YAAW,SAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAEV,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IAgB7D,SAAS,IAAK,OAAO;IAIrB,KAAK,IAAK,IAAI;IAId;;;;OAIG;IACH,UAAU,IAAK,IAAI;IAcb,MAAM,IAAK,OAAO,CAAC,IAAI,CAAC;IAuD9B,UAAU,IAAK,MAAM;IAerB;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAY7B;AAED,wBAAgB,cAAc,CAAE,IAAI,GAAE,WAAgB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAIlG"}
|
|
@@ -76,7 +76,7 @@ class UPnPNAT {
|
|
|
76
76
|
// eslint-disable-next-line no-continue
|
|
77
77
|
continue;
|
|
78
78
|
}
|
|
79
|
-
const client =
|
|
79
|
+
const client = this._getClient();
|
|
80
80
|
const publicIp = this.externalAddress ?? await client.externalIp();
|
|
81
81
|
const isPrivate = isPrivateIp(publicIp);
|
|
82
82
|
if (isPrivate === true) {
|
|
@@ -100,11 +100,11 @@ class UPnPNAT {
|
|
|
100
100
|
}, transport));
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
|
|
103
|
+
_getClient() {
|
|
104
104
|
if (this.client != null) {
|
|
105
105
|
return this.client;
|
|
106
106
|
}
|
|
107
|
-
this.client =
|
|
107
|
+
this.client = upnpNat({
|
|
108
108
|
description: this.description,
|
|
109
109
|
ttl: this.ttl,
|
|
110
110
|
keepAlive: this.keepAlive,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/upnp-nat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,WAAW,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAA;AAMpC,MAAM,GAAG,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA;AACrC,MAAM,WAAW,GAAG,IAAI,CAAA;AAExB,SAAS,QAAQ,CAAE,GAAG,GAAG,IAAI,EAAE,GAAG,GAAG,KAAK;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAA;AAC1D,CAAC;AA+CD,MAAM,OAAO;IACM,UAAU,CAAmB;IAC7B,eAAe,CAAS;IACxB,YAAY,CAAS;IACrB,WAAW,CA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f;IACH,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,OAAoB,EAAE;IACpD,OAAO,CAAC,UAA6B,EAAE,EAAE;QACvC,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
|
+
import type { QueueAddOptions, Options, Queue } from 'p-queue';
|
|
4
|
+
interface RunFunction {
|
|
5
|
+
(): Promise<unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface PeerPriorityQueueOptions extends QueueAddOptions {
|
|
8
|
+
peerId: PeerId;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Port of https://github.com/sindresorhus/p-queue/blob/main/source/priority-queue.ts
|
|
12
|
+
* that adds support for filtering jobs by peer id
|
|
13
|
+
*/
|
|
14
|
+
declare class PeerPriorityQueue implements Queue<RunFunction, PeerPriorityQueueOptions> {
|
|
15
|
+
#private;
|
|
16
|
+
enqueue(run: RunFunction, options?: Partial<PeerPriorityQueueOptions>): void;
|
|
17
|
+
dequeue(): RunFunction | undefined;
|
|
18
|
+
filter(options: Readonly<Partial<PeerPriorityQueueOptions>>): RunFunction[];
|
|
19
|
+
get size(): number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extends PQueue to add support for querying queued jobs by peer id
|
|
23
|
+
*/
|
|
24
|
+
export declare class PeerJobQueue extends PQueue<PeerPriorityQueue, PeerPriorityQueueOptions> {
|
|
25
|
+
constructor(options?: Options<PeerPriorityQueue, PeerPriorityQueueOptions>);
|
|
26
|
+
/**
|
|
27
|
+
* Returns true if this queue has a job for the passed peer id that has not yet
|
|
28
|
+
* started to run
|
|
29
|
+
*/
|
|
30
|
+
hasJob(peerId: PeerId): boolean;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=peer-job-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-job-queue.d.ts","sourceRoot":"","sources":["../../../src/utils/peer-job-queue.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAuB9D,UAAU,WAAW;IAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE;AAE9C,MAAM,WAAW,wBAAyB,SAAQ,eAAe;IAC/D,MAAM,EAAE,MAAM,CAAA;CACf;AAQD;;;GAGG;AACH,cAAM,iBAAkB,YAAW,KAAK,CAAC,WAAW,EAAE,wBAAwB,CAAC;;IAG7E,OAAO,CAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI;IA0B7E,OAAO,IAAK,WAAW,GAAG,SAAS;IAKnC,MAAM,CAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,WAAW,EAAE;IAc5E,IAAI,IAAI,IAAK,MAAM,CAElB;CACF;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM,CAAC,iBAAiB,EAAE,wBAAwB,CAAC;gBACtE,OAAO,GAAE,OAAO,CAAC,iBAAiB,EAAE,wBAAwB,CAAM;IAO/E;;;OAGG;IACH,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO;CAKjC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors';
|
|
3
|
+
import PQueue from 'p-queue';
|
|
4
|
+
import { codes } from '../errors.js';
|
|
5
|
+
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
|
|
6
|
+
// Used to compute insertion index to keep queue sorted after insertion
|
|
7
|
+
function lowerBound(array, value, comparator) {
|
|
8
|
+
let first = 0;
|
|
9
|
+
let count = array.length;
|
|
10
|
+
while (count > 0) {
|
|
11
|
+
const step = Math.trunc(count / 2);
|
|
12
|
+
let it = first + step;
|
|
13
|
+
if (comparator(array[it], value) <= 0) {
|
|
14
|
+
first = ++it;
|
|
15
|
+
count -= step + 1;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
count = step;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return first;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Port of https://github.com/sindresorhus/p-queue/blob/main/source/priority-queue.ts
|
|
25
|
+
* that adds support for filtering jobs by peer id
|
|
26
|
+
*/
|
|
27
|
+
class PeerPriorityQueue {
|
|
28
|
+
#queue = [];
|
|
29
|
+
enqueue(run, options) {
|
|
30
|
+
const peerId = options?.peerId;
|
|
31
|
+
const priority = options?.priority ?? 0;
|
|
32
|
+
if (peerId == null) {
|
|
33
|
+
throw new CodeError('missing peer id', codes.ERR_INVALID_PARAMETERS);
|
|
34
|
+
}
|
|
35
|
+
const element = {
|
|
36
|
+
priority,
|
|
37
|
+
peerId,
|
|
38
|
+
run
|
|
39
|
+
};
|
|
40
|
+
if (this.size > 0 && this.#queue[this.size - 1].priority >= priority) {
|
|
41
|
+
this.#queue.push(element);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
|
|
45
|
+
this.#queue.splice(index, 0, element);
|
|
46
|
+
}
|
|
47
|
+
dequeue() {
|
|
48
|
+
const item = this.#queue.shift();
|
|
49
|
+
return item?.run;
|
|
50
|
+
}
|
|
51
|
+
filter(options) {
|
|
52
|
+
if (options.peerId != null) {
|
|
53
|
+
const peerId = options.peerId;
|
|
54
|
+
return this.#queue.filter((element) => peerId.equals(element.peerId)).map((element) => element.run);
|
|
55
|
+
}
|
|
56
|
+
return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
57
|
+
}
|
|
58
|
+
get size() {
|
|
59
|
+
return this.#queue.length;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Extends PQueue to add support for querying queued jobs by peer id
|
|
64
|
+
*/
|
|
65
|
+
export class PeerJobQueue extends PQueue {
|
|
66
|
+
constructor(options = {}) {
|
|
67
|
+
super({
|
|
68
|
+
...options,
|
|
69
|
+
queueClass: PeerPriorityQueue
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if this queue has a job for the passed peer id that has not yet
|
|
74
|
+
* started to run
|
|
75
|
+
*/
|
|
76
|
+
hasJob(peerId) {
|
|
77
|
+
return this.sizeBy({
|
|
78
|
+
peerId
|
|
79
|
+
}) > 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=peer-job-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-job-queue.js","sourceRoot":"","sources":["../../../src/utils/peer-job-queue.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAIpC,mFAAmF;AACnF,uEAAuE;AACvE,SAAS,UAAU,CAAK,KAAmB,EAAE,KAAQ,EAAE,UAAkC;IACvF,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAA;IAExB,OAAO,KAAK,GAAG,CAAC,EAAE;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;QAClC,IAAI,EAAE,GAAG,KAAK,GAAG,IAAI,CA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EAAE,GAAG,CAAA;IAClB,CAAC;IAED,MAAM,CAAE,OAAoD;QAC1D,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;YAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;YAE7B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CACvB,CAAC,OAA2C,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAC/E,CAAC,GAAG,CAAC,CAAC,OAAuC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;SAChE;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CACvB,CAAC,OAA2C,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,QAAQ,CACvF,CAAC,GAAG,CAAC,CAAC,OAAuC,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;IAC3B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAmD;IACnF,YAAa,UAAgE,EAAE;QAC7E,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,UAAU,EAAE,iBAAiB;SAC9B,CAAC,CAAA;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAE,MAAc;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC;YACjB,MAAM;SACP,CAAC,GAAG,CAAC,CAAA;IACR,CAAC;CACF"}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"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,WAAW,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,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.6-de61ddb4",
|
|
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",
|
|
@@ -102,7 +102,6 @@
|
|
|
102
102
|
"dep-check": "aegir dep-check -i protons",
|
|
103
103
|
"prepublishOnly": "node scripts/update-version.js && npm run build",
|
|
104
104
|
"build": "aegir build",
|
|
105
|
-
"docs": "aegir docs",
|
|
106
105
|
"generate": "run-s generate:proto:*",
|
|
107
106
|
"generate:proto:autonat": "protons ./src/autonat/pb/index.proto",
|
|
108
107
|
"generate:proto:circuit": "protons ./src/circuit/pb/index.proto",
|
|
@@ -115,12 +114,12 @@
|
|
|
115
114
|
"test:chrome-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\"",
|
|
116
115
|
"test:firefox": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
|
|
117
116
|
"test:firefox-webworker": "aegir test -t webworker -f \"./dist/test/**/*.spec.js\" -- --browser firefox",
|
|
118
|
-
"test:
|
|
117
|
+
"test:webkit": "aegir test -t browser -f \"./dist/test/**/*.spec.js\" -- --browser webkit",
|
|
119
118
|
"test:interop": "aegir test -t node -f dist/test/interop.js"
|
|
120
119
|
},
|
|
121
120
|
"dependencies": {
|
|
122
|
-
"@achingbrain/nat-port-mapper": "^1.0.
|
|
123
|
-
"@libp2p/crypto": "^1.0.
|
|
121
|
+
"@achingbrain/nat-port-mapper": "^1.0.9",
|
|
122
|
+
"@libp2p/crypto": "^1.0.17",
|
|
124
123
|
"@libp2p/interface-address-manager": "^3.0.0",
|
|
125
124
|
"@libp2p/interface-connection": "^5.0.0",
|
|
126
125
|
"@libp2p/interface-connection-encrypter": "^4.0.0",
|
|
@@ -134,7 +133,7 @@
|
|
|
134
133
|
"@libp2p/interface-peer-id": "^2.0.1",
|
|
135
134
|
"@libp2p/interface-peer-info": "^1.0.3",
|
|
136
135
|
"@libp2p/interface-peer-routing": "^1.1.0",
|
|
137
|
-
"@libp2p/interface-peer-store": "^2.0.
|
|
136
|
+
"@libp2p/interface-peer-store": "^2.0.4",
|
|
138
137
|
"@libp2p/interface-pubsub": "^4.0.0",
|
|
139
138
|
"@libp2p/interface-record": "^2.0.6",
|
|
140
139
|
"@libp2p/interface-registrar": "^2.0.3",
|
|
@@ -142,13 +141,13 @@
|
|
|
142
141
|
"@libp2p/interface-transport": "^4.0.0",
|
|
143
142
|
"@libp2p/interfaces": "^3.2.0",
|
|
144
143
|
"@libp2p/keychain": "^2.0.0",
|
|
145
|
-
"@libp2p/logger": "^2.
|
|
144
|
+
"@libp2p/logger": "^2.1.1",
|
|
146
145
|
"@libp2p/multistream-select": "^3.1.8",
|
|
147
146
|
"@libp2p/peer-collections": "^3.0.0",
|
|
148
147
|
"@libp2p/peer-id": "^2.0.0",
|
|
149
148
|
"@libp2p/peer-id-factory": "^2.0.0",
|
|
150
149
|
"@libp2p/peer-record": "^5.0.0",
|
|
151
|
-
"@libp2p/peer-store": "^8.
|
|
150
|
+
"@libp2p/peer-store": "^8.2.0",
|
|
152
151
|
"@libp2p/topology": "^4.0.1",
|
|
153
152
|
"@libp2p/tracked-map": "^3.0.0",
|
|
154
153
|
"@libp2p/utils": "^3.0.10",
|
|
@@ -223,5 +222,8 @@
|
|
|
223
222
|
"browser": {
|
|
224
223
|
"./dist/src/config/connection-gater.js": "./dist/src/config/connection-gater.browser.js",
|
|
225
224
|
"nat-api": false
|
|
225
|
+
},
|
|
226
|
+
"typedoc": {
|
|
227
|
+
"entryPoint": "./src/index.ts"
|
|
226
228
|
}
|
|
227
229
|
}
|
package/src/autonat/index.ts
CHANGED
|
@@ -508,7 +508,7 @@ class DefaultAutoNATService implements Startable {
|
|
|
508
508
|
// they either told us which address worked/didn't work, or we only sent them one address
|
|
509
509
|
const addr = dialResponse.addr == null ? multiaddrs[0] : multiaddr(dialResponse.addr)
|
|
510
510
|
|
|
511
|
-
log('autonat response for %
|
|
511
|
+
log('autonat response for %a is %s', addr, dialResponse.status)
|
|
512
512
|
|
|
513
513
|
if (dialResponse.status === Message.ResponseStatus.E_BAD_REQUEST) {
|
|
514
514
|
// the remote could not parse our request
|
|
@@ -526,7 +526,7 @@ class DefaultAutoNATService implements Startable {
|
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
if (!multiaddrs.some(ma => ma.equals(addr))) {
|
|
529
|
-
log('peer reported %
|
|
529
|
+
log('peer reported %a as %s but it was not in our observed address list', addr, dialResponse.status)
|
|
530
530
|
continue
|
|
531
531
|
}
|
|
532
532
|
|
|
@@ -544,14 +544,14 @@ class DefaultAutoNATService implements Startable {
|
|
|
544
544
|
|
|
545
545
|
if (results[addrStr].success === REQUIRED_SUCCESSFUL_DIALS) {
|
|
546
546
|
// we are now convinced
|
|
547
|
-
log('%
|
|
547
|
+
log('%a is externally dialable', addr)
|
|
548
548
|
addressManager.confirmObservedAddr(addr)
|
|
549
549
|
return
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
if (results[addrStr].failure === REQUIRED_SUCCESSFUL_DIALS) {
|
|
553
553
|
// we are now unconvinced
|
|
554
|
-
log('%
|
|
554
|
+
log('%a is not externally dialable', addr)
|
|
555
555
|
addressManager.removeObservedAddr(addr)
|
|
556
556
|
return
|
|
557
557
|
}
|
|
@@ -89,10 +89,17 @@ export class RelayDiscovery extends EventEmitter<RelayDiscoveryEvents> implement
|
|
|
89
89
|
*/
|
|
90
90
|
async discover (): Promise<void> {
|
|
91
91
|
log('searching peer store for relays')
|
|
92
|
-
const peers = (await this.peerStore.all(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
const peers = (await this.peerStore.all({
|
|
93
|
+
filters: [
|
|
94
|
+
// filter by a list of peers supporting RELAY_V2_HOP and ones we are not listening on
|
|
95
|
+
(peer) => {
|
|
96
|
+
return peer.protocols.includes(RELAY_V2_HOP_CODEC)
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
orders: [
|
|
100
|
+
() => Math.random() < 0.5 ? 1 : -1
|
|
101
|
+
]
|
|
102
|
+
}))
|
|
96
103
|
|
|
97
104
|
for (const peer of peers) {
|
|
98
105
|
log('found relay peer %p in content peer store', peer.id)
|
|
@@ -3,7 +3,7 @@ import { logger } from '@libp2p/logger'
|
|
|
3
3
|
import { PeerMap } from '@libp2p/peer-collections'
|
|
4
4
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
5
5
|
import { pbStream } from 'it-pb-stream'
|
|
6
|
-
import
|
|
6
|
+
import { PeerJobQueue } from '../../utils/peer-job-queue.js'
|
|
7
7
|
import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js'
|
|
8
8
|
import { HopMessage, Status } from '../pb/index.js'
|
|
9
9
|
import { getExpirationMilliseconds } from '../utils.js'
|
|
@@ -50,6 +50,11 @@ export interface RelayStoreInit {
|
|
|
50
50
|
* How many discovered relays to allow in the reservation store
|
|
51
51
|
*/
|
|
52
52
|
discoverRelays?: number
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Limit the number of potential relays we will dial (default: 100)
|
|
56
|
+
*/
|
|
57
|
+
maxReservationQueueLength?: number
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
export type RelayType = 'discovered' | 'configured'
|
|
@@ -71,9 +76,10 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
71
76
|
private readonly transportManager: TransportManager
|
|
72
77
|
private readonly peerStore: PeerStore
|
|
73
78
|
private readonly events: EventEmitter<Libp2pEvents>
|
|
74
|
-
private readonly reserveQueue:
|
|
79
|
+
private readonly reserveQueue: PeerJobQueue
|
|
75
80
|
private readonly reservations: PeerMap<RelayEntry>
|
|
76
81
|
private readonly maxDiscoveredRelays: number
|
|
82
|
+
private readonly maxReservationQueueLength: number
|
|
77
83
|
private started: boolean
|
|
78
84
|
|
|
79
85
|
constructor (components: RelayStoreComponents, init?: RelayStoreInit) {
|
|
@@ -86,10 +92,11 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
86
92
|
this.events = components.events
|
|
87
93
|
this.reservations = new PeerMap()
|
|
88
94
|
this.maxDiscoveredRelays = init?.discoverRelays ?? 0
|
|
95
|
+
this.maxReservationQueueLength = init?.maxReservationQueueLength ?? 100
|
|
89
96
|
this.started = false
|
|
90
97
|
|
|
91
98
|
// ensure we don't listen on multiple relays simultaneously
|
|
92
|
-
this.reserveQueue = new
|
|
99
|
+
this.reserveQueue = new PeerJobQueue({
|
|
93
100
|
concurrency: init?.reservationConcurrency ?? DEFAULT_RESERVATION_CONCURRENCY
|
|
94
101
|
})
|
|
95
102
|
|
|
@@ -130,6 +137,16 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
130
137
|
return
|
|
131
138
|
}
|
|
132
139
|
|
|
140
|
+
if (this.reserveQueue.size > this.maxReservationQueueLength) {
|
|
141
|
+
log('not adding relay as the queue is full')
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (this.reserveQueue.hasJob(peerId)) {
|
|
146
|
+
log('relay peer is already in the reservation queue')
|
|
147
|
+
return
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
log('add relay %p', peerId)
|
|
134
151
|
|
|
135
152
|
await this.reserveQueue.add(async () => {
|
|
@@ -206,6 +223,8 @@ export class ReservationStore extends EventEmitter<ReservationStoreEvents> imple
|
|
|
206
223
|
// if listening failed, remove the reservation
|
|
207
224
|
this.reservations.delete(peerId)
|
|
208
225
|
}
|
|
226
|
+
}, {
|
|
227
|
+
peerId
|
|
209
228
|
})
|
|
210
229
|
}
|
|
211
230
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
|
|
3
|
-
import
|
|
4
|
-
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_PRIORITY, MIN_CONNECTIONS } from './constants.js'
|
|
3
|
+
import { PeerJobQueue } from '../utils/peer-job-queue.js'
|
|
4
|
+
import { AUTO_DIAL_CONCURRENCY, AUTO_DIAL_INTERVAL, AUTO_DIAL_MAX_QUEUE_LENGTH, AUTO_DIAL_PRIORITY, MIN_CONNECTIONS } from './constants.js'
|
|
5
5
|
import type { ConnectionManager } from '@libp2p/interface-connection-manager'
|
|
6
6
|
import type { Libp2pEvents } from '@libp2p/interface-libp2p'
|
|
7
7
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
@@ -12,6 +12,7 @@ const log = logger('libp2p:connection-manager:auto-dial')
|
|
|
12
12
|
|
|
13
13
|
interface AutoDialInit {
|
|
14
14
|
minConnections?: number
|
|
15
|
+
maxQueueLength?: number
|
|
15
16
|
autoDialConcurrency?: number
|
|
16
17
|
autoDialPriority?: number
|
|
17
18
|
autoDialInterval?: number
|
|
@@ -25,6 +26,7 @@ interface AutoDialComponents {
|
|
|
25
26
|
|
|
26
27
|
const defaultOptions = {
|
|
27
28
|
minConnections: MIN_CONNECTIONS,
|
|
29
|
+
maxQueueLength: AUTO_DIAL_MAX_QUEUE_LENGTH,
|
|
28
30
|
autoDialConcurrency: AUTO_DIAL_CONCURRENCY,
|
|
29
31
|
autoDialPriority: AUTO_DIAL_PRIORITY,
|
|
30
32
|
autoDialInterval: AUTO_DIAL_INTERVAL
|
|
@@ -33,12 +35,14 @@ const defaultOptions = {
|
|
|
33
35
|
export class AutoDial implements Startable {
|
|
34
36
|
private readonly connectionManager: ConnectionManager
|
|
35
37
|
private readonly peerStore: PeerStore
|
|
36
|
-
private readonly queue:
|
|
38
|
+
private readonly queue: PeerJobQueue
|
|
37
39
|
private readonly minConnections: number
|
|
38
40
|
private readonly autoDialPriority: number
|
|
39
41
|
private readonly autoDialIntervalMs: number
|
|
42
|
+
private readonly autoDialMaxQueueLength: number
|
|
40
43
|
private autoDialInterval?: ReturnType<typeof setInterval>
|
|
41
44
|
private started: boolean
|
|
45
|
+
private running: boolean
|
|
42
46
|
|
|
43
47
|
/**
|
|
44
48
|
* Proactively tries to connect to known peers stored in the PeerStore.
|
|
@@ -51,8 +55,10 @@ export class AutoDial implements Startable {
|
|
|
51
55
|
this.minConnections = init.minConnections ?? defaultOptions.minConnections
|
|
52
56
|
this.autoDialPriority = init.autoDialPriority ?? defaultOptions.autoDialPriority
|
|
53
57
|
this.autoDialIntervalMs = init.autoDialInterval ?? defaultOptions.autoDialInterval
|
|
58
|
+
this.autoDialMaxQueueLength = init.maxQueueLength ?? defaultOptions.maxQueueLength
|
|
54
59
|
this.started = false
|
|
55
|
-
this.
|
|
60
|
+
this.running = false
|
|
61
|
+
this.queue = new PeerJobQueue({
|
|
56
62
|
concurrency: init.autoDialConcurrency ?? defaultOptions.autoDialConcurrency
|
|
57
63
|
})
|
|
58
64
|
this.queue.addListener('error', (err) => {
|
|
@@ -73,7 +79,7 @@ export class AutoDial implements Startable {
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
start (): void {
|
|
76
|
-
this.autoDialInterval =
|
|
82
|
+
this.autoDialInterval = setTimeout(() => {
|
|
77
83
|
this.autoDial()
|
|
78
84
|
.catch(err => {
|
|
79
85
|
log.error('error while autodialing', err)
|
|
@@ -92,8 +98,9 @@ export class AutoDial implements Startable {
|
|
|
92
98
|
stop (): void {
|
|
93
99
|
// clear the queue
|
|
94
100
|
this.queue.clear()
|
|
95
|
-
|
|
101
|
+
clearTimeout(this.autoDialInterval)
|
|
96
102
|
this.started = false
|
|
103
|
+
this.running = false
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
async autoDial (): Promise<void> {
|
|
@@ -103,12 +110,6 @@ export class AutoDial implements Startable {
|
|
|
103
110
|
|
|
104
111
|
const connections = this.connectionManager.getConnectionsMap()
|
|
105
112
|
const numConnections = connections.size
|
|
106
|
-
const dialQueue = new PeerSet(
|
|
107
|
-
// @ts-expect-error boolean filter removes falsy peer IDs
|
|
108
|
-
this.connectionManager.getDialQueue()
|
|
109
|
-
.map(queue => queue.peerId)
|
|
110
|
-
.filter(Boolean)
|
|
111
|
-
)
|
|
112
113
|
|
|
113
114
|
// Already has enough connections
|
|
114
115
|
if (numConnections >= this.minConnections) {
|
|
@@ -116,34 +117,64 @@ export class AutoDial implements Startable {
|
|
|
116
117
|
return
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
if (this.queue.size > this.autoDialMaxQueueLength) {
|
|
121
|
+
log('not enough connections %d/%d but auto dial queue is full', numConnections, this.minConnections)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
if (this.running) {
|
|
126
|
+
log('not enough connections %d/%d - but skipping autodial as it is already running', numConnections, this.minConnections)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
123
129
|
|
|
124
|
-
|
|
125
|
-
const filteredPeers = peers.filter((peer) => {
|
|
126
|
-
// Remove peers without addresses
|
|
127
|
-
if (peer.addresses.length === 0) {
|
|
128
|
-
return false
|
|
129
|
-
}
|
|
130
|
+
this.running = true
|
|
130
131
|
|
|
131
|
-
|
|
132
|
-
if (connections.has(peer.id)) {
|
|
133
|
-
return false
|
|
134
|
-
}
|
|
132
|
+
log('not enough connections %d/%d - will dial peers to increase the number of connections', numConnections, this.minConnections)
|
|
135
133
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
const dialQueue = new PeerSet(
|
|
135
|
+
// @ts-expect-error boolean filter removes falsy peer IDs
|
|
136
|
+
this.connectionManager.getDialQueue()
|
|
137
|
+
.map(queue => queue.peerId)
|
|
138
|
+
.filter(Boolean)
|
|
139
|
+
)
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
// Sort peers on whether we know protocols or public keys for them
|
|
142
|
+
const peers = await this.peerStore.all({
|
|
143
|
+
filters: [
|
|
144
|
+
// Remove some peers
|
|
145
|
+
(peer) => {
|
|
146
|
+
// Remove peers without addresses
|
|
147
|
+
if (peer.addresses.length === 0) {
|
|
148
|
+
log.trace('not autodialing %p because they have no addresses')
|
|
149
|
+
return false
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// remove peers we are already connected to
|
|
153
|
+
if (connections.has(peer.id)) {
|
|
154
|
+
log.trace('not autodialing %p because they are already connected')
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// remove peers we are already dialling
|
|
159
|
+
if (dialQueue.has(peer.id)) {
|
|
160
|
+
log.trace('not autodialing %p because they are already being dialed')
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// remove peers already in the autodial queue
|
|
165
|
+
if (this.queue.hasJob(peer.id)) {
|
|
166
|
+
log.trace('not autodialing %p because they are already being autodialed')
|
|
167
|
+
return false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
]
|
|
142
173
|
})
|
|
143
174
|
|
|
144
175
|
// shuffle the peers - this is so peers with the same tag values will be
|
|
145
176
|
// dialled in a different order each time
|
|
146
|
-
const shuffledPeers =
|
|
177
|
+
const shuffledPeers = peers.sort(() => Math.random() > 0.5 ? 1 : -1)
|
|
147
178
|
|
|
148
179
|
// Sort shuffled peers by tag value
|
|
149
180
|
const peerValues = new PeerMap<number>()
|
|
@@ -192,9 +223,22 @@ export class AutoDial implements Startable {
|
|
|
192
223
|
// @ts-expect-error needs adding to the ConnectionManager interface
|
|
193
224
|
priority: this.autoDialPriority
|
|
194
225
|
})
|
|
226
|
+
}, {
|
|
227
|
+
peerId: peer.id
|
|
195
228
|
}).catch(err => {
|
|
196
229
|
log.error('could not connect to peerStore stored peer', err)
|
|
197
230
|
})
|
|
198
231
|
}
|
|
232
|
+
|
|
233
|
+
this.running = false
|
|
234
|
+
|
|
235
|
+
if (this.started) {
|
|
236
|
+
this.autoDialInterval = setTimeout(() => {
|
|
237
|
+
this.autoDial()
|
|
238
|
+
.catch(err => {
|
|
239
|
+
log.error('error while autodialing', err)
|
|
240
|
+
})
|
|
241
|
+
}, this.autoDialIntervalMs)
|
|
242
|
+
}
|
|
199
243
|
}
|
|
200
244
|
}
|
|
@@ -49,6 +49,11 @@ export const AUTO_DIAL_CONCURRENCY = 25
|
|
|
49
49
|
*/
|
|
50
50
|
export const AUTO_DIAL_PRIORITY = 0
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#autoDialMaxQueueLength
|
|
54
|
+
*/
|
|
55
|
+
export const AUTO_DIAL_MAX_QUEUE_LENGTH = 100
|
|
56
|
+
|
|
52
57
|
/**
|
|
53
58
|
* @see https://libp2p.github.io/js-libp2p/interfaces/index._internal_.ConnectionManagerConfig.html#inboundConnectionThreshold
|
|
54
59
|
*/
|