@dxos/teleport-extension-gossip 0.3.10 → 0.3.11-main.00a28cb
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.
|
@@ -12,7 +12,7 @@ import { invariant } from "@dxos/invariant";
|
|
|
12
12
|
import { log } from "@dxos/log";
|
|
13
13
|
import { schema } from "@dxos/protocols";
|
|
14
14
|
import { createProtoRpcPeer } from "@dxos/rpc";
|
|
15
|
-
var __dxlog_file = "/home/
|
|
15
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts";
|
|
16
16
|
var GossipExtension = class {
|
|
17
17
|
constructor(_callbacks = {}) {
|
|
18
18
|
this._callbacks = _callbacks;
|
|
@@ -115,7 +115,7 @@ var GossipExtension = class {
|
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
// packages/core/mesh/teleport-extension-gossip/src/gossip.ts
|
|
118
|
-
var __dxlog_file2 = "/home/
|
|
118
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/gossip.ts";
|
|
119
119
|
var RECEIVED_MESSAGES_GC_INTERVAL = 12e4;
|
|
120
120
|
var YJS_CHANNEL_PREFIX = "user-channel/yjs.awareness";
|
|
121
121
|
var YJS_TIMEOUT_THRESHOLD = 20;
|
|
@@ -334,7 +334,7 @@ import { invariant as invariant2 } from "@dxos/invariant";
|
|
|
334
334
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
335
335
|
import { log as log3 } from "@dxos/log";
|
|
336
336
|
import { ComplexMap as ComplexMap2 } from "@dxos/util";
|
|
337
|
-
var __dxlog_file3 = "/home/
|
|
337
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/presence.ts";
|
|
338
338
|
var PRESENCE_CHANNEL_ID = "dxos.mesh.presence.Presence";
|
|
339
339
|
var Presence = class {
|
|
340
340
|
// remotePeerId -> PresenceExtension
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/gossip.ts", "../../../src/gossip-extension.ts", "../../../src/presence.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { scheduleTask, Event, scheduleTaskInterval } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { RpcClosedError, TimeoutError } from '@dxos/protocols';\nimport { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { ComplexMap, ComplexSet } from '@dxos/util';\n\nimport { GossipExtension } from './gossip-extension';\n\nexport type GossipParams = {\n localPeerId: PublicKey;\n};\n\nconst RECEIVED_MESSAGES_GC_INTERVAL = 120_000;\n\nconst YJS_CHANNEL_PREFIX = 'user-channel/yjs.awareness';\nconst YJS_TIMEOUT_THRESHOLD = 20;\nconst YJS_TIMEOUT_WINDOW = 1000 * 30;\nconst MAX_CTX_TASKS = 50;\n\n/**\n * Gossip extensions manager.\n * Keeps track of all peers that are connected to the local peer.\n * Routes received announces to all connected peers.\n * Exposes API send announce to everybody and subscribe to .\n */\nexport class Gossip {\n private readonly _ctx = new Context({\n onError: (err) => {\n log.catch(err);\n },\n });\n\n private readonly _listeners = new Map<string, Set<(message: GossipMessage) => void>>();\n\n private readonly _receivedMessages = new ComplexSet<PublicKey>(PublicKey.hash);\n\n /**\n * Keys scheduled to be cleared from _receivedMessages on the next iteration.\n */\n private readonly _toClear = new ComplexSet<PublicKey>(PublicKey.hash);\n\n // remotePeerId -> PresenceExtension\n private readonly _connections = new ComplexMap<PublicKey, GossipExtension>(PublicKey.hash);\n\n public readonly connectionClosed = new Event<PublicKey>();\n\n // ringbuffer for yjs timeouts\n private _yjs_timeout = new Array(YJS_TIMEOUT_THRESHOLD);\n private _yjs_timeout_index = 0;\n\n constructor(private readonly _params: GossipParams) {}\n\n get localPeerId() {\n return this._params.localPeerId;\n }\n\n async open() {\n // Clear the map periodically.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this._performGc();\n },\n RECEIVED_MESSAGES_GC_INTERVAL,\n );\n }\n\n async close() {\n await this._ctx.dispose();\n }\n\n getConnections() {\n return Array.from(this._connections.keys());\n }\n\n createExtension({ remotePeerId }: { remotePeerId: PublicKey }): GossipExtension {\n const extension = new GossipExtension({\n onAnnounce: async (message) => {\n if (this._receivedMessages.has(message.messageId)) {\n return;\n }\n this._receivedMessages.add(message.messageId);\n this._callListeners(message);\n if (message.channelId.startsWith(YJS_CHANNEL_PREFIX) && this._oldestYjsTimeoutInWindow()) {\n log(\n `skipping propagating YJS gossip message due to timeouts (>${YJS_TIMEOUT_THRESHOLD} received in ${\n YJS_TIMEOUT_WINDOW / 1000\n })`,\n );\n return;\n }\n if (this._ctx.disposeCallbacksLength > MAX_CTX_TASKS) {\n log(`skipping propagating YJS gossip message due to exessive tasks (${MAX_CTX_TASKS})`);\n return;\n }\n scheduleTask(this._ctx, async () => {\n await this._propagateAnnounce(message);\n });\n },\n onClose: async (err) => {\n if (err) {\n log.catch(err);\n }\n if (this._connections.has(remotePeerId)) {\n this._connections.delete(remotePeerId);\n }\n this.connectionClosed.emit(remotePeerId);\n },\n });\n this._connections.set(remotePeerId, extension);\n\n return extension;\n }\n\n postMessage(channel: string, payload: any) {\n if (channel.startsWith(YJS_CHANNEL_PREFIX) && this._oldestYjsTimeoutInWindow()) {\n log(\n `skipping YJS gossip message due to timeouts (>${YJS_TIMEOUT_THRESHOLD} received in ${\n YJS_TIMEOUT_WINDOW / 1000\n }s )`,\n );\n return;\n }\n for (const extension of this._connections.values()) {\n this._sendAnnounceWithTimeoutTracking(extension, {\n peerId: this._params.localPeerId,\n messageId: PublicKey.random(),\n channelId: channel,\n timestamp: new Date(),\n payload,\n }).catch(async (err) => {\n if (err instanceof RpcClosedError) {\n log('sendAnnounce failed because of RpcClosedError', { err });\n } else if (\n err instanceof TimeoutError ||\n err.constructor.name === 'TimeoutError' ||\n err.message.startsWith('Timeout')\n ) {\n log('sendAnnounce failed because of TimeoutError', { err });\n } else {\n log.catch(err);\n }\n });\n }\n }\n\n listen(channel: string, callback: (message: GossipMessage) => void) {\n if (!this._listeners.has(channel)) {\n this._listeners.set(channel, new Set());\n }\n this._listeners.get(channel)!.add(callback);\n\n return {\n unsubscribe: () => {\n this._listeners.get(channel)!.delete(callback);\n },\n };\n }\n\n private _callListeners(message: GossipMessage) {\n if (this._listeners.has(message.channelId)) {\n this._listeners.get(message.channelId)!.forEach((callback) => {\n callback(message);\n });\n }\n }\n\n private _propagateAnnounce(message: GossipMessage) {\n return Promise.all(\n [...this._connections.entries()].map(async ([remotePeerId, extension]) => {\n if (this._params.localPeerId.equals(message.peerId) || remotePeerId.equals(message.peerId)) {\n return;\n }\n return this._sendAnnounceWithTimeoutTracking(extension, message).catch((err) => log(err));\n }),\n );\n }\n\n private _performGc() {\n const start = performance.now();\n\n for (const key of this._toClear.keys()) {\n this._receivedMessages.delete(key);\n }\n this._toClear.clear();\n for (const key of this._receivedMessages.keys()) {\n this._toClear.add(key);\n }\n\n const elapsed = performance.now() - start;\n if (elapsed > 100) {\n log.warn('GC took too long', { elapsed });\n }\n }\n\n private _addYjsTimeout() {\n this._yjs_timeout[this._yjs_timeout_index] = Date.now();\n this._yjs_timeout_index = (this._yjs_timeout_index + 1) % YJS_TIMEOUT_THRESHOLD;\n }\n\n private _oldestYjsTimeoutInWindow(): boolean {\n const lastTS = this._yjs_timeout[(this._yjs_timeout_index + 1) % YJS_TIMEOUT_THRESHOLD];\n if (!lastTS) {\n return false;\n }\n\n return Date.now() - lastTS < YJS_TIMEOUT_WINDOW;\n }\n\n private _sendAnnounceWithTimeoutTracking(extension: GossipExtension, message: GossipMessage) {\n return extension.sendAnnounce(message).catch((err) => {\n if (err instanceof TimeoutError || err.constructor.name === 'TimeoutError' || err.message.startsWith('Timeout')) {\n if (message.channelId.startsWith(YJS_CHANNEL_PREFIX)) {\n this._addYjsTimeout();\n }\n }\n });\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols';\nimport { type GossipMessage, type GossipService } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { createProtoRpcPeer, type ProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\n\nexport type GossipCallbacks = {\n /**\n * Callback to be called when a new announce is received.\n */\n onAnnounce?: (message: GossipMessage) => Promise<void>;\n\n /**\n * Callback to be called when the extension is closed.\n */\n onClose?: (err?: Error) => Promise<void>;\n};\n\n/**\n * Sends announces between two peers for a single teleport session.\n */\nexport class GossipExtension implements TeleportExtension {\n private readonly _opened = new Trigger();\n private _closed = false;\n\n private _rpc?: ProtoRpcPeer<ServiceBundle>;\n\n constructor(private readonly _callbacks: GossipCallbacks = {}) {}\n\n async onOpen(context: ExtensionContext): Promise<void> {\n log('onOpen', { localPeerId: context.localPeerId, remotePeerId: context.remotePeerId });\n\n this._rpc = createProtoRpcPeer<ServiceBundle, ServiceBundle>({\n requested: {\n GossipService: schema.getService('dxos.mesh.teleport.gossip.GossipService'),\n },\n exposed: {\n GossipService: schema.getService('dxos.mesh.teleport.gossip.GossipService'),\n },\n handlers: {\n GossipService: {\n announce: async (message: GossipMessage) => {\n log('received announce', { localPeerId: context.localPeerId, remotePeerId: context.remotePeerId, message });\n await this._callbacks.onAnnounce?.(message);\n },\n },\n },\n port: await context.createPort('rpc', { contentType: 'application/x-protobuf; messageType=\"dxos.rpc.Message\"' }),\n });\n await this._rpc.open();\n this._opened.wake();\n }\n\n async onClose(err?: Error): Promise<void> {\n log('close', { err });\n await this._rpc?.close();\n await this._callbacks.onClose?.(err);\n this._closed = true;\n }\n\n async onAbort(err?: Error): Promise<void> {\n log('abort', { err });\n try {\n await this._rpc?.abort();\n } catch (err) {\n log.catch(err);\n } finally {\n await this._callbacks.onClose?.(err);\n }\n this._closed = true;\n }\n\n async sendAnnounce(message: GossipMessage) {\n if (this._closed) {\n return;\n }\n await this._opened.wait();\n invariant(this._rpc, 'RPC not initialized');\n await this._rpc.rpc.GossipService.announce(message);\n }\n}\n\ntype ServiceBundle = {\n GossipService: GossipService;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Event, scheduleTaskInterval } from '@dxos/async';\nimport { type WithTypeUrl } from '@dxos/codec-protobuf';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';\nimport { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type Gossip } from './gossip';\n\nexport type PresenceParams = {\n /**\n * Interval between presence announces.\n */\n announceInterval: number;\n /**\n * Timeout after which a peer is considered offline.\n * Should be greater than announceInterval.\n */\n offlineTimeout: number;\n\n /**\n * Identity key of the local peer.\n */\n identityKey: PublicKey; // TODO(mykola): Remove once IdentityKey can be obtained from DeviceKey.\n\n gossip: Gossip;\n};\n\nconst PRESENCE_CHANNEL_ID = 'dxos.mesh.presence.Presence';\n\n/**\n * Presence manager.\n * Keeps track of all peers that are connected to the local peer.\n * Routes received presence announces to all connected peers.\n * Exposes API to get the list of peers that are online.\n */\nexport class Presence {\n public readonly updated = new Event<void>();\n private readonly _ctx = new Context({\n onError: (err) => {\n log.catch(err);\n },\n });\n\n private readonly _peerStates = new ComplexMap<PublicKey, GossipMessage>(PublicKey.hash);\n\n // remotePeerId -> PresenceExtension\n\n constructor(private readonly _params: PresenceParams) {\n invariant(\n this._params.announceInterval < this._params.offlineTimeout,\n 'Announce interval should be less than offline timeout.',\n );\n\n this._params.gossip.listen(PRESENCE_CHANNEL_ID, (message) => {\n this._receiveAnnounces(message);\n });\n\n // Send announce to all connected peers.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n const peerState: WithTypeUrl<PeerState> = {\n '@type': 'dxos.mesh.presence.PeerState',\n identityKey: this._params.identityKey,\n connections: this._params.gossip.getConnections(),\n };\n await this._params.gossip.postMessage(PRESENCE_CHANNEL_ID, peerState);\n },\n _params.announceInterval,\n );\n\n // Emit updated event in case some peers went offline.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this.updated.emit();\n },\n _params.offlineTimeout,\n );\n\n // Remove peer state when connection is closed.\n this._params.gossip.connectionClosed.on((peerId) => {\n this._peerStates.delete(peerId);\n this.updated.emit();\n });\n }\n\n getPeers(): PeerState[] {\n return Array.from(this._peerStates.values()).map((message) => message.payload);\n }\n\n getPeersOnline(): PeerState[] {\n return Array.from(this._peerStates.values())\n .filter((message) => message.timestamp.getTime() > Date.now() - this._params.offlineTimeout)\n .map((message) => message.payload);\n }\n\n getLocalState(): PeerState {\n return {\n identityKey: this._params.identityKey,\n connections: this._params.gossip.getConnections(),\n peerId: this._params.gossip.localPeerId,\n };\n }\n\n async destroy() {\n await this._ctx.dispose();\n }\n\n private _receiveAnnounces(message: GossipMessage) {\n invariant(message.channelId === PRESENCE_CHANNEL_ID, `Invalid channel ID: ${message.channelId}`);\n const oldPeerState = this._peerStates.get(message.peerId);\n if (!oldPeerState || oldPeerState.timestamp.getTime() < message.timestamp.getTime()) {\n // Assign peer id to payload.\n (message.payload as PeerState).peerId = message.peerId;\n\n this._peerStates.set(message.peerId, message);\n this.updated.emit();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,cAAcC,OAAOC,4BAA4B;AAC1D,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,OAAAA,YAAW;AACpB,SAASC,gBAAgBC,oBAAoB;AAE7C,SAASC,YAAYC,kBAAkB;;;ACNvC,SAASC,eAAe;AACxB,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,cAAc;AAEvB,SAASC,0BAA6C;;AA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AA8B;AAC5B,WAAOL,MAAMC,KAAK,KAAKpB,YAAYqB,OAAM,CAAA,EACtCI,OAAO,CAACnB,YAAYA,QAAQoB,UAAUC,QAAO,IAAKC,KAAKC,IAAG,IAAK,KAAKnC,QAAQS,cAAc,EAC1FmB,IAAI,CAAChB,YAAYA,QAAQiB,OAAO;EACrC;EAEAO,gBAA2B;AACzB,WAAO;MACLrB,aAAa,KAAKf,QAAQe;MAC1BC,aAAa,KAAKhB,QAAQU,OAAOO,eAAc;MAC/CK,QAAQ,KAAKtB,QAAQU,OAAO2B;IAC9B;EACF;EAEA,MAAMC,UAAU;AACd,UAAM,KAAKpC,KAAKqC,QAAO;EACzB;EAEQ1B,kBAAkBD,SAAwB;AAChDnB,IAAAA,WAAUmB,QAAQ4B,cAAc3C,qBAAqB,uBAAuBe,QAAQ4B,SAAS,IAAE;;;;;;;;;AAC/F,UAAMC,eAAe,KAAKnC,YAAYoC,IAAI9B,QAAQU,MAAM;AACxD,QAAI,CAACmB,gBAAgBA,aAAaT,UAAUC,QAAO,IAAKrB,QAAQoB,UAAUC,QAAO,GAAI;AAElFrB,cAAQiB,QAAsBP,SAASV,QAAQU;AAEhD,WAAKhB,YAAYqC,IAAI/B,QAAQU,QAAQV,OAAAA;AACrC,WAAKX,QAAQkB,KAAI;IACnB;EACF;AACF;",
|
|
6
6
|
"names": ["scheduleTask", "Event", "scheduleTaskInterval", "Context", "PublicKey", "log", "RpcClosedError", "TimeoutError", "ComplexMap", "ComplexSet", "Trigger", "invariant", "log", "schema", "createProtoRpcPeer", "GossipExtension", "constructor", "_callbacks", "_opened", "_closed", "onOpen", "context", "localPeerId", "remotePeerId", "_rpc", "requested", "GossipService", "getService", "exposed", "handlers", "announce", "message", "onAnnounce", "port", "createPort", "contentType", "open", "wake", "onClose", "err", "close", "onAbort", "abort", "catch", "sendAnnounce", "wait", "rpc", "RECEIVED_MESSAGES_GC_INTERVAL", "YJS_CHANNEL_PREFIX", "YJS_TIMEOUT_THRESHOLD", "YJS_TIMEOUT_WINDOW", "MAX_CTX_TASKS", "Gossip", "constructor", "_params", "_ctx", "Context", "onError", "err", "log", "catch", "_listeners", "Map", "_receivedMessages", "ComplexSet", "PublicKey", "hash", "_toClear", "_connections", "ComplexMap", "connectionClosed", "Event", "_yjs_timeout", "Array", "_yjs_timeout_index", "localPeerId", "open", "scheduleTaskInterval", "_performGc", "close", "dispose", "getConnections", "from", "keys", "createExtension", "remotePeerId", "extension", "GossipExtension", "onAnnounce", "message", "has", "messageId", "add", "_callListeners", "channelId", "startsWith", "_oldestYjsTimeoutInWindow", "disposeCallbacksLength", "scheduleTask", "_propagateAnnounce", "onClose", "delete", "emit", "set", "postMessage", "channel", "payload", "values", "_sendAnnounceWithTimeoutTracking", "peerId", "random", "timestamp", "Date", "RpcClosedError", "TimeoutError", "name", "listen", "callback", "Set", "get", "unsubscribe", "forEach", "Promise", "all", "entries", "map", "equals", "start", "performance", "now", "key", "clear", "elapsed", "warn", "_addYjsTimeout", "lastTS", "sendAnnounce", "Event", "scheduleTaskInterval", "Context", "invariant", "PublicKey", "log", "ComplexMap", "PRESENCE_CHANNEL_ID", "Presence", "constructor", "_params", "updated", "_ctx", "onError", "err", "catch", "_peerStates", "hash", "announceInterval", "offlineTimeout", "gossip", "listen", "message", "_receiveAnnounces", "peerState", "identityKey", "connections", "getConnections", "postMessage", "emit", "connectionClosed", "on", "peerId", "delete", "getPeers", "Array", "from", "values", "map", "payload", "getPeersOnline", "filter", "timestamp", "getTime", "Date", "now", "getLocalState", "localPeerId", "destroy", "dispose", "channelId", "oldPeerState", "get", "set"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytes":9939,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/gossip.ts":{"bytes":26044,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true},{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts","kind":"import-statement","original":"./gossip-extension"}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/presence.ts":{"bytes":13160,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/index.ts":{"bytes":678,"imports":[{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip.ts","kind":"import-statement","original":"./gossip"},{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts","kind":"import-statement","original":"./gossip-extension"},{"path":"packages/core/mesh/teleport-extension-gossip/src/presence.ts","kind":"import-statement","original":"./presence"}],"format":"esm"}},"outputs":{"packages/core/mesh/teleport-extension-gossip/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":23376},"packages/core/mesh/teleport-extension-gossip/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true}],"exports":["Gossip","GossipExtension","Presence"],"entryPoint":"packages/core/mesh/teleport-extension-gossip/src/index.ts","inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip.ts":{"bytesInOutput":6938},"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytesInOutput":2673},"packages/core/mesh/teleport-extension-gossip/src/index.ts":{"bytesInOutput":0},"packages/core/mesh/teleport-extension-gossip/src/presence.ts":{"bytesInOutput":3175}},"bytes":13136}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ var import_invariant2 = require("@dxos/invariant");
|
|
|
40
40
|
var import_keys2 = require("@dxos/keys");
|
|
41
41
|
var import_log3 = require("@dxos/log");
|
|
42
42
|
var import_util2 = require("@dxos/util");
|
|
43
|
-
var __dxlog_file = "/home/
|
|
43
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts";
|
|
44
44
|
var GossipExtension = class {
|
|
45
45
|
constructor(_callbacks = {}) {
|
|
46
46
|
this._callbacks = _callbacks;
|
|
@@ -141,7 +141,7 @@ var GossipExtension = class {
|
|
|
141
141
|
await this._rpc.rpc.GossipService.announce(message);
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
|
-
var __dxlog_file2 = "/home/
|
|
144
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/gossip.ts";
|
|
145
145
|
var RECEIVED_MESSAGES_GC_INTERVAL = 12e4;
|
|
146
146
|
var YJS_CHANNEL_PREFIX = "user-channel/yjs.awareness";
|
|
147
147
|
var YJS_TIMEOUT_THRESHOLD = 20;
|
|
@@ -352,7 +352,7 @@ var Gossip = class {
|
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
};
|
|
355
|
-
var __dxlog_file3 = "/home/
|
|
355
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport-extension-gossip/src/presence.ts";
|
|
356
356
|
var PRESENCE_CHANNEL_ID = "dxos.mesh.presence.Presence";
|
|
357
357
|
var Presence = class {
|
|
358
358
|
// remotePeerId -> PresenceExtension
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/gossip.ts", "../../../src/gossip-extension.ts", "../../../src/presence.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { scheduleTask, Event, scheduleTaskInterval } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { RpcClosedError, TimeoutError } from '@dxos/protocols';\nimport { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { ComplexMap, ComplexSet } from '@dxos/util';\n\nimport { GossipExtension } from './gossip-extension';\n\nexport type GossipParams = {\n localPeerId: PublicKey;\n};\n\nconst RECEIVED_MESSAGES_GC_INTERVAL = 120_000;\n\nconst YJS_CHANNEL_PREFIX = 'user-channel/yjs.awareness';\nconst YJS_TIMEOUT_THRESHOLD = 20;\nconst YJS_TIMEOUT_WINDOW = 1000 * 30;\nconst MAX_CTX_TASKS = 50;\n\n/**\n * Gossip extensions manager.\n * Keeps track of all peers that are connected to the local peer.\n * Routes received announces to all connected peers.\n * Exposes API send announce to everybody and subscribe to .\n */\nexport class Gossip {\n private readonly _ctx = new Context({\n onError: (err) => {\n log.catch(err);\n },\n });\n\n private readonly _listeners = new Map<string, Set<(message: GossipMessage) => void>>();\n\n private readonly _receivedMessages = new ComplexSet<PublicKey>(PublicKey.hash);\n\n /**\n * Keys scheduled to be cleared from _receivedMessages on the next iteration.\n */\n private readonly _toClear = new ComplexSet<PublicKey>(PublicKey.hash);\n\n // remotePeerId -> PresenceExtension\n private readonly _connections = new ComplexMap<PublicKey, GossipExtension>(PublicKey.hash);\n\n public readonly connectionClosed = new Event<PublicKey>();\n\n // ringbuffer for yjs timeouts\n private _yjs_timeout = new Array(YJS_TIMEOUT_THRESHOLD);\n private _yjs_timeout_index = 0;\n\n constructor(private readonly _params: GossipParams) {}\n\n get localPeerId() {\n return this._params.localPeerId;\n }\n\n async open() {\n // Clear the map periodically.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this._performGc();\n },\n RECEIVED_MESSAGES_GC_INTERVAL,\n );\n }\n\n async close() {\n await this._ctx.dispose();\n }\n\n getConnections() {\n return Array.from(this._connections.keys());\n }\n\n createExtension({ remotePeerId }: { remotePeerId: PublicKey }): GossipExtension {\n const extension = new GossipExtension({\n onAnnounce: async (message) => {\n if (this._receivedMessages.has(message.messageId)) {\n return;\n }\n this._receivedMessages.add(message.messageId);\n this._callListeners(message);\n if (message.channelId.startsWith(YJS_CHANNEL_PREFIX) && this._oldestYjsTimeoutInWindow()) {\n log(\n `skipping propagating YJS gossip message due to timeouts (>${YJS_TIMEOUT_THRESHOLD} received in ${\n YJS_TIMEOUT_WINDOW / 1000\n })`,\n );\n return;\n }\n if (this._ctx.disposeCallbacksLength > MAX_CTX_TASKS) {\n log(`skipping propagating YJS gossip message due to exessive tasks (${MAX_CTX_TASKS})`);\n return;\n }\n scheduleTask(this._ctx, async () => {\n await this._propagateAnnounce(message);\n });\n },\n onClose: async (err) => {\n if (err) {\n log.catch(err);\n }\n if (this._connections.has(remotePeerId)) {\n this._connections.delete(remotePeerId);\n }\n this.connectionClosed.emit(remotePeerId);\n },\n });\n this._connections.set(remotePeerId, extension);\n\n return extension;\n }\n\n postMessage(channel: string, payload: any) {\n if (channel.startsWith(YJS_CHANNEL_PREFIX) && this._oldestYjsTimeoutInWindow()) {\n log(\n `skipping YJS gossip message due to timeouts (>${YJS_TIMEOUT_THRESHOLD} received in ${\n YJS_TIMEOUT_WINDOW / 1000\n }s )`,\n );\n return;\n }\n for (const extension of this._connections.values()) {\n this._sendAnnounceWithTimeoutTracking(extension, {\n peerId: this._params.localPeerId,\n messageId: PublicKey.random(),\n channelId: channel,\n timestamp: new Date(),\n payload,\n }).catch(async (err) => {\n if (err instanceof RpcClosedError) {\n log('sendAnnounce failed because of RpcClosedError', { err });\n } else if (\n err instanceof TimeoutError ||\n err.constructor.name === 'TimeoutError' ||\n err.message.startsWith('Timeout')\n ) {\n log('sendAnnounce failed because of TimeoutError', { err });\n } else {\n log.catch(err);\n }\n });\n }\n }\n\n listen(channel: string, callback: (message: GossipMessage) => void) {\n if (!this._listeners.has(channel)) {\n this._listeners.set(channel, new Set());\n }\n this._listeners.get(channel)!.add(callback);\n\n return {\n unsubscribe: () => {\n this._listeners.get(channel)!.delete(callback);\n },\n };\n }\n\n private _callListeners(message: GossipMessage) {\n if (this._listeners.has(message.channelId)) {\n this._listeners.get(message.channelId)!.forEach((callback) => {\n callback(message);\n });\n }\n }\n\n private _propagateAnnounce(message: GossipMessage) {\n return Promise.all(\n [...this._connections.entries()].map(async ([remotePeerId, extension]) => {\n if (this._params.localPeerId.equals(message.peerId) || remotePeerId.equals(message.peerId)) {\n return;\n }\n return this._sendAnnounceWithTimeoutTracking(extension, message).catch((err) => log(err));\n }),\n );\n }\n\n private _performGc() {\n const start = performance.now();\n\n for (const key of this._toClear.keys()) {\n this._receivedMessages.delete(key);\n }\n this._toClear.clear();\n for (const key of this._receivedMessages.keys()) {\n this._toClear.add(key);\n }\n\n const elapsed = performance.now() - start;\n if (elapsed > 100) {\n log.warn('GC took too long', { elapsed });\n }\n }\n\n private _addYjsTimeout() {\n this._yjs_timeout[this._yjs_timeout_index] = Date.now();\n this._yjs_timeout_index = (this._yjs_timeout_index + 1) % YJS_TIMEOUT_THRESHOLD;\n }\n\n private _oldestYjsTimeoutInWindow(): boolean {\n const lastTS = this._yjs_timeout[(this._yjs_timeout_index + 1) % YJS_TIMEOUT_THRESHOLD];\n if (!lastTS) {\n return false;\n }\n\n return Date.now() - lastTS < YJS_TIMEOUT_WINDOW;\n }\n\n private _sendAnnounceWithTimeoutTracking(extension: GossipExtension, message: GossipMessage) {\n return extension.sendAnnounce(message).catch((err) => {\n if (err instanceof TimeoutError || err.constructor.name === 'TimeoutError' || err.message.startsWith('Timeout')) {\n if (message.channelId.startsWith(YJS_CHANNEL_PREFIX)) {\n this._addYjsTimeout();\n }\n }\n });\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { schema } from '@dxos/protocols';\nimport { type GossipMessage, type GossipService } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { createProtoRpcPeer, type ProtoRpcPeer } from '@dxos/rpc';\nimport { type ExtensionContext, type TeleportExtension } from '@dxos/teleport';\n\nexport type GossipCallbacks = {\n /**\n * Callback to be called when a new announce is received.\n */\n onAnnounce?: (message: GossipMessage) => Promise<void>;\n\n /**\n * Callback to be called when the extension is closed.\n */\n onClose?: (err?: Error) => Promise<void>;\n};\n\n/**\n * Sends announces between two peers for a single teleport session.\n */\nexport class GossipExtension implements TeleportExtension {\n private readonly _opened = new Trigger();\n private _closed = false;\n\n private _rpc?: ProtoRpcPeer<ServiceBundle>;\n\n constructor(private readonly _callbacks: GossipCallbacks = {}) {}\n\n async onOpen(context: ExtensionContext): Promise<void> {\n log('onOpen', { localPeerId: context.localPeerId, remotePeerId: context.remotePeerId });\n\n this._rpc = createProtoRpcPeer<ServiceBundle, ServiceBundle>({\n requested: {\n GossipService: schema.getService('dxos.mesh.teleport.gossip.GossipService'),\n },\n exposed: {\n GossipService: schema.getService('dxos.mesh.teleport.gossip.GossipService'),\n },\n handlers: {\n GossipService: {\n announce: async (message: GossipMessage) => {\n log('received announce', { localPeerId: context.localPeerId, remotePeerId: context.remotePeerId, message });\n await this._callbacks.onAnnounce?.(message);\n },\n },\n },\n port: await context.createPort('rpc', { contentType: 'application/x-protobuf; messageType=\"dxos.rpc.Message\"' }),\n });\n await this._rpc.open();\n this._opened.wake();\n }\n\n async onClose(err?: Error): Promise<void> {\n log('close', { err });\n await this._rpc?.close();\n await this._callbacks.onClose?.(err);\n this._closed = true;\n }\n\n async onAbort(err?: Error): Promise<void> {\n log('abort', { err });\n try {\n await this._rpc?.abort();\n } catch (err) {\n log.catch(err);\n } finally {\n await this._callbacks.onClose?.(err);\n }\n this._closed = true;\n }\n\n async sendAnnounce(message: GossipMessage) {\n if (this._closed) {\n return;\n }\n await this._opened.wait();\n invariant(this._rpc, 'RPC not initialized');\n await this._rpc.rpc.GossipService.announce(message);\n }\n}\n\ntype ServiceBundle = {\n GossipService: GossipService;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Event, scheduleTaskInterval } from '@dxos/async';\nimport { type WithTypeUrl } from '@dxos/codec-protobuf';\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';\nimport { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';\nimport { ComplexMap } from '@dxos/util';\n\nimport { type Gossip } from './gossip';\n\nexport type PresenceParams = {\n /**\n * Interval between presence announces.\n */\n announceInterval: number;\n /**\n * Timeout after which a peer is considered offline.\n * Should be greater than announceInterval.\n */\n offlineTimeout: number;\n\n /**\n * Identity key of the local peer.\n */\n identityKey: PublicKey; // TODO(mykola): Remove once IdentityKey can be obtained from DeviceKey.\n\n gossip: Gossip;\n};\n\nconst PRESENCE_CHANNEL_ID = 'dxos.mesh.presence.Presence';\n\n/**\n * Presence manager.\n * Keeps track of all peers that are connected to the local peer.\n * Routes received presence announces to all connected peers.\n * Exposes API to get the list of peers that are online.\n */\nexport class Presence {\n public readonly updated = new Event<void>();\n private readonly _ctx = new Context({\n onError: (err) => {\n log.catch(err);\n },\n });\n\n private readonly _peerStates = new ComplexMap<PublicKey, GossipMessage>(PublicKey.hash);\n\n // remotePeerId -> PresenceExtension\n\n constructor(private readonly _params: PresenceParams) {\n invariant(\n this._params.announceInterval < this._params.offlineTimeout,\n 'Announce interval should be less than offline timeout.',\n );\n\n this._params.gossip.listen(PRESENCE_CHANNEL_ID, (message) => {\n this._receiveAnnounces(message);\n });\n\n // Send announce to all connected peers.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n const peerState: WithTypeUrl<PeerState> = {\n '@type': 'dxos.mesh.presence.PeerState',\n identityKey: this._params.identityKey,\n connections: this._params.gossip.getConnections(),\n };\n await this._params.gossip.postMessage(PRESENCE_CHANNEL_ID, peerState);\n },\n _params.announceInterval,\n );\n\n // Emit updated event in case some peers went offline.\n scheduleTaskInterval(\n this._ctx,\n async () => {\n this.updated.emit();\n },\n _params.offlineTimeout,\n );\n\n // Remove peer state when connection is closed.\n this._params.gossip.connectionClosed.on((peerId) => {\n this._peerStates.delete(peerId);\n this.updated.emit();\n });\n }\n\n getPeers(): PeerState[] {\n return Array.from(this._peerStates.values()).map((message) => message.payload);\n }\n\n getPeersOnline(): PeerState[] {\n return Array.from(this._peerStates.values())\n .filter((message) => message.timestamp.getTime() > Date.now() - this._params.offlineTimeout)\n .map((message) => message.payload);\n }\n\n getLocalState(): PeerState {\n return {\n identityKey: this._params.identityKey,\n connections: this._params.gossip.getConnections(),\n peerId: this._params.gossip.localPeerId,\n };\n }\n\n async destroy() {\n await this._ctx.dispose();\n }\n\n private _receiveAnnounces(message: GossipMessage) {\n invariant(message.channelId === PRESENCE_CHANNEL_ID, `Invalid channel ID: ${message.channelId}`);\n const oldPeerState = this._peerStates.get(message.peerId);\n if (!oldPeerState || oldPeerState.timestamp.getTime() < message.timestamp.getTime()) {\n // Assign peer id to payload.\n (message.payload as PeerState).peerId = message.peerId;\n\n this._peerStates.set(message.peerId, message);\n this.updated.emit();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA0D;AAC1D,qBAAwB;AACxB,kBAA0B;AAC1B,iBAAoB;AACpB,uBAA6C;AAE7C,kBAAuC;ACNvC,IAAAA,gBAAwB;AACxB,uBAA0B;AAC1B,IAAAC,cAAoB;AACpB,IAAAC,oBAAuB;AAEvB,iBAAsD;ACLtD,IAAAF,gBAA4C;AAE5C,IAAAG,kBAAwB;AACxB,IAAAC,oBAA0B;AAC1B,IAAAC,eAA0B;AAC1B,IAAAJ,cAAoB;AAGpB,IAAAK,eAA2B;;ADepB,IAAMC,kBAAN,MAAMA;EAMXC,YAA6BC,aAA8B,CAAC,GAAG;
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA0D;AAC1D,qBAAwB;AACxB,kBAA0B;AAC1B,iBAAoB;AACpB,uBAA6C;AAE7C,kBAAuC;ACNvC,IAAAA,gBAAwB;AACxB,uBAA0B;AAC1B,IAAAC,cAAoB;AACpB,IAAAC,oBAAuB;AAEvB,iBAAsD;ACLtD,IAAAF,gBAA4C;AAE5C,IAAAG,kBAAwB;AACxB,IAAAC,oBAA0B;AAC1B,IAAAC,eAA0B;AAC1B,IAAAJ,cAAoB;AAGpB,IAAAK,eAA2B;;ADepB,IAAMC,kBAAN,MAAMA;EAMXC,YAA6BC,aAA8B,CAAC,GAAG;SAAlCA,aAAAA;SALZC,UAAU,IAAIC,sBAAAA;SACvBC,UAAU;EAI8C;EAEhE,MAAMC,OAAOC,SAA0C;AACrDC,yBAAI,UAAU;MAAEC,aAAaF,QAAQE;MAAaC,cAAcH,QAAQG;IAAa,GAAA;;;;;;AAErF,SAAKC,WAAOC,+BAAiD;MAC3D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,QAAI,CAAC6C,gBAAgBA,aAAa3C,UAAUwC,QAAO,IAAK7G,QAAQqE,UAAUwC,QAAO,GAAI;AAElF7G,cAAQgE,QAAsBG,SAASnE,QAAQmE;AAEhD,WAAK8B,YAAYpC,IAAI7D,QAAQmE,QAAQnE,OAAAA;AACrC,WAAKgG,QAAQpC,KAAI;IACnB;EACF;AACF;",
|
|
6
6
|
"names": ["import_async", "import_log", "import_protocols", "import_context", "import_invariant", "import_keys", "import_util", "GossipExtension", "constructor", "_callbacks", "_opened", "Trigger", "_closed", "onOpen", "context", "log", "localPeerId", "remotePeerId", "_rpc", "createProtoRpcPeer", "requested", "GossipService", "schema", "getService", "exposed", "handlers", "announce", "message", "onAnnounce", "port", "createPort", "contentType", "open", "wake", "onClose", "err", "close", "onAbort", "abort", "catch", "sendAnnounce", "wait", "invariant", "rpc", "RECEIVED_MESSAGES_GC_INTERVAL", "YJS_CHANNEL_PREFIX", "YJS_TIMEOUT_THRESHOLD", "YJS_TIMEOUT_WINDOW", "MAX_CTX_TASKS", "Gossip", "_params", "_ctx", "Context", "onError", "_listeners", "Map", "_receivedMessages", "ComplexSet", "PublicKey", "hash", "_toClear", "_connections", "ComplexMap", "connectionClosed", "Event", "_yjs_timeout", "Array", "_yjs_timeout_index", "scheduleTaskInterval", "_performGc", "dispose", "getConnections", "from", "keys", "createExtension", "extension", "has", "messageId", "add", "_callListeners", "channelId", "startsWith", "_oldestYjsTimeoutInWindow", "disposeCallbacksLength", "scheduleTask", "_propagateAnnounce", "delete", "emit", "set", "postMessage", "channel", "payload", "values", "_sendAnnounceWithTimeoutTracking", "peerId", "random", "timestamp", "Date", "RpcClosedError", "TimeoutError", "name", "listen", "callback", "Set", "get", "unsubscribe", "forEach", "Promise", "all", "entries", "map", "equals", "start", "performance", "now", "key", "clear", "elapsed", "warn", "_addYjsTimeout", "lastTS", "PRESENCE_CHANNEL_ID", "Presence", "updated", "_peerStates", "announceInterval", "offlineTimeout", "gossip", "_receiveAnnounces", "peerState", "identityKey", "connections", "on", "getPeers", "getPeersOnline", "filter", "getTime", "getLocalState", "destroy", "oldPeerState"]
|
|
7
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytes":9939,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/gossip.ts":{"bytes":26044,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true},{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts","kind":"import-statement","original":"./gossip-extension"}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/presence.ts":{"bytes":13160,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/teleport-extension-gossip/src/index.ts":{"bytes":678,"imports":[{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip.ts","kind":"import-statement","original":"./gossip"},{"path":"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts","kind":"import-statement","original":"./gossip-extension"},{"path":"packages/core/mesh/teleport-extension-gossip/src/presence.ts","kind":"import-statement","original":"./presence"}],"format":"esm"}},"outputs":{"packages/core/mesh/teleport-extension-gossip/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":23376},"packages/core/mesh/teleport-extension-gossip/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/rpc","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","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/util","kind":"import-statement","external":true}],"exports":["Gossip","GossipExtension","Presence"],"entryPoint":"packages/core/mesh/teleport-extension-gossip/src/index.ts","inputs":{"packages/core/mesh/teleport-extension-gossip/src/gossip.ts":{"bytesInOutput":6938},"packages/core/mesh/teleport-extension-gossip/src/gossip-extension.ts":{"bytesInOutput":2673},"packages/core/mesh/teleport-extension-gossip/src/index.ts":{"bytesInOutput":0},"packages/core/mesh/teleport-extension-gossip/src/presence.ts":{"bytesInOutput":3175}},"bytes":13136}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/teleport-extension-gossip",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11-main.00a28cb",
|
|
4
4
|
"description": "Gossip extension for teleport.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -16,17 +16,17 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@dxos/async": "0.3.
|
|
20
|
-
"@dxos/codec-protobuf": "0.3.
|
|
21
|
-
"@dxos/context": "0.3.
|
|
22
|
-
"@dxos/invariant": "0.3.
|
|
23
|
-
"@dxos/
|
|
24
|
-
"@dxos/node-std": "0.3.
|
|
25
|
-
"@dxos/
|
|
26
|
-
"@dxos/protocols": "0.3.
|
|
27
|
-
"@dxos/
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
19
|
+
"@dxos/async": "0.3.11-main.00a28cb",
|
|
20
|
+
"@dxos/codec-protobuf": "0.3.11-main.00a28cb",
|
|
21
|
+
"@dxos/context": "0.3.11-main.00a28cb",
|
|
22
|
+
"@dxos/invariant": "0.3.11-main.00a28cb",
|
|
23
|
+
"@dxos/keys": "0.3.11-main.00a28cb",
|
|
24
|
+
"@dxos/node-std": "0.3.11-main.00a28cb",
|
|
25
|
+
"@dxos/log": "0.3.11-main.00a28cb",
|
|
26
|
+
"@dxos/protocols": "0.3.11-main.00a28cb",
|
|
27
|
+
"@dxos/rpc": "0.3.11-main.00a28cb",
|
|
28
|
+
"@dxos/util": "0.3.11-main.00a28cb",
|
|
29
|
+
"@dxos/teleport": "0.3.11-main.00a28cb"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "^5.2.2"
|