@ibgib/core-gib 0.1.58 → 0.1.59
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/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs +6 -2
- package/dist/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.d.mts +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs +6 -10
- package/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-types.d.mts +13 -1
- package/dist/sync/sync-peer/sync-peer-types.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.d.mts +8 -4
- package/dist/sync/sync-peer/sync-peer-v1.d.mts.map +1 -1
- package/dist/sync/sync-peer/sync-peer-v1.mjs +78 -25
- package/dist/sync/sync-peer/sync-peer-v1.mjs.map +1 -1
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-constants.d.mts +46 -0
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-constants.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-constants.mjs +45 -0
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-constants.mjs.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-types.d.mts +2 -2
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-types.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-types.mjs.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-v1.d.mts +10 -8
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-v1.mjs +102 -58
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-websocket-peer-helpers.d.mts +3 -3
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-websocket-peer-helpers.mjs +6 -6
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-types.d.mts +1 -1
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-types.d.mts.map +1 -0
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-types.mjs.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-v1.d.mts +6 -4
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.d.mts.map +1 -0
- package/dist/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-v1.mjs +46 -25
- package/dist/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mjs.map +1 -0
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts +22 -5
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.d.mts.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs +223 -27
- package/dist/sync/sync-saga-context/sync-saga-context-helpers.mjs.map +1 -1
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts +9 -0
- package/dist/sync/sync-saga-context/sync-saga-context-types.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.d.mts +6 -1
- package/dist/sync/sync-saga-coordinator.d.mts.map +1 -1
- package/dist/sync/sync-saga-coordinator.mjs +49 -11
- package/dist/sync/sync-saga-coordinator.mjs.map +1 -1
- package/dist/sync/sync-types.d.mts +24 -0
- package/dist/sync/sync-types.d.mts.map +1 -1
- package/dist/sync/sync-types.mjs +0 -1
- package/dist/sync/sync-types.mjs.map +1 -1
- package/dist/sync/sync-withid.connect.respec.mjs +3 -3
- package/dist/sync/sync-withid.connect.respec.mjs.map +1 -1
- package/dist/sync/sync-withid.pingpong.respec.d.mts +11 -0
- package/dist/sync/sync-withid.pingpong.respec.d.mts.map +1 -0
- package/dist/sync/sync-withid.pingpong.respec.mjs +131 -0
- package/dist/sync/sync-withid.pingpong.respec.mjs.map +1 -0
- package/dist/witness/space/inner-space/inner-space-v1.d.mts.map +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.mjs +1 -1
- package/dist/witness/space/inner-space/inner-space-v1.mjs.map +1 -1
- package/package.json +1 -1
- package/src/sync/docs/ping_pong_plan.md +147 -0
- package/src/sync/sync-peer/sync-peer-http-receiver/sync-peer-http-receiver-v1.mts +6 -2
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-types.mts +1 -1
- package/src/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mts +10 -13
- package/src/sync/sync-peer/sync-peer-types.mts +18 -1
- package/src/sync/sync-peer/sync-peer-v1.mts +81 -35
- package/src/sync/sync-peer/sync-peer-websocket/sync-peer-websocket-constants.mts +68 -0
- package/src/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-types.mts +2 -2
- package/src/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-v1.mts +116 -68
- package/src/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-websocket-peer-helpers.mts +8 -8
- package/src/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-types.mts +1 -1
- package/src/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-v1.mts +51 -27
- package/src/sync/sync-saga-context/sync-saga-context-helpers.mts +223 -34
- package/src/sync/sync-saga-context/sync-saga-context-types.mts +9 -0
- package/src/sync/sync-saga-coordinator.mts +79 -7
- package/src/sync/sync-types.mts +28 -4
- package/src/sync/sync-withid.connect.respec.mts +3 -3
- package/src/sync/sync-withid.pingpong.respec.mts +161 -0
- package/src/witness/space/inner-space/inner-space-v1.mts +4 -5
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-peer-websocket-receiver-types.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-peer-websocket-receiver-types.mjs.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-peer-websocket-receiver-v1.mjs.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-websocket-peer-helpers.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-receiver/sync-websocket-peer-helpers.mjs.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-sender/sync-peer-websocket-sender-types.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-sender/sync-peer-websocket-sender-types.mjs.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.d.mts.map +0 -1
- package/dist/sync/sync-peer/sync-peer-websocket-sender/sync-peer-websocket-sender-v1.mjs.map +0 -1
- /package/dist/sync/sync-peer/{sync-peer-websocket-receiver → sync-peer-websocket/sync-peer-websocket-receiver}/sync-peer-websocket-receiver-types.mjs +0 -0
- /package/dist/sync/sync-peer/{sync-peer-websocket-sender → sync-peer-websocket/sync-peer-websocket-sender}/sync-peer-websocket-sender-types.mjs +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { IbGibData_V1, IbGibRel8ns_V1, IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
6
|
+
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
6
7
|
|
|
7
8
|
import { SubjectWitness } from '../../common/pubsub/subject/subject-types.mjs';
|
|
8
9
|
import { SyncSagaContextData_V1, SyncSagaContextIbGib_V1, SyncSagaContextRel8ns_V1 } from '../sync-saga-context/sync-saga-context-types.mjs';
|
|
@@ -162,6 +163,12 @@ export interface SyncPeerWitness<TInitializeOpts extends InitializeSyncPeerOpts
|
|
|
162
163
|
*/
|
|
163
164
|
payloadIbGibsDomainReceived$: SubjectWitness<IbGib_V1>;
|
|
164
165
|
|
|
166
|
+
currentSessionIdentity: KeystoneIbGib_V1 | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* convenience getter for {@link currentSessionIdentity}
|
|
169
|
+
*/
|
|
170
|
+
get currentSessionIdentityAddr(): IbGibAddr | undefined;
|
|
171
|
+
|
|
165
172
|
/**
|
|
166
173
|
* Pre-connect phase: creates the session keystone (S) locally, evolves
|
|
167
174
|
* `senderIdentity` (I → I1) with a `sync` claim targeting S, and posts
|
|
@@ -174,7 +181,7 @@ export interface SyncPeerWitness<TInitializeOpts extends InitializeSyncPeerOpts
|
|
|
174
181
|
* this reference for the remainder of the saga. The name `newSenderIdentity`
|
|
175
182
|
* (I1) is intentionally scoped only within this method to avoid confusion.
|
|
176
183
|
*/
|
|
177
|
-
establishSessionIdentity(): Promise<
|
|
184
|
+
establishSessionIdentity(): Promise<void>;
|
|
178
185
|
|
|
179
186
|
/**
|
|
180
187
|
* Establishes the connection context.
|
|
@@ -184,4 +191,14 @@ export interface SyncPeerWitness<TInitializeOpts extends InitializeSyncPeerOpts
|
|
|
184
191
|
* @param opts Connection options, including the sagaId for the upcoming sync saga.
|
|
185
192
|
*/
|
|
186
193
|
connect(opts?: { sagaId?: string }): Promise<void>;
|
|
194
|
+
|
|
195
|
+
// /**
|
|
196
|
+
// * Returns the sender's long-lived primary/domain identity.
|
|
197
|
+
// */
|
|
198
|
+
// getSenderIdentity(): KeystoneIbGib_V1 | undefined;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Evolves the session identity (S_n -> S_n+1) and signs targeting contextAddr.
|
|
202
|
+
*/
|
|
203
|
+
signContext(opts: { contextAddr: IbGibAddr }): Promise<KeystoneIbGib_V1 | undefined>;
|
|
187
204
|
}
|
|
@@ -7,11 +7,8 @@
|
|
|
7
7
|
import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
8
8
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
9
9
|
import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
10
|
-
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
11
|
-
import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
|
|
12
10
|
|
|
13
11
|
import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
|
|
14
|
-
import { SYNC_MSG_REL8N_NAME, SYNC_SAGA_PAYLOAD_ADDRS_DOMAIN } from '../sync-constants.mjs';
|
|
15
12
|
import { SubjectWitness } from '../../common/pubsub/subject/subject-types.mjs';
|
|
16
13
|
import { SyncSagaContextIbGib_V1 } from '../sync-saga-context/sync-saga-context-types.mjs';
|
|
17
14
|
import {
|
|
@@ -19,19 +16,18 @@ import {
|
|
|
19
16
|
SyncPeerRel8ns_V1, SyncPeerWitness
|
|
20
17
|
} from './sync-peer-types.mjs';
|
|
21
18
|
import { LightWitnessBase_V1 } from '../../witness/light-witness-base-v1.mjs';
|
|
22
|
-
import { IbGibSpaceAny } from '../../witness/space/space-base-v1.mjs';
|
|
23
19
|
import { newupSubject } from '../../common/pubsub/subject/subject-helper.mjs';
|
|
24
|
-
import {
|
|
20
|
+
import { authenticateContextIntrinsically, validateContextAndSagaFrame } from '../sync-saga-context/sync-saga-context-helpers.mjs';
|
|
25
21
|
import { getFromSpace } from '../../witness/space/space-helper.mjs';
|
|
26
22
|
import { getFullSyncSagaHistory, deriveSessionSecret } from '../sync-helpers.mjs';
|
|
27
|
-
import { SyncSagaFrameDependencyGraph } from '../sync-types.mjs';
|
|
23
|
+
import { SessionGenesisFrameDetails, SyncSagaFrameDependencyGraph } from '../sync-types.mjs';
|
|
28
24
|
import { KeystoneService_V1 } from '../../keystone/keystone-service-v1.mjs';
|
|
29
25
|
import { KeystoneIbGib_V1 } from '../../keystone/keystone-types.mjs';
|
|
30
|
-
import { KEYSTONE_VERB_SYNC } from '../../keystone/keystone-constants.mjs';
|
|
26
|
+
import { KEYSTONE_VERB_SYNC, } from '../../keystone/keystone-constants.mjs';
|
|
27
|
+
import { getTjpAddr } from '../../common/other/ibgib-helper.mjs';
|
|
28
|
+
import { IbGibAddr } from '@ibgib/ts-gib/dist/types.mjs';
|
|
31
29
|
|
|
32
30
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
33
|
-
const logalotControlDomain = false;
|
|
34
|
-
const lcControlDomain = '[ControlDomain]';
|
|
35
31
|
|
|
36
32
|
|
|
37
33
|
/**
|
|
@@ -54,6 +50,54 @@ export abstract class SyncPeer_V1<
|
|
|
54
50
|
|
|
55
51
|
public opts: TInitializeOpts | undefined;
|
|
56
52
|
public payloadIbGibsDomainReceived$!: SubjectWitness<IbGib_V1>;
|
|
53
|
+
public currentSessionIdentity: KeystoneIbGib_V1 | undefined;
|
|
54
|
+
public get currentSessionIdentityAddr(): IbGibAddr | undefined {
|
|
55
|
+
return this.currentSessionIdentity ?
|
|
56
|
+
getIbGibAddr({ ibGib: this.currentSessionIdentity }) :
|
|
57
|
+
undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// public getSenderIdentity(): KeystoneIbGib_V1 | undefined {
|
|
61
|
+
// return this.opts?.senderIdentity;
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
public async signContext({
|
|
65
|
+
contextAddr,
|
|
66
|
+
}: {
|
|
67
|
+
contextAddr: IbGibAddr;
|
|
68
|
+
}): Promise<KeystoneIbGib_V1 | undefined> {
|
|
69
|
+
const lc = `${this.lc}[${this.signContext.name}]`;
|
|
70
|
+
try {
|
|
71
|
+
if (!this.currentSessionIdentity) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
if (!this.opts) { throw new Error(`opts not initialized. (E: bcf5978aed789b0ebcbdc51971ebe826)`); }
|
|
75
|
+
const { fnSenderSecret, sagaId, localMetaspace, localSpace } = this.opts;
|
|
76
|
+
if (!fnSenderSecret) { throw new Error(`fnSenderSecret not initialized. (E: 207fd292a2e8c53c05fd0a74a4ae6d26)`); }
|
|
77
|
+
if (!sagaId) { throw new Error(`sagaId not initialized. (E: f2e35cc13ed873b638116188119d1826)`); }
|
|
78
|
+
|
|
79
|
+
const senderSecret = await fnSenderSecret();
|
|
80
|
+
const sessionSecret = await deriveSessionSecret({ senderSecret, sagaId });
|
|
81
|
+
|
|
82
|
+
const keystoneSvc = new KeystoneService_V1();
|
|
83
|
+
const evolved = await keystoneSvc.sign({
|
|
84
|
+
latestKeystone: this.currentSessionIdentity,
|
|
85
|
+
masterSecret: sessionSecret,
|
|
86
|
+
claim: {
|
|
87
|
+
verb: KEYSTONE_VERB_SYNC,
|
|
88
|
+
target: contextAddr,
|
|
89
|
+
},
|
|
90
|
+
metaspace: localMetaspace,
|
|
91
|
+
space: localSpace,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
this.currentSessionIdentity = evolved;
|
|
95
|
+
return evolved;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
57
101
|
|
|
58
102
|
get classname(): string {
|
|
59
103
|
if (!this.data) { throw new Error(`(UNEXPECTED) this.data falsy? (E: 1ab1841e9338b54f3aa615fa37024826)`); }
|
|
@@ -127,7 +171,7 @@ export abstract class SyncPeer_V1<
|
|
|
127
171
|
* hold a reference for subsequent per-turn signing. The name
|
|
128
172
|
* `newSenderIdentity` (I1) is scoped only within this method.
|
|
129
173
|
*/
|
|
130
|
-
public async establishSessionIdentity(): Promise<
|
|
174
|
+
public async establishSessionIdentity(): Promise<void> {
|
|
131
175
|
const lc = `${this.lc}[${this.establishSessionIdentity.name}]`;
|
|
132
176
|
try {
|
|
133
177
|
if (logalot) { console.log(`${lc} starting... (I: f2a1b3c4d5e6f7a8b9c0d1e2f3a4b526)`); }
|
|
@@ -141,6 +185,9 @@ export abstract class SyncPeer_V1<
|
|
|
141
185
|
if (logalot) { console.log(`${lc} no senderIdentity/fnSenderSecret — skipping establish (I: f29348a77d1542326d14043ea4b69126)`); }
|
|
142
186
|
return undefined;
|
|
143
187
|
}
|
|
188
|
+
const senderIdentityAddr = getIbGibAddr({ ibGib: senderIdentity });
|
|
189
|
+
const senderIdentityTjpAddr = getTjpAddr({ ibGib: senderIdentity });
|
|
190
|
+
if (!senderIdentityTjpAddr) { throw new Error(`(UNEXPECTED) senderIdentityTjpAddr falsy? (E: d5d8c3ab25a83a2c127904fe96de1526)`); }
|
|
144
191
|
|
|
145
192
|
if (!sagaId) { throw new Error(`(UNEXPECTED) sagaId falsy? Must be set in initializeOpts before calling establishSessionIdentity. (E: c6ba389d51b8af07d82458f875cf9826)`); }
|
|
146
193
|
|
|
@@ -155,10 +202,19 @@ export abstract class SyncPeer_V1<
|
|
|
155
202
|
if (!this.opts.sessionConnectPoolConfig) { throw new Error(`(UNEXPECTED) opts.sessionConnectPoolConfig falsy? (E: 3351fd566eb8bbd2f821bb08c4419826)`); }
|
|
156
203
|
if (!this.opts.sessionSyncPoolConfig) { throw new Error(`(UNEXPECTED) opts.sessionSyncPoolConfig falsy? (E: dbffa810d9e7ff6079088deb5b8e7826)`); }
|
|
157
204
|
|
|
205
|
+
// session genesis keystone should have soft links to both
|
|
206
|
+
// targetAddrs and the sender identity that spawned it.
|
|
207
|
+
const frameDetails: SessionGenesisFrameDetails = {
|
|
208
|
+
senderIdentityAddr,
|
|
209
|
+
senderIdentityTjpAddr,
|
|
210
|
+
}
|
|
211
|
+
if (this.opts.targetAddrs) {
|
|
212
|
+
frameDetails.targetAddrs = this.opts.targetAddrs
|
|
213
|
+
}
|
|
158
214
|
const sessionIdentity = await keystoneSvc.genesis({
|
|
159
215
|
masterSecret: sessionSecret,
|
|
160
216
|
configs: [this.opts.sessionConnectPoolConfig, this.opts.sessionSyncPoolConfig],
|
|
161
|
-
frameDetails
|
|
217
|
+
frameDetails,
|
|
162
218
|
metaspace: localMetaspace,
|
|
163
219
|
space: localSpace,
|
|
164
220
|
});
|
|
@@ -179,7 +235,7 @@ export abstract class SyncPeer_V1<
|
|
|
179
235
|
// Step 3: Post both to the receiver (peer-specific).
|
|
180
236
|
await this.postEstablishToReceiver({ newSenderIdentity, sessionIdentity });
|
|
181
237
|
|
|
182
|
-
|
|
238
|
+
this.currentSessionIdentity = sessionIdentity;
|
|
183
239
|
} catch (error) {
|
|
184
240
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
185
241
|
throw error;
|
|
@@ -257,16 +313,12 @@ export abstract class SyncPeer_V1<
|
|
|
257
313
|
// }
|
|
258
314
|
// }
|
|
259
315
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
protected async authenticateValidateAuthorize({
|
|
316
|
+
protected async authenticateAndValidate({
|
|
263
317
|
context,
|
|
264
|
-
fullSagaHistory,
|
|
265
318
|
}: {
|
|
266
319
|
context: SyncSagaContextIbGib_V1,
|
|
267
|
-
fullSagaHistory: SyncSagaFrameDependencyGraph[],
|
|
268
320
|
}): Promise<void> {
|
|
269
|
-
const lc = `${this.lc}[${this.
|
|
321
|
+
const lc = `${this.lc}[${this.authenticateAndValidate.name}]`;
|
|
270
322
|
try {
|
|
271
323
|
if (logalot) { console.log(`${lc} starting... (I: add238055cd84a222c5b8c89913af526)`); }
|
|
272
324
|
|
|
@@ -274,7 +326,8 @@ export abstract class SyncPeer_V1<
|
|
|
274
326
|
const { localSpace } = this.opts;
|
|
275
327
|
|
|
276
328
|
// first authenticate, because invalid authn is a non-starter
|
|
277
|
-
|
|
329
|
+
// (already validated intrinsically)
|
|
330
|
+
const authenticationErrors = await authenticateContextIntrinsically({
|
|
278
331
|
context,
|
|
279
332
|
space: localSpace,
|
|
280
333
|
});
|
|
@@ -288,12 +341,6 @@ export abstract class SyncPeer_V1<
|
|
|
288
341
|
if (validationErrors.length > 0) {
|
|
289
342
|
throw new Error(`invalid context received. validationErrors: ${validationErrors} (E: 8b34c875c968af29bc433138e57a7826)`);
|
|
290
343
|
}
|
|
291
|
-
// we have a valid authentication that points to a valid context,
|
|
292
|
-
// but what exactly is authorized ?
|
|
293
|
-
const authorizationErrors = await authorizeContext({ context, fullSagaHistory });
|
|
294
|
-
if (authorizationErrors.length > 0) {
|
|
295
|
-
throw new Error(`invalid context authorization. authorizationErrors: ${authorizationErrors} (E: 8ddc284a758cf10ba829334c1babb826)`);
|
|
296
|
-
}
|
|
297
344
|
} catch (error) {
|
|
298
345
|
console.error(`${lc} ${extractErrorMsg(error)}`);
|
|
299
346
|
throw error;
|
|
@@ -361,14 +408,12 @@ export abstract class SyncPeer_V1<
|
|
|
361
408
|
// this is not just happening on the client, but this peer may be
|
|
362
409
|
// the one receiving the context as well.
|
|
363
410
|
|
|
364
|
-
const sagaHistory_beforeSend = await getFullSyncSagaHistory({
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
});
|
|
411
|
+
// const sagaHistory_beforeSend = await getFullSyncSagaHistory({
|
|
412
|
+
// sagaIbGib: context.sagaFrame,
|
|
413
|
+
// space: this.opts.localSpace
|
|
414
|
+
// });
|
|
368
415
|
|
|
369
|
-
await this.
|
|
370
|
-
context, fullSagaHistory: sagaHistory_beforeSend,
|
|
371
|
-
});
|
|
416
|
+
await this.authenticateAndValidate({ context });
|
|
372
417
|
|
|
373
418
|
// at this point, we have a valid, authenticated, authorized context
|
|
374
419
|
|
|
@@ -389,9 +434,10 @@ export abstract class SyncPeer_V1<
|
|
|
389
434
|
space: this.opts.localSpace
|
|
390
435
|
});
|
|
391
436
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
437
|
+
// NOTE: I think this is the wrong place for this, as we must do this in the peer **before** storing any control ibgibs. This needs to be done in the continueSync I _think_ (not sure yet)
|
|
438
|
+
// await this.authenticateValidateAuthorize({
|
|
439
|
+
// context, fullSagaHistory: sagaHistory_afterSend,
|
|
440
|
+
// });
|
|
395
441
|
|
|
396
442
|
return response;
|
|
397
443
|
} else {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// #region SyncWebSocketMsgType enum
|
|
2
|
+
|
|
3
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE_INIT = 'auth-challenge-init';
|
|
4
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_INIT = 'auth-init';
|
|
5
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE = 'auth-challenge';
|
|
6
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_PROOF = 'auth-proof';
|
|
7
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_OK = 'auth-ok';
|
|
8
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_AUTH_FAIL = 'auth-fail';
|
|
9
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME = 'sync-frame';
|
|
10
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE = 'sync-frame-response';
|
|
11
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_AUTHENTICATED = 'sync-frame-authenticated';
|
|
12
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE_AUTHENTICATED = 'sync-frame-response-authenticated';
|
|
13
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_DOMAIN_PAYLOAD = 'domain-payload';
|
|
14
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_SYNC_ERROR = 'sync-error';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Message types transmitted over the stateful WebSocket connection
|
|
18
|
+
* during a sync saga session handshake and execution.
|
|
19
|
+
*/
|
|
20
|
+
export type SyncWebSocketMsgType =
|
|
21
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE_INIT
|
|
22
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_INIT
|
|
23
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE
|
|
24
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_PROOF
|
|
25
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_OK
|
|
26
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_AUTH_FAIL
|
|
27
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME
|
|
28
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE
|
|
29
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_AUTHENTICATED
|
|
30
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE_AUTHENTICATED
|
|
31
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_DOMAIN_PAYLOAD
|
|
32
|
+
| typeof SYNC_WEB_SOCKET_MSG_TYPE_SYNC_ERROR
|
|
33
|
+
;
|
|
34
|
+
|
|
35
|
+
export const SyncWebSocketMsgType = {
|
|
36
|
+
/** Sent by server/receiver to trigger connection authentication. */
|
|
37
|
+
auth_challenge_init: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE_INIT,
|
|
38
|
+
/** Sent by client/sender to start the authentication handshake with the target session address. */
|
|
39
|
+
auth_init: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_INIT,
|
|
40
|
+
/** Sent by server/receiver with dynamic connect challenges to be solved. */
|
|
41
|
+
auth_challenge: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_CHALLENGE,
|
|
42
|
+
/** Sent by client/sender with proof of session keystone evolution solving challenges. */
|
|
43
|
+
auth_proof: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_PROOF,
|
|
44
|
+
/** Sent by server/receiver signaling successful challenge resolution and upgrade to active sync. */
|
|
45
|
+
auth_ok: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_OK,
|
|
46
|
+
/** Sent when authentication fails. */
|
|
47
|
+
auth_fail: SYNC_WEB_SOCKET_MSG_TYPE_AUTH_FAIL,
|
|
48
|
+
/** Sent by client/sender to transmit the next sync transaction context without payload ibgibs. */
|
|
49
|
+
sync_frame: SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME,
|
|
50
|
+
/** Sent by server/receiver responding with the next sync transaction context. */
|
|
51
|
+
sync_frame_response: SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE,
|
|
52
|
+
/** Sent by server/receiver after context is validated/authenticated to signal payload transmission. */
|
|
53
|
+
sync_frame_authenticated: SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_AUTHENTICATED,
|
|
54
|
+
/** Sent by client/sender after response context is validated/authenticated to signal payload transmission. */
|
|
55
|
+
sync_frame_response_authenticated: SYNC_WEB_SOCKET_MSG_TYPE_SYNC_FRAME_RESPONSE_AUTHENTICATED,
|
|
56
|
+
/** Sent to stream a single domain payload ibgib. */
|
|
57
|
+
domain_payload: SYNC_WEB_SOCKET_MSG_TYPE_DOMAIN_PAYLOAD,
|
|
58
|
+
/** Sent when a sync runtime execution error occurs. */
|
|
59
|
+
sync_error: SYNC_WEB_SOCKET_MSG_TYPE_SYNC_ERROR,
|
|
60
|
+
} satisfies { readonly [key: string]: SyncWebSocketMsgType };
|
|
61
|
+
|
|
62
|
+
export const SYNC_WEB_SOCKET_MSG_TYPE_VALID_VALUES: SyncWebSocketMsgType[] = Object.values(SyncWebSocketMsgType);
|
|
63
|
+
|
|
64
|
+
export function isSyncWebSocketMsgType(value: any): value is SyncWebSocketMsgType {
|
|
65
|
+
return SYNC_WEB_SOCKET_MSG_TYPE_VALID_VALUES.includes(value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// #endregion SyncWebSocketMsgType enum
|
|
@@ -5,8 +5,8 @@ import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
|
5
5
|
import {
|
|
6
6
|
SyncPeerData_V1, SyncPeerRel8ns_V1, SyncPeerWitness,
|
|
7
7
|
InitializeSyncPeerOpts, ConnectSyncPeerOpts
|
|
8
|
-
} from '
|
|
9
|
-
import { SyncSagaCoordinator } from '
|
|
8
|
+
} from '../../sync-peer-types.mjs';
|
|
9
|
+
import { SyncSagaCoordinator } from '../../../sync-saga-coordinator.mjs';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Data for the SyncPeerWebSocketReceiver witness.
|
|
@@ -5,21 +5,25 @@
|
|
|
5
5
|
import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
6
6
|
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
7
7
|
import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
8
|
+
import { validateIbGibIntrinsically } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
|
|
9
|
+
|
|
10
|
+
import { GLOBAL_LOG_A_LOT } from '../../../../core-constants.mjs';
|
|
11
|
+
import { SyncPeer_V1 } from '../../sync-peer-v1.mjs';
|
|
12
|
+
import { SyncSagaContextIbGib_V1 } from '../../../sync-saga-context/sync-saga-context-types.mjs';
|
|
13
|
+
import { authenticateContextIntrinsically } from '../../../sync-saga-context/sync-saga-context-helpers.mjs';
|
|
14
|
+
import { IbGibSpaceAny } from '../../../../witness/space/space-base-v1.mjs';
|
|
15
|
+
import { putInSpace, registerNewIbGib } from '../../../../witness/space/space-helper.mjs';
|
|
15
16
|
import {
|
|
16
17
|
ConnectSyncPeerWebSocketReceiverOpts,
|
|
17
18
|
InitializeSyncPeerWebSocketReceiverOpts,
|
|
18
19
|
SyncPeerWebSocketReceiverData_V1, SyncPeerWebSocketReceiverRel8ns_V1,
|
|
19
20
|
SyncPeerWebSocketReceiverIbGib_V1
|
|
20
21
|
} from './sync-peer-websocket-receiver-types.mjs';
|
|
21
|
-
import { KeystoneIbGib_V1 } from '
|
|
22
|
+
import { KeystoneIbGib_V1 } from '../../../../keystone/keystone-types.mjs';
|
|
23
|
+
import { SyncWebSocketMsgType } from '../sync-peer-websocket-constants.mjs';
|
|
22
24
|
import { SESSION_KEYSTONE_POLICY, verifyConnectProof } from './sync-websocket-peer-helpers.mjs';
|
|
25
|
+
import { getFullSyncSagaHistory } from '../../../sync-helpers.mjs';
|
|
26
|
+
import { toDto } from '../../../../common/other/ibgib-helper.mjs';
|
|
23
27
|
|
|
24
28
|
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
25
29
|
|
|
@@ -59,6 +63,11 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
59
63
|
protected demandedIds?: string[];
|
|
60
64
|
protected sessionS_tjpAddr?: string;
|
|
61
65
|
|
|
66
|
+
// Runtime state variables for delayed payload streaming
|
|
67
|
+
protected pendingContext?: SyncSagaContextIbGib_V1;
|
|
68
|
+
protected pendingPayloadAddrs?: Set<string>;
|
|
69
|
+
protected pendingResponsePayloadsToSend: IbGib_V1[] = [];
|
|
70
|
+
|
|
62
71
|
constructor(
|
|
63
72
|
initialData: SyncPeerWebSocketReceiverData_V1,
|
|
64
73
|
initialRel8ns?: SyncPeerWebSocketReceiverRel8ns_V1,
|
|
@@ -79,13 +88,13 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
79
88
|
try {
|
|
80
89
|
this.challengeUuid = await getUUID();
|
|
81
90
|
socketWrapper.send(JSON.stringify({
|
|
82
|
-
type:
|
|
91
|
+
type: SyncWebSocketMsgType.auth_challenge_init,
|
|
83
92
|
challengeUuid: this.challengeUuid
|
|
84
93
|
}));
|
|
85
94
|
} catch (error) {
|
|
86
95
|
console.error(`${lc} failed triggering challenge init: ${extractErrorMsg(error)}`);
|
|
87
96
|
socketWrapper.send(JSON.stringify({
|
|
88
|
-
type:
|
|
97
|
+
type: SyncWebSocketMsgType.auth_fail,
|
|
89
98
|
message: 'Internal server connect error'
|
|
90
99
|
}));
|
|
91
100
|
}
|
|
@@ -171,39 +180,90 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
// 2. Authenticated Runtime Sync Route
|
|
174
|
-
if (msg.type ===
|
|
183
|
+
if (msg.type === SyncWebSocketMsgType.domain_payload) {
|
|
175
184
|
const ibGib = msg.ibGib as IbGib_V1;
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
const validationErrors =
|
|
186
|
+
await validateIbGibIntrinsically({ ibGib }) ?? [];
|
|
187
|
+
if (validationErrors.length > 0) {
|
|
188
|
+
throw new Error(`controlIbGibs invalid intrinsically. validationErrors: ${validationErrors.join('|')} (E: 5ee1787d4cc53d3d2c55f3d4f2865226)`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (this.pendingContext && this.pendingPayloadAddrs) {
|
|
192
|
+
const addr = getIbGibAddr({ ibGib });
|
|
193
|
+
if (this.pendingPayloadAddrs.has(addr)) {
|
|
194
|
+
const tempSpace = await this.ensureLocalTempSpace();
|
|
195
|
+
await putInSpace({ space: tempSpace, ibGibs: [ibGib] });
|
|
196
|
+
this.pendingPayloadAddrs.delete(addr);
|
|
197
|
+
|
|
198
|
+
// If all expected payloads for the pending context are received
|
|
199
|
+
if (this.pendingPayloadAddrs.size === 0) {
|
|
200
|
+
const context = this.pendingContext;
|
|
201
|
+
this.pendingContext = undefined;
|
|
202
|
+
this.pendingPayloadAddrs = undefined;
|
|
203
|
+
|
|
204
|
+
await this.executeIncomingSyncRequestAndRespond({ context });
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
console.warn(`${lc} received payload not in expected list: ${addr}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} else if (msg.type === SyncWebSocketMsgType.sync_frame) {
|
|
179
211
|
const context = msg.context as SyncSagaContextIbGib_V1;
|
|
180
212
|
|
|
181
|
-
//
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
// First, validate and authenticate the context
|
|
214
|
+
const allControlIbGibs: IbGib_V1[] = [
|
|
215
|
+
toDto({ ibGib: context }),
|
|
216
|
+
context.sagaFrame
|
|
217
|
+
];
|
|
218
|
+
if (context.signedSessionIdentity) {
|
|
219
|
+
allControlIbGibs.push(context.signedSessionIdentity);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const controlIbGib of allControlIbGibs) {
|
|
223
|
+
const validationErrors =
|
|
224
|
+
await validateIbGibIntrinsically({ ibGib: controlIbGib }) ?? [];
|
|
225
|
+
if (validationErrors.length > 0) {
|
|
226
|
+
throw new Error(`controlIbGibs invalid intrinsically. validationErrors: ${validationErrors.join('|')} (E: d40dfa87265a0b73c8ef784d1265ea26)`);
|
|
192
227
|
}
|
|
228
|
+
}
|
|
193
229
|
|
|
194
|
-
|
|
230
|
+
await this.authenticateAndValidate({ context });
|
|
231
|
+
|
|
232
|
+
// Put control ibgibs into durable space immediately for audit trail
|
|
233
|
+
for (const ibGib of allControlIbGibs) {
|
|
234
|
+
await putInSpace({ space: this.opts!.localSpace, ibGibs: [ibGib] });
|
|
235
|
+
await registerNewIbGib({ space: this.opts!.localSpace, ibGib });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Check if payloads are expected
|
|
239
|
+
const expectedPayloadAddrs = context.data?.['@payloadAddrsDomain'] || [];
|
|
240
|
+
if (expectedPayloadAddrs.length > 0) {
|
|
241
|
+
// Set up wait state and request payloads
|
|
242
|
+
this.pendingContext = context;
|
|
243
|
+
this.pendingPayloadAddrs = new Set(expectedPayloadAddrs);
|
|
195
244
|
this.socketWrapper.send(JSON.stringify({
|
|
196
|
-
type:
|
|
197
|
-
|
|
245
|
+
type: SyncWebSocketMsgType.sync_frame_authenticated,
|
|
246
|
+
contextAddr: getIbGibAddr({ ibGib: context })
|
|
198
247
|
}));
|
|
199
248
|
} else {
|
|
200
|
-
|
|
249
|
+
// No payloads expected, process immediately
|
|
250
|
+
await this.executeIncomingSyncRequestAndRespond({ context });
|
|
251
|
+
}
|
|
252
|
+
} else if (msg.type === SyncWebSocketMsgType.sync_frame_response_authenticated) {
|
|
253
|
+
// Alice authenticated our response context, stream our payloads now
|
|
254
|
+
const payloads = this.pendingResponsePayloadsToSend || [];
|
|
255
|
+
this.pendingResponsePayloadsToSend = [];
|
|
256
|
+
for (const ibGib of payloads) {
|
|
257
|
+
this.socketWrapper.send(JSON.stringify({
|
|
258
|
+
type: SyncWebSocketMsgType.domain_payload,
|
|
259
|
+
ibGib
|
|
260
|
+
}));
|
|
201
261
|
}
|
|
202
262
|
}
|
|
203
263
|
} catch (error) {
|
|
204
264
|
console.error(`${lc} message frame handling failed: ${extractErrorMsg(error)}`);
|
|
205
265
|
this.socketWrapper?.send(JSON.stringify({
|
|
206
|
-
type: this.isAuthenticated ?
|
|
266
|
+
type: this.isAuthenticated ? SyncWebSocketMsgType.sync_error : SyncWebSocketMsgType.auth_fail,
|
|
207
267
|
message: extractErrorMsg(error)
|
|
208
268
|
}));
|
|
209
269
|
}
|
|
@@ -217,7 +277,7 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
217
277
|
const metaspace = this.opts!.localMetaspace;
|
|
218
278
|
const space = this.opts!.localSpace;
|
|
219
279
|
|
|
220
|
-
if (msg.type ===
|
|
280
|
+
if (msg.type === SyncWebSocketMsgType.auth_init) {
|
|
221
281
|
const { sAddr } = msg;
|
|
222
282
|
if (logalot) { console.log(`${lc} auth-init for ${sAddr}`); }
|
|
223
283
|
|
|
@@ -237,12 +297,12 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
237
297
|
this.sessionS_tjpAddr = (past && past.length > 0) ? past[0] : getIbGibAddr({ ibGib: authorizedS });
|
|
238
298
|
|
|
239
299
|
this.socketWrapper!.send(JSON.stringify({
|
|
240
|
-
type:
|
|
300
|
+
type: SyncWebSocketMsgType.auth_challenge,
|
|
241
301
|
challengeUuid: this.challengeUuid,
|
|
242
302
|
demandedIds: this.demandedIds
|
|
243
303
|
}));
|
|
244
304
|
|
|
245
|
-
} else if (msg.type ===
|
|
305
|
+
} else if (msg.type === SyncWebSocketMsgType.auth_proof) {
|
|
246
306
|
const { proofFrame } = msg;
|
|
247
307
|
if (logalot) { console.log(`${lc} verifying auth-proof...`); }
|
|
248
308
|
|
|
@@ -272,7 +332,7 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
272
332
|
this.isAuthenticated = true;
|
|
273
333
|
|
|
274
334
|
this.socketWrapper!.send(JSON.stringify({
|
|
275
|
-
type:
|
|
335
|
+
type: SyncWebSocketMsgType.auth_ok
|
|
276
336
|
}));
|
|
277
337
|
} else {
|
|
278
338
|
throw new Error(`Unexpected message type ${msg.type} during connect phase (E: f67a0f47f8426c2b01af5bc3d0146b26)`);
|
|
@@ -280,57 +340,45 @@ export class SyncPeerWebSocketReceiver_V1
|
|
|
280
340
|
}
|
|
281
341
|
|
|
282
342
|
/**
|
|
283
|
-
* Executes the
|
|
343
|
+
* Executes the incoming sync request through the local SyncSagaCoordinator and sends response.
|
|
284
344
|
*/
|
|
285
|
-
|
|
286
|
-
context
|
|
287
|
-
payloadIbGibsControl = [],
|
|
345
|
+
protected async executeIncomingSyncRequestAndRespond({
|
|
346
|
+
context
|
|
288
347
|
}: {
|
|
289
348
|
context: SyncSagaContextIbGib_V1;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const lc = `${this.lc}[${this.handleIncomingSyncRequest.name}]`;
|
|
349
|
+
}): Promise<void> {
|
|
350
|
+
const lc = `${this.lc}[${this.executeIncomingSyncRequestAndRespond.name}]`;
|
|
293
351
|
try {
|
|
294
|
-
if (logalot) { console.log(`${lc}
|
|
352
|
+
if (logalot) { console.log(`${lc} executing incoming sync turn...`); }
|
|
295
353
|
|
|
296
354
|
if (!this.opts) { throw new Error(`opts not initialized. (E: 0c98186714e85b9a08bb9d98daada826)`); }
|
|
297
355
|
const { localCoordinator, localMetaspace, localSpace } = this.opts;
|
|
298
356
|
const localTempSpace = await this.ensureLocalTempSpace();
|
|
299
357
|
|
|
300
|
-
// Put control ibgibs into durable space
|
|
301
|
-
const allControlIbGibs = [context, ...payloadIbGibsControl];
|
|
302
|
-
for (const ibGib of allControlIbGibs) {
|
|
303
|
-
await putInSpace({ space: localSpace, ibGibs: [ibGib] });
|
|
304
|
-
await registerNewIbGib({ space: localSpace, ibGib });
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// Authenticate context signature
|
|
308
|
-
const authErrors = await authenticateContext({
|
|
309
|
-
context,
|
|
310
|
-
space: localSpace,
|
|
311
|
-
});
|
|
312
|
-
if (authErrors.length > 0) {
|
|
313
|
-
throw new Error(`Context authentication failed: ${authErrors.join(', ')} (E: 424bd9b03ff8a42df8b1a438ed393726)`);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Put incoming domain payloads into temp space
|
|
317
|
-
if (context.payloadIbGibsDomain && context.payloadIbGibsDomain.length > 0) {
|
|
318
|
-
for (const ibGib of context.payloadIbGibsDomain) {
|
|
319
|
-
await putInSpace({ space: localTempSpace, ibGibs: [ibGib] });
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Evolve frame and run next coordinator sync turn
|
|
324
358
|
const responseCtx = await localCoordinator.continueSync({
|
|
325
359
|
sagaContext: context,
|
|
326
360
|
metaspace: localMetaspace,
|
|
327
361
|
mySpace: localSpace,
|
|
328
362
|
myTempSpace: localTempSpace,
|
|
363
|
+
peer: this,
|
|
329
364
|
});
|
|
330
365
|
|
|
331
|
-
|
|
366
|
+
if (responseCtx) {
|
|
367
|
+
const responsePayloads = responseCtx.payloadIbGibsDomain ?? [];
|
|
368
|
+
delete responseCtx.payloadIbGibsDomain;
|
|
369
|
+
|
|
370
|
+
// Save payloads to stream once authenticated by Alice
|
|
371
|
+
this.pendingResponsePayloadsToSend = responsePayloads;
|
|
372
|
+
|
|
373
|
+
this.socketWrapper!.send(JSON.stringify({
|
|
374
|
+
type: SyncWebSocketMsgType.sync_frame_response,
|
|
375
|
+
context: responseCtx
|
|
376
|
+
}));
|
|
377
|
+
} else {
|
|
378
|
+
if (logalot) { console.log(`${lc} synchronization session completed successfully.`); }
|
|
379
|
+
}
|
|
332
380
|
} catch (error) {
|
|
333
|
-
console.error(`${lc}
|
|
381
|
+
console.error(`${lc} executeIncomingSyncRequestAndRespond failed: ${extractErrorMsg(error)}`);
|
|
334
382
|
throw error;
|
|
335
383
|
}
|
|
336
384
|
}
|
|
@@ -11,17 +11,17 @@ import { validateIbGibAddr, validateIbGibIntrinsically } from '@ibgib/ts-gib/dis
|
|
|
11
11
|
import { getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
12
12
|
import { IbGib_V1 } from '@ibgib/ts-gib/dist/V1/types.mjs';
|
|
13
13
|
|
|
14
|
-
import { GLOBAL_LOG_A_LOT } from '
|
|
14
|
+
import { GLOBAL_LOG_A_LOT } from '../../../../core-constants.mjs';
|
|
15
15
|
import {
|
|
16
16
|
KeystoneReplenishStrategy, KeystoneChallengeType, KeystoneIbGib_V1,
|
|
17
17
|
KeystoneSolution, KeystoneChallenge
|
|
18
|
-
} from '
|
|
19
|
-
import { parseKeystoneIb } from '
|
|
20
|
-
import { KeystoneStrategyFactory } from '
|
|
21
|
-
import { KeystoneService_V1 } from '
|
|
22
|
-
import { IbGibSpaceAny } from '
|
|
23
|
-
import { MetaspaceService } from '
|
|
24
|
-
import { POOL_ID_CONNECT, KEYSTONE_VERB_CONNECT } from '
|
|
18
|
+
} from '../../../../keystone/keystone-types.mjs';
|
|
19
|
+
import { parseKeystoneIb } from '../../../../keystone/keystone-helpers.mjs';
|
|
20
|
+
import { KeystoneStrategyFactory } from '../../../../keystone/strategy/keystone-strategy-factory.mjs';
|
|
21
|
+
import { KeystoneService_V1 } from '../../../../keystone/keystone-service-v1.mjs';
|
|
22
|
+
import { IbGibSpaceAny } from '../../../../witness/space/space-base-v1.mjs';
|
|
23
|
+
import { MetaspaceService } from '../../../../witness/space/metaspace/metaspace-types.mjs';
|
|
24
|
+
import { POOL_ID_CONNECT, KEYSTONE_VERB_CONNECT } from '../../../../keystone/keystone-constants.mjs';
|
|
25
25
|
|
|
26
26
|
const logalot = GLOBAL_LOG_A_LOT
|
|
27
27
|
|