@dxos/echo-pipeline 0.8.3 → 0.8.4-main.03d5cd7b56
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-35I6ERLG.mjs → neutral/chunk-VIHYDCCC.mjs} +313 -709
- package/dist/lib/neutral/chunk-VIHYDCCC.mjs.map +7 -0
- package/dist/lib/neutral/chunk-YBC6ONBZ.mjs +247 -0
- package/dist/lib/neutral/chunk-YBC6ONBZ.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/filter/index.mjs +3 -2
- package/dist/lib/neutral/index.mjs +7065 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +90 -311
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- package/dist/types/src/automerge/automerge-host-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-host-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-host.d.ts +99 -54
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-repo-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-repo-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/automerge-repo.test.d.ts +1 -1
- package/dist/types/src/automerge/automerge-repo.test.d.ts.map +1 -1
- package/dist/types/src/automerge/automerge-subduction.test.d.ts +2 -0
- package/dist/types/src/automerge/automerge-subduction.test.d.ts.map +1 -0
- package/dist/types/src/automerge/collection-synchronizer.d.ts +25 -4
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-data-monitor.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +23 -10
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +38 -15
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/handle-state.d.ts +52 -0
- package/dist/types/src/automerge/handle-state.d.ts.map +1 -0
- package/dist/types/src/automerge/heads-store.d.ts +9 -2
- package/dist/types/src/automerge/heads-store.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +2 -1
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +9 -5
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +9 -8
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts +6 -5
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/network-protocol.d.ts.map +1 -1
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/common/codec.d.ts +1 -1
- package/dist/types/src/common/codec.d.ts.map +1 -1
- package/dist/types/src/common/feeds.d.ts.map +1 -1
- package/dist/types/src/common/space-id.d.ts.map +1 -1
- package/dist/types/src/db-host/automerge-data-source.d.ts +35 -0
- package/dist/types/src/db-host/automerge-data-source.d.ts.map +1 -0
- package/dist/types/src/db-host/automerge-data-source.test.d.ts +2 -0
- package/dist/types/src/db-host/automerge-data-source.test.d.ts.map +1 -0
- package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts +8 -7
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +9 -3
- package/dist/types/src/db-host/database-root.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-synchronizer.d.ts +9 -8
- package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +62 -27
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/index.d.ts +2 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/invalidation-hint.d.ts +19 -0
- package/dist/types/src/db-host/invalidation-hint.d.ts.map +1 -0
- package/dist/types/src/db-host/local-queue-service.d.ts +19 -0
- package/dist/types/src/db-host/local-queue-service.d.ts.map +1 -0
- package/dist/types/src/db-host/query-invalidation.test.d.ts +2 -0
- package/dist/types/src/db-host/query-invalidation.test.d.ts.map +1 -0
- package/dist/types/src/db-host/query-service.d.ts +19 -11
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/db-host/queue-data-source.d.ts +38 -0
- package/dist/types/src/db-host/queue-data-source.d.ts.map +1 -0
- package/dist/types/src/db-host/queue-service.test.d.ts +2 -0
- package/dist/types/src/db-host/queue-service.test.d.ts.map +1 -0
- package/dist/types/src/db-host/space-state-manager.d.ts +4 -3
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -1
- package/dist/types/src/db-host/stub.d.ts +11 -0
- package/dist/types/src/db-host/stub.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts +10 -7
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-subduction-replicator.d.ts +39 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.test.d.ts +2 -0
- package/dist/types/src/edge/echo-edge-subduction-replicator.test.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts +1 -0
- package/dist/types/src/edge/index.d.ts.map +1 -1
- package/dist/types/src/edge/inflight-request-limiter.d.ts.map +1 -1
- package/dist/types/src/filter/filter-match.d.ts +4 -1
- package/dist/types/src/filter/filter-match.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
- package/dist/types/src/pipeline/pipeline.d.ts +3 -3
- package/dist/types/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/types/src/pipeline/timeframe-clock.d.ts.map +1 -1
- package/dist/types/src/query/errors.d.ts +22 -10
- package/dist/types/src/query/errors.d.ts.map +1 -1
- package/dist/types/src/query/plan.d.ts +66 -8
- package/dist/types/src/query/plan.d.ts.map +1 -1
- package/dist/types/src/query/query-executor.d.ts +66 -11
- package/dist/types/src/query/query-executor.d.ts.map +1 -1
- package/dist/types/src/query/query-planner.d.ts +12 -1
- package/dist/types/src/query/query-planner.d.ts.map +1 -1
- package/dist/types/src/space/admission-discovery-extension.d.ts.map +1 -1
- package/dist/types/src/space/auth.d.ts +3 -3
- package/dist/types/src/space/auth.d.ts.map +1 -1
- package/dist/types/src/space/control-pipeline.d.ts +5 -4
- package/dist/types/src/space/control-pipeline.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts +8 -8
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts +10 -9
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +6 -6
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/change-metadata.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +2 -2
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-feed-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
- package/dist/types/src/testing/test-replicator.d.ts +14 -13
- package/dist/types/src/testing/test-replicator.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +56 -54
- package/src/automerge/automerge-host-subduction.test.ts +247 -0
- package/src/automerge/automerge-host.test.ts +65 -39
- package/src/automerge/automerge-host.ts +589 -206
- package/src/automerge/automerge-repo-subduction.test.ts +1049 -0
- package/src/automerge/automerge-repo.test.ts +349 -91
- package/src/automerge/automerge-subduction.test.ts +330 -0
- package/src/automerge/collection-synchronizer.test.ts +53 -17
- package/src/automerge/collection-synchronizer.ts +119 -36
- package/src/automerge/echo-data-monitor.ts +1 -1
- package/src/automerge/echo-network-adapter.test.ts +5 -4
- package/src/automerge/echo-network-adapter.ts +74 -30
- package/src/automerge/echo-replicator.ts +41 -15
- package/src/automerge/handle-state.ts +62 -0
- package/src/automerge/heads-store.ts +42 -3
- package/src/automerge/index.ts +2 -1
- package/src/automerge/leveldb-storage-adapter.ts +40 -11
- package/src/automerge/mesh-echo-replicator-connection.ts +12 -8
- package/src/automerge/mesh-echo-replicator.ts +15 -11
- package/src/automerge/storage-adapter.test.ts +1 -1
- package/src/common/space-id.ts +1 -1
- package/src/db-host/automerge-data-source.test.ts +299 -0
- package/src/db-host/automerge-data-source.ts +187 -0
- package/src/db-host/data-service.ts +25 -26
- package/src/db-host/database-root.ts +20 -8
- package/src/db-host/documents-synchronizer.test.ts +143 -14
- package/src/db-host/documents-synchronizer.ts +72 -55
- package/src/db-host/echo-host.ts +348 -96
- package/src/db-host/index.ts +2 -0
- package/src/db-host/invalidation-hint.ts +50 -0
- package/src/db-host/local-queue-service.ts +127 -0
- package/src/db-host/query-invalidation.test.ts +270 -0
- package/src/db-host/query-service.ts +111 -106
- package/src/db-host/queue-data-source.ts +160 -0
- package/src/db-host/queue-service.test.ts +145 -0
- package/src/db-host/space-state-manager.ts +12 -10
- package/src/db-host/stub.ts +33 -0
- package/src/edge/echo-edge-replicator.test.ts +12 -10
- package/src/edge/echo-edge-replicator.ts +144 -58
- package/src/edge/echo-edge-subduction-replicator.test.ts +158 -0
- package/src/edge/echo-edge-subduction-replicator.ts +377 -0
- package/src/edge/index.ts +1 -0
- package/src/filter/filter-match.test.ts +68 -32
- package/src/filter/filter-match.ts +184 -20
- package/src/metadata/metadata-store.ts +11 -8
- package/src/pipeline/pipeline-stress.test.ts +1 -1
- package/src/pipeline/pipeline.test.ts +2 -2
- package/src/pipeline/pipeline.ts +9 -7
- package/src/query/errors.ts +3 -1
- package/src/query/plan.ts +82 -8
- package/src/query/query-executor.ts +1199 -164
- package/src/query/query-planner.test.ts +993 -81
- package/src/query/query-planner.ts +467 -27
- package/src/space/admission-discovery-extension.ts +3 -3
- package/src/space/auth.ts +6 -6
- package/src/space/control-pipeline.test.ts +5 -4
- package/src/space/control-pipeline.ts +16 -13
- package/src/space/space-manager.browser.test.ts +1 -1
- package/src/space/space-manager.ts +16 -20
- package/src/space/space-protocol.browser.test.ts +15 -14
- package/src/space/space-protocol.test.ts +15 -14
- package/src/space/space-protocol.ts +22 -18
- package/src/space/space.test.ts +3 -3
- package/src/space/space.ts +11 -11
- package/src/testing/index.ts +0 -2
- package/src/testing/test-agent-builder.ts +3 -3
- package/src/testing/test-network-adapter.ts +24 -3
- package/src/testing/test-replicator.ts +19 -20
- package/src/util.ts +7 -3
- package/dist/lib/browser/chunk-35I6ERLG.mjs.map +0 -7
- package/dist/lib/browser/chunk-CGS2ULMK.mjs +0 -11
- package/dist/lib/browser/chunk-CGS2ULMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-TQJTKNMS.mjs +0 -126
- package/dist/lib/browser/chunk-TQJTKNMS.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -4743
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/chunk-HOPOFWAL.cjs +0 -147
- package/dist/lib/node/chunk-HOPOFWAL.cjs.map +0 -7
- package/dist/lib/node/chunk-JXX6LF5U.cjs +0 -2084
- package/dist/lib/node/chunk-JXX6LF5U.cjs.map +0 -7
- package/dist/lib/node/chunk-Q7SFCCGT.cjs +0 -33
- package/dist/lib/node/chunk-Q7SFCCGT.cjs.map +0 -7
- package/dist/lib/node/filter/index.cjs +0 -32
- package/dist/lib/node/filter/index.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -4699
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -753
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-5BHLPT24.mjs +0 -2067
- package/dist/lib/node-esm/chunk-5BHLPT24.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RVK35BS7.mjs +0 -126
- package/dist/lib/node-esm/chunk-RVK35BS7.mjs.map +0 -7
- package/dist/lib/node-esm/filter/index.mjs +0 -11
- package/dist/lib/node-esm/filter/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -4743
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -742
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/db-host/documents-iterator.d.ts +0 -7
- package/dist/types/src/db-host/documents-iterator.d.ts.map +0 -1
- package/dist/types/src/testing/test-data.d.ts +0 -18
- package/dist/types/src/testing/test-data.d.ts.map +0 -1
- package/dist/types/src/testing/test-schema.d.ts +0 -37
- package/dist/types/src/testing/test-schema.d.ts.map +0 -1
- package/src/db-host/documents-iterator.ts +0 -74
- package/src/testing/test-data.ts +0 -127
- package/src/testing/test-schema.ts +0 -53
- /package/dist/lib/{browser → neutral}/filter/index.mjs.map +0 -0
package/src/space/auth.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type AuthProvider = (nonce: Uint8Array) => Promise<Uint8Array | undefined
|
|
|
15
15
|
|
|
16
16
|
export type AuthVerifier = (nonce: Uint8Array, credential: Uint8Array) => Promise<boolean>;
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type AuthExtensionProps = {
|
|
19
19
|
provider: AuthProvider;
|
|
20
20
|
verifier: AuthVerifier;
|
|
21
21
|
onAuthSuccess: () => void;
|
|
@@ -29,7 +29,7 @@ export class AuthExtension extends RpcExtension<Services, Services> {
|
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
constructor(private readonly
|
|
32
|
+
constructor(private readonly _authProps: AuthExtensionProps) {
|
|
33
33
|
super({
|
|
34
34
|
requested: {
|
|
35
35
|
AuthService: schema.getService('dxos.mesh.teleport.auth.AuthService'),
|
|
@@ -46,7 +46,7 @@ export class AuthExtension extends RpcExtension<Services, Services> {
|
|
|
46
46
|
AuthService: {
|
|
47
47
|
authenticate: async ({ challenge }) => {
|
|
48
48
|
try {
|
|
49
|
-
const credential = await this.
|
|
49
|
+
const credential = await this._authProps.provider(challenge);
|
|
50
50
|
if (!credential) {
|
|
51
51
|
throw new Error('auth rejected');
|
|
52
52
|
}
|
|
@@ -67,13 +67,13 @@ export class AuthExtension extends RpcExtension<Services, Services> {
|
|
|
67
67
|
const challenge = randomBytes(32);
|
|
68
68
|
const { credential } = await this.rpc.AuthService.authenticate({ challenge });
|
|
69
69
|
invariant(credential?.length > 0, 'invalid credential');
|
|
70
|
-
const success = await this.
|
|
70
|
+
const success = await this._authProps.verifier(challenge, credential);
|
|
71
71
|
invariant(success, 'credential not verified');
|
|
72
|
-
runInContext(this._ctx, () => this.
|
|
72
|
+
runInContext(this._ctx, () => this._authProps.onAuthSuccess());
|
|
73
73
|
} catch (err) {
|
|
74
74
|
log('auth failed', err);
|
|
75
75
|
this.close();
|
|
76
|
-
this.
|
|
76
|
+
this._authProps.onAuthFailure();
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, expect,
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
|
+
import { Context } from '@dxos/context';
|
|
7
8
|
import { CredentialGenerator, createCredential } from '@dxos/credentials';
|
|
8
9
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
9
10
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -11,12 +12,12 @@ import { type PublicKey } from '@dxos/keys';
|
|
|
11
12
|
import { log } from '@dxos/log';
|
|
12
13
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
14
|
import { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
14
|
-
import {
|
|
15
|
+
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
15
16
|
import { Timeframe } from '@dxos/timeframe';
|
|
16
17
|
|
|
17
|
-
import { ControlPipeline } from './control-pipeline';
|
|
18
18
|
import { valueEncoding } from '../common';
|
|
19
19
|
import { MetadataStore } from '../metadata';
|
|
20
|
+
import { ControlPipeline } from './control-pipeline';
|
|
20
21
|
|
|
21
22
|
describe('space/control-pipeline', () => {
|
|
22
23
|
test('admits feeds', async () => {
|
|
@@ -59,7 +60,7 @@ describe('space/control-pipeline', () => {
|
|
|
59
60
|
expect(admittedFeeds).toEqual([]);
|
|
60
61
|
|
|
61
62
|
await controlPipeline.setWriteFeed(genesisFeed);
|
|
62
|
-
await controlPipeline.start();
|
|
63
|
+
await controlPipeline.start(Context.default());
|
|
63
64
|
|
|
64
65
|
onTestFinished(() => controlPipeline.stop());
|
|
65
66
|
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { DeferredTask, sleepWithContext, trackLeaks } from '@dxos/async';
|
|
5
|
+
import { DeferredTask, scheduleMicroTask, sleepWithContext, trackLeaks } from '@dxos/async';
|
|
6
6
|
import { Context } from '@dxos/context';
|
|
7
7
|
import {
|
|
8
|
-
SpaceStateMachine,
|
|
9
|
-
type SpaceState,
|
|
10
|
-
type MemberInfo,
|
|
11
|
-
type FeedInfo,
|
|
12
8
|
type DelegateInvitationCredential,
|
|
9
|
+
type FeedInfo,
|
|
10
|
+
type MemberInfo,
|
|
11
|
+
type SpaceState,
|
|
12
|
+
SpaceStateMachine,
|
|
13
13
|
} from '@dxos/credentials';
|
|
14
14
|
import { type FeedWrapper } from '@dxos/feed-store';
|
|
15
15
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -25,7 +25,7 @@ import { type AsyncCallback, Callback, tracer } from '@dxos/util';
|
|
|
25
25
|
import { type MetadataStore } from '../metadata';
|
|
26
26
|
import { Pipeline, type PipelineAccessor } from '../pipeline';
|
|
27
27
|
|
|
28
|
-
export type
|
|
28
|
+
export type ControlPipelineProps = {
|
|
29
29
|
spaceKey: PublicKey;
|
|
30
30
|
genesisFeed: FeedWrapper<FeedMessage>;
|
|
31
31
|
feedProvider: (feedKey: PublicKey) => Promise<FeedWrapper<FeedMessage>>;
|
|
@@ -48,6 +48,7 @@ export class ControlPipeline {
|
|
|
48
48
|
private readonly _pipeline: Pipeline;
|
|
49
49
|
private readonly _spaceStateMachine: SpaceStateMachine;
|
|
50
50
|
|
|
51
|
+
@trace.info({ spanAttribute: true })
|
|
51
52
|
private readonly _spaceKey: PublicKey;
|
|
52
53
|
private readonly _metadata: MetadataStore;
|
|
53
54
|
private _targetTimeframe?: Timeframe;
|
|
@@ -70,7 +71,7 @@ export class ControlPipeline {
|
|
|
70
71
|
await this._saveSnapshot();
|
|
71
72
|
});
|
|
72
73
|
|
|
73
|
-
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }:
|
|
74
|
+
constructor({ spaceKey, genesisFeed, feedProvider, metadataStore }: ControlPipelineProps) {
|
|
74
75
|
this._spaceKey = spaceKey;
|
|
75
76
|
this._metadata = metadataStore;
|
|
76
77
|
this._pipeline = new Pipeline();
|
|
@@ -83,9 +84,12 @@ export class ControlPipeline {
|
|
|
83
84
|
|
|
84
85
|
// TODO(burdon): Check not stopping.
|
|
85
86
|
if (info.assertion.designation === AdmittedFeed.Designation.CONTROL && !info.key.equals(genesisFeed.key)) {
|
|
86
|
-
|
|
87
|
+
scheduleMicroTask(this._ctx, async () => {
|
|
87
88
|
try {
|
|
88
89
|
const feed = await feedProvider(info.key);
|
|
90
|
+
if (this._ctx.disposed) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
89
93
|
if (!this._pipeline.hasFeed(feed.key)) {
|
|
90
94
|
await this._pipeline.addFeed(feed);
|
|
91
95
|
}
|
|
@@ -117,8 +121,8 @@ export class ControlPipeline {
|
|
|
117
121
|
this._pipeline.setWriteFeed(feed);
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
@trace.span({ showInBrowserTimeline: true })
|
|
121
|
-
async start(): Promise<void> {
|
|
124
|
+
@trace.span({ showInBrowserTimeline: true, op: 'lifecycle' })
|
|
125
|
+
async start(ctx: Context): Promise<void> {
|
|
122
126
|
const snapshot = this._metadata.getSpaceControlPipelineSnapshot(this._spaceKey);
|
|
123
127
|
log('load snapshot', { key: this._spaceKey, present: !!snapshot, tf: snapshot?.timeframe });
|
|
124
128
|
if (USE_SNAPSHOTS && snapshot) {
|
|
@@ -127,7 +131,7 @@ export class ControlPipeline {
|
|
|
127
131
|
|
|
128
132
|
log('starting...');
|
|
129
133
|
setTimeout(async () => {
|
|
130
|
-
void this._consumePipeline(
|
|
134
|
+
void this._consumePipeline(ctx);
|
|
131
135
|
});
|
|
132
136
|
|
|
133
137
|
await this._pipeline.start();
|
|
@@ -164,7 +168,6 @@ export class ControlPipeline {
|
|
|
164
168
|
await this._metadata.setSpaceControlPipelineSnapshot(this._spaceKey, snapshot);
|
|
165
169
|
}
|
|
166
170
|
|
|
167
|
-
@trace.span()
|
|
168
171
|
private async _consumePipeline(ctx: Context): Promise<void> {
|
|
169
172
|
for await (const msg of this._pipeline.consume()) {
|
|
170
173
|
const span = this._usage.beginRecording();
|
|
@@ -180,7 +183,7 @@ export class ControlPipeline {
|
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
@trace.span()
|
|
186
|
+
@trace.span({ showInBrowserTimeline: true, showInRemoteTracing: false })
|
|
184
187
|
private async _processMessage(ctx: Context, msg: FeedMessageBlock): Promise<void> {
|
|
185
188
|
log('processing', { key: msg.feedKey, seq: msg.seq });
|
|
186
189
|
if (msg.data.payload.credential) {
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { type AutomergeUrl, parseAutomergeUrl } from '@automerge/automerge-repo';
|
|
6
6
|
|
|
7
|
-
import { synchronized, trackLeaks
|
|
8
|
-
import {
|
|
7
|
+
import { Trigger, synchronized, trackLeaks } from '@dxos/async';
|
|
8
|
+
import { Context } from '@dxos/context';
|
|
9
|
+
import { type DelegateInvitationCredential, type MemberInfo, getCredentialAssertion } from '@dxos/credentials';
|
|
9
10
|
import { failUndefined } from '@dxos/debug';
|
|
10
11
|
import { type FeedStore } from '@dxos/feed-store';
|
|
11
12
|
import { PublicKey } from '@dxos/keys';
|
|
12
13
|
import { log } from '@dxos/log';
|
|
13
14
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
14
|
-
import { trace } from '@dxos/protocols';
|
|
15
15
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
16
16
|
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
17
17
|
import type { Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -19,13 +19,13 @@ import { type Teleport } from '@dxos/teleport';
|
|
|
19
19
|
import { type BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
20
20
|
import { ComplexMap } from '@dxos/util';
|
|
21
21
|
|
|
22
|
+
import { createIdFromSpaceKey } from '../common/space-id';
|
|
23
|
+
import { type MetadataStore } from '../metadata';
|
|
22
24
|
import { CredentialRetrieverExtension } from './admission-discovery-extension';
|
|
23
25
|
import { Space } from './space';
|
|
24
26
|
import { SpaceProtocol, type SwarmIdentity } from './space-protocol';
|
|
25
|
-
import { createIdFromSpaceKey } from '../common/space-id';
|
|
26
|
-
import { type MetadataStore } from '../metadata';
|
|
27
27
|
|
|
28
|
-
export type
|
|
28
|
+
export type SpaceManagerProps = {
|
|
29
29
|
feedStore: FeedStore<FeedMessage>;
|
|
30
30
|
networkManager: SwarmNetworkManager;
|
|
31
31
|
metadataStore: MetadataStore;
|
|
@@ -35,7 +35,7 @@ export type SpaceManagerParams = {
|
|
|
35
35
|
disableP2pReplication?: boolean;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
export type
|
|
38
|
+
export type ConstructSpaceProps = {
|
|
39
39
|
metadata: SpaceMetadata;
|
|
40
40
|
swarmIdentity: SwarmIdentity;
|
|
41
41
|
memberKey: PublicKey;
|
|
@@ -48,7 +48,7 @@ export type ConstructSpaceParams = {
|
|
|
48
48
|
onMemberRolesChanged: (member: MemberInfo[]) => Promise<void>;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export type
|
|
51
|
+
export type RequestSpaceAdmissionCredentialProps = {
|
|
52
52
|
spaceKey: PublicKey;
|
|
53
53
|
identityKey: PublicKey;
|
|
54
54
|
swarmIdentity: SwarmIdentity;
|
|
@@ -65,10 +65,9 @@ export class SpaceManager {
|
|
|
65
65
|
private readonly _networkManager: SwarmNetworkManager;
|
|
66
66
|
private readonly _metadataStore: MetadataStore;
|
|
67
67
|
private readonly _blobStore: BlobStore;
|
|
68
|
-
private readonly _instanceId = PublicKey.random().toHex();
|
|
69
68
|
private readonly _disableP2pReplication: boolean;
|
|
70
69
|
|
|
71
|
-
constructor({ feedStore, networkManager, metadataStore, blobStore, disableP2pReplication }:
|
|
70
|
+
constructor({ feedStore, networkManager, metadataStore, blobStore, disableP2pReplication }: SpaceManagerProps) {
|
|
72
71
|
// TODO(burdon): Assert.
|
|
73
72
|
this._feedStore = feedStore;
|
|
74
73
|
this._networkManager = networkManager;
|
|
@@ -98,8 +97,7 @@ export class SpaceManager {
|
|
|
98
97
|
onDelegatedInvitationStatusChange,
|
|
99
98
|
onMemberRolesChanged,
|
|
100
99
|
memberKey,
|
|
101
|
-
}:
|
|
102
|
-
log.trace('dxos.echo.space-manager.construct-space', trace.begin({ id: this._instanceId }));
|
|
100
|
+
}: ConstructSpaceProps): Promise<Space> {
|
|
103
101
|
log('constructing space...', { spaceKey: metadata.genesisFeedKey });
|
|
104
102
|
|
|
105
103
|
// The genesis feed will be the same as the control feed if the space was created by the local agent.
|
|
@@ -130,13 +128,13 @@ export class SpaceManager {
|
|
|
130
128
|
});
|
|
131
129
|
this._spaces.set(space.key, space);
|
|
132
130
|
|
|
133
|
-
log.trace('dxos.echo.space-manager.construct-space', trace.end({ id: this._instanceId }));
|
|
134
131
|
return space;
|
|
135
132
|
}
|
|
136
133
|
|
|
137
|
-
public async requestSpaceAdmissionCredential(
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
public async requestSpaceAdmissionCredential(
|
|
135
|
+
ctx: Context,
|
|
136
|
+
params: RequestSpaceAdmissionCredentialProps,
|
|
137
|
+
): Promise<Credential> {
|
|
140
138
|
log('requesting space admission credential...', { spaceKey: params.spaceKey });
|
|
141
139
|
|
|
142
140
|
const onCredentialResolved = new Trigger<Credential>();
|
|
@@ -159,15 +157,13 @@ export class SpaceManager {
|
|
|
159
157
|
});
|
|
160
158
|
|
|
161
159
|
try {
|
|
162
|
-
await protocol.start();
|
|
160
|
+
await protocol.start(ctx);
|
|
163
161
|
const credential = await onCredentialResolved.wait({ timeout: params.timeout });
|
|
164
|
-
log.trace(traceKey, trace.end({ id: this._instanceId }));
|
|
165
162
|
return credential;
|
|
166
163
|
} catch (err: any) {
|
|
167
|
-
log.trace(traceKey, trace.error({ id: this._instanceId, error: err }));
|
|
168
164
|
throw err;
|
|
169
165
|
} finally {
|
|
170
|
-
await protocol.stop();
|
|
166
|
+
await protocol.stop(ctx);
|
|
171
167
|
}
|
|
172
168
|
}
|
|
173
169
|
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, expect,
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
|
+
import { Context } from '@dxos/context';
|
|
7
8
|
import { Keyring } from '@dxos/keyring';
|
|
8
9
|
import { PublicKey } from '@dxos/keys';
|
|
9
10
|
import { createStorage } from '@dxos/random-access-storage';
|
|
10
11
|
import { Timeframe } from '@dxos/timeframe';
|
|
11
12
|
|
|
12
|
-
import {
|
|
13
|
+
import { TestAgentBuilder, TestFeedBuilder, WebsocketNetworkManagerProvider } from '../testing';
|
|
13
14
|
|
|
14
15
|
// TODO(burdon): Config.
|
|
15
16
|
// Signal server will be started by the setup script.
|
|
@@ -35,11 +36,11 @@ describe('space/space-protocol', () => {
|
|
|
35
36
|
const presence2 = peer2.createPresence(gossip2);
|
|
36
37
|
const protocol2 = peer2.createSpaceProtocol(topic, gossip2);
|
|
37
38
|
|
|
38
|
-
await protocol1.start();
|
|
39
|
-
await protocol2.start();
|
|
39
|
+
await protocol1.start(Context.default());
|
|
40
|
+
await protocol2.start(Context.default());
|
|
40
41
|
|
|
41
|
-
onTestFinished(() => protocol1.stop());
|
|
42
|
-
onTestFinished(() => protocol2.stop());
|
|
42
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
43
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
43
44
|
|
|
44
45
|
await expect
|
|
45
46
|
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)))
|
|
@@ -62,11 +63,11 @@ describe('space/space-protocol', () => {
|
|
|
62
63
|
const peer2 = await builder.createPeer();
|
|
63
64
|
const protocol2 = peer2.createSpaceProtocol(topic);
|
|
64
65
|
|
|
65
|
-
await protocol1.start();
|
|
66
|
-
await protocol2.start();
|
|
66
|
+
await protocol1.start(Context.default());
|
|
67
|
+
await protocol2.start(Context.default());
|
|
67
68
|
|
|
68
|
-
onTestFinished(() => protocol1.stop());
|
|
69
|
-
onTestFinished(() => protocol2.stop());
|
|
69
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
70
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
70
71
|
|
|
71
72
|
const builder1 = new TestFeedBuilder();
|
|
72
73
|
const feedStore1 = builder1.createFeedStore();
|
|
@@ -109,11 +110,11 @@ describe('space/space-protocol', () => {
|
|
|
109
110
|
const peer2 = await builder.createPeer();
|
|
110
111
|
const protocol2 = peer2.createSpaceProtocol(topic);
|
|
111
112
|
|
|
112
|
-
await protocol1.start();
|
|
113
|
-
await protocol2.start();
|
|
113
|
+
await protocol1.start(Context.default());
|
|
114
|
+
await protocol2.start(Context.default());
|
|
114
115
|
|
|
115
|
-
onTestFinished(() => protocol1.stop());
|
|
116
|
-
onTestFinished(() => protocol2.stop());
|
|
116
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
117
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
117
118
|
|
|
118
119
|
const feedKey = await peer1.keyring.createKey();
|
|
119
120
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, expect,
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
|
+
import { Context } from '@dxos/context';
|
|
7
8
|
import { PublicKey } from '@dxos/keys';
|
|
8
9
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
9
10
|
import { MemoryTransportFactory, SwarmNetworkManager } from '@dxos/network-manager';
|
|
@@ -11,8 +12,8 @@ import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
|
11
12
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
12
13
|
import { Timeframe } from '@dxos/timeframe';
|
|
13
14
|
|
|
14
|
-
import { AuthStatus, MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceProtocol } from './space-protocol';
|
|
15
15
|
import { TestAgentBuilder, TestFeedBuilder } from '../testing';
|
|
16
|
+
import { AuthStatus, MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceProtocol } from './space-protocol';
|
|
16
17
|
|
|
17
18
|
describe('space/space-protocol', () => {
|
|
18
19
|
// Flaky.
|
|
@@ -35,11 +36,11 @@ describe('space/space-protocol', () => {
|
|
|
35
36
|
await presence2.open();
|
|
36
37
|
const protocol2 = peer2.createSpaceProtocol(topic, gossip2);
|
|
37
38
|
|
|
38
|
-
await protocol1.start();
|
|
39
|
-
onTestFinished(() => protocol1.stop());
|
|
39
|
+
await protocol1.start(Context.default());
|
|
40
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
40
41
|
|
|
41
|
-
await protocol2.start();
|
|
42
|
-
onTestFinished(() => protocol2.stop());
|
|
42
|
+
await protocol2.start(Context.default());
|
|
43
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
43
44
|
|
|
44
45
|
await expect
|
|
45
46
|
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)), {
|
|
@@ -95,11 +96,11 @@ describe('space/space-protocol', () => {
|
|
|
95
96
|
}),
|
|
96
97
|
});
|
|
97
98
|
|
|
98
|
-
await protocol1.start();
|
|
99
|
-
onTestFinished(() => protocol1.stop());
|
|
99
|
+
await protocol1.start(Context.default());
|
|
100
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
100
101
|
|
|
101
|
-
await protocol2.start();
|
|
102
|
-
onTestFinished(() => protocol2.stop());
|
|
102
|
+
await protocol2.start(Context.default());
|
|
103
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
103
104
|
|
|
104
105
|
await expect.poll(() => protocol1.sessions.get(peerId2)?.authStatus).toEqual(AuthStatus.FAILURE);
|
|
105
106
|
});
|
|
@@ -118,11 +119,11 @@ describe('space/space-protocol', () => {
|
|
|
118
119
|
const peer2 = await builder.createPeer();
|
|
119
120
|
const protocol2 = peer2.createSpaceProtocol(topic);
|
|
120
121
|
|
|
121
|
-
await protocol1.start();
|
|
122
|
-
await protocol2.start();
|
|
122
|
+
await protocol1.start(Context.default());
|
|
123
|
+
await protocol2.start(Context.default());
|
|
123
124
|
|
|
124
|
-
onTestFinished(() => protocol1.stop());
|
|
125
|
-
onTestFinished(() => protocol2.stop());
|
|
125
|
+
onTestFinished(() => protocol1.stop(Context.default()));
|
|
126
|
+
onTestFinished(() => protocol2.stop(Context.default()));
|
|
126
127
|
|
|
127
128
|
//
|
|
128
129
|
// Create feeds.
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
|
+
import { Context } from '@dxos/context';
|
|
6
7
|
import { discoveryKey, subtleCrypto } from '@dxos/crypto';
|
|
7
8
|
import { type FeedWrapper } from '@dxos/feed-store';
|
|
8
9
|
import { PublicKey } from '@dxos/keys';
|
|
9
10
|
import { log, logInfo } from '@dxos/log';
|
|
10
11
|
import {
|
|
11
12
|
MMSTTopology,
|
|
12
|
-
type SwarmNetworkManager,
|
|
13
13
|
type SwarmConnection,
|
|
14
|
+
type SwarmNetworkManager,
|
|
14
15
|
type WireProtocol,
|
|
15
|
-
type
|
|
16
|
+
type WireProtocolProps,
|
|
16
17
|
type WireProtocolProvider,
|
|
17
18
|
} from '@dxos/network-manager';
|
|
18
19
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
@@ -20,7 +21,7 @@ import { type MuxerStats, Teleport } from '@dxos/teleport';
|
|
|
20
21
|
import { type BlobStore, BlobSync } from '@dxos/teleport-extension-object-sync';
|
|
21
22
|
import { ReplicatorExtension } from '@dxos/teleport-extension-replicator';
|
|
22
23
|
import { trace } from '@dxos/tracing';
|
|
23
|
-
import { CallbackCollection, ComplexMap
|
|
24
|
+
import { type AsyncCallback, CallbackCollection, ComplexMap } from '@dxos/util';
|
|
24
25
|
|
|
25
26
|
import { AuthExtension, type AuthProvider, type AuthVerifier } from './auth';
|
|
26
27
|
|
|
@@ -118,7 +119,10 @@ export class SpaceProtocol {
|
|
|
118
119
|
this.blobSync = new BlobSync({ blobStore });
|
|
119
120
|
|
|
120
121
|
// TODO(burdon): Async race condition? Move to start?
|
|
121
|
-
this._topic = subtleCrypto
|
|
122
|
+
this._topic = subtleCrypto
|
|
123
|
+
.digest('SHA-256', topic.asBuffer() as ArrayBufferView<ArrayBuffer>)
|
|
124
|
+
.then(discoveryKey)
|
|
125
|
+
.then(PublicKey.from);
|
|
122
126
|
|
|
123
127
|
this._disableP2pReplication = disableP2pReplication ?? false;
|
|
124
128
|
}
|
|
@@ -136,7 +140,7 @@ export class SpaceProtocol {
|
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
// TODO(burdon): Rename open? Common open/close interfaces for all services?
|
|
139
|
-
async start(): Promise<void> {
|
|
143
|
+
async start(ctx: Context): Promise<void> {
|
|
140
144
|
if (this._connection) {
|
|
141
145
|
return;
|
|
142
146
|
}
|
|
@@ -148,7 +152,7 @@ export class SpaceProtocol {
|
|
|
148
152
|
|
|
149
153
|
log('starting...');
|
|
150
154
|
const topic = await this._topic;
|
|
151
|
-
this._connection = await this._networkManager.joinSwarm({
|
|
155
|
+
this._connection = await this._networkManager.joinSwarm(ctx, {
|
|
152
156
|
protocolProvider: this._createProtocolProvider(credentials),
|
|
153
157
|
topic,
|
|
154
158
|
topology: this._topology,
|
|
@@ -162,27 +166,27 @@ export class SpaceProtocol {
|
|
|
162
166
|
this._topology.forceUpdate();
|
|
163
167
|
}
|
|
164
168
|
|
|
165
|
-
async stop(): Promise<void> {
|
|
169
|
+
async stop(ctx: Context): Promise<void> {
|
|
166
170
|
await this.blobSync.close();
|
|
167
171
|
|
|
168
172
|
if (this._connection) {
|
|
169
173
|
log('stopping...');
|
|
170
|
-
await this._connection.close();
|
|
174
|
+
await this._connection.close(ctx);
|
|
171
175
|
log('stopped');
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
private _createProtocolProvider(credentials: Uint8Array | undefined): WireProtocolProvider {
|
|
176
|
-
return (
|
|
180
|
+
return (wireProps) => {
|
|
177
181
|
const session = new SpaceProtocolSession({
|
|
178
|
-
|
|
182
|
+
wireProps,
|
|
179
183
|
swarmIdentity: this._swarmIdentity,
|
|
180
184
|
onSessionAuth: this._onSessionAuth,
|
|
181
185
|
onAuthFailure: this._onAuthFailure,
|
|
182
186
|
blobSync: this.blobSync,
|
|
183
187
|
disableP2pReplication: this._disableP2pReplication,
|
|
184
188
|
});
|
|
185
|
-
this._sessions.set(
|
|
189
|
+
this._sessions.set(wireProps.remotePeerId, session);
|
|
186
190
|
|
|
187
191
|
for (const feed of this._feeds) {
|
|
188
192
|
session.replicator.addFeed(feed);
|
|
@@ -193,8 +197,8 @@ export class SpaceProtocol {
|
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
|
|
196
|
-
export type
|
|
197
|
-
|
|
200
|
+
export type SpaceProtocolSessionProps = {
|
|
201
|
+
wireProps: WireProtocolProps;
|
|
198
202
|
swarmIdentity: SwarmIdentity;
|
|
199
203
|
|
|
200
204
|
blobSync: BlobSync;
|
|
@@ -222,7 +226,7 @@ export enum AuthStatus {
|
|
|
222
226
|
*/
|
|
223
227
|
export class SpaceProtocolSession implements WireProtocol {
|
|
224
228
|
@logInfo
|
|
225
|
-
private readonly
|
|
229
|
+
private readonly _wireProps: WireProtocolProps;
|
|
226
230
|
|
|
227
231
|
private readonly _disableP2pReplication: boolean;
|
|
228
232
|
|
|
@@ -249,20 +253,20 @@ export class SpaceProtocolSession implements WireProtocol {
|
|
|
249
253
|
|
|
250
254
|
// TODO(dmaretskyi): Allow to pass in extra extensions.
|
|
251
255
|
constructor({
|
|
252
|
-
|
|
256
|
+
wireProps,
|
|
253
257
|
swarmIdentity,
|
|
254
258
|
onSessionAuth,
|
|
255
259
|
onAuthFailure,
|
|
256
260
|
blobSync,
|
|
257
261
|
disableP2pReplication,
|
|
258
|
-
}:
|
|
259
|
-
this.
|
|
262
|
+
}: SpaceProtocolSessionProps) {
|
|
263
|
+
this._wireProps = wireProps;
|
|
260
264
|
this._swarmIdentity = swarmIdentity;
|
|
261
265
|
this._onSessionAuth = onSessionAuth;
|
|
262
266
|
this._onAuthFailure = onAuthFailure;
|
|
263
267
|
this._blobSync = blobSync;
|
|
264
268
|
|
|
265
|
-
this._teleport = new Teleport(
|
|
269
|
+
this._teleport = new Teleport(wireProps);
|
|
266
270
|
|
|
267
271
|
this._disableP2pReplication = disableP2pReplication ?? false;
|
|
268
272
|
}
|
package/src/space/space.test.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Context } from '@dxos/context';
|
|
8
8
|
import { CredentialGenerator } from '@dxos/credentials';
|
|
@@ -49,7 +49,7 @@ describe('space/space', () => {
|
|
|
49
49
|
const space = await agent.createSpace(agent.identityKey);
|
|
50
50
|
|
|
51
51
|
await space.open(Context.default());
|
|
52
|
-
await space.startProtocol();
|
|
52
|
+
await space.startProtocol(Context.default());
|
|
53
53
|
expect(space.isOpen).toBeTruthy();
|
|
54
54
|
onTestFinished(async () => {
|
|
55
55
|
await space.close();
|
|
@@ -71,7 +71,7 @@ describe('space/space', () => {
|
|
|
71
71
|
const space = await agent.createSpace(agent.identityKey, space1.key, space1.genesisFeedKey, undefined, true);
|
|
72
72
|
|
|
73
73
|
await space.open(Context.default());
|
|
74
|
-
await space.startProtocol();
|
|
74
|
+
await space.startProtocol(Context.default());
|
|
75
75
|
expect(space.isOpen).toBeTruthy();
|
|
76
76
|
onTestFinished(async () => {
|
|
77
77
|
await space.close();
|
package/src/space/space.ts
CHANGED
|
@@ -15,15 +15,15 @@ import { type Timeframe } from '@dxos/timeframe';
|
|
|
15
15
|
import { trace } from '@dxos/tracing';
|
|
16
16
|
import { type AsyncCallback, Callback } from '@dxos/util';
|
|
17
17
|
|
|
18
|
-
import { ControlPipeline } from './control-pipeline';
|
|
19
|
-
import { type SpaceProtocol } from './space-protocol';
|
|
20
18
|
import { type MetadataStore } from '../metadata';
|
|
21
19
|
import { type PipelineAccessor } from '../pipeline';
|
|
20
|
+
import { ControlPipeline } from './control-pipeline';
|
|
21
|
+
import { type SpaceProtocol } from './space-protocol';
|
|
22
22
|
|
|
23
23
|
// TODO(burdon): Factor out?
|
|
24
24
|
type FeedProvider = (feedKey: PublicKey, opts?: FeedOptions) => Promise<FeedWrapper<FeedMessage>>;
|
|
25
25
|
|
|
26
|
-
export type
|
|
26
|
+
export type SpaceProps = {
|
|
27
27
|
id: SpaceId;
|
|
28
28
|
spaceKey: PublicKey;
|
|
29
29
|
protocol: SpaceProtocol;
|
|
@@ -39,7 +39,7 @@ export type SpaceParams = {
|
|
|
39
39
|
onMemberRolesChanged: (member: MemberInfo[]) => Promise<void>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export type
|
|
42
|
+
export type CreatePipelineProps = {
|
|
43
43
|
start: Timeframe;
|
|
44
44
|
// designation: AdmittedFeed.Designation;
|
|
45
45
|
};
|
|
@@ -67,7 +67,7 @@ export class Space extends Resource {
|
|
|
67
67
|
private _controlFeed?: FeedWrapper<FeedMessage>;
|
|
68
68
|
private _dataFeed?: FeedWrapper<FeedMessage>;
|
|
69
69
|
|
|
70
|
-
constructor(params:
|
|
70
|
+
constructor(params: SpaceProps) {
|
|
71
71
|
super();
|
|
72
72
|
invariant(params.spaceKey && params.feedProvider);
|
|
73
73
|
this._id = params.id;
|
|
@@ -171,29 +171,29 @@ export class Space extends Resource {
|
|
|
171
171
|
return Array.from(this._controlPipeline.spaceState.feeds.values());
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
@trace.span()
|
|
174
|
+
@trace.span({ op: 'lifecycle' })
|
|
175
175
|
protected override async _open(ctx: Context): Promise<void> {
|
|
176
176
|
log('opening...');
|
|
177
177
|
|
|
178
178
|
// Order is important.
|
|
179
|
-
await this._controlPipeline.start();
|
|
179
|
+
await this._controlPipeline.start(ctx);
|
|
180
180
|
|
|
181
181
|
log('opened');
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
@synchronized
|
|
185
|
-
public async startProtocol(): Promise<void> {
|
|
185
|
+
public async startProtocol(ctx: Context): Promise<void> {
|
|
186
186
|
invariant(this.isOpen);
|
|
187
|
-
await this.protocol.start();
|
|
187
|
+
await this.protocol.start(ctx);
|
|
188
188
|
await this.protocol.addFeed(await this._feedProvider(this._genesisFeedKey));
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
@synchronized
|
|
192
|
-
protected override async _close(): Promise<void> {
|
|
192
|
+
protected override async _close(ctx: Context): Promise<void> {
|
|
193
193
|
log('closing...', { key: this._key });
|
|
194
194
|
|
|
195
195
|
// Closes in reverse order to open.
|
|
196
|
-
await this.protocol.stop();
|
|
196
|
+
await this.protocol.stop(ctx);
|
|
197
197
|
await this._controlPipeline.stop();
|
|
198
198
|
|
|
199
199
|
log('closed');
|
package/src/testing/index.ts
CHANGED