libp2p 0.46.13 → 0.46.14-68504939
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 +33 -33
- package/dist/src/circuit-relay/utils.d.ts +1 -1
- package/dist/src/circuit-relay/utils.d.ts.map +1 -1
- package/dist/src/circuit-relay/utils.js +19 -21
- package/dist/src/circuit-relay/utils.js.map +1 -1
- package/dist/src/identify/consts.d.ts +1 -1
- package/dist/src/identify/consts.d.ts.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 +22 -22
- package/src/circuit-relay/utils.ts +21 -22
- package/src/errors.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -71
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid';
|
|
2
2
|
import type { Limit } from './pb/index.js';
|
|
3
3
|
import type { Stream } from '@libp2p/interface/connection';
|
|
4
|
-
export declare function createLimitedRelay(
|
|
4
|
+
export declare function createLimitedRelay(src: Stream, dst: Stream, abortSignal: AbortSignal, limit?: Limit): void;
|
|
5
5
|
/**
|
|
6
6
|
* Convert a namespace string into a cid
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/circuit-relay/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/circuit-relay/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAGtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAiC1D,wBAAgB,kBAAkB,CAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CA0E3G;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAKrE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAM5E"}
|
|
@@ -4,9 +4,9 @@ import { anySignal } from 'any-signal';
|
|
|
4
4
|
import { CID } from 'multiformats/cid';
|
|
5
5
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
6
6
|
import { codes } from '../errors.js';
|
|
7
|
-
import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js';
|
|
8
7
|
const log = logger('libp2p:circuit-relay:utils');
|
|
9
8
|
async function* countStreamBytes(source, limit) {
|
|
9
|
+
const limitBytes = limit.remaining;
|
|
10
10
|
for await (const buf of source) {
|
|
11
11
|
const len = BigInt(buf.byteLength);
|
|
12
12
|
if ((limit.remaining - len) < 0) {
|
|
@@ -21,13 +21,13 @@ async function* countStreamBytes(source, limit) {
|
|
|
21
21
|
catch (err) {
|
|
22
22
|
log.error(err);
|
|
23
23
|
}
|
|
24
|
-
throw new
|
|
24
|
+
throw new CodeError(`data limit of ${limitBytes} bytes exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED);
|
|
25
25
|
}
|
|
26
26
|
limit.remaining -= len;
|
|
27
27
|
yield buf;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
export function createLimitedRelay(src, dst, abortSignal, limit) {
|
|
31
31
|
function abortStreams(err) {
|
|
32
32
|
src.abort(err);
|
|
33
33
|
dst.abort(err);
|
|
@@ -35,20 +35,26 @@ const doRelay = (src, dst, abortSignal, limit) => {
|
|
|
35
35
|
}
|
|
36
36
|
const abortController = new AbortController();
|
|
37
37
|
const signal = anySignal([abortSignal, abortController.signal]);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
let timeout;
|
|
39
|
+
if (limit?.duration != null) {
|
|
40
|
+
timeout = setTimeout(() => {
|
|
41
|
+
abortController.abort();
|
|
42
|
+
}, limit.duration);
|
|
43
|
+
}
|
|
41
44
|
let srcDstFinished = false;
|
|
42
45
|
let dstSrcFinished = false;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
let dataLimit;
|
|
47
|
+
if (limit?.data != null) {
|
|
48
|
+
dataLimit = {
|
|
49
|
+
remaining: limit.data
|
|
50
|
+
};
|
|
51
|
+
}
|
|
46
52
|
queueMicrotask(() => {
|
|
47
53
|
const onAbort = () => {
|
|
48
|
-
dst.abort(new CodeError(
|
|
54
|
+
dst.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED));
|
|
49
55
|
};
|
|
50
56
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
51
|
-
void dst.sink(countStreamBytes(src.source, dataLimit))
|
|
57
|
+
void dst.sink(dataLimit == null ? src.source : countStreamBytes(src.source, dataLimit))
|
|
52
58
|
.catch(err => {
|
|
53
59
|
log.error('error while relaying streams src -> dst', err);
|
|
54
60
|
abortStreams(err);
|
|
@@ -64,10 +70,10 @@ const doRelay = (src, dst, abortSignal, limit) => {
|
|
|
64
70
|
});
|
|
65
71
|
queueMicrotask(() => {
|
|
66
72
|
const onAbort = () => {
|
|
67
|
-
src.abort(new CodeError(
|
|
73
|
+
src.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED));
|
|
68
74
|
};
|
|
69
75
|
signal.addEventListener('abort', onAbort, { once: true });
|
|
70
|
-
void src.sink(countStreamBytes(dst.source, dataLimit))
|
|
76
|
+
void src.sink(dataLimit == null ? dst.source : countStreamBytes(dst.source, dataLimit))
|
|
71
77
|
.catch(err => {
|
|
72
78
|
log.error('error while relaying streams dst -> src', err);
|
|
73
79
|
abortStreams(err);
|
|
@@ -81,14 +87,6 @@ const doRelay = (src, dst, abortSignal, limit) => {
|
|
|
81
87
|
}
|
|
82
88
|
});
|
|
83
89
|
});
|
|
84
|
-
};
|
|
85
|
-
export function createLimitedRelay(source, destination, abortSignal, limit) {
|
|
86
|
-
const dataLimit = limit?.data ?? BigInt(DEFAULT_DATA_LIMIT);
|
|
87
|
-
const durationLimit = limit?.duration ?? DEFAULT_DURATION_LIMIT;
|
|
88
|
-
doRelay(source, destination, abortSignal, {
|
|
89
|
-
data: dataLimit,
|
|
90
|
-
duration: durationLimit
|
|
91
|
-
});
|
|
92
90
|
}
|
|
93
91
|
/**
|
|
94
92
|
* Convert a namespace string into a cid
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/circuit-relay/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/circuit-relay/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AACjD,O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I,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAEvC,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAE,iBAAyB;IAClE,MAAM,gBAAgB,GAAG,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IACzD,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAExC,4CAA4C;IAC5C,OAAO,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAA;AACvD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const PROTOCOL_VERSION = "ipfs/0.1.0";
|
|
2
|
-
export declare const AGENT_VERSION = "js-libp2p/0.46.
|
|
2
|
+
export declare const AGENT_VERSION = "js-libp2p/0.46.14-68504939";
|
|
3
3
|
export declare const MULTICODEC_IDENTIFY = "/ipfs/id/1.0.0";
|
|
4
4
|
export declare const MULTICODEC_IDENTIFY_PUSH = "/ipfs/id/push/1.0.0";
|
|
5
5
|
export declare const IDENTIFY_PROTOCOL_VERSION = "0.1.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/identify/consts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/identify/consts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,aAAa,+BAAyB,CAAA;AACnD,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AACnD,eAAO,MAAM,wBAAwB,wBAAwB,CAAA;AAE7D,eAAO,MAAM,yBAAyB,UAAU,CAAA;AAChD,eAAO,MAAM,iCAAiC,OAAO,CAAA;AACrD,eAAO,MAAM,sCAAsC,YAAY,CAAA;AAC/D,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAC3D,eAAO,MAAM,yCAAyC,UAAU,CAAA"}
|
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,qBAAqB,CAAA;AACzC,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,kBAAkB,CAAA;AACzC,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.14-68504939",
|
|
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/master/packages/libp2p#readme",
|
|
@@ -121,18 +121,18 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@achingbrain/nat-port-mapper": "^1.0.9",
|
|
124
|
-
"@libp2p/crypto": "
|
|
125
|
-
"@libp2p/interface": "
|
|
126
|
-
"@libp2p/interface-internal": "
|
|
127
|
-
"@libp2p/keychain": "
|
|
128
|
-
"@libp2p/logger": "
|
|
129
|
-
"@libp2p/multistream-select": "
|
|
130
|
-
"@libp2p/peer-collections": "
|
|
131
|
-
"@libp2p/peer-id": "
|
|
132
|
-
"@libp2p/peer-id-factory": "
|
|
133
|
-
"@libp2p/peer-record": "
|
|
134
|
-
"@libp2p/peer-store": "
|
|
135
|
-
"@libp2p/utils": "
|
|
124
|
+
"@libp2p/crypto": "2.0.5-68504939",
|
|
125
|
+
"@libp2p/interface": "0.1.3-68504939",
|
|
126
|
+
"@libp2p/interface-internal": "0.1.6-68504939",
|
|
127
|
+
"@libp2p/keychain": "3.0.5-68504939",
|
|
128
|
+
"@libp2p/logger": "3.0.3-68504939",
|
|
129
|
+
"@libp2p/multistream-select": "4.0.3-68504939",
|
|
130
|
+
"@libp2p/peer-collections": "4.0.5-68504939",
|
|
131
|
+
"@libp2p/peer-id": "3.0.3-68504939",
|
|
132
|
+
"@libp2p/peer-id-factory": "3.0.5-68504939",
|
|
133
|
+
"@libp2p/peer-record": "6.0.6-68504939",
|
|
134
|
+
"@libp2p/peer-store": "9.0.6-68504939",
|
|
135
|
+
"@libp2p/utils": "4.0.4-68504939",
|
|
136
136
|
"@multiformats/mafmt": "^12.1.2",
|
|
137
137
|
"@multiformats/multiaddr": "^12.1.5",
|
|
138
138
|
"@multiformats/multiaddr-matcher": "^1.0.0",
|
|
@@ -171,17 +171,17 @@
|
|
|
171
171
|
"@chainsafe/libp2p-gossipsub": "^10.0.0",
|
|
172
172
|
"@chainsafe/libp2p-noise": "^13.0.0",
|
|
173
173
|
"@chainsafe/libp2p-yamux": "^5.0.0",
|
|
174
|
-
"@libp2p/bootstrap": "
|
|
174
|
+
"@libp2p/bootstrap": "9.0.8-68504939",
|
|
175
175
|
"@libp2p/daemon-client": "^7.0.0",
|
|
176
176
|
"@libp2p/daemon-server": "^6.0.0",
|
|
177
|
-
"@libp2p/floodsub": "
|
|
178
|
-
"@libp2p/interface-compliance-tests": "
|
|
177
|
+
"@libp2p/floodsub": "8.0.9-68504939",
|
|
178
|
+
"@libp2p/interface-compliance-tests": "4.1.1-68504939",
|
|
179
179
|
"@libp2p/interop": "^9.0.0",
|
|
180
|
-
"@libp2p/kad-dht": "
|
|
181
|
-
"@libp2p/mdns": "
|
|
182
|
-
"@libp2p/mplex": "
|
|
183
|
-
"@libp2p/tcp": "
|
|
184
|
-
"@libp2p/websockets": "
|
|
180
|
+
"@libp2p/kad-dht": "10.0.9-68504939",
|
|
181
|
+
"@libp2p/mdns": "9.0.10-68504939",
|
|
182
|
+
"@libp2p/mplex": "9.0.8-68504939",
|
|
183
|
+
"@libp2p/tcp": "8.0.9-68504939",
|
|
184
|
+
"@libp2p/websockets": "7.0.9-68504939",
|
|
185
185
|
"@types/xsalsa20": "^1.1.0",
|
|
186
186
|
"aegir": "^41.0.2",
|
|
187
187
|
"execa": "^8.0.1",
|
|
@@ -193,7 +193,7 @@
|
|
|
193
193
|
"p-times": "^4.0.0",
|
|
194
194
|
"p-wait-for": "^5.0.2",
|
|
195
195
|
"protons": "^7.0.2",
|
|
196
|
-
"sinon": "^
|
|
196
|
+
"sinon": "^17.0.0",
|
|
197
197
|
"sinon-ts": "^1.0.0"
|
|
198
198
|
},
|
|
199
199
|
"browser": {
|
|
@@ -4,7 +4,6 @@ import { anySignal } from 'any-signal'
|
|
|
4
4
|
import { CID } from 'multiformats/cid'
|
|
5
5
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
6
6
|
import { codes } from '../errors.js'
|
|
7
|
-
import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT } from './constants.js'
|
|
8
7
|
import type { Limit } from './pb/index.js'
|
|
9
8
|
import type { Stream } from '@libp2p/interface/connection'
|
|
10
9
|
import type { Source } from 'it-stream-types'
|
|
@@ -13,6 +12,8 @@ import type { Uint8ArrayList } from 'uint8arraylist'
|
|
|
13
12
|
const log = logger('libp2p:circuit-relay:utils')
|
|
14
13
|
|
|
15
14
|
async function * countStreamBytes (source: Source<Uint8Array | Uint8ArrayList>, limit: { remaining: bigint }): AsyncGenerator<Uint8Array | Uint8ArrayList, void, unknown> {
|
|
15
|
+
const limitBytes = limit.remaining
|
|
16
|
+
|
|
16
17
|
for await (const buf of source) {
|
|
17
18
|
const len = BigInt(buf.byteLength)
|
|
18
19
|
|
|
@@ -29,7 +30,7 @@ async function * countStreamBytes (source: Source<Uint8Array | Uint8ArrayList>,
|
|
|
29
30
|
log.error(err)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
throw new
|
|
33
|
+
throw new CodeError(`data limit of ${limitBytes} bytes exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
limit.remaining -= len
|
|
@@ -37,7 +38,7 @@ async function * countStreamBytes (source: Source<Uint8Array | Uint8ArrayList>,
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
export function createLimitedRelay (src: Stream, dst: Stream, abortSignal: AbortSignal, limit?: Limit): void {
|
|
41
42
|
function abortStreams (err: Error): void {
|
|
42
43
|
src.abort(err)
|
|
43
44
|
dst.abort(err)
|
|
@@ -47,25 +48,33 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
|
|
|
47
48
|
const abortController = new AbortController()
|
|
48
49
|
const signal = anySignal([abortSignal, abortController.signal])
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
let timeout: ReturnType<typeof setTimeout> | undefined
|
|
52
|
+
|
|
53
|
+
if (limit?.duration != null) {
|
|
54
|
+
timeout = setTimeout(() => {
|
|
55
|
+
abortController.abort()
|
|
56
|
+
}, limit.duration)
|
|
57
|
+
}
|
|
53
58
|
|
|
54
59
|
let srcDstFinished = false
|
|
55
60
|
let dstSrcFinished = false
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
let dataLimit: { remaining: bigint } | undefined
|
|
63
|
+
|
|
64
|
+
if (limit?.data != null) {
|
|
65
|
+
dataLimit = {
|
|
66
|
+
remaining: limit.data
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
queueMicrotask(() => {
|
|
62
71
|
const onAbort = (): void => {
|
|
63
|
-
dst.abort(new CodeError(
|
|
72
|
+
dst.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED))
|
|
64
73
|
}
|
|
65
74
|
|
|
66
75
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
67
76
|
|
|
68
|
-
void dst.sink(countStreamBytes(src.source, dataLimit))
|
|
77
|
+
void dst.sink(dataLimit == null ? src.source : countStreamBytes(src.source, dataLimit))
|
|
69
78
|
.catch(err => {
|
|
70
79
|
log.error('error while relaying streams src -> dst', err)
|
|
71
80
|
abortStreams(err)
|
|
@@ -83,12 +92,12 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
|
|
|
83
92
|
|
|
84
93
|
queueMicrotask(() => {
|
|
85
94
|
const onAbort = (): void => {
|
|
86
|
-
src.abort(new CodeError(
|
|
95
|
+
src.abort(new CodeError(`duration limit of ${limit?.duration} ms exceeded`, codes.ERR_TRANSFER_LIMIT_EXCEEDED))
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
90
99
|
|
|
91
|
-
void src.sink(countStreamBytes(dst.source, dataLimit))
|
|
100
|
+
void src.sink(dataLimit == null ? dst.source : countStreamBytes(dst.source, dataLimit))
|
|
92
101
|
.catch(err => {
|
|
93
102
|
log.error('error while relaying streams dst -> src', err)
|
|
94
103
|
abortStreams(err)
|
|
@@ -105,16 +114,6 @@ const doRelay = (src: Stream, dst: Stream, abortSignal: AbortSignal, limit: Requ
|
|
|
105
114
|
})
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
export function createLimitedRelay (source: Stream, destination: Stream, abortSignal: AbortSignal, limit?: Limit): void {
|
|
109
|
-
const dataLimit = limit?.data ?? BigInt(DEFAULT_DATA_LIMIT)
|
|
110
|
-
const durationLimit = limit?.duration ?? DEFAULT_DURATION_LIMIT
|
|
111
|
-
|
|
112
|
-
doRelay(source, destination, abortSignal, {
|
|
113
|
-
data: dataLimit,
|
|
114
|
-
duration: durationLimit
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
|
|
118
117
|
/**
|
|
119
118
|
* Convert a namespace string into a cid
|
|
120
119
|
*/
|
package/src/errors.ts
CHANGED
|
@@ -75,5 +75,5 @@ export enum codes {
|
|
|
75
75
|
ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS',
|
|
76
76
|
ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS',
|
|
77
77
|
ERR_CONNECTION_DENIED = 'ERR_CONNECTION_DENIED',
|
|
78
|
-
ERR_TRANSFER_LIMIT_EXCEEDED = 'ERR_TRANSFER_LIMIT_EXCEEDED'
|
|
78
|
+
ERR_TRANSFER_LIMIT_EXCEEDED = 'ERR_TRANSFER_LIMIT_EXCEEDED'
|
|
79
79
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '0.46.
|
|
1
|
+
export const version = '0.46.14-68504939'
|
|
2
2
|
export const name = 'libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATComponents.html",
|
|
3
|
-
"./autonat:AutoNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATComponents.html",
|
|
4
|
-
"AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATServiceInit.html",
|
|
5
|
-
"./autonat:AutoNATServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.autonat.AutoNATServiceInit.html",
|
|
6
|
-
"autoNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.autonat.autoNATService.html",
|
|
7
|
-
"./autonat:autoNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.autonat.autoNATService.html",
|
|
8
|
-
"CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayService.html",
|
|
9
|
-
"./circuit-relay:CircuitRelayService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayService.html",
|
|
10
|
-
"CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayServiceEvents.html",
|
|
11
|
-
"./circuit-relay:CircuitRelayServiceEvents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.CircuitRelayServiceEvents.html",
|
|
12
|
-
"RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.RelayReservation.html",
|
|
13
|
-
"./circuit-relay:RelayReservation": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.circuit_relay.RelayReservation.html",
|
|
14
|
-
"circuitRelayServer": "https://libp2p.github.io/js-libp2p/functions/libp2p.circuit_relay.circuitRelayServer.html",
|
|
15
|
-
"circuitRelayTransport": "https://libp2p.github.io/js-libp2p/functions/libp2p.circuit_relay.circuitRelayTransport.html",
|
|
16
|
-
"FetchService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchService.html",
|
|
17
|
-
"./fetch:FetchService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchService.html",
|
|
18
|
-
"FetchServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceComponents.html",
|
|
19
|
-
"./fetch:FetchServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceComponents.html",
|
|
20
|
-
"FetchServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceInit.html",
|
|
21
|
-
"./fetch:FetchServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.FetchServiceInit.html",
|
|
22
|
-
"HandleMessageOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.HandleMessageOptions.html",
|
|
23
|
-
"./fetch:HandleMessageOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.HandleMessageOptions.html",
|
|
24
|
-
"LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.LookupFunction.html",
|
|
25
|
-
"./fetch:LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.fetch.LookupFunction.html",
|
|
26
|
-
"fetchService": "https://libp2p.github.io/js-libp2p/functions/libp2p.fetch.fetchService-1.html",
|
|
27
|
-
"./fetch:fetchService": "https://libp2p.github.io/js-libp2p/functions/libp2p.fetch.fetchService-1.html",
|
|
28
|
-
"IdentifyService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyService.html",
|
|
29
|
-
"./identify:IdentifyService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyService.html",
|
|
30
|
-
"IdentifyServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceComponents.html",
|
|
31
|
-
"./identify:IdentifyServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceComponents.html",
|
|
32
|
-
"IdentifyServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceInit.html",
|
|
33
|
-
"./identify:IdentifyServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.identify.IdentifyServiceInit.html",
|
|
34
|
-
"Message": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.Message.html",
|
|
35
|
-
"./identify:Message": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.Message.html",
|
|
36
|
-
"multicodecs": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.multicodecs.html",
|
|
37
|
-
"./identify:multicodecs": "https://libp2p.github.io/js-libp2p/variables/libp2p.identify.multicodecs.html",
|
|
38
|
-
"identifyService": "https://libp2p.github.io/js-libp2p/functions/libp2p.identify.identifyService-1.html",
|
|
39
|
-
"./identify:identifyService": "https://libp2p.github.io/js-libp2p/functions/libp2p.identify.identifyService-1.html",
|
|
40
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
41
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
42
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
43
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
44
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
45
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
46
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
47
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
48
|
-
"plaintext": "https://libp2p.github.io/js-libp2p/functions/libp2p.insecure.plaintext.html",
|
|
49
|
-
"./insecure:plaintext": "https://libp2p.github.io/js-libp2p/functions/libp2p.insecure.plaintext.html",
|
|
50
|
-
"PingService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingService.html",
|
|
51
|
-
"./ping:PingService": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingService.html",
|
|
52
|
-
"PingServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceComponents.html",
|
|
53
|
-
"./ping:PingServiceComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceComponents.html",
|
|
54
|
-
"PingServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceInit.html",
|
|
55
|
-
"./ping:PingServiceInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.ping.PingServiceInit.html",
|
|
56
|
-
"pingService": "https://libp2p.github.io/js-libp2p/functions/libp2p.ping.pingService-1.html",
|
|
57
|
-
"./ping:pingService": "https://libp2p.github.io/js-libp2p/functions/libp2p.ping.pingService-1.html",
|
|
58
|
-
"ProtectorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.pnet.ProtectorInit.html",
|
|
59
|
-
"./pnet:ProtectorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.pnet.ProtectorInit.html",
|
|
60
|
-
"generateKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.generateKey.html",
|
|
61
|
-
"preSharedKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.preSharedKey.html",
|
|
62
|
-
"./pnet:preSharedKey": "https://libp2p.github.io/js-libp2p/functions/libp2p.pnet.preSharedKey.html",
|
|
63
|
-
"PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.PMPOptions.html",
|
|
64
|
-
"./upnp-nat:PMPOptions": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.PMPOptions.html",
|
|
65
|
-
"UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATComponents.html",
|
|
66
|
-
"./upnp-nat:UPnPNATComponents": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATComponents.html",
|
|
67
|
-
"UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATInit.html",
|
|
68
|
-
"./upnp-nat:UPnPNATInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.upnp_nat.UPnPNATInit.html",
|
|
69
|
-
"uPnPNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.upnp_nat.uPnPNATService.html",
|
|
70
|
-
"./upnp-nat:uPnPNATService": "https://libp2p.github.io/js-libp2p/functions/libp2p.upnp_nat.uPnPNATService.html"
|
|
71
|
-
}
|