@dxos/client-services 0.6.13-main.548ca8d → 0.6.13-staging.1e988a3
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-UEQIHAL2.mjs → chunk-4XKSDWEO.mjs} +5218 -5905
- package/dist/lib/browser/chunk-4XKSDWEO.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -3
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -8
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-MA5EWTRH.cjs → chunk-HNOOWB6F.cjs} +5060 -5743
- package/dist/lib/node/chunk-HNOOWB6F.cjs.map +7 -0
- package/dist/lib/node/index.cjs +46 -46
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -14
- package/dist/lib/node/testing/index.cjs.map +3 -3
- 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.test.d.ts +2 -0
- package/dist/types/src/packlets/identity/authenticator.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 +7 -19
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +1 -8
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +1 -2
- 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 +1 -2
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- 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/automerge-host.test.d.ts +2 -0
- package/dist/types/src/packlets/services/automerge-host.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +9 -9
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +0 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +3 -6
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +3 -4
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +0 -3
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- 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 +6 -31
- 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 +2 -1
- 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/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/package.json +39 -43
- package/src/packlets/devices/devices-service.test.ts +5 -4
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +0 -1
- package/src/packlets/identity/{authenticator.node.test.ts → authenticator.test.ts} +3 -2
- package/src/packlets/identity/authenticator.ts +2 -5
- package/src/packlets/identity/contacts-service.ts +1 -1
- package/src/packlets/identity/identity-manager.test.ts +6 -5
- package/src/packlets/identity/identity-manager.ts +19 -35
- package/src/packlets/identity/identity-service.test.ts +8 -4
- package/src/packlets/identity/identity.test.ts +239 -128
- package/src/packlets/identity/identity.ts +8 -42
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -7
- package/src/packlets/invitations/invitation-guest-extenstion.ts +4 -8
- package/src/packlets/invitations/invitation-host-extension.ts +7 -8
- package/src/packlets/invitations/invitations-handler.test.ts +9 -16
- package/src/packlets/invitations/invitations-handler.ts +92 -23
- package/src/packlets/invitations/space-invitation-protocol.test.ts +3 -4
- package/src/packlets/invitations/space-invitation-protocol.ts +0 -4
- package/src/packlets/logging/logging.test.ts +2 -1
- package/src/packlets/network/network-service.test.ts +3 -2
- package/src/packlets/services/automerge-host.test.ts +60 -0
- package/src/packlets/services/service-context.test.ts +1 -3
- package/src/packlets/services/service-context.ts +31 -68
- package/src/packlets/services/service-host.test.ts +12 -8
- package/src/packlets/services/service-host.ts +6 -8
- package/src/packlets/services/service-registry.test.ts +2 -1
- package/src/packlets/spaces/data-space-manager.test.ts +2 -2
- package/src/packlets/spaces/data-space-manager.ts +5 -40
- package/src/packlets/spaces/data-space.ts +6 -34
- package/src/packlets/spaces/edge-feed-replicator.ts +22 -80
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +7 -10
- package/src/packlets/spaces/notarization-plugin.ts +29 -169
- package/src/packlets/spaces/spaces-service.test.ts +9 -5
- package/src/packlets/spaces/spaces-service.ts +1 -6
- package/src/packlets/storage/storage.ts +1 -0
- package/src/packlets/system/system-service.test.ts +2 -1
- package/src/packlets/testing/test-builder.ts +4 -3
- package/src/packlets/worker/worker-runtime.ts +2 -2
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-UEQIHAL2.mjs.map +0 -7
- package/dist/lib/node/chunk-MA5EWTRH.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-AIBLDI4U.mjs +0 -8403
- package/dist/lib/node-esm/chunk-AIBLDI4U.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -416
- 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 -420
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts +0 -2
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts.map +0 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +0 -30
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +0 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts +0 -19
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +0 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +0 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +0 -1
- package/dist/types/src/testing/setup.d.ts +0 -3
- package/dist/types/src/testing/setup.d.ts.map +0 -1
- package/src/packlets/invitations/edge-invitation-handler.ts +0 -184
- package/src/packlets/invitations/invitation-state.ts +0 -111
- package/src/packlets/spaces/edge-feed-replicator.test.ts +0 -253
- package/src/testing/setup.ts +0 -11
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Trigger } from '@dxos/async';
|
|
6
6
|
import { Context, Resource } from '@dxos/context';
|
|
7
7
|
import { getCredentialAssertion, type CredentialProcessor } from '@dxos/credentials';
|
|
8
|
-
import { failUndefined
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
MeshEchoReplicator,
|
|
13
|
-
MetadataStore,
|
|
14
|
-
SpaceManager,
|
|
15
|
-
valueEncoding,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
17
|
-
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
|
-
import type { EdgeHttpClient, EdgeConnection } from '@dxos/edge-client';
|
|
8
|
+
import { failUndefined } from '@dxos/debug';
|
|
9
|
+
import { EchoEdgeReplicator, EchoHost } from '@dxos/echo-db';
|
|
10
|
+
import { MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
11
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
19
12
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
13
|
import { invariant } from '@dxos/invariant';
|
|
21
14
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -30,6 +23,7 @@ import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
|
30
23
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
31
24
|
import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
32
25
|
import { type Storage } from '@dxos/random-access-storage';
|
|
26
|
+
import type { TeleportParams } from '@dxos/teleport';
|
|
33
27
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
34
28
|
import { trace as Trace } from '@dxos/tracing';
|
|
35
29
|
import { safeInstanceof } from '@dxos/util';
|
|
@@ -37,7 +31,7 @@ import { safeInstanceof } from '@dxos/util';
|
|
|
37
31
|
import {
|
|
38
32
|
IdentityManager,
|
|
39
33
|
type CreateIdentityOptions,
|
|
40
|
-
type
|
|
34
|
+
type IdentityManagerRuntimeParams,
|
|
41
35
|
type JoinIdentityParams,
|
|
42
36
|
} from '../identity';
|
|
43
37
|
import {
|
|
@@ -46,16 +40,12 @@ import {
|
|
|
46
40
|
InvitationsManager,
|
|
47
41
|
SpaceInvitationProtocol,
|
|
48
42
|
type InvitationProtocol,
|
|
49
|
-
type InvitationConnectionParams,
|
|
50
43
|
} from '../invitations';
|
|
51
44
|
import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
|
|
52
45
|
|
|
53
|
-
export type ServiceContextRuntimeParams =
|
|
54
|
-
IdentityManagerParams,
|
|
55
|
-
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
56
|
-
> &
|
|
46
|
+
export type ServiceContextRuntimeParams = IdentityManagerRuntimeParams &
|
|
57
47
|
DataSpaceManagerRuntimeParams & {
|
|
58
|
-
invitationConnectionDefaultParams?:
|
|
48
|
+
invitationConnectionDefaultParams?: Partial<TeleportParams>;
|
|
59
49
|
disableP2pReplication?: boolean;
|
|
60
50
|
};
|
|
61
51
|
/**
|
|
@@ -66,8 +56,6 @@ export type ServiceContextRuntimeParams = Pick<
|
|
|
66
56
|
@safeInstanceof('dxos.client-services.ServiceContext')
|
|
67
57
|
@Trace.resource()
|
|
68
58
|
export class ServiceContext extends Resource {
|
|
69
|
-
private readonly _edgeIdentityUpdateMutex = new Mutex();
|
|
70
|
-
|
|
71
59
|
public readonly initialized = new Trigger();
|
|
72
60
|
public readonly metadataStore: MetadataStore;
|
|
73
61
|
public readonly blobStore: BlobStore;
|
|
@@ -99,7 +87,6 @@ export class ServiceContext extends Resource {
|
|
|
99
87
|
public readonly networkManager: SwarmNetworkManager,
|
|
100
88
|
public readonly signalManager: SignalManager,
|
|
101
89
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
102
|
-
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
103
90
|
public readonly _runtimeParams?: ServiceContextRuntimeParams,
|
|
104
91
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
105
92
|
) {
|
|
@@ -129,58 +116,39 @@ export class ServiceContext extends Resource {
|
|
|
129
116
|
disableP2pReplication: this._runtimeParams?.disableP2pReplication,
|
|
130
117
|
});
|
|
131
118
|
|
|
132
|
-
this.identityManager = new IdentityManager(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
edgeConnection: this._edgeConnection,
|
|
140
|
-
edgeFeatures: this._edgeFeatures,
|
|
141
|
-
callbacks: {
|
|
119
|
+
this.identityManager = new IdentityManager(
|
|
120
|
+
this.metadataStore,
|
|
121
|
+
this.keyring,
|
|
122
|
+
this.feedStore,
|
|
123
|
+
this.spaceManager,
|
|
124
|
+
this._runtimeParams as IdentityManagerRuntimeParams,
|
|
125
|
+
{
|
|
142
126
|
onIdentityConstruction: (identity) => {
|
|
143
127
|
if (this._edgeConnection) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
invariant(identity.deviceCredentialChain);
|
|
158
|
-
this._edgeConnection!.setIdentity(
|
|
159
|
-
await createChainEdgeIdentity(
|
|
160
|
-
identity.signer,
|
|
161
|
-
identity.identityKey,
|
|
162
|
-
identity.deviceKey,
|
|
163
|
-
identity.deviceCredentialChain,
|
|
164
|
-
[], // TODO(dmaretskyi): Service access credentials.
|
|
165
|
-
),
|
|
166
|
-
);
|
|
167
|
-
this.networkManager.setPeerInfo({
|
|
168
|
-
identityKey: identity.identityKey.toHex(),
|
|
169
|
-
peerKey: identity.deviceKey.toHex(),
|
|
170
|
-
});
|
|
128
|
+
log.info('Setting identity on edge connection', {
|
|
129
|
+
identity: identity.identityKey.toHex(),
|
|
130
|
+
oldIdentity: this._edgeConnection.identityKey,
|
|
131
|
+
swarms: this.networkManager.topics,
|
|
132
|
+
});
|
|
133
|
+
this._edgeConnection.setIdentity({
|
|
134
|
+
peerKey: identity.deviceKey.toHex(),
|
|
135
|
+
identityKey: identity.identityKey.toHex(),
|
|
136
|
+
});
|
|
137
|
+
this.networkManager.setPeerInfo({
|
|
138
|
+
identityKey: identity.identityKey.toHex(),
|
|
139
|
+
peerKey: identity.deviceKey.toHex(),
|
|
171
140
|
});
|
|
172
141
|
}
|
|
173
142
|
},
|
|
174
143
|
},
|
|
175
|
-
|
|
144
|
+
);
|
|
176
145
|
|
|
177
146
|
this.echoHost = new EchoHost({ kv: this.level });
|
|
178
147
|
|
|
179
148
|
this._meshReplicator = new MeshEchoReplicator();
|
|
180
149
|
|
|
181
150
|
this.invitations = new InvitationsHandler(
|
|
182
|
-
this.networkManager,
|
|
183
|
-
this._edgeHttpClient,
|
|
151
|
+
this.networkManager, //
|
|
184
152
|
_runtimeParams?.invitationConnectionDefaultParams,
|
|
185
153
|
);
|
|
186
154
|
this.invitationsManager = new InvitationsManager(
|
|
@@ -217,11 +185,7 @@ export class ServiceContext extends Resource {
|
|
|
217
185
|
|
|
218
186
|
log('opening...');
|
|
219
187
|
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
220
|
-
|
|
221
|
-
// TODO(dmaretskyi): Use device key.
|
|
222
|
-
this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
|
|
223
|
-
await this._edgeConnection.open();
|
|
224
|
-
}
|
|
188
|
+
await this._edgeConnection?.open();
|
|
225
189
|
await this.signalManager.open();
|
|
226
190
|
await this.networkManager.open();
|
|
227
191
|
|
|
@@ -328,7 +292,6 @@ export class ServiceContext extends Resource {
|
|
|
328
292
|
echoHost: this.echoHost,
|
|
329
293
|
invitationsManager: this.invitationsManager,
|
|
330
294
|
edgeConnection: this._edgeConnection,
|
|
331
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
332
295
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
333
296
|
meshReplicator: this._meshReplicator,
|
|
334
297
|
runtimeParams: this._runtimeParams as DataSpaceManagerRuntimeParams,
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import chai, { expect } from 'chai';
|
|
6
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
5
7
|
import { rmSync } from 'node:fs';
|
|
6
|
-
import { afterEach, onTestFinished, describe, expect, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { asyncTimeout, latch, Trigger } from '@dxos/async';
|
|
9
10
|
import { Config } from '@dxos/config';
|
|
@@ -13,10 +14,13 @@ import { type PublicKey } from '@dxos/keys';
|
|
|
13
14
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
14
15
|
import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
|
|
15
16
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
|
+
import { afterTest, describe, test } from '@dxos/test';
|
|
16
18
|
import { isNode } from '@dxos/util';
|
|
17
19
|
|
|
18
20
|
import { createMockCredential, createServiceHost } from '../testing';
|
|
19
21
|
|
|
22
|
+
chai.use(chaiAsPromised);
|
|
23
|
+
|
|
20
24
|
describe('ClientServicesHost', () => {
|
|
21
25
|
const dataRoot = '/tmp/dxos/client-services/service-host/storage';
|
|
22
26
|
|
|
@@ -34,7 +38,7 @@ describe('ClientServicesHost', () => {
|
|
|
34
38
|
test('queryCredentials', async () => {
|
|
35
39
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
36
40
|
await host.open(new Context());
|
|
37
|
-
|
|
41
|
+
afterTest(() => host.close());
|
|
38
42
|
|
|
39
43
|
await host.services.IdentityService!.createIdentity({});
|
|
40
44
|
const { spaceKey } = await host.services.SpacesService!.createSpace();
|
|
@@ -45,7 +49,7 @@ describe('ClientServicesHost', () => {
|
|
|
45
49
|
tick();
|
|
46
50
|
// console.log(credential);
|
|
47
51
|
});
|
|
48
|
-
|
|
52
|
+
afterTest(() => stream.close());
|
|
49
53
|
|
|
50
54
|
await done();
|
|
51
55
|
});
|
|
@@ -53,7 +57,7 @@ describe('ClientServicesHost', () => {
|
|
|
53
57
|
test('write and query credentials', async () => {
|
|
54
58
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
55
59
|
await host.open(new Context());
|
|
56
|
-
|
|
60
|
+
afterTest(() => host.close());
|
|
57
61
|
|
|
58
62
|
await host.services.IdentityService!.createIdentity({});
|
|
59
63
|
|
|
@@ -82,7 +86,7 @@ describe('ClientServicesHost', () => {
|
|
|
82
86
|
queriedCredential.wake(credential);
|
|
83
87
|
}
|
|
84
88
|
});
|
|
85
|
-
|
|
89
|
+
afterTest(() => credentials.close());
|
|
86
90
|
|
|
87
91
|
await queriedCredential.wait();
|
|
88
92
|
});
|
|
@@ -90,7 +94,7 @@ describe('ClientServicesHost', () => {
|
|
|
90
94
|
test('sign presentation', async () => {
|
|
91
95
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
92
96
|
await host.open(new Context());
|
|
93
|
-
|
|
97
|
+
afterTest(() => host.close());
|
|
94
98
|
|
|
95
99
|
await host.services.IdentityService!.createIdentity({});
|
|
96
100
|
|
|
@@ -143,9 +147,9 @@ describe('ClientServicesHost', () => {
|
|
|
143
147
|
trigger.wake(identity.identity);
|
|
144
148
|
}
|
|
145
149
|
});
|
|
146
|
-
await expect(asyncTimeout(trigger.wait(), 200)).
|
|
150
|
+
await expect(asyncTimeout(trigger.wait(), 200)).to.be.rejectedWith();
|
|
147
151
|
await stream?.close();
|
|
148
152
|
await host.close();
|
|
149
153
|
}
|
|
150
|
-
});
|
|
154
|
+
}).onlyEnvironments('nodejs', 'chromium', 'firefox');
|
|
151
155
|
});
|
|
@@ -6,7 +6,7 @@ import { Event, synchronized } from '@dxos/async';
|
|
|
6
6
|
import { clientServiceBundle, type ClientServices } from '@dxos/client-protocol';
|
|
7
7
|
import { type Config } from '@dxos/config';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { EdgeClient,
|
|
9
|
+
import { EdgeClient, type EdgeConnection } from '@dxos/edge-client';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { type LevelDB } from '@dxos/kv-store';
|
|
@@ -15,7 +15,7 @@ import { EdgeSignalManager, WebsocketSignalManager, type SignalManager } from '@
|
|
|
15
15
|
import {
|
|
16
16
|
SwarmNetworkManager,
|
|
17
17
|
createIceProvider,
|
|
18
|
-
|
|
18
|
+
createSimplePeerTransportFactory,
|
|
19
19
|
type TransportFactory,
|
|
20
20
|
} from '@dxos/network-manager';
|
|
21
21
|
import { trace } from '@dxos/protocols';
|
|
@@ -29,9 +29,9 @@ import { ServiceRegistry } from './service-registry';
|
|
|
29
29
|
import { DevicesServiceImpl } from '../devices';
|
|
30
30
|
import { DevtoolsHostEvents, DevtoolsServiceImpl } from '../devtools';
|
|
31
31
|
import {
|
|
32
|
+
type CollectDiagnosticsBroadcastHandler,
|
|
32
33
|
createCollectDiagnosticsBroadcastHandler,
|
|
33
34
|
createDiagnostics,
|
|
34
|
-
type CollectDiagnosticsBroadcastHandler,
|
|
35
35
|
} from '../diagnostics';
|
|
36
36
|
import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
|
|
37
37
|
import { ContactsServiceImpl } from '../identity/contacts-service';
|
|
@@ -89,7 +89,6 @@ export class ClientServicesHost {
|
|
|
89
89
|
private _callbacks?: ClientServicesHostCallbacks;
|
|
90
90
|
private _devtoolsProxy?: WebsocketRpcClient<{}, ClientServices>;
|
|
91
91
|
private _edgeConnection?: EdgeConnection = undefined;
|
|
92
|
-
private _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
93
92
|
|
|
94
93
|
private _serviceContext!: ServiceContext;
|
|
95
94
|
private readonly _runtimeParams: ServiceContextRuntimeParams;
|
|
@@ -213,13 +212,13 @@ export class ClientServicesHost {
|
|
|
213
212
|
|
|
214
213
|
const edgeEndpoint = config?.get('runtime.services.edge.url');
|
|
215
214
|
if (edgeEndpoint) {
|
|
216
|
-
|
|
217
|
-
this.
|
|
215
|
+
const randomKey = PublicKey.random().toHex();
|
|
216
|
+
this._edgeConnection = new EdgeClient(randomKey, randomKey, { socketEndpoint: edgeEndpoint });
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
const {
|
|
221
220
|
connectionLog = true,
|
|
222
|
-
transportFactory =
|
|
221
|
+
transportFactory = createSimplePeerTransportFactory(
|
|
223
222
|
{ iceServers: this._config?.get('runtime.services.ice') },
|
|
224
223
|
this._config?.get('runtime.services.iceProviders') &&
|
|
225
224
|
createIceProvider(this._config!.get('runtime.services.iceProviders')!),
|
|
@@ -279,7 +278,6 @@ export class ClientServicesHost {
|
|
|
279
278
|
this._networkManager,
|
|
280
279
|
this._signalManager,
|
|
281
280
|
this._edgeConnection,
|
|
282
|
-
this._edgeHttpClient,
|
|
283
281
|
this._runtimeParams,
|
|
284
282
|
this._config.get('runtime.client.edgeFeatures'),
|
|
285
283
|
);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
8
|
import { type ClientServices } from '@dxos/client-protocol';
|
|
@@ -12,6 +12,7 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
import { schema } from '@dxos/protocols/proto';
|
|
13
13
|
import { type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
14
14
|
import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxos/rpc';
|
|
15
|
+
import { describe, test } from '@dxos/test';
|
|
15
16
|
|
|
16
17
|
import { ServiceRegistry } from './service-registry';
|
|
17
18
|
import { SystemServiceImpl } from '../system';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, latch } from '@dxos/async';
|
|
8
8
|
import { createAdmissionCredentials } from '@dxos/credentials';
|
|
@@ -10,7 +10,7 @@ import { AuthStatus } from '@dxos/echo-pipeline';
|
|
|
10
10
|
import { writeMessages } from '@dxos/feed-store';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
13
|
-
import { openAndClose } from '@dxos/test
|
|
13
|
+
import { describe, openAndClose, test } from '@dxos/test';
|
|
14
14
|
|
|
15
15
|
import { TestBuilder, type TestPeer } from '../testing';
|
|
16
16
|
|
|
@@ -14,11 +14,8 @@ 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';
|
|
17
18
|
import {
|
|
18
|
-
convertLegacyReferences,
|
|
19
|
-
findInlineObjectOfType,
|
|
20
|
-
type EchoEdgeReplicator,
|
|
21
|
-
type EchoHost,
|
|
22
19
|
AuthStatus,
|
|
23
20
|
CredentialServerExtension,
|
|
24
21
|
type MeshEchoReplicator,
|
|
@@ -36,7 +33,7 @@ import {
|
|
|
36
33
|
type SpaceDoc,
|
|
37
34
|
} from '@dxos/echo-protocol';
|
|
38
35
|
import { TYPE_PROPERTIES, generateEchoId, getTypeReference } from '@dxos/echo-schema';
|
|
39
|
-
import type { EdgeConnection
|
|
36
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
40
37
|
import { writeMessages, type FeedStore } from '@dxos/feed-store';
|
|
41
38
|
import { invariant } from '@dxos/invariant';
|
|
42
39
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -46,7 +43,7 @@ import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
|
|
|
46
43
|
import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
47
44
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
48
45
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
49
|
-
import { type SpaceMetadata
|
|
46
|
+
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
50
47
|
import { SpaceMember, type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
51
48
|
import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
52
49
|
import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
|
|
@@ -110,7 +107,6 @@ export type DataSpaceManagerParams = {
|
|
|
110
107
|
echoHost: EchoHost;
|
|
111
108
|
invitationsManager: InvitationsManager;
|
|
112
109
|
edgeConnection?: EdgeConnection;
|
|
113
|
-
edgeHttpClient?: EdgeHttpClient;
|
|
114
110
|
meshReplicator?: MeshEchoReplicator;
|
|
115
111
|
echoEdgeReplicator?: EchoEdgeReplicator;
|
|
116
112
|
runtimeParams?: DataSpaceManagerRuntimeParams;
|
|
@@ -139,7 +135,6 @@ export class DataSpaceManager extends Resource {
|
|
|
139
135
|
private readonly _echoHost: EchoHost;
|
|
140
136
|
private readonly _invitationsManager: InvitationsManager;
|
|
141
137
|
private readonly _edgeConnection?: EdgeConnection = undefined;
|
|
142
|
-
private readonly _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
143
138
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
|
|
144
139
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
145
140
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
@@ -159,7 +154,6 @@ export class DataSpaceManager extends Resource {
|
|
|
159
154
|
this._edgeConnection = params.edgeConnection;
|
|
160
155
|
this._edgeFeatures = params.edgeFeatures;
|
|
161
156
|
this._echoEdgeReplicator = params.echoEdgeReplicator;
|
|
162
|
-
this._edgeHttpClient = params.edgeHttpClient;
|
|
163
157
|
this._runtimeParams = params.runtimeParams;
|
|
164
158
|
|
|
165
159
|
trace.diagnostic({
|
|
@@ -394,26 +388,6 @@ export class DataSpaceManager extends Resource {
|
|
|
394
388
|
});
|
|
395
389
|
}
|
|
396
390
|
|
|
397
|
-
async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting) {
|
|
398
|
-
const space = this._spaces.get(spaceKey);
|
|
399
|
-
invariant(space, 'Space not found.');
|
|
400
|
-
|
|
401
|
-
await this._metadataStore.setSpaceEdgeReplicationSetting(spaceKey, setting);
|
|
402
|
-
|
|
403
|
-
if (space.isOpen) {
|
|
404
|
-
switch (setting) {
|
|
405
|
-
case EdgeReplicationSetting.DISABLED:
|
|
406
|
-
await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
|
|
407
|
-
break;
|
|
408
|
-
case EdgeReplicationSetting.ENABLED:
|
|
409
|
-
await this._echoEdgeReplicator?.connectToSpace(space.id);
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
space.stateUpdate.emit();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
391
|
private async _constructSpace(metadata: SpaceMetadata) {
|
|
418
392
|
log('construct space', { metadata });
|
|
419
393
|
const gossip = new Gossip({
|
|
@@ -505,22 +479,13 @@ export class DataSpaceManager extends Resource {
|
|
|
505
479
|
},
|
|
506
480
|
cache: metadata.cache,
|
|
507
481
|
edgeConnection: this._edgeConnection,
|
|
508
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
509
482
|
edgeFeatures: this._edgeFeatures,
|
|
510
483
|
});
|
|
511
484
|
dataSpace.postOpen.append(async () => {
|
|
512
|
-
|
|
513
|
-
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
514
|
-
await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
|
|
515
|
-
} else if (this._echoEdgeReplicator) {
|
|
516
|
-
log('not connecting EchoEdgeReplicator because of EdgeReplicationSetting', { spaceId: dataSpace.id });
|
|
517
|
-
}
|
|
485
|
+
await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
|
|
518
486
|
});
|
|
519
487
|
dataSpace.preClose.append(async () => {
|
|
520
|
-
|
|
521
|
-
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
522
|
-
await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
|
|
523
|
-
}
|
|
488
|
+
await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
|
|
524
489
|
});
|
|
525
490
|
|
|
526
491
|
presence.newPeer.on((peerState) => {
|
|
@@ -7,15 +7,10 @@ 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
|
-
|
|
12
|
-
type DatabaseRoot,
|
|
13
|
-
createMappedFeedWriter,
|
|
14
|
-
type MetadataStore,
|
|
15
|
-
type Space,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
10
|
+
import { type EchoHost, type DatabaseRoot } from '@dxos/echo-db';
|
|
11
|
+
import { createMappedFeedWriter, type MetadataStore, type Space } from '@dxos/echo-pipeline';
|
|
17
12
|
import { SpaceDocVersion } from '@dxos/echo-protocol';
|
|
18
|
-
import type { EdgeConnection
|
|
13
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
19
14
|
import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
20
15
|
import { failedInvariant } from '@dxos/invariant';
|
|
21
16
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -80,7 +75,6 @@ export type DataSpaceParams = {
|
|
|
80
75
|
callbacks?: DataSpaceCallbacks;
|
|
81
76
|
cache?: SpaceCache;
|
|
82
77
|
edgeConnection?: EdgeConnection;
|
|
83
|
-
edgeHttpClient?: EdgeHttpClient;
|
|
84
78
|
edgeFeatures?: Runtime.Client.EdgeFeatures;
|
|
85
79
|
};
|
|
86
80
|
|
|
@@ -102,7 +96,7 @@ export class DataSpace {
|
|
|
102
96
|
private readonly _feedStore: FeedStore<FeedMessage>;
|
|
103
97
|
private readonly _metadataStore: MetadataStore;
|
|
104
98
|
private readonly _signingContext: SigningContext;
|
|
105
|
-
private readonly _notarizationPlugin
|
|
99
|
+
private readonly _notarizationPlugin = new NotarizationPlugin();
|
|
106
100
|
private readonly _callbacks: DataSpaceCallbacks;
|
|
107
101
|
private readonly _cache?: SpaceCache = undefined;
|
|
108
102
|
private readonly _echoHost: EchoHost;
|
|
@@ -142,11 +136,6 @@ export class DataSpace {
|
|
|
142
136
|
this._signingContext = params.signingContext;
|
|
143
137
|
this._callbacks = params.callbacks ?? {};
|
|
144
138
|
this._echoHost = params.echoHost;
|
|
145
|
-
this._notarizationPlugin = new NotarizationPlugin({
|
|
146
|
-
spaceId: this._inner.id,
|
|
147
|
-
edgeClient: params.edgeHttpClient,
|
|
148
|
-
edgeFeatures: params.edgeFeatures,
|
|
149
|
-
});
|
|
150
139
|
|
|
151
140
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
152
141
|
trustedKeysProvider: () =>
|
|
@@ -329,7 +318,6 @@ export class DataSpace {
|
|
|
329
318
|
this._state = SpaceState.SPACE_INITIALIZING;
|
|
330
319
|
log('new state', { state: SpaceState[this._state] });
|
|
331
320
|
|
|
332
|
-
log('initializing control pipeline');
|
|
333
321
|
await this._initializeAndReadControlPipeline();
|
|
334
322
|
|
|
335
323
|
// Allow other tasks to run before loading the data pipeline.
|
|
@@ -337,13 +325,10 @@ export class DataSpace {
|
|
|
337
325
|
|
|
338
326
|
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState.SPACE_READY);
|
|
339
327
|
|
|
340
|
-
log('initializing automerge root');
|
|
341
328
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
342
329
|
|
|
343
330
|
// TODO(dmaretskyi): Change so `initializeDataPipeline` doesn't wait for the space to be READY, but rather any state with a valid root.
|
|
344
|
-
log('waiting for space to be ready');
|
|
345
331
|
await ready;
|
|
346
|
-
log('space is ready');
|
|
347
332
|
}
|
|
348
333
|
|
|
349
334
|
private async _enterReadyState() {
|
|
@@ -360,7 +345,6 @@ export class DataSpace {
|
|
|
360
345
|
private async _initializeAndReadControlPipeline() {
|
|
361
346
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
362
347
|
ctx: this._ctx,
|
|
363
|
-
timeout: 10_000,
|
|
364
348
|
breakOnStall: false,
|
|
365
349
|
});
|
|
366
350
|
|
|
@@ -424,16 +408,8 @@ export class DataSpace {
|
|
|
424
408
|
}
|
|
425
409
|
|
|
426
410
|
if (credentials.length > 0) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// Never times out
|
|
430
|
-
await this.notarizationPlugin.notarize({ ctx: this._ctx, credentials, timeout: 0 });
|
|
431
|
-
|
|
432
|
-
log('credentials notarized');
|
|
433
|
-
} catch (err) {
|
|
434
|
-
log.error('error notarizing credentials for feed admission', err);
|
|
435
|
-
throw err;
|
|
436
|
-
}
|
|
411
|
+
// Never times out
|
|
412
|
+
await this.notarizationPlugin.notarize({ ctx: this._ctx, credentials, timeout: 0 });
|
|
437
413
|
|
|
438
414
|
// Set this after credentials are notarized so that on failure we will retry.
|
|
439
415
|
await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey!, this.inner.dataFeedKey!);
|
|
@@ -570,10 +546,6 @@ export class DataSpace {
|
|
|
570
546
|
this.stateUpdate.emit();
|
|
571
547
|
}
|
|
572
548
|
|
|
573
|
-
getEdgeReplicationSetting() {
|
|
574
|
-
return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
549
|
private _onFeedAdded = async (feed: FeedWrapper<any>) => {
|
|
578
550
|
await this._edgeFeedReplicator!.addFeed(feed);
|
|
579
551
|
};
|