-
Notifications
You must be signed in to change notification settings - Fork 443
/
index.ts
95 lines (85 loc) · 2.85 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type { AbortOptions, PendingDial, Connection, MultiaddrConnection, PeerId, IsDialableOptions, OpenConnectionProgressEvents } from '@libp2p/interface'
import type { PeerMap } from '@libp2p/peer-collections'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { ProgressOptions } from 'progress-events'
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
/**
* Connection requests with a higher priority will be executed before those
* with a lower priority. (default: 50)
*/
priority?: number
/**
* When opening a connection to a remote peer, if a connection already exists
* it will be returned instead of creating a new connection. Pass true here
* to override that and dial a new connection anyway. (default: false)
*/
force?: boolean
}
export interface ConnectionManager {
/**
* Return connections, optionally filtering by a PeerId
*
* @example
*
* ```TypeScript
* const connections = libp2p.connectionManager.get(peerId)
* // []
* ```
*/
getConnections(peerId?: PeerId): Connection[]
/**
* Return a map of all connections with their associated PeerIds
*
* @example
*
* ```TypeScript
* const connectionsMap = libp2p.connectionManager.getConnectionsMap()
* ```
*/
getConnectionsMap(): PeerMap<Connection[]>
/**
* Open a connection to a remote peer
*
* @example
*
* ```TypeScript
* const connection = await libp2p.connectionManager.openConnection(peerId)
* ```
*/
openConnection(peer: PeerId | Multiaddr | Multiaddr[], options?: OpenConnectionOptions): Promise<Connection>
/**
* Close our connections to a peer
*/
closeConnections(peer: PeerId, options?: AbortOptions): Promise<void>
/**
* Invoked after an incoming connection is opened but before PeerIds are
* exchanged, this lets the ConnectionManager check we have sufficient
* resources to accept the connection in which case it will return true,
* otherwise it will return false.
*/
acceptIncomingConnection(maConn: MultiaddrConnection): Promise<boolean>
/**
* Invoked after upgrading a multiaddr connection has finished
*/
afterUpgradeInbound(): void
/**
* Return the list of in-progress or queued dials
*
* @example
*
* ```TypeScript
* const dials = libp2p.connectionManager.getDialQueue()
* ```
*/
getDialQueue(): PendingDial[]
/**
* Given the current node configuration, returns a promise of `true` or
* `false` if the node would attempt to dial the passed multiaddr.
*
* This means a relevant transport is configured, and the connection gater
* would not block the dial attempt.
*
* This may involve resolving DNS addresses so you should pass an AbortSignal.
*/
isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>
}