@lodestar/reqresp 1.41.0-dev.ef310100c0 → 1.41.0-dev.f2caa915ab
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/README.md +1 -1
- package/lib/ReqResp.d.ts +3 -3
- package/lib/ReqResp.js +4 -4
- package/lib/ReqResp.js.map +1 -1
- package/lib/encoders/requestDecode.d.ts +2 -3
- package/lib/encoders/requestDecode.d.ts.map +1 -1
- package/lib/encoders/requestDecode.js +28 -11
- package/lib/encoders/requestDecode.js.map +1 -1
- package/lib/encoders/requestEncode.d.ts +1 -1
- package/lib/encoders/requestEncode.d.ts.map +1 -1
- package/lib/encoders/requestEncode.js +1 -1
- package/lib/encoders/requestEncode.js.map +1 -1
- package/lib/encoders/responseDecode.d.ts +10 -10
- package/lib/encoders/responseDecode.d.ts.map +1 -1
- package/lib/encoders/responseDecode.js +63 -60
- package/lib/encoders/responseDecode.js.map +1 -1
- package/lib/encoders/responseEncode.d.ts +2 -4
- package/lib/encoders/responseEncode.d.ts.map +1 -1
- package/lib/encoders/responseEncode.js +13 -22
- package/lib/encoders/responseEncode.js.map +1 -1
- package/lib/encodingStrategies/index.d.ts +4 -3
- package/lib/encodingStrategies/index.d.ts.map +1 -1
- package/lib/encodingStrategies/index.js +4 -4
- package/lib/encodingStrategies/index.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/decode.d.ts +5 -4
- package/lib/encodingStrategies/sszSnappy/decode.d.ts.map +1 -1
- package/lib/encodingStrategies/sszSnappy/decode.js +83 -52
- package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/encode.d.ts +2 -2
- package/lib/encodingStrategies/sszSnappy/encode.d.ts.map +1 -1
- package/lib/encodingStrategies/sszSnappy/encode.js +1 -1
- package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/errors.d.ts +0 -8
- package/lib/encodingStrategies/sszSnappy/errors.d.ts.map +1 -1
- package/lib/encodingStrategies/sszSnappy/errors.js +0 -2
- package/lib/encodingStrategies/sszSnappy/errors.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/index.d.ts +0 -1
- package/lib/encodingStrategies/sszSnappy/index.d.ts.map +1 -1
- package/lib/encodingStrategies/sszSnappy/index.js +0 -1
- package/lib/encodingStrategies/sszSnappy/index.js.map +1 -1
- package/lib/metrics.d.ts +1 -7
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +1 -17
- package/lib/metrics.js.map +1 -1
- package/lib/request/errors.d.ts +1 -7
- package/lib/request/errors.d.ts.map +1 -1
- package/lib/request/errors.js +1 -5
- package/lib/request/errors.js.map +1 -1
- package/lib/request/index.d.ts +0 -3
- package/lib/request/index.d.ts.map +1 -1
- package/lib/request/index.js +58 -70
- package/lib/request/index.js.map +1 -1
- package/lib/response/index.d.ts +1 -1
- package/lib/response/index.d.ts.map +1 -1
- package/lib/response/index.js +46 -50
- package/lib/response/index.js.map +1 -1
- package/lib/types.d.ts +1 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -2
- package/lib/types.js.map +1 -1
- package/lib/utils/collectMaxResponse.d.ts.map +1 -1
- package/lib/utils/collectMaxResponse.js +1 -2
- package/lib/utils/collectMaxResponse.js.map +1 -1
- package/lib/utils/errorMessage.d.ts +3 -3
- package/lib/utils/errorMessage.d.ts.map +1 -1
- package/lib/utils/errorMessage.js +14 -13
- package/lib/utils/errorMessage.js.map +1 -1
- package/lib/utils/index.d.ts +1 -3
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +1 -3
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/protocolId.d.ts +2 -2
- package/lib/utils/protocolId.js +2 -2
- package/lib/utils/snappyCompress.d.ts +1 -1
- package/lib/utils/snappyCompress.d.ts.map +1 -1
- package/lib/utils/snappyCompress.js +1 -1
- package/lib/utils/snappyCompress.js.map +1 -1
- package/lib/utils/snappyIndex.d.ts +1 -1
- package/lib/utils/snappyIndex.d.ts.map +1 -1
- package/lib/utils/snappyIndex.js +1 -1
- package/lib/utils/snappyIndex.js.map +1 -1
- package/lib/utils/snappyUncompress.d.ts +7 -11
- package/lib/utils/snappyUncompress.d.ts.map +1 -1
- package/lib/utils/snappyUncompress.js +68 -68
- package/lib/utils/snappyUncompress.js.map +1 -1
- package/lib/utils/stream.d.ts +6 -0
- package/lib/utils/stream.d.ts.map +1 -0
- package/lib/utils/stream.js +21 -0
- package/lib/utils/stream.js.map +1 -0
- package/package.json +14 -16
- package/src/ReqResp.ts +4 -4
- package/src/encoders/requestDecode.ts +32 -16
- package/src/encoders/requestEncode.ts +1 -1
- package/src/encoders/responseDecode.ts +68 -72
- package/src/encoders/responseEncode.ts +17 -29
- package/src/encodingStrategies/index.ts +8 -6
- package/src/encodingStrategies/sszSnappy/decode.ts +111 -53
- package/src/encodingStrategies/sszSnappy/encode.ts +2 -2
- package/src/encodingStrategies/sszSnappy/errors.ts +0 -4
- package/src/encodingStrategies/sszSnappy/index.ts +0 -1
- package/src/metrics.ts +1 -17
- package/src/request/errors.ts +1 -6
- package/src/request/index.ts +74 -86
- package/src/response/index.ts +55 -61
- package/src/types.ts +1 -3
- package/src/utils/collectMaxResponse.ts +1 -2
- package/src/utils/errorMessage.ts +14 -13
- package/src/utils/index.ts +1 -3
- package/src/utils/protocolId.ts +2 -2
- package/src/utils/snappyCompress.ts +1 -1
- package/src/utils/snappyIndex.ts +1 -1
- package/src/utils/snappyUncompress.ts +73 -75
- package/src/utils/stream.ts +34 -0
- package/lib/utils/abortableSource.d.ts +0 -12
- package/lib/utils/abortableSource.d.ts.map +0 -1
- package/lib/utils/abortableSource.js +0 -69
- package/lib/utils/abortableSource.js.map +0 -1
- package/lib/utils/bufferedSource.d.ts +0 -16
- package/lib/utils/bufferedSource.d.ts.map +0 -1
- package/lib/utils/bufferedSource.js +0 -40
- package/lib/utils/bufferedSource.js.map +0 -1
- package/lib/utils/onChunk.d.ts +0 -6
- package/lib/utils/onChunk.d.ts.map +0 -1
- package/lib/utils/onChunk.js +0 -13
- package/lib/utils/onChunk.js.map +0 -1
- package/lib/utils/snappy.d.ts +0 -3
- package/lib/utils/snappy.d.ts.map +0 -1
- package/lib/utils/snappy.js +0 -3
- package/lib/utils/snappy.js.map +0 -1
- package/src/utils/abortableSource.ts +0 -80
- package/src/utils/bufferedSource.ts +0 -46
- package/src/utils/onChunk.ts +0 -12
- package/src/utils/snappy.ts +0 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Encoding, ProtocolAttributes } from "../types.js";
|
|
2
2
|
/**
|
|
3
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
3
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
4
4
|
*/
|
|
5
5
|
export declare function formatProtocolID(protocolPrefix: string, method: string, version: number, encoding: Encoding): string;
|
|
6
6
|
/**
|
|
7
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
7
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
8
8
|
*/
|
|
9
9
|
export declare function parseProtocolID(protocolId: string): ProtocolAttributes;
|
|
10
10
|
//# sourceMappingURL=protocolId.d.ts.map
|
package/lib/utils/protocolId.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Encoding } from "../types.js";
|
|
2
2
|
/**
|
|
3
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
3
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
4
4
|
*/
|
|
5
5
|
export function formatProtocolID(protocolPrefix, method, version, encoding) {
|
|
6
6
|
return `${protocolPrefix}/${method}/${version}/${encoding}`;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
9
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
10
10
|
*/
|
|
11
11
|
export function parseProtocolID(protocolId) {
|
|
12
12
|
const result = protocolId.split("/");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function encodeSnappy(bytes: Buffer):
|
|
1
|
+
export declare function encodeSnappy(bytes: Buffer): Generator<Buffer>;
|
|
2
2
|
//# sourceMappingURL=snappyCompress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyCompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyCompress.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"snappyCompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyCompress.ts"],"names":[],"mappings":"AAKA,wBAAiB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAmB9D"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { compressSync } from "snappy";
|
|
3
3
|
import { ChunkType, IDENTIFIER_FRAME, UNCOMPRESSED_CHUNK_SIZE, crc } from "./snappyCommon.js";
|
|
4
4
|
// The logic in this file is largely copied (in simplified form) from https://github.com/ChainSafe/node-snappy-stream/
|
|
5
|
-
export
|
|
5
|
+
export function* encodeSnappy(bytes) {
|
|
6
6
|
yield IDENTIFIER_FRAME;
|
|
7
7
|
for (let i = 0; i < bytes.length; i += UNCOMPRESSED_CHUNK_SIZE) {
|
|
8
8
|
const chunk = bytes.subarray(i, i + UNCOMPRESSED_CHUNK_SIZE);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyCompress.js","sourceRoot":"","sources":["../../src/utils/snappyCompress.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,SAAS,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,GAAG,EAAC,MAAM,mBA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AC,CAAC;gBAClE,GAAG,CAAC,KAAK,CAAC;gBACV,KAAK;aACN,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyIndex.d.ts","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,
|
|
1
|
+
{"version":3,"file":"snappyIndex.d.ts","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,cAAc,uBAAuB,CAAC"}
|
package/lib/utils/snappyIndex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyIndex.js","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,
|
|
1
|
+
{"version":3,"file":"snappyIndex.js","sourceRoot":"","sources":["../../src/utils/snappyIndex.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Uint8ArrayList } from "uint8arraylist";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
uncompress(chunk: Uint8ArrayList): Uint8ArrayList | null;
|
|
11
|
-
reset(): void;
|
|
12
|
-
}
|
|
2
|
+
import { ChunkType } from "./snappyCommon.js";
|
|
3
|
+
export declare function parseSnappyFrameHeader(header: Uint8Array): {
|
|
4
|
+
type: ChunkType;
|
|
5
|
+
frameSize: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function decodeSnappyFrameData(type: ChunkType, frame: Uint8Array): Uint8Array | null;
|
|
8
|
+
export declare function decodeSnappyFrames(data: Uint8Array): Uint8ArrayList;
|
|
13
9
|
//# sourceMappingURL=snappyUncompress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyUncompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"snappyUncompress.d.ts","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAA2C,MAAM,mBAAmB,CAAC;AAEtF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,GAAG;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,CAQ/F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI,CAwC3F;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,cAAc,CAoCnE"}
|
|
@@ -1,81 +1,81 @@
|
|
|
1
1
|
import { uncompress } from "snappyjs";
|
|
2
2
|
import { Uint8ArrayList } from "uint8arraylist";
|
|
3
3
|
import { ChunkType, IDENTIFIER, UNCOMPRESSED_CHUNK_SIZE, crc } from "./snappyCommon.js";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
while (this.buffer.length > 0) {
|
|
18
|
-
if (this.buffer.length < 4)
|
|
19
|
-
break;
|
|
20
|
-
const type = getChunkType(this.buffer.get(0));
|
|
21
|
-
if (!this.state.foundIdentifier && type !== ChunkType.IDENTIFIER) {
|
|
22
|
-
throw "malformed input: must begin with an identifier";
|
|
4
|
+
export function parseSnappyFrameHeader(header) {
|
|
5
|
+
if (header.length !== 4) {
|
|
6
|
+
throw new Error("malformed input: incomplete frame header");
|
|
7
|
+
}
|
|
8
|
+
const type = getChunkType(header[0]);
|
|
9
|
+
const frameSize = header[1] + (header[2] << 8) + (header[3] << 16);
|
|
10
|
+
return { type, frameSize };
|
|
11
|
+
}
|
|
12
|
+
export function decodeSnappyFrameData(type, frame) {
|
|
13
|
+
switch (type) {
|
|
14
|
+
case ChunkType.IDENTIFIER: {
|
|
15
|
+
if (!Buffer.prototype.equals.call(frame, IDENTIFIER)) {
|
|
16
|
+
throw new Error("malformed input: bad identifier");
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
case ChunkType.PADDING:
|
|
21
|
+
case ChunkType.SKIPPABLE:
|
|
22
|
+
return null;
|
|
23
|
+
case ChunkType.COMPRESSED: {
|
|
24
|
+
if (frame.length < 4) {
|
|
25
|
+
throw new Error("malformed input: too short");
|
|
27
26
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw "malformed input: bad identifier";
|
|
34
|
-
}
|
|
35
|
-
this.state.foundIdentifier = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
case ChunkType.PADDING:
|
|
39
|
-
case ChunkType.SKIPPABLE:
|
|
40
|
-
continue;
|
|
41
|
-
case ChunkType.COMPRESSED: {
|
|
42
|
-
const checksum = frame.subarray(0, 4);
|
|
43
|
-
const data = frame.subarray(4);
|
|
44
|
-
const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
|
|
45
|
-
if (crc(uncompressed).compare(checksum) !== 0) {
|
|
46
|
-
throw "malformed input: bad checksum";
|
|
47
|
-
}
|
|
48
|
-
result.append(uncompressed);
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case ChunkType.UNCOMPRESSED: {
|
|
52
|
-
const checksum = frame.subarray(0, 4);
|
|
53
|
-
const uncompressed = frame.subarray(4);
|
|
54
|
-
if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
|
|
55
|
-
throw "malformed input: too large";
|
|
56
|
-
}
|
|
57
|
-
if (crc(uncompressed).compare(checksum) !== 0) {
|
|
58
|
-
throw "malformed input: bad checksum";
|
|
59
|
-
}
|
|
60
|
-
result.append(uncompressed);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
27
|
+
const checksum = frame.subarray(0, 4);
|
|
28
|
+
const data = frame.subarray(4);
|
|
29
|
+
const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
|
|
30
|
+
if (crc(uncompressed).compare(checksum) !== 0) {
|
|
31
|
+
throw new Error("malformed input: bad checksum");
|
|
63
32
|
}
|
|
33
|
+
return uncompressed;
|
|
64
34
|
}
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
case ChunkType.UNCOMPRESSED: {
|
|
36
|
+
if (frame.length < 4) {
|
|
37
|
+
throw new Error("malformed input: too short");
|
|
38
|
+
}
|
|
39
|
+
const checksum = frame.subarray(0, 4);
|
|
40
|
+
const uncompressed = frame.subarray(4);
|
|
41
|
+
if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
|
|
42
|
+
throw new Error("malformed input: too large");
|
|
43
|
+
}
|
|
44
|
+
if (crc(uncompressed).compare(checksum) !== 0) {
|
|
45
|
+
throw new Error("malformed input: bad checksum");
|
|
46
|
+
}
|
|
47
|
+
return uncompressed;
|
|
67
48
|
}
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
reset() {
|
|
71
|
-
this.buffer = new Uint8ArrayList();
|
|
72
|
-
this.state = {
|
|
73
|
-
foundIdentifier: false,
|
|
74
|
-
};
|
|
75
49
|
}
|
|
76
50
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
51
|
+
export function decodeSnappyFrames(data) {
|
|
52
|
+
const out = new Uint8ArrayList();
|
|
53
|
+
let foundIdentifier = false;
|
|
54
|
+
let offset = 0;
|
|
55
|
+
while (offset < data.length) {
|
|
56
|
+
const remaining = data.length - offset;
|
|
57
|
+
if (remaining < 4) {
|
|
58
|
+
throw new Error("malformed input: incomplete frame header");
|
|
59
|
+
}
|
|
60
|
+
const { type, frameSize } = parseSnappyFrameHeader(data.subarray(offset, offset + 4));
|
|
61
|
+
if (!foundIdentifier && type !== ChunkType.IDENTIFIER) {
|
|
62
|
+
throw new Error("malformed input: must begin with an identifier");
|
|
63
|
+
}
|
|
64
|
+
offset += 4;
|
|
65
|
+
if (data.length - offset < frameSize) {
|
|
66
|
+
throw new Error("malformed input: incomplete frame");
|
|
67
|
+
}
|
|
68
|
+
const frame = data.subarray(offset, offset + frameSize);
|
|
69
|
+
offset += frameSize;
|
|
70
|
+
if (type === ChunkType.IDENTIFIER) {
|
|
71
|
+
foundIdentifier = true;
|
|
72
|
+
}
|
|
73
|
+
const uncompressed = decodeSnappyFrameData(type, frame);
|
|
74
|
+
if (uncompressed !== null) {
|
|
75
|
+
out.append(uncompressed);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
79
|
}
|
|
80
80
|
function getChunkType(value) {
|
|
81
81
|
switch (value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snappyUncompress.js","sourceRoot":"","sources":["../../src/utils/snappyUncompress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,uBAAuB,EAA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,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,SAAS,CAAC,UAAU;YACvB,OAAO,SAAS,CAAC,UAAU,CAAC;QAC9B,KAAK,SAAS,CAAC,UAAU;YACvB,OAAO,SAAS,CAAC,UAAU,CAAC;QAC9B,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,SAAS,CAAC,YAAY,CAAC;QAChC,KAAK,SAAS,CAAC,OAAO;YACpB,OAAO,SAAS,CAAC,OAAO,CAAC;QAC3B;YACE,qEAAqE;YACrE,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBACnC,OAAO,SAAS,CAAC,SAAS,CAAC;YAC7B,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Stream } from "@libp2p/interface";
|
|
2
|
+
import { ByteStream } from "@libp2p/utils";
|
|
3
|
+
import { Uint8ArrayList } from "uint8arraylist";
|
|
4
|
+
export declare function sendChunks(stream: Stream, source: Iterable<Uint8Array | Uint8ArrayList> | AsyncIterable<Uint8Array | Uint8ArrayList>, signal?: AbortSignal): Promise<void>;
|
|
5
|
+
export declare function drainByteStream(bytes: ByteStream<Stream>): Uint8Array | undefined;
|
|
6
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAG9C,wBAAsB,UAAU,CAC9B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,QAAQ,CAAC,UAAU,GAAG,cAAc,CAAC,GAAG,aAAa,CAAC,UAAU,GAAG,cAAc,CAAC,EAC1F,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,GAAG,SAAS,CAYjF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ErrorAborted } from "@lodestar/utils";
|
|
2
|
+
export async function sendChunks(stream, source, signal) {
|
|
3
|
+
for await (const chunk of source) {
|
|
4
|
+
if (signal?.aborted) {
|
|
5
|
+
throw new ErrorAborted("sendChunks");
|
|
6
|
+
}
|
|
7
|
+
if (!stream.send(chunk)) {
|
|
8
|
+
await stream.onDrain({ signal });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function drainByteStream(bytes) {
|
|
13
|
+
const readBuffer = bytes.readBuffer;
|
|
14
|
+
if (readBuffer && readBuffer.byteLength > 0) {
|
|
15
|
+
const drained = readBuffer.subarray();
|
|
16
|
+
readBuffer.consume(readBuffer.byteLength);
|
|
17
|
+
return drained;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,MAA0F,EAC1F,MAAoB;IAEpB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,MAAM,CAAC,OAAO,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAyB;IACvD,MAAM,UAAU,GACd,KAGD,CAAC,UAAU,CAAC;IACb,IAAI,UAAU,IAAI,UAAU,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;QACtC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.41.0-dev.
|
|
14
|
+
"version": "1.41.0-dev.f2caa915ab",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -45,12 +45,11 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@chainsafe/fast-crc32c": "^4.2.0",
|
|
48
|
-
"@libp2p/interface": "^
|
|
49
|
-
"@
|
|
50
|
-
"@lodestar/
|
|
51
|
-
"@lodestar/
|
|
52
|
-
"
|
|
53
|
-
"it-pipe": "^3.0.1",
|
|
48
|
+
"@libp2p/interface": "^3.1.0",
|
|
49
|
+
"@libp2p/utils": "^7.0.11",
|
|
50
|
+
"@lodestar/config": "^1.41.0-dev.f2caa915ab",
|
|
51
|
+
"@lodestar/params": "^1.41.0-dev.f2caa915ab",
|
|
52
|
+
"@lodestar/utils": "^1.41.0-dev.f2caa915ab",
|
|
54
53
|
"snappy": "^7.2.2",
|
|
55
54
|
"snappyjs": "^0.7.0",
|
|
56
55
|
"uint8-varint": "^2.0.2",
|
|
@@ -58,16 +57,15 @@
|
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"@chainsafe/ssz": "^1.2.2",
|
|
61
|
-
"@libp2p/crypto": "^5.1.
|
|
62
|
-
"@libp2p/logger": "^
|
|
63
|
-
"@libp2p/peer-id": "^
|
|
64
|
-
"@lodestar/logger": "^1.41.0-dev.
|
|
65
|
-
"@lodestar/types": "^1.41.0-dev.
|
|
66
|
-
"
|
|
67
|
-
"libp2p": "2.9.0"
|
|
60
|
+
"@libp2p/crypto": "^5.1.13",
|
|
61
|
+
"@libp2p/logger": "^6.2.2",
|
|
62
|
+
"@libp2p/peer-id": "^6.0.4",
|
|
63
|
+
"@lodestar/logger": "^1.41.0-dev.f2caa915ab",
|
|
64
|
+
"@lodestar/types": "^1.41.0-dev.f2caa915ab",
|
|
65
|
+
"libp2p": "3.1.3"
|
|
68
66
|
},
|
|
69
67
|
"peerDependencies": {
|
|
70
|
-
"libp2p": "
|
|
68
|
+
"libp2p": "^3.1.3"
|
|
71
69
|
},
|
|
72
70
|
"keywords": [
|
|
73
71
|
"ethereum",
|
|
@@ -77,5 +75,5 @@
|
|
|
77
75
|
"reqresp",
|
|
78
76
|
"blockchain"
|
|
79
77
|
],
|
|
80
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "68d33fac21da9c1aa57fe7c24f9721b14ed96761"
|
|
81
79
|
}
|
package/src/ReqResp.ts
CHANGED
|
@@ -37,8 +37,8 @@ export interface ReqRespOpts extends SendRequestOpts, ReqRespRateLimiterOpts {
|
|
|
37
37
|
/**
|
|
38
38
|
* Implementation of Ethereum Consensus p2p Req/Resp domain.
|
|
39
39
|
* For the spec that this code is based on, see:
|
|
40
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.1
|
|
41
|
-
* https://github.com/ethereum/consensus-specs/blob/
|
|
40
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#the-reqresp-domain
|
|
41
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/altair/light-client/p2p-interface.md#the-reqresp-domain
|
|
42
42
|
*/
|
|
43
43
|
export class ReqResp {
|
|
44
44
|
// protected to be usable by extending class
|
|
@@ -221,7 +221,7 @@ export class ReqResp {
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
private getRequestHandler(protocol: MixedProtocol, protocolID: string) {
|
|
224
|
-
return async (
|
|
224
|
+
return async (stream: Stream, connection: Connection) => {
|
|
225
225
|
if (this.dialOnlyProtocols.get(protocolID)) {
|
|
226
226
|
throw new Error(`Received request on dial only protocol '${protocolID}'`);
|
|
227
227
|
}
|
|
@@ -281,7 +281,7 @@ export class ReqResp {
|
|
|
281
281
|
* ```
|
|
282
282
|
* /ProtocolPrefix/MessageName/SchemaVersion/Encoding
|
|
283
283
|
* ```
|
|
284
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
284
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
285
285
|
*/
|
|
286
286
|
protected formatProtocolID(protocol: Pick<MixedProtocol, "method" | "version" | "encoding">): string {
|
|
287
287
|
return formatProtocolID(this.protocolPrefix, protocol.method, protocol.version, protocol.encoding);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type {Stream} from "@libp2p/interface";
|
|
2
|
+
import {byteStream} from "@libp2p/utils";
|
|
3
3
|
import {readEncodedPayload} from "../encodingStrategies/index.js";
|
|
4
4
|
import {MixedProtocol} from "../types.js";
|
|
5
|
-
import {
|
|
5
|
+
import {drainByteStream} from "../utils/stream.ts";
|
|
6
6
|
|
|
7
7
|
const EMPTY_DATA = new Uint8Array();
|
|
8
8
|
|
|
@@ -12,18 +12,34 @@ const EMPTY_DATA = new Uint8Array();
|
|
|
12
12
|
* request ::= <encoding-dependent-header> | <encoded-payload>
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export function requestDecode(
|
|
16
|
-
protocol: MixedProtocol
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
export async function requestDecode(
|
|
16
|
+
protocol: MixedProtocol,
|
|
17
|
+
stream: Stream,
|
|
18
|
+
signal?: AbortSignal
|
|
19
|
+
): Promise<Uint8Array> {
|
|
20
|
+
const type = protocol.requestSizes;
|
|
21
|
+
if (type === null) {
|
|
22
|
+
// method has no body
|
|
23
|
+
return EMPTY_DATA;
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// Request has a single payload, so return immediately
|
|
27
|
+
const bytes = byteStream(stream);
|
|
28
|
+
let requestReadDone = false;
|
|
29
|
+
try {
|
|
30
|
+
const requestBody = await readEncodedPayload(bytes, protocol.encoding, type, signal);
|
|
31
|
+
requestReadDone = true;
|
|
32
|
+
return requestBody;
|
|
33
|
+
} finally {
|
|
34
|
+
try {
|
|
35
|
+
if (!requestReadDone) {
|
|
36
|
+
// Do not push partial bytes back into the stream on decode failure/abort.
|
|
37
|
+
// This stream is consumed by req/resp only once.
|
|
38
|
+
drainByteStream(bytes);
|
|
39
|
+
}
|
|
40
|
+
bytes.unwrap();
|
|
41
|
+
} catch {
|
|
42
|
+
// Ignore unwrap errors - stream may already be closed
|
|
43
|
+
}
|
|
44
|
+
}
|
|
29
45
|
}
|
|
@@ -9,7 +9,7 @@ import {MixedProtocol} from "../types.js";
|
|
|
9
9
|
* Requests may contain no payload (e.g. /eth2/beacon_chain/req/metadata/1/)
|
|
10
10
|
* if so, it would yield no byte chunks
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export function* requestEncode(protocol: MixedProtocol, requestBody: Uint8Array): Generator<Buffer> {
|
|
13
13
|
const type = protocol.requestSizes;
|
|
14
14
|
|
|
15
15
|
if (type && requestBody !== null) {
|