@dxos/client-services 0.6.13 → 0.6.14-main.2b6a0f3
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/lib/browser/{chunk-CRXXOI45.mjs → chunk-BBLK6AUB.mjs} +6301 -5383
- package/dist/lib/browser/chunk-BBLK6AUB.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +320 -45
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +12 -7
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-PZ3JJJ3K.cjs → chunk-SJEDBF7U.cjs} +6286 -5378
- package/dist/lib/node/chunk-SJEDBF7U.cjs.map +7 -0
- package/dist/lib/node/index.cjs +369 -94
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -13
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-A6GS6OOD.mjs +8634 -0
- package/dist/lib/node-esm/chunk-A6GS6OOD.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +691 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +424 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +35 -0
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -0
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +10 -0
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -0
- package/dist/types/src/packlets/agents/index.d.ts +3 -0
- package/dist/types/src/packlets/agents/index.d.ts.map +1 -0
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts +2 -0
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +28 -9
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +18 -0
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/identity-service.d.ts +7 -2
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +12 -3
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +30 -0
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +2 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts +2 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts +19 -0
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -8
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +14 -9
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +2 -0
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +7 -3
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +5 -3
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +3 -0
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +2 -0
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +35 -6
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +1 -2
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/testing/setup.d.ts +3 -0
- package/dist/types/src/testing/setup.d.ts.map +1 -0
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/package.json +44 -39
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +163 -0
- package/src/packlets/agents/edge-agent-service.ts +42 -0
- package/src/packlets/agents/index.ts +6 -0
- package/src/packlets/devices/devices-service.test.ts +4 -5
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -0
- package/src/packlets/identity/{authenticator.test.ts → authenticator.node.test.ts} +2 -3
- package/src/packlets/identity/authenticator.ts +5 -2
- package/src/packlets/identity/contacts-service.ts +1 -1
- package/src/packlets/identity/identity-manager.test.ts +31 -16
- package/src/packlets/identity/identity-manager.ts +76 -32
- package/src/packlets/identity/identity-recovery-manager.ts +95 -0
- package/src/packlets/identity/identity-service.test.ts +5 -8
- package/src/packlets/identity/identity-service.ts +11 -5
- package/src/packlets/identity/identity.test.ts +130 -239
- package/src/packlets/identity/identity.ts +60 -17
- package/src/packlets/invitations/device-invitation-protocol.test.ts +7 -4
- package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
- package/src/packlets/invitations/edge-invitation-handler.ts +185 -0
- package/src/packlets/invitations/invitation-guest-extenstion.ts +8 -4
- package/src/packlets/invitations/invitation-host-extension.ts +8 -7
- package/src/packlets/invitations/invitation-state.ts +111 -0
- package/src/packlets/invitations/invitations-handler.test.ts +16 -9
- package/src/packlets/invitations/invitations-handler.ts +23 -93
- package/src/packlets/invitations/space-invitation-protocol.test.ts +4 -3
- package/src/packlets/invitations/space-invitation-protocol.ts +4 -0
- package/src/packlets/logging/logging.test.ts +1 -2
- package/src/packlets/network/network-service.test.ts +2 -3
- package/src/packlets/services/service-context.test.ts +3 -1
- package/src/packlets/services/service-context.ts +113 -35
- package/src/packlets/services/service-host.test.ts +8 -12
- package/src/packlets/services/service-host.ts +25 -7
- package/src/packlets/services/service-registry.test.ts +1 -2
- package/src/packlets/spaces/data-space-manager.test.ts +2 -2
- package/src/packlets/spaces/data-space-manager.ts +44 -7
- package/src/packlets/spaces/data-space.ts +37 -6
- package/src/packlets/spaces/edge-feed-replicator.test.ts +252 -0
- package/src/packlets/spaces/edge-feed-replicator.ts +80 -22
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +10 -7
- package/src/packlets/spaces/notarization-plugin.ts +196 -29
- package/src/packlets/spaces/spaces-service.test.ts +5 -9
- package/src/packlets/spaces/spaces-service.ts +6 -1
- package/src/packlets/storage/storage.ts +0 -1
- package/src/packlets/system/system-service.test.ts +1 -2
- package/src/packlets/testing/test-builder.ts +7 -4
- package/src/packlets/worker/worker-runtime.ts +2 -2
- package/src/testing/setup.ts +11 -0
- package/src/version.ts +1 -5
- package/dist/lib/browser/chunk-CRXXOI45.mjs.map +0 -7
- package/dist/lib/node/chunk-PZ3JJJ3K.cjs.map +0 -7
- package/dist/types/src/packlets/identity/authenticator.test.d.ts +0 -2
- package/dist/types/src/packlets/identity/authenticator.test.d.ts.map +0 -1
- package/dist/types/src/packlets/services/automerge-host.test.d.ts +0 -2
- package/dist/types/src/packlets/services/automerge-host.test.d.ts.map +0 -1
- package/src/packlets/services/automerge-host.test.ts +0 -60
|
@@ -14,8 +14,11 @@ import {
|
|
|
14
14
|
type DelegateInvitationCredential,
|
|
15
15
|
type MemberInfo,
|
|
16
16
|
} from '@dxos/credentials';
|
|
17
|
-
import { convertLegacyReferences, findInlineObjectOfType, type EchoEdgeReplicator, type EchoHost } from '@dxos/echo-db';
|
|
18
17
|
import {
|
|
18
|
+
convertLegacyReferences,
|
|
19
|
+
findInlineObjectOfType,
|
|
20
|
+
type EchoEdgeReplicator,
|
|
21
|
+
type EchoHost,
|
|
19
22
|
AuthStatus,
|
|
20
23
|
CredentialServerExtension,
|
|
21
24
|
type MeshEchoReplicator,
|
|
@@ -32,8 +35,8 @@ import {
|
|
|
32
35
|
type ObjectStructure,
|
|
33
36
|
type SpaceDoc,
|
|
34
37
|
} from '@dxos/echo-protocol';
|
|
35
|
-
import { TYPE_PROPERTIES,
|
|
36
|
-
import type { EdgeConnection } from '@dxos/edge-client';
|
|
38
|
+
import { TYPE_PROPERTIES, createObjectId, getTypeReference } from '@dxos/echo-schema';
|
|
39
|
+
import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
|
|
37
40
|
import { writeMessages, type FeedStore } from '@dxos/feed-store';
|
|
38
41
|
import { invariant } from '@dxos/invariant';
|
|
39
42
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -43,7 +46,7 @@ import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
|
|
|
43
46
|
import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
44
47
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
45
48
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
46
|
-
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
49
|
+
import { type SpaceMetadata, EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
47
50
|
import { SpaceMember, type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
48
51
|
import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
49
52
|
import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
|
|
@@ -107,6 +110,7 @@ export type DataSpaceManagerParams = {
|
|
|
107
110
|
echoHost: EchoHost;
|
|
108
111
|
invitationsManager: InvitationsManager;
|
|
109
112
|
edgeConnection?: EdgeConnection;
|
|
113
|
+
edgeHttpClient?: EdgeHttpClient;
|
|
110
114
|
meshReplicator?: MeshEchoReplicator;
|
|
111
115
|
echoEdgeReplicator?: EchoEdgeReplicator;
|
|
112
116
|
runtimeParams?: DataSpaceManagerRuntimeParams;
|
|
@@ -116,6 +120,7 @@ export type DataSpaceManagerParams = {
|
|
|
116
120
|
export type DataSpaceManagerRuntimeParams = {
|
|
117
121
|
spaceMemberPresenceAnnounceInterval?: number;
|
|
118
122
|
spaceMemberPresenceOfflineTimeout?: number;
|
|
123
|
+
activeEdgeNotarizationPollingInterval?: number;
|
|
119
124
|
disableP2pReplication?: boolean;
|
|
120
125
|
};
|
|
121
126
|
|
|
@@ -135,6 +140,7 @@ export class DataSpaceManager extends Resource {
|
|
|
135
140
|
private readonly _echoHost: EchoHost;
|
|
136
141
|
private readonly _invitationsManager: InvitationsManager;
|
|
137
142
|
private readonly _edgeConnection?: EdgeConnection = undefined;
|
|
143
|
+
private readonly _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
138
144
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
|
|
139
145
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
140
146
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
@@ -154,6 +160,7 @@ export class DataSpaceManager extends Resource {
|
|
|
154
160
|
this._edgeConnection = params.edgeConnection;
|
|
155
161
|
this._edgeFeatures = params.edgeFeatures;
|
|
156
162
|
this._echoEdgeReplicator = params.echoEdgeReplicator;
|
|
163
|
+
this._edgeHttpClient = params.edgeHttpClient;
|
|
157
164
|
this._runtimeParams = params.runtimeParams;
|
|
158
165
|
|
|
159
166
|
trace.diagnostic({
|
|
@@ -290,7 +297,7 @@ export class DataSpaceManager extends Resource {
|
|
|
290
297
|
},
|
|
291
298
|
};
|
|
292
299
|
|
|
293
|
-
const propertiesId =
|
|
300
|
+
const propertiesId = createObjectId();
|
|
294
301
|
document.change((doc: SpaceDoc) => {
|
|
295
302
|
setDeep(doc, ['objects', propertiesId], properties);
|
|
296
303
|
});
|
|
@@ -388,6 +395,26 @@ export class DataSpaceManager extends Resource {
|
|
|
388
395
|
});
|
|
389
396
|
}
|
|
390
397
|
|
|
398
|
+
async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting) {
|
|
399
|
+
const space = this._spaces.get(spaceKey);
|
|
400
|
+
invariant(space, 'Space not found.');
|
|
401
|
+
|
|
402
|
+
await this._metadataStore.setSpaceEdgeReplicationSetting(spaceKey, setting);
|
|
403
|
+
|
|
404
|
+
if (space.isOpen) {
|
|
405
|
+
switch (setting) {
|
|
406
|
+
case EdgeReplicationSetting.DISABLED:
|
|
407
|
+
await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
|
|
408
|
+
break;
|
|
409
|
+
case EdgeReplicationSetting.ENABLED:
|
|
410
|
+
await this._echoEdgeReplicator?.connectToSpace(space.id);
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
space.stateUpdate.emit();
|
|
416
|
+
}
|
|
417
|
+
|
|
391
418
|
private async _constructSpace(metadata: SpaceMetadata) {
|
|
392
419
|
log('construct space', { metadata });
|
|
393
420
|
const gossip = new Gossip({
|
|
@@ -479,13 +506,23 @@ export class DataSpaceManager extends Resource {
|
|
|
479
506
|
},
|
|
480
507
|
cache: metadata.cache,
|
|
481
508
|
edgeConnection: this._edgeConnection,
|
|
509
|
+
edgeHttpClient: this._edgeHttpClient,
|
|
482
510
|
edgeFeatures: this._edgeFeatures,
|
|
511
|
+
activeEdgeNotarizationPollingInterval: this._runtimeParams?.activeEdgeNotarizationPollingInterval,
|
|
483
512
|
});
|
|
484
513
|
dataSpace.postOpen.append(async () => {
|
|
485
|
-
|
|
514
|
+
const setting = dataSpace.getEdgeReplicationSetting();
|
|
515
|
+
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
516
|
+
await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
|
|
517
|
+
} else if (this._echoEdgeReplicator) {
|
|
518
|
+
log('not connecting EchoEdgeReplicator because of EdgeReplicationSetting', { spaceId: dataSpace.id });
|
|
519
|
+
}
|
|
486
520
|
});
|
|
487
521
|
dataSpace.preClose.append(async () => {
|
|
488
|
-
|
|
522
|
+
const setting = dataSpace.getEdgeReplicationSetting();
|
|
523
|
+
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
524
|
+
await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
|
|
525
|
+
}
|
|
489
526
|
});
|
|
490
527
|
|
|
491
528
|
presence.newPeer.on((peerState) => {
|
|
@@ -7,10 +7,15 @@ import { AUTH_TIMEOUT } from '@dxos/client-protocol';
|
|
|
7
7
|
import { Context, ContextDisposedError, cancelWithContext } from '@dxos/context';
|
|
8
8
|
import type { SpecificCredential } from '@dxos/credentials';
|
|
9
9
|
import { timed, warnAfterTimeout } from '@dxos/debug';
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import {
|
|
11
|
+
type EchoHost,
|
|
12
|
+
type DatabaseRoot,
|
|
13
|
+
createMappedFeedWriter,
|
|
14
|
+
type MetadataStore,
|
|
15
|
+
type Space,
|
|
16
|
+
} from '@dxos/echo-pipeline';
|
|
12
17
|
import { SpaceDocVersion } from '@dxos/echo-protocol';
|
|
13
|
-
import type { EdgeConnection } from '@dxos/edge-client';
|
|
18
|
+
import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
|
|
14
19
|
import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
15
20
|
import { failedInvariant } from '@dxos/invariant';
|
|
16
21
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -75,7 +80,9 @@ export type DataSpaceParams = {
|
|
|
75
80
|
callbacks?: DataSpaceCallbacks;
|
|
76
81
|
cache?: SpaceCache;
|
|
77
82
|
edgeConnection?: EdgeConnection;
|
|
83
|
+
edgeHttpClient?: EdgeHttpClient;
|
|
78
84
|
edgeFeatures?: Runtime.Client.EdgeFeatures;
|
|
85
|
+
activeEdgeNotarizationPollingInterval?: number;
|
|
79
86
|
};
|
|
80
87
|
|
|
81
88
|
export type CreateEpochOptions = {
|
|
@@ -96,7 +103,7 @@ export class DataSpace {
|
|
|
96
103
|
private readonly _feedStore: FeedStore<FeedMessage>;
|
|
97
104
|
private readonly _metadataStore: MetadataStore;
|
|
98
105
|
private readonly _signingContext: SigningContext;
|
|
99
|
-
private readonly _notarizationPlugin
|
|
106
|
+
private readonly _notarizationPlugin: NotarizationPlugin;
|
|
100
107
|
private readonly _callbacks: DataSpaceCallbacks;
|
|
101
108
|
private readonly _cache?: SpaceCache = undefined;
|
|
102
109
|
private readonly _echoHost: EchoHost;
|
|
@@ -136,6 +143,12 @@ export class DataSpace {
|
|
|
136
143
|
this._signingContext = params.signingContext;
|
|
137
144
|
this._callbacks = params.callbacks ?? {};
|
|
138
145
|
this._echoHost = params.echoHost;
|
|
146
|
+
this._notarizationPlugin = new NotarizationPlugin({
|
|
147
|
+
spaceId: this._inner.id,
|
|
148
|
+
edgeClient: params.edgeHttpClient,
|
|
149
|
+
edgeFeatures: params.edgeFeatures,
|
|
150
|
+
activeEdgePollingInterval: params.activeEdgeNotarizationPollingInterval,
|
|
151
|
+
});
|
|
139
152
|
|
|
140
153
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
141
154
|
trustedKeysProvider: () =>
|
|
@@ -231,6 +244,7 @@ export class DataSpace {
|
|
|
231
244
|
}
|
|
232
245
|
|
|
233
246
|
await this._inner.open(new Context());
|
|
247
|
+
await this._inner.startProtocol();
|
|
234
248
|
|
|
235
249
|
await this._edgeFeedReplicator?.open();
|
|
236
250
|
|
|
@@ -318,6 +332,7 @@ export class DataSpace {
|
|
|
318
332
|
this._state = SpaceState.SPACE_INITIALIZING;
|
|
319
333
|
log('new state', { state: SpaceState[this._state] });
|
|
320
334
|
|
|
335
|
+
log('initializing control pipeline');
|
|
321
336
|
await this._initializeAndReadControlPipeline();
|
|
322
337
|
|
|
323
338
|
// Allow other tasks to run before loading the data pipeline.
|
|
@@ -325,10 +340,13 @@ export class DataSpace {
|
|
|
325
340
|
|
|
326
341
|
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState.SPACE_READY);
|
|
327
342
|
|
|
343
|
+
log('initializing automerge root');
|
|
328
344
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
329
345
|
|
|
330
346
|
// TODO(dmaretskyi): Change so `initializeDataPipeline` doesn't wait for the space to be READY, but rather any state with a valid root.
|
|
347
|
+
log('waiting for space to be ready');
|
|
331
348
|
await ready;
|
|
349
|
+
log('space is ready');
|
|
332
350
|
}
|
|
333
351
|
|
|
334
352
|
private async _enterReadyState() {
|
|
@@ -345,6 +363,7 @@ export class DataSpace {
|
|
|
345
363
|
private async _initializeAndReadControlPipeline() {
|
|
346
364
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
347
365
|
ctx: this._ctx,
|
|
366
|
+
timeout: 10_000,
|
|
348
367
|
breakOnStall: false,
|
|
349
368
|
});
|
|
350
369
|
|
|
@@ -408,8 +427,16 @@ export class DataSpace {
|
|
|
408
427
|
}
|
|
409
428
|
|
|
410
429
|
if (credentials.length > 0) {
|
|
411
|
-
|
|
412
|
-
|
|
430
|
+
try {
|
|
431
|
+
log('will notarize credentials for feed admission', { count: credentials.length });
|
|
432
|
+
// Never times out
|
|
433
|
+
await this.notarizationPlugin.notarize({ ctx: this._ctx, credentials, timeout: 0 });
|
|
434
|
+
|
|
435
|
+
log('credentials notarized');
|
|
436
|
+
} catch (err) {
|
|
437
|
+
log.error('error notarizing credentials for feed admission', err);
|
|
438
|
+
throw err;
|
|
439
|
+
}
|
|
413
440
|
|
|
414
441
|
// Set this after credentials are notarized so that on failure we will retry.
|
|
415
442
|
await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey!, this.inner.dataFeedKey!);
|
|
@@ -546,6 +573,10 @@ export class DataSpace {
|
|
|
546
573
|
this.stateUpdate.emit();
|
|
547
574
|
}
|
|
548
575
|
|
|
576
|
+
getEdgeReplicationSetting() {
|
|
577
|
+
return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
|
|
578
|
+
}
|
|
579
|
+
|
|
549
580
|
private _onFeedAdded = async (feed: FeedWrapper<any>) => {
|
|
550
581
|
await this._edgeFeedReplicator!.addFeed(feed);
|
|
551
582
|
};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { decode as decodeCbor, encode as encodeCbor } from 'cbor-x';
|
|
6
|
+
import { getPort } from 'get-port-please';
|
|
7
|
+
import { describe, expect, onTestFinished, test, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import { sleep, Trigger } from '@dxos/async';
|
|
10
|
+
import { Context } from '@dxos/context';
|
|
11
|
+
import { valueEncoding } from '@dxos/echo-pipeline';
|
|
12
|
+
import { createEphemeralEdgeIdentity, EdgeClient, EdgeIdentityChangedError } from '@dxos/edge-client';
|
|
13
|
+
import { createTestEdgeWsServer } from '@dxos/edge-client/testing';
|
|
14
|
+
import { FeedFactory, FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
15
|
+
import { Keyring } from '@dxos/keyring';
|
|
16
|
+
import { SpaceId } from '@dxos/keys';
|
|
17
|
+
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
18
|
+
import { createStorage } from '@dxos/random-access-storage';
|
|
19
|
+
import { openAndClose } from '@dxos/test-utils';
|
|
20
|
+
import { Timeframe } from '@dxos/timeframe';
|
|
21
|
+
import { range } from '@dxos/util';
|
|
22
|
+
|
|
23
|
+
import { EdgeFeedReplicator } from './edge-feed-replicator';
|
|
24
|
+
|
|
25
|
+
describe('EdgeFeedReplicator', () => {
|
|
26
|
+
test('requests metadata after connection is open', async () => {
|
|
27
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
28
|
+
const { messenger, sendSpy } = await createClient(endpoint);
|
|
29
|
+
|
|
30
|
+
await attachReplicator(messenger);
|
|
31
|
+
|
|
32
|
+
await sleep(50);
|
|
33
|
+
|
|
34
|
+
expect(sendSpy).not.toHaveBeenCalled();
|
|
35
|
+
expect(messageSink.length).toEqual(0);
|
|
36
|
+
|
|
37
|
+
admitConnection.wake();
|
|
38
|
+
await expect.poll(() => sendSpy.mock.calls.length).toEqual(1);
|
|
39
|
+
expect(messageSink.length).toEqual(1);
|
|
40
|
+
expect(messageSink[0].type).toEqual('get-metadata');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('replicates if added to a connected client', async () => {
|
|
44
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
45
|
+
const { messenger } = await createClient(endpoint);
|
|
46
|
+
admitConnection.wake();
|
|
47
|
+
await expect.poll(() => messenger.isConnected).toBeTruthy();
|
|
48
|
+
|
|
49
|
+
await attachReplicator(messenger);
|
|
50
|
+
await expect.poll(() => messageSink.length).toEqual(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('sends a block', async () => {
|
|
54
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
55
|
+
const { messenger } = await createClient(endpoint);
|
|
56
|
+
|
|
57
|
+
const { feed } = await attachReplicator(messenger);
|
|
58
|
+
|
|
59
|
+
admitConnection.wake();
|
|
60
|
+
await appendMessage(feed);
|
|
61
|
+
|
|
62
|
+
await expect.poll(() => messageSink.length).toEqual(2);
|
|
63
|
+
expect(messageSink[1].type).toEqual('data');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('re-requests metadata on reconnect', async () => {
|
|
67
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
68
|
+
const { messenger } = await createClient(endpoint);
|
|
69
|
+
|
|
70
|
+
await attachReplicator(messenger);
|
|
71
|
+
|
|
72
|
+
admitConnection.wake();
|
|
73
|
+
await expect.poll(() => messageSink.length).toEqual(1);
|
|
74
|
+
|
|
75
|
+
await updateIdentity(messenger);
|
|
76
|
+
await messenger.reconnect.waitForCount(1);
|
|
77
|
+
|
|
78
|
+
await expect.poll(() => messageSink.length).toEqual(2);
|
|
79
|
+
expect(messageSink[1].type).toEqual('get-metadata');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('recovers after query sending failure during identity change', async () => {
|
|
83
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
84
|
+
const { messenger, sendSpy } = await createClient(endpoint);
|
|
85
|
+
|
|
86
|
+
await attachReplicator(messenger);
|
|
87
|
+
|
|
88
|
+
sendSpy.mockImplementationOnce(() => {
|
|
89
|
+
throw new EdgeIdentityChangedError(); // Hard to mock the exact race condition for when this error is thrown
|
|
90
|
+
});
|
|
91
|
+
admitConnection.wake();
|
|
92
|
+
|
|
93
|
+
await expect.poll(() => sendSpy.mock.calls.length).toEqual(1);
|
|
94
|
+
expect(messageSink.length).toEqual(0);
|
|
95
|
+
await updateIdentity(messenger);
|
|
96
|
+
|
|
97
|
+
await expect.poll(() => messageSink.length).toEqual(1);
|
|
98
|
+
expect(messageSink[0].type).toEqual('get-metadata');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('recovers after response sending failure during identity change', async () => {
|
|
102
|
+
const { endpoint, admitConnection, messageSink, sendResponseMessage } = await createEdge();
|
|
103
|
+
const { messenger, sendSpy } = await createClient(endpoint);
|
|
104
|
+
|
|
105
|
+
const { feed } = await attachReplicator(messenger);
|
|
106
|
+
await appendMessage(feed);
|
|
107
|
+
|
|
108
|
+
sendSpy.mockImplementationOnce(async (request: any) => {
|
|
109
|
+
sendResponseMessage(request, encodeCbor({ type: 'metadata', feedKey: feed.key.toHex(), length: 0 }));
|
|
110
|
+
return Promise.resolve();
|
|
111
|
+
});
|
|
112
|
+
sendSpy.mockImplementationOnce(async () => {
|
|
113
|
+
throw new EdgeIdentityChangedError();
|
|
114
|
+
});
|
|
115
|
+
admitConnection.wake();
|
|
116
|
+
|
|
117
|
+
await expect.poll(() => sendSpy.mock.calls.length).toEqual(2);
|
|
118
|
+
sendSpy.mockRestore();
|
|
119
|
+
expect(messageSink.length).toEqual(0);
|
|
120
|
+
await updateIdentity(messenger);
|
|
121
|
+
|
|
122
|
+
await messenger.reconnect.waitForCount(1);
|
|
123
|
+
await expect.poll(() => messageSink.find((msg) => msg.type === 'data')).toBeDefined();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('propagates errors unrelated to reconnect', async () => {
|
|
127
|
+
const { endpoint, admitConnection } = await createEdge();
|
|
128
|
+
const { messenger, sendSpy } = await createClient(endpoint);
|
|
129
|
+
|
|
130
|
+
const { replicator } = await attachReplicator(messenger, { skipOpen: true });
|
|
131
|
+
const raised = new Trigger();
|
|
132
|
+
await replicator.open(new Context({ onError: () => raised.wake() }));
|
|
133
|
+
onTestFinished(async () => {
|
|
134
|
+
await replicator.close();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
sendSpy.mockImplementationOnce(() => {
|
|
138
|
+
throw new Error();
|
|
139
|
+
});
|
|
140
|
+
admitConnection.wake();
|
|
141
|
+
|
|
142
|
+
await raised.wait();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('identity update before connected', async () => {
|
|
146
|
+
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
147
|
+
const { messenger } = await createClient(endpoint);
|
|
148
|
+
|
|
149
|
+
await attachReplicator(messenger);
|
|
150
|
+
await updateIdentity(messenger);
|
|
151
|
+
await sleep(100);
|
|
152
|
+
admitConnection.wake();
|
|
153
|
+
|
|
154
|
+
await expect.poll(() => messageSink.length).toEqual(2);
|
|
155
|
+
expect(messageSink.map((m) => m.type)).toStrictEqual(range(2, () => 'get-metadata'));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('block appended during reconnect', async () => {
|
|
159
|
+
const { endpoint, admitConnection, feedLength } = await createEdge();
|
|
160
|
+
const { messenger } = await createClient(endpoint);
|
|
161
|
+
|
|
162
|
+
const { feed } = await attachReplicator(messenger);
|
|
163
|
+
admitConnection.wake();
|
|
164
|
+
await sleep(10);
|
|
165
|
+
|
|
166
|
+
admitConnection.reset();
|
|
167
|
+
await updateIdentity(messenger);
|
|
168
|
+
await appendMessage(feed);
|
|
169
|
+
await sleep(20);
|
|
170
|
+
admitConnection.wake();
|
|
171
|
+
|
|
172
|
+
await expect.poll(() => feedLength()).toEqual(1);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('reconnect during block append', async () => {
|
|
176
|
+
const { endpoint, admitConnection, feedLength } = await createEdge();
|
|
177
|
+
const { messenger } = await createClient(endpoint);
|
|
178
|
+
|
|
179
|
+
const { feed } = await attachReplicator(messenger);
|
|
180
|
+
admitConnection.wake();
|
|
181
|
+
await sleep(10);
|
|
182
|
+
|
|
183
|
+
void appendMessage(feed);
|
|
184
|
+
await updateIdentity(messenger);
|
|
185
|
+
|
|
186
|
+
await expect.poll(() => feedLength()).toEqual(1);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const createEdge = async () => {
|
|
190
|
+
const port = await getPort({ host: 'localhost', port: 7200, portRange: [7200, 7299] });
|
|
191
|
+
let lastBlockIndex = -1;
|
|
192
|
+
const admitConnection = new Trigger();
|
|
193
|
+
const { cleanup, endpoint, messageSink, sendResponseMessage } = await createTestEdgeWsServer(port, {
|
|
194
|
+
admitConnection,
|
|
195
|
+
payloadDecoder: decodeCbor,
|
|
196
|
+
messageHandler: async (message: any) => {
|
|
197
|
+
if (message.type === 'get-metadata') {
|
|
198
|
+
return encodeCbor({ type: 'metadata', feedKey: message.feedKey, length: lastBlockIndex + 1 });
|
|
199
|
+
} else {
|
|
200
|
+
lastBlockIndex = Math.max(lastBlockIndex, message.blocks[message.blocks.length - 1].index);
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
onTestFinished(cleanup);
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
endpoint,
|
|
208
|
+
messageSink,
|
|
209
|
+
admitConnection,
|
|
210
|
+
sendResponseMessage,
|
|
211
|
+
feedLength: () => lastBlockIndex + 1,
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const createClient = async (endpoint: string) => {
|
|
216
|
+
const messenger = new EdgeClient(await createEphemeralEdgeIdentity(), { socketEndpoint: endpoint });
|
|
217
|
+
const sendSpy = vi.spyOn(messenger, 'send');
|
|
218
|
+
await openAndClose(messenger);
|
|
219
|
+
return { messenger, sendSpy };
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const attachReplicator = async (messenger: EdgeClient, options?: { skipOpen?: boolean }) => {
|
|
223
|
+
const spaceId = SpaceId.random();
|
|
224
|
+
const feed = await createNewFeed();
|
|
225
|
+
const replicator = new EdgeFeedReplicator({ messenger, spaceId });
|
|
226
|
+
await replicator.addFeed(feed);
|
|
227
|
+
if (!options?.skipOpen) {
|
|
228
|
+
await openAndClose(replicator);
|
|
229
|
+
}
|
|
230
|
+
return { feed, replicator };
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const createNewFeed = async () => {
|
|
234
|
+
const storage = createStorage();
|
|
235
|
+
const keyring = new Keyring();
|
|
236
|
+
const feedStore = new FeedStore<FeedMessage>({
|
|
237
|
+
factory: new FeedFactory<FeedMessage>({
|
|
238
|
+
root: storage.createDirectory(),
|
|
239
|
+
signer: keyring,
|
|
240
|
+
hypercore: { valueEncoding },
|
|
241
|
+
}),
|
|
242
|
+
});
|
|
243
|
+
onTestFinished(() => feedStore.close());
|
|
244
|
+
return feedStore.openFeed(await keyring.createKey(), { writable: true });
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const updateIdentity = async (messenger: EdgeClient) => {
|
|
248
|
+
messenger.setIdentity(await createEphemeralEdgeIdentity());
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const appendMessage = (feed: FeedWrapper<FeedMessage>) => feed.append({ timeframe: new Timeframe() });
|
|
252
|
+
});
|