From 7d5f3719f9590f84d9707e532ef39e3525ce84ee Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 17 Dec 2022 11:03:47 -0500 Subject: [PATCH] *Update dist --- dist/index.d.ts | 3 +++ dist/index.d.ts.map | 2 +- dist/index.js | 27 ++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 69e769b..1ceebd2 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -47,5 +47,8 @@ export default class DHTCache extends EventEmitter { private _heartbeatCheck; private _emitHeartbeat; private _hello; + private _sendItemsToPeer; + private _createAddItemRequestMessage; + private _createAddItemRequest; } //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 6ef45d5..f7488dc 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAYlC,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAc1C,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAChD,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;IACrB,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,iBAAiB,CAAS;IAElC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAa;gBAGtB,KAAK,EAAE,GAAG,EACV,EACE,EAA4B,EAC5B,iBAAsB,EACtB,GAAG,IAAI,EACR,GAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAO;IAuC7C,OAAO,CAAC,MA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E,OAAO,EAAE,GAAG;IAInC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG;IAmClC,iBAAiB,CAAC,IAAI,EAAE,GAAG;IAa3B,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG;IAqBhC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAkGpD,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,uBAAuB;IAa/B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAmCtB,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,YAAY;IAgDpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;IA4BtB,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,4BAA4B;IAKpC,OAAO,CAAC,qBAAqB;CAS9B"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 65be3c0..2436947 100644 --- a/dist/index.js +++ b/dist/index.js @@ -73,11 +73,7 @@ class DHTCache extends events_1.default { this._ensureItem(item); this._addEntityConnection(this.id, item); const broadcast = () => { - this._broadcastMessage({ - type: messages_js_1.Type.ADD_ITEM, - data: b4a_1.default.from(item, "hex"), - signature: this._signItem(item), - }); + this._broadcastMessage(this._createAddItemRequest(item)); }; if (!this.bootstrapped) { this.once("bootstrapped", broadcast); @@ -142,6 +138,7 @@ class DHTCache extends events_1.default { this.log.debug(`Relay peer connected: ${stringId}`); } if (this.bootstrapped) { + this._sendItemsToPeer(peer); return; } this.log.debug(`Broadcasting bootstrap request`); @@ -229,6 +226,9 @@ class DHTCache extends events_1.default { else if (type === messages_js_1.Type.BOOTSTRAP_RESPONSE) { const { bootstrap } = decoded; this._bootstrapFrom(bootstrap); + if (this.swarm._allConnections.has(id)) { + this._sendItemsToPeer(this.swarm._allConnections.get(id)); + } this.log.debug(`Bootstrap response received`); } else if (type === messages_js_1.Type.HEARTBEAT) { @@ -438,5 +438,22 @@ class DHTCache extends events_1.default { this.send(peer, b4a_1.default.from("hello")); this.swarm.leavePeer(peer.remotePublicKey); } + _sendItemsToPeer(peer) { + for (let item of this.cache) { + item = this._maybeHexify(item); + this.send(peer, this._createAddItemRequestMessage(item)); + } + } + _createAddItemRequestMessage(item) { + item = this._maybeHexify(item); + return messages_js_1.Message.toBinary(messages_js_1.Message.create(this._createAddItemRequest(item))); + } + _createAddItemRequest(item) { + return { + type: messages_js_1.Type.ADD_ITEM, + data: b4a_1.default.from(item, "hex"), + signature: this._signItem(item), + }; + } } exports.default = DHTCache;