Compare commits
No commits in common. "9cd5e798d91bfb5ffe9665894421e22372852f8f" and "993eff5398ce3018dc52f281d71750676d4cb700" have entirely different histories.
9cd5e798d9
...
993eff5398
|
@ -8,7 +8,6 @@ export default class DHTFlood extends EventEmitter {
|
||||||
private lru;
|
private lru;
|
||||||
private swarm;
|
private swarm;
|
||||||
private protocol;
|
private protocol;
|
||||||
private topic;
|
|
||||||
private symbol;
|
private symbol;
|
||||||
private socketMap;
|
private socketMap;
|
||||||
constructor({ lruSize, ttl, messageNumber, id, swarm, protocol, }?: {
|
constructor({ lruSize, ttl, messageNumber, id, swarm, protocol, }?: {
|
||||||
|
|
|
@ -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"}
|
|
@ -14,8 +14,6 @@ const messages_js_1 = require("./messages.js");
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const compact_encoding_1 = __importDefault(require("compact-encoding"));
|
const compact_encoding_1 = __importDefault(require("compact-encoding"));
|
||||||
const b4a_1 = __importDefault(require("b4a"));
|
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 debug = (0, debug_1.default)("dht-flood");
|
||||||
const LRU_SIZE = 255;
|
const LRU_SIZE = 255;
|
||||||
const TTL = 255;
|
const TTL = 255;
|
||||||
|
@ -27,7 +25,6 @@ class DHTFlood extends events_1.default {
|
||||||
lru;
|
lru;
|
||||||
swarm;
|
swarm;
|
||||||
protocol;
|
protocol;
|
||||||
topic;
|
|
||||||
symbol;
|
symbol;
|
||||||
socketMap = new Set();
|
socketMap = new Set();
|
||||||
constructor({ lruSize = LRU_SIZE, ttl = TTL, messageNumber = 0, id = crypto_1.default.randomBytes(32), swarm = null, protocol = PROTOCOL, } = {}) {
|
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);
|
const mux = protomux_1.default.from(peer);
|
||||||
mux.pair({ protocol: this.protocol }, () => this.setupPeer(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);
|
this.symbol = Symbol.for(this.protocol);
|
||||||
}
|
}
|
||||||
handleMessage({ originId, messageNumber, ttl, data }, messenger) {
|
handleMessage({ originId, messageNumber, ttl, data }, messenger) {
|
||||||
|
@ -121,16 +113,8 @@ class DHTFlood extends events_1.default {
|
||||||
broadcast(data, ttl = this.ttl) {
|
broadcast(data, ttl = this.ttl) {
|
||||||
this.messageNumber++;
|
this.messageNumber++;
|
||||||
const { id, messageNumber } = this;
|
const { id, messageNumber } = this;
|
||||||
let topicString = this.topic.toString("hex");
|
for (const peer of this.swarm.connections.values()) {
|
||||||
let peers = [...this.swarm.peers.values()]
|
const message = this.setupPeer(peer);
|
||||||
.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);
|
|
||||||
message.send({
|
message.send({
|
||||||
originId: id,
|
originId: id,
|
||||||
messageNumber,
|
messageNumber,
|
||||||
|
|
26
src/index.ts
26
src/index.ts
|
@ -9,8 +9,6 @@ import { Packet } from "./messages.js";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import c from "compact-encoding";
|
import c from "compact-encoding";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
// @ts-ignore
|
|
||||||
import sodium from "sodium-universal";
|
|
||||||
|
|
||||||
const debug = debug0("dht-flood");
|
const debug = debug0("dht-flood");
|
||||||
|
|
||||||
|
@ -25,7 +23,6 @@ export default class DHTFlood extends EventEmitter {
|
||||||
private lru: LRU;
|
private lru: LRU;
|
||||||
private swarm: any;
|
private swarm: any;
|
||||||
private protocol: string;
|
private protocol: string;
|
||||||
private topic: Buffer;
|
|
||||||
private symbol: Symbol;
|
private symbol: Symbol;
|
||||||
private socketMap: Set<Function> = new Set<Function>();
|
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));
|
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);
|
this.symbol = Symbol.for(this.protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,19 +148,8 @@ export default class DHTFlood extends EventEmitter {
|
||||||
this.messageNumber++;
|
this.messageNumber++;
|
||||||
const { id, messageNumber } = this;
|
const { id, messageNumber } = this;
|
||||||
|
|
||||||
let topicString = this.topic.toString("hex");
|
for (const peer of this.swarm.connections.values()) {
|
||||||
|
const message = this.setupPeer(peer);
|
||||||
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);
|
|
||||||
message.send({
|
message.send({
|
||||||
originId: id,
|
originId: id,
|
||||||
messageNumber,
|
messageNumber,
|
||||||
|
|
Loading…
Reference in New Issue