*Update dist
This commit is contained in:
parent
ef79936384
commit
993eff5398
|
@ -1,7 +1,6 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import EventEmitter from "events";
|
||||
export declare const FLOOD_SYMBOL: unique symbol;
|
||||
export default class DHTFlood extends EventEmitter {
|
||||
private id;
|
||||
private ttl;
|
||||
|
@ -9,6 +8,8 @@ export default class DHTFlood extends EventEmitter {
|
|||
private lru;
|
||||
private swarm;
|
||||
private protocol;
|
||||
private symbol;
|
||||
private socketMap;
|
||||
constructor({ lruSize, ttl, messageNumber, id, swarm, protocol, }?: {
|
||||
lruSize?: number | undefined;
|
||||
ttl?: number | undefined;
|
||||
|
|
|
@ -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;AAIjD,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;IAsDjB,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,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"}
|
|
@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FLOOD_SYMBOL = void 0;
|
||||
const events_1 = __importDefault(require("events"));
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
// @ts-ignore
|
||||
|
@ -19,8 +18,6 @@ const debug = (0, debug_1.default)("dht-flood");
|
|||
const LRU_SIZE = 255;
|
||||
const TTL = 255;
|
||||
const PROTOCOL = "lumeweb.flood";
|
||||
exports.FLOOD_SYMBOL = Symbol.for(PROTOCOL);
|
||||
const closedMap = new Set();
|
||||
class DHTFlood extends events_1.default {
|
||||
id;
|
||||
ttl;
|
||||
|
@ -28,6 +25,8 @@ class DHTFlood extends events_1.default {
|
|||
lru;
|
||||
swarm;
|
||||
protocol;
|
||||
symbol;
|
||||
socketMap = new Set();
|
||||
constructor({ lruSize = LRU_SIZE, ttl = TTL, messageNumber = 0, id = crypto_1.default.randomBytes(32), swarm = null, protocol = PROTOCOL, } = {}) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
@ -43,6 +42,7 @@ class DHTFlood extends events_1.default {
|
|||
const mux = protomux_1.default.from(peer);
|
||||
mux.pair({ protocol: this.protocol }, () => this.setupPeer(peer));
|
||||
});
|
||||
this.symbol = Symbol.for(this.protocol);
|
||||
}
|
||||
handleMessage({ originId, messageNumber, ttl, data }, messenger) {
|
||||
const originIdBuf = b4a_1.default.from(originId);
|
||||
|
@ -77,19 +77,21 @@ class DHTFlood extends events_1.default {
|
|||
},
|
||||
});
|
||||
if (chan) {
|
||||
peer[exports.FLOOD_SYMBOL] = chan;
|
||||
// @ts-ignore
|
||||
peer[this.symbol] = chan;
|
||||
}
|
||||
}
|
||||
if (!closedMap.has(peer)) {
|
||||
if (!this.socketMap.has(peer)) {
|
||||
const close = () => {
|
||||
self.emit("peer-remove", peer);
|
||||
peer.removeListener("close", close);
|
||||
closedMap.delete(peer);
|
||||
this.socketMap.delete(peer);
|
||||
};
|
||||
peer.on("close", close);
|
||||
closedMap.add(peer);
|
||||
this.socketMap.add(peer);
|
||||
}
|
||||
chan = peer[exports.FLOOD_SYMBOL];
|
||||
// @ts-ignore
|
||||
chan = peer[this.symbol];
|
||||
if (!chan) {
|
||||
throw new Error("could not find channel");
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { MessageType } from "@protobuf-ts/runtime";
|
|||
/**
|
||||
* @generated from protobuf message Packet
|
||||
*/
|
||||
export interface PacketType {
|
||||
export interface Packet {
|
||||
/**
|
||||
* @generated from protobuf field: bytes originId = 1;
|
||||
*/
|
||||
|
@ -25,11 +25,11 @@ export interface PacketType {
|
|||
*/
|
||||
data: Uint8Array;
|
||||
}
|
||||
declare class Packet$Type extends MessageType<PacketType> {
|
||||
declare class Packet$Type extends MessageType<Packet> {
|
||||
constructor();
|
||||
create(value?: PartialMessage<PacketType>): PacketType;
|
||||
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: PacketType): PacketType;
|
||||
internalBinaryWrite(message: PacketType, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
||||
create(value?: PartialMessage<Packet>): Packet;
|
||||
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Packet): Packet;
|
||||
internalBinaryWrite(message: Packet, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
||||
}
|
||||
/**
|
||||
* @generated MessageType for protobuf message Packet
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;IACrB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,cAAM,WAAY,SAAQ,WAAW,CAAC,UAAU,CAAC;;IAc/C,MAAM,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU;IAetD,kBAAkB,CAChB,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,EAC1B,MAAM,CAAC,EAAE,UAAU,GAClB,UAAU;IAqCb,mBAAmB,CACjB,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,kBAAkB,GAC1B,aAAa;CAqBjB;AACD;;GAEG;AACH,eAAO,MAAM,MAAM,aAAoB,CAAC"}
|
||||
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;IACrB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;CACpB;AAED,cAAM,WAAY,SAAQ,WAAW,CAAC,MAAM,CAAC;;IASzC,MAAM,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,MAAM;IAO9C,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IA4B9G,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,kBAAkB,GAAG,aAAa;CAkB1G;AACD;;GAEG;AACH,eAAO,MAAM,MAAM,aAAoB,CAAC"}
|
|
@ -11,27 +11,14 @@ class Packet$Type extends runtime_5.MessageType {
|
|||
constructor() {
|
||||
super("Packet", [
|
||||
{ no: 1, name: "originId", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
|
||||
{
|
||||
no: 2,
|
||||
name: "messageNumber",
|
||||
kind: "scalar",
|
||||
T: 13 /*ScalarType.UINT32*/,
|
||||
},
|
||||
{ no: 2, name: "messageNumber", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
||||
{ no: 3, name: "ttl", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
||||
{ no: 4, name: "data", kind: "scalar", T: 12 /*ScalarType.BYTES*/ },
|
||||
{ no: 4, name: "data", kind: "scalar", T: 12 /*ScalarType.BYTES*/ }
|
||||
]);
|
||||
}
|
||||
create(value) {
|
||||
const message = {
|
||||
originId: new Uint8Array(0),
|
||||
messageNumber: 0,
|
||||
ttl: 0,
|
||||
data: new Uint8Array(0),
|
||||
};
|
||||
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, {
|
||||
enumerable: false,
|
||||
value: this,
|
||||
});
|
||||
const message = { originId: new Uint8Array(0), messageNumber: 0, ttl: 0, data: new Uint8Array(0) };
|
||||
globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this });
|
||||
if (value !== undefined)
|
||||
(0, runtime_3.reflectionMergePartial)(this, message, value);
|
||||
return message;
|
||||
|
|
Loading…
Reference in New Issue