Compare commits

..

No commits in common. "9cd5e798d91bfb5ffe9665894421e22372852f8f" and "993eff5398ce3018dc52f281d71750676d4cb700" have entirely different histories.

4 changed files with 5 additions and 44 deletions

1
dist/index.d.ts vendored
View File

@ -8,7 +8,6 @@ export default class DHTFlood extends EventEmitter {
private lru;
private swarm;
private protocol;
private topic;
private symbol;
private socketMap;
constructor({ lruSize, ttl, messageNumber, id, swarm, protocol, }?: {

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoBlC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAChD,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAsC;gBAE3C,EACV,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,EACZ,QAAmB,GACpB;;;;;;;KAAK;IA6BN,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,SAAS;IAwDjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;IA0BnC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;CAY1C"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAkBlC,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,YAAY;IAChD,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAsC;gBAE3C,EACV,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,EACZ,QAAmB,GACpB;;;;;;;KAAK;IAqBN,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,SAAS;IAwDjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;IAenC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;CAY1C"}

20
dist/index.js vendored
View File

@ -14,8 +14,6 @@ const messages_js_1 = require("./messages.js");
// @ts-ignore
const compact_encoding_1 = __importDefault(require("compact-encoding"));
const b4a_1 = __importDefault(require("b4a"));
// @ts-ignore
const sodium_universal_1 = __importDefault(require("sodium-universal"));
const debug = (0, debug_1.default)("dht-flood");
const LRU_SIZE = 255;
const TTL = 255;
@ -27,7 +25,6 @@ class DHTFlood extends events_1.default {
lru;
swarm;
protocol;
topic;
symbol;
socketMap = new Set();
constructor({ lruSize = LRU_SIZE, ttl = TTL, messageNumber = 0, id = crypto_1.default.randomBytes(32), swarm = null, protocol = PROTOCOL, } = {}) {
@ -45,11 +42,6 @@ class DHTFlood extends events_1.default {
const mux = protomux_1.default.from(peer);
mux.pair({ protocol: this.protocol }, () => this.setupPeer(peer));
});
const topic = b4a_1.default.from(this.protocol);
const topicHash = b4a_1.default.allocUnsafe(32);
sodium_universal_1.default.crypto_generichash(topicHash, topic);
this.topic = topicHash;
this.swarm.join(topicHash);
this.symbol = Symbol.for(this.protocol);
}
handleMessage({ originId, messageNumber, ttl, data }, messenger) {
@ -121,16 +113,8 @@ class DHTFlood extends events_1.default {
broadcast(data, ttl = this.ttl) {
this.messageNumber++;
const { id, messageNumber } = this;
let topicString = this.topic.toString("hex");
let peers = [...this.swarm.peers.values()]
.filter((peerInfo) => peerInfo.topics.includes(topicString))
.map((peerInfo) => peerInfo.publicKey);
for (const peer of peers) {
const conn = this.swarm._allConnections.get(peer);
if (conn) {
continue;
}
const message = this.setupPeer(conn);
for (const peer of this.swarm.connections.values()) {
const message = this.setupPeer(peer);
message.send({
originId: id,
messageNumber,

View File

@ -9,8 +9,6 @@ import { Packet } from "./messages.js";
// @ts-ignore
import c from "compact-encoding";
import b4a from "b4a";
// @ts-ignore
import sodium from "sodium-universal";
const debug = debug0("dht-flood");
@ -25,7 +23,6 @@ export default class DHTFlood extends EventEmitter {
private lru: LRU;
private swarm: any;
private protocol: string;
private topic: Buffer;
private symbol: Symbol;
private socketMap: Set<Function> = new Set<Function>();
@ -54,14 +51,6 @@ export default class DHTFlood extends EventEmitter {
mux.pair({ protocol: this.protocol }, () => this.setupPeer(peer));
});
const topic = b4a.from(this.protocol);
const topicHash = b4a.allocUnsafe(32);
sodium.crypto_generichash(topicHash, topic);
this.topic = topicHash as Buffer;
this.swarm.join(topicHash);
this.symbol = Symbol.for(this.protocol);
}
@ -159,19 +148,8 @@ export default class DHTFlood extends EventEmitter {
this.messageNumber++;
const { id, messageNumber } = this;
let topicString = this.topic.toString("hex");
let peers: Buffer[] = [...this.swarm.peers.values()]
.filter((peerInfo: any) => peerInfo.topics.includes(topicString))
.map((peerInfo) => peerInfo.publicKey);
for (const peer of peers) {
const conn = this.swarm._allConnections.get(peer);
if (conn) {
continue;
}
const message = this.setupPeer(conn);
for (const peer of this.swarm.connections.values()) {
const message = this.setupPeer(peer);
message.send({
originId: id,
messageNumber,