@libp2p/topology
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -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 |
@@ -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 |
{ | ||
"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", |
@@ -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 @@ |
@@ -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) | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
7991
66
34
Updated@libp2p/interfaces@^1.3.12
Updated@libp2p/logger@^1.1.0