@optimystic/db-p2p 0.16.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cluster/block-transfer-service.d.ts +4 -1
- package/dist/src/cluster/block-transfer-service.d.ts.map +1 -1
- package/dist/src/cluster/block-transfer-service.js +11 -3
- package/dist/src/cluster/block-transfer-service.js.map +1 -1
- package/dist/src/cluster/cluster-repo.d.ts +6 -2
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +28 -4
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/cluster/quorum-restore.d.ts +42 -14
- package/dist/src/cluster/quorum-restore.d.ts.map +1 -1
- package/dist/src/cluster/quorum-restore.js +0 -0
- package/dist/src/cluster/quorum-restore.js.map +1 -1
- package/dist/src/cluster/reconcile-block.d.ts +52 -0
- package/dist/src/cluster/reconcile-block.d.ts.map +1 -0
- package/dist/src/cluster/reconcile-block.js +113 -0
- package/dist/src/cluster/reconcile-block.js.map +1 -0
- package/dist/src/cluster/service.d.ts +4 -1
- package/dist/src/cluster/service.d.ts.map +1 -1
- package/dist/src/cluster/service.js +9 -1
- package/dist/src/cluster/service.js.map +1 -1
- package/dist/src/inbound-authorization.d.ts +111 -0
- package/dist/src/inbound-authorization.d.ts.map +1 -0
- package/dist/src/inbound-authorization.js +143 -0
- package/dist/src/inbound-authorization.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p-node-base.d.ts +42 -0
- package/dist/src/libp2p-node-base.d.ts.map +1 -1
- package/dist/src/libp2p-node-base.js +43 -68
- package/dist/src/libp2p-node-base.js.map +1 -1
- package/dist/src/repo/coordinator-repo.d.ts +83 -10
- package/dist/src/repo/coordinator-repo.d.ts.map +1 -1
- package/dist/src/repo/coordinator-repo.js +176 -24
- package/dist/src/repo/coordinator-repo.js.map +1 -1
- package/dist/src/repo/service.d.ts +4 -1
- package/dist/src/repo/service.d.ts.map +1 -1
- package/dist/src/repo/service.js +9 -1
- package/dist/src/repo/service.js.map +1 -1
- package/dist/src/storage/block-storage.d.ts.map +1 -1
- package/dist/src/storage/block-storage.js +11 -0
- package/dist/src/storage/block-storage.js.map +1 -1
- package/dist/src/storage/storage-repo.d.ts +47 -0
- package/dist/src/storage/storage-repo.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.js +99 -9
- package/dist/src/storage/storage-repo.js.map +1 -1
- package/dist/src/sync/service.d.ts +4 -7
- package/dist/src/sync/service.d.ts.map +1 -1
- package/dist/src/sync/service.js +13 -10
- package/dist/src/sync/service.js.map +1 -1
- package/dist/src/testing/mesh-harness.d.ts.map +1 -1
- package/dist/src/testing/mesh-harness.js +41 -48
- package/dist/src/testing/mesh-harness.js.map +1 -1
- package/package.json +2 -2
- package/{README.md → readme.md} +17 -0
- package/src/cluster/block-transfer-service.ts +12 -5
- package/src/cluster/cluster-repo.ts +28 -4
- package/src/cluster/quorum-restore.ts +0 -0
- package/src/cluster/reconcile-block.ts +158 -0
- package/src/cluster/service.ts +10 -3
- package/src/inbound-authorization.ts +184 -0
- package/src/index.ts +1 -0
- package/src/libp2p-node-base.ts +90 -72
- package/src/repo/coordinator-repo.ts +224 -25
- package/src/repo/service.ts +10 -3
- package/src/storage/block-storage.ts +11 -0
- package/src/storage/storage-repo.ts +114 -9
- package/src/sync/service.ts +14 -12
- package/src/testing/mesh-harness.ts +40 -48
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ActionRev, BlockId, IBlock } from "@optimystic/db-core";
|
|
2
|
+
import type { BlockArchive } from "../storage/struct.js";
|
|
3
|
+
import type { ReconcileBlockCallback } from "./cluster-repo.js";
|
|
4
|
+
import type { IPeerReputation } from "../reputation/types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Wall-clock bound on one whole reconcile pass (all cohort peers, both quorums, the persist).
|
|
7
|
+
* Shared by both callers so a slow or unreachable cohort peer stalls neither the commit path
|
|
8
|
+
* (`ClusterMember.withReconcileTimeout` — a stall there holds up consensus execution) nor the read
|
|
9
|
+
* path (`CoordinatorRepo.restoreCorroborated` — a stall there holds up a caller's `get`).
|
|
10
|
+
*/
|
|
11
|
+
export declare const RECONCILE_TIMEOUT_MS = 5000;
|
|
12
|
+
/** Collaborators {@link createReconcileBlock} needs, injected so the logic stays transport-agnostic. */
|
|
13
|
+
export interface ReconcileBlockDeps {
|
|
14
|
+
/** This node's own peer id; excluded from the cohort targets. */
|
|
15
|
+
selfPeerId: string;
|
|
16
|
+
/** Fetch one cohort peer's archive for `blockId` — `undefined` when it is unreachable or holds nothing. */
|
|
17
|
+
fetchArchive: (peerId: string, blockId: BlockId) => Promise<BlockArchive | undefined>;
|
|
18
|
+
/** Persist the agreed content through the churn-replication funnel. */
|
|
19
|
+
saveReplicatedBlock: (blockId: BlockId, block: IBlock, source: ActionRev) => Promise<void>;
|
|
20
|
+
/** Proportional corroboration threshold; the cohort's `simpleMajorityThreshold`. */
|
|
21
|
+
simpleMajorityThreshold: number;
|
|
22
|
+
/** Configured full cluster size — the floor for {@link corroboratorCapacity}. */
|
|
23
|
+
clusterSize: number;
|
|
24
|
+
/** Best-effort misbehavior reporting; a throwing implementation is swallowed. */
|
|
25
|
+
reputation?: Pick<IPeerReputation, 'reportPeer'>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Active reconciliation for a block this member committed without a materializable base
|
|
29
|
+
* (cohort drift between the independent pend and commit cluster-transactions, or a refused
|
|
30
|
+
* `missing-base-revision` commit). Queries the commit cohort — self already excluded by
|
|
31
|
+
* `ClusterMember.reconcileDivergentCommit` — for the block, picks the target revision by quorum
|
|
32
|
+
* corroboration rather than raw `Math.max` (a lone peer inflating its rev cannot steer
|
|
33
|
+
* reconciliation), verifies the cohort agrees on the *content* at that revision, and persists it.
|
|
34
|
+
*
|
|
35
|
+
* Both quorums are capped by {@link corroboratorCapacity}: demanding two corroborators from a
|
|
36
|
+
* cohort that contains exactly one other peer is a permanent deadlock, not a safety property —
|
|
37
|
+
* the node can never heal and stays unreadable forever.
|
|
38
|
+
*
|
|
39
|
+
* **Exposure at capacity 1 (documented, not accidental).** Block ids are random 256-bit strings
|
|
40
|
+
* (`db-core` `structs.ts`), NOT content-addressed, so nothing on the receive path can re-derive
|
|
41
|
+
* the id from the bytes: `canonicalBlockHash` is a cross-peer *agreement* hash, never a check
|
|
42
|
+
* against `blockId`. A sole cohort peer's content is therefore believed on its word. That adds no
|
|
43
|
+
* trust the cohort had not already extended — the same peer's `(rev, actionId)` claim is likewise
|
|
44
|
+
* uncorroborable at that size (see `selectQuorumRev`'s capacity note), and a two-member cohort has
|
|
45
|
+
* no honest majority to appeal to in the first place. Closing it needs commit-cert verification,
|
|
46
|
+
* tracked by backlog `debt-read-repair-commit-cert-verification`.
|
|
47
|
+
*
|
|
48
|
+
* Declines are cheap and retryable: nothing is persisted, nothing is marked, and the next commit
|
|
49
|
+
* or churn/rebalance pass tries again.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createReconcileBlock(deps: ReconcileBlockDeps): ReconcileBlockCallback;
|
|
52
|
+
//# sourceMappingURL=reconcile-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconcile-block.d.ts","sourceRoot":"","sources":["../../../src/cluster/reconcile-block.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAU9D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAWzC,wGAAwG;AACxG,MAAM,WAAW,kBAAkB;IAClC,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,2GAA2G;IAC3G,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAAC;IACtF,uEAAuE;IACvE,mBAAmB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3F,oFAAoF;IACpF,uBAAuB,EAAE,MAAM,CAAC;IAChC,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,UAAU,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;CACjD;AA0DD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,kBAAkB,GAAG,sBAAsB,CA+BrF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { PenaltyReason } from "../reputation/types.js";
|
|
2
|
+
import { selectQuorumRev, selectQuorumBlock, canonicalBlockHash } from "./quorum-restore.js";
|
|
3
|
+
import { createLogger } from '../logger.js';
|
|
4
|
+
const log = createLogger('reconcile-block');
|
|
5
|
+
/**
|
|
6
|
+
* Wall-clock bound on one whole reconcile pass (all cohort peers, both quorums, the persist).
|
|
7
|
+
* Shared by both callers so a slow or unreachable cohort peer stalls neither the commit path
|
|
8
|
+
* (`ClusterMember.withReconcileTimeout` — a stall there holds up consensus execution) nor the read
|
|
9
|
+
* path (`CoordinatorRepo.restoreCorroborated` — a stall there holds up a caller's `get`).
|
|
10
|
+
*/
|
|
11
|
+
export const RECONCILE_TIMEOUT_MS = 5000;
|
|
12
|
+
/**
|
|
13
|
+
* How many peers other than this node could answer for the block at all. Mirrors
|
|
14
|
+
* `CoordinatorRepo.corroboratorCapacity` exactly, and for the same reason: the corroboration
|
|
15
|
+
* floor may be relaxed only for a cohort that is *genuinely* small, never for one that merely
|
|
16
|
+
* looks small. `cohortPeerIds` come from the (untrusted) coordinator-declared peer set, so a
|
|
17
|
+
* self-shrunk record could otherwise talk the requirement down to a single voter; taking the MAX
|
|
18
|
+
* against the configured `clusterSize` keeps that shrunken view out of the relaxed branch. The
|
|
19
|
+
* escape hatch for a real two-node deployment is to configure `clusterSize: 2`.
|
|
20
|
+
*/
|
|
21
|
+
function corroboratorCapacity(targets, clusterSize) {
|
|
22
|
+
return Math.max(targets.length, clusterSize - 1);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The claim a peer's archive makes: its highest revision, provided that revision is at least the
|
|
26
|
+
* one we committed. `undefined` when the peer served nothing usable (unreachable, empty archive,
|
|
27
|
+
* or only revisions older than the commit we are healing).
|
|
28
|
+
*/
|
|
29
|
+
function toCandidate(peerId, archive, committedRev) {
|
|
30
|
+
if (!archive)
|
|
31
|
+
return undefined;
|
|
32
|
+
const revs = Object.keys(archive.revisions).map(Number);
|
|
33
|
+
if (revs.length === 0)
|
|
34
|
+
return undefined;
|
|
35
|
+
const maxRev = Math.max(...revs);
|
|
36
|
+
if (maxRev < committedRev)
|
|
37
|
+
return undefined;
|
|
38
|
+
const data = archive.revisions[maxRev];
|
|
39
|
+
if (!data?.action)
|
|
40
|
+
return undefined;
|
|
41
|
+
return { peerId, rev: maxRev, actionId: data.action.actionId, block: data.block };
|
|
42
|
+
}
|
|
43
|
+
/** Hash the block bytes of every candidate that both corroborates `selected` and actually carried content. */
|
|
44
|
+
async function hashCarriers(candidates, selected) {
|
|
45
|
+
const carriers = candidates.filter(c => c.rev === selected.rev && c.actionId === selected.actionId && c.block);
|
|
46
|
+
return await Promise.all(carriers.map(async (c) => ({ peerId: c.peerId, hash: await canonicalBlockHash(c.block), block: c.block })));
|
|
47
|
+
}
|
|
48
|
+
/** Report cohort members that served content contradicting the agreed hash. Best-effort; never throws. */
|
|
49
|
+
function penalizeContradictingContent(reputation, candidates, agreedHash, blockId) {
|
|
50
|
+
if (!reputation)
|
|
51
|
+
return;
|
|
52
|
+
try {
|
|
53
|
+
for (const c of candidates) {
|
|
54
|
+
if (c.hash !== agreedHash) {
|
|
55
|
+
reputation.reportPeer(c.peerId, PenaltyReason.InvalidRestoration, `reconcile:${blockId}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
log('reconcile:penalize-error', { blockId, error: err.message });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Active reconciliation for a block this member committed without a materializable base
|
|
65
|
+
* (cohort drift between the independent pend and commit cluster-transactions, or a refused
|
|
66
|
+
* `missing-base-revision` commit). Queries the commit cohort — self already excluded by
|
|
67
|
+
* `ClusterMember.reconcileDivergentCommit` — for the block, picks the target revision by quorum
|
|
68
|
+
* corroboration rather than raw `Math.max` (a lone peer inflating its rev cannot steer
|
|
69
|
+
* reconciliation), verifies the cohort agrees on the *content* at that revision, and persists it.
|
|
70
|
+
*
|
|
71
|
+
* Both quorums are capped by {@link corroboratorCapacity}: demanding two corroborators from a
|
|
72
|
+
* cohort that contains exactly one other peer is a permanent deadlock, not a safety property —
|
|
73
|
+
* the node can never heal and stays unreadable forever.
|
|
74
|
+
*
|
|
75
|
+
* **Exposure at capacity 1 (documented, not accidental).** Block ids are random 256-bit strings
|
|
76
|
+
* (`db-core` `structs.ts`), NOT content-addressed, so nothing on the receive path can re-derive
|
|
77
|
+
* the id from the bytes: `canonicalBlockHash` is a cross-peer *agreement* hash, never a check
|
|
78
|
+
* against `blockId`. A sole cohort peer's content is therefore believed on its word. That adds no
|
|
79
|
+
* trust the cohort had not already extended — the same peer's `(rev, actionId)` claim is likewise
|
|
80
|
+
* uncorroborable at that size (see `selectQuorumRev`'s capacity note), and a two-member cohort has
|
|
81
|
+
* no honest majority to appeal to in the first place. Closing it needs commit-cert verification,
|
|
82
|
+
* tracked by backlog `debt-read-repair-commit-cert-verification`.
|
|
83
|
+
*
|
|
84
|
+
* Declines are cheap and retryable: nothing is persisted, nothing is marked, and the next commit
|
|
85
|
+
* or churn/rebalance pass tries again.
|
|
86
|
+
*/
|
|
87
|
+
export function createReconcileBlock(deps) {
|
|
88
|
+
return async (blockId, committed, cohortPeerIds) => {
|
|
89
|
+
const targets = cohortPeerIds.filter(id => id !== deps.selfPeerId);
|
|
90
|
+
if (targets.length === 0)
|
|
91
|
+
return;
|
|
92
|
+
const fetched = await Promise.all(targets.map(async (peerId) => toCandidate(peerId, await deps.fetchArchive(peerId, blockId), committed.rev)));
|
|
93
|
+
const candidates = fetched.filter((c) => c !== undefined);
|
|
94
|
+
const capacity = corroboratorCapacity(targets, deps.clusterSize);
|
|
95
|
+
const revClaims = candidates.map(({ peerId, rev, actionId }) => ({ peerId, rev, actionId }));
|
|
96
|
+
const selected = selectQuorumRev(revClaims, deps.simpleMajorityThreshold, capacity);
|
|
97
|
+
if (!selected) {
|
|
98
|
+
// Leave the block behind; churn/rebalance and the next commit retry.
|
|
99
|
+
log('reconcile:no-rev-quorum', { blockId, rev: committed.rev, responders: revClaims.length, capacity });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const hashCandidates = await hashCarriers(candidates, selected);
|
|
103
|
+
const agreed = selectQuorumBlock(hashCandidates, deps.simpleMajorityThreshold, capacity);
|
|
104
|
+
if (!agreed) {
|
|
105
|
+
log('reconcile:no-content-quorum', { blockId, rev: selected.rev, carriers: hashCandidates.length, capacity });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
penalizeContradictingContent(deps.reputation, hashCandidates, agreed.hash, blockId);
|
|
109
|
+
await deps.saveReplicatedBlock(blockId, agreed.block, { actionId: selected.actionId, rev: selected.rev });
|
|
110
|
+
log('reconcile:restored', { blockId, rev: selected.rev, actionId: selected.actionId });
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=reconcile-block.js.map
|
|
@@ -0,0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,CAAC;QAChE,MAAM,MAAM,GAAG,iBAAiB,CAAC,cAAc,EAAE,IAAI,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;QACzF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,GAAG,CAAC,6BAA6B,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC9G,OAAO;QACR,CAAC;QAED,4BAA4B,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEpF,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1G,GAAG,CAAC,oBAAoB,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IACxF,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Startable, Logger, StreamHandler, PeerId } from '@libp2p/interface';
|
|
2
2
|
import type { ICluster, ClusterRecord } from '@optimystic/db-core';
|
|
3
3
|
import { type RedirectPayload } from '../repo/redirect.js';
|
|
4
|
+
import { type InboundStreamAuthorizationInit } from '../inbound-authorization.js';
|
|
4
5
|
interface BaseComponents {
|
|
5
6
|
logger: {
|
|
6
7
|
forComponent: (name: string) => Logger;
|
|
@@ -24,7 +25,7 @@ export interface ClusterServiceComponents extends BaseComponents {
|
|
|
24
25
|
*/
|
|
25
26
|
getConnectionAddrs?: (peerId: PeerId) => string[];
|
|
26
27
|
}
|
|
27
|
-
export interface ClusterServiceInit {
|
|
28
|
+
export interface ClusterServiceInit extends InboundStreamAuthorizationInit {
|
|
28
29
|
protocol?: string;
|
|
29
30
|
protocolPrefix?: string;
|
|
30
31
|
maxInboundStreams?: number;
|
|
@@ -54,6 +55,8 @@ export declare class ClusterService implements Startable {
|
|
|
54
55
|
private running;
|
|
55
56
|
/** Responsibility K - small-mesh bypass threshold for redirect decisions */
|
|
56
57
|
private readonly responsibilityK;
|
|
58
|
+
/** Optional embedder authorization gate; `undefined` (the default) means no check runs. */
|
|
59
|
+
private readonly authorization;
|
|
57
60
|
constructor(components: ClusterServiceComponents, init?: ClusterServiceInit);
|
|
58
61
|
readonly [Symbol.toStringTag] = "@libp2p/cluster";
|
|
59
62
|
private getSelfId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/cluster/service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAsB,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/cluster/service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAsB,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtG,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAIxE,OAAO,EAAqE,KAAK,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAErJ,UAAU,cAAc;IACvB,MAAM,EAAE;QAAE,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,CAAC;IACnD,SAAS,EAAE;QAC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,2FAA2F;IAC3F,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyC;gBAE3D,UAAU,EAAE,wBAAwB,EAAE,IAAI,GAAE,kBAAuB;IAY/E,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,qBAAqB;IAElD,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,YAAY;IAmBpB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,eAAe,GAAG,IAAI;IAwBtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAatB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B;;;;;OAKG;YACW,gBAAgB;IAU9B,OAAO,CAAC,oBAAoB;CAsD5B"}
|
|
@@ -4,6 +4,7 @@ import { peerIdFromString } from '@libp2p/peer-id';
|
|
|
4
4
|
import { encodePeers } from '../repo/redirect.js';
|
|
5
5
|
import { toClusterErrorEnvelope } from './cluster-error.js';
|
|
6
6
|
import { MAX_CONTROL_MESSAGE_BYTES } from '../protocol-limits.js';
|
|
7
|
+
import { createInboundStreamAuthorization } from '../inbound-authorization.js';
|
|
7
8
|
export function clusterService(init = {}) {
|
|
8
9
|
return (components) => new ClusterService(components, init);
|
|
9
10
|
}
|
|
@@ -20,6 +21,8 @@ export class ClusterService {
|
|
|
20
21
|
running;
|
|
21
22
|
/** Responsibility K - small-mesh bypass threshold for redirect decisions */
|
|
22
23
|
responsibilityK;
|
|
24
|
+
/** Optional embedder authorization gate; `undefined` (the default) means no check runs. */
|
|
25
|
+
authorization;
|
|
23
26
|
constructor(components, init = {}) {
|
|
24
27
|
this.components = components;
|
|
25
28
|
this.protocol = init.protocol ?? (init.protocolPrefix ?? '/db-p2p') + '/cluster/1.0.0';
|
|
@@ -29,6 +32,7 @@ export class ClusterService {
|
|
|
29
32
|
this.cluster = components.cluster;
|
|
30
33
|
this.running = false;
|
|
31
34
|
this.responsibilityK = init.responsibilityK ?? 1;
|
|
35
|
+
this.authorization = createInboundStreamAuthorization(init, this.protocol, (msg, ...args) => this.log.error(msg, ...args));
|
|
32
36
|
}
|
|
33
37
|
[Symbol.toStringTag] = '@libp2p/cluster';
|
|
34
38
|
getSelfId() {
|
|
@@ -127,7 +131,7 @@ export class ClusterService {
|
|
|
127
131
|
throw new Error(`Unknown operation: ${message.operation}`);
|
|
128
132
|
}
|
|
129
133
|
handleIncomingStream(stream, connection) {
|
|
130
|
-
const peerId = connection
|
|
134
|
+
const peerId = connection?.remotePeer;
|
|
131
135
|
const processStream = async function* (source) {
|
|
132
136
|
for await (const msg of source) {
|
|
133
137
|
// Decode the framing. A malformed/undecodable message is a transport
|
|
@@ -158,6 +162,10 @@ export class ClusterService {
|
|
|
158
162
|
};
|
|
159
163
|
void (async () => {
|
|
160
164
|
try {
|
|
165
|
+
// Authorization runs before ANY decoding or execution. Guarded on the field so a
|
|
166
|
+
// node without a predicate keeps the original path untouched.
|
|
167
|
+
if (this.authorization && await this.authorization.deny(stream, peerId?.toString()))
|
|
168
|
+
return;
|
|
161
169
|
const responses = pipe(stream, (source) => lpDecode(source, { maxDataLength: MAX_CONTROL_MESSAGE_BYTES }), processStream.bind(this), (source) => lpEncode(source));
|
|
162
170
|
for await (const chunk of responses) {
|
|
163
171
|
stream.send(chunk);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/cluster/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAwB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAu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AC;oBAAE,OAAO;gBAC5F,MAAM,SAAS,GAAG,IAAI,CACrB,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,yBAAyB,EAAE,CAAC,EAC1E,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EACxB,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAC5B,CAAC;gBACF,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;oBACrC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;gBACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sDAAsD,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;gBACpF,MAAM,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACnE,CAAC;QACF,CAAC,CAAC,EAAE,CAAC;IACN,CAAC;CACD"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional, embedder-supplied authorization for inbound protocol streams.
|
|
3
|
+
*
|
|
4
|
+
* The `repo`, `cluster`, `sync` and `block-transfer` services otherwise go straight from
|
|
5
|
+
* "stream opened" to "decode and execute", so any peer that can open a connection can issue
|
|
6
|
+
* database operations. An application that owns a *private* database (only nodes it admitted
|
|
7
|
+
* may read or write) needs a seam ahead of decoding; this is that seam.
|
|
8
|
+
*
|
|
9
|
+
* Contract:
|
|
10
|
+
*
|
|
11
|
+
* - **Absent predicate → today's behavior exactly.** Every service holds
|
|
12
|
+
* `InboundStreamAuthorization | undefined`; when it is `undefined` the handler never
|
|
13
|
+
* awaits anything extra and no code on this path runs.
|
|
14
|
+
* - **Supplied predicate → fail closed.** Only a literal `true` allows the stream. `false`,
|
|
15
|
+
* a throw, a rejection, a timeout, or an unidentifiable remote peer all deny, and denial
|
|
16
|
+
* aborts the stream *before* any frame is decoded or any operation executed.
|
|
17
|
+
* - **Called once per inbound stream**, not once per operation — which is equivalent here
|
|
18
|
+
* because all four protocols are strictly one request per stream (each handler's generator
|
|
19
|
+
* `return`s after the first response, so a second queued frame is never read).
|
|
20
|
+
* - **Peer id encoding**: the predicate receives `connection.remotePeer.toString()` — the
|
|
21
|
+
* libp2p base58btc/CIDv1 peer-id string (e.g. `12D3KooW…`), the same form
|
|
22
|
+
* `PeerId.toString()` produces everywhere else in this codebase. Compare against that,
|
|
23
|
+
* never against a multiaddr, a public-key hash, or a base64 encoding.
|
|
24
|
+
* - **What a caller observes**: a stream reset. Denial is deliberately *not* reported on the
|
|
25
|
+
* wire — telling an unauthorized peer "you are not a member" confirms membership state to
|
|
26
|
+
* exactly the party the embedder decided not to trust, and the four protocols have four
|
|
27
|
+
* different response shapes with no common error frame. The denial is instead loud on the
|
|
28
|
+
* *denying* node: it is logged with the peer id, protocol and reason, and the stream is
|
|
29
|
+
* aborted with an {@link UnauthorizedInboundStreamError} carrying
|
|
30
|
+
* {@link INBOUND_STREAM_UNAUTHORIZED_CODE}, so local diagnostics can tell a denial apart
|
|
31
|
+
* from a transport fault.
|
|
32
|
+
* - **Cost**: the predicate sits in the hot path of every inbound stream, ahead of the work
|
|
33
|
+
* that stream would do. Embedders are expected to make it cheap — an in-memory set lookup —
|
|
34
|
+
* and to memoize anything that would otherwise hit storage or the network per stream.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Predicate deciding whether `remotePeerId` may open `protocol` on this node.
|
|
38
|
+
*
|
|
39
|
+
* @param remotePeerId the dialing peer's `PeerId.toString()` (base58btc / CIDv1, `12D3KooW…`)
|
|
40
|
+
* @param protocol the full protocol id the stream was opened on, e.g.
|
|
41
|
+
* `/optimystic/<network>/repo/1.0.0`
|
|
42
|
+
* @returns `true` to allow. Anything else — `false`, a throw, or a rejection — denies.
|
|
43
|
+
*/
|
|
44
|
+
export type AuthorizeInboundStream = (remotePeerId: string, protocol: string) => Promise<boolean> | boolean;
|
|
45
|
+
/** Stable error code carried by {@link UnauthorizedInboundStreamError}. */
|
|
46
|
+
export declare const INBOUND_STREAM_UNAUTHORIZED_CODE = "ERR_INBOUND_STREAM_UNAUTHORIZED";
|
|
47
|
+
/**
|
|
48
|
+
* The reason an inbound stream was aborted by the authorization gate. Distinct from a
|
|
49
|
+
* transport fault so the denying node's logs and any local abort-reason inspection can tell
|
|
50
|
+
* the two apart; the remote only ever sees the stream reset (see the module doc).
|
|
51
|
+
*/
|
|
52
|
+
export declare class UnauthorizedInboundStreamError extends Error {
|
|
53
|
+
readonly code = "ERR_INBOUND_STREAM_UNAUTHORIZED";
|
|
54
|
+
constructor(remotePeerId: string, protocol: string, reason: string);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* How long the predicate may take before the stream is denied. A hanging predicate would
|
|
58
|
+
* otherwise pin an inbound stream slot indefinitely; timing out is the fail-closed reading of
|
|
59
|
+
* "we could not establish that this peer is allowed".
|
|
60
|
+
*/
|
|
61
|
+
export declare const DEFAULT_INBOUND_AUTHORIZATION_TIMEOUT_MS = 5000;
|
|
62
|
+
/** The slice of a service's init that configures this gate. Mixed into all four service inits. */
|
|
63
|
+
export interface InboundStreamAuthorizationInit {
|
|
64
|
+
/**
|
|
65
|
+
* Optional predicate consulted once per inbound stream, before any decoding or execution.
|
|
66
|
+
* Absent → no check at all. See {@link AuthorizeInboundStream}.
|
|
67
|
+
*/
|
|
68
|
+
authorizeInboundStream?: AuthorizeInboundStream;
|
|
69
|
+
/**
|
|
70
|
+
* Deadline for {@link InboundStreamAuthorizationInit.authorizeInboundStream}; expiry denies
|
|
71
|
+
* the stream. Default {@link DEFAULT_INBOUND_AUTHORIZATION_TIMEOUT_MS}.
|
|
72
|
+
*/
|
|
73
|
+
authorizeInboundStreamTimeoutMs?: number;
|
|
74
|
+
}
|
|
75
|
+
/** The part of a libp2p `Stream` this gate needs: the ability to tear it down. */
|
|
76
|
+
interface AbortableStream {
|
|
77
|
+
abort: (err: Error) => void;
|
|
78
|
+
}
|
|
79
|
+
/** Log sink shape shared by the component loggers and the `debug` loggers the services use. */
|
|
80
|
+
export type AuthorizationLog = (message: string, ...args: unknown[]) => void;
|
|
81
|
+
/**
|
|
82
|
+
* A configured authorization gate for one service's protocol. Constructed only when the
|
|
83
|
+
* embedder supplied a predicate, so a service holding `undefined` runs the original code path.
|
|
84
|
+
*/
|
|
85
|
+
export declare class InboundStreamAuthorization {
|
|
86
|
+
private readonly authorize;
|
|
87
|
+
private readonly protocol;
|
|
88
|
+
private readonly timeoutMs;
|
|
89
|
+
private readonly log;
|
|
90
|
+
constructor(authorize: AuthorizeInboundStream, protocol: string, timeoutMs: number, log: AuthorizationLog);
|
|
91
|
+
/**
|
|
92
|
+
* Consult the predicate for one inbound stream and abort the stream if it is not allowed.
|
|
93
|
+
*
|
|
94
|
+
* @returns `true` when the stream was denied — the caller must return immediately without
|
|
95
|
+
* decoding anything — and `false` when it may proceed.
|
|
96
|
+
*/
|
|
97
|
+
deny(stream: AbortableStream, remotePeerId: string | undefined): Promise<boolean>;
|
|
98
|
+
/** Run the predicate under its deadline, converting every failure mode into a denial. */
|
|
99
|
+
private decide;
|
|
100
|
+
/** Log the denial and tear the stream down. Always returns `true` (denied). */
|
|
101
|
+
private abort;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Build the gate for a service, or `undefined` when the embedder supplied no predicate.
|
|
105
|
+
*
|
|
106
|
+
* Returning `undefined` (rather than an always-allow gate) is what makes the absent-predicate
|
|
107
|
+
* case genuinely free: the call site guards on the field and never awaits.
|
|
108
|
+
*/
|
|
109
|
+
export declare function createInboundStreamAuthorization(init: InboundStreamAuthorizationInit, protocol: string, log: AuthorizationLog): InboundStreamAuthorization | undefined;
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=inbound-authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound-authorization.d.ts","sourceRoot":"","sources":["../../src/inbound-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAE5G,2EAA2E;AAC3E,eAAO,MAAM,gCAAgC,oCAAoC,CAAC;AAElF;;;;GAIG;AACH,qBAAa,8BAA+B,SAAQ,KAAK;IACxD,QAAQ,CAAC,IAAI,qCAAoC;gBACrC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAIlE;AAED;;;;GAIG;AACH,eAAO,MAAM,wCAAwC,OAAQ,CAAC;AAE9D,kGAAkG;AAClG,MAAM,WAAW,8BAA8B;IAC9C;;;OAGG;IACH,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD;;;OAGG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAC;CACzC;AAED,kFAAkF;AAClF,UAAU,eAAe;IACxB,KAAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAC5B;AAED,+FAA+F;AAC/F,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAK7E;;;GAGG;AACH,qBAAa,0BAA0B;IAErC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAHH,SAAS,EAAE,sBAAsB,EACjC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,gBAAgB;IAGvC;;;;;OAKG;IACG,IAAI,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvF,yFAAyF;YAC3E,MAAM;IA0BpB,+EAA+E;IAC/E,OAAO,CAAC,KAAK;CAWb;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC/C,IAAI,EAAE,8BAA8B,EACpC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,gBAAgB,GACnB,0BAA0B,GAAG,SAAS,CAUxC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional, embedder-supplied authorization for inbound protocol streams.
|
|
3
|
+
*
|
|
4
|
+
* The `repo`, `cluster`, `sync` and `block-transfer` services otherwise go straight from
|
|
5
|
+
* "stream opened" to "decode and execute", so any peer that can open a connection can issue
|
|
6
|
+
* database operations. An application that owns a *private* database (only nodes it admitted
|
|
7
|
+
* may read or write) needs a seam ahead of decoding; this is that seam.
|
|
8
|
+
*
|
|
9
|
+
* Contract:
|
|
10
|
+
*
|
|
11
|
+
* - **Absent predicate → today's behavior exactly.** Every service holds
|
|
12
|
+
* `InboundStreamAuthorization | undefined`; when it is `undefined` the handler never
|
|
13
|
+
* awaits anything extra and no code on this path runs.
|
|
14
|
+
* - **Supplied predicate → fail closed.** Only a literal `true` allows the stream. `false`,
|
|
15
|
+
* a throw, a rejection, a timeout, or an unidentifiable remote peer all deny, and denial
|
|
16
|
+
* aborts the stream *before* any frame is decoded or any operation executed.
|
|
17
|
+
* - **Called once per inbound stream**, not once per operation — which is equivalent here
|
|
18
|
+
* because all four protocols are strictly one request per stream (each handler's generator
|
|
19
|
+
* `return`s after the first response, so a second queued frame is never read).
|
|
20
|
+
* - **Peer id encoding**: the predicate receives `connection.remotePeer.toString()` — the
|
|
21
|
+
* libp2p base58btc/CIDv1 peer-id string (e.g. `12D3KooW…`), the same form
|
|
22
|
+
* `PeerId.toString()` produces everywhere else in this codebase. Compare against that,
|
|
23
|
+
* never against a multiaddr, a public-key hash, or a base64 encoding.
|
|
24
|
+
* - **What a caller observes**: a stream reset. Denial is deliberately *not* reported on the
|
|
25
|
+
* wire — telling an unauthorized peer "you are not a member" confirms membership state to
|
|
26
|
+
* exactly the party the embedder decided not to trust, and the four protocols have four
|
|
27
|
+
* different response shapes with no common error frame. The denial is instead loud on the
|
|
28
|
+
* *denying* node: it is logged with the peer id, protocol and reason, and the stream is
|
|
29
|
+
* aborted with an {@link UnauthorizedInboundStreamError} carrying
|
|
30
|
+
* {@link INBOUND_STREAM_UNAUTHORIZED_CODE}, so local diagnostics can tell a denial apart
|
|
31
|
+
* from a transport fault.
|
|
32
|
+
* - **Cost**: the predicate sits in the hot path of every inbound stream, ahead of the work
|
|
33
|
+
* that stream would do. Embedders are expected to make it cheap — an in-memory set lookup —
|
|
34
|
+
* and to memoize anything that would otherwise hit storage or the network per stream.
|
|
35
|
+
*/
|
|
36
|
+
/** Stable error code carried by {@link UnauthorizedInboundStreamError}. */
|
|
37
|
+
export const INBOUND_STREAM_UNAUTHORIZED_CODE = 'ERR_INBOUND_STREAM_UNAUTHORIZED';
|
|
38
|
+
/**
|
|
39
|
+
* The reason an inbound stream was aborted by the authorization gate. Distinct from a
|
|
40
|
+
* transport fault so the denying node's logs and any local abort-reason inspection can tell
|
|
41
|
+
* the two apart; the remote only ever sees the stream reset (see the module doc).
|
|
42
|
+
*/
|
|
43
|
+
export class UnauthorizedInboundStreamError extends Error {
|
|
44
|
+
code = INBOUND_STREAM_UNAUTHORIZED_CODE;
|
|
45
|
+
constructor(remotePeerId, protocol, reason) {
|
|
46
|
+
super(`inbound stream denied: peer=${remotePeerId} protocol=${protocol} reason=${reason}`);
|
|
47
|
+
this.name = 'UnauthorizedInboundStreamError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* How long the predicate may take before the stream is denied. A hanging predicate would
|
|
52
|
+
* otherwise pin an inbound stream slot indefinitely; timing out is the fail-closed reading of
|
|
53
|
+
* "we could not establish that this peer is allowed".
|
|
54
|
+
*/
|
|
55
|
+
export const DEFAULT_INBOUND_AUTHORIZATION_TIMEOUT_MS = 5_000;
|
|
56
|
+
/** Marker resolved by the deadline race when the predicate has not settled in time. */
|
|
57
|
+
const TIMED_OUT = Symbol('inbound-authorization-timeout');
|
|
58
|
+
/**
|
|
59
|
+
* A configured authorization gate for one service's protocol. Constructed only when the
|
|
60
|
+
* embedder supplied a predicate, so a service holding `undefined` runs the original code path.
|
|
61
|
+
*/
|
|
62
|
+
export class InboundStreamAuthorization {
|
|
63
|
+
authorize;
|
|
64
|
+
protocol;
|
|
65
|
+
timeoutMs;
|
|
66
|
+
log;
|
|
67
|
+
constructor(authorize, protocol, timeoutMs, log) {
|
|
68
|
+
this.authorize = authorize;
|
|
69
|
+
this.protocol = protocol;
|
|
70
|
+
this.timeoutMs = timeoutMs;
|
|
71
|
+
this.log = log;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Consult the predicate for one inbound stream and abort the stream if it is not allowed.
|
|
75
|
+
*
|
|
76
|
+
* @returns `true` when the stream was denied — the caller must return immediately without
|
|
77
|
+
* decoding anything — and `false` when it may proceed.
|
|
78
|
+
*/
|
|
79
|
+
async deny(stream, remotePeerId) {
|
|
80
|
+
// No identifiable remote → the predicate cannot be asked, so we cannot establish
|
|
81
|
+
// authorization. Fail closed rather than fall through to execution.
|
|
82
|
+
if (remotePeerId === undefined) {
|
|
83
|
+
return this.abort(stream, '<unidentified>', 'no remote peer id on the inbound connection');
|
|
84
|
+
}
|
|
85
|
+
const verdict = await this.decide(remotePeerId);
|
|
86
|
+
return verdict.allowed ? false : this.abort(stream, remotePeerId, verdict.reason);
|
|
87
|
+
}
|
|
88
|
+
/** Run the predicate under its deadline, converting every failure mode into a denial. */
|
|
89
|
+
async decide(remotePeerId) {
|
|
90
|
+
let timer;
|
|
91
|
+
try {
|
|
92
|
+
const verdict = this.authorize(remotePeerId, this.protocol);
|
|
93
|
+
// A synchronous predicate needs no timer at all.
|
|
94
|
+
if (typeof verdict === 'boolean') {
|
|
95
|
+
return verdict ? { allowed: true } : { allowed: false, reason: 'predicate returned false' };
|
|
96
|
+
}
|
|
97
|
+
const decision = await Promise.race([
|
|
98
|
+
verdict,
|
|
99
|
+
new Promise(resolve => { timer = setTimeout(() => resolve(TIMED_OUT), this.timeoutMs); })
|
|
100
|
+
]);
|
|
101
|
+
if (decision === TIMED_OUT) {
|
|
102
|
+
return { allowed: false, reason: `predicate did not settle within ${this.timeoutMs}ms` };
|
|
103
|
+
}
|
|
104
|
+
return decision === true ? { allowed: true } : { allowed: false, reason: 'predicate returned false' };
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// A throwing predicate is a bug in the embedder, not permission to proceed: log it
|
|
108
|
+
// (never swallow) and deny.
|
|
109
|
+
this.log('authorization predicate threw for peer=%s protocol=%s - %o', remotePeerId, this.protocol, err);
|
|
110
|
+
return { allowed: false, reason: `predicate threw: ${err instanceof Error ? err.message : String(err)}` };
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
if (timer !== undefined)
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Log the denial and tear the stream down. Always returns `true` (denied). */
|
|
118
|
+
abort(stream, remotePeerId, reason) {
|
|
119
|
+
const error = new UnauthorizedInboundStreamError(remotePeerId, this.protocol, reason);
|
|
120
|
+
this.log('inbound stream denied peer=%s protocol=%s reason=%s', remotePeerId, this.protocol, reason);
|
|
121
|
+
try {
|
|
122
|
+
stream.abort(error);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
// The stream may already be torn down; the denial itself still stands.
|
|
126
|
+
this.log('aborting a denied stream failed peer=%s protocol=%s - %o', remotePeerId, this.protocol, err);
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Build the gate for a service, or `undefined` when the embedder supplied no predicate.
|
|
133
|
+
*
|
|
134
|
+
* Returning `undefined` (rather than an always-allow gate) is what makes the absent-predicate
|
|
135
|
+
* case genuinely free: the call site guards on the field and never awaits.
|
|
136
|
+
*/
|
|
137
|
+
export function createInboundStreamAuthorization(init, protocol, log) {
|
|
138
|
+
if (init.authorizeInboundStream === undefined) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
return new InboundStreamAuthorization(init.authorizeInboundStream, protocol, init.authorizeInboundStreamTimeoutMs ?? DEFAULT_INBOUND_AUTHORIZATION_TIMEOUT_MS, log);
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=inbound-authorization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound-authorization.js","sourceRoot":"","sources":["../../src/inbound-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAYH,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gCAAgC,GAAG,iCAAiC,CAAC;AAElF;;;;GAIG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAC/C,IAAI,GAAG,gCAAgC,CAAC;IACjD,YAAY,YAAoB,EAAE,QAAgB,EAAE,MAAc;QACjE,KAAK,CAAC,+BAA+B,YAAY,aAAa,QAAQ,WAAW,MAAM,EAAE,CAAC,CAAC;QAC3F,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,KAAK,CAAC;AAwB9D,uFAAuF;AACvF,MAAM,SAAS,GAAG,MAAM,CAAC,+BAA+B,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,OAAO,0BAA0B;IAEpB;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,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,uEAAuE;YACvE,IAAI,CAAC,GAAG,CAAC,0DAA0D,EAAE,YAAY,EAAE,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACxG,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,IAAoC,EACpC,QAAgB,EAChB,GAAqB;IAErB,IAAI,IAAI,CAAC,sBAAsB,KAAK,SAAS,EAAE,CAAC;QAC/C,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,0BAA0B,CACpC,IAAI,CAAC,sBAAsB,EAC3B,QAAQ,EACR,IAAI,CAAC,+BAA+B,IAAI,wCAAwC,EAChF,GAAG,CACH,CAAC;AACH,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./cluster/rebalance-monitor.js";
|
|
|
6
6
|
export * from "./cluster/spread-on-churn.js";
|
|
7
7
|
export * from "./cluster/block-transfer.js";
|
|
8
8
|
export * from "./cluster/block-transfer-service.js";
|
|
9
|
+
export * from "./inbound-authorization.js";
|
|
9
10
|
export * from "./protocol-client.js";
|
|
10
11
|
export * from "./repo/client.js";
|
|
11
12
|
export * from "./repo/cluster-coordinator.js";
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA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AAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wCAAwC,CAAC;AACvD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./cluster/rebalance-monitor.js";
|
|
|
6
6
|
export * from "./cluster/spread-on-churn.js";
|
|
7
7
|
export * from "./cluster/block-transfer.js";
|
|
8
8
|
export * from "./cluster/block-transfer-service.js";
|
|
9
|
+
export * from "./inbound-authorization.js";
|
|
9
10
|
export * from "./protocol-client.js";
|
|
10
11
|
export * from "./repo/client.js";
|
|
11
12
|
export * from "./repo/cluster-coordinator.js";
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,kCAAkC,CAAC;AACjD,cAAc,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