@libp2p/utils 6.0.5 → 6.0.6-27b2fa6b6

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.
@@ -9,4 +9,8 @@ export declare class RateLimitError extends Error {
9
9
  isFirstInDuration: boolean;
10
10
  constructor(message: string | undefined, props: RateLimiterResult);
11
11
  }
12
+ export declare class QueueFullError extends Error {
13
+ static name: string;
14
+ constructor(message?: string);
15
+ }
12
16
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE1D;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,OAAO,CAAA;gBAEb,OAAO,oBAAwB,EAAE,KAAK,EAAE,iBAAiB;CAQvE"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE1D;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,iBAAiB,EAAE,OAAO,CAAA;gBAEb,OAAO,oBAAwB,EAAE,KAAK,EAAE,iBAAiB;CAQvE;AAED,qBAAa,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,IAAI,SAAmB;gBAEjB,OAAO,GAAE,MAA6B;CAIpD"}
@@ -15,4 +15,11 @@ export class RateLimitError extends Error {
15
15
  this.isFirstInDuration = props.isFirstInDuration;
16
16
  }
17
17
  }
18
+ export class QueueFullError extends Error {
19
+ static name = 'QueueFullError';
20
+ constructor(message = 'The queue was full') {
21
+ super(message);
22
+ this.name = 'QueueFullError';
23
+ }
24
+ }
18
25
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,eAAe,CAAQ;IACvB,YAAY,CAAQ;IACpB,cAAc,CAAQ;IACtB,iBAAiB,CAAS;IAE1B,YAAa,OAAO,GAAG,qBAAqB,EAAE,KAAwB;QACpE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAA;QAC5C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAA;QACtC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;QAC1C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAA;IAClD,CAAC;CACF"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,eAAe,CAAQ;IACvB,YAAY,CAAQ;IACpB,cAAc,CAAQ;IACtB,iBAAiB,CAAS;IAE1B,YAAa,OAAO,GAAG,qBAAqB,EAAE,KAAwB;QACpE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC,eAAe,CAAA;QAC5C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAA;QACtC,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,cAAc,CAAA;QAC1C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAA;IAClD,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAE9B,YAAa,UAAkB,oBAAoB;QACjD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC"}
@@ -15,6 +15,13 @@ export interface QueueInit<JobReturnType, JobOptions extends AbortOptions = Abor
15
15
  * @default Infinity
16
16
  */
17
17
  concurrency?: number;
18
+ /**
19
+ * If the queue size grows to larger than this number the promise returned
20
+ * from the add function will reject
21
+ *
22
+ * @default Infinity
23
+ */
24
+ maxSize?: number;
18
25
  /**
19
26
  * The name of the metric for the queue length
20
27
  */
@@ -29,8 +36,8 @@ export interface QueueInit<JobReturnType, JobOptions extends AbortOptions = Abor
29
36
  sort?: Comparator<Job<JobOptions, JobReturnType>>;
30
37
  }
31
38
  export type JobStatus = 'queued' | 'running' | 'errored' | 'complete';
