This repository was archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.ts
79 lines (70 loc) · 2.03 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
import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { AbortOptions } from '@libp2p/interfaces'
import type { PeerMap } from '@libp2p/peer-collections'
import type { Multiaddr } from '@multiformats/multiaddr'
export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'
export interface PendingDial {
id: string
status: PendingDialStatus
peerId?: PeerId
multiaddrs: Multiaddr[]
}
export interface ConnectionManager {
/**
* Return connections, optionally filtering by a PeerId
*
* @example
*
* ```js
* const connections = libp2p.connectionManager.get(peerId)
* // []
* ```
*/
getConnections: (peerId?: PeerId) => Connection[]
/**
* Return a map of all connections with their associated PeerIds
*
* @example
*
* ```js
* const connectionsMap = libp2p.connectionManager.getConnectionsMap()
* ```
*/
getConnectionsMap: () => PeerMap<Connection[]>
/**
* Open a connection to a remote peer
*
* @example
*
* ```js
* const connection = await libp2p.connectionManager.openConnection(peerId)
* ```
*/
openConnection: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise<Connection>
/**
* Close our connections to a peer
*/
closeConnections: (peer: PeerId) => 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
*
* ```js
* const dials = libp2p.connectionManager.getDialQueue()
* ```
*/
getDialQueue: () => PendingDial[]
}