@libp2p/topology
Advanced tools
+2
-27
@@ -1,28 +0,3 @@ | ||
| import type { PeerId } from '@libp2p/interfaces/peer-id'; | ||
| import type { TopologyOptions, onConnectHandler, onDisconnectHandler } from '@libp2p/interfaces/topology'; | ||
| import type { Registrar } from '@libp2p/interfaces/registrar'; | ||
| declare const topologySymbol: unique symbol; | ||
| export declare class Topology { | ||
| min: number; | ||
| max: number; | ||
| /** | ||
| * Set of peers that support the protocol | ||
| */ | ||
| peers: Set<string>; | ||
| onConnect: onConnectHandler; | ||
| onDisconnect: onDisconnectHandler; | ||
| protected _registrar: Registrar | undefined; | ||
| constructor(options: TopologyOptions); | ||
| get [Symbol.toStringTag](): string; | ||
| get [topologySymbol](): boolean; | ||
| /** | ||
| * Checks if the given value is a Topology instance | ||
| */ | ||
| static isTopology(other: any): other is Topology; | ||
| /** | ||
| * Notify about peer disconnected event | ||
| */ | ||
| disconnect(peerId: PeerId): void; | ||
| } | ||
| export {}; | ||
| import type { Topology, TopologyInit } from '@libp2p/interfaces/topology'; | ||
| export declare function createTopology(init: TopologyInit): Topology; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACzG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAG7D,QAAA,MAAM,cAAc,eAAiC,CAAA;AAErD,qBAAa,QAAQ;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAElB;;OAEG;IACI,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAClB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,YAAY,EAAE,mBAAmB,CAAA;IAExC,SAAS,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,CAAA;gBAE9B,OAAO,EAAE,eAAe;IASrC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,IAAI,CAAC,cAAc,CAAC,YAEnB;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAE,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,QAAQ;IAIjD;;OAEG;IACH,UAAU,CAAE,MAAM,EAAE,MAAM;CAG3B"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAyC,MAAM,6BAA6B,CAAA;AA2ChH,wBAAgB,cAAc,CAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAE5D"} |
+12
-15
@@ -0,24 +1,18 @@ | ||
| import { symbol } from '@libp2p/interfaces/topology'; | ||
| const noop = () => { }; | ||
| const topologySymbol = Symbol.for('@libp2p/topology'); | ||
| export class Topology { | ||
| constructor(options) { | ||
| this.min = options.min ?? 0; | ||
| this.max = options.max ?? Infinity; | ||
| class TopologyImpl { | ||
| constructor(init) { | ||
| this.min = init.min ?? 0; | ||
| this.max = init.max ?? Infinity; | ||
| this.peers = new Set(); | ||
| this.onConnect = options.onConnect ?? noop; | ||
| this.onDisconnect = options.onDisconnect ?? noop; | ||
| this.onConnect = init.onConnect ?? noop; | ||
| this.onDisconnect = init.onDisconnect ?? noop; | ||
| } | ||
| get [Symbol.toStringTag]() { | ||
| return topologySymbol.toString(); | ||
| return symbol.toString(); | ||
| } | ||
| get [topologySymbol]() { | ||
| get [symbol]() { | ||
| return true; | ||
| } | ||
| /** | ||
| * Checks if the given value is a Topology instance | ||
| */ | ||
| static isTopology(other) { | ||
| return topologySymbol in other; | ||
| } | ||
| /** | ||
| * Notify about peer disconnected event | ||
@@ -30,2 +24,5 @@ */ | ||
| } | ||
| export function createTopology(init) { | ||
| return new TopologyImpl(init); | ||
| } | ||
| //# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AACrB,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AAErD,MAAM,OAAO,QAAQ;IAanB,YAAa,OAAwB;QACnC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;QAC3B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,QAAQ,CAAA;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAA;QAEtB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAA;QAC1C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAA;IAClD,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,cAAc,CAAC,QAAQ,EAAE,CAAA;IAClC,CAAC;IAED,IAAI,CAAC,cAAc,CAAC;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAE,KAAU;QAC3B,OAAO,cAAc,IAAI,KAAK,CAAA;IAChC,CAAC;IAED;;OAEG;IACH,UAAU,CAAE,MAAc;QACxB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;CACF"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAKpD,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAA;AAErB,MAAM,YAAY;IAahB,YAAa,IAAkB;QAC7B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACxB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAA;QAC/B,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAA;QAEtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAA;QACvC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAA;IAC/C,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;IAC1B,CAAC;IAED,IAAI,CAAC,MAAM,CAAC;QACV,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,UAAU,CAAE,MAAc;QACxB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,IAAkB;IAChD,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,CAAA;AAC/B,CAAC"} |
+3
-3
| { | ||
| "name": "@libp2p/topology", | ||
| "version": "1.1.4", | ||
| "version": "1.1.5", | ||
| "description": "libp2p network topology", | ||
@@ -149,4 +149,4 @@ "license": "Apache-2.0 OR MIT", | ||
| "dependencies": { | ||
| "@libp2p/interfaces": "^1.3.6", | ||
| "@libp2p/logger": "^1.0.3", | ||
| "@libp2p/interfaces": "^1.3.12", | ||
| "@libp2p/logger": "^1.1.0", | ||
| "@multiformats/multiaddr": "^10.1.5", | ||
@@ -153,0 +153,0 @@ "err-code": "^3.0.1", |
+2
-4
@@ -18,7 +18,5 @@ # libp2p-topology <!-- omit in toc --> | ||
| ```javascript | ||
| import { Topology } from '@libp2p/topology' | ||
| import { MulticodecTopology } from '@libp2p/topology/multicodec-topology' | ||
| import { createTopology } from '@libp2p/topology' | ||
| const topology = new Topology({ ... }) | ||
| const multicodecTopology = new MulticodecTopology({ ... }) | ||
| const topology = createTopology({ ... }) | ||
| ``` | ||
@@ -25,0 +23,0 @@ |
+14
-17
@@ -0,9 +1,9 @@ | ||
| import { symbol } from '@libp2p/interfaces/topology' | ||
| import type { PeerId } from '@libp2p/interfaces/peer-id' | ||
| import type { TopologyOptions, onConnectHandler, onDisconnectHandler } from '@libp2p/interfaces/topology' | ||
| import type { Topology, TopologyInit, onConnectHandler, onDisconnectHandler } from '@libp2p/interfaces/topology' | ||
| import type { Registrar } from '@libp2p/interfaces/registrar' | ||
| const noop = () => {} | ||
| const topologySymbol = Symbol.for('@libp2p/topology') | ||
| export class Topology { | ||
| class TopologyImpl implements Topology { | ||
| public min: number | ||
@@ -21,16 +21,16 @@ public max: number | ||
| constructor (options: TopologyOptions) { | ||
| this.min = options.min ?? 0 | ||
| this.max = options.max ?? Infinity | ||
| constructor (init: TopologyInit) { | ||
| this.min = init.min ?? 0 | ||
| this.max = init.max ?? Infinity | ||
| this.peers = new Set() | ||
| this.onConnect = options.onConnect ?? noop | ||
| this.onDisconnect = options.onDisconnect ?? noop | ||
| this.onConnect = init.onConnect ?? noop | ||
| this.onDisconnect = init.onDisconnect ?? noop | ||
| } | ||
| get [Symbol.toStringTag] () { | ||
| return topologySymbol.toString() | ||
| return symbol.toString() | ||
| } | ||
| get [topologySymbol] () { | ||
| get [symbol] () { | ||
| return true | ||
@@ -40,9 +40,2 @@ } | ||
| /** | ||
| * Checks if the given value is a Topology instance | ||
| */ | ||
| static isTopology (other: any): other is Topology { | ||
| return topologySymbol in other | ||
| } | ||
| /** | ||
| * Notify about peer disconnected event | ||
@@ -54,1 +47,5 @@ */ | ||
| } | ||
| export function createTopology (init: TopologyInit): Topology { | ||
| return new TopologyImpl(init) | ||
| } |
7991
-16.72%66
-31.96%34
-5.56%Updated
Updated