@lodestar/reqresp 1.41.0-dev.a35cbde8b3 → 1.41.0-dev.afd446235e
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
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
|
|
9
9
|
|
|
10
|
-
Typescript implementation of the [Ethereum Consensus Req/Resp protocol](https://github.com/ethereum/consensus-specs/blob/v1.
|
|
10
|
+
Typescript implementation of the [Ethereum Consensus Req/Resp protocol](https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#reqresp)
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
package/lib/ReqResp.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export interface ReqRespOpts extends SendRequestOpts, ReqRespRateLimiterOpts {
|
|
|
19
19
|
/**
|
|
20
20
|
* Implementation of Ethereum Consensus p2p Req/Resp domain.
|
|
21
21
|
* For the spec that this code is based on, see:
|
|
22
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.1
|
|
23
|
-
* https://github.com/ethereum/consensus-specs/blob/
|
|
22
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#the-reqresp-domain
|
|
23
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/altair/light-client/p2p-interface.md#the-reqresp-domain
|
|
24
24
|
*/
|
|
25
25
|
export declare class ReqResp {
|
|
26
26
|
private readonly opts;
|
|
@@ -74,7 +74,7 @@ export declare class ReqResp {
|
|
|
74
74
|
* ```
|
|
75
75
|
* /ProtocolPrefix/MessageName/SchemaVersion/Encoding
|
|
76
76
|
* ```
|
|
77
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
77
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
78
78
|
*/
|
|
79
79
|
protected formatProtocolID(protocol: Pick<MixedProtocol, "method" | "version" | "encoding">): string;
|
|
80
80
|
}
|
package/lib/ReqResp.js
CHANGED
|
@@ -9,8 +9,8 @@ export const DEFAULT_PROTOCOL_PREFIX = "/eth2/beacon_chain/req";
|
|
|
9
9
|
/**
|
|
10
10
|
* Implementation of Ethereum Consensus p2p Req/Resp domain.
|
|
11
11
|
* For the spec that this code is based on, see:
|
|
12
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.1
|
|
13
|
-
* https://github.com/ethereum/consensus-specs/blob/
|
|
12
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#the-reqresp-domain
|
|
13
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/altair/light-client/p2p-interface.md#the-reqresp-domain
|
|
14
14
|
*/
|
|
15
15
|
export class ReqResp {
|
|
16
16
|
opts;
|
|
@@ -151,7 +151,7 @@ export class ReqResp {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
getRequestHandler(protocol, protocolID) {
|
|
154
|
-
return async (
|
|
154
|
+
return async (stream, connection) => {
|
|
155
155
|
if (this.dialOnlyProtocols.get(protocolID)) {
|
|
156
156
|
throw new Error(`Received request on dial only protocol '${protocolID}'`);
|
|
157
157
|
}
|
|
@@ -203,7 +203,7 @@ export class ReqResp {
|
|
|
203
203
|
* ```
|
|
204
204
|
* /ProtocolPrefix/MessageName/SchemaVersion/Encoding
|
|
205
205
|
* ```
|
|
206
|
-
* https://github.com/ethereum/consensus-specs/blob/v1.
|
|
206
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#protocol-identification
|
|
207
207
|
*/
|
|
208
208
|
formatProtocolID(protocol) {
|
|
209
209
|
return formatProtocolID(this.protocolPrefix, protocol.method, protocol.version, protocol.encoding);
|
package/lib/ReqResp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReqResp.js","sourceRoot":"","sources":["../src/ReqResp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAI5C,OAAO,EAAU,UAAU,EAAC,MAAM,cAAc,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,eAAe,EAAC,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAmB,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAUlD,OAAO,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAIvD,MAAM,CAAC,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AAchE;;;;;GAKG;AACH,MAAM,OAAO,OAAO;IAsBC;IArBnB,4CAA4C;IACzB,MAAM,CAAS;IACf,MAAM,CAAS;IACf,OAAO,CAAiB;IAE3C,4EAA4E;IAC3D,WAAW,CAAqB;IACjD,6CAA6C;IAC5B,eAAe,CAAkB;IAE1C,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAC3C,2DAA2D;IACnD,QAAQ,GAAG,CAAC,CAAC;IACJ,cAAc,CAAS;IAExC,2DAA2D;IAC1C,mBAAmB,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC3D,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEpE,YACE,OAA+B,EACd,OAAoB,EAAE;QAAtB,SAAI,GAAJ,IAAI,CAAkB;QAEvC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;Q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oB;oBAC9B,UAAU;oBACV,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;oBAC9B,SAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;oBAC1B,UAAU;oBACV,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB;iBAC7C,CAAC,CAAC;gBACH,qCAAqC;YACvC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;gBAE3C,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;oBAChC,IAAI,CAAC,sBAAsB,CAAC,QAA8B,EAAE,GAAG,CAAC,CAAC;gBACnE,CAAC;gBAED,mCAAmC;gBACnC,gDAAgD;YAClD,CAAC;oBAAS,CAAC;gBACT,KAAK,EAAE,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAES,iBAAiB,CAAC,OAAe,EAAE,SAA6B;QACxE,WAAW;IACb,CAAC;IAES,sBAAsB,CAAC,SAA6B,EAAE,MAAoB;QAClF,WAAW;IACb,CAAC;IAES,sBAAsB,CAAC,OAAe,EAAE,OAAe,EAAE,MAAoB;QACrF,WAAW;IACb,CAAC;IAED;;;;;OAKG;IACO,gBAAgB,CAAC,QAAgE;QACzF,OAAO,gBAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrG,CAAC;CACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { Uint8ArrayList } from "uint8arraylist";
|
|
1
|
+
import type { Stream } from "@libp2p/interface";
|
|
3
2
|
import { MixedProtocol } from "../types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Consumes a stream source to read a `<request>`
|
|
@@ -7,5 +6,5 @@ import { MixedProtocol } from "../types.js";
|
|
|
7
6
|
* request ::= <encoding-dependent-header> | <encoded-payload>
|
|
8
7
|
* ```
|
|
9
8
|
*/
|
|
10
|
-
export declare function requestDecode(protocol: MixedProtocol
|
|
9
|
+
export declare function requestDecode(protocol: MixedProtocol, stream: Stream, signal?: AbortSignal): Promise<Uint8Array>;
|
|
11
10
|
//# sourceMappingURL=requestDecode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestDecode.d.ts","sourceRoot":"","sources":["../../src/encoders/requestDecode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"requestDecode.d.ts","sourceRoot":"","sources":["../../src/encoders/requestDecode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAG9C,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAK1C;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CA0BrB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { byteStream } from "@libp2p/utils";
|
|
1
2
|
import { readEncodedPayload } from "../encodingStrategies/index.js";
|
|
2
|
-
import {
|
|
3
|
+
import { drainByteStream } from "../utils/stream.js";
|
|
3
4
|
const EMPTY_DATA = new Uint8Array();
|
|
4
5
|
/**
|
|
5
6
|
* Consumes a stream source to read a `<request>`
|
|
@@ -7,16 +8,32 @@ const EMPTY_DATA = new Uint8Array();
|
|
|
7
8
|
* request ::= <encoding-dependent-header> | <encoded-payload>
|
|
8
9
|
* ```
|
|
9
10
|
*/
|
|
10
|
-
export function requestDecode(protocol) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export async function requestDecode(protocol, stream, signal) {
|
|
12
|
+
const type = protocol.requestSizes;
|
|
13
|
+
if (type === null) {
|
|
14
|
+
// method has no body
|
|
15
|
+
return EMPTY_DATA;
|
|
16
|
+
}
|
|
17
|
+
// Request has a single payload, so return immediately
|
|
18
|
+
const bytes = byteStream(stream);
|
|
19
|
+
let requestReadDone = false;
|
|
20
|
+
try {
|
|
21
|
+
const requestBody = await readEncodedPayload(bytes, protocol.encoding, type, signal);
|
|
22
|
+
requestReadDone = true;
|
|
23
|
+
return requestBody;
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
try {
|
|
27
|
+
if (!requestReadDone) {
|
|
28
|
+
// Do not push partial bytes back into the stream on decode failure/abort.
|
|
29
|
+
// This stream is consumed by req/resp only once.
|
|
30
|
+
drainByteStream(bytes);
|
|
31
|
+
}
|
|
32
|
+
bytes.unwrap();
|
|
16
33
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
34
|
+
catch {
|
|
35
|
+
// Ignore unwrap errors - stream may already be closed
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
//# sourceMappingURL=requestDecode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestDecode.js","sourceRoot":"","sources":["../../src/encoders/requestDecode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"requestDecode.js","sourceRoot":"","sources":["../../src/encoders/requestDecode.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAElE,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnD,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAuB,EACvB,MAAc,EACd,MAAoB;IAEpB,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC;IACnC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,qBAAqB;QACrB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,sDAAsD;IACtD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACjC,IAAI,eAAe,GAAG,KAAK,CAAC;IAC5B,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACrF,eAAe,GAAG,IAAI,CAAC;QACvB,OAAO,WAAW,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,0EAA0E;gBAC1E,iDAAiD;gBACjD,eAAe,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YACD,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,sDAAsD;QACxD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -7,5 +7,5 @@ import { MixedProtocol } from "../types.js";
|
|
|
7
7
|
* Requests may contain no payload (e.g. /eth2/beacon_chain/req/metadata/1/)
|
|
8
8
|
* if so, it would yield no byte chunks
|
|
9
9
|
*/
|
|
10
|
-
export declare function requestEncode(protocol: MixedProtocol, requestBody: Uint8Array):
|
|
10
|
+
export declare function requestEncode(protocol: MixedProtocol, requestBody: Uint8Array): Generator<Buffer>;
|
|
11
11
|
//# sourceMappingURL=requestEncode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestEncode.d.ts","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"requestEncode.d.ts","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAE1C;;;;;;;GAOG;AACH,wBAAiB,aAAa,CAAC,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAMlG"}
|
|
@@ -7,7 +7,7 @@ import { writeEncodedPayload } from "../encodingStrategies/index.js";
|
|
|
7
7
|
* Requests may contain no payload (e.g. /eth2/beacon_chain/req/metadata/1/)
|
|
8
8
|
* if so, it would yield no byte chunks
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export function* requestEncode(protocol, requestBody) {
|
|
11
11
|
const type = protocol.requestSizes;
|
|
12
12
|
if (type && requestBody !== null) {
|
|
13
13
|
yield* writeEncodedPayload(requestBody, protocol.encoding);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestEncode.js","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAGnE;;;;;;;GAOG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"requestEncode.js","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAGnE;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,aAAa,CAAC,QAAuB,EAAE,WAAuB;IAC7E,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC;IAEnC,IAAI,IAAI,IAAI,WAAW,KAAK,IAAI,EAAE,CAAC;QACjC,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Stream } from "@libp2p/interface";
|
|
2
|
+
import type { ByteStream } from "@libp2p/utils";
|
|
2
3
|
import { ForkName } from "@lodestar/params";
|
|
3
4
|
import { RespStatus } from "../interface.js";
|
|
4
5
|
import { ContextBytesFactory, MixedProtocol, ResponseIncoming } from "../types.js";
|
|
5
|
-
import { BufferedSource } from "../utils/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Internal helper type to signal stream ended early
|
|
8
8
|
*/
|
|
@@ -17,10 +17,10 @@ declare enum StreamStatus {
|
|
|
17
17
|
* result ::= "0" | "1" | "2" | ["128" ... "255"]
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function responseDecode(protocol: MixedProtocol,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}):
|
|
20
|
+
export declare function responseDecode(protocol: MixedProtocol, stream: Stream, opts?: {
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
getError?: () => Error;
|
|
23
|
+
}): AsyncIterable<ResponseIncoming>;
|
|
24
24
|
/**
|
|
25
25
|
* Consumes a stream source to read a `<result>`
|
|
26
26
|
* ```bnf
|
|
@@ -28,7 +28,7 @@ export declare function responseDecode(protocol: MixedProtocol, cbs: {
|
|
|
28
28
|
* ```
|
|
29
29
|
* `<response_chunk>` starts with a single-byte response code which determines the contents of the response_chunk
|
|
30
30
|
*/
|
|
31
|
-
export declare function readResultHeader(
|
|
31
|
+
export declare function readResultHeader(bytes: ByteStream<Stream>, signal?: AbortSignal): Promise<RespStatus | StreamStatus>;
|
|
32
32
|
/**
|
|
33
33
|
* Consumes a stream source to read an optional `<error_response>?`
|
|
34
34
|
* ```bnf
|
|
@@ -36,16 +36,16 @@ export declare function readResultHeader(bufferedSource: BufferedSource): Promis
|
|
|
36
36
|
* result ::= "1" | "2" | ["128" ... "255"]
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare function readErrorMessage(
|
|
39
|
+
export declare function readErrorMessage(bytes: ByteStream<Stream>, signal?: AbortSignal): Promise<string>;
|
|
40
40
|
/**
|
|
41
41
|
* Consumes a stream source to read a variable length `<context-bytes>` depending on the method.
|
|
42
42
|
* While `<context-bytes>` has a single type of `ForkDigest`, this function only parses the `ForkName`
|
|
43
43
|
* of the `ForkDigest` or defaults to `phase0`
|
|
44
44
|
*/
|
|
45
|
-
export declare function readContextBytes(contextBytes: ContextBytesFactory,
|
|
45
|
+
export declare function readContextBytes(contextBytes: ContextBytesFactory, bytes: ByteStream<Stream>, signal?: AbortSignal): Promise<ForkName>;
|
|
46
46
|
/**
|
|
47
47
|
* Consumes a stream source to read `<context-bytes>`, where it's a fixed-width 4 byte
|
|
48
48
|
*/
|
|
49
|
-
export declare function readContextBytesForkDigest(
|
|
49
|
+
export declare function readContextBytesForkDigest(bytes: ByteStream<Stream>, signal?: AbortSignal): Promise<Uint8Array>;
|
|
50
50
|
export {};
|
|
51
51
|
//# sourceMappingURL=responseDecode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseDecode.d.ts","sourceRoot":"","sources":["../../src/encoders/responseDecode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"responseDecode.d.ts","sourceRoot":"","sources":["../../src/encoders/responseDecode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACb,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,aAAK,YAAY;IACf,KAAK,iBAAiB;CACvB;AAED;;;;;;;GAOG;AACH,wBAAuB,cAAc,CACnC,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE;IAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,KAAK,CAAA;CAAM,GACxD,aAAa,CAAC,gBAAgB,CAAC,CAiDjC;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EACzB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,GAAG,YAAY,CAAC,CAQpC;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBvG;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,mBAAmB,EACjC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EACzB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,CAUnB;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAErH"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { byteStream } from "@libp2p/utils";
|
|
1
2
|
import { ForkName } from "@lodestar/params";
|
|
2
3
|
import { readEncodedPayload } from "../encodingStrategies/index.js";
|
|
3
4
|
import { RespStatus } from "../interface.js";
|
|
4
5
|
import { ResponseError } from "../response/index.js";
|
|
5
6
|
import { CONTEXT_BYTES_FORK_DIGEST_LENGTH, ContextBytesType, } from "../types.js";
|
|
6
|
-
import {
|
|
7
|
+
import { decodeErrorMessage, drainByteStream } from "../utils/index.js";
|
|
7
8
|
/**
|
|
8
9
|
* Internal helper type to signal stream ended early
|
|
9
10
|
*/
|
|
@@ -19,43 +20,53 @@ var StreamStatus;
|
|
|
19
20
|
* result ::= "0" | "1" | "2" | ["128" ... "255"]
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
|
-
export function responseDecode(protocol,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
while (!bufferedSource.isDone) {
|
|
29
|
-
const status = await readResultHeader(bufferedSource);
|
|
23
|
+
export async function* responseDecode(protocol, stream, opts = {}) {
|
|
24
|
+
const bytes = byteStream(stream);
|
|
25
|
+
let responseReadDone = false;
|
|
26
|
+
try {
|
|
27
|
+
while (true) {
|
|
28
|
+
const status = await readResultHeader(bytes, opts.signal);
|
|
30
29
|
// Stream is only allowed to end at the start of a <response_chunk> block
|
|
31
30
|
// The happens when source ends before readResultHeader() can fetch 1 byte
|
|
32
31
|
if (status === StreamStatus.Ended) {
|
|
33
32
|
break;
|
|
34
33
|
}
|
|
35
|
-
if (!readFirstHeader) {
|
|
36
|
-
cbs.onFirstHeader();
|
|
37
|
-
readFirstHeader = true;
|
|
38
|
-
}
|
|
39
34
|
// For multiple chunks, only the last chunk is allowed to have a non-zero error
|
|
40
35
|
// code (i.e. The chunk stream is terminated once an error occurs
|
|
41
36
|
if (status !== RespStatus.SUCCESS) {
|
|
42
|
-
const errorMessage = await readErrorMessage(
|
|
37
|
+
const errorMessage = await readErrorMessage(bytes, opts.signal);
|
|
43
38
|
throw new ResponseError(status, errorMessage);
|
|
44
39
|
}
|
|
45
|
-
const forkName = await readContextBytes(protocol.contextBytes,
|
|
40
|
+
const forkName = await readContextBytes(protocol.contextBytes, bytes, opts.signal);
|
|
46
41
|
const typeSizes = protocol.responseSizes(forkName);
|
|
47
|
-
const chunkData = await readEncodedPayload(
|
|
42
|
+
const chunkData = await readEncodedPayload(bytes, protocol.encoding, typeSizes, opts.signal);
|
|
48
43
|
yield {
|
|
49
44
|
data: chunkData,
|
|
50
45
|
fork: forkName,
|
|
51
46
|
protocolVersion: protocol.version,
|
|
52
47
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
}
|
|
49
|
+
responseReadDone = true;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (opts.signal?.aborted && opts.getError) {
|
|
53
|
+
throw opts.getError();
|
|
54
|
+
}
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (!responseReadDone) {
|
|
60
|
+
// Do not push partial bytes back into the stream on decode failure/abort.
|
|
61
|
+
// This stream is consumed by req/resp only once.
|
|
62
|
+
drainByteStream(bytes);
|
|
56
63
|
}
|
|
64
|
+
bytes.unwrap();
|
|
57
65
|
}
|
|
58
|
-
|
|
66
|
+
catch {
|
|
67
|
+
// Ignore unwrap errors - stream may already be closed
|
|
68
|
+
}
|
|
69
|
+
}
|
|
59
70
|
}
|
|
60
71
|
/**
|
|
61
72
|
* Consumes a stream source to read a `<result>`
|
|
@@ -64,16 +75,15 @@ export function responseDecode(protocol, cbs) {
|
|
|
64
75
|
* ```
|
|
65
76
|
* `<response_chunk>` starts with a single-byte response code which determines the contents of the response_chunk
|
|
66
77
|
*/
|
|
67
|
-
export async function readResultHeader(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return StreamStatus.Ended;
|
|
78
|
+
export async function readResultHeader(bytes, signal) {
|
|
79
|
+
const chunk = await bytes.read({ bytes: 1, signal }).catch((e) => {
|
|
80
|
+
if (e.name === "UnexpectedEOFError")
|
|
81
|
+
return null;
|
|
82
|
+
throw e;
|
|
83
|
+
});
|
|
84
|
+
if (chunk === null)
|
|
85
|
+
return StreamStatus.Ended;
|
|
86
|
+
return chunk.get(0);
|
|
77
87
|
}
|
|
78
88
|
/**
|
|
79
89
|
* Consumes a stream source to read an optional `<error_response>?`
|
|
@@ -82,39 +92,40 @@ export async function readResultHeader(bufferedSource) {
|
|
|
82
92
|
* result ::= "1" | "2" | ["128" ... "255"]
|
|
83
93
|
* ```
|
|
84
94
|
*/
|
|
85
|
-
export async function readErrorMessage(
|
|
86
|
-
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
export async function readErrorMessage(bytes, signal) {
|
|
96
|
+
const chunks = [];
|
|
97
|
+
let total = 0;
|
|
98
|
+
while (total < 256) {
|
|
99
|
+
const chunk = await bytes.read({ signal }).catch((e) => {
|
|
100
|
+
if (e.name === "UnexpectedEOFError")
|
|
101
|
+
return null;
|
|
102
|
+
throw e;
|
|
103
|
+
});
|
|
104
|
+
if (chunk === null) {
|
|
105
|
+
// If EOF is reached while satisfying a larger read, libp2p v3 may still have
|
|
106
|
+
// buffered bytes available. Drain them so error_message matches pre-v3 behavior.
|
|
107
|
+
const remaining = drainByteStream(bytes);
|
|
108
|
+
if (remaining) {
|
|
109
|
+
chunks.push(remaining);
|
|
110
|
+
}
|
|
93
111
|
break;
|
|
94
112
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// biome-ignore lint/complexity/useLiteralKeys: It is a private attribute
|
|
98
|
-
const bytes = bufferedSource["buffer"].slice(0, length);
|
|
99
|
-
try {
|
|
100
|
-
return decodeErrorMessage(bytes);
|
|
101
|
-
}
|
|
102
|
-
catch (_e) {
|
|
103
|
-
// Error message is optional and may not be included in the response stream
|
|
104
|
-
return Buffer.prototype.toString.call(bytes, "hex");
|
|
113
|
+
chunks.push(chunk.subarray());
|
|
114
|
+
total += chunk.byteLength;
|
|
105
115
|
}
|
|
116
|
+
return decodeErrorMessage(Buffer.concat(chunks).subarray(0, 256));
|
|
106
117
|
}
|
|
107
118
|
/**
|
|
108
119
|
* Consumes a stream source to read a variable length `<context-bytes>` depending on the method.
|
|
109
120
|
* While `<context-bytes>` has a single type of `ForkDigest`, this function only parses the `ForkName`
|
|
110
121
|
* of the `ForkDigest` or defaults to `phase0`
|
|
111
122
|
*/
|
|
112
|
-
export async function readContextBytes(contextBytes,
|
|
123
|
+
export async function readContextBytes(contextBytes, bytes, signal) {
|
|
113
124
|
switch (contextBytes.type) {
|
|
114
125
|
case ContextBytesType.Empty:
|
|
115
126
|
return ForkName.phase0;
|
|
116
127
|
case ContextBytesType.ForkDigest: {
|
|
117
|
-
const forkDigest = await readContextBytesForkDigest(
|
|
128
|
+
const forkDigest = await readContextBytesForkDigest(bytes, signal);
|
|
118
129
|
return contextBytes.config.forkDigest2ForkBoundary(forkDigest).fork;
|
|
119
130
|
}
|
|
120
131
|
}
|
|
@@ -122,15 +133,7 @@ export async function readContextBytes(contextBytes, bufferedSource) {
|
|
|
122
133
|
/**
|
|
123
134
|
* Consumes a stream source to read `<context-bytes>`, where it's a fixed-width 4 byte
|
|
124
135
|
*/
|
|
125
|
-
export async function readContextBytesForkDigest(
|
|
126
|
-
|
|
127
|
-
if (buffer.length >= CONTEXT_BYTES_FORK_DIGEST_LENGTH) {
|
|
128
|
-
const bytes = buffer.slice(0, CONTEXT_BYTES_FORK_DIGEST_LENGTH);
|
|
129
|
-
buffer.consume(CONTEXT_BYTES_FORK_DIGEST_LENGTH);
|
|
130
|
-
return bytes;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// TODO: Use typed error
|
|
134
|
-
throw Error("Source ended while reading context bytes");
|
|
136
|
+
export async function readContextBytesForkDigest(bytes, signal) {
|
|
137
|
+
return (await bytes.read({ bytes: CONTEXT_BYTES_FORK_DIGEST_LENGTH, signal })).subarray();
|
|
135
138
|
}
|
|
136
139
|
//# sourceMappingURL=responseDecode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseDecode.js","sourceRoot":"","sources":["../../src/encoders/responseDecode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"responseDecode.js","sourceRoot":"","sources":["../../src/encoders/responseDecode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,QAAQ,EAAC,MAAM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AC;YACjC,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YACnE,OAAO,YAAY,CAAC,MAAM,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC;QACtE,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,KAAyB,EAAE,MAAoB;IAC9F,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,gCAAgC,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC1F,CAAC"}
|
|
@@ -9,9 +9,7 @@ import { MixedProtocol, Protocol, ResponseOutgoing } from "../types.js";
|
|
|
9
9
|
* ```
|
|
10
10
|
* Note: `response` has zero or more chunks (denoted by `<>*`)
|
|
11
11
|
*/
|
|
12
|
-
export declare function responseEncodeSuccess(protocol: Protocol,
|
|
13
|
-
onChunk: (chunkIndex: number) => void;
|
|
14
|
-
}): (source: AsyncIterable<ResponseOutgoing>) => AsyncIterable<Buffer>;
|
|
12
|
+
export declare function responseEncodeSuccess(protocol: Protocol, source: AsyncIterable<ResponseOutgoing>): AsyncIterable<Uint8Array>;
|
|
15
13
|
/**
|
|
16
14
|
* Yields byte chunks for a `<response_chunk>` with a non-zero response code `<result>`
|
|
17
15
|
* denoted as `<error_response>`
|
|
@@ -22,5 +20,5 @@ export declare function responseEncodeSuccess(protocol: Protocol, cbs: {
|
|
|
22
20
|
* Only the last `<response_chunk>` is allowed to have a non-zero error code, so this
|
|
23
21
|
* fn yields exactly one `<error_response>` and afterwards the stream must be terminated
|
|
24
22
|
*/
|
|
25
|
-
export declare function responseEncodeError(protocol: Pick<MixedProtocol, "encoding">, status: RpcResponseStatusError, errorMessage: string):
|
|
23
|
+
export declare function responseEncodeError(protocol: Pick<MixedProtocol, "encoding">, status: RpcResponseStatusError, errorMessage: string): Generator<Buffer>;
|
|
26
24
|
//# sourceMappingURL=responseEncode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEncode.d.ts","sourceRoot":"","sources":["../../src/encoders/responseEncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,sBAAsB,EAAC,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAwC,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAK7G;;;;;;;;GAQG;AACH,
|
|
1
|
+
{"version":3,"file":"responseEncode.d.ts","sourceRoot":"","sources":["../../src/encoders/responseEncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,sBAAsB,EAAC,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAwC,aAAa,EAAE,QAAQ,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAK7G;;;;;;;;GAQG;AACH,wBAAuB,qBAAqB,CAC1C,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,GACtC,aAAa,CAAC,UAAU,CAAC,CAc3B;AAED;;;;;;;;;GASG;AACH,wBAAiB,mBAAmB,CAClC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,EACzC,MAAM,EAAE,sBAAsB,EAC9B,YAAY,EAAE,MAAM,GACnB,SAAS,CAAC,MAAM,CAAC,CAMnB"}
|
|
@@ -12,23 +12,18 @@ const SUCCESS_BUFFER = Buffer.from([RespStatus.SUCCESS]);
|
|
|
12
12
|
* ```
|
|
13
13
|
* Note: `response` has zero or more chunks (denoted by `<>*`)
|
|
14
14
|
*/
|
|
15
|
-
export function responseEncodeSuccess(protocol,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
yield
|
|
23
|
-
// <context-bytes> - from altair
|
|
24
|
-
const contextBytes = getContextBytes(protocol.contextBytes, chunk);
|
|
25
|
-
if (contextBytes) {
|
|
26
|
-
yield contextBytes;
|
|
27
|
-
}
|
|
28
|
-
// <encoding-dependent-header> | <encoded-payload>
|
|
29
|
-
yield* writeEncodedPayload(chunk.data, protocol.encoding);
|
|
15
|
+
export async function* responseEncodeSuccess(protocol, source) {
|
|
16
|
+
for await (const chunk of source) {
|
|
17
|
+
// <result>
|
|
18
|
+
yield SUCCESS_BUFFER;
|
|
19
|
+
// <context-bytes> - from altair
|
|
20
|
+
const contextBytes = getContextBytes(protocol.contextBytes, chunk);
|
|
21
|
+
if (contextBytes) {
|
|
22
|
+
yield contextBytes;
|
|
30
23
|
}
|
|
31
|
-
|
|
24
|
+
// <encoding-dependent-header> | <encoded-payload>
|
|
25
|
+
yield* writeEncodedPayload(chunk.data, protocol.encoding);
|
|
26
|
+
}
|
|
32
27
|
}
|
|
33
28
|
/**
|
|
34
29
|
* Yields byte chunks for a `<response_chunk>` with a non-zero response code `<result>`
|
|
@@ -40,15 +35,11 @@ export function responseEncodeSuccess(protocol, cbs) {
|
|
|
40
35
|
* Only the last `<response_chunk>` is allowed to have a non-zero error code, so this
|
|
41
36
|
* fn yields exactly one `<error_response>` and afterwards the stream must be terminated
|
|
42
37
|
*/
|
|
43
|
-
export
|
|
44
|
-
if (!errorMessage) {
|
|
45
|
-
yield Buffer.from([status]);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
38
|
+
export function* responseEncodeError(protocol, status, errorMessage) {
|
|
48
39
|
// Combine <result> and <error_message> into a single chunk for atomic delivery.
|
|
49
40
|
// Yielding them separately causes a race condition where the stream closes after the
|
|
50
41
|
// status byte but before the error message arrives on the reader side.
|
|
51
|
-
const errorMessageBuffer =
|
|
42
|
+
const errorMessageBuffer = encodeErrorMessageToBuffer(errorMessage, protocol.encoding);
|
|
52
43
|
yield Buffer.concat([Buffer.from([status]), errorMessageBuffer]);
|
|
53
44
|
}
|
|
54
45
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEncode.js","sourceRoot":"","sources":["../../src/encoders/responseEncode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAC,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAsB,gBAAgB,EAA4C,MAAM,aAAa,CAAC;AAC7G,OAAO,EAAC,0BAA0B,EAAC,MAAM,mBAAmB,CAAC;AAE7D,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"responseEncode.js","sourceRoot":"","sources":["../../src/encoders/responseEncode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAC,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAsB,gBAAgB,EAA4C,MAAM,aAAa,CAAC;AAC7G,OAAO,EAAC,0BAA0B,EAAC,MAAM,mBAAmB,CAAC;AAE7D,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,QAAkB,EAClB,MAAuC;IAEvC,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACjC,WAAW;QACX,MAAM,cAAc,CAAC;QAErB,gCAAgC;QAChC,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACnE,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,YAAY,CAAC;QACrB,CAAC;QAED,kDAAkD;QAClD,KAAK,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,SAAS,CAAC,CAAC,mBAAmB,CAClC,QAAyC,EACzC,MAA8B,EAC9B,YAAoB;IAEpB,gFAAgF;IAChF,qFAAqF;IACrF,uEAAuE;IACvE,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvF,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,YAAiC,EAAE,KAAuB;IACjF,QAAQ,YAAY,CAAC,IAAI,EAAE,CAAC;QAC1B,gBAAgB;QAChB,KAAK,gBAAgB,CAAC,KAAK;YACzB,OAAO,IAAI,CAAC;QAEd,4DAA4D;QAC5D,KAAK,gBAAgB,CAAC,UAAU;YAC9B,OAAO,YAAY,CAAC,MAAM,CAAC,uBAAuB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { Stream } from "@libp2p/interface";
|
|
2
|
+
import type { ByteStream } from "@libp2p/utils";
|
|
1
3
|
import { Encoding, TypeSizes } from "../types.js";
|
|
2
|
-
import { BufferedSource } from "../utils/index.js";
|
|
3
4
|
/**
|
|
4
5
|
* Consumes a stream source to read encoded header and payload as defined in the spec:
|
|
5
6
|
* ```
|
|
6
7
|
* <encoding-dependent-header> | <encoded-payload>
|
|
7
8
|
* ```
|
|
8
9
|
*/
|
|
9
|
-
export declare function readEncodedPayload(
|
|
10
|
+
export declare function readEncodedPayload(stream: ByteStream<Stream>, encoding: Encoding, type: TypeSizes, signal?: AbortSignal): Promise<Uint8Array>;
|
|
10
11
|
/**
|
|
11
12
|
* Yields byte chunks for encoded header and payload as defined in the spec:
|
|
12
13
|
* ```
|
|
13
14
|
* <encoding-dependent-header> | <encoded-payload>
|
|
14
15
|
* ```
|
|
15
16
|
*/
|
|
16
|
-
export declare function writeEncodedPayload(chunkData: Uint8Array, encoding: Encoding):
|
|
17
|
+
export declare function writeEncodedPayload(chunkData: Uint8Array, encoding: Encoding): Generator<Buffer>;
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encodingStrategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encodingStrategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAShD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,EAC1B,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC,CAQrB;AAED;;;;;GAKG;AACH,wBAAiB,mBAAmB,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,CASjG"}
|