*Allow protocol to be configurable
This commit is contained in:
parent
175d66c994
commit
2d62822908
|
@ -24,6 +24,7 @@ export default class DHTFlood extends EventEmitter {
|
||||||
private messageNumber: number;
|
private messageNumber: number;
|
||||||
private lru: LRU;
|
private lru: LRU;
|
||||||
private swarm: any;
|
private swarm: any;
|
||||||
|
private protocol: string;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
lruSize = LRU_SIZE,
|
lruSize = LRU_SIZE,
|
||||||
|
@ -31,6 +32,7 @@ export default class DHTFlood extends EventEmitter {
|
||||||
messageNumber = 0,
|
messageNumber = 0,
|
||||||
id = crypto.randomBytes(32),
|
id = crypto.randomBytes(32),
|
||||||
swarm = null,
|
swarm = null,
|
||||||
|
protocol = PROTOCOL,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -38,6 +40,7 @@ export default class DHTFlood extends EventEmitter {
|
||||||
this.ttl = ttl;
|
this.ttl = ttl;
|
||||||
this.messageNumber = messageNumber;
|
this.messageNumber = messageNumber;
|
||||||
this.lru = new LRU(lruSize);
|
this.lru = new LRU(lruSize);
|
||||||
|
this.protocol = protocol;
|
||||||
if (!swarm) {
|
if (!swarm) {
|
||||||
throw new Error("swarm is required");
|
throw new Error("swarm is required");
|
||||||
}
|
}
|
||||||
|
@ -45,7 +48,7 @@ export default class DHTFlood extends EventEmitter {
|
||||||
|
|
||||||
this.swarm.on("connection", (peer: any) => {
|
this.swarm.on("connection", (peer: any) => {
|
||||||
const mux = Protomux.from(peer);
|
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 })) {
|
if (!mux.opened({ protocol: PROTOCOL })) {
|
||||||
chan = mux.createChannel({
|
chan = mux.createChannel({
|
||||||
protocol: PROTOCOL,
|
protocol: this.protocol,
|
||||||
async onopen() {
|
async onopen() {
|
||||||
self.emit("peer-open", peer);
|
self.emit("peer-open", peer);
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue