Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer 21f7f2e67d
*Update dist 2022-11-16 02:41:56 -05:00
Derrick Hammer 2d62822908
*Allow protocol to be configurable 2022-11-16 02:41:37 -05:00
4 changed files with 14 additions and 7 deletions

4
dist/index.d.ts vendored
View File

@ -8,12 +8,14 @@ export default class DHTFlood extends EventEmitter {
private messageNumber;
private lru;
private swarm;
constructor({ lruSize, ttl, messageNumber, id, swarm, }?: {
private protocol;
constructor({ lruSize, ttl, messageNumber, id, swarm, protocol, }?: {
lruSize?: number | undefined;
ttl?: number | undefined;
messageNumber?: number | undefined;
id?: Buffer | undefined;
swarm?: null | undefined;
protocol?: string | undefined;
});
private handleMessage;
private setupPeer;

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;AAkBlC,eAAO,MAAM,YAAY,eAAuB,CAAC;AAEjD,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;gBAEP,EACV,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,GACb;;;;;;KAAK;IAkBN,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,SAAS;IA6CjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;IAenC,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,eAAO,MAAM,YAAY,eAAuB,CAAC;AAEjD,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;gBAEb,EACV,OAAkB,EAClB,GAAS,EACT,aAAiB,EACjB,EAA2B,EAC3B,KAAY,EACZ,QAAmB,GACpB;;;;;;;KAAK;IAmBN,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,SAAS;IA6CjB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;IAenC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,SAAW;CAY1C"}

8
dist/index.js vendored
View File

@ -26,19 +26,21 @@ class DHTFlood extends events_1.default {
messageNumber;
lru;
swarm;
constructor({ lruSize = LRU_SIZE, ttl = TTL, messageNumber = 0, id = crypto_1.default.randomBytes(32), swarm = null, } = {}) {
protocol;
constructor({ lruSize = LRU_SIZE, ttl = TTL, messageNumber = 0, id = crypto_1.default.randomBytes(32), swarm = null, protocol = PROTOCOL, } = {}) {
super();
this.id = id;
this.ttl = ttl;
this.messageNumber = messageNumber;
this.lru = new lru_1.default(lruSize);
this.protocol = protocol;
if (!swarm) {
throw new Error("swarm is required");
}
this.swarm = swarm;
this.swarm.on("connection", (peer) => {
const mux = protomux_1.default.from(peer);
mux.pair({ protocol: PROTOCOL }, () => this.setupPeer(peer));
mux.pair({ protocol: this.protocol }, () => this.setupPeer(peer));
});
}
handleMessage({ originId, messageNumber, ttl, data }, messenger) {
@ -68,7 +70,7 @@ class DHTFlood extends events_1.default {
const self = this;
if (!mux.opened({ protocol: PROTOCOL })) {
chan = mux.createChannel({
protocol: PROTOCOL,
protocol: this.protocol,
async onopen() {
self.emit("peer-open", peer);
},

View File

@ -24,6 +24,7 @@ export default class DHTFlood extends EventEmitter {
private messageNumber: number;
private lru: LRU;
private swarm: any;
private protocol: string;
constructor({
lruSize = LRU_SIZE,
@ -31,6 +32,7 @@ export default class DHTFlood extends EventEmitter {
messageNumber = 0,
id = crypto.randomBytes(32),
swarm = null,
protocol = PROTOCOL,
} = {}) {
super();
@ -38,6 +40,7 @@ export default class DHTFlood extends EventEmitter {
this.ttl = ttl;
this.messageNumber = messageNumber;
this.lru = new LRU(lruSize);
this.protocol = protocol;
if (!swarm) {
throw new Error("swarm is required");
}
@ -45,7 +48,7 @@ export default class DHTFlood extends EventEmitter {
this.swarm.on("connection", (peer: any) => {
const mux = Protomux.from(peer);
mux.pair({ protocol: PROTOCOL }, () => this.setupPeer(peer));
mux.pair({ protocol: this.protocol }, () => this.setupPeer(peer));
});
}
@ -91,7 +94,7 @@ export default class DHTFlood extends EventEmitter {
if (!mux.opened({ protocol: PROTOCOL })) {
chan = mux.createChannel({
protocol: PROTOCOL,
protocol: this.protocol,
async onopen() {
self.emit("peer-open", peer);
},