diff --git a/.gitignore b/.gitignore index 69f5439f..3b1ae85c 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,6 @@ build node_modules lib -dist test/test-data/go-ipfs-repo/LOCK test/test-data/go-ipfs-repo/LOG test/test-data/go-ipfs-repo/LOG.old diff --git a/dist/src/address-manager/index.d.ts b/dist/src/address-manager/index.d.ts new file mode 100644 index 00000000..b4768452 --- /dev/null +++ b/dist/src/address-manager/index.d.ts @@ -0,0 +1,73 @@ +export = AddressManager; +declare const AddressManager_base: import("../types").EventEmitterFactory; +/** + * @typedef {Object} AddressManagerOptions + * @property {string[]} [listen = []] - list of multiaddrs string representation to listen. + * @property {string[]} [announce = []] - list of multiaddrs string representation to announce. + */ +/** + * @fires AddressManager#change:addresses Emitted when a addresses change. + */ +declare class AddressManager extends AddressManager_base { + /** + * Responsible for managing the peer addresses. + * Peers can specify their listen and announce addresses. + * The listen addresses will be used by the libp2p transports to listen for new connections, + * while the announce addresses will be used for the peer addresses' to other peers in the network. + * + * @class + * @param {PeerId} peerId - The Peer ID of the node + * @param {object} [options] + * @param {Array} [options.listen = []] - list of multiaddrs string representation to listen. + * @param {Array} [options.announce = []] - list of multiaddrs string representation to announce. + */ + constructor(peerId: PeerId, { listen, announce }?: { + listen?: string[] | undefined; + announce?: string[] | undefined; + } | undefined); + peerId: PeerId; + listen: Set; + announce: Set; + observed: Set; + /** + * Get peer listen multiaddrs. + * + * @returns {Multiaddr[]} + */ + getListenAddrs(): Multiaddr[]; + /** + * Get peer announcing multiaddrs. + * + * @returns {Multiaddr[]} + */ + getAnnounceAddrs(): Multiaddr[]; + /** + * Get observed multiaddrs. + * + * @returns {Array} + */ + getObservedAddrs(): Array; + /** + * Add peer observed addresses + * + * @param {string | Multiaddr} addr + */ + addObservedAddr(addr: string | Multiaddr): void; +} +declare namespace AddressManager { + export { Events, AddressManagerOptions }; +} +import PeerId = require("peer-id"); +import { Multiaddr } from "multiaddr"; +type Events = import('../types').EventEmitterFactory; +type AddressManagerOptions = { + /** + * - list of multiaddrs string representation to listen. + */ + listen?: string[] | undefined; + /** + * - list of multiaddrs string representation to announce. + */ + announce?: string[] | undefined; +}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/address-manager/index.d.ts.map b/dist/src/address-manager/index.d.ts.map new file mode 100644 index 00000000..345ddb85 --- /dev/null +++ b/dist/src/address-manager/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.js"],"names":[],"mappings":";;AAQA;;;;GAIG;AAEH;;GAEG;AACH;IACE;;;;;;;;;;;OAWG;IACH,oBALW,MAAM;;;mBAYhB;IAJC,eAAoB;IACpB,oBAAsD;IACtD,sBAA0D;IAC1D,mBAAyB;IAG3B;;;;OAIG;IACH,kBAFa,SAAS,EAAE,CAIvB;IAED;;;;OAIG;IACH,oBAFa,SAAS,EAAE,CAIvB;IAED;;;;OAIG;IACH,oBAFa,MAAM,SAAS,CAAC,CAI5B;IAED;;;;OAIG;IACH,sBAFW,MAAM,GAAG,SAAS,QAyB5B;CACF;;;;;;cA7Fa,OAAO,UAAU,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/circuit/auto-relay.d.ts b/dist/src/circuit/auto-relay.d.ts new file mode 100644 index 00000000..72beff16 --- /dev/null +++ b/dist/src/circuit/auto-relay.d.ts @@ -0,0 +1,109 @@ +export = AutoRelay; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('../peer-store/address-book').Address} Address + */ +/** + * @typedef {Object} AutoRelayProperties + * @property {import('../')} libp2p + * + * @typedef {Object} AutoRelayOptions + * @property {number} [maxListeners = 1] - maximum number of relays to listen. + * @property {(error: Error, msg?: string) => {}} [onError] + */ +declare class AutoRelay { + /** + * Creates an instance of AutoRelay. + * + * @class + * @param {AutoRelayProperties & AutoRelayOptions} props + */ + constructor({ libp2p, maxListeners, onError }: AutoRelayProperties & AutoRelayOptions); + _libp2p: import("../"); + _peerId: PeerId; + _peerStore: import("../peer-store"); + _connectionManager: import("../connection-manager"); + _transportManager: import("../transport-manager"); + _addressSorter: (addresses: import("../peer-store/address-book").Address[]) => import("../peer-store/address-book").Address[]; + maxListeners: number; + /** + * @type {Set} + */ + _listenRelays: Set; + /** + * Check if a peer supports the relay protocol. + * If the protocol is not supported, check if it was supported before and remove it as a listen relay. + * If the protocol is supported, check if the peer supports **HOP** and add it as a listener if + * inside the threshold. + * + * @param {Object} props + * @param {PeerId} props.peerId + * @param {string[]} props.protocols + * @returns {Promise} + */ + _onProtocolChange({ peerId, protocols }: { + peerId: PeerId; + protocols: string[]; + }): Promise; + /** + * Peer disconnects. + * + * @param {Connection} connection - connection to the peer + * @returns {void} + */ + _onPeerDisconnected(connection: Connection): void; + /** + * @param {Error} error + * @param {string} [msg] + */ + _onError: (error: Error, msg?: string | undefined) => void; + /** + * Attempt to listen on the given relay connection. + * + * @private + * @param {Connection} connection - connection to the peer + * @param {string} id - peer identifier string + * @returns {Promise} + */ + private _addListenRelay; + /** + * Remove listen relay. + * + * @private + * @param {string} id - peer identifier string. + * @returns {void} + */ + private _removeListenRelay; + /** + * Try to listen on available hop relay connections. + * The following order will happen while we do not have enough relays. + * 1. Check the metadata store for known relays, try to listen on the ones we are already connected. + * 2. Dial and try to listen on the peers we know that support hop but are not connected. + * 3. Search the network. + * + * @param {string[]} [peersToIgnore] + * @returns {Promise} + */ + _listenOnAvailableHopRelays(peersToIgnore?: string[] | undefined): Promise; + /** + * @param {PeerId} peerId + */ + _tryToListenOnRelay(peerId: PeerId): Promise; +} +declare namespace AutoRelay { + export { Connection, Address, AutoRelayProperties, AutoRelayOptions }; +} +import PeerId = require("peer-id"); +type Connection = import("libp2p-interfaces/src/connection/connection"); +type AutoRelayProperties = { + libp2p: import('../'); +}; +type AutoRelayOptions = { + /** + * - maximum number of relays to listen. + */ + maxListeners?: number | undefined; + onError?: ((error: Error, msg?: string | undefined) => {}) | undefined; +}; +type Address = import('../peer-store/address-book').Address; +//# sourceMappingURL=auto-relay.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/auto-relay.d.ts.map b/dist/src/circuit/auto-relay.d.ts.map new file mode 100644 index 00000000..e6aaa3ce --- /dev/null +++ b/dist/src/circuit/auto-relay.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"auto-relay.d.ts","sourceRoot":"","sources":["../../../src/circuit/auto-relay.js"],"names":[],"mappings":";AAsBA;;;GAGG;AAEH;;;;;;;GAOG;AAEH;IACE;;;;;OAKG;IACH,+CAFW,mBAAmB,GAAG,gBAAgB,EA+BhD;IA5BC,uBAAqB;IACrB,gBAA4B;IAC5B,oCAAkC;IAClC,oDAAkD;IAClD,kDAAgD;IAChD,8HAAiD;IAEjD,qBAAgC;IAEhC;;OAEG;IACH,eAFU,IAAI,MAAM,CAAC,CAES;IAkBhC;;;;;;;;;;OAUG;IACH;QAJyB,MAAM,EAApB,MAAM;QACU,SAAS,EAAzB,MAAM,EAAE;QACN,QAAQ,IAAI,CAAC,CAsCzB;IAED;;;;;OAKG;IACH,gCAHW,UAAU,GACR,IAAI,CAYhB;IA3EC;;;OAGG;IACH,kBAHW,KAAK,oCAMf;IAsEH;;;;;;;OAOG;IACH,wBA0BC;IAED;;;;;;OAMG;IACH,2BAKC;IAED;;;;;;;;;OASG;IACH,mEAFa,QAAQ,IAAI,CAAC,CAyEzB;IAED;;OAEG;IACH,4BAFW,MAAM,iBAShB;CACF;;;;;;;YAhQa,OAAO,KAAK,CAAC;;;;;;;uBAIL,KAAK,+BAAmB,EAAE;;eATnC,OAAO,4BAA4B,EAAE,OAAO"} \ No newline at end of file diff --git a/dist/src/circuit/circuit/hop.d.ts b/dist/src/circuit/circuit/hop.d.ts new file mode 100644 index 00000000..aabee158 --- /dev/null +++ b/dist/src/circuit/circuit/hop.d.ts @@ -0,0 +1,67 @@ +export type ICircuitRelay = import('../protocol').ICircuitRelay; +export type Connection = import("libp2p-interfaces/src/connection/connection"); +export type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +export type Transport = import('../transport'); +export type HopRequest = { + connection: Connection; + request: ICircuitRelay; + streamHandler: StreamHandler; + circuit: Transport; +}; +/** + * @typedef {import('../protocol').ICircuitRelay} ICircuitRelay + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('../transport')} Transport + */ +/** + * @typedef {Object} HopRequest + * @property {Connection} connection + * @property {ICircuitRelay} request + * @property {StreamHandler} streamHandler + * @property {Transport} circuit + */ +/** + * @param {HopRequest} options + * @returns {Promise} + */ +export function handleHop({ connection, request, streamHandler, circuit }: HopRequest): Promise; +/** + * Performs a HOP request to a relay peer, to request a connection to another + * peer. A new, virtual, connection will be created between the two via the relay. + * + * @param {object} options + * @param {Connection} options.connection - Connection to the relay + * @param {ICircuitRelay} options.request + * @returns {Promise} + */ +export function hop({ connection, request }: { + connection: Connection; + request: ICircuitRelay; +}): Promise; +/** + * Performs a CAN_HOP request to a relay peer, in order to understand its capabilities. + * + * @param {object} options + * @param {Connection} options.connection - Connection to the relay + * @returns {Promise} + */ +export function canHop({ connection }: { + connection: Connection; +}): Promise; +/** + * Creates an unencoded CAN_HOP response based on the Circuits configuration + * + * @param {Object} options + * @param {Connection} options.connection + * @param {StreamHandler} options.streamHandler + * @param {Transport} options.circuit + * @private + */ +export function handleCanHop({ connection, streamHandler, circuit }: { + connection: Connection; + streamHandler: StreamHandler; + circuit: Transport; +}): void; +import StreamHandler = require("./stream-handler"); +//# sourceMappingURL=hop.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/circuit/hop.d.ts.map b/dist/src/circuit/circuit/hop.d.ts.map new file mode 100644 index 00000000..0e79880e --- /dev/null +++ b/dist/src/circuit/circuit/hop.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hop.d.ts","sourceRoot":"","sources":["../../../../src/circuit/circuit/hop.js"],"names":[],"mappings":"4BAoBa,OAAO,aAAa,EAAE,aAAa;;0BAEnC,OAAO,0CAA0C,EAAE,WAAW;wBAC9D,OAAO,cAAc,CAAC;;gBAKrB,UAAU;aACV,aAAa;mBACb,aAAa;aACb,SAAS;;AAZvB;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AACH,2EAHW,UAAU,GACR,QAAQ,IAAI,CAAC,CA4EzB;AAED;;;;;;;;GAQG;AACH;IAJ+B,UAAU,EAA9B,UAAU;IACa,OAAO,EAA9B,aAAa;IACX,QAAQ,WAAW,CAAC,CA0BhC;AAED;;;;;;GAMG;AACH;IAH+B,UAAU,EAA9B,UAAU;IACR,QAAQ,OAAO,CAAC,CAqB5B;AAED;;;;;;;;GAQG;AACH;IAL+B,UAAU,EAA9B,UAAU;IACa,aAAa,EAApC,aAAa;IACM,OAAO,EAA1B,SAAS;SAcnB"} \ No newline at end of file diff --git a/dist/src/circuit/circuit/stop.d.ts b/dist/src/circuit/circuit/stop.d.ts new file mode 100644 index 00000000..2b4d9091 --- /dev/null +++ b/dist/src/circuit/circuit/stop.d.ts @@ -0,0 +1,14 @@ +export function handleStop({ connection, request, streamHandler }: { + connection: Connection; + request: ICircuitRelay; + streamHandler: StreamHandler; +}): Promise | void; +export function stop({ connection, request }: { + connection: Connection; + request: ICircuitRelay; +}): Promise; +export type Connection = import("libp2p-interfaces/src/connection/connection"); +export type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +export type ICircuitRelay = import('../protocol').ICircuitRelay; +import StreamHandler = require("./stream-handler"); +//# sourceMappingURL=stop.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/circuit/stop.d.ts.map b/dist/src/circuit/circuit/stop.d.ts.map new file mode 100644 index 00000000..e8cd7a4c --- /dev/null +++ b/dist/src/circuit/circuit/stop.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../../src/circuit/circuit/stop.js"],"names":[],"mappings":"AA4B4B;IALG,UAAU,EAA9B,UAAU;IACa,OAAO,EAA9B,aAAa;IACU,aAAa,EAApC,aAAa;IACX,QAAQ,WAAW,CAAC,GAAC,IAAI,CAqBrC;AAWqB;IAJS,UAAU,EAA9B,UAAU;IACa,OAAO,EAA9B,aAAa;IACX,QAAQ,WAAW,GAAC,IAAI,CAAC,CAwBrC;;0BAlEY,OAAO,0CAA0C,EAAE,WAAW;4BAC9D,OAAO,aAAa,EAAE,aAAa"} \ No newline at end of file diff --git a/dist/src/circuit/circuit/stream-handler.d.ts b/dist/src/circuit/circuit/stream-handler.d.ts new file mode 100644 index 00000000..c1fa53ce --- /dev/null +++ b/dist/src/circuit/circuit/stream-handler.d.ts @@ -0,0 +1,58 @@ +export = StreamHandler; +/** + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('../protocol').ICircuitRelay} ICircuitRelay + */ +declare class StreamHandler { + /** + * Create a stream handler for connection + * + * @class + * @param {object} options + * @param {MuxedStream} options.stream - A duplex iterable + * @param {number} [options.maxLength = 4096] - max bytes length of message + */ + constructor({ stream, maxLength }: { + stream: MuxedStream; + maxLength?: number | undefined; + }); + stream: import("libp2p-interfaces/src/stream-muxer/types").MuxedStream; + shake: any; + decoder: AsyncGenerator; + /** + * Read and decode message + * + * @async + */ + read(): Promise; + /** + * Encode and write array of buffers + * + * @param {ICircuitRelay} msg - An unencoded CircuitRelay protobuf message + * @returns {void} + */ + write(msg: ICircuitRelay): void; + /** + * Return the handshake rest stream and invalidate handler + * + * @returns {*} A duplex iterable + */ + rest(): any; + /** + * @param {ICircuitRelay} msg - An unencoded CircuitRelay protobuf message + */ + end(msg: ICircuitRelay): void; + /** + * Close the stream + * + * @returns {void} + */ + close(): void; +} +declare namespace StreamHandler { + export { MuxedStream, ICircuitRelay }; +} +import { CircuitRelay } from "../protocol"; +type ICircuitRelay = import('../protocol').ICircuitRelay; +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +//# sourceMappingURL=stream-handler.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/circuit/stream-handler.d.ts.map b/dist/src/circuit/circuit/stream-handler.d.ts.map new file mode 100644 index 00000000..f2bcab52 --- /dev/null +++ b/dist/src/circuit/circuit/stream-handler.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../../../src/circuit/circuit/stream-handler.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;IACE;;;;;;;OAOG;IACH;QAHgC,MAAM,EAA3B,WAAW;QACM,SAAS;OAQpC;IALC,uEAAoB;IAEpB,WAAmC;IAEnC,4CAAoF;IAGtF;;;;OAIG;IACH,0CAWC;IAED;;;;;OAKG;IACH,WAHW,aAAa,GACX,IAAI,CAMhB;IAED;;;;OAIG;IACH,YAGC;IAED;;OAEG;IACH,SAFW,aAAa,QAKvB;IAED;;;;OAIG;IACH,SAFa,IAAI,CAKhB;CACF;;;;;qBA7EY,OAAO,aAAa,EAAE,aAAa;mBADnC,OAAO,0CAA0C,EAAE,WAAW"} \ No newline at end of file diff --git a/dist/src/circuit/circuit/utils.d.ts b/dist/src/circuit/circuit/utils.d.ts new file mode 100644 index 00000000..0076087c --- /dev/null +++ b/dist/src/circuit/circuit/utils.d.ts @@ -0,0 +1,10 @@ +export type StreamHandler = import('./stream-handler'); +export type ICircuitRelay = import('../protocol').ICircuitRelay; +/** + * Validate incomming HOP/STOP message + * + * @param {ICircuitRelay} msg - A CircuitRelay unencoded protobuf message + * @param {StreamHandler} streamHandler + */ +export function validateAddrs(msg: ICircuitRelay, streamHandler: StreamHandler): void; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/circuit/utils.d.ts.map b/dist/src/circuit/circuit/utils.d.ts.map new file mode 100644 index 00000000..60811e49 --- /dev/null +++ b/dist/src/circuit/circuit/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/circuit/circuit/utils.js"],"names":[],"mappings":"4BAMa,OAAO,kBAAkB,CAAC;4BAC1B,OAAO,aAAa,EAAE,aAAa;AAgBhD;;;;;GAKG;AACH,mCAHW,aAAa,iBACb,aAAa,QA4BvB"} \ No newline at end of file diff --git a/dist/src/circuit/constants.d.ts b/dist/src/circuit/constants.d.ts new file mode 100644 index 00000000..56df991a --- /dev/null +++ b/dist/src/circuit/constants.d.ts @@ -0,0 +1,7 @@ +export const ADVERTISE_BOOT_DELAY: number; +export const ADVERTISE_TTL: number; +export const CIRCUIT_PROTO_CODE: number; +export const HOP_METADATA_KEY: string; +export const HOP_METADATA_VALUE: string; +export const RELAY_RENDEZVOUS_NS: string; +//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/constants.d.ts.map b/dist/src/circuit/constants.d.ts.map new file mode 100644 index 00000000..634b461c --- /dev/null +++ b/dist/src/circuit/constants.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/circuit/constants.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/circuit/index.d.ts b/dist/src/circuit/index.d.ts new file mode 100644 index 00000000..44446bb9 --- /dev/null +++ b/dist/src/circuit/index.d.ts @@ -0,0 +1,85 @@ +export = Relay; +/** + * @typedef {import('../')} Libp2p + * + * @typedef {Object} RelayAdvertiseOptions + * @property {number} [bootDelay = ADVERTISE_BOOT_DELAY] + * @property {boolean} [enabled = true] + * @property {number} [ttl = ADVERTISE_TTL] + * + * @typedef {Object} HopOptions + * @property {boolean} [enabled = false] + * @property {boolean} [active = false] + * + * @typedef {Object} AutoRelayOptions + * @property {number} [maxListeners = 2] - maximum number of relays to listen. + * @property {boolean} [enabled = false] + */ +declare class Relay { + /** + * Creates an instance of Relay. + * + * @class + * @param {Libp2p} libp2p + */ + constructor(libp2p: Libp2p); + _libp2p: import("../"); + _options: { + enabled: boolean; + advertise: { + bootDelay: number; + enabled: boolean; + ttl: number; + } & RelayAdvertiseOptions; + hop: { + enabled: boolean; + active: boolean; + } & HopOptions; + autoRelay: { + enabled: boolean; + maxListeners: number; + } & AutoRelayOptions; + }; + _autoRelay: false | AutoRelay; + /** + * Advertise hop relay service in the network. + * + * @returns {Promise} + */ + _advertiseService(): Promise; + /** + * Start Relay service. + * + * @returns {void} + */ + start(): void; + _timeout: any; + /** + * Stop Relay service. + * + * @returns {void} + */ + stop(): void; +} +declare namespace Relay { + export { Libp2p, RelayAdvertiseOptions, HopOptions, AutoRelayOptions }; +} +type RelayAdvertiseOptions = { + bootDelay?: number | undefined; + enabled?: boolean | undefined; + ttl?: number | undefined; +}; +type HopOptions = { + enabled?: boolean | undefined; + active?: boolean | undefined; +}; +type AutoRelayOptions = { + /** + * - maximum number of relays to listen. + */ + maxListeners?: number | undefined; + enabled?: boolean | undefined; +}; +import AutoRelay = require("./auto-relay"); +type Libp2p = import('../'); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/index.d.ts.map b/dist/src/circuit/index.d.ts.map new file mode 100644 index 00000000..f9453bb2 --- /dev/null +++ b/dist/src/circuit/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/circuit/index.js"],"names":[],"mappings":";AAmBA;;;;;;;;;;;;;;;GAeG;AAEH;IACE;;;;;OAKG;IACH,oBAFW,MAAM,EAYhB;IATC,uBAAqB;IACrB;;;;;;;;;;;;;;;MAEC;IAGD,8BAA0G;IA8B5G;;;;OAIG;IACH,qBAFa,QAAQ,IAAI,CAAC,CAezB;IA3CD;;;;OAIG;IACH,SAFa,IAAI,CAWhB;IAJG,cAEC;IAIL;;;;OAIG;IACH,QAFa,IAAI,CAIhB;CAqBF;;;;;;;;;;;;;;;;;;;;;cA/EY,OAAO,KAAK,CAAC"} \ No newline at end of file diff --git a/dist/src/circuit/listener.d.ts b/dist/src/circuit/listener.d.ts new file mode 100644 index 00000000..82dd0564 --- /dev/null +++ b/dist/src/circuit/listener.d.ts @@ -0,0 +1,5 @@ +declare function _exports(libp2p: import('../')): Listener; +export = _exports; +export type Events = import('../types').EventEmitterFactory; +export type Listener = import('libp2p-interfaces/src/transport/types').Listener; +//# sourceMappingURL=listener.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/listener.d.ts.map b/dist/src/circuit/listener.d.ts.map new file mode 100644 index 00000000..57ff4328 --- /dev/null +++ b/dist/src/circuit/listener.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/circuit/listener.js"],"names":[],"mappings":"AAeiB,kCAHN,OAAO,KAAK,CAAC,GACX,QAAQ,CA+DpB;;qBA1Ea,OAAO,UAAU,EAAE,mBAAmB;uBAMvC,OAAO,uCAAuC,EAAE,QAAQ"} \ No newline at end of file diff --git a/dist/src/circuit/multicodec.d.ts b/dist/src/circuit/multicodec.d.ts new file mode 100644 index 00000000..c78b406c --- /dev/null +++ b/dist/src/circuit/multicodec.d.ts @@ -0,0 +1,2 @@ +export const relay: string; +//# sourceMappingURL=multicodec.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/multicodec.d.ts.map b/dist/src/circuit/multicodec.d.ts.map new file mode 100644 index 00000000..53249c22 --- /dev/null +++ b/dist/src/circuit/multicodec.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multicodec.d.ts","sourceRoot":"","sources":["../../../src/circuit/multicodec.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/circuit/protocol/index.d.ts b/dist/src/circuit/protocol/index.d.ts new file mode 100644 index 00000000..68e4880b --- /dev/null +++ b/dist/src/circuit/protocol/index.d.ts @@ -0,0 +1,173 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a CircuitRelay. */ +export interface ICircuitRelay { + + /** CircuitRelay type */ + type?: (CircuitRelay.Type|null); + + /** CircuitRelay srcPeer */ + srcPeer?: (CircuitRelay.IPeer|null); + + /** CircuitRelay dstPeer */ + dstPeer?: (CircuitRelay.IPeer|null); + + /** CircuitRelay code */ + code?: (CircuitRelay.Status|null); +} + +/** Represents a CircuitRelay. */ +export class CircuitRelay implements ICircuitRelay { + + /** + * Constructs a new CircuitRelay. + * @param [p] Properties to set + */ + constructor(p?: ICircuitRelay); + + /** CircuitRelay type. */ + public type: CircuitRelay.Type; + + /** CircuitRelay srcPeer. */ + public srcPeer?: (CircuitRelay.IPeer|null); + + /** CircuitRelay dstPeer. */ + public dstPeer?: (CircuitRelay.IPeer|null); + + /** CircuitRelay code. */ + public code: CircuitRelay.Status; + + /** + * Encodes the specified CircuitRelay message. Does not implicitly {@link CircuitRelay.verify|verify} messages. + * @param m CircuitRelay message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: ICircuitRelay, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a CircuitRelay message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns CircuitRelay + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): CircuitRelay; + + /** + * Creates a CircuitRelay message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns CircuitRelay + */ + public static fromObject(d: { [k: string]: any }): CircuitRelay; + + /** + * Creates a plain object from a CircuitRelay message. Also converts values to other types if specified. + * @param m CircuitRelay + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: CircuitRelay, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this CircuitRelay to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace CircuitRelay { + + /** Status enum. */ + enum Status { + SUCCESS = 100, + HOP_SRC_ADDR_TOO_LONG = 220, + HOP_DST_ADDR_TOO_LONG = 221, + HOP_SRC_MULTIADDR_INVALID = 250, + HOP_DST_MULTIADDR_INVALID = 251, + HOP_NO_CONN_TO_DST = 260, + HOP_CANT_DIAL_DST = 261, + HOP_CANT_OPEN_DST_STREAM = 262, + HOP_CANT_SPEAK_RELAY = 270, + HOP_CANT_RELAY_TO_SELF = 280, + STOP_SRC_ADDR_TOO_LONG = 320, + STOP_DST_ADDR_TOO_LONG = 321, + STOP_SRC_MULTIADDR_INVALID = 350, + STOP_DST_MULTIADDR_INVALID = 351, + STOP_RELAY_REFUSED = 390, + MALFORMED_MESSAGE = 400 + } + + /** Type enum. */ + enum Type { + HOP = 1, + STOP = 2, + STATUS = 3, + CAN_HOP = 4 + } + + /** Properties of a Peer. */ + interface IPeer { + + /** Peer id */ + id: Uint8Array; + + /** Peer addrs */ + addrs?: (Uint8Array[]|null); + } + + /** Represents a Peer. */ + class Peer implements IPeer { + + /** + * Constructs a new Peer. + * @param [p] Properties to set + */ + constructor(p?: CircuitRelay.IPeer); + + /** Peer id. */ + public id: Uint8Array; + + /** Peer addrs. */ + public addrs: Uint8Array[]; + + /** + * Encodes the specified Peer message. Does not implicitly {@link CircuitRelay.Peer.verify|verify} messages. + * @param m Peer message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: CircuitRelay.IPeer, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Peer message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Peer + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): CircuitRelay.Peer; + + /** + * Creates a Peer message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Peer + */ + public static fromObject(d: { [k: string]: any }): CircuitRelay.Peer; + + /** + * Creates a plain object from a Peer message. Also converts values to other types if specified. + * @param m Peer + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: CircuitRelay.Peer, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Peer to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/dist/src/circuit/transport.d.ts b/dist/src/circuit/transport.d.ts new file mode 100644 index 00000000..001fdbb2 --- /dev/null +++ b/dist/src/circuit/transport.d.ts @@ -0,0 +1,93 @@ +export = Circuit; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + */ +declare class Circuit { + /** + * Checks if the given value is a Transport instance. + * + * @param {any} other + * @returns {other is Transport} + */ + static isTransport(other: any): other is Transport; + /** + * Creates an instance of the Circuit Transport. + * + * @class + * @param {object} options + * @param {import('../')} options.libp2p + * @param {import('../upgrader')} options.upgrader + */ + constructor({ libp2p, upgrader }: { + libp2p: import('../'); + upgrader: import('../upgrader'); + }); + _dialer: import("../dialer"); + _registrar: import("../registrar"); + _connectionManager: import("../connection-manager"); + _upgrader: import("../upgrader"); + _options: { + enabled: boolean; + advertise: { + bootDelay: number; + enabled: boolean; + ttl: number; + }; + hop: { + enabled: boolean; + active: boolean; + }; + autoRelay: { + enabled: boolean; + maxListeners: number; + }; + } & import("../").RelayOptions; + _libp2p: import("../"); + peerId: PeerId; + /** + * @param {Object} props + * @param {Connection} props.connection + * @param {MuxedStream} props.stream + */ + _onProtocol({ connection, stream }: { + connection: Connection; + stream: MuxedStream; + }): Promise; + /** + * Dial a peer over a relay + * + * @param {Multiaddr} ma - the multiaddr of the peer to dial + * @param {Object} options - dial options + * @param {AbortSignal} [options.signal] - An optional abort signal + * @returns {Promise} - the connection + */ + dial(ma: Multiaddr, options: { + signal?: AbortSignal | undefined; + }): Promise; + /** + * Create a listener + * + * @param {any} options + * @param {Function} handler + * @returns {import('libp2p-interfaces/src/transport/types').Listener} + */ + createListener(options: any, handler: Function): import('libp2p-interfaces/src/transport/types').Listener; + handler: Function | undefined; + /** + * Filter check for all Multiaddrs that this transport can dial on + * + * @param {Multiaddr[]} multiaddrs + * @returns {Multiaddr[]} + */ + filter(multiaddrs: Multiaddr[]): Multiaddr[]; + get [Symbol.toStringTag](): string; +} +declare namespace Circuit { + export { Connection, MuxedStream }; +} +import PeerId = require("peer-id"); +type Connection = import("libp2p-interfaces/src/connection/connection"); +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +import { Multiaddr } from "multiaddr"; +//# sourceMappingURL=transport.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/transport.d.ts.map b/dist/src/circuit/transport.d.ts.map new file mode 100644 index 00000000..03300b85 --- /dev/null +++ b/dist/src/circuit/transport.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/circuit/transport.js"],"names":[],"mappings":";AAwBA;;;GAGG;AAEH;IA4LE;;;;;OAKG;IACH,0BAHW,GAAG,sBAKb;IAnMD;;;;;;;OAOG;IACH;QAHkC,MAAM,EAA7B,OAAO,KAAK,CAAC;QACkB,QAAQ,EAAvC,OAAO,aAAa,CAAC;OAY/B;IATC,6BAA4B;IAC5B,mCAAkC;IAClC,oDAAkD;IAClD,iCAAyB;IACzB;;;;;;;;;;;;;;;mCAAoC;IACpC,uBAAqB;IACrB,eAA2B;IAK7B;;;;OAIG;IACH;QAH6B,UAAU,EAA5B,UAAU;QACS,MAAM,EAAzB,WAAW;sBA6DrB;IAED;;;;;;;OAOG;IACH,SALW,SAAS;QAEa,MAAM;QAC1B,QAAQ,UAAU,CAAC,CAwD/B;IAED;;;;;;OAMG;IACH,wBAJW,GAAG,sBAED,OAAO,uCAAuC,EAAE,QAAQ,CAYpE;IAHC,8BAAsB;IAKxB;;;;;OAKG;IACH,mBAHW,SAAS,EAAE,GACT,SAAS,EAAE,CAQvB;IAED,mCAEC;CAWF;;;;;;mBAxMY,OAAO,0CAA0C,EAAE,WAAW"} \ No newline at end of file diff --git a/dist/src/circuit/utils.d.ts b/dist/src/circuit/utils.d.ts new file mode 100644 index 00000000..9a989d3e --- /dev/null +++ b/dist/src/circuit/utils.d.ts @@ -0,0 +1,3 @@ +export function namespaceToCid(namespace: string): Promise; +import CID = require("cids"); +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/circuit/utils.d.ts.map b/dist/src/circuit/utils.d.ts.map new file mode 100644 index 00000000..6826ced2 --- /dev/null +++ b/dist/src/circuit/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/circuit/utils.js"],"names":[],"mappings":"AAagC,0CAHrB,MAAM,GACJ,QAAQ,GAAG,CAAC,CAOxB"} \ No newline at end of file diff --git a/dist/src/config.d.ts b/dist/src/config.d.ts new file mode 100644 index 00000000..216de4a5 --- /dev/null +++ b/dist/src/config.d.ts @@ -0,0 +1,90 @@ +export function validate(opts: Libp2pOptions): { + addresses: { + listen: never[]; + announce: never[]; + noAnnounce: never[]; + announceFilter: (multiaddrs: Multiaddr[]) => import("multiaddr").Multiaddr[]; + }; + connectionManager: { + minConnections: number; + }; + transportManager: { + faultTolerance: number; + }; + dialer: { + maxParallelDials: number; + maxDialsPerPeer: number; + dialTimeout: number; + resolvers: { + dnsaddr: any; + }; + addressSorter: typeof publicAddressesFirst; + }; + host: { + agentVersion: string; + }; + metrics: { + enabled: boolean; + }; + peerStore: { + persistence: boolean; + threshold: number; + }; + peerRouting: { + refreshManager: { + enabled: boolean; + interval: number; + bootDelay: number; + }; + }; + config: { + dht: { + enabled: boolean; + kBucketSize: number; + randomWalk: { + enabled: boolean; + queriesPerPeriod: number; + interval: number; + timeout: number; + }; + }; + nat: { + enabled: boolean; + ttl: number; + keepAlive: boolean; + gateway: null; + externalIp: null; + pmp: { + enabled: boolean; + }; + }; + peerDiscovery: { + autoDial: boolean; + }; + pubsub: { + enabled: boolean; + }; + relay: { + enabled: boolean; + advertise: { + bootDelay: number; + enabled: boolean; + ttl: number; + }; + hop: { + enabled: boolean; + active: boolean; + }; + autoRelay: { + enabled: boolean; + maxListeners: number; + }; + }; + transport: {}; + }; +} & Libp2pOptions & constructorOptions; +export type Multiaddr = import('multiaddr').Multiaddr; +export type Libp2pOptions = import('.').Libp2pOptions; +export type constructorOptions = import('.').constructorOptions; +import { publicAddressesFirst } from "libp2p-utils/src/address-sort"; +//# sourceMappingURL=config.d.ts.map \ No newline at end of file diff --git a/dist/src/config.d.ts.map b/dist/src/config.d.ts.map new file mode 100644 index 00000000..14948616 --- /dev/null +++ b/dist/src/config.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.js"],"names":[],"mappings":"AA6G0B,+BAHf,aAAa,GACX;;;;;qCAnFmB,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAmFd,aAAa,GAAG,kBAAkB,CAS9D;wBAtGY,OAAO,WAAW,EAAE,SAAS;4BAC7B,OAAO,GAAG,EAAE,aAAa;iCACzB,OAAO,GAAG,EAAE,kBAAkB"} \ No newline at end of file diff --git a/dist/src/connection-manager/index.d.ts b/dist/src/connection-manager/index.d.ts new file mode 100644 index 00000000..e8c53c20 --- /dev/null +++ b/dist/src/connection-manager/index.d.ts @@ -0,0 +1,205 @@ +export = ConnectionManager; +declare const ConnectionManager_base: import("../types").EventEmitterFactory; +/** + * @typedef {import('../')} Libp2p + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + */ +/** + * @typedef {Object} ConnectionManagerOptions + * @property {number} [maxConnections = Infinity] - The maximum number of connections allowed. + * @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning. + * @property {number} [maxData = Infinity] - The max data (in and out), per average interval to allow. + * @property {number} [maxSentData = Infinity] - The max outgoing data, per average interval to allow. + * @property {number} [maxReceivedData = Infinity] - The max incoming data, per average interval to allow. + * @property {number} [maxEventLoopDelay = Infinity] - The upper limit the event loop can take to run. + * @property {number} [pollInterval = 2000] - How often, in milliseconds, metrics and latency should be checked. + * @property {number} [movingAverageInterval = 60000] - How often, in milliseconds, to compute averages. + * @property {number} [defaultPeerValue = 1] - The value of the peer. + * @property {boolean} [autoDial = true] - Should preemptively guarantee connections are above the low watermark. + * @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark. + */ +/** + * + * @fires ConnectionManager#peer:connect Emitted when a new peer is connected. + * @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected. + */ +declare class ConnectionManager extends ConnectionManager_base { + /** + * Responsible for managing known connections. + * + * @class + * @param {Libp2p} libp2p + * @param {ConnectionManagerOptions} options + */ + constructor(libp2p: Libp2p, options?: ConnectionManagerOptions); + _libp2p: import("../"); + _peerId: string; + _options: any; + /** + * Map of peer identifiers to their peer value for pruning connections. + * + * @type {Map} + */ + _peerValues: Map; + /** + * Map of connections per peer + * + * @type {Map} + */ + connections: Map; + _started: boolean; + _timer: any; + _autoDialTimeout: any; + /** + * Checks the libp2p metrics to determine if any values have exceeded + * the configured maximums. + * + * @private + */ + private _checkMetrics; + /** + * Proactively tries to connect to known peers stored in the PeerStore. + * It will keep the number of connections below the upper limit and sort + * the peers to connect based on wether we know their keys and protocols. + * + * @async + * @private + */ + private _autoDial; + /** + * Get current number of open connections. + */ + get size(): number; + /** + * Starts the Connection Manager. If Metrics are not enabled on libp2p + * only event loop and connection limits will be monitored. + */ + start(): void; + _latencyMonitor: LatencyMonitor | undefined; + /** + * If the event loop is slow, maybe close a connection + * + * @private + * @param {*} summary - The LatencyMonitor summary + */ + private _onLatencyMeasure; + /** + * Stops the Connection Manager + * + * @async + */ + stop(): Promise; + /** + * Cleans up the connections + * + * @async + */ + _close(): Promise; + /** + * Sets the value of the given peer. Peers with lower values + * will be disconnected first. + * + * @param {PeerId} peerId + * @param {number} value - A number between 0 and 1 + * @returns {void} + */ + setPeerValue(peerId: PeerId, value: number): void; + /** + * Tracks the incoming connection and check the connection limit + * + * @param {Connection} connection + * @returns {void} + */ + onConnect(connection: Connection): void; + /** + * Removes the connection from tracking + * + * @param {Connection} connection + * @returns {void} + */ + onDisconnect(connection: Connection): void; + /** + * Get a connection with a peer. + * + * @param {PeerId} peerId + * @returns {Connection|null} + */ + get(peerId: PeerId): Connection | null; + /** + * Get all open connections with a peer. + * + * @param {PeerId} peerId + * @returns {Connection[]} + */ + getAll(peerId: PeerId): Connection[]; + /** + * If the `value` of `name` has exceeded its limit, maybe close a connection + * + * @private + * @param {string} name - The name of the field to check limits for + * @param {number} value - The current value of the field + */ + private _checkMaxLimit; + /** + * If we have more connections than our maximum, close a connection + * to the lowest valued peer. + * + * @private + */ + private _maybeDisconnectOne; +} +declare namespace ConnectionManager { + export { Events, Libp2p, Connection, ConnectionManagerOptions }; +} +type Connection = import("libp2p-interfaces/src/connection/connection"); +import LatencyMonitor = require("./latency-monitor"); +import PeerId = require("peer-id"); +type Libp2p = import('../'); +type ConnectionManagerOptions = { + /** + * - The maximum number of connections allowed. + */ + maxConnections?: number | undefined; + /** + * - The minimum number of connections to avoid pruning. + */ + minConnections?: number | undefined; + /** + * - The max data (in and out), per average interval to allow. + */ + maxData?: number | undefined; + /** + * - The max outgoing data, per average interval to allow. + */ + maxSentData?: number | undefined; + /** + * - The max incoming data, per average interval to allow. + */ + maxReceivedData?: number | undefined; + /** + * - The upper limit the event loop can take to run. + */ + maxEventLoopDelay?: number | undefined; + /** + * - How often, in milliseconds, metrics and latency should be checked. + */ + pollInterval?: number | undefined; + /** + * - How often, in milliseconds, to compute averages. + */ + movingAverageInterval?: number | undefined; + /** + * - The value of the peer. + */ + defaultPeerValue?: number | undefined; + /** + * - Should preemptively guarantee connections are above the low watermark. + */ + autoDial?: boolean | undefined; + /** + * - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark. + */ + autoDialInterval?: number | undefined; +}; +type Events = import('../types').EventEmitterFactory; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/connection-manager/index.d.ts.map b/dist/src/connection-manager/index.d.ts.map new file mode 100644 index 00000000..2f21551d --- /dev/null +++ b/dist/src/connection-manager/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";;AAoCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,oBAHW,MAAM,YACN,wBAAwB,EAkClC;IA7BC,uBAAqB;IACrB,gBAA0C;IAE1C,cAAqF;IAOrF;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,MAAM,CAAC,CAED;IAE5B;;;;OAIG;IACH,aAFU,IAAI,MAAM,EAAE,UAAU,EAAE,CAAC,CAEP;IAE5B,kBAAqB;IACrB,YAAkB;IAClB,sBAA4B;IAoF9B;;;;;OAKG;IACH,sBAcC;IA8GD;;;;;;;OAOG;IACH,kBAqCC;IA9PD;;OAEG;IACH,mBAGC;IAED;;;OAGG;IACH,cAiBC;IAXC,4CAGE;IAkKJ;;;;;OAKG;IACH,0BAEC;IAhKD;;;;OAIG;IACH,sBAQC;IAED;;;;OAIG;IACH,wBAWC;IAED;;;;;;;OAOG;IACH,qBAJW,MAAM,SACN,MAAM,GACJ,IAAI,CAOhB;IAwBD;;;;;OAKG;IACH,sBAHW,UAAU,GACR,IAAI,CAqBhB;IAED;;;;;OAKG;IACH,yBAHW,UAAU,GACR,IAAI,CAchB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,UAAU,GAAC,IAAI,CAQ3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,UAAU,EAAE,CAexB;IAYD;;;;;;OAMG;IACH,uBAOC;IAiDD;;;;;OAKG;IACH,4BAiBC;CACF;;;;;;;cA1VY,OAAO,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAxBZ,OAAO,UAAU,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/connection-manager/latency-monitor.d.ts b/dist/src/connection-manager/latency-monitor.d.ts new file mode 100644 index 00000000..0cd6d29e --- /dev/null +++ b/dist/src/connection-manager/latency-monitor.d.ts @@ -0,0 +1,140 @@ +export = LatencyMonitor; +declare const LatencyMonitor_base: import("../types").EventEmitterFactory; +/** + * @typedef {Object} SummaryObject + * @property {number} events How many events were called + * @property {number} minMS What was the min time for a cb to be called + * @property {number} maxMS What was the max time for a cb to be called + * @property {number} avgMs What was the average time for a cb to be called + * @property {number} lengthMs How long this interval was in ms + * + * @typedef {Object} LatencyMonitorOptions + * @property {number} [latencyCheckIntervalMs=500] - How often to add a latency check event (ms) + * @property {number} [dataEmitIntervalMs=5000] - How often to summarize latency check events. null or 0 disables event firing + * @property {Function} [asyncTestFn] - What cb-style async function to use + * @property {number} [latencyRandomPercentage=5] - What percent (+/-) of latencyCheckIntervalMs should we randomly use? This helps avoid alignment to other events. + */ +/** + * A class to monitor latency of any async function which works in a browser or node. This works by periodically calling + * the asyncTestFn and timing how long it takes the callback to be called. It can also periodically emit stats about this. + * This can be disabled and stats can be pulled via setting dataEmitIntervalMs = 0. + * + * @extends {EventEmitter} + * + * The default implementation is an event loop latency monitor. This works by firing periodic events into the event loop + * and timing how long it takes to get back. + * + * @example + * const monitor = new LatencyMonitor(); + * monitor.on('data', (summary) => console.log('Event Loop Latency: %O', summary)); + * + * @example + * const monitor = new LatencyMonitor({latencyCheckIntervalMs: 1000, dataEmitIntervalMs: 60000, asyncTestFn:ping}); + * monitor.on('data', (summary) => console.log('Ping Pong Latency: %O', summary)); + */ +declare class LatencyMonitor extends LatencyMonitor_base { + /** + * @class + * @param {LatencyMonitorOptions} [options] + */ + constructor({ latencyCheckIntervalMs, dataEmitIntervalMs, asyncTestFn, latencyRandomPercentage }?: LatencyMonitorOptions | undefined); + latencyCheckIntervalMs: number; + latencyRandomPercentage: number; + _latecyCheckMultiply: number; + _latecyCheckSubtract: number; + dataEmitIntervalMs: number | undefined; + asyncTestFn: Function | undefined; + _latencyData: { + startTime: any; + minMs: number; + maxMs: number; + events: number; + totalMs: number; + }; + /** + * Start internal timers + * + * @private + */ + private _startTimers; + _emitIntervalID: NodeJS.Timeout | undefined; + /** + * Stop internal timers + * + * @private + */ + private _stopTimers; + _checkLatencyID: NodeJS.Timeout | undefined; + /** + * Emit summary only if there were events. It might not have any events if it was forced via a page hidden/show + * + * @private + */ + private _emitSummary; + /** + * Calling this function will end the collection period. If a timing event was already fired and somewhere in the queue, + * it will not count for this time period + * + * @returns {SummaryObject} + */ + getSummary(): SummaryObject; + /** + * Randomly calls an async fn every roughly latencyCheckIntervalMs (plus some randomness). If no async fn is found, + * it will simply report on event loop latency. + * + * @private + */ + private _checkLatency; + _initLatencyData(): { + startTime: any; + minMs: number; + maxMs: number; + events: number; + totalMs: number; + }; +} +declare namespace LatencyMonitor { + export { Events, SummaryObject, LatencyMonitorOptions }; +} +type SummaryObject = { + /** + * How many events were called + */ + events: number; + /** + * What was the min time for a cb to be called + */ + minMS: number; + /** + * What was the max time for a cb to be called + */ + maxMS: number; + /** + * What was the average time for a cb to be called + */ + avgMs: number; + /** + * How long this interval was in ms + */ + lengthMs: number; +}; +type LatencyMonitorOptions = { + /** + * - How often to add a latency check event (ms) + */ + latencyCheckIntervalMs?: number | undefined; + /** + * - How often to summarize latency check events. null or 0 disables event firing + */ + dataEmitIntervalMs?: number | undefined; + /** + * - What cb-style async function to use + */ + asyncTestFn?: Function | undefined; + /** + * - What percent (+/-) of latencyCheckIntervalMs should we randomly use? This helps avoid alignment to other events. + */ + latencyRandomPercentage?: number | undefined; +}; +type Events = import('../types').EventEmitterFactory; +//# sourceMappingURL=latency-monitor.d.ts.map \ No newline at end of file diff --git a/dist/src/connection-manager/latency-monitor.d.ts.map b/dist/src/connection-manager/latency-monitor.d.ts.map new file mode 100644 index 00000000..d14e80a9 --- /dev/null +++ b/dist/src/connection-manager/latency-monitor.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"latency-monitor.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/latency-monitor.js"],"names":[],"mappings":";;AAaA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;OAGG;IACH,sIA+DC;IA1DC,+BAA2D;IAC3D,gCAA4D;IAC5D,6BAAoG;IACpG,6BAAyD;IAEzD,uCAEkC;IASlC,kCAA8B;IAqB9B;;;;;;MAA2C;IAuB7C;;;;OAIG;IACH,qBAYC;IALG,4CAAsF;IAO1F;;;;OAIG;IACH,oBASC;IANG,4CAAgC;IAQpC;;;;OAIG;IACH,qBAKC;IAED;;;;;OAKG;IACH,cAFa,aAAa,CAmBzB;IAED;;;;;OAKG;IACH,sBAgDC;IAED;;;;;;MAQC;CACF;;;;;;;;YA9Oa,MAAM;;;;WACN,MAAM;;;;WACN,MAAM;;;;WACN,MAAM;;;;cACN,MAAM;;;;;;;;;;;;;;;;;;;;cAZN,OAAO,UAAU,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/connection-manager/visibility-change-emitter.d.ts b/dist/src/connection-manager/visibility-change-emitter.d.ts new file mode 100644 index 00000000..cd62b584 --- /dev/null +++ b/dist/src/connection-manager/visibility-change-emitter.d.ts @@ -0,0 +1,65 @@ +export = VisibilityChangeEmitter; +declare const VisibilityChangeEmitter_base: import("../types").EventEmitterFactory; +/** + * Listen to page visibility change events (i.e. when the page is focused / blurred) by an event emitter. + * + * Warning: This does not work on all browsers, but should work on all modern browsers + * + * @example + * + * const myVisibilityEmitter = new VisibilityChangeEmitter(); + * + * myVisibilityEmitter.on('visibilityChange', (pageInFocus) => { + * if ( pageInFocus ){ + * // Page is in focus + * console.log('In focus'); + * } + * else { + * // Page is blurred + * console.log('Out of focus'); + * } + * }); + * // To access the visibility state directly, call: + * console.log('Am I focused now? ' + myVisibilityEmitter.isVisible()); + */ +declare class VisibilityChangeEmitter extends VisibilityChangeEmitter_base { + /** + * document.hidden and document.visibilityChange are the two variables we need to check for; + * Since these variables are named differently in different browsers, this function sets + * the appropriate name based on the browser being used. Once executed, tha actual names of + * document.hidden and document.visibilityChange are found in this._hidden and this._visibilityChange + * respectively + * + * @private + */ + private _initializeVisibilityVarNames; + _hidden: string | undefined; + _visibilityChange: string | undefined; + /** + * Adds an event listener on the document that listens to changes in document.visibilityChange + * (or whatever name by which the visibilityChange variable is known in the browser) + * + * @private + */ + private _addVisibilityChangeListener; + /** + * The function returns ```true``` if the page is visible or ```false``` if the page is not visible and + * ```undefined``` if the page visibility API is not supported by the browser. + * + * @returns {boolean | void} whether the page is now visible or not (undefined is unknown) + */ + isVisible(): boolean | void; + /** + * The function that is called when document.visibilityChange has changed + * It emits an event called visibilityChange and sends the value of document.hidden as a + * parameter + * + * @private + */ + private _handleVisibilityChange; +} +declare namespace VisibilityChangeEmitter { + export { Events }; +} +type Events = import('../types').EventEmitterFactory; +//# sourceMappingURL=visibility-change-emitter.d.ts.map \ No newline at end of file diff --git a/dist/src/connection-manager/visibility-change-emitter.d.ts.map b/dist/src/connection-manager/visibility-change-emitter.d.ts.map new file mode 100644 index 00000000..146dffed --- /dev/null +++ b/dist/src/connection-manager/visibility-change-emitter.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"visibility-change-emitter.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/visibility-change-emitter.js"],"names":[],"mappings":";;AAcA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;IAgBE;;;;;;;;OAQG;IACH,sCAkBC;IAFC,4BAAqB;IACrB,sCAAyC;IAG3C;;;;;OAKG;IACH,qCAQC;IAED;;;;;OAKG;IACH,aAFa,OAAO,GAAG,IAAI,CAQ1B;IAED;;;;;;OAMG;IACH,gCAKC;CACF;;;;cApHa,OAAO,UAAU,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/constants.d.ts b/dist/src/constants.d.ts new file mode 100644 index 00000000..4ba1f890 --- /dev/null +++ b/dist/src/constants.d.ts @@ -0,0 +1,10 @@ +export const DIAL_TIMEOUT: number; +export const MAX_PARALLEL_DIALS: number; +export const MAX_PER_PEER_DIALS: number; +export namespace METRICS { + const computeThrottleMaxQueueSize: number; + const computeThrottleTimeout: number; + const movingAverageIntervals: number[]; + const maxOldPeersRetention: number; +} +//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/dist/src/constants.d.ts.map b/dist/src/constants.d.ts.map new file mode 100644 index 00000000..485d4f8e --- /dev/null +++ b/dist/src/constants.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/content-routing/index.d.ts b/dist/src/content-routing/index.d.ts new file mode 100644 index 00000000..c48f81b1 --- /dev/null +++ b/dist/src/content-routing/index.d.ts @@ -0,0 +1,95 @@ +export = ContentRouting; +/** + * @typedef {import('peer-id')} PeerId + * @typedef {import('multiaddr').Multiaddr} Multiaddr + * @typedef {import('cids')} CID + * @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule + */ +/** + * @typedef {Object} GetData + * @property {PeerId} from + * @property {Uint8Array} val + */ +declare class ContentRouting { + /** + * @class + * @param {import('..')} libp2p + */ + constructor(libp2p: import('..')); + libp2p: import(".."); + /** @type {ContentRoutingModule[]} */ + routers: ContentRoutingModule[]; + dht: any; + /** + * Iterates over all content routers in parallel to find providers of the given key. + * + * @param {CID} key - The CID key of the content to find + * @param {object} [options] + * @param {number} [options.timeout] - How long the query should run + * @param {number} [options.maxNumProviders] - maximum number of providers to find + * @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} + */ + findProviders(key: CID, options?: { + timeout?: number | undefined; + maxNumProviders?: number | undefined; + } | undefined): AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; + }>; + /** + * Iterates over all content routers in parallel to notify it is + * a provider of the given key. + * + * @param {CID} key - The CID key of the content to find + * @returns {Promise} + */ + provide(key: CID): Promise; + /** + * Store the given key/value pair in the DHT. + * + * @param {Uint8Array} key + * @param {Uint8Array} value + * @param {Object} [options] - put options + * @param {number} [options.minPeers] - minimum number of peers required to successfully put + * @returns {Promise} + */ + put(key: Uint8Array, value: Uint8Array, options?: { + minPeers?: number | undefined; + } | undefined): Promise; + /** + * Get the value to the given key. + * Times out after 1 minute by default. + * + * @param {Uint8Array} key + * @param {Object} [options] - get options + * @param {number} [options.timeout] - optional timeout (default: 60000) + * @returns {Promise} + */ + get(key: Uint8Array, options?: { + timeout?: number | undefined; + } | undefined): Promise; + /** + * Get the `n` values to the given key without sorting. + * + * @param {Uint8Array} key + * @param {number} nVals + * @param {Object} [options] - get options + * @param {number} [options.timeout] - optional timeout (default: 60000) + * @returns {Promise} + */ + getMany(key: Uint8Array, nVals: number, options?: { + timeout?: number | undefined; + } | undefined): Promise; +} +declare namespace ContentRouting { + export { PeerId, Multiaddr, CID, ContentRoutingModule, GetData }; +} +type ContentRoutingModule = import('libp2p-interfaces/src/content-routing/types').ContentRouting; +type CID = import('cids'); +type PeerId = import('peer-id'); +type Multiaddr = import('multiaddr').Multiaddr; +type GetData = { + from: PeerId; + val: Uint8Array; +}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/content-routing/index.d.ts.map b/dist/src/content-routing/index.d.ts.map new file mode 100644 index 00000000..8bd1afdd --- /dev/null +++ b/dist/src/content-routing/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-routing/index.js"],"names":[],"mappings":";AAcA;;;;;GAKG;AAEH;;;;GAIG;AAEH;IACE;;;OAGG;IACH,oBAFW,OAAO,IAAI,CAAC,EAYtB;IATC,qBAAoB;IACpB,qCAAqC;IACrC,SADW,oBAAoB,EAAE,CACkB;IACnD,SAAsB;IAQxB;;;;;;;;OAQG;IACH,mBANW,GAAG;;;oBAID,cAAc;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CAgBlE;IAED;;;;;;OAMG;IACH,aAHW,GAAG,GACD,QAAQ,IAAI,CAAC,CAQzB;IAED;;;;;;;;OAQG;IACH,SANW,UAAU,SACV,UAAU;;oBAGR,QAAQ,IAAI,CAAC,CAQzB;IAED;;;;;;;;OAQG;IACH,SALW,UAAU;;oBAGR,QAAQ,OAAO,CAAC,CAQ5B;IAED;;;;;;;;OAQG;IACH,aANW,UAAU,SACV,MAAM;;oBAGJ,QAAQ,OAAO,EAAE,CAAC,CAQ9B;CACF;;;;4BApHY,OAAO,6CAA6C,EAAE,cAAc;WADpE,OAAO,MAAM,CAAC;cAFd,OAAO,SAAS,CAAC;iBACjB,OAAO,WAAW,EAAE,SAAS;;UAO5B,MAAM;SACN,UAAU"} \ No newline at end of file diff --git a/dist/src/content-routing/utils.d.ts b/dist/src/content-routing/utils.d.ts new file mode 100644 index 00000000..851e5245 --- /dev/null +++ b/dist/src/content-routing/utils.d.ts @@ -0,0 +1,59 @@ +export type PeerId = import('peer-id'); +export type Multiaddr = import('multiaddr').Multiaddr; +/** + * @typedef {import('peer-id')} PeerId + * @typedef {import('multiaddr').Multiaddr} Multiaddr + */ +/** + * Store the multiaddrs from every peer in the passed peer store + * + * @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source + * @param {import('../peer-store')} peerStore + */ +export function storeAddresses(source: AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>, peerStore: import('../peer-store')): AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>; +/** + * Filter peers by unique peer id + * + * @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source + */ +export function uniquePeers(source: AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>): AsyncGenerator<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}, void, unknown>; +/** + * Require at least `min` peers to be yielded from `source` + * + * @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source + * @param {number} min + */ +export function requirePeers(source: AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>, min?: number): AsyncGenerator<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}, void, unknown>; +/** + * If `max` is passed, only take that number of peers from the source + * otherwise take all the peers + * + * @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source + * @param {number} [max] + */ +export function maybeLimitSource(source: AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>, max?: number | undefined): AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; +}>; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/content-routing/utils.d.ts.map b/dist/src/content-routing/utils.d.ts.map new file mode 100644 index 00000000..0818c689 --- /dev/null +++ b/dist/src/content-routing/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/content-routing/utils.js"],"names":[],"mappings":"qBAQa,OAAO,SAAS,CAAC;wBACjB,OAAO,WAAW,EAAE,SAAS;AAF1C;;;GAGG;AAEH;;;;;GAKG;AACH,uCAHW,cAAc;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC,aACtD,OAAO,eAAe,CAAC;QADH,MAAM;gBAAc,SAAS,EAAE;GAU7D;AAED;;;;GAIG;AACH,oCAFW,cAAc;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;QAAlC,MAAM;gBAAc,SAAS,EAAE;kBAgB7D;AAED;;;;;GAKG;AACH,qCAHW,cAAc;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC,QACtD,MAAM;QADc,MAAM;gBAAc,SAAS,EAAE;kBAe7D;AAED;;;;;;GAMG;AACH,yCAHW,cAAc;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;QAAlC,MAAM;gBAAc,SAAS,EAAE;GAS7D"} \ No newline at end of file diff --git a/dist/src/dialer/dial-request.d.ts b/dist/src/dialer/dial-request.d.ts new file mode 100644 index 00000000..d983c968 --- /dev/null +++ b/dist/src/dialer/dial-request.d.ts @@ -0,0 +1,55 @@ +export = DialRequest; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('./')} Dialer + * @typedef {import('multiaddr').Multiaddr} Multiaddr + */ +/** + * @typedef {Object} DialOptions + * @property {AbortSignal} signal + * + * @typedef {Object} DialRequestOptions + * @property {Multiaddr[]} addrs + * @property {(m: Multiaddr, options: DialOptions) => Promise} dialAction + * @property {Dialer} dialer + */ +declare class DialRequest { + /** + * Manages running the `dialAction` on multiple provided `addrs` in parallel + * up to a maximum determined by the number of tokens returned + * from `dialer.getTokens`. Once a DialRequest is created, it can be + * started using `DialRequest.run(options)`. Once a single dial has succeeded, + * all other dials in the request will be cancelled. + * + * @class + * @param {DialRequestOptions} options + */ + constructor({ addrs, dialAction, dialer }: DialRequestOptions); + addrs: import("multiaddr").Multiaddr[]; + dialer: import("./"); + dialAction: (m: Multiaddr, options: DialOptions) => Promise; + /** + * @async + * @param {object} [options] + * @param {AbortSignal} [options.signal] - An AbortController signal + * @returns {Promise} + */ + run(options?: { + signal?: AbortSignal | undefined; + } | undefined): Promise; +} +declare namespace DialRequest { + export { Connection, Dialer, Multiaddr, DialOptions, DialRequestOptions }; +} +type Multiaddr = import('multiaddr').Multiaddr; +type DialOptions = { + signal: AbortSignal; +}; +type Connection = import("libp2p-interfaces/src/connection/connection"); +type DialRequestOptions = { + addrs: Multiaddr[]; + dialAction: (m: Multiaddr, options: DialOptions) => Promise; + dialer: Dialer; +}; +type Dialer = import('./'); +//# sourceMappingURL=dial-request.d.ts.map \ No newline at end of file diff --git a/dist/src/dialer/dial-request.d.ts.map b/dist/src/dialer/dial-request.d.ts.map new file mode 100644 index 00000000..45f15ce8 --- /dev/null +++ b/dist/src/dialer/dial-request.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"dial-request.d.ts","sourceRoot":"","sources":["../../../src/dialer/dial-request.js"],"names":[],"mappings":";AASA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;IACE;;;;;;;;;OASG;IACH,2CAFW,kBAAkB,EAU5B;IAHC,uCAAkB;IAClB,qBAAoB;IACpB,gBAtBc,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC,CAsBzC;IAG9B;;;;;OAKG;IACH;;oBAFa,QAAQ,UAAU,CAAC,CAuC/B;CACF;;;;iBA9EY,OAAO,WAAW,EAAE,SAAS;;YAK5B,WAAW;;;;WAGX,SAAS,EAAE;oBACP,SAAS,WAAW,WAAW,KAAK,QAAQ,UAAU,CAAC;YAC3D,MAAM;;cAXP,OAAO,IAAI,CAAC"} \ No newline at end of file diff --git a/dist/src/dialer/index.d.ts b/dist/src/dialer/index.d.ts new file mode 100644 index 00000000..ba5da41b --- /dev/null +++ b/dist/src/dialer/index.d.ts @@ -0,0 +1,155 @@ +export = Dialer; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('peer-id')} PeerId + * @typedef {import('../peer-store')} PeerStore + * @typedef {import('../peer-store/address-book').Address} Address + * @typedef {import('../transport-manager')} TransportManager + */ +/** + * @typedef {Object} DialerProperties + * @property {PeerStore} peerStore + * @property {TransportManager} transportManager + * + * @typedef {(addr:Multiaddr) => Promise} Resolver + * + * @typedef {Object} DialerOptions + * @property {(addresses: Address[]) => Address[]} [options.addressSorter = publicAddressesFirst] - Sort the known addresses of a peer before trying to dial. + * @property {number} [maxParallelDials = MAX_PARALLEL_DIALS] - Number of max concurrent dials. + * @property {number} [maxDialsPerPeer = MAX_PER_PEER_DIALS] - Number of max concurrent dials per peer. + * @property {number} [dialTimeout = DIAL_TIMEOUT] - How long a dial attempt is allowed to take. + * @property {Record} [resolvers = {}] - multiaddr resolvers to use when dialing + * + * @typedef DialTarget + * @property {string} id + * @property {Multiaddr[]} addrs + * + * @typedef PendingDial + * @property {DialRequest} dialRequest + * @property {TimeoutController} controller + * @property {Promise} promise + * @property {function():void} destroy + */ +declare class Dialer { + /** + * @class + * @param {DialerProperties & DialerOptions} options + */ + constructor({ transportManager, peerStore, addressSorter, maxParallelDials, dialTimeout, maxDialsPerPeer, resolvers }: DialerProperties & DialerOptions); + transportManager: import("../transport-manager"); + peerStore: import("../peer-store"); + addressSorter: (addresses: Address[]) => Address[]; + maxParallelDials: number; + timeout: number; + maxDialsPerPeer: number; + tokens: number[]; + _pendingDials: Map; + /** + * Clears any pending dials + */ + destroy(): void; + /** + * Connects to a given `peer` by dialing all of its known addresses. + * The dial to the first address that is successfully able to upgrade a connection + * will be used. + * + * @param {PeerId|Multiaddr|string} peer - The peer to dial + * @param {object} [options] + * @param {AbortSignal} [options.signal] - An AbortController signal + * @returns {Promise} + */ + connectToPeer(peer: PeerId | Multiaddr | string, options?: { + signal?: AbortSignal | undefined; + } | undefined): Promise; + /** + * Creates a DialTarget. The DialTarget is used to create and track + * the DialRequest to a given peer. + * If a multiaddr is received it should be the first address attempted. + * Multiaddrs not supported by the available transports will be filtered out. + * + * @private + * @param {PeerId|Multiaddr|string} peer - A PeerId or Multiaddr + * @returns {Promise} + */ + private _createDialTarget; + /** + * Creates a PendingDial that wraps the underlying DialRequest + * + * @private + * @param {DialTarget} dialTarget + * @param {object} [options] + * @param {AbortSignal} [options.signal] - An AbortController signal + * @returns {PendingDial} + */ + private _createPendingDial; + /** + * @param {number} num + */ + getTokens(num: number): number[]; + /** + * @param {number} token + */ + releaseToken(token: number): void; + /** + * Resolve multiaddr recursively. + * + * @param {Multiaddr} ma + * @returns {Promise} + */ + _resolve(ma: Multiaddr): Promise; + /** + * Resolve a given multiaddr. If this fails, an empty array will be returned + * + * @param {Multiaddr} ma + * @returns {Promise} + */ + _resolveRecord(ma: Multiaddr): Promise; +} +declare namespace Dialer { + export { Connection, PeerId, PeerStore, Address, TransportManager, DialerProperties, Resolver, DialerOptions, DialTarget, PendingDial }; +} +type Address = import('../peer-store/address-book').Address; +type PeerId = import('peer-id'); +import { Multiaddr } from "multiaddr"; +type Connection = import("libp2p-interfaces/src/connection/connection"); +type DialerProperties = { + peerStore: PeerStore; + transportManager: TransportManager; +}; +type DialerOptions = { + /** + * - Sort the known addresses of a peer before trying to dial. + */ + addressSorter?: ((addresses: Address[]) => Address[]) | undefined; + /** + * - Number of max concurrent dials. + */ + maxParallelDials?: number | undefined; + /** + * - Number of max concurrent dials per peer. + */ + maxDialsPerPeer?: number | undefined; + /** + * - How long a dial attempt is allowed to take. + */ + dialTimeout?: number | undefined; + /** + * - multiaddr resolvers to use when dialing + */ + resolvers?: Record | undefined; +}; +type PeerStore = import('../peer-store'); +type TransportManager = import('../transport-manager'); +type Resolver = (addr: Multiaddr) => Promise; +type DialTarget = { + id: string; + addrs: Multiaddr[]; +}; +type PendingDial = { + dialRequest: DialRequest; + controller: any; + promise: Promise; + destroy: () => void; +}; +import DialRequest = require("./dial-request"); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/dialer/index.d.ts.map b/dist/src/dialer/index.d.ts.map new file mode 100644 index 00000000..a7359b7b --- /dev/null +++ b/dist/src/dialer/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dialer/index.js"],"names":[],"mappings":";AAuBA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;IACE;;;OAGG;IACH,uHAFW,gBAAgB,GAAG,aAAa,EAuB1C;IAZC,iDAAwC;IACxC,mCAA0B;IAC1B,2BAjCsB,OAAO,EAAE,KAAK,OAAO,EAAE,CAiCX;IAClC,yBAAwC;IACxC,gBAA0B;IAC1B,wBAAsC;IACtC,iBAAuE;IACvE,6BAA8B;IAOhC;;OAEG;IACH,gBASC;IAED;;;;;;;;;OASG;IACH,oBALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAwB/B;IAED;;;;;;;;;OASG;IACH,0BA8BC;IAED;;;;;;;;OAQG;IACH,2BAiCC;IAED;;OAEG;IACH,eAFW,MAAM,YAOhB;IAED;;OAEG;IACH,oBAFW,MAAM,QAOhB;IAED;;;;;OAKG;IACH,aAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAwBhC;IAED;;;;;OAKG;IACH,mBAHW,SAAS,GACP,QAAQ,SAAS,EAAE,CAAC,CAWhC;CACF;;;;eAjQY,OAAO,4BAA4B,EAAE,OAAO;cAF5C,OAAO,SAAS,CAAC;;;;eAQhB,SAAS;sBACT,gBAAgB;;;;;;iCAKJ,OAAO,EAAE,KAAK,OAAO,EAAE;;;;;;;;;;;;;;;;;;iBAbpC,OAAO,eAAe,CAAC;wBAEvB,OAAO,sBAAsB,CAAC;uBAQxB,SAAS,KAAK,QAAQ,MAAM,EAAE,CAAC;;QAUpC,MAAM;WACN,SAAS,EAAE;;;iBAGX,WAAW;;aAEX,QAAQ,UAAU,CAAC;mBACR,IAAI"} \ No newline at end of file diff --git a/dist/src/errors.d.ts b/dist/src/errors.d.ts new file mode 100644 index 00000000..3c1fd09a --- /dev/null +++ b/dist/src/errors.d.ts @@ -0,0 +1,37 @@ +export namespace messages { + const NOT_STARTED_YET: string; + const DHT_DISABLED: string; + const CONN_ENCRYPTION_REQUIRED: string; +} +export namespace codes { + const DHT_DISABLED_1: string; + export { DHT_DISABLED_1 as DHT_DISABLED }; + export const PUBSUB_NOT_STARTED: string; + export const DHT_NOT_STARTED: string; + const CONN_ENCRYPTION_REQUIRED_1: string; + export { CONN_ENCRYPTION_REQUIRED_1 as CONN_ENCRYPTION_REQUIRED }; + export const ERR_INVALID_PROTOCOLS_FOR_STREAM: string; + export const ERR_CONNECTION_ENDED: string; + export const ERR_CONNECTION_FAILED: string; + export const ERR_NODE_NOT_STARTED: string; + export const ERR_ALREADY_ABORTED: string; + export const ERR_NO_VALID_ADDRESSES: string; + export const ERR_RELAYED_DIAL: string; + export const ERR_DIALED_SELF: string; + export const ERR_DISCOVERED_SELF: string; + export const ERR_DUPLICATE_TRANSPORT: string; + export const ERR_ENCRYPTION_FAILED: string; + export const ERR_HOP_REQUEST_FAILED: string; + export const ERR_INVALID_KEY: string; + export const ERR_INVALID_MESSAGE: string; + export const ERR_INVALID_PARAMETERS: string; + export const ERR_INVALID_PEER: string; + export const ERR_MUXER_UNAVAILABLE: string; + export const ERR_TIMEOUT: string; + export const ERR_TRANSPORT_UNAVAILABLE: string; + export const ERR_TRANSPORT_DIAL_FAILED: string; + export const ERR_UNSUPPORTED_PROTOCOL: string; + export const ERR_INVALID_MULTIADDR: string; + export const ERR_SIGNATURE_NOT_VALID: string; +} +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/src/errors.d.ts.map b/dist/src/errors.d.ts.map new file mode 100644 index 00000000..80c209d6 --- /dev/null +++ b/dist/src/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/get-peer.d.ts b/dist/src/get-peer.d.ts new file mode 100644 index 00000000..c9643ac5 --- /dev/null +++ b/dist/src/get-peer.d.ts @@ -0,0 +1,15 @@ +export = getPeer; +/** + * Converts the given `peer` to a `Peer` object. + * If a multiaddr is received, the addressBook is updated. + * + * @param {PeerId|Multiaddr|string} peer + * @returns {{ id: PeerId, multiaddrs: Multiaddr[]|undefined }} + */ +declare function getPeer(peer: PeerId | Multiaddr | string): { + id: PeerId; + multiaddrs: Multiaddr[] | undefined; +}; +import PeerId = require("peer-id"); +import { Multiaddr } from "multiaddr"; +//# sourceMappingURL=get-peer.d.ts.map \ No newline at end of file diff --git a/dist/src/get-peer.d.ts.map b/dist/src/get-peer.d.ts.map new file mode 100644 index 00000000..6efefc51 --- /dev/null +++ b/dist/src/get-peer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"get-peer.d.ts","sourceRoot":"","sources":["../../src/get-peer.js"],"names":[],"mappings":";AAQA;;;;;;GAMG;AACH,+BAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,SAAS,EAAE,GAAC,SAAS,CAAA;CAAE,CAiC7D"} \ No newline at end of file diff --git a/dist/src/identify/consts.d.ts b/dist/src/identify/consts.d.ts new file mode 100644 index 00000000..fe198a2d --- /dev/null +++ b/dist/src/identify/consts.d.ts @@ -0,0 +1,5 @@ +export var PROTOCOL_VERSION: string; +export var AGENT_VERSION: string; +export var MULTICODEC_IDENTIFY: string; +export var MULTICODEC_IDENTIFY_PUSH: string; +//# sourceMappingURL=consts.d.ts.map \ No newline at end of file diff --git a/dist/src/identify/consts.d.ts.map b/dist/src/identify/consts.d.ts.map new file mode 100644 index 00000000..ed5f1691 --- /dev/null +++ b/dist/src/identify/consts.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/identify/consts.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/identify/index.d.ts b/dist/src/identify/index.d.ts new file mode 100644 index 00000000..f06444e0 --- /dev/null +++ b/dist/src/identify/index.d.ts @@ -0,0 +1,111 @@ +export = IdentifyService; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + */ +/** + * @typedef {Object} HostProperties + * @property {string} agentVersion + */ +declare class IdentifyService { + /** + * Takes the `addr` and converts it to a Multiaddr if possible + * + * @param {Uint8Array | string} addr + * @returns {Multiaddr|null} + */ + static getCleanMultiaddr(addr: Uint8Array | string): Multiaddr | null; + /** + * @class + * @param {Object} options + * @param {import('../')} options.libp2p + */ + constructor({ libp2p }: { + libp2p: import('../'); + }); + _libp2p: import("../"); + peerStore: import("../peer-store"); + addressManager: import("../address-manager"); + connectionManager: import("../connection-manager"); + peerId: PeerId; + /** + * A handler to register with Libp2p to process identify messages. + * + * @param {Object} options + * @param {Connection} options.connection + * @param {MuxedStream} options.stream + * @param {string} options.protocol + * @returns {Promise|undefined} + */ + handleMessage({ connection, stream, protocol }: { + connection: Connection; + stream: MuxedStream; + protocol: string; + }): Promise | undefined; + _host: { + agentVersion: string; + protocolVersion: string; + }; + /** + * Send an Identify Push update to the list of connections + * + * @param {Connection[]} connections + * @returns {Promise} + */ + push(connections: Connection[]): Promise; + /** + * Calls `push` for all peers in the `peerStore` that are connected + * + * @returns {void} + */ + pushToPeerStore(): void; + /** + * Requests the `Identify` message from peer associated with the given `connection`. + * If the identified peer does not match the `PeerId` associated with the connection, + * an error will be thrown. + * + * @async + * @param {Connection} connection + * @returns {Promise} + */ + identify(connection: Connection): Promise; + /** + * Sends the `Identify` response with the Signed Peer Record + * to the requesting peer over the given `connection` + * + * @private + * @param {Object} options + * @param {MuxedStream} options.stream + * @param {Connection} options.connection + * @returns {Promise} + */ + private _handleIdentify; + /** + * Reads the Identify Push message from the given `connection` + * + * @private + * @param {object} options + * @param {MuxedStream} options.stream + * @param {Connection} options.connection + * @returns {Promise} + */ + private _handlePush; +} +declare namespace IdentifyService { + export { multicodecs, Message as Messsage, Connection, MuxedStream, HostProperties }; +} +import PeerId = require("peer-id"); +type Connection = import("libp2p-interfaces/src/connection/connection"); +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +import { Multiaddr } from "multiaddr"; +declare namespace multicodecs { + export { MULTICODEC_IDENTIFY as IDENTIFY }; + export { MULTICODEC_IDENTIFY_PUSH as IDENTIFY_PUSH }; +} +import Message = require("./message"); +type HostProperties = { + agentVersion: string; +}; +import { MULTICODEC_IDENTIFY } from "./consts"; +import { MULTICODEC_IDENTIFY_PUSH } from "./consts"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/identify/index.d.ts.map b/dist/src/identify/index.d.ts.map new file mode 100644 index 00000000..7f6d3fd6 --- /dev/null +++ b/dist/src/identify/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identify/index.js"],"names":[],"mappings":";AA8BA;;;GAGG;AAEH;;;GAGG;AAEH;IA0RE;;;;;OAKG;IACH,+BAHW,UAAU,GAAG,MAAM,GACjB,SAAS,GAAC,IAAI,CAW1B;IAxSD;;;;OAIG;IACH;QAFkC,MAAM,EAA7B,OAAO,KAAK,CAAC;OAqCvB;IAlCC,uBAAqB;IACrB,mCAAiC;IACjC,6CAA2C;IAC3C,mDAAiD;IACjD,eAA2B;IAiK7B;;;;;;;;OAQG;IACH;oBALW,UAAU;gBACV,WAAW;kBACX,MAAM;QACJ,QAAQ,IAAI,CAAC,GAAC,SAAS,CAWnC;IA9KC;sBAnBU,MAAM;;MAsBf;IAwBH;;;;;OAKG;IACH,kBAHW,UAAU,EAAE,GACV,QAAQ,IAAI,EAAE,CAAC,CA4B3B;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAiBhB;IAED;;;;;;;;OAQG;IACH,qBAHW,UAAU,GACR,QAAQ,IAAI,CAAC,CAgEzB;IAsBD;;;;;;;;;OASG;IACH,wBA6BC;IAED;;;;;;;;OAQG;IACH,oBAsCC;CAkBF;;;;;;mBAlTY,OAAO,0CAA0C,EAAE,WAAW;;;;;;;;kBAK7D,MAAM"} \ No newline at end of file diff --git a/dist/src/identify/message.d.ts b/dist/src/identify/message.d.ts new file mode 100644 index 00000000..ba49c586 --- /dev/null +++ b/dist/src/identify/message.d.ts @@ -0,0 +1,95 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Identify. */ +export interface IIdentify { + + /** Identify protocolVersion */ + protocolVersion?: (string|null); + + /** Identify agentVersion */ + agentVersion?: (string|null); + + /** Identify publicKey */ + publicKey?: (Uint8Array|null); + + /** Identify listenAddrs */ + listenAddrs?: (Uint8Array[]|null); + + /** Identify observedAddr */ + observedAddr?: (Uint8Array|null); + + /** Identify protocols */ + protocols?: (string[]|null); + + /** Identify signedPeerRecord */ + signedPeerRecord?: (Uint8Array|null); +} + +/** Represents an Identify. */ +export class Identify implements IIdentify { + + /** + * Constructs a new Identify. + * @param [p] Properties to set + */ + constructor(p?: IIdentify); + + /** Identify protocolVersion. */ + public protocolVersion: string; + + /** Identify agentVersion. */ + public agentVersion: string; + + /** Identify publicKey. */ + public publicKey: Uint8Array; + + /** Identify listenAddrs. */ + public listenAddrs: Uint8Array[]; + + /** Identify observedAddr. */ + public observedAddr: Uint8Array; + + /** Identify protocols. */ + public protocols: string[]; + + /** Identify signedPeerRecord. */ + public signedPeerRecord: Uint8Array; + + /** + * Encodes the specified Identify message. Does not implicitly {@link Identify.verify|verify} messages. + * @param m Identify message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IIdentify, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Identify message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Identify + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Identify; + + /** + * Creates an Identify message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Identify + */ + public static fromObject(d: { [k: string]: any }): Identify; + + /** + * Creates a plain object from an Identify message. Also converts values to other types if specified. + * @param m Identify + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Identify, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Identify to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts new file mode 100644 index 00000000..169afab3 --- /dev/null +++ b/dist/src/index.d.ts @@ -0,0 +1,534 @@ +export = Libp2p; +declare const Libp2p_base: import("./types").EventEmitterFactory; +/** + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory + * @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule + * @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscoveryFactory} PeerDiscoveryFactory + * @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule + * @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto + * @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub + * @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions + * @typedef {import('interface-datastore').Datastore} Datastore + * @typedef {import('./pnet')} Protector + */ +/** + * @typedef {Object} HandlerProps + * @property {Connection} connection + * @property {MuxedStream} stream + * @property {string} protocol + * + * @typedef {Object} RandomWalkOptions + * @property {boolean} [enabled = false] + * @property {number} [queriesPerPeriod = 1] + * @property {number} [interval = 300e3] + * @property {number} [timeout = 10e3] + * + * @typedef {Object} DhtOptions + * @property {boolean} [enabled = false] + * @property {number} [kBucketSize = 20] + * @property {RandomWalkOptions} [randomWalk] + * @property {boolean} [clientMode] + * @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors] + * @property {import('libp2p-interfaces/src/types').DhtValidators} [validators] + * + * @typedef {Object} KeychainOptions + * @property {Datastore} [datastore] + * + * @typedef {Object} PeerStoreOptions + * @property {boolean} persistence + * + * @typedef {Object} PubsubLocalOptions + * @property {boolean} enabled + * + * @typedef {Object} MetricsOptions + * @property {boolean} enabled + * + * @typedef {Object} RelayOptions + * @property {boolean} [enabled = true] + * @property {import('./circuit').RelayAdvertiseOptions} [advertise] + * @property {import('./circuit').HopOptions} [hop] + * @property {import('./circuit').AutoRelayOptions} [autoRelay] + * + * @typedef {Object} Libp2pConfig + * @property {DhtOptions} [dht] dht module options + * @property {import('./nat-manager').NatManagerOptions} [nat] + * @property {Record} [peerDiscovery] + * @property {PubsubLocalOptions & PubsubOptions} [pubsub] pubsub module options + * @property {RelayOptions} [relay] + * @property {Record} [transport] transport options indexed by transport key + * + * @typedef {Object} Libp2pModules + * @property {TransportFactory[]} transport + * @property {MuxerFactory[]} streamMuxer + * @property {Crypto[]} connEncryption + * @property {PeerDiscoveryFactory[]} [peerDiscovery] + * @property {PeerRoutingModule[]} [peerRouting] + * @property {ContentRoutingModule[]} [contentRouting] + * @property {Object} [dht] + * @property {{new(...args: any[]): Pubsub}} [pubsub] + * @property {Protector} [connProtector] + * + * @typedef {Object} Libp2pOptions + * @property {Libp2pModules} modules libp2p modules to use + * @property {import('./address-manager').AddressManagerOptions} [addresses] + * @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager] + * @property {Datastore} [datastore] + * @property {import('./dialer').DialerOptions} [dialer] + * @property {import('./identify/index').HostProperties} [host] libp2p host + * @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain] + * @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics] + * @property {import('./peer-routing').PeerRoutingOptions} [peerRouting] + * @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore] + * @property {import('./transport-manager').TransportManagerOptions} [transportManager] + * @property {Libp2pConfig} [config] + * + * @typedef {Object} constructorOptions + * @property {PeerId} peerId + * + * @typedef {Object} CreateOptions + * @property {PeerId} [peerId] + * + * @extends {EventEmitter} + * @fires Libp2p#error Emitted when an error occurs + * @fires Libp2p#peer:discovery Emitted when a peer is discovered + */ +declare class Libp2p extends Libp2p_base { + /** + * Like `new Libp2p(options)` except it will create a `PeerId` + * instance if one is not provided in options. + * + * @param {Libp2pOptions & CreateOptions} options - Libp2p configuration options + * @returns {Promise} + */ + static create(options: Libp2pOptions & CreateOptions): Promise; + /** + * Libp2p node. + * + * @class + * @param {Libp2pOptions & constructorOptions} _options + */ + constructor(_options: Libp2pOptions & constructorOptions); + _options: { + addresses: { + listen: never[]; + announce: never[]; + noAnnounce: never[]; + announceFilter: (multiaddrs: Multiaddr[]) => Multiaddr[]; + }; + connectionManager: { + minConnections: number; + }; + transportManager: { + faultTolerance: number; + }; + dialer: { + maxParallelDials: number; + maxDialsPerPeer: number; + dialTimeout: number; + resolvers: { + dnsaddr: any; + }; + addressSorter: typeof import("libp2p-utils/src/address-sort").publicAddressesFirst; + }; + host: { + agentVersion: string; + }; + metrics: { + enabled: boolean; + }; + peerStore: { + persistence: boolean; + threshold: number; + }; + peerRouting: { + refreshManager: { + enabled: boolean; + interval: number; + bootDelay: number; + }; + }; + config: { + dht: { + enabled: boolean; + kBucketSize: number; + randomWalk: { + enabled: boolean; + queriesPerPeriod: number; + interval: number; + timeout: number; + }; + }; + nat: { + enabled: boolean; + ttl: number; + keepAlive: boolean; + gateway: null; + externalIp: null; + pmp: { + enabled: boolean; + }; + }; + peerDiscovery: { + autoDial: boolean; + }; + pubsub: { + enabled: boolean; + }; + relay: { + enabled: boolean; + advertise: { + bootDelay: number; + enabled: boolean; + ttl: number; + }; + hop: { + enabled: boolean; + active: boolean; + }; + autoRelay: { + enabled: boolean; + maxListeners: number; + }; + }; + transport: {}; + }; + } & Libp2pOptions & constructorOptions; + /** @type {PeerId} */ + peerId: PeerId; + datastore: import("interface-datastore/dist/src/types").Datastore | undefined; + peerStore: PeerStore; + addresses: { + listen: never[]; + announce: never[]; + noAnnounce: never[]; + announceFilter: (multiaddrs: Multiaddr[]) => Multiaddr[]; + } & AddressManager.AddressManagerOptions; + addressManager: AddressManager; + _modules: Libp2pModules; + _config: { + dht: { + enabled: boolean; + kBucketSize: number; + randomWalk: { + enabled: boolean; + queriesPerPeriod: number; + interval: number; + timeout: number; + }; + }; + nat: { + enabled: boolean; + ttl: number; + keepAlive: boolean; + gateway: null; + externalIp: null; + pmp: { + enabled: boolean; + }; + }; + peerDiscovery: { + autoDial: boolean; + }; + pubsub: { + enabled: boolean; + }; + relay: { + enabled: boolean; + advertise: { + bootDelay: number; + enabled: boolean; + ttl: number; + }; + hop: { + enabled: boolean; + active: boolean; + }; + autoRelay: { + enabled: boolean; + maxListeners: number; + }; + }; + transport: {}; + } & Libp2pConfig; + _transport: any[]; + _discovery: Map; + connectionManager: ConnectionManager; + metrics: Metrics | undefined; + keychain: Keychain | undefined; + upgrader: Upgrader; + transportManager: TransportManager; + natManager: NatManager; + registrar: Registrar; + /** + * Registers the `handler` for each protocol + * + * @param {string[]|string} protocols + * @param {(props: HandlerProps) => void} handler + */ + handle(protocols: string[] | string, handler: (props: HandlerProps) => void): void; + dialer: Dialer; + relay: Relay | undefined; + identifyService: IdentifyService | undefined; + _dht: any; + /** @type {Pubsub} */ + pubsub: import("libp2p-interfaces/src/pubsub"); + peerRouting: PeerRouting; + contentRouting: ContentRouting; + /** + * Called whenever peer discovery services emit `peer` events. + * Known peers may be emitted. + * + * @private + * @param {{ id: PeerId, multiaddrs: Multiaddr[], protocols: string[] }} peer + */ + private _onDiscoveryPeer; + /** + * Starts the libp2p node and all its subsystems + * + * @returns {Promise} + */ + start(): Promise; + /** + * Stop the libp2p node by closing its listeners and open connections + * + * @async + * @returns {Promise} + */ + stop(): Promise; + _isStarted: boolean | undefined; + /** + * Load keychain keys from the datastore. + * Imports the private key as 'self', if needed. + * + * @async + * @returns {Promise} + */ + loadKeychain(): Promise; + isStarted(): boolean | undefined; + /** + * Gets a Map of the current connections. The keys are the stringified + * `PeerId` of the peer. The value is an array of Connections to that peer. + * + * @returns {Map} + */ + get connections(): Map; + /** + * Dials to the provided peer. If successful, the known metadata of the + * peer will be added to the nodes `peerStore` + * + * @param {PeerId|Multiaddr|string} peer - The peer to dial + * @param {object} [options] + * @param {AbortSignal} [options.signal] + * @returns {Promise} + */ + dial(peer: PeerId | Multiaddr | string, options?: { + signal?: AbortSignal | undefined; + } | undefined): Promise; + /** + * Dials to the provided peer and tries to handshake with the given protocols in order. + * If successful, the known metadata of the peer will be added to the nodes `peerStore`, + * and the `MuxedStream` will be returned together with the successful negotiated protocol. + * + * @async + * @param {PeerId|Multiaddr|string} peer - The peer to dial + * @param {string[]|string} protocols + * @param {object} [options] + * @param {AbortSignal} [options.signal] + */ + dialProtocol(peer: PeerId | Multiaddr | string, protocols: string[] | string, options?: { + signal?: AbortSignal | undefined; + } | undefined): Promise<{ + stream: import("libp2p-interfaces/src/stream-muxer/types").MuxedStream; + protocol: string; + }>; + /** + * @async + * @param {PeerId|Multiaddr|string} peer - The peer to dial + * @param {object} [options] + * @returns {Promise} + */ + _dial(peer: PeerId | Multiaddr | string, options?: object | undefined): Promise; + /** + * Get a deduplicated list of peer advertising multiaddrs by concatenating + * the listen addresses used by transports with any configured + * announce addresses as well as observed addresses reported by peers. + * + * If Announce addrs are specified, configured listen addresses will be + * ignored though observed addresses will still be included. + * + * @returns {Multiaddr[]} + */ + get multiaddrs(): Multiaddr[]; + /** + * Disconnects all connections to the given `peer` + * + * @param {PeerId|Multiaddr|string} peer - the peer to close connections to + * @returns {Promise} + */ + hangUp(peer: PeerId | Multiaddr | string): Promise; + /** + * Pings the given peer in order to obtain the operation latency. + * + * @param {PeerId|Multiaddr|string} peer - The peer to ping + * @returns {Promise} + */ + ping(peer: PeerId | Multiaddr | string): Promise; + /** + * Removes the handler for each protocol. The protocol + * will no longer be supported on streams. + * + * @param {string[]|string} protocols + */ + unhandle(protocols: string[] | string): void; + _onStarting(): Promise; + /** + * Called when libp2p has started and before it returns + * + * @private + */ + private _onDidStart; + /** + * Will dial to the given `peerId` if the current number of + * connected peers is less than the configured `ConnectionManager` + * minConnections. + * + * @private + * @param {PeerId} peerId + */ + private _maybeConnect; + /** + * Initializes and starts peer discovery services + * + * @async + * @private + */ + private _setupPeerDiscovery; +} +declare namespace Libp2p { + export { Events, Connection, MuxedStream, TransportFactory, MuxerFactory, ContentRoutingModule, PeerDiscoveryFactory, PeerRoutingModule, Crypto, Pubsub, PubsubOptions, Datastore, Protector, HandlerProps, RandomWalkOptions, DhtOptions, KeychainOptions, PeerStoreOptions, PubsubLocalOptions, MetricsOptions, RelayOptions, Libp2pConfig, Libp2pModules, Libp2pOptions, constructorOptions, CreateOptions }; +} +import { Multiaddr } from "multiaddr"; +type Libp2pOptions = { + /** + * libp2p modules to use + */ + modules: Libp2pModules; + addresses?: AddressManager.AddressManagerOptions | undefined; + connectionManager?: ConnectionManager.ConnectionManagerOptions | undefined; + datastore?: import("interface-datastore/dist/src/types").Datastore | undefined; + dialer?: Dialer.DialerOptions | undefined; + /** + * libp2p host + */ + host?: IdentifyService.HostProperties | undefined; + keychain?: (KeychainOptions & Keychain.KeychainOptions) | undefined; + metrics?: (MetricsOptions & Metrics.MetricsOptions) | undefined; + peerRouting?: PeerRouting.PeerRoutingOptions | undefined; + peerStore?: (PeerStoreOptions & PersistentPeerStore.PersistentPeerStoreOptions) | undefined; + transportManager?: TransportManager.TransportManagerOptions | undefined; + config?: Libp2pConfig | undefined; +}; +type constructorOptions = { + peerId: PeerId; +}; +import PeerId = require("peer-id"); +import PeerStore = require("./peer-store"); +import AddressManager = require("./address-manager"); +type Libp2pModules = { + transport: import("libp2p-interfaces/src/transport/types").TransportFactory[]; + streamMuxer: MuxerFactory[]; + connEncryption: Crypto[]; + peerDiscovery?: import("libp2p-interfaces/src/peer-discovery/types").PeerDiscoveryFactory[] | undefined; + peerRouting?: import("libp2p-interfaces/src/peer-routing/types").PeerRouting[] | undefined; + contentRouting?: import("libp2p-interfaces/src/content-routing/types").ContentRouting[] | undefined; + dht?: Object | undefined; + pubsub?: (new (...args: any[]) => Pubsub) | undefined; + connProtector?: import("./pnet") | undefined; +}; +type Libp2pConfig = { + /** + * dht module options + */ + dht?: DhtOptions | undefined; + nat?: NatManager.NatManagerOptions | undefined; + peerDiscovery?: Record | undefined; + /** + * pubsub module options + */ + pubsub?: (PubsubLocalOptions & import("libp2p-interfaces/src/pubsub").PubsubOptions) | undefined; + relay?: RelayOptions | undefined; + /** + * transport options indexed by transport key + */ + transport?: Record | undefined; +}; +import ConnectionManager = require("./connection-manager"); +import Metrics = require("./metrics"); +import Keychain = require("./keychain"); +import Upgrader = require("./upgrader"); +import TransportManager = require("./transport-manager"); +import NatManager = require("./nat-manager"); +import Registrar = require("./registrar"); +type HandlerProps = { + connection: Connection; + stream: MuxedStream; + protocol: string; +}; +import Dialer = require("./dialer"); +import Relay = require("./circuit"); +import IdentifyService = require("./identify"); +import PeerRouting = require("./peer-routing"); +import ContentRouting = require("./content-routing"); +type Connection = import("libp2p-interfaces/src/connection/connection"); +type CreateOptions = { + peerId?: PeerId | undefined; +}; +type Events = import('./types').EventEmitterFactory; +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +type TransportFactory = import('libp2p-interfaces/src/transport/types').TransportFactory; +type MuxerFactory = import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory; +type ContentRoutingModule = import('libp2p-interfaces/src/content-routing/types').ContentRouting; +type PeerDiscoveryFactory = import('libp2p-interfaces/src/peer-discovery/types').PeerDiscoveryFactory; +type PeerRoutingModule = import('libp2p-interfaces/src/peer-routing/types').PeerRouting; +type Crypto = import('libp2p-interfaces/src/crypto/types').Crypto; +type Pubsub = import('libp2p-interfaces/src/pubsub'); +type PubsubOptions = import('libp2p-interfaces/src/pubsub').PubsubOptions; +type Datastore = import('interface-datastore').Datastore; +type Protector = import('./pnet'); +type RandomWalkOptions = { + enabled?: boolean | undefined; + queriesPerPeriod?: number | undefined; + interval?: number | undefined; + timeout?: number | undefined; +}; +type DhtOptions = { + enabled?: boolean | undefined; + kBucketSize?: number | undefined; + randomWalk?: RandomWalkOptions | undefined; + clientMode?: boolean | undefined; + selectors?: import("libp2p-interfaces/src/types").DhtSelectors | undefined; + validators?: import("libp2p-interfaces/src/types").DhtValidators | undefined; +}; +type KeychainOptions = { + datastore?: import("interface-datastore/dist/src/types").Datastore | undefined; +}; +type PeerStoreOptions = { + persistence: boolean; +}; +type PubsubLocalOptions = { + enabled: boolean; +}; +type MetricsOptions = { + enabled: boolean; +}; +type RelayOptions = { + enabled?: boolean | undefined; + advertise?: Relay.RelayAdvertiseOptions | undefined; + hop?: Relay.HopOptions | undefined; + autoRelay?: Relay.AutoRelayOptions | undefined; +}; +import PersistentPeerStore = require("./peer-store/persistent"); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/index.d.ts.map b/dist/src/index.d.ts.map new file mode 100644 index 00000000..d0ccdb0f --- /dev/null +++ b/dist/src/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":";;AAuCA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH;IACE;;;;;;OAMG;IACH,uBAHW,aAAa,GAAG,aAAa,GAC3B,QAAQ,MAAM,CAAC,CAa3B;IAED;;;;;OAKG;IACH,sBAFW,aAAa,GAAG,kBAAkB,EA+K5C;IAzKC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAAwC;IAExC,qBAAqB;IACrB,QADW,MAAM,CACiB;IAClC,8EAAwC;IAExC,qBAM0C;IAG1C;;;;;6CAAwC;IACxC,+BAA8E;IAS9E,wBAAqC;IACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAAmC;IACnC,kBAAoB;IACpB,0BAA2B;IAG3B,qCAGE;IAIA,6BAGE;IASF,+BAGE;IAMJ,mBAKE;IAGF,mCAIE;IAGF,uBAME;IAGF,qBAGE;IAwUJ;;;;;OAKG;IACH,kBAHW,MAAM,EAAE,GAAC,MAAM,mBACP,YAAY,KAAK,IAAI,QAUvC;IAxUC,eAIE;IAWA,yBAA4B;IAW5B,6CAA4D;IAe5D,UAQE;IAOF,qBAAqB;IACrB,+CAA8D;IAKhE,yBAAwC;IACxC,+BAA8C;IAqVhD;;;;;;OAMG;IACH,yBAQC;IAzUD;;;;OAIG;IACH,SAFa,QAAQ,IAAI,CAAC,CAezB;IAED;;;;;OAKG;IACH,QAFa,QAAQ,IAAI,CAAC,CAwCzB;IAlCG,gCAAuB;IAoC3B;;;;;;OAMG;IACH,gBAFa,QAAQ,IAAI,CAAC,CAYzB;IAED,iCAEC;IAED;;;;;OAKG;IACH,wFAEC;IAED;;;;;;;;OAQG;IACH,WALW,MAAM,GAAC,SAAS,GAAC,MAAM;;oBAGrB,QAAQ,UAAU,CAAC,CAI/B;IAED;;;;;;;;;;OAUG;IACH,mBALW,MAAM,GAAC,SAAS,GAAC,MAAM,aACvB,MAAM,EAAE,GAAC,MAAM;;;;;OAWzB;IAED;;;;;OAKG;IACH,YAJW,MAAM,GAAC,SAAS,GAAC,MAAM,iCAErB,QAAQ,UAAU,CAAC,CAkB/B;IAED;;;;;;;;;OASG;IACH,8BAiBC;IAED;;;;;OAKG;IACH,aAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,IAAI,CAAC,CAgBzB;IAED;;;;;OAKG;IACH,WAHW,MAAM,GAAC,SAAS,GAAC,MAAM,GACrB,QAAQ,MAAM,CAAC,CAW3B;IAkBD;;;;;OAKG;IACH,oBAFW,MAAM,EAAE,GAAC,MAAM,QAUzB;IAED,6BA0BC;IAED;;;;OAIG;IACH,oBAuBC;IAmBD;;;;;;;OAOG;IACH,sBAaC;IAED;;;;;OAKG;IACH,4BAkDC;CACF;;;;;;;;;aA/oBa,aAAa;;;;;;;;;;;;;;;;;YAcb,MAAM;;;;;;eAzBN,4EAAkB;iBAClB,YAAY,EAAE;oBACd,MAAM,EAAE;;;;;4BAKM,GAAG,EAAE,KAAG,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBApD5B,UAAU;YACV,WAAW;cACX,MAAM;;;;;;;;;;;cApDN,OAAO,SAAS,EAAE,mBAAmB;mBAmCtC,OAAO,0CAA0C,EAAE,WAAW;wBAC9D,OAAO,uCAAuC,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC;oBAC1E,OAAO,0CAA0C,EAAE,YAAY;4BAC/D,OAAO,6CAA6C,EAAE,cAAc;4BACpE,OAAO,4CAA4C,EAAE,oBAAoB;yBACzE,OAAO,0CAA0C,EAAE,WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;cACnD,OAAO,8BAA8B,CAAC;qBACtC,OAAO,8BAA8B,EAAE,aAAa;iBACpD,OAAO,qBAAqB,EAAE,SAAS;iBACvC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;iBA2Bf,OAAO;;;aAGP,OAAO;;;aAGP,OAAO"} \ No newline at end of file diff --git a/dist/src/insecure/plaintext.d.ts b/dist/src/insecure/plaintext.d.ts new file mode 100644 index 00000000..d1ac2833 --- /dev/null +++ b/dist/src/insecure/plaintext.d.ts @@ -0,0 +1,12 @@ +export type Connection = import("libp2p-interfaces/src/connection/connection"); +export const protocol: "/plaintext/2.0.0"; +import PeerId = require("peer-id"); +export declare function secureInbound(localId: PeerId, conn: import("libp2p-interfaces/src/connection/connection"), remoteId: PeerId | undefined): Promise<{ + conn: any; + remotePeer: PeerId; +}>; +export declare function secureOutbound(localId: PeerId, conn: import("libp2p-interfaces/src/connection/connection"), remoteId: PeerId | undefined): Promise<{ + conn: any; + remotePeer: PeerId; +}>; +//# sourceMappingURL=plaintext.d.ts.map \ No newline at end of file diff --git a/dist/src/insecure/plaintext.d.ts.map b/dist/src/insecure/plaintext.d.ts.map new file mode 100644 index 00000000..23280044 --- /dev/null +++ b/dist/src/insecure/plaintext.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"plaintext.d.ts","sourceRoot":"","sources":["../../../src/insecure/plaintext.js"],"names":[],"mappings":";AAaA,0CAAmC;;AAsEjB;;;GAEd;AAMe;;;GAEf"} \ No newline at end of file diff --git a/dist/src/insecure/proto.d.ts b/dist/src/insecure/proto.d.ts new file mode 100644 index 00000000..a4fbac06 --- /dev/null +++ b/dist/src/insecure/proto.d.ts @@ -0,0 +1,128 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Exchange. */ +export interface IExchange { + + /** Exchange id */ + id?: (Uint8Array|null); + + /** Exchange pubkey */ + pubkey?: (IPublicKey|null); +} + +/** Represents an Exchange. */ +export class Exchange implements IExchange { + + /** + * Constructs a new Exchange. + * @param [p] Properties to set + */ + constructor(p?: IExchange); + + /** Exchange id. */ + public id: Uint8Array; + + /** Exchange pubkey. */ + public pubkey?: (IPublicKey|null); + + /** + * Encodes the specified Exchange message. Does not implicitly {@link Exchange.verify|verify} messages. + * @param m Exchange message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IExchange, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Exchange message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Exchange + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Exchange; + + /** + * Creates an Exchange message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Exchange + */ + public static fromObject(d: { [k: string]: any }): Exchange; + + /** + * Creates a plain object from an Exchange message. Also converts values to other types if specified. + * @param m Exchange + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Exchange, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Exchange to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +/** KeyType enum. */ +export enum KeyType { + RSA = 0, + Ed25519 = 1, + Secp256k1 = 2, + ECDSA = 3 +} + +/** Represents a PublicKey. */ +export class PublicKey implements IPublicKey { + + /** + * Constructs a new PublicKey. + * @param [p] Properties to set + */ + constructor(p?: IPublicKey); + + /** PublicKey Type. */ + public Type: KeyType; + + /** PublicKey Data. */ + public Data: Uint8Array; + + /** + * Encodes the specified PublicKey message. Does not implicitly {@link PublicKey.verify|verify} messages. + * @param m PublicKey message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IPublicKey, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a PublicKey message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns PublicKey + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): PublicKey; + + /** + * Creates a PublicKey message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns PublicKey + */ + public static fromObject(d: { [k: string]: any }): PublicKey; + + /** + * Creates a plain object from a PublicKey message. Also converts values to other types if specified. + * @param m PublicKey + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: PublicKey, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this PublicKey to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/dist/src/keychain/cms.d.ts b/dist/src/keychain/cms.d.ts new file mode 100644 index 00000000..cf716f80 --- /dev/null +++ b/dist/src/keychain/cms.d.ts @@ -0,0 +1,41 @@ +export = CMS; +/** + * Cryptographic Message Syntax (aka PKCS #7) + * + * CMS describes an encapsulation syntax for data protection. It + * is used to digitally sign, digest, authenticate, or encrypt + * arbitrary message content. + * + * See RFC 5652 for all the details. + */ +declare class CMS { + /** + * Creates a new instance with a keychain + * + * @param {import('./index')} keychain - the available keys + * @param {string} dek + */ + constructor(keychain: import('./index'), dek: string); + keychain: import("./index"); + /** + * Creates some protected data. + * + * The output Uint8Array contains the PKCS #7 message in DER. + * + * @param {string} name - The local key name. + * @param {Uint8Array} plain - The data to encrypt. + * @returns {Promise} + */ + encrypt(name: string, plain: Uint8Array): Promise; + /** + * Reads some protected data. + * + * The keychain must contain one of the keys used to encrypt the data. If none of the keys + * exists, an Error is returned with the property 'missingKeys'. It is array of key ids. + * + * @param {Uint8Array} cmsData - The CMS encrypted data to decrypt. + * @returns {Promise} + */ + decrypt(cmsData: Uint8Array): Promise; +} +//# sourceMappingURL=cms.d.ts.map \ No newline at end of file diff --git a/dist/src/keychain/cms.d.ts.map b/dist/src/keychain/cms.d.ts.map new file mode 100644 index 00000000..d3184610 --- /dev/null +++ b/dist/src/keychain/cms.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../../src/keychain/cms.js"],"names":[],"mappings":";AAeA;;;;;;;;GAQG;AACH;IACE;;;;;OAKG;IACH,sBAHW,OAAO,SAAS,CAAC,OACjB,MAAM,EAShB;IAFC,4BAAwB;IAI1B;;;;;;;;OAQG;IACH,cAJW,MAAM,SACN,UAAU,GACR,QAAQ,UAAU,CAAC,CAuB/B;IAED;;;;;;;;OAQG;IACH,iBAHW,UAAU,GACR,QAAQ,UAAU,CAAC,CA8D/B;CACF"} \ No newline at end of file diff --git a/dist/src/keychain/index.d.ts b/dist/src/keychain/index.d.ts new file mode 100644 index 00000000..63498da3 --- /dev/null +++ b/dist/src/keychain/index.d.ts @@ -0,0 +1,151 @@ +export = Keychain; +/** + * Manages the lifecycle of a key. Keys are encrypted at rest using PKCS #8. + * + * A key in the store has two entries + * - '/info/*key-name*', contains the KeyInfo for the key + * - '/pkcs8/*key-name*', contains the PKCS #8 for the key + * + */ +declare class Keychain { + /** + * Generates the options for a keychain. A random salt is produced. + * + * @returns {Object} + */ + static generateOptions(): Object; + /** + * Gets an object that can encrypt/decrypt protected data. + * The default options for a keychain. + * + * @returns {Object} + */ + static get options(): Object; + /** + * Creates a new instance of a key chain. + * + * @param {Datastore} store - where the key are. + * @param {KeychainOptions} options + * @class + */ + constructor(store: Datastore, options: KeychainOptions); + store: import("interface-datastore/dist/src/types").Datastore; + opts: any; + /** + * Gets an object that can encrypt/decrypt protected data + * using the Cryptographic Message Syntax (CMS). + * + * CMS describes an encapsulation syntax for data protection. It + * is used to digitally sign, digest, authenticate, or encrypt + * arbitrary message content. + * + * @returns {CMS} + */ + get cms(): CMS; + /** + * Create a new key. + * + * @param {string} name - The local key name; cannot already exist. + * @param {string} type - One of the key types; 'rsa'. + * @param {number} [size = 2048] - The key size in bits. Used for rsa keys only. + * @returns {Promise} + */ + createKey(name: string, type: string, size?: number | undefined): Promise; + /** + * List all the keys. + * + * @returns {Promise} + */ + listKeys(): Promise; + /** + * Find a key by it's id. + * + * @param {string} id - The universally unique key identifier. + * @returns {Promise} + */ + findKeyById(id: string): Promise; + /** + * Find a key by it's name. + * + * @param {string} name - The local key name. + * @returns {Promise} + */ + findKeyByName(name: string): Promise; + /** + * Remove an existing key. + * + * @param {string} name - The local key name; must already exist. + * @returns {Promise} + */ + removeKey(name: string): Promise; + /** + * Rename a key + * + * @param {string} oldName - The old local key name; must already exist. + * @param {string} newName - The new local key name; must not already exist. + * @returns {Promise} + */ + renameKey(oldName: string, newName: string): Promise; + /** + * Export an existing key as a PEM encrypted PKCS #8 string + * + * @param {string} name - The local key name; must already exist. + * @param {string} password - The password + * @returns {Promise} + */ + exportKey(name: string, password: string): Promise; + /** + * Import a new key from a PEM encoded PKCS #8 string + * + * @param {string} name - The local key name; must not already exist. + * @param {string} pem - The PEM encoded PKCS #8 string + * @param {string} password - The password. + * @returns {Promise} + */ + importKey(name: string, pem: string, password: string): Promise; + /** + * Import a peer key + * + * @param {string} name - The local key name; must not already exist. + * @param {PeerId} peer - The PEM encoded PKCS #8 string + * @returns {Promise} + */ + importPeer(name: string, peer: PeerId): Promise; + /** + * Gets the private key as PEM encoded PKCS #8 string. + * + * @param {string} name + * @returns {Promise} + */ + _getPrivateKey(name: string): Promise; +} +declare namespace Keychain { + export { PeerId, Datastore, DekOptions, KeychainOptions, KeyInfo }; +} +import CMS = require("./cms"); +/** + * Information about a key. + */ +type KeyInfo = { + /** + * - The universally unique key id. + */ + id: string; + /** + * - The local key name. + */ + name: string; +}; +type PeerId = import('peer-id'); +type Datastore = import('interface-datastore').Datastore; +type KeychainOptions = { + pass?: string | undefined; + dek?: DekOptions | undefined; +}; +type DekOptions = { + hash: string; + salt: string; + iterationCount: number; + keyLength: number; +}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/keychain/index.d.ts.map b/dist/src/keychain/index.d.ts.map new file mode 100644 index 00000000..9522b79e --- /dev/null +++ b/dist/src/keychain/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/keychain/index.js"],"names":[],"mappings":";AA+GA;;;;;;;GAOG;AACH;IAwDE;;;;OAIG;IACH,0BAFa,MAAM,CAOlB;IAED;;;;;OAKG;IACH,6BAEC;IA3ED;;;;;;OAMG;IACH,mBAJW,SAAS,WACT,eAAe,EAmCzB;IA5BC,8DAAkB;IAElB,UAAiD;IA4BnD;;;;;;;;;OASG;IACH,eAEC;IAwBD;;;;;;;OAOG;IACH,gBALW,MAAM,QACN,MAAM,8BAEJ,QAAQ,OAAO,CAAC,CAiD5B;IAED;;;;OAIG;IACH,YAFa,QAAQ,OAAO,EAAE,CAAC,CAc9B;IAED;;;;;OAKG;IACH,gBAHW,MAAM,GACJ,QAAQ,OAAO,GAAC,SAAS,CAAC,CAStC;IAED;;;;;OAKG;IACH,oBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAc5B;IAED;;;;;OAKG;IACH,gBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAc5B;IAED;;;;;;OAMG;IACH,mBAJW,MAAM,WACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAkC5B;IAED;;;;;;OAMG;IACH,gBAJW,MAAM,YACN,MAAM,GACJ,QAAQ,MAAM,CAAC,CAqB3B;IAED;;;;;;;OAOG;IACH,gBALW,MAAM,OACN,MAAM,YACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAyC5B;IAED;;;;;;OAMG;IACH,iBAJW,MAAM,QACN,MAAM,GACJ,QAAQ,OAAO,CAAC,CAiC5B;IAED;;;;;OAKG;IACH,qBAHW,MAAM,GACJ,QAAQ,MAAM,CAAC,CAc3B;CACF;;;;;;;;;;;;QArda,MAAM;;;;UACN,MAAM;;cArBP,OAAO,SAAS,CAAC;iBACjB,OAAO,qBAAqB,EAAE,SAAS;;;;;;UAKtC,MAAM;UACN,MAAM;oBACN,MAAM;eACN,MAAM"} \ No newline at end of file diff --git a/dist/src/keychain/util.d.ts b/dist/src/keychain/util.d.ts new file mode 100644 index 00000000..378ff4ea --- /dev/null +++ b/dist/src/keychain/util.d.ts @@ -0,0 +1,24 @@ +/** + * Gets a self-signed X.509 certificate for the key. + * + * The output Uint8Array contains the PKCS #7 message in DER. + * + * TODO: move to libp2p-crypto package + * + * @param {KeyInfo} key - The id and name of the key + * @param {RsaPrivateKey} privateKey - The naked key + * @returns {Uint8Array} + */ +export function certificateForKey(key: any, privateKey: any): Uint8Array; +/** + * Finds the first item in a collection that is matched in the + * `asyncCompare` function. + * + * `asyncCompare` is an async function that must + * resolve to either `true` or `false`. + * + * @param {Array} array + * @param {function(*)} asyncCompare - An async function that returns a boolean + */ +export function findAsync(array: any[], asyncCompare: (arg0: any) => any): Promise; +//# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/dist/src/keychain/util.d.ts.map b/dist/src/keychain/util.d.ts.map new file mode 100644 index 00000000..d9af810f --- /dev/null +++ b/dist/src/keychain/util.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/keychain/util.js"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,8DAFa,UAAU,CAqDtB;AAED;;;;;;;;;GASG;AACH,wFAKC"} \ No newline at end of file diff --git a/dist/src/metrics/index.d.ts b/dist/src/metrics/index.d.ts new file mode 100644 index 00000000..3a6d0e3e --- /dev/null +++ b/dist/src/metrics/index.d.ts @@ -0,0 +1,147 @@ +export = Metrics; +/** + * @typedef {import('peer-id')} PeerId + * @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection + */ +/** + * @typedef MetricsProperties + * @property {import('../connection-manager')} connectionManager + * + * @typedef MetricsOptions + * @property {number} [computeThrottleMaxQueueSize = defaultOptions.computeThrottleMaxQueueSize] + * @property {number} [computeThrottleTimeout = defaultOptions.computeThrottleTimeout] + * @property {number[]} [movingAverageIntervals = defaultOptions.movingAverageIntervals] + * @property {number} [maxOldPeersRetention = defaultOptions.maxOldPeersRetention] + */ +declare class Metrics { + /** + * Merges `other` into `target`. `target` will be modified + * and returned. + * + * @param {Stats} target + * @param {Stats} other + * @returns {Stats} + */ + static mergeStats(target: Stats, other: Stats): Stats; + /** + * @class + * @param {MetricsProperties & MetricsOptions} options + */ + constructor(options: MetricsProperties & MetricsOptions); + _options: any; + _globalStats: Stats; + _peerStats: Map; + _protocolStats: Map; + _oldPeers: any; + _running: boolean; + /** + * Takes the metadata for a message and tracks it in the + * appropriate categories. If the protocol is present, protocol + * stats will also be tracked. + * + * @private + * @param {object} params + * @param {PeerId} params.remotePeer - Remote peer + * @param {string} [params.protocol] - Protocol string the stream is running + * @param {string} params.direction - One of ['in','out'] + * @param {number} params.dataLength - Size of the message + * @returns {void} + */ + private _onMessage; + _connectionManager: import("../connection-manager"); + /** + * Must be called for stats to saved. Any data pushed for tracking + * will be ignored. + */ + start(): void; + /** + * Stops all averages timers and prevents new data from being tracked. + * Once `stop` is called, `start` must be called to resume stats tracking. + */ + stop(): void; + /** + * Gets the global `Stats` object + * + * @returns {Stats} + */ + get global(): Stats; + /** + * Returns a list of `PeerId` strings currently being tracked + * + * @returns {string[]} + */ + get peers(): string[]; + /** + * Returns the `Stats` object for the given `PeerId` whether it + * is a live peer, or in the disconnected peer LRU cache. + * + * @param {PeerId} peerId + * @returns {Stats} + */ + forPeer(peerId: PeerId): Stats; + /** + * Returns a list of all protocol strings currently being tracked. + * + * @returns {string[]} + */ + get protocols(): string[]; + /** + * Returns the `Stats` object for the given `protocol`. + * + * @param {string} protocol + * @returns {Stats} + */ + forProtocol(protocol: string): Stats; + /** + * Should be called when all connections to a given peer + * have closed. The `Stats` collection for the peer will + * be stopped and moved to an LRU for temporary retention. + * + * @param {PeerId} peerId + */ + onPeerDisconnected(peerId: PeerId): void; + /** + * Replaces the `PeerId` string with the given `peerId`. + * If stats are already being tracked for the given `peerId`, the + * placeholder stats will be merged with the existing stats. + * + * @param {PeerId} placeholder - A peerId string + * @param {PeerId} peerId + * @returns {void} + */ + updatePlaceholder(placeholder: PeerId, peerId: PeerId): void; + /** + * Tracks data running through a given Duplex Iterable `stream`. If + * the `peerId` is not provided, a placeholder string will be created and + * returned. This allows lazy tracking of a peer when the peer is not yet known. + * When the `PeerId` is known, `Metrics.updatePlaceholder` should be called + * with the placeholder string returned from here, and the known `PeerId`. + * + * @param {Object} options + * @param {MultiaddrConnection} options.stream - A duplex iterable stream + * @param {PeerId} [options.remotePeer] - The id of the remote peer that's connected + * @param {string} [options.protocol] - The protocol the stream is running + * @returns {MultiaddrConnection} The peerId string or placeholder string + */ + trackStream({ stream, remotePeer, protocol }: { + stream: MultiaddrConnection; + remotePeer?: import("peer-id") | undefined; + protocol?: string | undefined; + }): MultiaddrConnection; +} +declare namespace Metrics { + export { PeerId, MultiaddrConnection, MetricsProperties, MetricsOptions }; +} +import Stats = require("./stats"); +type PeerId = import('peer-id'); +type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection; +type MetricsProperties = { + connectionManager: import('../connection-manager'); +}; +type MetricsOptions = { + computeThrottleMaxQueueSize?: number | undefined; + computeThrottleTimeout?: number | undefined; + movingAverageIntervals?: number[] | undefined; + maxOldPeersRetention?: number | undefined; +}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/metrics/index.d.ts.map b/dist/src/metrics/index.d.ts.map new file mode 100644 index 00000000..88bb89d1 --- /dev/null +++ b/dist/src/metrics/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.js"],"names":[],"mappings":";AAoBA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH;IAwNE;;;;;;;OAOG;IACH,0BAJW,KAAK,SACL,KAAK,GACH,KAAK,CAWjB;IAxOD;;;OAGG;IACH,qBAFW,iBAAiB,GAAG,cAAc,EAc5C;IAXC,cAAqD;IACrD,oBAA6D;IAC7D,0BAA2B;IAC3B,8BAA+B;IAC/B,eAA+D;IAC/D,kBAAqB;IAiGvB;;;;;;;;;;;;OAYG;IACH,mBAwBC;IApIC,oDAAmD;IAMrD;;;OAGG;IACH,cAEC;IAED;;;OAGG;IACH,aASC;IAED;;;;OAIG;IACH,oBAEC;IAED;;;;OAIG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,gBAHW,MAAM,GACJ,KAAK,CAKjB;IAED;;;;OAIG;IACH,0BAEC;IAED;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,KAAK,CAIjB;IAED;;;;;;OAMG;IACH,2BAFW,MAAM,QAUhB;IAyCD;;;;;;;;OAQG;IACH,+BAJW,MAAM,UACN,MAAM,GACJ,IAAI,CAoBhB;IAED;;;;;;;;;;;;OAYG;IACH;QALwC,MAAM,EAAnC,mBAAmB;QACF,UAAU;QACV,QAAQ;QACvB,mBAAmB,CA2B/B;CAoBF;;;;;cAzPY,OAAO,SAAS,CAAC;2BACjB,OAAO,uCAAuC,EAAE,mBAAmB;;uBAKlE,OAAO,uBAAuB,CAAC"} \ No newline at end of file diff --git a/dist/src/metrics/old-peers.d.ts b/dist/src/metrics/old-peers.d.ts new file mode 100644 index 00000000..b96556f9 --- /dev/null +++ b/dist/src/metrics/old-peers.d.ts @@ -0,0 +1,3 @@ +declare function _exports(maxSize: number): any; +export = _exports; +//# sourceMappingURL=old-peers.d.ts.map \ No newline at end of file diff --git a/dist/src/metrics/old-peers.d.ts.map b/dist/src/metrics/old-peers.d.ts.map new file mode 100644 index 00000000..f9f88898 --- /dev/null +++ b/dist/src/metrics/old-peers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"old-peers.d.ts","sourceRoot":"","sources":["../../../src/metrics/old-peers.js"],"names":[],"mappings":"AAUiB,mCAHN,MAAM,GACJ,GAAG,CAOf"} \ No newline at end of file diff --git a/dist/src/metrics/stats.d.ts b/dist/src/metrics/stats.d.ts new file mode 100644 index 00000000..81fff97e --- /dev/null +++ b/dist/src/metrics/stats.d.ts @@ -0,0 +1,136 @@ +export = Stats; +declare const Stats_base: import("../types").EventEmitterFactory; +declare class Stats extends Stats_base { + /** + * A queue based manager for stat processing + * + * @class + * @param {string[]} initialCounters + * @param {any} options + */ + constructor(initialCounters: string[], options: any); + _options: any; + _queue: any[]; + /** @type {{ dataReceived: Big, dataSent: Big }} */ + _stats: { + dataReceived: Big; + dataSent: Big; + }; + _frequencyLastTime: number; + _frequencyAccumulators: {}; + /** @type {{ dataReceived: MovingAverage[], dataSent: MovingAverage[] }} */ + _movingAverages: { + dataReceived: MovingAverage[]; + dataSent: MovingAverage[]; + }; + /** + * If there are items in the queue, they will will be processed and + * the frequency for all items will be updated based on the Timestamp + * of the last item in the queue. The `update` event will also be emitted + * with the latest stats. + * + * If there are no items in the queue, no action is taken. + * + * @private + * @returns {void} + */ + private _update; + /** + * Initializes the internal timer if there are items in the queue. This + * should only need to be called if `Stats.stop` was previously called, as + * `Stats.push` will also start the processing. + * + * @returns {void} + */ + start(): void; + /** + * Stops processing and computing of stats by clearing the internal + * timer. + * + * @returns {void} + */ + stop(): void; + _timeout: any; + /** + * Returns a clone of the current stats. + */ + get snapshot(): { + dataReceived: Big; + dataSent: Big; + }; + /** + * Returns a clone of the internal movingAverages + */ + get movingAverages(): { + dataReceived: MovingAverage[]; + dataSent: MovingAverage[]; + }; + /** + * Returns a plain JSON object of the stats + * + * @returns {*} + */ + toJSON(): any; + /** + * Pushes the given operation data to the queue, along with the + * current Timestamp, then resets the update timer. + * + * @param {string} counter + * @param {number} inc + * @returns {void} + */ + push(counter: string, inc: number): void; + /** + * Resets the timeout for triggering updates. + * + * @private + * @returns {void} + */ + private _resetComputeTimeout; + /** + * Calculates and returns the timeout for the next update based on + * the urgency of the update. + * + * @private + * @returns {number} + */ + private _nextTimeout; + /** + * For each key in the stats, the frequency and moving averages + * will be updated via Stats._updateFrequencyFor based on the time + * difference between calls to this method. + * + * @private + * @param {Timestamp} latestTime + * @returns {void} + */ + private _updateFrequency; + /** + * Updates the `movingAverages` for the given `key` and also + * resets the `frequencyAccumulator` for the `key`. + * + * @private + * @param {string} key + * @param {number} timeDiffMS - Time in milliseconds + * @param {Timestamp} latestTime - Time in ticks + * @returns {void} + */ + private _updateFrequencyFor; + /** + * For the given operation, `op`, the stats and `frequencyAccumulator` + * will be updated or initialized if they don't already exist. + * + * @private + * @param {{string, number}[]} op + * @throws {InvalidNumber} + * @returns {void} + */ + private _applyOp; +} +declare namespace Stats { + export { Events }; +} +import { BigNumber as Big } from "bignumber.js"; +import MovingAverage = require("moving-average"); +type Events = import('../types').EventEmitterFactory; +//# sourceMappingURL=stats.d.ts.map \ No newline at end of file diff --git a/dist/src/metrics/stats.d.ts.map b/dist/src/metrics/stats.d.ts.map new file mode 100644 index 00000000..01a2fd91 --- /dev/null +++ b/dist/src/metrics/stats.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/metrics/stats.js"],"names":[],"mappings":";;AAUA;IACE;;;;;;OAMG;IACH,6BAHW,MAAM,EAAE,WACR,GAAG,EAkCb;IA7BC,cAAuB;IACvB,cAAgB;IAEhB,mDAAmD;IACnD;sBAD2B,GAAG;kBAAY,GAAG;MAI5C;IAED,2BAAoC;IACpC,2BAAgC;IAEhC,2EAA2E;IAC3E;sBAD2B,aAAa,EAAE;kBAAY,aAAa,EAAE;MAC5C;IAwH3B;;;;;;;;;;OAUG;IACH,gBAaC;IA9HD;;;;;;OAMG;IACH,SAFa,IAAI,CAMhB;IAED;;;;;OAKG;IACH,QAFa,IAAI,CAOhB;IAFG,cAAoB;IAIxB;;OAEG;IACH;sBAzD6B,GAAG;kBAAY,GAAG;MA2D9C;IAED;;OAEG;IACH;sBAvD6B,aAAa,EAAE;kBAAY,aAAa,EAAE;MAyDtE;IAED;;;;OAIG;IACH,cAkBC;IAED;;;;;;;OAOG;IACH,cAJW,MAAM,OACN,MAAM,GACJ,IAAI,CAKhB;IAED;;;;;OAKG;IACH,6BAEC;IAED;;;;;;OAMG;IACH,qBAKC;IA4BD;;;;;;;;OAQG;IACH,yBAQC;IAED;;;;;;;;;OASG;IACH,4BAsBC;IAED;;;;;;;;OAQG;IACH,iBAqBC;CACF;;;;;;cArQa,OAAO,UAAU,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/nat-manager.d.ts b/dist/src/nat-manager.d.ts new file mode 100644 index 00000000..718b5fda --- /dev/null +++ b/dist/src/nat-manager.d.ts @@ -0,0 +1,121 @@ +export = NatManager; +declare class NatManager { + /** + * @class + * @param {NatManagerProperties & NatManagerOptions} options + */ + constructor({ peerId, addressManager, transportManager, ...options }: NatManagerProperties & NatManagerOptions); + _peerId: import("peer-id"); + _addressManager: import("./address-manager"); + _transportManager: import("./transport-manager"); + _enabled: boolean; + _externalIp: string | undefined; + _options: { + description: string; + ttl: number; + autoUpdate: true; + gateway: string | undefined; + enablePMP: boolean; + }; + /** + * Starts the NAT manager + */ + start(): void; + _start(): Promise; + _getClient(): { + /** + * @param {...any} args + * @returns {Promise} + */ + map: (...args: any[]) => Promise; + /** + * @param {...any} args + * @returns {Promise} + */ + destroy: (...args: any[]) => Promise; + /** + * @param {...any} args + * @returns {Promise} + */ + externalIp: (...args: any[]) => Promise; + }; + _client: { + /** + * @param {...any} args + * @returns {Promise} + */ + map: (...args: any[]) => Promise; + /** + * @param {...any} args + * @returns {Promise} + */ + destroy: (...args: any[]) => Promise; + /** + * @param {...any} args + * @returns {Promise} + */ + externalIp: (...args: any[]) => Promise; + } | null | undefined; + /** + * Stops the NAT manager + * + * @async + */ + stop(): Promise; +} +declare namespace NatManager { + export { PeerId, TransportManager, AddressManager, NatManagerProperties, NatManagerOptions }; +} +type NatManagerProperties = { + /** + * - The peer ID of the current node + */ + peerId: PeerId; + /** + * - A transport manager + */ + transportManager: TransportManager; + /** + * - An address manager + */ + addressManager: AddressManager; +}; +type NatManagerOptions = { + /** + * - Whether to enable the NAT manager + */ + enabled: boolean; + /** + * - Pass a value to use instead of auto-detection + */ + externalIp?: string | undefined; + /** + * - A string value to use for the port mapping description on the gateway + */ + description?: string | undefined; + /** + * - How long UPnP port mappings should last for in seconds (minimum 1200) + */ + ttl?: number | undefined; + /** + * - Whether to automatically refresh UPnP port mappings when their TTL is reached + */ + keepAlive?: boolean | undefined; + /** + * - Pass a value to use instead of auto-detection + */ + gateway?: string | undefined; + /** + * - PMP options + */ + pmp?: { + /** + * - Whether to enable PMP as well as UPnP + */ + enabled?: boolean | undefined; + } | undefined; +}; +type PeerId = import('peer-id'); +type TransportManager = import('./transport-manager'); +type AddressManager = import('./address-manager'); +//# sourceMappingURL=nat-manager.d.ts.map \ No newline at end of file diff --git a/dist/src/nat-manager.d.ts.map b/dist/src/nat-manager.d.ts.map new file mode 100644 index 00000000..693e25ea --- /dev/null +++ b/dist/src/nat-manager.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"nat-manager.d.ts","sourceRoot":"","sources":["../../src/nat-manager.js"],"names":[],"mappings":";AAkDA;IACE;;;OAGG;IACH,sEAFW,oBAAoB,GAAG,iBAAiB,EAoBlD;IAjBC,2BAAqB;IACrB,6CAAqC;IACrC,iDAAyC;IAEzC,kBAA+B;IAC/B,gCAAqC;IACrC;;;;;;MAMC;IAOH;;OAEG;IACH,cAUC;IAED,wBA+CC;IAED;QAgBI;;;WAGG;uBAFY,GAAG,OACL,QAAQ,IAAI,CAAC;QAI1B;;;WAGG;2BAFY,GAAG,OACL,QAAQ,IAAI,CAAC;QAI1B;;;WAGG;8BAFY,GAAG,OACL,QAAQ,MAAM,CAAC;MAM/B;IArBC;QACE;;;WAGG;uBAFY,GAAG,OACL,QAAQ,IAAI,CAAC;QAI1B;;;WAGG;2BAFY,GAAG,OACL,QAAQ,IAAI,CAAC;QAI1B;;;WAGG;8BAFY,GAAG,OACL,QAAQ,MAAM,CAAC;yBAG7B;IAKH;;;;OAIG;IACH,sBAWC;CACF;;;;;;;;YAnKa,MAAM;;;;sBACN,gBAAgB;;;;oBAChB,cAAc;;;;;;aAGd,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAZR,OAAO,SAAS,CAAC;wBACjB,OAAO,qBAAqB,CAAC;sBAC7B,OAAO,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/src/peer-routing.d.ts b/dist/src/peer-routing.d.ts new file mode 100644 index 00000000..c757712a --- /dev/null +++ b/dist/src/peer-routing.d.ts @@ -0,0 +1,96 @@ +export = PeerRouting; +/** + * @typedef {import('peer-id')} PeerId + * @typedef {import('multiaddr').Multiaddr} Multiaddr + * @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule + */ +/** + * @typedef {Object} RefreshManagerOptions + * @property {boolean} [enabled = true] - Whether to enable the Refresh manager + * @property {number} [bootDelay = 6e5] - Boot delay to start the Refresh Manager (in ms) + * @property {number} [interval = 10e3] - Interval between each Refresh Manager run (in ms) + * + * @typedef {Object} PeerRoutingOptions + * @property {RefreshManagerOptions} [refreshManager] + */ +declare class PeerRouting { + /** + * @class + * @param {import('./')} libp2p + */ + constructor(libp2p: import('./')); + _peerId: import("peer-id"); + _peerStore: import("./peer-store"); + /** @type {PeerRoutingModule[]} */ + _routers: PeerRoutingModule[]; + _refreshManagerOptions: { + enabled: boolean; + interval: number; + bootDelay: number; + } & RefreshManagerOptions; + /** + * Recurrent task to find closest peers and add their addresses to the Address Book. + */ + _findClosestPeersTask(): Promise; + /** + * Start peer routing service. + */ + start(): void; + _timeoutId: any; + /** + * Stop peer routing service. + */ + stop(): void; + /** + * Iterates over all peer routers in parallel to find the given peer. + * + * @param {PeerId} id - The id of the peer to find + * @param {object} [options] + * @param {number} [options.timeout] - How long the query should run + * @returns {Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>} + */ + findPeer(id: PeerId, options?: { + timeout?: number | undefined; + } | undefined): Promise<{ + id: PeerId; + multiaddrs: Multiaddr[]; + }>; + /** + * Attempt to find the closest peers on the network to the given key. + * + * @param {Uint8Array} key - A CID like key + * @param {Object} [options] + * @param {number} [options.timeout=30e3] - How long the query can take. + * @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} + */ + getClosestPeers(key: Uint8Array, options?: { + timeout?: number | undefined; + } | undefined): AsyncIterable<{ + id: PeerId; + multiaddrs: Multiaddr[]; + }>; +} +declare namespace PeerRouting { + export { PeerId, Multiaddr, PeerRoutingModule, RefreshManagerOptions, PeerRoutingOptions }; +} +type PeerRoutingModule = import('libp2p-interfaces/src/peer-routing/types').PeerRouting; +type RefreshManagerOptions = { + /** + * - Whether to enable the Refresh manager + */ + enabled?: boolean | undefined; + /** + * - Boot delay to start the Refresh Manager (in ms) + */ + bootDelay?: number | undefined; + /** + * - Interval between each Refresh Manager run (in ms) + */ + interval?: number | undefined; +}; +type PeerId = import('peer-id'); +type Multiaddr = import('multiaddr').Multiaddr; +type PeerRoutingOptions = { + refreshManager?: RefreshManagerOptions | undefined; +}; +//# sourceMappingURL=peer-routing.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-routing.d.ts.map b/dist/src/peer-routing.d.ts.map new file mode 100644 index 00000000..b641b268 --- /dev/null +++ b/dist/src/peer-routing.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"peer-routing.d.ts","sourceRoot":"","sources":["../../src/peer-routing.js"],"names":[],"mappings":";AAwBA;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;IACE;;;OAGG;IACH,oBAFW,OAAO,IAAI,CAAC,EAgBtB;IAbC,2BAA4B;IAC5B,mCAAkC;IAClC,kCAAkC;IAClC,UADW,iBAAiB,EAAE,CACmB;IAOjD;;;;8BAAwE;IAkB1E;;OAEG;IACH,uCAOC;IAvBD;;OAEG;IACH,cAQC;IAHC,gBAEC;IAeH;;OAEG;IACH,aAEC;IAED;;;;;;;OAOG;IACH,aALW,MAAM;;oBAGJ,QAAQ;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CAsB5D;IAED;;;;;;;OAOG;IACH,qBALW,UAAU;;oBAGR,cAAc;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,SAAS,EAAE,CAAA;KAAE,CAAC,CAelE;CACF;;;;yBAtHY,OAAO,0CAA0C,EAAE,WAAW;;;;;;;;;;;;;;;cAF9D,OAAO,SAAS,CAAC;iBACjB,OAAO,WAAW,EAAE,SAAS"} \ No newline at end of file diff --git a/dist/src/peer-store/address-book.d.ts b/dist/src/peer-store/address-book.d.ts new file mode 100644 index 00000000..08ae69b4 --- /dev/null +++ b/dist/src/peer-store/address-book.d.ts @@ -0,0 +1,121 @@ +export = AddressBook; +/** + * @typedef {import('./')} PeerStore + */ +/** + * @typedef {Object} Address + * @property {Multiaddr} multiaddr peer multiaddr. + * @property {boolean} isCertified obtained from a signed peer record. + * + * @typedef {Object} CertifiedRecord + * @property {Uint8Array} raw raw envelope. + * @property {number} seqNumber seq counter. + * + * @typedef {Object} Entry + * @property {Address[]} addresses peer Addresses. + * @property {CertifiedRecord} record certified peer record. + */ +/** + * @extends {Book} + */ +declare class AddressBook extends Book { + /** + * The AddressBook is responsible for keeping the known multiaddrs of a peer. + * + * @class + * @param {PeerStore} peerStore + */ + constructor(peerStore: PeerStore); + /** + * ConsumePeerRecord adds addresses from a signed peer record contained in a record envelope. + * This will return a boolean that indicates if the record was successfully processed and added + * into the AddressBook. + * + * @param {Envelope} envelope + * @returns {boolean} + */ + consumePeerRecord(envelope: Envelope): boolean; + /** + * Get the raw Envelope for a peer. Returns + * undefined if no Envelope is found. + * + * @param {PeerId} peerId + * @returns {Uint8Array|undefined} + */ + getRawEnvelope(peerId: PeerId): Uint8Array | undefined; + /** + * Get an Envelope containing a PeerRecord for the given peer. + * Returns undefined if no record exists. + * + * @param {PeerId} peerId + * @returns {Promise|undefined} + */ + getPeerRecord(peerId: PeerId): Promise | undefined; + /** + * Add known addresses of a provided peer. + * If the peer is not known, it is set with the given addresses. + * + * @param {PeerId} peerId + * @param {Multiaddr[]} multiaddrs + * @returns {AddressBook} + */ + add(peerId: PeerId, multiaddrs: Multiaddr[]): AddressBook; + /** + * Transforms received multiaddrs into Address. + * + * @private + * @param {Multiaddr[]} multiaddrs + * @param {boolean} [isCertified] + * @returns {Address[]} + */ + private _toAddresses; + /** + * Get the known multiaddrs for a given peer. All returned multiaddrs + * will include the encapsulated `PeerId` of the peer. + * Returns `undefined` if there are no known multiaddrs for the given peer. + * + * @param {PeerId} peerId + * @param {(addresses: Address[]) => Address[]} [addressSorter] + * @returns {Multiaddr[]|undefined} + */ + getMultiaddrsForPeer(peerId: PeerId, addressSorter?: ((addresses: Address[]) => Address[]) | undefined): Multiaddr[] | undefined; +} +declare namespace AddressBook { + export { PeerStore, Address, CertifiedRecord, Entry }; +} +import Book = require("./book"); +import Envelope = require("../record/envelope"); +import PeerId = require("peer-id"); +import { Multiaddr } from "multiaddr"; +type Address = { + /** + * peer multiaddr. + */ + multiaddr: Multiaddr; + /** + * obtained from a signed peer record. + */ + isCertified: boolean; +}; +type PeerStore = import('./'); +type CertifiedRecord = { + /** + * raw envelope. + */ + raw: Uint8Array; + /** + * seq counter. + */ + seqNumber: number; +}; +type Entry = { + /** + * peer Addresses. + */ + addresses: Address[]; + /** + * certified peer record. + */ + record: CertifiedRecord; +}; +//# sourceMappingURL=address-book.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/address-book.d.ts.map b/dist/src/peer-store/address-book.d.ts.map new file mode 100644 index 00000000..607c0b5a --- /dev/null +++ b/dist/src/peer-store/address-book.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/address-book.js"],"names":[],"mappings":";AAmBA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH,uBAFW,SAAS,EA0BnB;IAED;;;;;;;OAOG;IACH,4BAHW,QAAQ,GACN,OAAO,CA8CnB;IAED;;;;;;OAMG;IACH,uBAHW,MAAM,GACJ,UAAU,GAAC,SAAS,CAUhC;IAED;;;;;;OAMG;IACH,sBAHW,MAAM,GACJ,QAAQ,QAAQ,GAAC,IAAI,CAAC,GAAC,SAAS,CAU5C;IAuDD;;;;;;;OAOG;IACH,YAJW,MAAM,cACN,SAAS,EAAE,GACT,WAAW,CA+CvB;IAmBD;;;;;;;OAOG;IACH,qBAyBC;IAED;;;;;;;;OAQG;IACH,6BAJW,MAAM,+BACM,OAAO,EAAE,KAAK,OAAO,EAAE,gBACjC,SAAS,EAAE,GAAC,SAAS,CAsBjC;CACF;;;;;;;;;;;;eAtUa,SAAS;;;;iBACT,OAAO;;iBANR,OAAO,IAAI,CAAC;;;;;SASX,UAAU;;;;eACV,MAAM;;;;;;eAGN,OAAO,EAAE;;;;YACT,eAAe"} \ No newline at end of file diff --git a/dist/src/peer-store/book.d.ts b/dist/src/peer-store/book.d.ts new file mode 100644 index 00000000..bf4ad5ae --- /dev/null +++ b/dist/src/peer-store/book.d.ts @@ -0,0 +1,81 @@ +export = Book; +/** + * @typedef {import('./')} PeerStore + */ +declare class Book { + /** + * The Book is the skeleton for the PeerStore books. + * + * @class + * @param {Object} properties + * @param {PeerStore} properties.peerStore - PeerStore instance. + * @param {string} properties.eventName - Name of the event to emit by the PeerStore. + * @param {string} properties.eventProperty - Name of the property to emit by the PeerStore. + * @param {(data: any) => any[]} [properties.eventTransformer] - Transformer function of the provided data for being emitted. + */ + constructor({ peerStore, eventName, eventProperty, eventTransformer }: { + peerStore: PeerStore; + eventName: string; + eventProperty: string; + eventTransformer?: ((data: any) => any[]) | undefined; + }); + _ps: import("./"); + eventName: string; + eventProperty: string; + eventTransformer: (data: any) => any[]; + /** + * Map known peers to their data. + * + * @type {Map} + */ + data: Map; + /** + * Set known data of a provided peer. + * + * @param {PeerId} peerId + * @param {any[]|any} data + */ + set(peerId: PeerId, data: any[] | any): void; + /** + * Set data into the datastructure, persistence and emit it using the provided transformers. + * + * @protected + * @param {PeerId} peerId - peerId of the data to store + * @param {any} data - data to store. + * @param {Object} [options] - storing options. + * @param {boolean} [options.emit = true] - emit the provided data. + * @returns {void} + */ + protected _setData(peerId: PeerId, data: any, { emit }?: { + emit?: boolean | undefined; + } | undefined): void; + /** + * Emit data. + * + * @protected + * @param {PeerId} peerId + * @param {any} [data] + */ + protected _emit(peerId: PeerId, data?: any): void; + /** + * Get the known data of a provided peer. + * Returns `undefined` if there is no available data for the given peer. + * + * @param {PeerId} peerId + * @returns {any[]|any|undefined} + */ + get(peerId: PeerId): any[] | any | undefined; + /** + * Deletes the provided peer from the book. + * + * @param {PeerId} peerId + * @returns {boolean} + */ + delete(peerId: PeerId): boolean; +} +declare namespace Book { + export { PeerStore }; +} +import PeerId = require("peer-id"); +type PeerStore = import('./'); +//# sourceMappingURL=book.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/book.d.ts.map b/dist/src/peer-store/book.d.ts.map new file mode 100644 index 00000000..757bfb79 --- /dev/null +++ b/dist/src/peer-store/book.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/book.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;OASG;IACH;QALiC,SAAS,EAA/B,SAAS;QACU,SAAS,EAA5B,MAAM;QACa,aAAa,EAAhC,MAAM;QAC4B,gBAAgB,WAA3C,GAAG,KAAK,GAAG,EAAE;OAc9B;IAXC,kBAAoB;IACpB,kBAA0B;IAC1B,sBAAkC;IAClC,yBANgB,GAAG,KAAK,GAAG,EAAE,CAMW;IAExC;;;;OAIG;IACH,MAFU,IAAI,MAAM,EAAE,GAAG,EAAE,GAAC,GAAG,CAAC,CAEX;IAGvB;;;;;OAKG;IACH,YAHW,MAAM,QACN,GAAG,EAAE,GAAC,GAAG,QAInB;IAED;;;;;;;;;OASG;IACH,2BANW,MAAM,QACN,GAAG;;oBAGD,IAAI,CAUhB;IAED;;;;;;OAMG;IACH,wBAHW,MAAM,SACN,GAAG,QAOb;IAED;;;;;;OAMG;IACH,YAHW,MAAM,GACJ,GAAG,EAAE,GAAC,GAAG,GAAC,SAAS,CAW/B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAcnB;CACF;;;;;iBA7GY,OAAO,IAAI,CAAC"} \ No newline at end of file diff --git a/dist/src/peer-store/index.d.ts b/dist/src/peer-store/index.d.ts new file mode 100644 index 00000000..ca7004f2 --- /dev/null +++ b/dist/src/peer-store/index.d.ts @@ -0,0 +1,112 @@ +export = PeerStore; +declare const PeerStore_base: import("../types").EventEmitterFactory; +/** + * @typedef {import('./address-book').Address} Address + */ +/** + * @extends {EventEmitter} + * + * @fires PeerStore#peer Emitted when a new peer is added. + * @fires PeerStore#change:protocols Emitted when a known peer supports a different set of protocols. + * @fires PeerStore#change:multiaddrs Emitted when a known peer has a different set of multiaddrs. + * @fires PeerStore#change:pubkey Emitted emitted when a peer's public key is known. + * @fires PeerStore#change:metadata Emitted when the known metadata of a peer change. + */ +declare class PeerStore extends PeerStore_base { + /** + * Peer object + * + * @typedef {Object} Peer + * @property {PeerId} id peer's peer-id instance. + * @property {Address[]} addresses peer's addresses containing its multiaddrs and metadata. + * @property {string[]} protocols peer's supported protocols. + * @property {Map|undefined} metadata peer's metadata map. + */ + /** + * Responsible for managing known peers, as well as their addresses, protocols and metadata. + * + * @param {object} options + * @param {PeerId} options.peerId + * @class + */ + constructor({ peerId }: { + peerId: PeerId; + }); + _peerId: PeerId; + /** + * AddressBook containing a map of peerIdStr to Address. + */ + addressBook: AddressBook; + /** + * KeyBook containing a map of peerIdStr to their PeerId with public keys. + */ + keyBook: KeyBook; + /** + * MetadataBook containing a map of peerIdStr to their metadata Map. + */ + metadataBook: MetadataBook; + /** + * ProtoBook containing a map of peerIdStr to supported protocols. + */ + protoBook: ProtoBook; + /** + * Start the PeerStore. + */ + start(): void; + /** + * Stop the PeerStore. + */ + stop(): void; + /** + * Get all the stored information of every peer known. + * + * @returns {Map} + */ + get peers(): Map; + /** + * Delete the information of the given peer in every book. + * + * @param {PeerId} peerId + * @returns {boolean} true if found and removed + */ + delete(peerId: PeerId): boolean; + /** + * Get the stored information of a given peer. + * + * @param {PeerId} peerId + * @returns {Peer|undefined} + */ + get(peerId: PeerId): Peer | undefined; +} +declare namespace PeerStore { + export { Events, Peer, Address }; +} +import PeerId = require("peer-id"); +import AddressBook = require("./address-book"); +import KeyBook = require("./key-book"); +import MetadataBook = require("./metadata-book"); +import ProtoBook = require("./proto-book"); +/** + * Peer object + */ +type Peer = { + /** + * peer's peer-id instance. + */ + id: PeerId; + /** + * peer's addresses containing its multiaddrs and metadata. + */ + addresses: Address[]; + /** + * peer's supported protocols. + */ + protocols: string[]; + /** + * peer's metadata map. + */ + metadata: Map | undefined; +}; +type Events = import('../types').EventEmitterFactory; +type Address = import('./address-book').Address; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/index.d.ts.map b/dist/src/peer-store/index.d.ts.map new file mode 100644 index 00000000..884c40f2 --- /dev/null +++ b/dist/src/peer-store/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-store/index.js"],"names":[],"mappings":";;AAkBA;;GAEG;AAEH;;;;;;;;GAQG;AACH;IACE;;;;;;;;OAQG;IAEH;;;;;;OAMG;IACH;QAH2B,MAAM,EAAtB,MAAM;OA2BhB;IArBC,gBAAqB;IAErB;;OAEG;IACH,yBAAwC;IAExC;;OAEG;IACH,iBAAgC;IAEhC;;OAEG;IACH,2BAA0C;IAE1C;;OAEG;IACH,qBAAoC;IAGtC;;OAEG;IACH,cAAW;IAEX;;OAEG;IACH,aAAU;IAEV;;;;OAIG;IACH,+BAiBC;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CASnB;IAED;;;;;OAKG;IACH,YAHW,MAAM,GACJ,IAAI,GAAC,SAAS,CAsB1B;CACF;;;;;;;;;;;;;;;;QAnHe,MAAM;;;;eACN,OAAO,EAAE;;;;eACT,MAAM,EAAE;;;;cACR,IAAI,MAAM,EAAE,UAAU,CAAC,GAAC,SAAS;;cAnCnC,OAAO,UAAU,EAAE,mBAAmB;eAevC,OAAO,gBAAgB,EAAE,OAAO"} \ No newline at end of file diff --git a/dist/src/peer-store/key-book.d.ts b/dist/src/peer-store/key-book.d.ts new file mode 100644 index 00000000..a7189743 --- /dev/null +++ b/dist/src/peer-store/key-book.d.ts @@ -0,0 +1,24 @@ +export = KeyBook; +/** + * @typedef {import('./')} PeerStore + * @typedef {import('libp2p-crypto').PublicKey} PublicKey + */ +/** + * @extends {Book} + */ +declare class KeyBook extends Book { + /** + * The KeyBook is responsible for keeping the known public keys of a peer. + * + * @class + * @param {PeerStore} peerStore + */ + constructor(peerStore: PeerStore); +} +declare namespace KeyBook { + export { PeerStore, PublicKey }; +} +import Book = require("./book"); +type PeerStore = import('./'); +type PublicKey = import('libp2p-crypto').PublicKey; +//# sourceMappingURL=key-book.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/key-book.d.ts.map b/dist/src/peer-store/key-book.d.ts.map new file mode 100644 index 00000000..0a829887 --- /dev/null +++ b/dist/src/peer-store/key-book.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"key-book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/key-book.js"],"names":[],"mappings":";AAgBA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH,uBAFW,SAAS,EAgBnB;CAgDF;;;;;iBA5EY,OAAO,IAAI,CAAC;iBACZ,OAAO,eAAe,EAAE,SAAS"} \ No newline at end of file diff --git a/dist/src/peer-store/metadata-book.d.ts b/dist/src/peer-store/metadata-book.d.ts new file mode 100644 index 00000000..46cab772 --- /dev/null +++ b/dist/src/peer-store/metadata-book.d.ts @@ -0,0 +1,53 @@ +export = MetadataBook; +/** + * @typedef {import('./')} PeerStore + */ +/** + * @extends {Book} + * + * @fires MetadataBook#change:metadata + */ +declare class MetadataBook extends Book { + /** + * The MetadataBook is responsible for keeping the known supported + * protocols of a peer. + * + * @class + * @param {PeerStore} peerStore + */ + constructor(peerStore: PeerStore); + /** + * Set data into the datastructure + * + * @override + * @param {PeerId} peerId + * @param {string} key + * @param {Uint8Array} value + */ + _setValue(peerId: PeerId, key: string, value: Uint8Array, { emit }?: { + emit?: boolean | undefined; + }): void; + /** + * Get specific metadata value, if it exists + * + * @param {PeerId} peerId + * @param {string} key + * @returns {Uint8Array | undefined} + */ + getValue(peerId: PeerId, key: string): Uint8Array | undefined; + /** + * Deletes the provided peer metadata key from the book. + * + * @param {PeerId} peerId + * @param {string} key + * @returns {boolean} + */ + deleteValue(peerId: PeerId, key: string): boolean; +} +declare namespace MetadataBook { + export { PeerStore }; +} +import Book = require("./book"); +import PeerId = require("peer-id"); +type PeerStore = import('./'); +//# sourceMappingURL=metadata-book.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/metadata-book.d.ts.map b/dist/src/peer-store/metadata-book.d.ts.map new file mode 100644 index 00000000..6cade1b8 --- /dev/null +++ b/dist/src/peer-store/metadata-book.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata-book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/metadata-book.js"],"names":[],"mappings":";AAiBA;;GAEG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,uBAFW,SAAS,EAmBnB;IA4BD;;;;;;;OAOG;IACH,kBAJW,MAAM,OACN,MAAM,SACN,UAAU;;aAiBpB;IAgBD;;;;;;OAMG;IACH,iBAJW,MAAM,OACN,MAAM,GACJ,UAAU,GAAG,SAAS,CASlC;IAsBD;;;;;;OAMG;IACH,oBAJW,MAAM,OACN,MAAM,GACJ,OAAO,CAgBnB;CACF;;;;;;iBA9JY,OAAO,IAAI,CAAC"} \ No newline at end of file diff --git a/dist/src/peer-store/persistent/consts.d.ts b/dist/src/peer-store/persistent/consts.d.ts new file mode 100644 index 00000000..efaafca1 --- /dev/null +++ b/dist/src/peer-store/persistent/consts.d.ts @@ -0,0 +1,6 @@ +export var NAMESPACE_COMMON: string; +export var NAMESPACE_ADDRESS: string; +export var NAMESPACE_KEYS: string; +export var NAMESPACE_METADATA: string; +export var NAMESPACE_PROTOCOL: string; +//# sourceMappingURL=consts.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/persistent/consts.d.ts.map b/dist/src/peer-store/persistent/consts.d.ts.map new file mode 100644 index 00000000..44a2187c --- /dev/null +++ b/dist/src/peer-store/persistent/consts.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/consts.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/peer-store/persistent/index.d.ts b/dist/src/peer-store/persistent/index.d.ts new file mode 100644 index 00000000..c277bcb8 --- /dev/null +++ b/dist/src/peer-store/persistent/index.d.ts @@ -0,0 +1,130 @@ +export = PersistentPeerStore; +/** + * @typedef {import('interface-datastore').Batch} Batch + * @typedef {import('../address-book.js').Address} Address + */ +/** + * @typedef {Object} PersistentPeerStoreProperties + * @property {PeerId} peerId + * @property {import('interface-datastore').Datastore} datastore + * + * @typedef {Object} PersistentPeerStoreOptions + * @property {number} [threshold = 5] - Number of dirty peers allowed before commit data. + */ +/** + * Responsible for managing the persistence of data in the PeerStore. + */ +declare class PersistentPeerStore extends PeerStore { + /** + * @class + * @param {PersistentPeerStoreProperties & PersistentPeerStoreOptions} properties + */ + constructor({ peerId, datastore, threshold }: PersistentPeerStoreProperties & PersistentPeerStoreOptions); + /** + * Backend datastore used to persist data. + */ + _datastore: import("interface-datastore/dist/src/types").Datastore; + /** + * Peers modified after the latest data persisted. + */ + _dirtyPeers: Set; + /** + * Peers metadata changed mapping peer identifers to metadata changed. + * + * @type {Map>} + */ + _dirtyMetadata: Map>; + threshold: number; + /** + * Add modified peer to the dirty set + * + * @private + * @param {Object} params + * @param {PeerId} params.peerId + */ + private _addDirtyPeer; + /** + * Add modified peer key to the dirty set + * + * @private + * @param {Object} params + * @param {PeerId} params.peerId + */ + private _addDirtyPeerKey; + /** + * Add modified metadata peer to the set. + * + * @private + * @param {Object} params + * @param {PeerId} params.peerId + * @param {string} params.metadata + */ + private _addDirtyPeerMetadata; + /** + * Add all the peers current data to a datastore batch and commit it. + * + * @private + * @returns {Promise} + */ + private _commitData; + /** + * Add address book data of the peer to the batch. + * + * @private + * @param {PeerId} peerId + * @param {Batch} batch + */ + private _batchAddressBook; + /** + * Add Key book data of the peer to the batch. + * + * @private + * @param {PeerId} peerId + * @param {Batch} batch + */ + private _batchKeyBook; + /** + * Add metadata book data of the peer to the batch. + * + * @private + * @param {PeerId} peerId + * @param {Batch} batch + */ + private _batchMetadataBook; + /** + * Add proto book data of the peer to the batch. + * + * @private + * @param {PeerId} peerId + * @param {Batch} batch + */ + private _batchProtoBook; + /** + * Process datastore entry and add its data to the correct book. + * + * @private + * @param {Object} params + * @param {Key} params.key - datastore key + * @param {Uint8Array} params.value - datastore value stored + * @returns {Promise} + */ + private _processDatastoreEntry; +} +declare namespace PersistentPeerStore { + export { Batch, Address, PersistentPeerStoreProperties, PersistentPeerStoreOptions }; +} +import PeerStore = require(".."); +type PersistentPeerStoreProperties = { + peerId: PeerId; + datastore: import('interface-datastore').Datastore; +}; +type PersistentPeerStoreOptions = { + /** + * - Number of dirty peers allowed before commit data. + */ + threshold?: number | undefined; +}; +type Batch = import('interface-datastore').Batch; +type Address = import('../address-book.js').Address; +import PeerId = require("peer-id"); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/persistent/index.d.ts.map b/dist/src/peer-store/persistent/index.d.ts.map new file mode 100644 index 00000000..ef408e87 --- /dev/null +++ b/dist/src/peer-store/persistent/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/index.js"],"names":[],"mappings":";AAuBA;;;GAGG;AAEH;;;;;;;GAOG;AAEH;;GAEG;AACH;IACE;;;OAGG;IACH,8CAFW,6BAA6B,GAAG,0BAA0B,EAwBpE;IAnBC;;OAEG;IACH,mEAA2B;IAE3B;;OAEG;IACH,sBAA4B;IAE5B;;;;OAIG;IACH,gBAFU,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC,CAEH;IAE/B,kBAA0B;IAsC5B;;;;;;OAMG;IACH,sBAYC;IAED;;;;;;OAMG;IACH,yBAiBC;IAED;;;;;;;OAOG;IACH,8BAiBC;IAED;;;;;OAKG;IACH,oBA+BC;IAED;;;;;;OAMG;IACH,0BA8BC;IAED;;;;;;OAMG;IACH,sBAiBC;IAED;;;;;;OAMG;IACH,2BAkBC;IAED;;;;;;OAMG;IACH,wBAmBC;IAED;;;;;;;;OAQG;IACH,+BA0DC;CACF;;;;;;YAtXa,MAAM;eACN,OAAO,qBAAqB,EAAE,SAAS;;;;;;;;aAPxC,OAAO,qBAAqB,EAAE,KAAK;eACnC,OAAO,oBAAoB,EAAE,OAAO"} \ No newline at end of file diff --git a/dist/src/peer-store/persistent/pb/address-book.d.ts b/dist/src/peer-store/persistent/pb/address-book.d.ts new file mode 100644 index 00000000..0080a639 --- /dev/null +++ b/dist/src/peer-store/persistent/pb/address-book.d.ts @@ -0,0 +1,198 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Addresses. */ +export interface IAddresses { + + /** Addresses addrs */ + addrs?: (Addresses.IAddress[]|null); + + /** Addresses certifiedRecord */ + certifiedRecord?: (Addresses.ICertifiedRecord|null); +} + +/** Represents an Addresses. */ +export class Addresses implements IAddresses { + + /** + * Constructs a new Addresses. + * @param [p] Properties to set + */ + constructor(p?: IAddresses); + + /** Addresses addrs. */ + public addrs: Addresses.IAddress[]; + + /** Addresses certifiedRecord. */ + public certifiedRecord?: (Addresses.ICertifiedRecord|null); + + /** + * Encodes the specified Addresses message. Does not implicitly {@link Addresses.verify|verify} messages. + * @param m Addresses message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IAddresses, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Addresses message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Addresses + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses; + + /** + * Creates an Addresses message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Addresses + */ + public static fromObject(d: { [k: string]: any }): Addresses; + + /** + * Creates a plain object from an Addresses message. Also converts values to other types if specified. + * @param m Addresses + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Addresses to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace Addresses { + + /** Properties of an Address. */ + interface IAddress { + + /** Address multiaddr */ + multiaddr?: (Uint8Array|null); + + /** Address isCertified */ + isCertified?: (boolean|null); + } + + /** Represents an Address. */ + class Address implements IAddress { + + /** + * Constructs a new Address. + * @param [p] Properties to set + */ + constructor(p?: Addresses.IAddress); + + /** Address multiaddr. */ + public multiaddr: Uint8Array; + + /** Address isCertified. */ + public isCertified: boolean; + + /** + * Encodes the specified Address message. Does not implicitly {@link Addresses.Address.verify|verify} messages. + * @param m Address message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: Addresses.IAddress, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Address message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Address + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.Address; + + /** + * Creates an Address message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Address + */ + public static fromObject(d: { [k: string]: any }): Addresses.Address; + + /** + * Creates a plain object from an Address message. Also converts values to other types if specified. + * @param m Address + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses.Address, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Address to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a CertifiedRecord. */ + interface ICertifiedRecord { + + /** CertifiedRecord seq */ + seq?: (number|null); + + /** CertifiedRecord raw */ + raw?: (Uint8Array|null); + } + + /** Represents a CertifiedRecord. */ + class CertifiedRecord implements ICertifiedRecord { + + /** + * Constructs a new CertifiedRecord. + * @param [p] Properties to set + */ + constructor(p?: Addresses.ICertifiedRecord); + + /** CertifiedRecord seq. */ + public seq: number; + + /** CertifiedRecord raw. */ + public raw: Uint8Array; + + /** + * Encodes the specified CertifiedRecord message. Does not implicitly {@link Addresses.CertifiedRecord.verify|verify} messages. + * @param m CertifiedRecord message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: Addresses.ICertifiedRecord, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a CertifiedRecord message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns CertifiedRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.CertifiedRecord; + + /** + * Creates a CertifiedRecord message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns CertifiedRecord + */ + public static fromObject(d: { [k: string]: any }): Addresses.CertifiedRecord; + + /** + * Creates a plain object from a CertifiedRecord message. Also converts values to other types if specified. + * @param m CertifiedRecord + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Addresses.CertifiedRecord, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this CertifiedRecord to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/dist/src/peer-store/persistent/pb/proto-book.d.ts b/dist/src/peer-store/persistent/pb/proto-book.d.ts new file mode 100644 index 00000000..f3590f87 --- /dev/null +++ b/dist/src/peer-store/persistent/pb/proto-book.d.ts @@ -0,0 +1,59 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a Protocols. */ +export interface IProtocols { + + /** Protocols protocols */ + protocols?: (string[]|null); +} + +/** Represents a Protocols. */ +export class Protocols implements IProtocols { + + /** + * Constructs a new Protocols. + * @param [p] Properties to set + */ + constructor(p?: IProtocols); + + /** Protocols protocols. */ + public protocols: string[]; + + /** + * Encodes the specified Protocols message. Does not implicitly {@link Protocols.verify|verify} messages. + * @param m Protocols message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IProtocols, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Protocols message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Protocols + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Protocols; + + /** + * Creates a Protocols message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Protocols + */ + public static fromObject(d: { [k: string]: any }): Protocols; + + /** + * Creates a plain object from a Protocols message. Also converts values to other types if specified. + * @param m Protocols + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Protocols, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Protocols to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/dist/src/peer-store/proto-book.d.ts b/dist/src/peer-store/proto-book.d.ts new file mode 100644 index 00000000..6e66c7d5 --- /dev/null +++ b/dist/src/peer-store/proto-book.d.ts @@ -0,0 +1,44 @@ +export = ProtoBook; +/** + * @typedef {import('./')} PeerStore + */ +/** + * @extends {Book} + * + * @fires ProtoBook#change:protocols + */ +declare class ProtoBook extends Book { + /** + * The ProtoBook is responsible for keeping the known supported + * protocols of a peer. + * + * @class + * @param {PeerStore} peerStore + */ + constructor(peerStore: PeerStore); + /** + * Adds known protocols of a provided peer. + * If the peer was not known before, it will be added. + * + * @param {PeerId} peerId + * @param {string[]} protocols + * @returns {ProtoBook} + */ + add(peerId: PeerId, protocols: string[]): ProtoBook; + /** + * Removes known protocols of a provided peer. + * If the protocols did not exist before, nothing will be done. + * + * @param {PeerId} peerId + * @param {string[]} protocols + * @returns {ProtoBook} + */ + remove(peerId: PeerId, protocols: string[]): ProtoBook; +} +declare namespace ProtoBook { + export { PeerStore }; +} +import Book = require("./book"); +import PeerId = require("peer-id"); +type PeerStore = import('./'); +//# sourceMappingURL=proto-book.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-store/proto-book.d.ts.map b/dist/src/peer-store/proto-book.d.ts.map new file mode 100644 index 00000000..5d8097d4 --- /dev/null +++ b/dist/src/peer-store/proto-book.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"proto-book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/proto-book.js"],"names":[],"mappings":";AAeA;;GAEG;AAEH;;;;GAIG;AACH;IACE;;;;;;OAMG;IACH,uBAFW,SAAS,EAoBnB;IA6CD;;;;;;;OAOG;IACH,YAJW,MAAM,aACN,MAAM,EAAE,GACN,SAAS,CA2BrB;IAED;;;;;;;OAOG;IACH,eAJW,MAAM,aACN,MAAM,EAAE,GACN,SAAS,CA+BrB;CACF;;;;;;iBAxJY,OAAO,IAAI,CAAC"} \ No newline at end of file diff --git a/dist/src/ping/constants.d.ts b/dist/src/ping/constants.d.ts new file mode 100644 index 00000000..7b1061e7 --- /dev/null +++ b/dist/src/ping/constants.d.ts @@ -0,0 +1,3 @@ +export const PROTOCOL: string; +export const PING_LENGTH: number; +//# sourceMappingURL=constants.d.ts.map \ No newline at end of file diff --git a/dist/src/ping/constants.d.ts.map b/dist/src/ping/constants.d.ts.map new file mode 100644 index 00000000..8d847176 --- /dev/null +++ b/dist/src/ping/constants.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/ping/constants.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/ping/index.d.ts b/dist/src/ping/index.d.ts new file mode 100644 index 00000000..05dbf0cc --- /dev/null +++ b/dist/src/ping/index.d.ts @@ -0,0 +1,35 @@ +export = ping; +/** + * @typedef {import('../')} Libp2p + * @typedef {import('multiaddr').Multiaddr} Multiaddr + * @typedef {import('peer-id')} PeerId + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + */ +/** + * Ping a given peer and wait for its response, getting the operation latency. + * + * @param {Libp2p} node + * @param {PeerId|Multiaddr} peer + * @returns {Promise} + */ +declare function ping(node: Libp2p, peer: PeerId | Multiaddr): Promise; +declare namespace ping { + export { mount, unmount, Libp2p, Multiaddr, PeerId, MuxedStream }; +} +type Libp2p = import('../'); +type PeerId = import('peer-id'); +type Multiaddr = import('multiaddr').Multiaddr; +/** + * Subscribe ping protocol handler. + * + * @param {Libp2p} node + */ +declare function mount(node: Libp2p): void; +/** + * Unsubscribe ping protocol handler. + * + * @param {Libp2p} node + */ +declare function unmount(node: Libp2p): void; +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/ping/index.d.ts.map b/dist/src/ping/index.d.ts.map new file mode 100644 index 00000000..930ecbd0 --- /dev/null +++ b/dist/src/ping/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.js"],"names":[],"mappings":";AAiBA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,4BAJW,MAAM,QACN,MAAM,GAAC,SAAS,GACd,QAAQ,MAAM,CAAC,CA0B3B;;;;cArCY,OAAO,KAAK,CAAC;cAEb,OAAO,SAAS,CAAC;iBADjB,OAAO,WAAW,EAAE,SAAS;AAsC1C;;;;GAIG;AACH,6BAFW,MAAM,QAIhB;AAED;;;;GAIG;AACH,+BAFW,MAAM,QAIhB;mBApDY,OAAO,0CAA0C,EAAE,WAAW"} \ No newline at end of file diff --git a/dist/src/ping/util.d.ts b/dist/src/ping/util.d.ts new file mode 100644 index 00000000..f5d87504 --- /dev/null +++ b/dist/src/ping/util.d.ts @@ -0,0 +1,5 @@ +/** + * @param {number} length + */ +export function rnd(length: number): Uint8Array; +//# sourceMappingURL=util.d.ts.map \ No newline at end of file diff --git a/dist/src/ping/util.d.ts.map b/dist/src/ping/util.d.ts.map new file mode 100644 index 00000000..4ffc8a83 --- /dev/null +++ b/dist/src/ping/util.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/ping/util.js"],"names":[],"mappings":"AAKA;;GAEG;AACH,4BAFW,MAAM,cAOhB"} \ No newline at end of file diff --git a/dist/src/pnet/crypto.d.ts b/dist/src/pnet/crypto.d.ts new file mode 100644 index 00000000..4ea254f5 --- /dev/null +++ b/dist/src/pnet/crypto.d.ts @@ -0,0 +1,8 @@ +export function createBoxStream(nonce: Uint8Array, psk: Uint8Array): any; +export function createUnboxStream(nonce: Uint8Array, psk: Uint8Array): any; +export function decodeV1PSK(pskBuffer: Uint8Array): { + tag?: string; + codecName?: string; + psk: Uint8Array; +}; +//# sourceMappingURL=crypto.d.ts.map \ No newline at end of file diff --git a/dist/src/pnet/crypto.d.ts.map b/dist/src/pnet/crypto.d.ts.map new file mode 100644 index 00000000..328d7c69 --- /dev/null +++ b/dist/src/pnet/crypto.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/pnet/crypto.js"],"names":[],"mappings":"AAsBiC,uCAJtB,UAAU,OACV,UAAU,OAWpB;AASkC,yCAJxB,UAAU,OACV,UAAU,OAYpB;AAS4B,uCAJlB,UAAU,GAER;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,CA4BjE"} \ No newline at end of file diff --git a/dist/src/pnet/errors.d.ts b/dist/src/pnet/errors.d.ts new file mode 100644 index 00000000..e59b966e --- /dev/null +++ b/dist/src/pnet/errors.d.ts @@ -0,0 +1,6 @@ +export var INVALID_PEER: string; +export var INVALID_PSK: string; +export var NO_LOCAL_ID: string; +export var NO_HANDSHAKE_CONNECTION: string; +export var STREAM_ENDED: string; +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/src/pnet/errors.d.ts.map b/dist/src/pnet/errors.d.ts.map new file mode 100644 index 00000000..9db10ede --- /dev/null +++ b/dist/src/pnet/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/pnet/errors.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/pnet/index.d.ts b/dist/src/pnet/index.d.ts new file mode 100644 index 00000000..45852e71 --- /dev/null +++ b/dist/src/pnet/index.d.ts @@ -0,0 +1,32 @@ +export = Protector; +/** + * @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection + */ +declare class Protector { + /** + * Takes a Private Shared Key (psk) and provides a `protect` method + * for wrapping existing connections in a private encryption stream. + * + * @param {Uint8Array} keyBuffer - The private shared key buffer + * @class + */ + constructor(keyBuffer: Uint8Array); + psk: Uint8Array; + tag: string | undefined; + /** + * Takes a given Connection and creates a private encryption stream + * between its two peers from the PSK the Protector instance was + * created with. + * + * @param {MultiaddrConnection} connection - The connection to protect + * @returns {Promise} A protected duplex iterable + */ + protect(connection: MultiaddrConnection): Promise; +} +declare namespace Protector { + export { Errors as errors, generate, MultiaddrConnection }; +} +type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection; +import Errors = require("./errors"); +declare var generate: typeof import("./key-generator"); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/pnet/index.d.ts.map b/dist/src/pnet/index.d.ts.map new file mode 100644 index 00000000..d64b1f69 --- /dev/null +++ b/dist/src/pnet/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.js"],"names":[],"mappings":";AAwBA;;GAEG;AAEH;IACE;;;;;;OAMG;IACH,uBAHW,UAAU,EAOpB;IAFC,gBAAyB;IACzB,wBAAyB;IAG3B;;;;;;;OAOG;IACH,oBAHW,mBAAmB,GACjB,QAAQ,mBAAmB,CAAC,CAgCxC;CACF;;;;2BAxDY,OAAO,uCAAuC,EAAE,mBAAmB"} \ No newline at end of file diff --git a/dist/src/pnet/key-generator.d.ts b/dist/src/pnet/key-generator.d.ts new file mode 100644 index 00000000..52d57ceb --- /dev/null +++ b/dist/src/pnet/key-generator.d.ts @@ -0,0 +1,14 @@ +export = generate; +/** + * Generates a PSK that can be used in a libp2p-pnet private network + * + * @param {Uint8Array} bytes - An object to write the psk into + * @returns {void} + */ +declare function generate(bytes: Uint8Array): void; +declare namespace generate { + export { NONCE_LENGTH, KEY_LENGTH }; +} +declare var NONCE_LENGTH: number; +declare const KEY_LENGTH: 32; +//# sourceMappingURL=key-generator.d.ts.map \ No newline at end of file diff --git a/dist/src/pnet/key-generator.d.ts.map b/dist/src/pnet/key-generator.d.ts.map new file mode 100644 index 00000000..7410c852 --- /dev/null +++ b/dist/src/pnet/key-generator.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.js"],"names":[],"mappings":";AAOA;;;;;GAKG;AACH,iCAHW,UAAU,GACR,IAAI,CAOhB;;;;;AAfD,6BAAqB"} \ No newline at end of file diff --git a/dist/src/pubsub-adapter.d.ts b/dist/src/pubsub-adapter.d.ts new file mode 100644 index 00000000..0443d402 --- /dev/null +++ b/dist/src/pubsub-adapter.d.ts @@ -0,0 +1,22 @@ +export = pubsubAdapter; +/** + * @typedef {import('libp2p-interfaces/src/pubsub').InMessage} InMessage + * @typedef {import('libp2p-interfaces/src/pubsub')} PubsubRouter + */ +/** + * @param {{new(...args: any[]): PubsubRouter}} PubsubRouter + * @param {import('.')} libp2p + * @param {{ enabled: boolean; } & import(".").PubsubLocalOptions & import("libp2p-interfaces/src/pubsub").PubsubOptions} options + */ +declare function pubsubAdapter(PubsubRouter: new (...args: any[]) => PubsubRouter, libp2p: import('.'), options: { + enabled: boolean; +} & import(".").PubsubLocalOptions & import("libp2p-interfaces/src/pubsub").PubsubOptions): import("libp2p-interfaces/src/pubsub") & { + _subscribeAdapter: (topic: string) => void; + _unsubscribeAdapter: (topic: string) => void; +}; +declare namespace pubsubAdapter { + export { InMessage, PubsubRouter }; +} +type PubsubRouter = import('libp2p-interfaces/src/pubsub'); +type InMessage = import('libp2p-interfaces/src/pubsub').InMessage; +//# sourceMappingURL=pubsub-adapter.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub-adapter.d.ts.map b/dist/src/pubsub-adapter.d.ts.map new file mode 100644 index 00000000..56c1ebeb --- /dev/null +++ b/dist/src/pubsub-adapter.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"pubsub-adapter.d.ts","sourceRoot":"","sources":["../../src/pubsub-adapter.js"],"names":[],"mappings":";AAGA;;;GAGG;AAEH;;;;GAIG;AACH,2DAJyB,GAAG,EAAE,KAAG,YAAY,UAClC,OAAO,GAAG,CAAC,WACX;IAAE,OAAO,EAAE,OAAO,CAAC;CAAE,GAAG,OAAO,GAAG,EAAE,kBAAkB,GAAG,OAAO,8BAA8B,EAAE,aAAa;;;EA+CvH;;;;oBArDY,OAAO,8BAA8B,CAAC;iBADtC,OAAO,8BAA8B,EAAE,SAAS"} \ No newline at end of file diff --git a/dist/src/record/envelope/envelope.d.ts b/dist/src/record/envelope/envelope.d.ts new file mode 100644 index 00000000..440590c1 --- /dev/null +++ b/dist/src/record/envelope/envelope.d.ts @@ -0,0 +1,77 @@ +import * as $protobuf from "protobufjs"; +/** Properties of an Envelope. */ +export interface IEnvelope { + + /** Envelope publicKey */ + publicKey?: (Uint8Array|null); + + /** Envelope payloadType */ + payloadType?: (Uint8Array|null); + + /** Envelope payload */ + payload?: (Uint8Array|null); + + /** Envelope signature */ + signature?: (Uint8Array|null); +} + +/** Represents an Envelope. */ +export class Envelope implements IEnvelope { + + /** + * Constructs a new Envelope. + * @param [p] Properties to set + */ + constructor(p?: IEnvelope); + + /** Envelope publicKey. */ + public publicKey: Uint8Array; + + /** Envelope payloadType. */ + public payloadType: Uint8Array; + + /** Envelope payload. */ + public payload: Uint8Array; + + /** Envelope signature. */ + public signature: Uint8Array; + + /** + * Encodes the specified Envelope message. Does not implicitly {@link Envelope.verify|verify} messages. + * @param m Envelope message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IEnvelope, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an Envelope message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Envelope + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Envelope; + + /** + * Creates an Envelope message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Envelope + */ + public static fromObject(d: { [k: string]: any }): Envelope; + + /** + * Creates a plain object from an Envelope message. Also converts values to other types if specified. + * @param m Envelope + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: Envelope, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Envelope to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} diff --git a/dist/src/record/envelope/index.d.ts b/dist/src/record/envelope/index.d.ts new file mode 100644 index 00000000..3ee67005 --- /dev/null +++ b/dist/src/record/envelope/index.d.ts @@ -0,0 +1,57 @@ +export = Envelope; +/** + * @typedef {import('libp2p-interfaces/src/record/types').Record} Record + */ +declare class Envelope { + /** + * The Envelope is responsible for keeping an arbitrary signed record + * by a libp2p peer. + * + * @class + * @param {object} params + * @param {PeerId} params.peerId + * @param {Uint8Array} params.payloadType + * @param {Uint8Array} params.payload - marshaled record + * @param {Uint8Array} params.signature - signature of the domain string :: type hint :: payload. + */ + constructor({ peerId, payloadType, payload, signature }: { + peerId: PeerId; + payloadType: Uint8Array; + payload: Uint8Array; + signature: Uint8Array; + }); + peerId: PeerId; + payloadType: Uint8Array; + payload: Uint8Array; + signature: Uint8Array; + _marshal: Uint8Array | undefined; + /** + * Marshal the envelope content. + * + * @returns {Uint8Array} + */ + marshal(): Uint8Array; + /** + * Verifies if the other Envelope is identical to this one. + * + * @param {Envelope} other + * @returns {boolean} + */ + equals(other: Envelope): boolean; + /** + * Validate envelope data signature for the given domain. + * + * @param {string} domain + * @returns {Promise} + */ + validate(domain: string): Promise; +} +declare namespace Envelope { + export { createFromProtobuf, seal, openAndCertify, Record }; +} +import PeerId = require("peer-id"); +declare function createFromProtobuf(data: Uint8Array): Promise; +declare function seal(record: Record, peerId: PeerId): Promise; +declare function openAndCertify(data: Uint8Array, domain: string): Promise; +type Record = import('libp2p-interfaces/src/record/types').Record; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/record/envelope/index.d.ts.map b/dist/src/record/envelope/index.d.ts.map new file mode 100644 index 00000000..a46e28cb --- /dev/null +++ b/dist/src/record/envelope/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/envelope/index.js"],"names":[],"mappings":";AAcA;;GAEG;AAEH;IACE;;;;;;;;;;OAUG;IACH;QAL0B,MAAM,EAArB,MAAM;QACa,WAAW,EAA9B,UAAU;QACS,OAAO,EAA1B,UAAU;QACS,SAAS,EAA5B,UAAU;OAUpB;IAPC,eAAoB;IACpB,wBAA8B;IAC9B,oBAAsB;IACtB,sBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAiBtB;IAED;;;;;OAKG;IACH,cAHW,QAAQ,GACN,OAAO,CAOnB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAM5B;CACF;;;;;AAwC6B,0CAHnB,UAAU,GACR,QAAQ,QAAQ,CAAC,CAY7B;AAWe,8BAJL,MAAM,UACN,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAgB7B;AAUyB,sCAJf,UAAU,UACV,MAAM,GACJ,QAAQ,QAAQ,CAAC,CAW7B;cArKY,OAAO,oCAAoC,EAAE,MAAM"} \ No newline at end of file diff --git a/dist/src/record/peer-record/consts.d.ts b/dist/src/record/peer-record/consts.d.ts new file mode 100644 index 00000000..3ba9b13f --- /dev/null +++ b/dist/src/record/peer-record/consts.d.ts @@ -0,0 +1,5 @@ +declare const domain: multicodec.CodecName; +declare const payloadType: Uint8Array; +import multicodec = require("multicodec"); +export { domain as ENVELOPE_DOMAIN_PEER_RECORD, payloadType as ENVELOPE_PAYLOAD_TYPE_PEER_RECORD }; +//# sourceMappingURL=consts.d.ts.map \ No newline at end of file diff --git a/dist/src/record/peer-record/consts.d.ts.map b/dist/src/record/peer-record/consts.d.ts.map new file mode 100644 index 00000000..d4618c31 --- /dev/null +++ b/dist/src/record/peer-record/consts.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/consts.js"],"names":[],"mappings":"AAKA,2CAAwF;AAKxF,sCAA2C"} \ No newline at end of file diff --git a/dist/src/record/peer-record/index.d.ts b/dist/src/record/peer-record/index.d.ts new file mode 100644 index 00000000..59de9b45 --- /dev/null +++ b/dist/src/record/peer-record/index.d.ts @@ -0,0 +1,54 @@ +export = PeerRecord; +/** + * @typedef {import('../../peer-store/address-book.js').Address} Address + * @typedef {import('libp2p-interfaces/src/record/types').Record} Record + */ +/** + * @implements {Record} + */ +declare class PeerRecord implements Record { + /** + * The PeerRecord is used for distributing peer routing records across the network. + * It contains the peer's reachable listen addresses. + * + * @class + * @param {Object} params + * @param {PeerId} params.peerId + * @param {Multiaddr[]} params.multiaddrs - addresses of the associated peer. + * @param {number} [params.seqNumber] - monotonically-increasing sequence counter that's used to order PeerRecords in time. + */ + constructor({ peerId, multiaddrs, seqNumber }: { + peerId: PeerId; + multiaddrs: Multiaddr[]; + seqNumber?: number | undefined; + }); + domain: import("multicodec/src/").CodecName; + codec: Uint8Array; + peerId: PeerId; + multiaddrs: Multiaddr[]; + seqNumber: number; + _marshal: Uint8Array | undefined; + /** + * Marshal a record to be used in an envelope. + * + * @returns {Uint8Array} + */ + marshal(): Uint8Array; + /** + * Returns true if `this` record equals the `other`. + * + * @param {unknown} other + * @returns {boolean} + */ + equals(other: unknown): boolean; +} +declare namespace PeerRecord { + export { createFromProtobuf, ENVELOPE_DOMAIN_PEER_RECORD as DOMAIN, Address, Record }; +} +type Record = import('libp2p-interfaces/src/record/types').Record; +import PeerId = require("peer-id"); +import { Multiaddr } from "multiaddr"; +declare function createFromProtobuf(buf: Uint8Array): PeerRecord; +import { ENVELOPE_DOMAIN_PEER_RECORD } from "./consts"; +type Address = import('../../peer-store/address-book.js').Address; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/record/peer-record/index.d.ts.map b/dist/src/record/peer-record/index.d.ts.map new file mode 100644 index 00000000..030ce91a --- /dev/null +++ b/dist/src/record/peer-record/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,4CAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAsFhC,yCAHrB,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,kCAAkC,EAAE,OAAO"} \ No newline at end of file diff --git a/dist/src/record/peer-record/peer-record.d.ts b/dist/src/record/peer-record/peer-record.d.ts new file mode 100644 index 00000000..a851b533 --- /dev/null +++ b/dist/src/record/peer-record/peer-record.d.ts @@ -0,0 +1,133 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a PeerRecord. */ +export interface IPeerRecord { + + /** PeerRecord peerId */ + peerId?: (Uint8Array|null); + + /** PeerRecord seq */ + seq?: (number|null); + + /** PeerRecord addresses */ + addresses?: (PeerRecord.IAddressInfo[]|null); +} + +/** Represents a PeerRecord. */ +export class PeerRecord implements IPeerRecord { + + /** + * Constructs a new PeerRecord. + * @param [p] Properties to set + */ + constructor(p?: IPeerRecord); + + /** PeerRecord peerId. */ + public peerId: Uint8Array; + + /** PeerRecord seq. */ + public seq: number; + + /** PeerRecord addresses. */ + public addresses: PeerRecord.IAddressInfo[]; + + /** + * Encodes the specified PeerRecord message. Does not implicitly {@link PeerRecord.verify|verify} messages. + * @param m PeerRecord message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IPeerRecord, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a PeerRecord message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns PeerRecord + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): PeerRecord; + + /** + * Creates a PeerRecord message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns PeerRecord + */ + public static fromObject(d: { [k: string]: any }): PeerRecord; + + /** + * Creates a plain object from a PeerRecord message. Also converts values to other types if specified. + * @param m PeerRecord + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: PeerRecord, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this PeerRecord to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace PeerRecord { + + /** Properties of an AddressInfo. */ + interface IAddressInfo { + + /** AddressInfo multiaddr */ + multiaddr?: (Uint8Array|null); + } + + /** Represents an AddressInfo. */ + class AddressInfo implements IAddressInfo { + + /** + * Constructs a new AddressInfo. + * @param [p] Properties to set + */ + constructor(p?: PeerRecord.IAddressInfo); + + /** AddressInfo multiaddr. */ + public multiaddr: Uint8Array; + + /** + * Encodes the specified AddressInfo message. Does not implicitly {@link PeerRecord.AddressInfo.verify|verify} messages. + * @param m AddressInfo message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: PeerRecord.IAddressInfo, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an AddressInfo message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns AddressInfo + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): PeerRecord.AddressInfo; + + /** + * Creates an AddressInfo message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns AddressInfo + */ + public static fromObject(d: { [k: string]: any }): PeerRecord.AddressInfo; + + /** + * Creates a plain object from an AddressInfo message. Also converts values to other types if specified. + * @param m AddressInfo + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: PeerRecord.AddressInfo, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this AddressInfo to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/dist/src/record/utils.d.ts b/dist/src/record/utils.d.ts new file mode 100644 index 00000000..46680a00 --- /dev/null +++ b/dist/src/record/utils.d.ts @@ -0,0 +1,12 @@ +export type Libp2p = import('../'); +/** + * @typedef {import('../')} Libp2p + */ +/** + * Create (or update if existing) self peer record and store it in the AddressBook. + * + * @param {Libp2p} libp2p + * @returns {Promise} + */ +export function updateSelfPeerRecord(libp2p: Libp2p): Promise; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/record/utils.d.ts.map b/dist/src/record/utils.d.ts.map new file mode 100644 index 00000000..89eb669f --- /dev/null +++ b/dist/src/record/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/record/utils.js"],"names":[],"mappings":"qBAMa,OAAO,KAAK,CAAC;AAD1B;;GAEG;AAEH;;;;;GAKG;AACH,6CAHW,MAAM,GACJ,QAAQ,IAAI,CAAC,CASzB"} \ No newline at end of file diff --git a/dist/src/registrar.d.ts b/dist/src/registrar.d.ts new file mode 100644 index 00000000..23ca0ad6 --- /dev/null +++ b/dist/src/registrar.d.ts @@ -0,0 +1,82 @@ +export = Registrar; +/** + * @typedef {import('peer-id')} PeerId + * @typedef {import('./peer-store')} PeerStore + * @typedef {import('./connection-manager')} ConnectionManager + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('./').HandlerProps} HandlerProps + */ +/** + * + */ +/** + * Responsible for notifying registered protocols of events in the network. + */ +declare class Registrar { + /** + * @param {Object} props + * @param {PeerStore} props.peerStore + * @param {ConnectionManager} props.connectionManager + * @class + */ + constructor({ peerStore, connectionManager }: { + peerStore: PeerStore; + connectionManager: ConnectionManager; + }); + peerStore: import("./peer-store"); + connectionManager: import("./connection-manager"); + /** + * Map of topologies + * + * @type {Map} + */ + topologies: Map; + /** @type {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} */ + _handle: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void; + /** + * Remove a disconnected peer from the record + * + * @param {Connection} connection + * @returns {void} + */ + _onDisconnect(connection: Connection): void; + /** + * @param {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} handle + */ + set handle(arg: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void); + /** + * @returns {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} + */ + get handle(): (protocols: string[] | string, handler: (props: HandlerProps) => void) => void; + /** + * Get a connection with a peer. + * + * @param {PeerId} peerId + * @returns {Connection | null} + */ + getConnection(peerId: PeerId): Connection | null; + /** + * Register handlers for a set of multicodecs given + * + * @param {Topology} topology - protocol topology + * @returns {string} registrar identifier + */ + register(topology: Topology): string; + /** + * Unregister topology. + * + * @param {string} id - registrar identifier + * @returns {boolean} unregistered successfully + */ + unregister(id: string): boolean; +} +declare namespace Registrar { + export { PeerId, PeerStore, ConnectionManager, Connection, HandlerProps }; +} +import Topology = require("libp2p-interfaces/src/topology"); +type HandlerProps = import('./').HandlerProps; +type Connection = import("libp2p-interfaces/src/connection/connection"); +type PeerId = import('peer-id'); +type PeerStore = import('./peer-store'); +type ConnectionManager = import('./connection-manager'); +//# sourceMappingURL=registrar.d.ts.map \ No newline at end of file diff --git a/dist/src/registrar.d.ts.map b/dist/src/registrar.d.ts.map new file mode 100644 index 00000000..a7d9937f --- /dev/null +++ b/dist/src/registrar.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,kCAA0B;IAE1B,kDAA0C;IAE1C;;;;OAIG;IACH,YAFU,IAAI,MAAM,EAAE,QAAQ,CAAC,CAEJ;IAE3B,2FAA2F;IAE3F,qBAFuB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAE/D;IA+D1B;;;;;OAKG;IACH,0BAHW,UAAU,GACR,IAAI,CAMhB;IA5DD;;OAEG;IACH,4BATyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,EAWxF;IAZD;;OAEG;IACH,0BAFyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAIxF;IASD;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,UAAU,GAAG,IAAI,CAI7B;IAED;;;;;OAKG;IACH,mBAHW,QAAQ,GACN,MAAM,CAiBlB;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF;;;;;oBA1GY,OAAO,IAAI,EAAE,YAAY;;cAJzB,OAAO,SAAS,CAAC;iBACjB,OAAO,cAAc,CAAC;yBACtB,OAAO,sBAAsB,CAAC"} \ No newline at end of file diff --git a/dist/src/transport-manager.d.ts b/dist/src/transport-manager.d.ts new file mode 100644 index 00000000..2648ad09 --- /dev/null +++ b/dist/src/transport-manager.d.ts @@ -0,0 +1,120 @@ +export = TransportManager; +/** + * @typedef {import('multiaddr').Multiaddr} Multiaddr + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory + * @typedef {import('libp2p-interfaces/src/transport/types').Transport} Transport + * + * @typedef {Object} TransportManagerProperties + * @property {import('./')} libp2p + * @property {import('./upgrader')} upgrader + * + * @typedef {Object} TransportManagerOptions + * @property {number} [faultTolerance = FAULT_TOLERANCE.FATAL_ALL] - Address listen error tolerance. + */ +declare class TransportManager { + /** + * @class + * @param {TransportManagerProperties & TransportManagerOptions} options + */ + constructor({ libp2p, upgrader, faultTolerance }: TransportManagerProperties & TransportManagerOptions); + libp2p: import("./"); + upgrader: import("./upgrader"); + /** @type {Map} */ + _transports: Map>; + _listeners: Map; + _listenerOptions: Map; + faultTolerance: number; + /** + * Adds a `Transport` to the manager + * + * @param {string} key + * @param {TransportFactory} Transport + * @param {*} transportOptions - Additional options to pass to the transport + * @returns {void} + */ + add(key: string, Transport: import("libp2p-interfaces/src/transport/types").TransportFactory, transportOptions?: any): void; + /** + * Stops all listeners + * + * @async + */ + close(): Promise; + /** + * Dials the given Multiaddr over it's supported transport + * + * @param {Multiaddr} ma + * @param {*} options + * @returns {Promise} + */ + dial(ma: Multiaddr, options: any): Promise; + /** + * Returns all Multiaddr's the listeners are using + * + * @returns {Multiaddr[]} + */ + getAddrs(): Multiaddr[]; + /** + * Returns all the transports instances. + * + * @returns {IterableIterator} + */ + getTransports(): IterableIterator>; + /** + * Finds a transport that matches the given Multiaddr + * + * @param {Multiaddr} ma + * @returns {Transport|null} + */ + transportForMultiaddr(ma: Multiaddr): import("libp2p-interfaces/src/transport/types").Transport | null; + /** + * Starts listeners for each listen Multiaddr. + * + * @async + * @param {Multiaddr[]} addrs - addresses to attempt to listen on + */ + listen(addrs: Multiaddr[]): Promise; + /** + * Removes the given transport from the manager. + * If a transport has any running listeners, they will be closed. + * + * @async + * @param {string} key + */ + remove(key: string): Promise; + /** + * Removes all transports from the manager. + * If any listeners are running, they will be closed. + * + * @async + */ + removeAll(): Promise; +} +declare namespace TransportManager { + export { FAULT_TOLERANCE as FaultTolerance, Multiaddr, Connection, TransportFactory, Transport, TransportManagerProperties, TransportManagerOptions }; +} +type Multiaddr = import('multiaddr').Multiaddr; +type Connection = import("libp2p-interfaces/src/connection/connection"); +type TransportManagerProperties = { + libp2p: import('./'); + upgrader: import('./upgrader'); +}; +type TransportManagerOptions = { + /** + * - Address listen error tolerance. + */ + faultTolerance?: number | undefined; +}; +/** + * Enum Transport Manager Fault Tolerance values. + * FATAL_ALL should be used for failing in any listen circumstance. + * NO_FATAL should be used for not failing when not listening. + */ +type FAULT_TOLERANCE = number; +declare namespace FAULT_TOLERANCE { + const FATAL_ALL: number; + const NO_FATAL: number; +} +type TransportFactory = import('libp2p-interfaces/src/transport/types').TransportFactory; +type Transport = import('libp2p-interfaces/src/transport/types').Transport; +//# sourceMappingURL=transport-manager.d.ts.map \ No newline at end of file diff --git a/dist/src/transport-manager.d.ts.map b/dist/src/transport-manager.d.ts.map new file mode 100644 index 00000000..90a67317 --- /dev/null +++ b/dist/src/transport-manager.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;GAYG;AAEH;IACE;;;OAGG;IACH,kDAFW,0BAA0B,GAAG,uBAAuB,EAU9D;IAPC,qBAAoB;IACpB,+BAAwB;IACxB,qCAAqC;IACrC,aADW,IAAI,MAAM,sEAAY,CACL;IAC5B,0BAA2B;IAC3B,gCAAiC;IACjC,uBAAoC;IAGtC;;;;;;;OAOG;IACH,SALW,MAAM,kHAGJ,IAAI,CAsBhB;IAED;;;;OAIG;IACH,uBAiBC;IAED;;;;;;OAMG;IACH,SAJW,SAAS,iBAEP,QAAQ,UAAU,CAAC,CAc/B;IAED;;;;OAIG;IACH,YAFa,SAAS,EAAE,CAWvB;IAED;;;;OAIG;IACH,iBAFa,qFAA2B,CAIvC;IAED;;;;;OAKG;IACH,0BAHW,SAAS,GACP,sEAAU,IAAI,CAQ1B;IAED;;;;;OAKG;IACH,cAFW,SAAS,EAAE,iBAqDrB;IAED;;;;;;OAMG;IACH,YAFW,MAAM,iBAehB;IAED;;;;;OAKG;IACH,2BAOC;CACF;;;;iBA7OY,OAAO,WAAW,EAAE,SAAS;;;YAM5B,OAAO,IAAI,CAAC;cACZ,OAAO,YAAY,CAAC;;;;;;;;;;;;;uBA8OxB,MAAM;;;;;wBAnPH,OAAO,uCAAuC,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC;iBAC1E,OAAO,uCAAuC,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC"} \ No newline at end of file diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts new file mode 100644 index 00000000..2bfc0461 --- /dev/null +++ b/dist/src/types.d.ts @@ -0,0 +1,18 @@ +export interface EventEmitterFactory { + new(): EventEmitter; +} + +export interface EventEmitter { + addListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + on(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + once(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + removeListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + off(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; + removeAllListeners(event?: string | symbol): EventEmitter; + setMaxListeners(n: number): EventEmitter; + getMaxListeners(): number; + listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types + rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types + emit(event: string | symbol, ...args: any[]): boolean; + listenerCount(event: string | symbol): number; +} diff --git a/dist/src/upgrader.d.ts b/dist/src/upgrader.d.ts new file mode 100644 index 00000000..eb65f196 --- /dev/null +++ b/dist/src/upgrader.d.ts @@ -0,0 +1,151 @@ +export = Upgrader; +/** + * @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').Muxer} Muxer + * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto + * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection + * @typedef {import('multiaddr').Multiaddr} Multiaddr + */ +/** + * @typedef CryptoResult + * @property {MultiaddrConnection} conn A duplex iterable + * @property {PeerId} remotePeer + * @property {string} protocol + */ +declare class Upgrader { + /** + * @param {object} options + * @param {PeerId} options.localPeer + * @param {import('./metrics')} [options.metrics] + * @param {Map} [options.cryptos] + * @param {Map} [options.muxers] + * @param {(connection: Connection) => void} options.onConnection - Called when a connection is upgraded + * @param {(connection: Connection) => void} options.onConnectionEnd + */ + constructor({ localPeer, metrics, cryptos, muxers, onConnectionEnd, onConnection }: { + localPeer: PeerId; + metrics?: import("./metrics") | undefined; + cryptos?: Map | undefined; + muxers?: Map | undefined; + onConnection: (connection: Connection) => void; + onConnectionEnd: (connection: Connection) => void; + }); + localPeer: PeerId; + metrics: import("./metrics") | undefined; + cryptos: Map; + muxers: Map; + /** @type {import("./pnet") | null} */ + protector: import("./pnet") | null; + protocols: Map; + onConnection: (connection: Connection) => void; + onConnectionEnd: (connection: Connection) => void; + /** + * Upgrades an inbound connection + * + * @async + * @param {MultiaddrConnection} maConn + * @returns {Promise} + */ + upgradeInbound(maConn: MultiaddrConnection): Promise; + /** + * Upgrades an outbound connection + * + * @async + * @param {MultiaddrConnection} maConn + * @returns {Promise} + */ + upgradeOutbound(maConn: MultiaddrConnection): Promise; + /** + * A convenience method for generating a new `Connection` + * + * @private + * @param {object} options + * @param {string} options.cryptoProtocol - The crypto protocol that was negotiated + * @param {'inbound' | 'outbound'} options.direction - One of ['inbound', 'outbound'] + * @param {MultiaddrConnection} options.maConn - The transport layer connection + * @param {MuxedStream | MultiaddrConnection} options.upgradedConn - A duplex connection returned from multiplexer and/or crypto selection + * @param {MuxerFactory} [options.Muxer] - The muxer to be used for muxing + * @param {PeerId} options.remotePeer - The peer the connection is with + * @returns {Connection} + */ + private _createConnection; + /** + * Routes incoming streams to the correct handler + * + * @private + * @param {object} options + * @param {Connection} options.connection - The connection the stream belongs to + * @param {MuxedStream} options.stream + * @param {string} options.protocol + */ + private _onStream; + /** + * Attempts to encrypt the incoming `connection` with the provided `cryptos`. + * + * @private + * @async + * @param {PeerId} localPeer - The initiators PeerId + * @param {*} connection + * @param {Map} cryptos + * @returns {Promise} An encrypted connection, remote peer `PeerId` and the protocol of the `Crypto` used + */ + private _encryptInbound; + /** + * Attempts to encrypt the given `connection` with the provided `cryptos`. + * The first `Crypto` module to succeed will be used + * + * @private + * @async + * @param {PeerId} localPeer - The initiators PeerId + * @param {MultiaddrConnection} connection + * @param {PeerId} remotePeerId + * @param {Map} cryptos + * @returns {Promise} An encrypted connection, remote peer `PeerId` and the protocol of the `Crypto` used + */ + private _encryptOutbound; + /** + * Selects one of the given muxers via multistream-select. That + * muxer will be used for all future streams on the connection. + * + * @private + * @async + * @param {MultiaddrConnection} connection - A basic duplex connection to multiplex + * @param {Map} muxers - The muxers to attempt multiplexing with + * @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection + */ + private _multiplexOutbound; + /** + * Registers support for one of the given muxers via multistream-select. The + * selected muxer will be used for all future streams on the connection. + * + * @private + * @async + * @param {MultiaddrConnection} connection - A basic duplex connection to multiplex + * @param {Map} muxers - The muxers to attempt multiplexing with + * @returns {Promise<{ stream: MuxedStream, Muxer?: MuxerFactory}>} A muxed connection + */ + private _multiplexInbound; +} +declare namespace Upgrader { + export { MultiaddrConnection, MuxerFactory, Muxer, MuxedStream, Crypto, Connection, Multiaddr, CryptoResult }; +} +import PeerId = require("peer-id"); +import { Connection } from "libp2p-interfaces/src/connection"; +type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection; +type MuxerFactory = import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory; +type Muxer = import('libp2p-interfaces/src/stream-muxer/types').Muxer; +type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream; +type Crypto = import('libp2p-interfaces/src/crypto/types').Crypto; +type Connection = import("libp2p-interfaces/src/connection/connection"); +type Multiaddr = import('multiaddr').Multiaddr; +type CryptoResult = { + /** + * A duplex iterable + */ + conn: MultiaddrConnection; + remotePeer: PeerId; + protocol: string; +}; +//# sourceMappingURL=upgrader.d.ts.map \ No newline at end of file diff --git a/dist/src/upgrader.d.ts.map b/dist/src/upgrader.d.ts.map new file mode 100644 index 00000000..f5a88e8d --- /dev/null +++ b/dist/src/upgrader.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,0BA8GC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;OASG;IACH,2BAYC;IAED;;;;;;;;;OASG;IACH,0BAWC;CACF;;;;;;2BAzbY,OAAO,uCAAuC,EAAE,mBAAmB;oBACnE,OAAO,0CAA0C,EAAE,YAAY;aAC/D,OAAO,0CAA0C,EAAE,KAAK;mBACxD,OAAO,0CAA0C,EAAE,WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;;iBAEnD,OAAO,WAAW,EAAE,SAAS;;;;;UAK5B,mBAAmB;gBACnB,MAAM;cACN,MAAM"} \ No newline at end of file diff --git a/examples/libp2p-in-the-browser/dist/index.fd532818.js b/examples/libp2p-in-the-browser/dist/index.fd532818.js new file mode 100644 index 00000000..bdf72a16 --- /dev/null +++ b/examples/libp2p-in-the-browser/dist/index.fd532818.js @@ -0,0 +1,214066 @@ +// modules are defined as an array +// [ module function, map of requires ] +// +// map of requires is short require name -> numeric require +// +// anything defined in a previous bundle is accessed via the +// orig method which is the require for previous bundles + +(function(modules, entry, mainEntry, parcelRequireName, globalName) { + /* eslint-disable no-undef */ + var globalObject = + typeof globalThis !== 'undefined' + ? globalThis + : typeof self !== 'undefined' + ? self + : typeof window !== 'undefined' + ? window + : typeof global !== 'undefined' + ? global + : {}; + /* eslint-enable no-undef */ + + // Save the require from previous bundle to this closure if any + var previousRequire = + typeof globalObject[parcelRequireName] === 'function' && + globalObject[parcelRequireName]; + + var cache = previousRequire.cache || {}; + // Do not use `require` to prevent Webpack from trying to bundle this call + var nodeRequire = + typeof module !== 'undefined' && + typeof module.require === 'function' && + module.require.bind(module); + + function newRequire(name, jumped) { + if (!cache[name]) { + if (!modules[name]) { + // if we cannot find the module within our internal map or + // cache jump to the current global require ie. the last bundle + // that was added to the page. + var currentRequire = + typeof globalObject[parcelRequireName] === 'function' && + globalObject[parcelRequireName]; + if (!jumped && currentRequire) { + return currentRequire(name, true); + } + + // If there are other bundles on this page the require from the + // previous one is saved to 'previousRequire'. Repeat this as + // many times as there are bundles until the module is found or + // we exhaust the require chain. + if (previousRequire) { + return previousRequire(name, true); + } + + // Try the node require function if it exists. + if (nodeRequire && typeof name === 'string') { + return nodeRequire(name); + } + + var err = new Error("Cannot find module '" + name + "'"); + err.code = 'MODULE_NOT_FOUND'; + throw err; + } + + localRequire.resolve = resolve; + localRequire.cache = {}; + + var module = (cache[name] = new newRequire.Module(name)); + + modules[name][0].call( + module.exports, + localRequire, + module, + module.exports, + this + ); + } + + return cache[name].exports; + + function localRequire(x) { + return newRequire(localRequire.resolve(x)); + } + + function resolve(x) { + return modules[name][1][x] || x; + } + } + + function Module(moduleName) { + this.id = moduleName; + this.bundle = newRequire; + this.exports = {}; + } + + newRequire.isParcelRequire = true; + newRequire.Module = Module; + newRequire.modules = modules; + newRequire.cache = cache; + newRequire.parent = previousRequire; + newRequire.register = function(id, exports) { + modules[id] = [ + function(require, module) { + module.exports = exports; + }, + {}, + ]; + }; + + Object.defineProperty(newRequire, 'root', { + get: function() { + return globalObject[parcelRequireName]; + }, + }); + + globalObject[parcelRequireName] = newRequire; + + for (var i = 0; i < entry.length; i++) { + newRequire(entry[i]); + } + + if (mainEntry) { + // Expose entry point to Node, AMD or browser globals + // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js + var mainExports = newRequire(mainEntry); + + // CommonJS + if (typeof exports === 'object' && typeof module !== 'undefined') { + module.exports = mainExports; + + // RequireJS + } else if (typeof define === 'function' && define.amd) { + define(function() { + return mainExports; + }); + + // + + + + \ No newline at end of file diff --git a/examples/webrtc-direct/dist/dialer.58c9dcfc.js b/examples/webrtc-direct/dist/dialer.58c9dcfc.js new file mode 100644 index 00000000..80c5a11f --- /dev/null +++ b/examples/webrtc-direct/dist/dialer.58c9dcfc.js @@ -0,0 +1,2093 @@ +parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c0?r:o)(t)}; +},{}],"HdKs":[function(require,module,exports) { +var e=require("./_to-integer"),r=Math.min;module.exports=function(t){return t>0?r(e(t),9007199254740991):0}; +},{"./_to-integer":"cHfm"}],"AXg2":[function(require,module,exports) { +var e=require("./_to-integer"),r=Math.max,t=Math.min;module.exports=function(n,a){return(n=e(n))<0?r(n+a,0):t(n,a)}; +},{"./_to-integer":"cHfm"}],"/dIP":[function(require,module,exports) { +var e=require("./_to-iobject"),r=require("./_to-length"),t=require("./_to-absolute-index");module.exports=function(n){return function(i,o,u){var f,l=e(i),a=r(l.length),c=t(u,a);if(n&&o!=o){for(;a>c;)if((f=l[c++])!=f)return!0}else for(;a>c;c++)if((n||c in l)&&l[c]===o)return n||c||0;return!n&&-1}}; +},{"./_to-iobject":"mwRI","./_to-length":"HdKs","./_to-absolute-index":"AXg2"}],"xSc0":[function(require,module,exports) { +var e=require("./_shared")("keys"),r=require("./_uid");module.exports=function(u){return e[u]||(e[u]=r(u))}; +},{"./_shared":"8sTG","./_uid":"f0sk"}],"UrZ8":[function(require,module,exports) { +var r=require("./_has"),e=require("./_to-iobject"),u=require("./_array-includes")(!1),i=require("./_shared-key")("IE_PROTO");module.exports=function(o,a){var n,s=e(o),t=0,h=[];for(n in s)n!=i&&r(s,n)&&h.push(n);for(;a.length>t;)r(s,n=a[t++])&&(~u(h,n)||h.push(n));return h}; +},{"./_has":"nW2g","./_to-iobject":"mwRI","./_array-includes":"/dIP","./_shared-key":"xSc0"}],"t611":[function(require,module,exports) { +module.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(","); +},{}],"kfVX":[function(require,module,exports) { +var e=require("./_object-keys-internal"),r=require("./_enum-bug-keys");module.exports=Object.keys||function(u){return e(u,r)}; +},{"./_object-keys-internal":"UrZ8","./_enum-bug-keys":"t611"}],"JErC":[function(require,module,exports) { +exports.f=Object.getOwnPropertySymbols; +},{}],"Blc0":[function(require,module,exports) { +exports.f={}.propertyIsEnumerable; +},{}],"wCtS":[function(require,module,exports) { +var e=require("./_object-keys"),r=require("./_object-gops"),o=require("./_object-pie");module.exports=function(t){var u=e(t),i=r.f;if(i)for(var c,f=i(t),a=o.f,l=0;f.length>l;)a.call(t,c=f[l++])&&u.push(c);return u}; +},{"./_object-keys":"kfVX","./_object-gops":"JErC","./_object-pie":"Blc0"}],"Osm+":[function(require,module,exports) { +var r=require("./_cof");module.exports=Array.isArray||function(e){return"Array"==r(e)}; +},{"./_cof":"viv7"}],"4JfJ":[function(require,module,exports) { +var e=require("./_defined");module.exports=function(r){return Object(e(r))}; +},{"./_defined":"Zcur"}],"Vixs":[function(require,module,exports) { +var e=require("./_object-dp"),r=require("./_an-object"),t=require("./_object-keys");module.exports=require("./_descriptors")?Object.defineProperties:function(o,i){r(o);for(var u,c=t(i),n=c.length,s=0;n>s;)e.f(o,u=c[s++],i[u]);return o}; +},{"./_object-dp":"/+wv","./_an-object":"DBsB","./_object-keys":"kfVX","./_descriptors":"ZJLI"}],"DBa9":[function(require,module,exports) { +var e=require("./_global").document;module.exports=e&&e.documentElement; +},{"./_global":"kql1"}],"d4Ek":[function(require,module,exports) { +var e=require("./_an-object"),r=require("./_object-dps"),t=require("./_enum-bug-keys"),n=require("./_shared-key")("IE_PROTO"),o=function(){},i="prototype",u=function(){var e,r=require("./_dom-create")("iframe"),n=t.length;for(r.style.display="none",require("./_html").appendChild(r),r.src="javascript:",(e=r.contentWindow.document).open(),e.write(" + + diff --git a/examples/webrtc-direct/dist/lib.aae26b51.cjs b/examples/webrtc-direct/dist/lib.aae26b51.cjs new file mode 100644 index 00000000..e2553da3 --- /dev/null +++ b/examples/webrtc-direct/dist/lib.aae26b51.cjs @@ -0,0 +1,7 @@ +"use strict" + +exports.TextEncoder = + typeof TextEncoder !== "undefined" ? TextEncoder : require("util").TextEncoder + +exports.TextDecoder = + typeof TextDecoder !== "undefined" ? TextDecoder : require("util").TextDecoder diff --git a/examples/webrtc-direct/dist/lib.fbbb5318.cjs b/examples/webrtc-direct/dist/lib.fbbb5318.cjs new file mode 100644 index 00000000..e2553da3 --- /dev/null +++ b/examples/webrtc-direct/dist/lib.fbbb5318.cjs @@ -0,0 +1,7 @@ +"use strict" + +exports.TextEncoder = + typeof TextEncoder !== "undefined" ? TextEncoder : require("util").TextEncoder + +exports.TextDecoder = + typeof TextDecoder !== "undefined" ? TextDecoder : require("util").TextDecoder diff --git a/src/content-routing/index.js b/src/content-routing/index.js index 44f1d9c5..00211f71 100644 --- a/src/content-routing/index.js +++ b/src/content-routing/index.js @@ -16,7 +16,7 @@ const { pipe } = require('it-pipe') * @typedef {import('peer-id')} PeerId * @typedef {import('multiaddr').Multiaddr} Multiaddr * @typedef {import('cids')} CID - * @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule + * @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule */ /** diff --git a/src/index.js b/src/index.js index d8eb517d..592e7785 100644 --- a/src/index.js +++ b/src/index.js @@ -42,9 +42,9 @@ const { updateSelfPeerRecord } = require('./record/utils') * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream * @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory * @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory - * @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule - * @typedef {import('libp2p-interfaces/src/peer-discovery/types')} PeerDiscoveryModule - * @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule + * @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule + * @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscoveryFactory} PeerDiscoveryFactory + * @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule * @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto * @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub * @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions @@ -102,7 +102,7 @@ const { updateSelfPeerRecord } = require('./record/utils') * @property {TransportFactory[]} transport * @property {MuxerFactory[]} streamMuxer * @property {Crypto[]} connEncryption - * @property {PeerDiscoveryModule[]} [peerDiscovery] + * @property {PeerDiscoveryFactory[]} [peerDiscovery] * @property {PeerRoutingModule[]} [peerRouting] * @property {ContentRoutingModule[]} [contentRouting] * @property {Object} [dht] @@ -716,7 +716,7 @@ class Libp2p extends EventEmitter { */ async _setupPeerDiscovery () { /** - * @param {PeerDiscoveryModule} DiscoveryService + * @param {PeerDiscoveryFactory} DiscoveryService */ const setupService = (DiscoveryService) => { let config = { diff --git a/src/peer-routing.js b/src/peer-routing.js index e2809361..0ff6f7b8 100644 --- a/src/peer-routing.js +++ b/src/peer-routing.js @@ -25,7 +25,7 @@ const { /** * @typedef {import('peer-id')} PeerId * @typedef {import('multiaddr').Multiaddr} Multiaddr - * @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule + * @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule */ /**