Skip to content

Commit 3b0fd30

Browse files
author
Jurij Skornik
committed
Fix imported source markdown sharing
1 parent 185c4de commit 3b0fd30

21 files changed

Lines changed: 1703 additions & 41 deletions

packages/agent/src/dkg-agent-base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ import {
343343
type DKGAgentConfig,
344344
type ReplicationEvent,
345345
type SyncReconcilerBackoff,
346+
type ImportedSourceBlobStore,
346347
} from './dkg-agent-types.js';
347348
import {
348349
normalizePublishContextGraphId,
@@ -434,6 +435,7 @@ export class DKGAgentBase {
434435
/** Shared write locks so gossip writes serialize against local CAS writes. */
435436
protected readonly writeLocks: Map<string, Promise<void>>;
436437
protected readonly publicSnapshotStore?: WorkspacePublicSnapshotStore;
438+
protected importedSourceBlobStore?: ImportedSourceBlobStore;
437439
protected sharedMemoryHandler?: InstanceType<typeof SharedMemoryHandler>;
438440
protected gossipPublishHandler?: GossipPublishHandler;
439441
protected finalizationHandler?: FinalizationHandler;

packages/agent/src/dkg-agent-cg-resolve.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ export class ContextGraphResolveMethods extends DKGAgentBase {
477477
return {
478478
contextGraphId: parsed.contextGraphId,
479479
offset: parsed.offset ?? 0,
480-
limit: Math.min(parsed.limit ?? SYNC_PAGE_SIZE, SYNC_PAGE_SIZE),
480+
limit: parsed.limit ?? SYNC_PAGE_SIZE,
481481
includeSharedMemory: parsed.includeSharedMemory ?? false,
482482
phase: normalizeSyncPhase(parsed.phase),
483483
snapshotRef: typeof parsed.snapshotRef === 'string' ? parsed.snapshotRef : undefined,
@@ -489,6 +489,8 @@ export class ContextGraphResolveMethods extends DKGAgentBase {
489489
requesterAgentAddress: parsed.requesterAgentAddress,
490490
requesterSignatureR: parsed.requesterSignatureR,
491491
requesterSignatureVS: parsed.requesterSignatureVS,
492+
authPurpose: typeof parsed.authPurpose === 'string' ? parsed.authPurpose : undefined,
493+
authSelector: typeof parsed.authSelector === 'string' ? parsed.authSelector : undefined,
492494
// Phase C: unsigned delta hint. Validated/normalised in the responder.
493495
sinceBatchId: typeof parsed.sinceBatchId === 'string' ? parsed.sinceBatchId : undefined,
494496
};
@@ -644,27 +646,34 @@ export class ContextGraphResolveMethods extends DKGAgentBase {
644646
requestId: string | undefined,
645647
issuedAtMs: number | undefined,
646648
requesterAgentAddress: string | undefined,
649+
authPurpose?: string,
650+
authSelector?: string,
647651
): Uint8Array {
648652
// `requesterAgentAddress` participates in the digest so the
649653
// "on behalf of" claim is signed, not free-form envelope data.
650654
// Without it, the responder's delegation lookup can be steered by
651655
// tampering with `requesterAgentAddress` after the signature was
652656
// produced — which would be a way to bypass the per-agent
653657
// delegation binding in `request-authorize`.
658+
const baseTypes = ['string', 'uint256', 'uint256', 'bool', 'string', 'string', 'string', 'uint256', 'string'];
659+
const baseValues = [
660+
contextGraphId,
661+
BigInt(offset),
662+
BigInt(limit),
663+
includeSharedMemory,
664+
targetPeerId,
665+
requesterPeerId ?? '',
666+
requestId ?? '',
667+
BigInt(issuedAtMs ?? 0),
668+
(requesterAgentAddress ?? '').toLowerCase(),
669+
];
670+
if (!authPurpose && !authSelector) {
671+
return ethers.getBytes(ethers.solidityPackedKeccak256(baseTypes, baseValues));
672+
}
654673
return ethers.getBytes(
655674
ethers.solidityPackedKeccak256(
656-
['string', 'uint256', 'uint256', 'bool', 'string', 'string', 'string', 'uint256', 'string'],
657-
[
658-
contextGraphId,
659-
BigInt(offset),
660-
BigInt(limit),
661-
includeSharedMemory,
662-
targetPeerId,
663-
requesterPeerId ?? '',
664-
requestId ?? '',
665-
BigInt(issuedAtMs ?? 0),
666-
(requesterAgentAddress ?? '').toLowerCase(),
667-
],
675+
[...baseTypes, 'string', 'string'],
676+
[...baseValues, authPurpose ?? '', authSelector ?? ''],
668677
),
669678
);
670679
}

packages/agent/src/dkg-agent-lifecycle.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createHash, randomUUID } from 'node:crypto';
1212
import {
1313
DKGNode, ProtocolRouter, GossipSubManager, TypedEventBus, DKGEvent,
1414
LibP2PNetwork, PeerResolver, StubNetworkStateRegistry,
15-
PROTOCOL_ACCESS, PROTOCOL_PUBLISH, PROTOCOL_SYNC, PROTOCOL_QUERY_REMOTE, PROTOCOL_STORAGE_ACK, PROTOCOL_STORAGE_ACK_V2, PROTOCOL_STORAGE_UPDATE_ACK, PROTOCOL_GET_CIPHERTEXT_CHUNK, PROTOCOL_VERIFY_PROPOSAL, PROTOCOL_JOIN_REQUEST,
15+
PROTOCOL_ACCESS, PROTOCOL_PUBLISH, PROTOCOL_SYNC, PROTOCOL_QUERY_REMOTE, PROTOCOL_STORAGE_ACK, PROTOCOL_STORAGE_ACK_V2, PROTOCOL_STORAGE_UPDATE_ACK, PROTOCOL_GET_CIPHERTEXT_CHUNK, PROTOCOL_GET_IMPORTED_SOURCE_BLOB, PROTOCOL_VERIFY_PROPOSAL, PROTOCOL_JOIN_REQUEST,
1616
PROTOCOL_SWM_SENDER_KEY, PROTOCOL_SWM_UPDATE, PROTOCOL_SWM_SHARE_ACK, PROTOCOL_SWM_HOST_CATCHUP, PROTOCOL_MESSAGE,
1717
contextGraphPublishTopic, contextGraphWorkspaceTopic, contextGraphAppTopic, contextGraphUpdateTopic, contextGraphFinalizationTopic,
1818
contextGraphDataGraphUri, contextGraphMetaGraphUri, contextGraphWorkspaceGraphUri, contextGraphWorkspaceMetaGraphUri,
@@ -1553,6 +1553,14 @@ export class LifecycleSyncMethods extends DKGAgentBase {
15531553
logDebug: (ctx, message) => this.log.debug(ctx, message),
15541554
});
15551555

1556+
// Issue #872: imported Markdown source blobs can be larger than the
1557+
// Universal Messenger response cache, so serve them on the raw router
1558+
// like sync pages. The handler performs its own signed selector check.
1559+
this.router.register(
1560+
PROTOCOL_GET_IMPORTED_SOURCE_BLOB,
1561+
(data, peerIdObj) => this.handleGetImportedSourceBlob(data, peerIdObj.toString()),
1562+
);
1563+
15561564
// Join-request protocol: receives signed join requests forwarded by peers.
15571565
// Stores them locally if this node is the curator; ACKs with "ok" or "error".
15581566
// rc.9 PR-10: migrated onto the Universal Messenger substrate

packages/agent/src/dkg-agent-query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,10 @@ export class QueryMethods extends DKGAgentBase {
646646
opts: {
647647
callerAgentAddress?: string;
648648
allowSubscriptionFallback?: boolean;
649+
forcePrivatePolicy?: boolean;
649650
} = {},
650651
): Promise<boolean> {
651-
if (!(await this.isPrivateContextGraph(contextGraphId))) {
652+
if (!opts.forcePrivatePolicy && !(await this.isPrivateContextGraph(contextGraphId))) {
652653
return true;
653654
}
654655

0 commit comments

Comments
 (0)