@dxos/teleport-extension-replicator 0.8.4-main.84f28bd → 0.8.4-main.a4bbb77

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.
@@ -1,7 +1,7 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
3
  // src/replicator-extension.ts
4
- import { asyncTimeout, DeferredTask, synchronized } from "@dxos/async";
4
+ import { DeferredTask, asyncTimeout, synchronized } from "@dxos/async";
5
5
  import { Context } from "@dxos/context";
6
6
  import { failUndefined } from "@dxos/debug";
7
7
  import { invariant } from "@dxos/invariant";
@@ -11,6 +11,19 @@ import { RpcClosedError, TimeoutError } from "@dxos/protocols";
11
11
  import { schema } from "@dxos/protocols/proto";
12
12
  import { createProtoRpcPeer } from "@dxos/rpc";
13
13
  import { ComplexMap } from "@dxos/util";
14
+ function _define_property(obj, key, value) {
15
+ if (key in obj) {
16
+ Object.defineProperty(obj, key, {
17
+ value,
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true
21
+ });
22
+ } else {
23
+ obj[key] = value;
24
+ }
25
+ return obj;
26
+ }
14
27
  function _ts_decorate(decorators, target, key, desc) {
15
28
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
29
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -19,41 +32,6 @@ function _ts_decorate(decorators, target, key, desc) {
19
32
  }
20
33
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/teleport-extension-replicator/src/replicator-extension.ts";
21
34
  var ReplicatorExtension = class {
22
- constructor() {
23
- this._ctx = new Context({
24
- onError: (err) => {
25
- this._extensionContext?.close(err);
26
- }
27
- }, {
28
- F: __dxlog_file,
29
- L: 30
30
- });
31
- this._feeds = new ComplexMap(PublicKey.hash);
32
- this._streams = new ComplexMap(PublicKey.hash);
33
- this._options = {
34
- upload: false
35
- };
36
- this._updateTask = new DeferredTask(this._ctx, async () => {
37
- try {
38
- if (this._extensionContext.initiator === false) {
39
- await this._rpc.rpc.ReplicatorService.updateFeeds({
40
- feeds: Array.from(this._feeds.values()).map((feed) => ({
41
- feedKey: feed.key,
42
- download: true,
43
- upload: this._options.upload
44
- }))
45
- });
46
- } else if (this._extensionContext.initiator === true) {
47
- await this._reevaluateFeeds();
48
- }
49
- } catch (err) {
50
- if (err instanceof RpcClosedError) {
51
- return;
52
- }
53
- throw err;
54
- }
55
- });
56
- }
57
35
  get extensionInfo() {
58
36
  return {
59
37
  initiator: this._extensionContext?.initiator,
@@ -68,7 +46,7 @@ var ReplicatorExtension = class {
68
46
  options
69
47
  }, {
70
48
  F: __dxlog_file,
71
- L: 79,
49
+ L: 80,
72
50
  S: this,
73
51
  C: (f, a) => f(...a)
74
52
  });
@@ -83,7 +61,7 @@ var ReplicatorExtension = class {
83
61
  feedKey: feed.key
84
62
  }, {
85
63
  F: __dxlog_file,
86
- L: 88,
64
+ L: 89,
87
65
  S: this,
88
66
  C: (f, a) => f(...a)
89
67
  });
@@ -95,7 +73,7 @@ var ReplicatorExtension = class {
95
73
  this._extensionContext = context;
96
74
  log("open", void 0, {
97
75
  F: __dxlog_file,
98
- L: 96,
76
+ L: 97,
99
77
  S: this,
100
78
  C: (f, a) => f(...a)
101
79
  });
@@ -113,13 +91,13 @@ var ReplicatorExtension = class {
113
91
  feeds
114
92
  }, {
115
93
  F: __dxlog_file,
116
- L: 108,
94
+ L: 109,
117
95
  S: this,
118
96
  C: (f, a) => f(...a)
119
97
  });
120
98
  invariant(this._extensionContext.initiator === true, "Invalid call", {
121
99
  F: __dxlog_file,
122
- L: 109,
100
+ L: 110,
123
101
  S: this,
124
102
  A: [
125
103
  "this._extensionContext!.initiator === true",
@@ -133,13 +111,13 @@ var ReplicatorExtension = class {
133
111
  info
134
112
  }, {
135
113
  F: __dxlog_file,
136
- L: 113,
114
+ L: 114,
137
115
  S: this,
138
116
  C: (f, a) => f(...a)
139
117
  });
140
118
  invariant(this._extensionContext.initiator === false, "Invalid call", {
141
119
  F: __dxlog_file,
142
- L: 114,
120
+ L: 115,
143
121
  S: this,
144
122
  A: [
145
123
  "this._extensionContext!.initiator === false",
@@ -156,13 +134,13 @@ var ReplicatorExtension = class {
156
134
  info
157
135
  }, {
158
136
  F: __dxlog_file,
159
- L: 122,
137
+ L: 123,
160
138
  S: this,
161
139
  C: (f, a) => f(...a)
162
140
  });
163
141
  invariant(this._extensionContext.initiator === false, "Invalid call", {
164
142
  F: __dxlog_file,
165
- L: 124,
143
+ L: 125,
166
144
  S: this,
167
145
  A: [
168
146
  "this._extensionContext!.initiator === false",
@@ -186,7 +164,7 @@ var ReplicatorExtension = class {
186
164
  err
187
165
  }, {
188
166
  F: __dxlog_file,
189
- L: 141,
167
+ L: 142,
190
168
  S: this,
191
169
  C: (f, a) => f(...a)
192
170
  });
@@ -201,7 +179,7 @@ var ReplicatorExtension = class {
201
179
  err
202
180
  }, {
203
181
  F: __dxlog_file,
204
- L: 150,
182
+ L: 151,
205
183
  S: this,
206
184
  C: (f, a) => f(...a)
207
185
  });
@@ -214,7 +192,7 @@ var ReplicatorExtension = class {
214
192
  async _reevaluateFeeds() {
215
193
  log("_reevaluateFeeds", void 0, {
216
194
  F: __dxlog_file,
217
- L: 161,
195
+ L: 162,
218
196
  S: this,
219
197
  C: (f, a) => f(...a)
220
198
  });
@@ -228,7 +206,7 @@ var ReplicatorExtension = class {
228
206
  } catch (err) {
229
207
  log.catch(err, void 0, {
230
208
  F: __dxlog_file,
231
- L: 170,
209
+ L: 171,
232
210
  S: this,
233
211
  C: (f, a) => f(...a)
234
212
  });
@@ -254,13 +232,13 @@ var ReplicatorExtension = class {
254
232
  feedInfo
255
233
  }, {
256
234
  F: __dxlog_file,
257
- L: 191,
235
+ L: 192,
258
236
  S: this,
259
237
  C: (f, a) => f(...a)
260
238
  });
261
239
  invariant(this._extensionContext.initiator === true, "Invalid call", {
262
240
  F: __dxlog_file,
263
- L: 192,
241
+ L: 193,
264
242
  S: this,
265
243
  A: [
266
244
  "this._extensionContext!.initiator === true",
@@ -269,7 +247,7 @@ var ReplicatorExtension = class {
269
247
  });
270
248
  invariant(!this._streams.has(feedInfo.feedKey), `Replication already in progress for feed: ${feedInfo.feedKey}`, {
271
249
  F: __dxlog_file,
272
- L: 193,
250
+ L: 194,
273
251
  S: this,
274
252
  A: [
275
253
  "!this._streams.has(feedInfo.feedKey)",
@@ -291,7 +269,7 @@ var ReplicatorExtension = class {
291
269
  async _acceptReplication(feedInfo) {
292
270
  invariant(this._extensionContext.initiator === false, "Invalid call", {
293
271
  F: __dxlog_file,
294
- L: 208,
272
+ L: 209,
295
273
  S: this,
296
274
  A: [
297
275
  "this._extensionContext!.initiator === false",
@@ -311,13 +289,13 @@ var ReplicatorExtension = class {
311
289
  streamTag
312
290
  }, {
313
291
  F: __dxlog_file,
314
- L: 220,
292
+ L: 221,
315
293
  S: this,
316
294
  C: (f, a) => f(...a)
317
295
  });
318
296
  invariant(!this._streams.has(info.feedKey), `Replication already in progress for feed: ${info.feedKey}`, {
319
297
  F: __dxlog_file,
320
- L: 221,
298
+ L: 222,
321
299
  S: this,
322
300
  A: [
323
301
  "!this._streams.has(info.feedKey)",
@@ -344,7 +322,7 @@ var ReplicatorExtension = class {
344
322
  info
345
323
  }, {
346
324
  F: __dxlog_file,
347
- L: 257,
325
+ L: 258,
348
326
  S: this,
349
327
  C: (f, a) => f(...a)
350
328
  });
@@ -356,7 +334,7 @@ var ReplicatorExtension = class {
356
334
  info
357
335
  }, {
358
336
  F: __dxlog_file,
359
- L: 265,
337
+ L: 266,
360
338
  S: this,
361
339
  C: (f, a) => f(...a)
362
340
  });
@@ -368,7 +346,7 @@ var ReplicatorExtension = class {
368
346
  info
369
347
  }, {
370
348
  F: __dxlog_file,
371
- L: 271,
349
+ L: 272,
372
350
  S: this,
373
351
  C: (f, a) => f(...a)
374
352
  });
@@ -379,7 +357,7 @@ var ReplicatorExtension = class {
379
357
  count: replicationStreamErrors
380
358
  }, {
381
359
  F: __dxlog_file,
382
- L: 273,
360
+ L: 274,
383
361
  S: this,
384
362
  C: (f, a) => f(...a)
385
363
  });
@@ -402,6 +380,43 @@ var ReplicatorExtension = class {
402
380
  stream.networkStream.destroy();
403
381
  this._streams.delete(feedKey);
404
382
  }
383
+ constructor() {
384
+ _define_property(this, "_ctx", new Context({
385
+ onError: (err) => {
386
+ this._extensionContext?.close(err);
387
+ }
388
+ }, {
389
+ F: __dxlog_file,
390
+ L: 31
391
+ }));
392
+ _define_property(this, "_feeds", new ComplexMap(PublicKey.hash));
393
+ _define_property(this, "_streams", new ComplexMap(PublicKey.hash));
394
+ _define_property(this, "_rpc", void 0);
395
+ _define_property(this, "_extensionContext", void 0);
396
+ _define_property(this, "_options", {
397
+ upload: false
398
+ });
399
+ _define_property(this, "_updateTask", new DeferredTask(this._ctx, async () => {
400
+ try {
401
+ if (this._extensionContext.initiator === false) {
402
+ await this._rpc.rpc.ReplicatorService.updateFeeds({
403
+ feeds: Array.from(this._feeds.values()).map((feed) => ({
404
+ feedKey: feed.key,
405
+ download: true,
406
+ upload: this._options.upload
407
+ }))
408
+ });
409
+ } else if (this._extensionContext.initiator === true) {
410
+ await this._reevaluateFeeds();
411
+ }
412
+ } catch (err) {
413
+ if (err instanceof RpcClosedError) {
414
+ return;
415
+ }
416
+ throw err;
417
+ }
418
+ }));
419
+ }
405
420
  };
406
421
  _ts_decorate([
407
422
  logInfo
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/replicator-extension.ts"],
4
- "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport type { ProtocolStream } from 'hypercore-protocol';\nimport { type Duplex } from 'node:stream';\n\nimport { asyncTimeout, DeferredTask, synchronized } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { failUndefined } from '@dxos/debug';\nimport { type FeedWrapper } from '@dxos/feed-store';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log, logInfo } from '@dxos/log';\nimport { RpcClosedError, TimeoutError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type FeedInfo, type ReplicatorService } from '@dxos/protocols/proto/dxos/mesh/teleport/replicator';\nimport { createProtoRpcPeer, type ProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\nimport { ComplexMap } from '@dxos/util';\n\nexport type ReplicationOptions = {\n upload: boolean;\n};\n\n/**\n * Manages replication between a set of feeds for a single teleport session.\n */\nexport class ReplicatorExtension implements TeleportExtension {\n private readonly _ctx = new Context({\n onError: (err) => {\n this._extensionContext?.close(err);\n },\n });\n\n private readonly _feeds = new ComplexMap<PublicKey, FeedWrapper<any>>(PublicKey.hash);\n private readonly _streams = new ComplexMap<PublicKey, ActiveStream>(PublicKey.hash);\n\n private _rpc?: ProtoRpcPeer<ServiceBundle>;\n private _extensionContext?: ExtensionContext;\n\n private _options: ReplicationOptions = {\n upload: false,\n };\n\n private readonly _updateTask = new DeferredTask(this._ctx, async () => {\n try {\n if (this._extensionContext!.initiator === false) {\n await this._rpc!.rpc.ReplicatorService.updateFeeds({\n feeds: Array.from(this._feeds.values()).map((feed) => ({\n feedKey: feed.key,\n download: true,\n upload: this._options.upload,\n })),\n });\n } else if (this._extensionContext!.initiator === true) {\n await this._reevaluateFeeds();\n }\n } catch (err) {\n if (err instanceof RpcClosedError) {\n return; // Some RPC requests might be pending while closing.\n }\n throw err;\n }\n });\n\n @logInfo\n private get extensionInfo() {\n return {\n initiator: this._extensionContext?.initiator,\n localPeerId: this._extensionContext?.localPeerId,\n remotePeerId: this._extensionContext?.remotePeerId,\n feeds: Array.from(this._feeds.keys()),\n };\n }\n\n setOptions(options: ReplicationOptions): this {\n this._options = options;\n log('setOptions', { options });\n if (this._extensionContext) {\n this._updateTask.schedule();\n }\n return this;\n }\n\n addFeed(feed: FeedWrapper<any>): void {\n this._feeds.set(feed.key, feed);\n log('addFeed', { feedKey: feed.key });\n if (this._extensionContext) {\n this._updateTask.schedule();\n }\n }\n\n async onOpen(context: ExtensionContext): Promise<void> {\n this._extensionContext = context;\n log('open');\n\n this._rpc = createProtoRpcPeer<ServiceBundle, ServiceBundle>({\n requested: {\n ReplicatorService: schema.getService('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n exposed: {\n ReplicatorService: schema.getService('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n handlers: {\n ReplicatorService: {\n updateFeeds: async ({ feeds }) => {\n log('received feed info', { feeds });\n invariant(this._extensionContext!.initiator === true, 'Invalid call');\n this._updateTask.schedule();\n },\n startReplication: async ({ info }) => {\n log('starting replication...', { info });\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n const streamTag = await this._acceptReplication(info);\n return {\n streamTag,\n };\n },\n stopReplication: async ({ info }) => {\n log('stopping replication...', { info });\n // TODO(dmaretskyi): Make sure any peer can stop replication.\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n await this._stopReplication(info.feedKey);\n },\n },\n },\n port: await context.createPort('rpc', {\n contentType: 'application/x-protobuf; messageType=\"dxos.rpc.Message\"',\n }),\n timeout: 10_000,\n });\n await this._rpc.open();\n\n this._updateTask.schedule();\n }\n\n async onClose(err?: Error | undefined): Promise<void> {\n log('close', { err });\n await this._ctx.dispose();\n await this._rpc?.close();\n for (const feedKey of this._streams.keys()) {\n await this._stopReplication(feedKey);\n }\n }\n\n async onAbort(err?: Error | undefined): Promise<void> {\n log('abort', { err });\n\n await this._ctx.dispose();\n await this._rpc?.abort();\n for (const feedKey of this._streams.keys()) {\n await this._stopReplication(feedKey);\n }\n }\n\n @synchronized\n private async _reevaluateFeeds(): Promise<void> {\n log('_reevaluateFeeds');\n for (const feedKey of this._feeds.keys()) {\n if (this._ctx.disposed) {\n return;\n }\n if (this._streams.has(feedKey) && this._options.upload !== this._streams.get(feedKey)?.info.upload) {\n try {\n await asyncTimeout(this._stopReplication(feedKey), 1000);\n } catch (err) {\n log.catch(err);\n }\n }\n\n if (this._ctx.disposed) {\n return;\n }\n if (!this._streams.has(feedKey)) {\n await this._initiateReplication({\n feedKey,\n download: true,\n upload: this._options.upload,\n });\n }\n }\n }\n\n /**\n * Try to initiate feed replication.\n */\n private async _initiateReplication(feedInfo: FeedInfo): Promise<void> {\n log('initiating replication', { feedInfo });\n invariant(this._extensionContext!.initiator === true, 'Invalid call');\n invariant(!this._streams.has(feedInfo.feedKey), `Replication already in progress for feed: ${feedInfo.feedKey}`);\n const { streamTag } = await this._rpc!.rpc.ReplicatorService.startReplication({ info: feedInfo });\n if (!streamTag) {\n return;\n }\n\n await this._replicateFeed(feedInfo, streamTag);\n }\n\n /**\n * Respond to a remote request to replicate a feed.\n * @returns A stream tag for the replication stream or `undefined` if we don't want to replicate.\n */\n @synchronized\n private async _acceptReplication(feedInfo: FeedInfo): Promise<string | undefined> {\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n if (!this._feeds.has(feedInfo.feedKey) || this._streams.has(feedInfo.feedKey)) {\n return undefined; // We don't have the feed or we are already replicating it.\n }\n\n const tag = `feed-${feedInfo.feedKey.toHex()}-${PublicKey.random().toHex().slice(0, 8)}`; // Generate a unique tag for the stream.\n await this._replicateFeed(feedInfo, tag);\n return tag;\n }\n\n private async _replicateFeed(info: FeedInfo, streamTag: string): Promise<void> {\n log('replicate', { info, streamTag });\n invariant(!this._streams.has(info.feedKey), `Replication already in progress for feed: ${info.feedKey}`);\n\n const feed = this._feeds.get(info.feedKey) ?? failUndefined();\n const networkStream = await this._extensionContext!.createStream(streamTag, {\n contentType: 'application/x-hypercore',\n });\n let replicationStreamErrors = 0;\n\n // https://github.com/holepunchto/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n const replicationStream = feed.replicate(true, {\n live: true,\n upload: info.upload,\n download: info.download,\n noise: false,\n encrypted: false,\n maxRequests: 1024,\n });\n\n // Left for testing.\n // const debug = true;\n // if (debug) {\n // feed.on('sync', () => {\n // log.info('sync', { key: feed.key, length: feed.length });\n // });\n // feed.on('download', (index: number, data: any) => {\n // log.info('download', {\n // key: feed.key,\n // index,\n // length: feed.length,\n // data: data.length,\n // });\n // });\n // }\n\n replicationStream.on('error', (err) => {\n if (err instanceof TimeoutError) {\n log.info('replication stream timeout', { err, info });\n return;\n }\n // TODO(nf): use sentinel errors\n if (\n err?.message === 'Writable stream closed prematurely' ||\n err?.message === 'Cannot call write after a stream was destroyed'\n ) {\n log('replication stream closed', { err, info });\n return;\n }\n\n // TODO(nf): WARN on first error? log full info on some subsequent errors?\n if (replicationStreamErrors === 0) {\n log.info('replication stream error', { err, info });\n } else {\n log.info('replication stream error', { err, feedKey: info.feedKey, count: replicationStreamErrors });\n }\n replicationStreamErrors++;\n });\n\n this._streams.set(info.feedKey, {\n streamTag,\n networkStream,\n replicationStream,\n info,\n });\n\n networkStream.pipe(replicationStream as any).pipe(networkStream);\n }\n\n private async _stopReplication(feedKey: PublicKey): Promise<void> {\n const stream = this._streams.get(feedKey);\n if (!stream) {\n return;\n }\n\n stream.networkStream.destroy();\n this._streams.delete(feedKey);\n }\n}\n\ntype ServiceBundle = {\n ReplicatorService: ReplicatorService;\n};\n\ntype ActiveStream = {\n streamTag: string;\n networkStream: Duplex;\n replicationStream: ProtocolStream;\n info: FeedInfo;\n};\n"],
5
- "mappings": ";;;AAOA,SAASA,cAAcC,cAAcC,oBAAoB;AACzD,SAASC,eAAe;AACxB,SAASC,qBAAqB;AAE9B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,KAAKC,eAAe;AAC7B,SAASC,gBAAgBC,oBAAoB;AAC7C,SAASC,cAAc;AAEvB,SAASC,0BAA6C;AAEtD,SAASC,kBAAkB;;;;;;;;AASpB,IAAMC,sBAAN,MAAMA;EAAN;AACYC,gBAAO,IAAIZ,QAAQ;MAClCa,SAAS,CAACC,QAAAA;AACR,aAAKC,mBAAmBC,MAAMF,GAAAA;MAChC;IACF,GAAA;;;;AAEiBG,kBAAS,I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,YAAI,6BAA6B;UAAEU;UAAKwC;QAAK,GAAA;;;;;;AAC7C;MACF;AAGA,UAAI4B,4BAA4B,GAAG;AACjC9E,YAAIkD,KAAK,4BAA4B;UAAExC;UAAKwC;QAAK,GAAA;;;;;;MACnD,OAAO;AACLlD,YAAIkD,KAAK,4BAA4B;UAAExC;UAAKoB,SAASoB,KAAKpB;UAASyD,OAAOT;QAAwB,GAAA;;;;;;MACpG;AACAA;IACF,CAAA;AAEA,SAAK/D,SAAS2B,IAAIQ,KAAKpB,SAAS;MAC9BqB;MACAyB;MACAG;MACA7B;IACF,CAAA;AAEA0B,kBAAcY,KAAKT,iBAAAA,EAA0BS,KAAKZ,aAAAA;EACpD;EAEA,MAActB,iBAAiBxB,SAAmC;AAChE,UAAM2D,SAAS,KAAK1E,SAASmD,IAAIpC,OAAAA;AACjC,QAAI,CAAC2D,QAAQ;AACX;IACF;AAEAA,WAAOb,cAAcc,QAAO;AAC5B,SAAK3E,SAAS4E,OAAO7D,OAAAA;EACvB;AACF;;;;;;;;;;",
6
- "names": ["asyncTimeout", "DeferredTask", "synchronized", "Context", "failUndefined", "invariant", "PublicKey", "log", "logInfo", "RpcClosedError", "TimeoutError", "schema", "createProtoRpcPeer", "ComplexMap", "ReplicatorExtension", "_ctx", "onError", "err", "_extensionContext", "close", "_feeds", "hash", "_streams", "_options", "upload", "_updateTask", "initiator", "_rpc", "rpc", "ReplicatorService", "updateFeeds", "feeds", "Array", "from", "values", "map", "feed", "feedKey", "key", "download", "_reevaluateFeeds", "extensionInfo", "localPeerId", "remotePeerId", "keys", "setOptions", "options", "schedule", "addFeed", "set", "onOpen", "context", "requested", "getService", "exposed", "handlers", "startReplication", "info", "streamTag", "_acceptReplication", "stopReplication", "_stopReplication", "port", "createPort", "contentType", "timeout", "open", "onClose", "dispose", "onAbort", "abort", "disposed", "has", "get", "catch", "_initiateReplication", "feedInfo", "_replicateFeed", "undefined", "tag", "toHex", "random", "slice", "networkStream", "createStream", "replicationStreamErrors", "replicationStream", "replicate", "live", "noise", "encrypted", "maxRequests", "on", "message", "count", "pipe", "stream", "destroy", "delete"]
4
+ "sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Duplex } from 'node:stream';\n\nimport type { ProtocolStream } from 'hypercore-protocol';\n\nimport { DeferredTask, asyncTimeout, synchronized } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { failUndefined } from '@dxos/debug';\nimport { type FeedWrapper } from '@dxos/feed-store';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log, logInfo } from '@dxos/log';\nimport { RpcClosedError, TimeoutError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type FeedInfo, type ReplicatorService } from '@dxos/protocols/proto/dxos/mesh/teleport/replicator';\nimport { type ProtoRpcPeer, createProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\nimport { ComplexMap } from '@dxos/util';\n\nexport type ReplicationOptions = {\n upload: boolean;\n};\n\n/**\n * Manages replication between a set of feeds for a single teleport session.\n */\nexport class ReplicatorExtension implements TeleportExtension {\n private readonly _ctx = new Context({\n onError: (err) => {\n this._extensionContext?.close(err);\n },\n });\n\n private readonly _feeds = new ComplexMap<PublicKey, FeedWrapper<any>>(PublicKey.hash);\n private readonly _streams = new ComplexMap<PublicKey, ActiveStream>(PublicKey.hash);\n\n private _rpc?: ProtoRpcPeer<ServiceBundle>;\n private _extensionContext?: ExtensionContext;\n\n private _options: ReplicationOptions = {\n upload: false,\n };\n\n private readonly _updateTask = new DeferredTask(this._ctx, async () => {\n try {\n if (this._extensionContext!.initiator === false) {\n await this._rpc!.rpc.ReplicatorService.updateFeeds({\n feeds: Array.from(this._feeds.values()).map((feed) => ({\n feedKey: feed.key,\n download: true,\n upload: this._options.upload,\n })),\n });\n } else if (this._extensionContext!.initiator === true) {\n await this._reevaluateFeeds();\n }\n } catch (err) {\n if (err instanceof RpcClosedError) {\n return; // Some RPC requests might be pending while closing.\n }\n throw err;\n }\n });\n\n @logInfo\n private get extensionInfo() {\n return {\n initiator: this._extensionContext?.initiator,\n localPeerId: this._extensionContext?.localPeerId,\n remotePeerId: this._extensionContext?.remotePeerId,\n feeds: Array.from(this._feeds.keys()),\n };\n }\n\n setOptions(options: ReplicationOptions): this {\n this._options = options;\n log('setOptions', { options });\n if (this._extensionContext) {\n this._updateTask.schedule();\n }\n return this;\n }\n\n addFeed(feed: FeedWrapper<any>): void {\n this._feeds.set(feed.key, feed);\n log('addFeed', { feedKey: feed.key });\n if (this._extensionContext) {\n this._updateTask.schedule();\n }\n }\n\n async onOpen(context: ExtensionContext): Promise<void> {\n this._extensionContext = context;\n log('open');\n\n this._rpc = createProtoRpcPeer<ServiceBundle, ServiceBundle>({\n requested: {\n ReplicatorService: schema.getService('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n exposed: {\n ReplicatorService: schema.getService('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n handlers: {\n ReplicatorService: {\n updateFeeds: async ({ feeds }) => {\n log('received feed info', { feeds });\n invariant(this._extensionContext!.initiator === true, 'Invalid call');\n this._updateTask.schedule();\n },\n startReplication: async ({ info }) => {\n log('starting replication...', { info });\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n const streamTag = await this._acceptReplication(info);\n return {\n streamTag,\n };\n },\n stopReplication: async ({ info }) => {\n log('stopping replication...', { info });\n // TODO(dmaretskyi): Make sure any peer can stop replication.\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n await this._stopReplication(info.feedKey);\n },\n },\n },\n port: await context.createPort('rpc', {\n contentType: 'application/x-protobuf; messageType=\"dxos.rpc.Message\"',\n }),\n timeout: 10_000,\n });\n await this._rpc.open();\n\n this._updateTask.schedule();\n }\n\n async onClose(err?: Error | undefined): Promise<void> {\n log('close', { err });\n await this._ctx.dispose();\n await this._rpc?.close();\n for (const feedKey of this._streams.keys()) {\n await this._stopReplication(feedKey);\n }\n }\n\n async onAbort(err?: Error | undefined): Promise<void> {\n log('abort', { err });\n\n await this._ctx.dispose();\n await this._rpc?.abort();\n for (const feedKey of this._streams.keys()) {\n await this._stopReplication(feedKey);\n }\n }\n\n @synchronized\n private async _reevaluateFeeds(): Promise<void> {\n log('_reevaluateFeeds');\n for (const feedKey of this._feeds.keys()) {\n if (this._ctx.disposed) {\n return;\n }\n if (this._streams.has(feedKey) && this._options.upload !== this._streams.get(feedKey)?.info.upload) {\n try {\n await asyncTimeout(this._stopReplication(feedKey), 1000);\n } catch (err) {\n log.catch(err);\n }\n }\n\n if (this._ctx.disposed) {\n return;\n }\n if (!this._streams.has(feedKey)) {\n await this._initiateReplication({\n feedKey,\n download: true,\n upload: this._options.upload,\n });\n }\n }\n }\n\n /**\n * Try to initiate feed replication.\n */\n private async _initiateReplication(feedInfo: FeedInfo): Promise<void> {\n log('initiating replication', { feedInfo });\n invariant(this._extensionContext!.initiator === true, 'Invalid call');\n invariant(!this._streams.has(feedInfo.feedKey), `Replication already in progress for feed: ${feedInfo.feedKey}`);\n const { streamTag } = await this._rpc!.rpc.ReplicatorService.startReplication({ info: feedInfo });\n if (!streamTag) {\n return;\n }\n\n await this._replicateFeed(feedInfo, streamTag);\n }\n\n /**\n * Respond to a remote request to replicate a feed.\n * @returns A stream tag for the replication stream or `undefined` if we don't want to replicate.\n */\n @synchronized\n private async _acceptReplication(feedInfo: FeedInfo): Promise<string | undefined> {\n invariant(this._extensionContext!.initiator === false, 'Invalid call');\n\n if (!this._feeds.has(feedInfo.feedKey) || this._streams.has(feedInfo.feedKey)) {\n return undefined; // We don't have the feed or we are already replicating it.\n }\n\n const tag = `feed-${feedInfo.feedKey.toHex()}-${PublicKey.random().toHex().slice(0, 8)}`; // Generate a unique tag for the stream.\n await this._replicateFeed(feedInfo, tag);\n return tag;\n }\n\n private async _replicateFeed(info: FeedInfo, streamTag: string): Promise<void> {\n log('replicate', { info, streamTag });\n invariant(!this._streams.has(info.feedKey), `Replication already in progress for feed: ${info.feedKey}`);\n\n const feed = this._feeds.get(info.feedKey) ?? failUndefined();\n const networkStream = await this._extensionContext!.createStream(streamTag, {\n contentType: 'application/x-hypercore',\n });\n let replicationStreamErrors = 0;\n\n // https://github.com/holepunchto/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n const replicationStream = feed.replicate(true, {\n live: true,\n upload: info.upload,\n download: info.download,\n noise: false,\n encrypted: false,\n maxRequests: 1024,\n });\n\n // Left for testing.\n // const debug = true;\n // if (debug) {\n // feed.on('sync', () => {\n // log.info('sync', { key: feed.key, length: feed.length });\n // });\n // feed.on('download', (index: number, data: any) => {\n // log.info('download', {\n // key: feed.key,\n // index,\n // length: feed.length,\n // data: data.length,\n // });\n // });\n // }\n\n replicationStream.on('error', (err) => {\n if (err instanceof TimeoutError) {\n log.info('replication stream timeout', { err, info });\n return;\n }\n // TODO(nf): use sentinel errors\n if (\n err?.message === 'Writable stream closed prematurely' ||\n err?.message === 'Cannot call write after a stream was destroyed'\n ) {\n log('replication stream closed', { err, info });\n return;\n }\n\n // TODO(nf): WARN on first error? log full info on some subsequent errors?\n if (replicationStreamErrors === 0) {\n log.info('replication stream error', { err, info });\n } else {\n log.info('replication stream error', { err, feedKey: info.feedKey, count: replicationStreamErrors });\n }\n replicationStreamErrors++;\n });\n\n this._streams.set(info.feedKey, {\n streamTag,\n networkStream,\n replicationStream,\n info,\n });\n\n networkStream.pipe(replicationStream as any).pipe(networkStream);\n }\n\n private async _stopReplication(feedKey: PublicKey): Promise<void> {\n const stream = this._streams.get(feedKey);\n if (!stream) {\n return;\n }\n\n stream.networkStream.destroy();\n this._streams.delete(feedKey);\n }\n}\n\ntype ServiceBundle = {\n ReplicatorService: ReplicatorService;\n};\n\ntype ActiveStream = {\n streamTag: string;\n networkStream: Duplex;\n replicationStream: ProtocolStream;\n info: FeedInfo;\n};\n"],
5
+ "mappings": ";;;AAQA,SAASA,cAAcC,cAAcC,oBAAoB;AACzD,SAASC,eAAe;AACxB,SAASC,qBAA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AAKZ,aAAAA;EACpD;EAEA,MAAc9B,iBAAiBf,SAAmC;AAChE,UAAM0D,SAAS,KAAKhC,SAASO,IAAIjC,OAAAA;AACjC,QAAI,CAAC0D,QAAQ;AACX;IACF;AAEAA,WAAOb,cAAcc,QAAO;AAC5B,SAAKjC,SAASkC,OAAO5D,OAAAA;EACvB;;AA1QA,qBAAA,MAAiBuB,QAAO,IAAItD,QAAQ;MAClC4F,SAAS,CAACvC,QAAAA;AACR,aAAKvC,mBAAmB0C,MAAMH,GAAAA;MAChC;IACF,GAAA;;;;AAEA,qBAAA,MAAiBjC,UAAS,IAAIV,WAAwCP,UAAU0F,IAAI,CAAA;AACpF,qBAAA,MAAiBpC,YAAW,IAAI/C,WAAoCP,UAAU0F,IAAI,CAAA;AAElF,qBAAA,MAAQ3D,QAAR,MAAA;AACA,qBAAA,MAAQpB,qBAAR,MAAA;AAEA,qBAAA,MAAQU,YAA+B;MACrCuC,QAAQ;IACV,CAAA;AAEA,qBAAA,MAAiBtC,eAAc,IAAI5B,aAAa,KAAKyD,MAAM,YAAA;AACzD,UAAI;AACF,YAAI,KAAKxC,kBAAmBD,cAAc,OAAO;AAC/C,gBAAM,KAAKqB,KAAMmC,IAAIjC,kBAAkBI,YAAY;YACjDvB,OAAOC,MAAMC,KAAK,KAAKC,OAAO0E,OAAM,CAAA,EAAIC,IAAI,CAACnE,UAAU;cACrDG,SAASH,KAAKE;cACdqC,UAAU;cACVJ,QAAQ,KAAKvC,SAASuC;YACxB,EAAA;UACF,CAAA;QACF,WAAW,KAAKjD,kBAAmBD,cAAc,MAAM;AACrD,gBAAM,KAAK+C,iBAAgB;QAC7B;MACF,SAASP,KAAK;AACZ,YAAIA,eAAe/C,gBAAgB;AACjC;QACF;AACA,cAAM+C;MACR;IACF,CAAA,CAAA;;AAwOF;;;;;;;;;;",
6
+ "names": ["DeferredTask", "asyncTimeout", "synchronized", "Context", "failUndefined", "invariant", "PublicKey", "log", "logInfo", "RpcClosedError", "TimeoutError", "schema", "createProtoRpcPeer", "ComplexMap", "ReplicatorExtension", "extensionInfo", "initiator", "_extensionContext", "localPeerId", "remotePeerId", "feeds", "Array", "from", "_feeds", "keys", "setOptions", "options", "_options", "_updateTask", "schedule", "addFeed", "feed", "set", "key", "feedKey", "onOpen", "context", "_rpc", "requested", "ReplicatorService", "getService", "exposed", "handlers", "updateFeeds", "startReplication", "info", "streamTag", "_acceptReplication", "stopReplication", "_stopReplication", "port", "createPort", "contentType", "timeout", "open", "onClose", "err", "_ctx", "dispose", "close", "_streams", "onAbort", "abort", "_reevaluateFeeds", "disposed", "has", "upload", "get", "catch", "_initiateReplication", "download", "feedInfo", "rpc", "_replicateFeed", "undefined", "tag", "toHex", "random", "slice", "networkStream", "createStream", "replicationStreamErrors", "replicationStream", "replicate", "live", "noise", "encrypted", "maxRequests", "on", "message", "count", "pipe", "stream", "destroy", "delete", "onError", "hash", "values", "map"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/replicator-extension.ts":{"bytes":38831,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":507,"imports":[{"path":"src/replicator-extension.ts","kind":"import-statement","original":"./replicator-extension"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":16530},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["ReplicatorExtension"],"entryPoint":"src/index.ts","inputs":{"src/replicator-extension.ts":{"bytesInOutput":11694},"src/index.ts":{"bytesInOutput":0}},"bytes":11828}}}
1
+ {"inputs":{"src/replicator-extension.ts":{"bytes":39539,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":507,"imports":[{"path":"src/replicator-extension.ts","kind":"import-statement","original":"./replicator-extension"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":16654},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["ReplicatorExtension"],"entryPoint":"src/index.ts","inputs":{"src/replicator-extension.ts":{"bytesInOutput":12143},"src/index.ts":{"bytesInOutput":0}},"bytes":12277}}}