@dxos/teleport-extension-replicator 0.16.0 → 0.17.0
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/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["_decorate"],"sources":["../../src/hypercore-bridge.ts","../../src/replicator-extension.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Duplex } from 'node:stream';\n\nimport { type DuplexStream } from '@dxos/teleport';\n\n/**\n * Adapts a web-stream byte pipe to the Node `Duplex` that hypercore's `feed.replicate()` requires.\n *\n * This is the only place in MESH that still needs a Node stream: `@dxos/vendor-hypercore` dictates\n * the interface and is not ours to reshape. Keeping the bridge here — rather than in the muxer —\n * is what lets every other package in the stack compile without the `readable-stream` polyfill.\n *\n * Hand-written because `Duplex.fromWeb` takes `node:stream/web`'s `ReadableStream`, a different\n * declaration from the global one the seam is typed with.\n */\nexport const toNodeDuplex = (stream: DuplexStream): Duplex => {\n const reader = stream.readable.getReader();\n const writer = stream.writable.getWriter();\n\n const duplex: Duplex = new Duplex({\n read: () => {\n reader\n .read()\n .then(({ done, value }) => {\n // hypercore-protocol reads `Buffer`, not any typed array, so the copy here is load-bearing.\n duplex.push(done || !value ? null : Buffer.from(value));\n })\n .catch((err) => {\n duplex.destroy(err);\n });\n },\n write: (chunk, _encoding, callback) => {\n writer.write(chunk).then(() => callback(), callback);\n },\n final: (callback) => {\n writer.close().then(() => callback(), callback);\n },\n destroy: (err, callback) => {\n void reader.cancel().catch(() => {});\n void writer.abort().catch(() => {});\n callback(err);\n },\n });\n\n return duplex;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { create } from '@bufbuild/protobuf';\nimport { EmptySchema } from '@bufbuild/protobuf/wkt';\nimport type { ProtocolStream } from 'hypercore-protocol';\nimport { type Duplex } from 'node:stream';\n\nimport { DeferredTask, asyncTimeout, synchronized } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { failUndefined } from '@dxos/debug';\nimport { type HypercoreWrapper } 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 { fromPublicKey, requirePublicKey } from '@dxos/protocols/buf';\nimport { type BufService, getBufService } from '@dxos/protocols/buf-service';\nimport {\n type FeedInfo,\n FeedInfoSchema,\n ReplicatorService as ReplicatorServiceDesc,\n StartReplicationRequestSchema,\n StartReplicationResponseSchema,\n UpdateFeedsRequestSchema,\n} from '@dxos/protocols/buf/dxos/mesh/teleport/replicator_pb';\nimport { type ProtoRpcPeer, createProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\nimport { ComplexMap } from '@dxos/util';\n\nimport { toNodeDuplex } from './hypercore-bridge.ts';\n\ntype ReplicatorService = BufService<typeof ReplicatorServiceDesc>;\n\n/**\n * A feed's replication settings as this extension holds them.\n *\n * proto3 makes `FeedInfo.feed_key` optional and carries it as raw bytes, so the wire shape is\n * converted at the RPC boundary and the maps below stay keyed by `PublicKey`.\n */\ntype FeedReplication = {\n feedKey: PublicKey;\n download: boolean;\n upload: boolean;\n};\n\nconst toFeedReplication = (info: FeedInfo | undefined): FeedReplication => ({\n feedKey: requirePublicKey(info?.feedKey),\n download: info?.download ?? false,\n upload: info?.upload ?? false,\n});\n\nconst fromFeedReplication = (info: FeedReplication): FeedInfo =>\n create(FeedInfoSchema, { ...info, feedKey: fromPublicKey(info.feedKey) });\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, HypercoreWrapper<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 create(UpdateFeedsRequestSchema, {\n feeds: Array.from(this._feeds.values()).map((feed) =>\n fromFeedReplication({ feedKey: feed.key, download: true, upload: this._options.upload }),\n ),\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 addHypercore(feed: HypercoreWrapper<any>): void {\n this._feeds.set(feed.key, feed);\n log('addHypercore', { 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: getBufService<ReplicatorService>('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n exposed: {\n ReplicatorService: getBufService<ReplicatorService>('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 return create(EmptySchema);\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(toFeedReplication(info));\n return create(StartReplicationResponseSchema, { streamTag });\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(requirePublicKey(info?.feedKey));\n return create(EmptySchema);\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: FeedReplication): 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(\n create(StartReplicationRequestSchema, { info: fromFeedReplication(feedInfo) }),\n );\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: FeedReplication): 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: FeedReplication, 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 = toNodeDuplex(\n await this._extensionContext!.createStream(streamTag, {\n contentType: 'application/x-hypercore',\n }),\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: FeedReplication;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAa,gBAAgB,WAAiC;CAC5D,MAAM,SAAS,OAAO,SAAS,UAAU;CACzC,MAAM,SAAS,OAAO,SAAS,UAAU;CAEzC,MAAM,SAAiB,IAAI,OAAO;EAChC,YAAY;GACV,OACG,KAAK,CAAA,CACL,MAAM,EAAE,MAAM,YAAY;IAEzB,OAAO,KAAK,QAAQ,CAAC,QAAQ,OAAO,OAAO,KAAK,KAAK,CAAC;GACxD,CAAC,CAAA,CACA,OAAO,QAAQ;IACd,OAAO,QAAQ,GAAG;GACpB,CAAC;EACL;EACA,QAAQ,OAAO,WAAW,aAAa;GACrC,OAAO,MAAM,KAAK,CAAC,CAAC,WAAW,SAAS,GAAG,QAAQ;EACrD;EACA,QAAQ,aAAa;GACnB,OAAO,MAAM,CAAC,CAAC,WAAW,SAAS,GAAG,QAAQ;EAChD;EACA,UAAU,KAAK,aAAa;GAC1B,OAAY,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;GACnC,OAAY,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;GAClC,SAAS,GAAG;EACd;CACF,CAAC;CAED,OAAO;AACT;;;;;;;;;;;;ACDA,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A,GAAA;KAAA,GAAA;KAAA,GAAA;IAAA,CAAC;IAC9C;GACF;GAGA,IAAI,4BAA4B,GAC9B,IAAI,KAAK,4BAA4B;IAAE;IAAK;GAAK,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA;GAAA,CAAC;QAElD,IAAI,KAAK,4BAA4B;IAAE;IAAK,SAAS,KAAK;IAAS,OAAO;GAAwB,GAAA;IAAA,YAAA;IAAA,GAAA;IAAA,GAAA;IAAA,GAAA;GAAA,CAAC;GAErG;EACF,CAAC;EAED,KAAK,SAAS,IAAI,KAAK,SAAS;GAC9B;GACA;GACA;GACA;EACF,CAAC;EAED,cAAc,KAAK,iBAAwB,CAAC,CAAC,KAAK,aAAa;CACjE;CAEA,MAAc,iBAAiB,SAAmC;EAChE,MAAM,SAAS,KAAK,SAAS,IAAI,OAAO;EACxC,IAAI,CAAC,QACH;EAGF,OAAO,cAAc,QAAQ;EAC7B,KAAK,SAAS,OAAO,OAAO;CAC9B;AACF;AA1OGA,WAAA,CAAA,OAAA,GAAA,oBAAA,WAAA,iBAAA,IAAA;AA4FAA,WAAA,CAAA,YAAA,GAAA,oBAAA,WAAA,oBAAA,IAAA;AAiDAA,WAAA,CAAA,YAAA,GAAA,oBAAA,WAAA,sBAAA,IAAA"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["_decorate"],"sources":["../../src/hypercore-bridge.ts","../../src/replicator-extension.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { Duplex } from 'node:stream';\n\nimport { type DuplexStream } from '@dxos/teleport';\n\n/**\n * Adapts a web-stream byte pipe to the Node `Duplex` that hypercore's `feed.replicate()` requires.\n *\n * This is the only place in MESH that still needs a Node stream: `@dxos/vendor-hypercore` dictates\n * the interface and is not ours to reshape. Keeping the bridge here — rather than in the muxer —\n * is what lets every other package in the stack compile without the `readable-stream` polyfill.\n *\n * Hand-written because `Duplex.fromWeb` takes `node:stream/web`'s `ReadableStream`, a different\n * declaration from the global one the seam is typed with.\n */\nexport const toNodeDuplex = (stream: DuplexStream): Duplex => {\n const reader = stream.readable.getReader();\n const writer = stream.writable.getWriter();\n\n const duplex: Duplex = new Duplex({\n read: () => {\n reader\n .read()\n .then(({ done, value }) => {\n // hypercore-protocol reads `Buffer`, not any typed array, so the copy here is load-bearing.\n duplex.push(done || !value ? null : Buffer.from(value));\n })\n .catch((err) => {\n duplex.destroy(err);\n });\n },\n write: (chunk, _encoding, callback) => {\n writer.write(chunk).then(() => callback(), callback);\n },\n final: (callback) => {\n writer.close().then(() => callback(), callback);\n },\n destroy: (err, callback) => {\n void reader.cancel().catch(() => {});\n void writer.abort().catch(() => {});\n callback(err);\n },\n });\n\n return duplex;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { create } from '@bufbuild/protobuf';\nimport { EmptySchema } from '@bufbuild/protobuf/wkt';\nimport type { ProtocolStream } from 'hypercore-protocol';\nimport { type Duplex } from 'node:stream';\n\nimport { DeferredTask, asyncTimeout, synchronized } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { failUndefined } from '@dxos/debug';\nimport { type HypercoreWrapper } 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 { fromPublicKey, requirePublicKey } from '@dxos/protocols/buf';\nimport { type BufService, getBufService } from '@dxos/protocols/buf-service';\nimport {\n type FeedInfo,\n FeedInfoSchema,\n ReplicatorService as ReplicatorServiceDesc,\n StartReplicationRequestSchema,\n StartReplicationResponseSchema,\n UpdateFeedsRequestSchema,\n} from '@dxos/protocols/buf/dxos/mesh/teleport/replicator_pb';\nimport { type ProtoRpcPeer, createProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\nimport { ComplexMap } from '@dxos/util';\n\nimport { toNodeDuplex } from './hypercore-bridge.ts';\n\ntype ReplicatorService = BufService<typeof ReplicatorServiceDesc>;\n\n/**\n * A feed's replication settings as this extension holds them.\n *\n * proto3 makes `FeedInfo.feed_key` optional and carries it as raw bytes, so the wire shape is\n * converted at the RPC boundary and the maps below stay keyed by `PublicKey`.\n */\ntype FeedReplication = {\n feedKey: PublicKey;\n download: boolean;\n upload: boolean;\n};\n\nconst toFeedReplication = (info: FeedInfo | undefined): FeedReplication => ({\n feedKey: requirePublicKey(info?.feedKey),\n download: info?.download ?? false,\n upload: info?.upload ?? false,\n});\n\nconst fromFeedReplication = (info: FeedReplication): FeedInfo =>\n create(FeedInfoSchema, { ...info, feedKey: fromPublicKey(info.feedKey) });\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, HypercoreWrapper<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 create(UpdateFeedsRequestSchema, {\n feeds: Array.from(this._feeds.values()).map((feed) =>\n fromFeedReplication({ feedKey: feed.key, download: true, upload: this._options.upload }),\n ),\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 addHypercore(feed: HypercoreWrapper<any>): void {\n this._feeds.set(feed.key, feed);\n log('addHypercore', { 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: getBufService<ReplicatorService>('dxos.mesh.teleport.replicator.ReplicatorService'),\n },\n exposed: {\n ReplicatorService: getBufService<ReplicatorService>('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 return create(EmptySchema);\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(toFeedReplication(info));\n return create(StartReplicationResponseSchema, { streamTag });\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(requirePublicKey(info?.feedKey));\n return create(EmptySchema);\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: FeedReplication): 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(\n create(StartReplicationRequestSchema, { info: fromFeedReplication(feedInfo) }),\n );\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: FeedReplication): 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: FeedReplication, 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 = toNodeDuplex(\n await this._extensionContext!.createStream(streamTag, {\n contentType: 'application/x-hypercore',\n }),\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: FeedReplication;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,IAAa,gBAAgB,WAAiC;CAC5D,MAAM,SAAS,OAAO,SAAS,UAAU;CACz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