-
Notifications
You must be signed in to change notification settings - Fork 436
/
index.ts
48 lines (43 loc) · 1.23 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { Connection } from '../connection/index.js'
import type { PeerId } from '../peer-id/index.js'
/**
* A topology filter
*
* @see https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerFilter-1.html
*/
export interface TopologyFilter {
has (peerId: PeerId): boolean
add (peerId: PeerId): void
remove (peerId: PeerId): void
}
/**
* A topology is a network overlay that contains a subset of peers in the
* complete network.
*
* It is a way to be notified when peers that support a given protocol connect
* to or disconnect from the current node.
*/
export interface Topology {
/**
* An optional filter can prevent duplicate topology notifications for the
* same peer.
*/
filter?: TopologyFilter
/**
* If true, invoke `onConnect` for this topology on transient (e.g. short-lived
* and/or data-limited) connections
*
* @default false
*/
notifyOnTransient?: boolean
/**
* Invoked when a new connection is opened to a peer that supports the
* registered protocol
*/
onConnect?(peerId: PeerId, conn: Connection): void
/**
* Invoked when the last connection to a peer that supports the registered
* protocol closes
*/
onDisconnect?(peerId: PeerId): void
}