*Update dist
This commit is contained in:
parent
37ad6d304a
commit
d65d33aa18
|
@ -10,6 +10,7 @@ export default class DHTCache extends EventEmitter {
|
||||||
private connectedTo;
|
private connectedTo;
|
||||||
private heartBeatInterval;
|
private heartBeatInterval;
|
||||||
protected flood: DHTFlood;
|
protected flood: DHTFlood;
|
||||||
|
private log;
|
||||||
constructor(swarm: any, { id, heartBeatInterval, ...opts }?: {
|
constructor(swarm: any, { id, heartBeatInterval, ...opts }?: {
|
||||||
id?: Buffer;
|
id?: Buffer;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
|
|
@ -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;AAa1C,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;gBAGxB,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;IAqC7C,OAAO,CAAC,MAAM,CAAc;IAE5B,IAAW,KAAK,IAAI,MAAM,EAAE,CAE3B;IAED,IAAW,QAAQ,IAAI,MAAM,EAAE,CAU9B;IAEM,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO;IAOlE,OAAO,CAAC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AAO,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;IAwBtB,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,YAAY;IA8CpB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,cAAc;CA2BvB"}
|
|
@ -11,6 +11,7 @@ const hypercore_crypto_1 = __importDefault(require("hypercore-crypto"));
|
||||||
const b4a_1 = __importDefault(require("b4a"));
|
const b4a_1 = __importDefault(require("b4a"));
|
||||||
const messages_js_1 = require("./messages.js");
|
const messages_js_1 = require("./messages.js");
|
||||||
const dht_flood_1 = __importDefault(require("@lumeweb/dht-flood"));
|
const dht_flood_1 = __importDefault(require("@lumeweb/dht-flood"));
|
||||||
|
const loglevel_1 = require("loglevel");
|
||||||
const EntityType = {
|
const EntityType = {
|
||||||
PUBKEY: Symbol.for("PUBKEY"),
|
PUBKEY: Symbol.for("PUBKEY"),
|
||||||
ITEM: Symbol.for("ITEM"),
|
ITEM: Symbol.for("ITEM"),
|
||||||
|
@ -24,6 +25,7 @@ class DHTCache extends events_1.default {
|
||||||
connectedTo;
|
connectedTo;
|
||||||
heartBeatInterval;
|
heartBeatInterval;
|
||||||
flood;
|
flood;
|
||||||
|
log;
|
||||||
constructor(swarm, { id = swarm.keyPair.publicKey, heartBeatInterval = 15, ...opts } = {}) {
|
constructor(swarm, { id = swarm.keyPair.publicKey, heartBeatInterval = 15, ...opts } = {}) {
|
||||||
super();
|
super();
|
||||||
if (!id)
|
if (!id)
|
||||||
|
@ -37,6 +39,7 @@ class DHTCache extends events_1.default {
|
||||||
this._online = new Set([this._maybeHexify(this.id)]);
|
this._online = new Set([this._maybeHexify(this.id)]);
|
||||||
this.swarm = swarm;
|
this.swarm = swarm;
|
||||||
this.flood = new dht_flood_1.default({ id, swarm, ...opts });
|
this.flood = new dht_flood_1.default({ id, swarm, ...opts });
|
||||||
|
this.log = (0, loglevel_1.getLogger)("dht-cache");
|
||||||
this.flood.on("peer-open", (peer) => this.addPeerHandler(peer));
|
this.flood.on("peer-open", (peer) => this.addPeerHandler(peer));
|
||||||
this.flood.on("peer-remove", (peer) => this.removePeerHandler(peer));
|
this.flood.on("peer-remove", (peer) => this.removePeerHandler(peer));
|
||||||
this.flood.on("message", (message, id) => this.onGetBroadcast(message, id));
|
this.flood.on("message", (message, id) => this.onGetBroadcast(message, id));
|
||||||
|
@ -146,9 +149,11 @@ class DHTCache extends events_1.default {
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
this._emitHeartbeat(peer);
|
this._emitHeartbeat(peer);
|
||||||
|
this.log.debug(`Relay peer connected: ${stringId}`);
|
||||||
if (this.bootstrapped) {
|
if (this.bootstrapped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.log.debug(`Broadcasting bootstrap request`);
|
||||||
// If this is the first person we've met, get their graph
|
// If this is the first person we've met, get their graph
|
||||||
this._broadcastMessage({ type: messages_js_1.Type.BOOTSTRAP_REQUEST }, 0);
|
this._broadcastMessage({ type: messages_js_1.Type.BOOTSTRAP_REQUEST }, 0);
|
||||||
}
|
}
|
||||||
|
@ -161,6 +166,7 @@ class DHTCache extends events_1.default {
|
||||||
}
|
}
|
||||||
this.onRemovePeer(peer);
|
this.onRemovePeer(peer);
|
||||||
}, DISCONNECT_SMOOTH);
|
}, DISCONNECT_SMOOTH);
|
||||||
|
this.log.debug(`Relay peer might have disconnected: ${id.toString("hex")}`);
|
||||||
}
|
}
|
||||||
onRemovePeer(peer) {
|
onRemovePeer(peer) {
|
||||||
const id = peer.remotePublicKey;
|
const id = peer.remotePublicKey;
|
||||||
|
@ -172,6 +178,7 @@ class DHTCache extends events_1.default {
|
||||||
type: messages_js_1.Type.DISCONNECTED,
|
type: messages_js_1.Type.DISCONNECTED,
|
||||||
id,
|
id,
|
||||||
}, 0);
|
}, 0);
|
||||||
|
this.log.debug(`Relay peer confirmed disconnected: ${id.toString("hex")}`);
|
||||||
}
|
}
|
||||||
onGetBroadcast(message, id) {
|
onGetBroadcast(message, id) {
|
||||||
let decoded;
|
let decoded;
|
||||||
|
@ -193,26 +200,32 @@ class DHTCache extends events_1.default {
|
||||||
this._ensureItem(bufData);
|
this._ensureItem(bufData);
|
||||||
this._addEntityConnection(id, bufData);
|
this._addEntityConnection(id, bufData);
|
||||||
this.emit("item-added", id, bufData);
|
this.emit("item-added", id, bufData);
|
||||||
|
this.log.debug(`New item added: ${bufData.toString("hex")} from ${id.toString("hex")}`);
|
||||||
}
|
}
|
||||||
if (messages_js_1.Type.REMOVE_ITEM === type) {
|
if (messages_js_1.Type.REMOVE_ITEM === type) {
|
||||||
this.removeItem(bufData);
|
this.removeItem(bufData);
|
||||||
this._pruneItems();
|
this._pruneItems();
|
||||||
this.emit("item-removed", id, bufData);
|
this.emit("item-removed", id, bufData);
|
||||||
|
this.log.debug(`Item removed: ${bufData.toString("hex")} from ${id.toString("hex")}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (type === messages_js_1.Type.CONNECTED) {
|
else if (type === messages_js_1.Type.CONNECTED) {
|
||||||
const { id: toId } = decoded;
|
const { id: toId } = decoded;
|
||||||
this._addEntityConnection(id, b4a_1.default.from(toId));
|
let bufId = b4a_1.default.from(toId);
|
||||||
this.emit("peer-add-seen", id, toId);
|
this._addEntityConnection(id, bufId);
|
||||||
|
this.emit("peer-add-seen", id, bufId);
|
||||||
this._recalculate();
|
this._recalculate();
|
||||||
|
this.log.debug(`Network peer connected: ${bufId.toString("hex")}`);
|
||||||
}
|
}
|
||||||
else if (type === messages_js_1.Type.DISCONNECTED) {
|
else if (type === messages_js_1.Type.DISCONNECTED) {
|
||||||
const { id: toId } = decoded;
|
const { id: toId } = decoded;
|
||||||
|
let bufId = b4a_1.default.from(toId);
|
||||||
this._removeEntityConnection(id, b4a_1.default.from(toId));
|
this._removeEntityConnection(id, b4a_1.default.from(toId));
|
||||||
this.emit("peer-remove-seen", id, toId);
|
this.emit("peer-remove-seen", id, toId);
|
||||||
this._recalculate();
|
this._recalculate();
|
||||||
this._pruneItems();
|
this._pruneItems();
|
||||||
|
this.log.debug(`Network peer disconnected: ${bufId.toString("hex")}`);
|
||||||
}
|
}
|
||||||
else if (type === messages_js_1.Type.BOOTSTRAP_REQUEST) {
|
else if (type === messages_js_1.Type.BOOTSTRAP_REQUEST) {
|
||||||
const bootstrap = this._getBootstrapInfo();
|
const bootstrap = this._getBootstrapInfo();
|
||||||
|
@ -220,18 +233,20 @@ class DHTCache extends events_1.default {
|
||||||
type: messages_js_1.Type.BOOTSTRAP_RESPONSE,
|
type: messages_js_1.Type.BOOTSTRAP_RESPONSE,
|
||||||
bootstrap,
|
bootstrap,
|
||||||
})), 0);
|
})), 0);
|
||||||
|
this.log.debug(`Bootstrap request received`);
|
||||||
}
|
}
|
||||||
else if (type === messages_js_1.Type.BOOTSTRAP_RESPONSE) {
|
else if (type === messages_js_1.Type.BOOTSTRAP_RESPONSE) {
|
||||||
const { bootstrap } = decoded;
|
const { bootstrap } = decoded;
|
||||||
this._bootstrapFrom(bootstrap);
|
this._bootstrapFrom(bootstrap);
|
||||||
}
|
}
|
||||||
else if (type === messages_js_1.Type.HEARTBEAT) {
|
else if (type === messages_js_1.Type.HEARTBEAT) {
|
||||||
let { id: toId, signature, data: bufData } = decoded;
|
const { id: toId, signature, data: bufData } = decoded;
|
||||||
toId = b4a_1.default.from(toId);
|
let bufId = b4a_1.default.from(toId);
|
||||||
if (signature && hypercore_crypto_1.default.verify(bufData, signature, id)) {
|
if (signature && hypercore_crypto_1.default.verify(bufData, signature, id)) {
|
||||||
this._addEntityConnection(id, toId);
|
this._addEntityConnection(id, bufId);
|
||||||
this._setEntity(toId, { heartbeat: Date.now() });
|
this._setEntity(bufId, { heartbeat: Date.now() });
|
||||||
}
|
}
|
||||||
|
this.log.debug(`Bootstrap response received from ${bufId.toString("hex")}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_signItem(item) {
|
_signItem(item) {
|
||||||
|
@ -342,6 +357,7 @@ class DHTCache extends events_1.default {
|
||||||
}
|
}
|
||||||
this._online = online;
|
this._online = online;
|
||||||
this.emit("online", online);
|
this.emit("online", online);
|
||||||
|
this.log.debug(`Online list updated: ${online.size} network peers online, ${offline.size} network peers offline and removed from DAG`);
|
||||||
}
|
}
|
||||||
_maybeHexify(data) {
|
_maybeHexify(data) {
|
||||||
if (b4a_1.default.isBuffer(data)) {
|
if (b4a_1.default.isBuffer(data)) {
|
||||||
|
|
Loading…
Reference in New Issue