*Update dist

This commit is contained in:
Derrick Hammer 2022-11-16 11:15:00 -05:00
parent 0016903687
commit 47eba446b7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 27 additions and 23 deletions

View File

@ -6,20 +6,21 @@ export default class DHTOnlineBase extends EventEmitter {
private bootstrapped;
private graph;
private connectedTo;
private data;
private encoding;
constructor(id: Buffer, { encoding }?: {
encoding?: string | undefined;
});
private _data;
get data(): {};
set data(value: {});
private _online;
get online(): string[];
broadcast(data: any, ttl?: number): void;
getPeerData(id: Buffer | string): any;
setData(data: any): void;
private _broadcastData;
protected onAddPeer(id: Buffer): void;
protected onRemovePeer(id: Buffer): void;
protected onGetBroadcast(message: Buffer, id: Buffer): void;
private _broadcastData;
private _hasSeenPeer;
private _setPeer;
private _ensurePeer;

View File

@ -1 +1 @@
{"version":3,"file":"dhtOnlineBase.d.ts","sourceRoot":"","sources":["../src/dhtOnlineBase.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAYlC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,YAAY;IACrD,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAU;IAC9B,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,WAAW,CAAW;IAC9B,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,QAAQ,CAAoB;gBAExB,EAAE,EAAE,MAAM,EAAE,EAAE,QAA2B,EAAE;;KAAK;IAa5D,OAAO,CAAC,OAAO,CAAW;IAE1B,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM;IAIjC,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAIxB,OAAO,CAAC,IAAI,EAAE,GAAG;IAQxB,OAAO,CAAC,cAAc;IAgBtB,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM;IAqC9B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OAAO,CAAC,cAAc;IAgBtB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,QAAQ;IAGhB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,kBAAkB;IAY1B,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,cAAc;IA2BtB,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,YAAY;IAwBpB,OAAO,CAAC,YAAY;CAOrB"}

39
dist/dhtOnlineBase.js vendored
View File

@ -14,7 +14,6 @@ class DHTOnlineBase extends events_1.default {
bootstrapped;
graph;
connectedTo;
data;
encoding;
constructor(id, { encoding = DEFAULT_ENCODING } = {}) {
super();
@ -24,10 +23,19 @@ class DHTOnlineBase extends events_1.default {
this.bootstrapped = false;
this.graph = new jsnetworkx_1.DiGraph();
this.connectedTo = new Set();
this.data = {};
this._data = {};
this.encoding = (0, codecs_1.default)(encoding || DEFAULT_ENCODING);
this._online = [this._maybeHexify(this.id)];
}
_data;
get data() {
return this._data;
}
set data(value) {
this._data = value;
this._setPeer(this.id, value);
this._broadcastData();
}
_online;
get online() {
return this._online;
@ -38,22 +46,6 @@ class DHTOnlineBase extends events_1.default {
getPeerData(id) {
return this.graph.node.get(this._maybeHexify(id));
}
setData(data) {
this.data = data;
this._setPeer(this.id, data);
this._broadcastData();
}
_broadcastData() {
const rawData = this.data;
if (!Object.keys(rawData).length) {
return;
}
const data = this.encoding.encode(rawData);
this.broadcast(messages_js_1.Message.toBinary(messages_js_1.Message.create({
type: messages_js_1.Type.STATE,
data,
})));
}
onAddPeer(id) {
const stringId = id.toString("hex");
if (this.connectedTo.has(stringId)) {
@ -129,6 +121,17 @@ class DHTOnlineBase extends events_1.default {
this._bootstrapFrom(bootstrap);
}
}
_broadcastData() {
const rawData = this._data;
if (!Object.keys(rawData).length) {
return;
}
const data = this.encoding.encode(rawData);
this.broadcast(messages_js_1.Message.toBinary(messages_js_1.Message.create({
type: messages_js_1.Type.STATE,
data,
})));
}
_hasSeenPeer(id) {
return this.graph.hasNode(this._maybeHexify(id));
}

2
dist/index.js vendored
View File

@ -17,7 +17,7 @@ class DHTOnline extends dhtOnlineBase_js_1.default {
this.flood.on("peer-remove", (peer) => this.handlePeerRemove(peer));
this.flood.on("message", (message, id) => this.onGetBroadcast(message, id));
this.swarm.on("connection", (peer) => this.flood.send(peer, Buffer.from("hello"), 0));
this.setData(data);
this.data = data;
[...this.swarm.peers.values()].forEach(this.handlePeerAdd.bind(this));
}
handlePeerAdd(peer) {