32
- export interface RunFunction<Options = AbortOptions, ReturnType = void> {
33
- (opts?: Options): Promise<ReturnType>;
39
+ export interface RunFunction<Options extends AbortOptions = AbortOptions, ReturnType = void> {
40
+ (options: Options): Promise<ReturnType>;
34
41
  }
35
42
  export interface JobMatcher<JobOptions extends AbortOptions = AbortOptions> {
36
43
  (options?: Partial<JobOptions>): boolean;
@@ -91,6 +98,7 @@ export interface QueueEvents<JobReturnType, JobOptions extends AbortOptions = Ab
91
98
  */
92
99
  export declare class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = AbortOptions> extends TypedEventEmitter<QueueEvents<JobReturnType, JobOptions>> {
93
100
  concurrency: number;
101
+ maxSize: number;
94
102
  queue: Array<Job<JobOptions, JobReturnType>>;
95
103
  private pending;
96
104
  private readonly sort?;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAA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Qd;;;;OAIG;IACG,OAAO,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IASrD;;;;;;;;;;OAUG;IACG,cAAc,CAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3E;;;;;;;OAOG;IACG,MAAM,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IASpD;;OAEG;IACH,IAAI,IAAI,IAAK,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,MAAM,IAAK,MAAM,CAEpB;IAED;;OAEG;IACH,IAAI,OAAO,IAAK,MAAM,CAErB;IAED;;;;;;;;;OASG;IACK,WAAW,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC;CAuD3F"}
@@ -1,6 +1,7 @@
1
1
  import { AbortError, TypedEventEmitter } from '@libp2p/interface';
2
2
  import { pushable } from 'it-pushable';
3
3
  import { raceEvent } from 'race-event';
4
+ import { QueueFullError } from '../errors.js';
4
5
  import { Job } from './job.js';
5
6
  /**
6
7
  * Heavily influence by `p-queue` with the following differences:
@@ -10,12 +11,14 @@ import { Job } from './job.js';
10
11
  */
11
12
  export class Queue extends TypedEventEmitter {
12
13
  concurrency;
14
+ maxSize;
13
15
  queue;
14
16
  pending;
15
17
  sort;
16
18
  constructor(init = {}) {
17
19
  super();
18
20
  this.concurrency = init.concurrency ?? Number.POSITIVE_INFINITY;
21
+ this.maxSize = init.maxSize ?? Number.POSITIVE_INFINITY;
19
22
  this.pending = 0;
20
23
  if (init.metricName != null) {
21
24
  init.metrics?.registerMetricGroup(init.metricName, {
@@ -88,6 +91,9 @@ export class Queue extends TypedEventEmitter {
88
91
  */
89
92
  async add(fn, options) {
90
93
  options?.signal?.throwIfAborted();
94
+ if (this.size === this.maxSize) {
95
+ throw new QueueFullError();
96
+ }
91
97
  const job = new Job(fn, options);
92
98
  this.enqueue(job);
93
99
  this.safeDispatchEvent('add');
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/queue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAyG9B;;;;;GAKG;AACH,MAAM,OAAO,KAA+E,SAAQ,iBAAyD;IACpJ,WAAW,CAAQ;IACnB,KAAK,CAAuC;IAC3C,OAAO,CAAQ;IACN,IAAI,CAA6C;IAElE,YAAa,OAA6C,EAAE;QAC1D,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,MAAM,CAAC,iBAAiB,CAAA;QAC/D,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA;QAEhB,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE;gBACjD,SAAS,EAAE,GAAG,EAAE;oBACd,OAAO;wBACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;wBACvB,OAAO,EAAE,IAAI,CAAC,OAAO;wBACrB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO;qBACzC,CAAA;gBACH,CAAC;aACF,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACjB,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACpB,mEAAmE;YACnE,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AE,aAAa,CAAC,CAAA;YAE5D,mEAAmE;YACnE,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "6.0.5",
3
+ "version": "6.0.6-27b2fa6b6",
4
4
  "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/utils#readme",
@@ -56,10 +56,6 @@
56
56
  "types": "./dist/src/adaptive-timeout.d.ts",
57
57
  "import": "./dist/src/adaptive-timeout.js"
58
58
  },
59
- "./address-sort": {
60
- "types": "./dist/src/address-sort.d.ts",
61
- "import": "./dist/src/address-sort.js"
62
- },
63
59
  "./array-equals": {
64
60
  "types": "./dist/src/array-equals.d.ts",
65
61
  "import": "./dist/src/array-equals.js"
@@ -152,11 +148,10 @@
152
148
  },
153
149
  "dependencies": {
154
150
  "@chainsafe/is-ip": "^2.0.2",
155
- "@libp2p/crypto": "^5.0.4",
156
- "@libp2p/interface": "^2.1.2",
157
- "@libp2p/logger": "^5.1.0",
151
+ "@libp2p/crypto": "5.0.4-27b2fa6b6",
152
+ "@libp2p/interface": "2.1.2-27b2fa6b6",
153
+ "@libp2p/logger": "5.1.0-27b2fa6b6",
158
154
  "@multiformats/multiaddr": "^12.2.3",
159
- "@multiformats/multiaddr-matcher": "^1.2.1",
160
155
  "@sindresorhus/fnv1a": "^3.1.0",
161
156
  "@types/murmurhash3js-revisited": "^3.0.3",
162
157
  "any-signal": "^4.1.1",
@@ -176,6 +171,7 @@
176
171
  "uint8arrays": "^5.1.0"
177
172
  },
178
173
  "devDependencies": {
174
+ "@libp2p/peer-id": "5.0.4-27b2fa6b6",
179
175
  "@types/netmask": "^2.0.5",
180
176
  "aegir": "^44.0.1",
181
177
  "benchmark": "^2.1.4",
package/src/errors.ts CHANGED
@@ -18,3 +18,12 @@ export class RateLimitError extends Error {
18
18
  this.isFirstInDuration = props.isFirstInDuration
19
19
  }
20
20
  }
21
+
22
+ export class QueueFullError extends Error {
23
+ static name = 'QueueFullError'
24
+
25
+ constructor (message: string = 'The queue was full') {
26
+ super(message)
27
+ this.name = 'QueueFullError'
28
+ }
29
+ }
@@ -1,6 +1,7 @@
1
1
  import { AbortError, TypedEventEmitter } from '@libp2p/interface'
2
2
  import { pushable } from 'it-pushable'
3
3
  import { raceEvent } from 'race-event'
4
+ import { QueueFullError } from '../errors.js'
4
5
  import { Job } from './job.js'
5
6
  import type { AbortOptions, Metrics } from '@libp2p/interface'
6
7
 
@@ -21,6 +22,14 @@ export interface QueueInit<JobReturnType, JobOptions extends AbortOptions = Abor
21
22
  */
22
23
  concurrency?: number
23
24
 
25
+ /**
26
+ * If the queue size grows to larger than this number the promise returned
27
+ * from the add function will reject
28
+ *
29
+ * @default Infinity
30
+ */
31
+ maxSize?: number
32
+
24
33
  /**
25
34
  * The name of the metric for the queue length
26
35
  */
@@ -39,8 +48,8 @@ export interface QueueInit<JobReturnType, JobOptions extends AbortOptions = Abor
39
48
 
40
49
  export type JobStatus = 'queued' | 'running' | 'errored' | 'complete'
41
50
 
42
- export interface RunFunction<Options = AbortOptions, ReturnType = void> {
43
- (opts?: Options): Promise<ReturnType>
51
+ export interface RunFunction<Options extends AbortOptions = AbortOptions, ReturnType = void> {
52
+ (options: Options): Promise<ReturnType>
44
53
  }
45
54
 
46
55
  export interface JobMatcher<JobOptions extends AbortOptions = AbortOptions> {
@@ -114,6 +123,7 @@ export interface QueueEvents<JobReturnType, JobOptions extends AbortOptions = Ab
114
123
  */
115
124
  export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = AbortOptions> extends TypedEventEmitter<QueueEvents<JobReturnType, JobOptions>> {
116
125
  public concurrency: number
126
+ public maxSize: number
117
127
  public queue: Array<Job<JobOptions, JobReturnType>>
118
128
  private pending: number
119
129
  private readonly sort?: Comparator<Job<JobOptions, JobReturnType>>
@@ -122,6 +132,7 @@ export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = Ab
122
132
  super()
123
133
 
124
134
  this.concurrency = init.concurrency ?? Number.POSITIVE_INFINITY
135
+ this.maxSize = init.maxSize ?? Number.POSITIVE_INFINITY
125
136
  this.pending = 0
126
137
 
127
138
  if (init.metricName != null) {
@@ -212,6 +223,10 @@ export class Queue<JobReturnType = unknown, JobOptions extends AbortOptions = Ab
212
223
  async add (fn: RunFunction<JobOptions, JobReturnType>, options?: JobOptions): Promise<JobReturnType> {
213
224
  options?.signal?.throwIfAborted()
214
225
 
226
+ if (this.size === this.maxSize) {
227
+ throw new QueueFullError()
228
+ }
229
+
215
230
  const job = new Job<JobOptions, JobReturnType>(fn, options)
216
231
  this.enqueue(job)
217
232
  this.safeDispatchEvent('add')
@@ -1,39 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies to sort a list of multiaddrs.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- *
13
- * const addresses = [
14
- * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
- * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
- * ].sort(publicAddressesFirst)
17
- *
18
- * console.info(addresses)
19
- * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
- * ```
21
- */
22
- import type { Address } from '@libp2p/interface';
23
- /**
24
- * Compare function for array.sort() that moves public addresses to the start
25
- * of the array.
26
- */
27
- export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
28
- /**
29
- * Compare function for array.sort() that moves certified addresses to the start
30
- * of the array.
31
- */
32
- export declare function certifiedAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
33
- /**
34
- * Compare function for array.sort() that moves circuit relay addresses to the
35
- * start of the array.
36
- */
37
- export declare function circuitRelayAddressesLast(a: Address, b: Address): -1 | 0 | 1;
38
- export declare function defaultAddressSort(a: Address, b: Address): -1 | 0 | 1;
39
- //# sourceMappingURL=address-sort.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAWxE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAQ3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAW7E;AAED,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAgBtE"}
@@ -1,79 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies to sort a list of multiaddrs.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- *
13
- * const addresses = [
14
- * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
- * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
- * ].sort(publicAddressesFirst)
17
- *
18
- * console.info(addresses)
19
- * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
- * ```
21
- */
22
- import { Circuit } from '@multiformats/multiaddr-matcher';
23
- import { isPrivate } from './multiaddr/is-private.js';
24
- /**
25
- * Compare function for array.sort() that moves public addresses to the start
26
- * of the array.
27
- */
28
- export function publicAddressesFirst(a, b) {
29
- const isAPrivate = isPrivate(a.multiaddr);
30
- const isBPrivate = isPrivate(b.multiaddr);
31
- if (isAPrivate && !isBPrivate) {
32
- return 1;
33
- }
34
- else if (!isAPrivate && isBPrivate) {
35
- return -1;
36
- }
37
- return 0;
38
- }
39
- /**
40
- * Compare function for array.sort() that moves certified addresses to the start
41
- * of the array.
42
- */
43
- export function certifiedAddressesFirst(a, b) {
44
- if (a.isCertified && !b.isCertified) {
45
- return -1;
46
- }
47
- else if (!a.isCertified && b.isCertified) {
48
- return 1;
49
- }
50
- return 0;
51
- }
52
- /**
53
- * Compare function for array.sort() that moves circuit relay addresses to the
54
- * start of the array.
55
- */
56
- export function circuitRelayAddressesLast(a, b) {
57
- const isACircuit = Circuit.exactMatch(a.multiaddr);
58
- const isBCircuit = Circuit.exactMatch(b.multiaddr);
59
- if (isACircuit && !isBCircuit) {
60
- return 1;
61
- }
62
- else if (!isACircuit && isBCircuit) {
63
- return -1;
64
- }
65
- return 0;
66
- }
67
- export function defaultAddressSort(a, b) {
68
- const publicResult = publicAddressesFirst(a, b);
69
- if (publicResult !== 0) {
70
- return publicResult;
71
- }
72
- const relayResult = circuitRelayAddressesLast(a, b);
73
- if (relayResult !== 0) {
74
- return relayResult;
75
- }
76
- const certifiedResult = certifiedAddressesFirst(a, b);
77
- return certifiedResult;
78
- }
79
- //# sourceMappingURL=address-sort.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAGrD;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,CAAU,EAAE,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AAK,CAAC,EAAE,CAAC;QACvB,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,MAAM,WAAW,GAAG,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAEnD,IAAI,WAAW,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,MAAM,eAAe,GAAG,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAErD,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -1,121 +0,0 @@
1
- {
2
- "createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort_options.createTimeoutOptions.html",
3
- "./abort-options:createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort_options.createTimeoutOptions.html",
4
- "AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract_stream.AbstractStream.html",
5
- "./abstract-stream:AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract_stream.AbstractStream.html",
6
- "AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract_stream.AbstractStreamInit.html",
7
- "./abstract-stream:AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract_stream.AbstractStreamInit.html",
8
- "AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive_timeout.AdaptiveTimeout.html",
9
- "./adaptive-timeout:AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive_timeout.AdaptiveTimeout.html",
10
- "AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.AdaptiveTimeoutInit.html",
11
- "./adaptive-timeout:AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.AdaptiveTimeoutInit.html",
12
- "AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.AdaptiveTimeoutSignal.html",
13
- "./adaptive-timeout:AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.AdaptiveTimeoutSignal.html",
14
- "GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.GetTimeoutSignalOptions.html",
15
- "./adaptive-timeout:GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive_timeout.GetTimeoutSignalOptions.html",
16
- "DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_FAILURE_MULTIPLIER.html",
17
- "./adaptive-timeout:DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_FAILURE_MULTIPLIER.html",
18
- "DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_MIN_TIMEOUT.html",
19
- "./adaptive-timeout:DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_MIN_TIMEOUT.html",
20
- "DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
21
- "./adaptive-timeout:DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive_timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
22
- "certifiedAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.certifiedAddressesFirst.html",
23
- "./address-sort:certifiedAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.certifiedAddressesFirst.html",
24
- "circuitRelayAddressesLast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.circuitRelayAddressesLast.html",
25
- "./address-sort:circuitRelayAddressesLast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.circuitRelayAddressesLast.html",
26
- "defaultAddressSort": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.defaultAddressSort.html",
27
- "./address-sort:defaultAddressSort": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.defaultAddressSort.html",
28
- "publicAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.publicAddressesFirst.html",
29
- "./address-sort:publicAddressesFirst": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.address_sort.publicAddressesFirst.html",
30
- "arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array_equals.arrayEquals.html",
31
- "./array-equals:arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array_equals.arrayEquals.html",
32
- "SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
33
- "./close:SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
34
- "safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
35
- "./close:safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
36
- "safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
37
- "./close:safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
38
- "closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close_source.closeSource.html",
39
- "./close-source:closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close_source.closeSource.html",
40
- "BloomFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.BloomFilter.html",
41
- "Bucket": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.Bucket.html",
42
- "CuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.CuckooFilter.html",
43
- "Fingerprint": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.Fingerprint.html",
44
- "ScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.ScalableCuckooFilter.html",
45
- "BloomFilterOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.BloomFilterOptions.html",
46
- "CuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.CuckooFilterInit.html",
47
- "Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
48
- "./filters:Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
49
- "Hash": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Hash.html",
50
- "ScalableCuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.ScalableCuckooFilterInit.html",
51
- "createBloomFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createBloomFilter.html",
52
- "createCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createCuckooFilter.html",
53
- "createScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createScalableCuckooFilter.html",
54
- "ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip_port_to_multiaddr.ipPortToMultiaddr.html",
55
- "./ip-port-to-multiaddr:ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip_port_to_multiaddr.ipPortToMultiaddr.html",
56
- "isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is_promise.isPromise.html",
57
- "./is-promise:isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is_promise.isPromise.html",
58
- "MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving_average.MovingAverage.html",
59
- "./moving-average:MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving_average.MovingAverage.html",
60
- "isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_loopback.isLoopback.html",
61
- "./multiaddr/is-loopback:isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_loopback.isLoopback.html",
62
- "isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_private.isPrivate.html",
63
- "./multiaddr/is-private:isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is_private.isPrivate.html",
64
- "PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer_queue.PeerQueue.html",
65
- "./peer-queue:PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer_queue.PeerQueue.html",
66
- "PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer_queue.PeerQueueJobOptions.html",
67
- "./peer-queue:PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer_queue.PeerQueueJobOptions.html",
68
- "PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority_queue.PriorityQueue.html",
69
- "./priority-queue:PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority_queue.PriorityQueue.html",
70
- "PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority_queue.PriorityQueueJobOptions.html",
71
- "./priority-queue:PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority_queue.PriorityQueueJobOptions.html",
72
- "isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private_ip.isPrivateIp.html",
73
- "./private-ip:isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private_ip.isPrivateIp.html",
74
- "Job": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Job.html",
75
- "JobRecipient": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.JobRecipient.html",
76
- "Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
77
- "./queue:Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
78
- "Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
79
- "./queue:Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
80
- "JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
81
- "./queue:JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
82
- "JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobTimeline.html",
83
- "QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
84
- "./queue:QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
85
- "QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
86
- "./queue:QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
87
- "QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
88
- "./queue:QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
89
- "QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
90
- "./queue:QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
91
- "RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
92
- "./queue:RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
93
- "JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
94
- "./queue:JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
95
- "MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.MemoryStorage.html",
96
- "./rate-limiter:MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.MemoryStorage.html",
97
- "RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.RateLimiter.html",
98
- "./rate-limiter:RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate_limiter.RateLimiter.html",
99
- "GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.GetKeySecDurationOptions.html",
100
- "./rate-limiter:GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.GetKeySecDurationOptions.html",
101
- "RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterInit.html",
102
- "./rate-limiter:RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterInit.html",
103
- "RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterResult.html",
104
- "./rate-limiter:RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateLimiterResult.html",
105
- "RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateRecord.html",
106
- "./rate-limiter:RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate_limiter.RateRecord.html",
107
- "StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream_to_ma_conn.StreamProperties.html",
108
- "./stream-to-ma-conn:StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream_to_ma_conn.StreamProperties.html",
109
- "streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream_to_ma_conn.streamToMaConnection.html",
110
- "./stream-to-ma-conn:streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream_to_ma_conn.streamToMaConnection.html",
111
- "CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_list.CreateTrackedListInit.html",
112
- "./tracked-list:CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_list.CreateTrackedListInit.html",
113
- "trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_list.trackedList.html",
114
- "./tracked-list:trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_list.trackedList.html",
115
- "CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.CreateTrackedMapInit.html",
116
- "./tracked-map:CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.CreateTrackedMapInit.html",
117
- "TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.TrackedMapInit.html",
118
- "./tracked-map:TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked_map.TrackedMapInit.html",
119
- "trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_map.trackedMap.html",
120
- "./tracked-map:trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked_map.trackedMap.html"
121
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies to sort a list of multiaddrs.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { publicAddressesFirst } from '@libp2p/utils/address-sort'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- *
13
- * const addresses = [
14
- * multiaddr('/ip4/127.0.0.1/tcp/9000'),
15
- * multiaddr('/ip4/82.41.53.1/tcp/9000')
16
- * ].sort(publicAddressesFirst)
17
- *
18
- * console.info(addresses)
19
- * // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
20
- * ```
21
- */
22
-
23
- import { Circuit } from '@multiformats/multiaddr-matcher'
24
- import { isPrivate } from './multiaddr/is-private.js'
25
- import type { Address } from '@libp2p/interface'
26
-
27
- /**
28
- * Compare function for array.sort() that moves public addresses to the start
29
- * of the array.
30
- */
31
- export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
32
- const isAPrivate = isPrivate(a.multiaddr)
33
- const isBPrivate = isPrivate(b.multiaddr)
34
-
35
- if (isAPrivate && !isBPrivate) {
36
- return 1
37
- } else if (!isAPrivate && isBPrivate) {
38
- return -1
39
- }
40
-
41
- return 0
42
- }
43
-
44
- /**
45
- * Compare function for array.sort() that moves certified addresses to the start
46
- * of the array.
47
- */
48
- export function certifiedAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
49
- if (a.isCertified && !b.isCertified) {
50
- return -1
51
- } else if (!a.isCertified && b.isCertified) {
52
- return 1
53
- }
54
-
55
- return 0
56
- }
57
-
58
- /**
59
- * Compare function for array.sort() that moves circuit relay addresses to the
60
- * start of the array.
61
- */
62
- export function circuitRelayAddressesLast (a: Address, b: Address): -1 | 0 | 1 {
63
- const isACircuit = Circuit.exactMatch(a.multiaddr)
64
- const isBCircuit = Circuit.exactMatch(b.multiaddr)
65
-
66
- if (isACircuit && !isBCircuit) {
67
- return 1
68
- } else if (!isACircuit && isBCircuit) {
69
- return -1
70
- }
71
-
72
- return 0
73
- }
74
-
75
- export function defaultAddressSort (a: Address, b: Address): -1 | 0 | 1 {
76
- const publicResult = publicAddressesFirst(a, b)
77
-
78
- if (publicResult !== 0) {
79
- return publicResult
80
- }
81
-
82
- const relayResult = circuitRelayAddressesLast(a, b)
83
-
84
- if (relayResult !== 0) {
85
- return relayResult
86
- }
87
-
88
- const certifiedResult = certifiedAddressesFirst(a, b)
89
-
90
- return certifiedResult
91
- }