@lodestar/reqresp 1.8.0 → 1.9.0-dev.b90a09c997
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 +19 -7
- package/lib/ReqResp.d.ts +7 -7
- package/lib/ReqResp.js +1 -1
- package/lib/ReqResp.js.map +1 -1
- package/lib/encoders/requestDecode.d.ts +2 -2
- package/lib/encoders/requestDecode.js +3 -3
- package/lib/encoders/requestDecode.js.map +1 -1
- package/lib/encoders/requestEncode.d.ts +2 -2
- package/lib/encoders/requestEncode.js +2 -4
- package/lib/encoders/requestEncode.js.map +1 -1
- package/lib/encoders/responseDecode.d.ts +4 -4
- package/lib/encoders/responseDecode.js +7 -2
- package/lib/encoders/responseDecode.js.map +1 -1
- package/lib/encoders/responseEncode.d.ts +3 -3
- package/lib/encoders/responseEncode.js +3 -31
- package/lib/encoders/responseEncode.js.map +1 -1
- package/lib/encodingStrategies/index.d.ts +3 -3
- package/lib/encodingStrategies/index.js +2 -2
- package/lib/encodingStrategies/index.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/decode.d.ts +3 -3
- package/lib/encodingStrategies/sszSnappy/decode.js +1 -14
- package/lib/encodingStrategies/sszSnappy/decode.js.map +1 -1
- package/lib/encodingStrategies/sszSnappy/encode.d.ts +1 -2
- package/lib/encodingStrategies/sszSnappy/encode.js +2 -23
- package/lib/encodingStrategies/sszSnappy/encode.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js.map +1 -1
- package/lib/rate_limiter/ReqRespRateLimiter.d.ts +1 -1
- package/lib/rate_limiter/ReqRespRateLimiter.js.map +1 -1
- package/lib/request/errors.d.ts +5 -14
- package/lib/request/errors.js +3 -11
- package/lib/request/errors.js.map +1 -1
- package/lib/request/index.d.ts +2 -2
- package/lib/request/index.js +12 -17
- package/lib/request/index.js.map +1 -1
- package/lib/response/index.d.ts +4 -4
- package/lib/response/index.js +10 -5
- package/lib/response/index.js.map +1 -1
- package/lib/types.d.ts +62 -79
- package/lib/types.js +0 -8
- package/lib/types.js.map +1 -1
- package/lib/utils/bufferedSource.d.ts +1 -1
- package/lib/utils/bufferedSource.js.map +1 -1
- package/lib/utils/collectExactOne.js +2 -2
- package/lib/utils/collectExactOne.js.map +1 -1
- package/lib/utils/protocolId.d.ts +2 -2
- package/lib/utils/protocolId.js.map +1 -1
- package/package.json +9 -9
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.d.ts +0 -4
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.js +0 -27
- package/lib/protocols/BeaconBlockAndBlobsSidecarByRoot.js.map +0 -1
- package/lib/protocols/BeaconBlocksByRange.d.ts +0 -5
- package/lib/protocols/BeaconBlocksByRange.js +0 -38
- package/lib/protocols/BeaconBlocksByRange.js.map +0 -1
- package/lib/protocols/BeaconBlocksByRoot.d.ts +0 -5
- package/lib/protocols/BeaconBlocksByRoot.js +0 -38
- package/lib/protocols/BeaconBlocksByRoot.js.map +0 -1
- package/lib/protocols/BlobsSidecarsByRange.d.ts +0 -4
- package/lib/protocols/BlobsSidecarsByRange.js +0 -27
- package/lib/protocols/BlobsSidecarsByRange.js.map +0 -1
- package/lib/protocols/Goodbye.d.ts +0 -4
- package/lib/protocols/Goodbye.js +0 -21
- package/lib/protocols/Goodbye.js.map +0 -1
- package/lib/protocols/LightClientBootstrap.d.ts +0 -4
- package/lib/protocols/LightClientBootstrap.js +0 -30
- package/lib/protocols/LightClientBootstrap.js.map +0 -1
- package/lib/protocols/LightClientFinalityUpdate.d.ts +0 -4
- package/lib/protocols/LightClientFinalityUpdate.js +0 -29
- package/lib/protocols/LightClientFinalityUpdate.js.map +0 -1
- package/lib/protocols/LightClientOptimisticUpdate.d.ts +0 -4
- package/lib/protocols/LightClientOptimisticUpdate.js +0 -29
- package/lib/protocols/LightClientOptimisticUpdate.js.map +0 -1
- package/lib/protocols/LightClientUpdatesByRange.d.ts +0 -4
- package/lib/protocols/LightClientUpdatesByRange.js +0 -28
- package/lib/protocols/LightClientUpdatesByRange.js.map +0 -1
- package/lib/protocols/Metadata.d.ts +0 -5
- package/lib/protocols/Metadata.js +0 -31
- package/lib/protocols/Metadata.js.map +0 -1
- package/lib/protocols/Ping.d.ts +0 -4
- package/lib/protocols/Ping.js +0 -20
- package/lib/protocols/Ping.js.map +0 -1
- package/lib/protocols/Status.d.ts +0 -4
- package/lib/protocols/Status.js +0 -24
- package/lib/protocols/Status.js.map +0 -1
- package/lib/protocols/index.d.ts +0 -13
- package/lib/protocols/index.js +0 -13
- package/lib/protocols/index.js.map +0 -1
- package/lib/protocols/utils.d.ts +0 -7
- package/lib/protocols/utils.js +0 -9
- package/lib/protocols/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,19 +13,31 @@ Typescript REST client for the [Ethereum Consensus API spec](https://github.com/
|
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import {Libp2p} from "libp2p";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import {ssz} from "@lodestar/types";
|
|
17
|
+
import {ReqResp, ContextBytesType, Protocol, Encoding} from "@lodestar/reqresp";
|
|
18
|
+
import {ForkName} from "@lodestar/params";
|
|
18
19
|
import {Logger} from "@lodestar/utils";
|
|
19
20
|
|
|
20
21
|
async function getReqResp(libp2p: Libp2p, logger: Logger): Promise<void> {
|
|
21
22
|
const reqResp = new ReqResp({libp2p, logger, metricsRegister: null});
|
|
22
23
|
|
|
23
24
|
// Register a PONG handler to respond with caller's Ping request
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const pingProtocol: Protocol = {
|
|
26
|
+
method: "ping",
|
|
27
|
+
version: 1,
|
|
28
|
+
encoding: Encoding.SSZ_SNAPPY,
|
|
29
|
+
contextBytes: {type: ContextBytesType.Empty},
|
|
30
|
+
requestSizes: ssz.phase0.Ping,
|
|
31
|
+
responseSizes: () => ssz.phase0.Ping,
|
|
32
|
+
handler: async function* (req) {
|
|
33
|
+
yield {
|
|
34
|
+
data: req.data,
|
|
35
|
+
fork: ForkName.phase0,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
reqResp.registerProtocol(pingProtocol);
|
|
29
41
|
}
|
|
30
42
|
```
|
|
31
43
|
|
package/lib/ReqResp.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Libp2p } from "libp2p";
|
|
|
3
3
|
import { Logger } from "@lodestar/utils";
|
|
4
4
|
import { Metrics, MetricsRegister } from "./metrics.js";
|
|
5
5
|
import { RequestError, SendRequestOpts } from "./request/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { DialOnlyProtocol, Encoding, MixedProtocol, ReqRespRateLimiterOpts, Protocol, ProtocolDescriptor, ResponseIncoming } from "./types.js";
|
|
7
7
|
type ProtocolID = string;
|
|
8
8
|
export declare const DEFAULT_PROTOCOL_PREFIX = "/eth2/beacon_chain/req";
|
|
9
9
|
export interface ReqRespProtocolModules {
|
|
@@ -45,14 +45,14 @@ export declare class ReqResp {
|
|
|
45
45
|
*
|
|
46
46
|
* Made it explicit method to avoid any developer mistake
|
|
47
47
|
*/
|
|
48
|
-
registerDialOnlyProtocol
|
|
48
|
+
registerDialOnlyProtocol(protocol: DialOnlyProtocol, opts?: ReqRespRegisterOpts): void;
|
|
49
49
|
/**
|
|
50
50
|
* Register protocol as supported and to libp2p.
|
|
51
51
|
* async because libp2p registar persists the new protocol list in the peer-store.
|
|
52
52
|
* Throws if the same protocol is registered twice.
|
|
53
53
|
* Can be called at any time, no concept of started / stopped
|
|
54
54
|
*/
|
|
55
|
-
registerProtocol
|
|
55
|
+
registerProtocol(protocol: Protocol, opts?: ReqRespRegisterOpts): Promise<void>;
|
|
56
56
|
/**
|
|
57
57
|
* Remove protocol as supported and from libp2p.
|
|
58
58
|
* async because libp2p registar persists the new protocol list in the peer-store.
|
|
@@ -67,10 +67,10 @@ export declare class ReqResp {
|
|
|
67
67
|
getRegisteredProtocols(): ProtocolID[];
|
|
68
68
|
start(): Promise<void>;
|
|
69
69
|
stop(): Promise<void>;
|
|
70
|
-
protected sendRequest
|
|
70
|
+
protected sendRequest(peerId: PeerId, method: string, versions: number[], encoding: Encoding, body: Uint8Array): AsyncIterable<ResponseIncoming>;
|
|
71
71
|
private getRequestHandler;
|
|
72
|
-
protected onIncomingRequest(_peerId: PeerId, _protocol:
|
|
73
|
-
protected onIncomingRequestError(_protocol:
|
|
72
|
+
protected onIncomingRequest(_peerId: PeerId, _protocol: ProtocolDescriptor): void;
|
|
73
|
+
protected onIncomingRequestError(_protocol: ProtocolDescriptor, _error: RequestError): void;
|
|
74
74
|
protected onOutgoingRequestError(_peerId: PeerId, _method: string, _error: RequestError): void;
|
|
75
75
|
/**
|
|
76
76
|
* ```
|
|
@@ -78,7 +78,7 @@ export declare class ReqResp {
|
|
|
78
78
|
* ```
|
|
79
79
|
* https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/p2p-interface.md#protocol-identification
|
|
80
80
|
*/
|
|
81
|
-
protected formatProtocolID(protocol: Pick<
|
|
81
|
+
protected formatProtocolID(protocol: Pick<MixedProtocol, "method" | "version" | "encoding">): string;
|
|
82
82
|
}
|
|
83
83
|
export {};
|
|
84
84
|
//# sourceMappingURL=ReqResp.d.ts.map
|
package/lib/ReqResp.js
CHANGED
|
@@ -53,7 +53,7 @@ export class ReqResp {
|
|
|
53
53
|
*/
|
|
54
54
|
async registerProtocol(protocol, opts) {
|
|
55
55
|
const protocolID = this.formatProtocolID(protocol);
|
|
56
|
-
const { handler: _handler,
|
|
56
|
+
const { handler: _handler, inboundRateLimits, ...rest } = protocol;
|
|
57
57
|
this.registerDialOnlyProtocol(rest, opts);
|
|
58
58
|
this.dialOnlyProtocols.set(protocolID, false);
|
|
59
59
|
if (inboundRateLimits) {
|
package/lib/ReqResp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReqResp.js","sourceRoot":"","sources":["../src/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AC7B,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;aACtC;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAA,IAAI,CAAC,OAAO,0CAAE,cAAc,CAAC,GAAG,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC;gBAE3C,IAAI,GAAG,YAAY,YAAY,EAAE;oBAC/B,IAAI,CAAC,sBAAsB,CAAC,QAA8B,EAAE,GAAG,CAAC,CAAC;iBAClE;gBAED,mCAAmC;gBACnC,gDAAgD;aACjD;oBAAS;gBACR,KAAK,aAAL,KAAK,uBAAL,KAAK,EAAI,CAAC;aACX;QACH,CAAC,CAAC;IACJ,CAAC;IAES,iBAAiB,CAAC,OAAe,EAAE,SAA6B;QACxE,WAAW;IACb,CAAC;IAED,8DAA8D;IACpD,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,11 +1,11 @@
|
|
|
1
1
|
import { Sink } from "it-stream-types";
|
|
2
2
|
import { Uint8ArrayList } from "uint8arraylist";
|
|
3
|
-
import {
|
|
3
|
+
import { MixedProtocol } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Consumes a stream source to read a `<request>`
|
|
6
6
|
* ```bnf
|
|
7
7
|
* request ::= <encoding-dependent-header> | <encoded-payload>
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
export declare function requestDecode
|
|
10
|
+
export declare function requestDecode(protocol: MixedProtocol): Sink<Uint8Array | Uint8ArrayList, Promise<Uint8Array>>;
|
|
11
11
|
//# sourceMappingURL=requestDecode.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ForkName } from "@lodestar/params";
|
|
2
1
|
import { BufferedSource } from "../utils/index.js";
|
|
3
2
|
import { readEncodedPayload } from "../encodingStrategies/index.js";
|
|
3
|
+
const EMPTY_DATA = new Uint8Array();
|
|
4
4
|
/**
|
|
5
5
|
* Consumes a stream source to read a `<request>`
|
|
6
6
|
* ```bnf
|
|
@@ -9,10 +9,10 @@ import { readEncodedPayload } from "../encodingStrategies/index.js";
|
|
|
9
9
|
*/
|
|
10
10
|
export function requestDecode(protocol) {
|
|
11
11
|
return async function requestDecodeSink(source) {
|
|
12
|
-
const type = protocol.
|
|
12
|
+
const type = protocol.requestSizes;
|
|
13
13
|
if (type === null) {
|
|
14
14
|
// method has no body
|
|
15
|
-
return
|
|
15
|
+
return EMPTY_DATA;
|
|
16
16
|
}
|
|
17
17
|
// Request has a single payload, so return immediately
|
|
18
18
|
const bufferedSource = new BufferedSource(source);
|
|
@@ -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":"AAGA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAElE,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAAuB;IACnD,OAAO,KAAK,UAAU,iBAAiB,CAAC,MAAM;QAC5C,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC;QACnC,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,qBAAqB;YACrB,OAAO,UAAU,CAAC;SACnB;QAED,sDAAsD;QACtD,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,MAAwC,CAAC,CAAC;QACpF,OAAO,kBAAkB,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACrE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { MixedProtocol } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Yields byte chunks for a `<request>`
|
|
5
5
|
* ```bnf
|
|
@@ -8,5 +8,5 @@ import { MixedProtocolDefinition } from "../types.js";
|
|
|
8
8
|
* Requests may contain no payload (e.g. /eth2/beacon_chain/req/metadata/1/)
|
|
9
9
|
* if so, it would yield no byte chunks
|
|
10
10
|
*/
|
|
11
|
-
export declare function requestEncode
|
|
11
|
+
export declare function requestEncode(protocol: MixedProtocol, requestBody: Uint8Array): AsyncGenerator<Buffer>;
|
|
12
12
|
//# sourceMappingURL=requestEncode.d.ts.map
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ForkName } from "@lodestar/params";
|
|
2
|
-
import { EncodedPayloadType } from "../types.js";
|
|
3
1
|
import { writeEncodedPayload } from "../encodingStrategies/index.js";
|
|
4
2
|
/**
|
|
5
3
|
* Yields byte chunks for a `<request>`
|
|
@@ -10,9 +8,9 @@ import { writeEncodedPayload } from "../encodingStrategies/index.js";
|
|
|
10
8
|
* if so, it would yield no byte chunks
|
|
11
9
|
*/
|
|
12
10
|
export async function* requestEncode(protocol, requestBody) {
|
|
13
|
-
const type = protocol.
|
|
11
|
+
const type = protocol.requestSizes;
|
|
14
12
|
if (type && requestBody !== null) {
|
|
15
|
-
yield* writeEncodedPayload(
|
|
13
|
+
yield* writeEncodedPayload(requestBody, protocol.encoding);
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
//# sourceMappingURL=requestEncode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestEncode.js","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"requestEncode.js","sourceRoot":"","sources":["../../src/encoders/requestEncode.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,aAAa,CAAC,QAAuB,EAAE,WAAuB;IACnF,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,CAAC;IAEnC,IAAI,IAAI,IAAI,WAAW,KAAK,IAAI,EAAE;QAChC,KAAK,CAAC,CAAC,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC5D;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Uint8ArrayList } from "uint8arraylist";
|
|
2
2
|
import { ForkName } from "@lodestar/params";
|
|
3
3
|
import { BufferedSource } from "../utils/index.js";
|
|
4
|
-
import { ContextBytesFactory,
|
|
4
|
+
import { ContextBytesFactory, MixedProtocol, ResponseIncoming } from "../types.js";
|
|
5
5
|
import { RespStatus } from "../interface.js";
|
|
6
6
|
/**
|
|
7
7
|
* Internal helper type to signal stream ended early
|
|
@@ -17,10 +17,10 @@ declare enum StreamStatus {
|
|
|
17
17
|
* result ::= "0" | "1" | "2" | ["128" ... "255"]
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
|
-
export declare function responseDecode
|
|
20
|
+
export declare function responseDecode(protocol: MixedProtocol, cbs: {
|
|
21
21
|
onFirstHeader: () => void;
|
|
22
22
|
onFirstResponseChunk: () => void;
|
|
23
|
-
}): (source: AsyncIterable<Uint8Array | Uint8ArrayList>) => AsyncIterable<
|
|
23
|
+
}): (source: AsyncIterable<Uint8Array | Uint8ArrayList>) => AsyncIterable<ResponseIncoming>;
|
|
24
24
|
/**
|
|
25
25
|
* Consumes a stream source to read a `<result>`
|
|
26
26
|
* ```bnf
|
|
@@ -42,7 +42,7 @@ export declare function readErrorMessage(bufferedSource: BufferedSource): Promis
|
|
|
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, bufferedSource: BufferedSource): Promise<ForkName>;
|
|
46
46
|
/**
|
|
47
47
|
* Consumes a stream source to read `<context-bytes>`, where it's a fixed-width 4 byte
|
|
48
48
|
*/
|
|
@@ -43,8 +43,13 @@ export function responseDecode(protocol, cbs) {
|
|
|
43
43
|
throw new ResponseError(status, errorMessage);
|
|
44
44
|
}
|
|
45
45
|
const forkName = await readContextBytes(protocol.contextBytes, bufferedSource);
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const typeSizes = protocol.responseSizes(forkName);
|
|
47
|
+
const chunkData = await readEncodedPayload(bufferedSource, protocol.encoding, typeSizes);
|
|
48
|
+
yield {
|
|
49
|
+
data: chunkData,
|
|
50
|
+
fork: forkName,
|
|
51
|
+
protocolVersion: protocol.version,
|
|
52
|
+
};
|
|
48
53
|
if (!readFirstResponseChunk) {
|
|
49
54
|
cbs.onFirstResponseChunk();
|
|
50
55
|
readFirstResponseChunk = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseDecode.js","sourceRoot":"","sources":["../../src/encoders/responseDecode.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAE,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAC,kBAAkB,EAAC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M,IAAI,cAAc,EAAE;QACzC,IAAI,MAAM,CAAC,MAAM,IAAI,gCAAgC,EAAE;YACrD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,gCAAgC,CAAC,CAAC;YAChE,MAAM,CAAC,OAAO,CAAC,gCAAgC,CAAC,CAAC;YACjD,OAAO,KAAK,CAAC;SACd;KACF;IAED,wBAAwB;IACxB,MAAM,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { MixedProtocol, Protocol, ResponseOutgoing } from "../types.js";
|
|
3
3
|
import { RpcResponseStatusError } from "../interface.js";
|
|
4
4
|
/**
|
|
5
5
|
* Yields byte chunks for a `<response>` with a zero response code `<result>`
|
|
@@ -10,7 +10,7 @@ import { RpcResponseStatusError } from "../interface.js";
|
|
|
10
10
|
* ```
|
|
11
11
|
* Note: `response` has zero or more chunks (denoted by `<>*`)
|
|
12
12
|
*/
|
|
13
|
-
export declare function responseEncodeSuccess
|
|
13
|
+
export declare function responseEncodeSuccess(protocol: Protocol): (source: AsyncIterable<ResponseOutgoing>) => AsyncIterable<Buffer>;
|
|
14
14
|
/**
|
|
15
15
|
* Yields byte chunks for a `<response_chunk>` with a non-zero response code `<result>`
|
|
16
16
|
* denoted as `<error_response>`
|
|
@@ -21,5 +21,5 @@ export declare function responseEncodeSuccess<Req, Resp>(protocol: ProtocolDefin
|
|
|
21
21
|
* Only the last `<response_chunk>` is allowed to have a non-zero error code, so this
|
|
22
22
|
* fn yields exactly one `<error_response>` and afterwards the stream must be terminated
|
|
23
23
|
*/
|
|
24
|
-
export declare function responseEncodeError(protocol: Pick<
|
|
24
|
+
export declare function responseEncodeError(protocol: Pick<MixedProtocol, "encoding">, status: RpcResponseStatusError, errorMessage: string): AsyncGenerator<Buffer>;
|
|
25
25
|
//# sourceMappingURL=responseEncode.d.ts.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ForkName } from "@lodestar/params";
|
|
2
1
|
import { writeEncodedPayload } from "../encodingStrategies/index.js";
|
|
3
2
|
import { encodeErrorMessage } from "../utils/index.js";
|
|
4
|
-
import { ContextBytesType
|
|
3
|
+
import { ContextBytesType } from "../types.js";
|
|
5
4
|
import { RespStatus } from "../interface.js";
|
|
6
5
|
/**
|
|
7
6
|
* Yields byte chunks for a `<response>` with a zero response code `<result>`
|
|
@@ -23,9 +22,7 @@ export function responseEncodeSuccess(protocol) {
|
|
|
23
22
|
yield contextBytes;
|
|
24
23
|
}
|
|
25
24
|
// <encoding-dependent-header> | <encoded-payload>
|
|
26
|
-
|
|
27
|
-
const respType = protocol.responseType(forkName);
|
|
28
|
-
yield* writeEncodedPayload(chunk, protocol.encoding, respType);
|
|
25
|
+
yield* writeEncodedPayload(chunk.data, protocol.encoding);
|
|
29
26
|
}
|
|
30
27
|
};
|
|
31
28
|
}
|
|
@@ -58,32 +55,7 @@ function getContextBytes(contextBytes, chunk) {
|
|
|
58
55
|
return null;
|
|
59
56
|
// Yield a fixed-width 4 byte chunk, set to the `ForkDigest`
|
|
60
57
|
case ContextBytesType.ForkDigest:
|
|
61
|
-
|
|
62
|
-
case EncodedPayloadType.ssz:
|
|
63
|
-
return contextBytes.forkDigestContext.forkName2ForkDigest(contextBytes.forkFromResponse(chunk.data));
|
|
64
|
-
case EncodedPayloadType.bytes:
|
|
65
|
-
if (chunk.contextBytes.type !== ContextBytesType.ForkDigest) {
|
|
66
|
-
throw Error(`Expected context bytes ForkDigest but got ${chunk.contextBytes.type}`);
|
|
67
|
-
}
|
|
68
|
-
return contextBytes.forkDigestContext.forkName2ForkDigest(contextBytes.forkDigestContext.getForkName(chunk.contextBytes.forkSlot));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function getForkNameFromContextBytes(contextBytes, chunk) {
|
|
73
|
-
switch (contextBytes.type) {
|
|
74
|
-
case ContextBytesType.Empty:
|
|
75
|
-
return ForkName.phase0;
|
|
76
|
-
// Yield a fixed-width 4 byte chunk, set to the `ForkDigest`
|
|
77
|
-
case ContextBytesType.ForkDigest:
|
|
78
|
-
switch (chunk.type) {
|
|
79
|
-
case EncodedPayloadType.ssz:
|
|
80
|
-
return contextBytes.forkFromResponse(chunk.data);
|
|
81
|
-
case EncodedPayloadType.bytes:
|
|
82
|
-
if (chunk.contextBytes.type !== ContextBytesType.ForkDigest) {
|
|
83
|
-
throw Error(`Expected context bytes ForkDigest but got ${chunk.contextBytes.type}`);
|
|
84
|
-
}
|
|
85
|
-
return contextBytes.forkDigestContext.getForkName(chunk.contextBytes.forkSlot);
|
|
86
|
-
}
|
|
58
|
+
return contextBytes.forkDigestContext.forkName2ForkDigest(chunk.fork);
|
|
87
59
|
}
|
|
88
60
|
}
|
|
89
61
|
//# sourceMappingURL=responseEncode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responseEncode.js","sourceRoot":"","sources":["../../src/encoders/responseEncode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
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,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAC,gBAAgB,EAAiE,MAAM,aAAa,CAAC;AAC7G,OAAO,EAAC,UAAU,EAAyB,MAAM,iBAAiB,CAAC;AAEnE;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAkB;IAElB,OAAO,KAAK,SAAS,CAAC,CAAC,8BAA8B,CAAC,MAAM;QAC1D,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;YAChC,WAAW;YACX,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;YAExC,gCAAgC;YAChC,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;YACnE,IAAI,YAAY,EAAE;gBAChB,MAAM,YAAsB,CAAC;aAC9B;YAED,kDAAkD;YAClD,KAAK,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC3D;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CACxC,QAAyC,EACzC,MAA8B,EAC9B,YAAoB;IAEpB,WAAW;IACX,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5B,+BAA+B;IAC/B,IAAI,YAAY,EAAE;QAChB,KAAK,CAAC,CAAC,kBAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC5D;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe,CAAC,YAAiC,EAAE,KAAuB;IACjF,QAAQ,YAAY,CAAC,IAAI,EAAE;QACzB,gBAAgB;QAChB,KAAK,gBAAgB,CAAC,KAAK;YACzB,OAAO,IAAI,CAAC;QAEd,4DAA4D;QAC5D,KAAK,gBAAgB,CAAC,UAAU;YAC9B,OAAO,YAAY,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAW,CAAC;KACnF;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Encoding,
|
|
2
|
+
import { Encoding, TypeSizes } from "../types.js";
|
|
3
3
|
import { BufferedSource } from "../utils/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Consumes a stream source to read encoded header and payload as defined in the spec:
|
|
@@ -7,12 +7,12 @@ import { BufferedSource } from "../utils/index.js";
|
|
|
7
7
|
* <encoding-dependent-header> | <encoded-payload>
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
|
-
export declare function readEncodedPayload
|
|
10
|
+
export declare function readEncodedPayload(bufferedSource: BufferedSource, encoding: Encoding, type: TypeSizes): Promise<Uint8Array>;
|
|
11
11
|
/**
|
|
12
12
|
* Yields byte chunks for encoded header and payload as defined in the spec:
|
|
13
13
|
* ```
|
|
14
14
|
* <encoding-dependent-header> | <encoded-payload>
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export declare function writeEncodedPayload
|
|
17
|
+
export declare function writeEncodedPayload(chunkData: Uint8Array, encoding: Encoding): AsyncGenerator<Buffer>;
|
|
18
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -25,10 +25,10 @@ export async function readEncodedPayload(bufferedSource, encoding, type) {
|
|
|
25
25
|
* <encoding-dependent-header> | <encoded-payload>
|
|
26
26
|
* ```
|
|
27
27
|
*/
|
|
28
|
-
export async function* writeEncodedPayload(
|
|
28
|
+
export async function* writeEncodedPayload(chunkData, encoding) {
|
|
29
29
|
switch (encoding) {
|
|
30
30
|
case Encoding.SSZ_SNAPPY:
|
|
31
|
-
yield* writeSszSnappyPayload(
|
|
31
|
+
yield* writeSszSnappyPayload(chunkData);
|
|
32
32
|
break;
|
|
33
33
|
default:
|
|
34
34
|
throw Error("Unsupported encoding");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/encodingStrategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/encodingStrategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAY,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAE5D,oFAAoF;AACpF,6GAA6G;AAC7G,iCAAiC;AACjC,eAAe;AAEf;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,cAA8B,EAC9B,QAAkB,EAClB,IAAe;IAEf,QAAQ,QAAQ,EAAE;QAChB,KAAK,QAAQ,CAAC,UAAU;YACtB,OAAO,oBAAoB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;QAEpD;YACE,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACvC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,mBAAmB,CAAC,SAAqB,EAAE,QAAkB;IAClF,QAAQ,QAAQ,EAAE;QAChB,KAAK,QAAQ,CAAC,UAAU;YACtB,KAAK,CAAC,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;YACxC,MAAM;QAER;YACE,MAAM,KAAK,CAAC,sBAAsB,CAAC,CAAC;KACvC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BufferedSource } from "../../utils/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { TypeSizes } from "../../types.js";
|
|
3
3
|
export declare const MAX_VARINT_BYTES = 10;
|
|
4
4
|
/**
|
|
5
5
|
* ssz_snappy encoding strategy reader.
|
|
@@ -8,12 +8,12 @@ export declare const MAX_VARINT_BYTES = 10;
|
|
|
8
8
|
* <encoding-dependent-header> | <encoded-payload>
|
|
9
9
|
* ```
|
|
10
10
|
*/
|
|
11
|
-
export declare function readSszSnappyPayload
|
|
11
|
+
export declare function readSszSnappyPayload(bufferedSource: BufferedSource, type: TypeSizes): Promise<Uint8Array>;
|
|
12
12
|
/**
|
|
13
13
|
* Reads `<encoding-dependent-header>` for ssz-snappy.
|
|
14
14
|
* encoding-header ::= the length of the raw SSZ bytes, encoded as an unsigned protobuf varint
|
|
15
15
|
*/
|
|
16
|
-
export declare function readSszSnappyHeader(bufferedSource: BufferedSource, type:
|
|
16
|
+
export declare function readSszSnappyHeader(bufferedSource: BufferedSource, type: TypeSizes): Promise<number>;
|
|
17
17
|
/**
|
|
18
18
|
* Reads `<encoded-payload>` for ssz-snappy and decompress.
|
|
19
19
|
* The returned bytes can be SSZ deseralized
|
|
@@ -13,8 +13,7 @@ export const MAX_VARINT_BYTES = 10;
|
|
|
13
13
|
*/
|
|
14
14
|
export async function readSszSnappyPayload(bufferedSource, type) {
|
|
15
15
|
const sszDataLength = await readSszSnappyHeader(bufferedSource, type);
|
|
16
|
-
|
|
17
|
-
return deserializeSszBody(bytes, type);
|
|
16
|
+
return readSszSnappyBody(bufferedSource, sszDataLength);
|
|
18
17
|
}
|
|
19
18
|
/**
|
|
20
19
|
* Reads `<encoding-dependent-header>` for ssz-snappy.
|
|
@@ -100,16 +99,4 @@ export async function readSszSnappyBody(bufferedSource, sszDataLength) {
|
|
|
100
99
|
// SHOULD consider invalid: An early EOF before fully reading the declared length-prefix worth of SSZ bytes
|
|
101
100
|
throw new SszSnappyError({ code: SszSnappyErrorCode.SOURCE_ABORTED });
|
|
102
101
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Deseralizes SSZ body.
|
|
105
|
-
* `isSszTree` option allows the SignedBeaconBlock type to be deserialized as a tree
|
|
106
|
-
*/
|
|
107
|
-
function deserializeSszBody(bytes, type) {
|
|
108
|
-
try {
|
|
109
|
-
return type.deserialize(bytes);
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
throw new SszSnappyError({ code: SszSnappyErrorCode.DESERIALIZE_ERROR, deserializeError: e });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
102
|
//# sourceMappingURL=decode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/encodingStrategies/sszSnappy/decode.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,cAAc,EAAC,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAC,sBAAsB,E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MAAM,IAAI,cAAc,CAAC,EAAC,IAAI,EAAE,kBAAkB,CAAC,cAAc,EAAC,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { EncodedPayload, TypeSerializer } from "../../types.js";
|
|
3
2
|
/**
|
|
4
3
|
* ssz_snappy encoding strategy writer.
|
|
5
4
|
* Yields byte chunks for encoded header and payload as defined in the spec:
|
|
@@ -7,7 +6,7 @@ import { EncodedPayload, TypeSerializer } from "../../types.js";
|
|
|
7
6
|
* <encoding-dependent-header> | <encoded-payload>
|
|
8
7
|
* ```
|
|
9
8
|
*/
|
|
10
|
-
export declare function writeSszSnappyPayload
|
|
9
|
+
export declare function writeSszSnappyPayload(bodyData: Uint8Array): AsyncGenerator<Buffer>;
|
|
11
10
|
/**
|
|
12
11
|
* Buffered Snappy writer
|
|
13
12
|
*/
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import varint from "varint";
|
|
2
2
|
import { source } from "stream-to-it";
|
|
3
3
|
import snappy from "@chainsafe/snappy-stream";
|
|
4
|
-
import { EncodedPayloadType } from "../../types.js";
|
|
5
|
-
import { SszSnappyError, SszSnappyErrorCode } from "./errors.js";
|
|
6
4
|
/**
|
|
7
5
|
* ssz_snappy encoding strategy writer.
|
|
8
6
|
* Yields byte chunks for encoded header and payload as defined in the spec:
|
|
@@ -10,9 +8,8 @@ import { SszSnappyError, SszSnappyErrorCode } from "./errors.js";
|
|
|
10
8
|
* <encoding-dependent-header> | <encoded-payload>
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
13
|
-
export async function* writeSszSnappyPayload(
|
|
14
|
-
|
|
15
|
-
yield* encodeSszSnappy(serializedBody);
|
|
11
|
+
export async function* writeSszSnappyPayload(bodyData) {
|
|
12
|
+
yield* encodeSszSnappy(bodyData);
|
|
16
13
|
}
|
|
17
14
|
/**
|
|
18
15
|
* Buffered Snappy writer
|
|
@@ -35,22 +32,4 @@ export async function* encodeSszSnappy(bytes) {
|
|
|
35
32
|
stream.end();
|
|
36
33
|
yield* source(stream);
|
|
37
34
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Returns SSZ serialized body. Wrapps errors with SszSnappyError.SERIALIZE_ERROR
|
|
40
|
-
*/
|
|
41
|
-
function serializeSszBody(chunk, type) {
|
|
42
|
-
switch (chunk.type) {
|
|
43
|
-
case EncodedPayloadType.bytes:
|
|
44
|
-
return chunk.bytes;
|
|
45
|
-
case EncodedPayloadType.ssz: {
|
|
46
|
-
try {
|
|
47
|
-
const bytes = type.serialize(chunk.data);
|
|
48
|
-
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
throw new SszSnappyError({ code: SszSnappyErrorCode.SERIALIZE_ERROR, serializeError: e });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
35
|
//# sourceMappingURL=encode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/encodingStrategies/sszSnappy/encode.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,MAAM,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/encodingStrategies/sszSnappy/encode.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAAC,QAAoB;IAC/D,KAAK,CAAC,CAAC,eAAe,CAAC,QAAkB,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,eAAe,CAAC,KAAa;IAClD,sFAAsF;IACtF,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/C,wFAAwF;IACxF,kFAAkF;IAElF;;;;;;;OAOG;IACH,MAAM,MAAM,GAAG,MAAM,CAAC,oBAAoB,EAAE,CAAC;IAC7C,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpB,MAAM,CAAC,GAAG,EAAE,CAAC;IACb,KAAK,CAAC,CAAC,MAAM,CAAS,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { ReqResp } from "./ReqResp.js";
|
|
1
|
+
export { ReqResp, ReqRespOpts } from "./ReqResp.js";
|
|
2
2
|
export { getMetrics, Metrics, MetricsRegister } from "./metrics.js";
|
|
3
3
|
export { Encoding as ReqRespEncoding } from "./types.js";
|
|
4
4
|
export * from "./types.js";
|
|
5
5
|
export * from "./interface.js";
|
|
6
6
|
export { ResponseErrorCode, ResponseError } from "./response/errors.js";
|
|
7
|
-
export { RequestErrorCode, RequestError
|
|
7
|
+
export { RequestErrorCode, RequestError } from "./request/errors.js";
|
|
8
8
|
export { collectExactOne, collectMaxResponse, formatProtocolID, parseProtocolID } from "./utils/index.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAc,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,UAAU,EAA2B,MAAM,cAAc,CAAC;AAClE,OAAO,EAAC,QAAQ,IAAI,eAAe,EAAC,MAAM,YAAY,CAAC,CAAC,uBAAuB;AAC/E,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAC,gBAAgB,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAC,eAAe,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -12,7 +12,7 @@ export declare class ReqRespRateLimiter {
|
|
|
12
12
|
private lastSeenRequestsByPeer;
|
|
13
13
|
constructor(opts?: ReqRespRateLimiterOpts | undefined);
|
|
14
14
|
get enabled(): boolean;
|
|
15
|
-
initRateLimits
|
|
15
|
+
initRateLimits(protocolID: ProtocolID, rateLimits: InboundRateLimitQuota): void;
|
|
16
16
|
allows(peerId: PeerId, protocolID: string, requestCount: number): boolean;
|
|
17
17
|
prune(peerId: PeerId): void;
|
|
18
18
|
start(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReqRespRateLimiter.js","sourceRoot":"","sources":["../../src/rate_limiter/ReqRespRateLimiter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAErD,0GAA0G;AAC1G,MAAM,oCAAoC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5D,oEAAoE;AACpE,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAI9C,MAAM,OAAO,kBAAkB;IAS7B,YAA6B,IAA6B;;QAA7B,SAAI,GAAJ,IAAI,CAAyB;QARzC,wBAAmB,GAAG,IAAI,GAAG,EAAuC,CAAC;QACrE,sBAAiB,GAAG,IAAI,GAAG,EAAqC,CAAC;QAClF,+CAA+C;QACvC,oBAAe,GAA+B,SAAS,C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