libp2p 0.41.0-19e96cc → 0.41.0-3e53c19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,10 @@ import type { PeerId } from '@libp2p/interface-peer-id'
7
7
  import type { TransportManager } from '@libp2p/interface-transport'
8
8
 
9
9
  export interface AddressManagerInit {
10
+ /**
11
+ * Pass an function in this field to override the list of addresses
12
+ * that are announced to the network
13
+ */
10
14
  announceFilter?: AddressFilter
11
15
 
12
16
  /**
@@ -30,6 +34,10 @@ export interface DefaultAddressManagerComponents {
30
34
  transportManager: TransportManager
31
35
  }
32
36
 
37
+ /**
38
+ * A function that takes a list of multiaddrs and returns a list
39
+ * to announce
40
+ */
33
41
  export interface AddressFilter {
34
42
  (addrs: Multiaddr[]): Multiaddr[]
35
43
  }
@@ -12,12 +12,24 @@ import {
12
12
  } from './constants.js'
13
13
  import type { AddressSorter, PeerStore } from '@libp2p/interface-peer-store'
14
14
  import type { Startable } from '@libp2p/interfaces/startable'
15
- import type { RelayConfig } from '../index.js'
16
15
  import type { ContentRouting } from '@libp2p/interface-content-routing'
17
16
  import type { ConnectionManager } from '@libp2p/interface-connection-manager'
18
17
  import type { TransportManager } from '@libp2p/interface-transport'
19
18
  import type { PeerId } from '@libp2p/interface-peer-id'
20
19
 
20
+ export interface RelayConfig {
21
+ enabled: boolean
22
+ advertise: RelayAdvertiseConfig
23
+ hop: HopConfig
24
+ autoRelay: AutoRelayConfig
25
+ }
26
+
27
+ export interface HopConfig {
28
+ enabled?: boolean
29
+ active?: boolean
30
+ timeout: number
31
+ }
32
+
21
33
  const log = logger('libp2p:relay')
22
34
 
23
35
  export interface RelayAdvertiseConfig {
@@ -17,7 +17,7 @@ import type { AbortOptions } from '@libp2p/interfaces'
17
17
  import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
18
18
  import type { Listener, Transport, CreateListenerOptions, ConnectionHandler } from '@libp2p/interface-transport'
19
19
  import type { Connection } from '@libp2p/interface-connection'
20
- import type { RelayConfig } from '../index.js'
20
+ import type { RelayConfig } from './index.js'
21
21
  import { abortableDuplex } from 'abortable-iterator'
22
22
  import { TimeoutController } from 'timeout-abort-controller'
23
23
  import { setMaxListeners } from 'events'
package/src/config.ts CHANGED
@@ -31,7 +31,15 @@ const DefaultConfig: Partial<Libp2pInit> = {
31
31
  resolvers: {
32
32
  dnsaddr: dnsaddrResolver
33
33
  },
34
- addressSorter: publicAddressesFirst
34
+ addressSorter: publicAddressesFirst,
35
+ maxEventLoopDelay: Infinity,
36
+ pollInterval: Infinity,
37
+ maxAddrsToDial: Infinity,
38
+ startupReconnectTimeout: Infinity,
39
+ allow: [],
40
+ deny: [],
41
+ maxIncomingPendingConnections: Infinity,
42
+ inboundConnectionThreshold: Infinity
35
43
  },
36
44
  connectionGater: {},
37
45
  transportManager: {
@@ -42,7 +50,8 @@ const DefaultConfig: Partial<Libp2pInit> = {
42
50
  enabled: true,
43
51
  interval: 6e5,
44
52
  bootDelay: 10e3
45
- }
53
+ },
54
+ routers: []
46
55
  },
47
56
  nat: {
48
57
  enabled: true,
@@ -11,8 +11,8 @@ import { setMaxListeners } from 'events'
11
11
  import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
12
12
  import type { ConnectionManager, ConnectionManagerEvents, Dialer } from '@libp2p/interface-connection-manager'
13
13
  import * as STATUS from '@libp2p/interface-connection/status'
14
- import type { PeerStore } from '@libp2p/interface-peer-store'
15
- import { isMultiaddr, multiaddr, Multiaddr } from '@multiformats/multiaddr'
14
+ import type { AddressSorter, PeerStore } from '@libp2p/interface-peer-store'
15
+ import { isMultiaddr, multiaddr, Multiaddr, Resolver } from '@multiformats/multiaddr'
16
16
  import { PeerMap } from '@libp2p/peer-collections'
17
17
  import { TimeoutController } from 'timeout-abort-controller'
18
18
  import { KEEP_ALIVE } from '@libp2p/interface-peer-store/tags'
@@ -20,10 +20,109 @@ import { RateLimiterMemory } from 'rate-limiter-flexible'
20
20
  import type { Metrics } from '@libp2p/interface-metrics'
21
21
  import type { Upgrader } from '@libp2p/interface-transport'
22
22
  import { getPeer } from '../get-peer.js'
23
- import type { ConnectionManagerConfig } from '../index.js'
24
23
 
25
24
  const log = logger('libp2p:connection-manager')
26
25
 
26
+ export interface ConnectionManagerConfig {
27
+ /**
28
+ * The maximum number of connections libp2p is willing to have before it starts disconnecting. Defaults to `Infinity`
29
+ */
30
+ maxConnections: number
31
+
32
+ /**
33
+ * The minimum number of connections below which libp2p not activate preemptive disconnections. Defaults to `0`.
34
+ */
35
+ minConnections: number
36
+
37
+ /**
38
+ * Sets the maximum event loop delay (measured in milliseconds) this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.
39
+ */
40
+ maxEventLoopDelay?: number
41
+
42
+ /**
43
+ * Sets the poll interval (in milliseconds) for assessing the current state and determining if this peer needs to force a disconnect. Defaults to `2000` (2 seconds).
44
+ */
45
+ pollInterval?: number
46
+
47
+ /**
48
+ * If true, try to connect to all discovered peers up to the connection manager limit
49
+ */
50
+ autoDial?: boolean
51
+
52
+ /**
53
+ * How long to wait between attempting to keep our number of concurrent connections
54
+ * above minConnections
55
+ */
56
+ autoDialInterval: number
57
+
58
+ /**
59
+ * Sort the known addresses of a peer before trying to dial
60
+ */
61
+ addressSorter?: AddressSorter
62
+
63
+ /**
64
+ * Number of max concurrent dials
65
+ */
66
+ maxParallelDials?: number
67
+
68
+ /**
69
+ * Number of max addresses to dial for a given peer
70
+ */
71
+ maxAddrsToDial?: number
72
+
73
+ /**
74
+ * How long a dial attempt is allowed to take, including DNS resolution
75
+ * of the multiaddr, opening a socket and upgrading it to a Connection.
76
+ */
77
+ dialTimeout?: number
78
+
79
+ /**
80
+ * When a new inbound connection is opened, the upgrade process (e.g. protect,
81
+ * encrypt, multiplex etc) must complete within this number of ms.
82
+ */
83
+ inboundUpgradeTimeout: number
84
+
85
+ /**
86
+ * Number of max concurrent dials per peer
87
+ */
88
+ maxDialsPerPeer?: number
89
+
90
+ /**
91
+ * Multiaddr resolvers to use when dialing
92
+ */
93
+ resolvers?: Record<string, Resolver>
94
+
95
+ /**
96
+ * On startup we try to dial any peer that has previously been
97
+ * tagged with KEEP_ALIVE up to this timeout in ms. (default: 60000)
98
+ */
99
+ startupReconnectTimeout?: number
100
+
101
+ /**
102
+ * A list of multiaddrs that will always be allowed (except if they are in the
103
+ * deny list) to open connections to this node even if we've reached maxConnections
104
+ */
105
+ allow?: string[]
106
+
107
+ /**
108
+ * A list of multiaddrs that will never be allowed to open connections to
109
+ * this node under any circumstances
110
+ */
111
+ deny?: string[]
112
+
113
+ /**
114
+ * If more than this many connections are opened per second by a single
115
+ * host, reject subsequent connections
116
+ */
117
+ inboundConnectionThreshold?: number
118
+
119
+ /**
120
+ * The maximum number of parallel incoming connections allowed that have yet to
121
+ * complete the connection upgrade - e.g. choosing connection encryption, muxer, etc
122
+ */
123
+ maxIncomingPendingConnections?: number
124
+ }
125
+
27
126
  const defaultOptions: Partial<ConnectionManagerConfig> = {
28
127
  maxConnections: Infinity,
29
128
  minConnections: 0,
package/src/index.ts CHANGED
@@ -16,14 +16,13 @@
16
16
 
17
17
  import { createLibp2pNode } from './libp2p.js'
18
18
  import type { RecursivePartial } from '@libp2p/interfaces'
19
- import type { Multiaddr, Resolver } from '@multiformats/multiaddr'
20
- import type { FaultTolerance } from './transport-manager.js'
19
+ import type { TransportManagerInit } from './transport-manager.js'
21
20
  import type { IdentifyServiceInit } from './identify/index.js'
22
21
  import type { DualDHT } from '@libp2p/interface-dht'
23
22
  import type { Datastore } from 'interface-datastore'
24
- import type { AddressSorter, PeerStoreInit } from '@libp2p/interface-peer-store'
23
+ import type { PeerStoreInit } from '@libp2p/interface-peer-store'
25
24
  import type { PeerId } from '@libp2p/interface-peer-id'
26
- import type { AutoRelayConfig, RelayAdvertiseConfig } from './circuit/index.js'
25
+ import type { RelayConfig } from './circuit/index.js'
27
26
  import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
28
27
  import type { ConnectionGater, ConnectionProtector } from '@libp2p/interface-connection'
29
28
  import type { Transport } from '@libp2p/interface-transport'
@@ -38,175 +37,11 @@ import type { PingServiceInit } from './ping/index.js'
38
37
  import type { FetchServiceInit } from './fetch/index.js'
39
38
  import type { Components } from './components.js'
40
39
  import type { Libp2p } from '@libp2p/interface-libp2p'
41
-
42
- export interface PersistentPeerStoreOptions {
43
- threshold?: number
44
- }
45
-
46
- export interface DEKConfig {
47
- keyLength: number
48
- iterationCount: number
49
- salt: string
50
- hash: string
51
- }
52
-
53
- export interface KeychainConfig {
54
- pass?: string
55
- dek?: DEKConfig
56
- }
57
-
58
- export interface MetricsConfig {
59
- enabled?: boolean
60
- }
61
-
62
- export interface HopConfig {
63
- enabled?: boolean
64
- active?: boolean
65
- timeout: number
66
- }
67
-
68
- export interface RelayConfig {
69
- enabled: boolean
70
- advertise: RelayAdvertiseConfig
71
- hop: HopConfig
72
- autoRelay: AutoRelayConfig
73
- }
74
-
75
- export interface NatManagerConfig {
76
- enabled: boolean
77
- externalAddress?: string
78
- localAddress?: string
79
- description?: string
80
- ttl?: number
81
- keepAlive: boolean
82
- gateway?: string
83
- }
84
-
85
- export interface AddressesConfig {
86
- listen: string[]
87
- announce: string[]
88
- noAnnounce: string[]
89
- announceFilter: (multiaddrs: Multiaddr[]) => Multiaddr[]
90
- }
91
-
92
- export interface TransportManagerConfig {
93
- faultTolerance?: FaultTolerance
94
- }
95
-
96
- export interface PeerStoreConfig {
97
- persistence?: boolean
98
- threshold?: number
99
- }
100
-
101
- export interface PeerRoutingConfig {
102
- refreshManager: RefreshManagerConfig
103
- }
104
-
105
- export interface RefreshManagerConfig {
106
- enabled?: boolean
107
- interval: number
108
- bootDelay: number
109
- }
110
-
111
- export interface ConnectionManagerConfig {
112
- /**
113
- * The maximum number of connections libp2p is willing to have before it starts disconnecting. Defaults to `Infinity`
114
- */
115
- maxConnections: number
116
-
117
- /**
118
- * The minimum number of connections below which libp2p not activate preemptive disconnections. Defaults to `0`.
119
- */
120
- minConnections: number
121
-
122
- /**
123
- * Sets the maximum event loop delay (measured in milliseconds) this node is willing to endure before it starts disconnecting peers. Defaults to `Infinity`.
124
- */
125
- maxEventLoopDelay?: number
126
-
127
- /**
128
- * Sets the poll interval (in milliseconds) for assessing the current state and determining if this peer needs to force a disconnect. Defaults to `2000` (2 seconds).
129
- */
130
- pollInterval?: number
131
-
132
- /**
133
- * If true, try to connect to all discovered peers up to the connection manager limit
134
- */
135
- autoDial?: boolean
136
-
137
- /**
138
- * How long to wait between attempting to keep our number of concurrent connections
139
- * above minConnections
140
- */
141
- autoDialInterval: number
142
-
143
- /**
144
- * Sort the known addresses of a peer before trying to dial
145
- */
146
- addressSorter?: AddressSorter
147
-
148
- /**
149
- * Number of max concurrent dials
150
- */
151
- maxParallelDials?: number
152
-
153
- /**
154
- * Number of max addresses to dial for a given peer
155
- */
156
- maxAddrsToDial?: number
157
-
158
- /**
159
- * How long a dial attempt is allowed to take, including DNS resolution
160
- * of the multiaddr, opening a socket and upgrading it to a Connection.
161
- */
162
- dialTimeout?: number
163
-
164
- /**
165
- * When a new inbound connection is opened, the upgrade process (e.g. protect,
166
- * encrypt, multiplex etc) must complete within this number of ms.
167
- */
168
- inboundUpgradeTimeout: number
169
-
170
- /**
171
- * Number of max concurrent dials per peer
172
- */
173
- maxDialsPerPeer?: number
174
-
175
- /**
176
- * Multiaddr resolvers to use when dialing
177
- */
178
- resolvers?: Record<string, Resolver>
179
-
180
- /**
181
- * On startup we try to dial any peer that has previously been
182
- * tagged with KEEP_ALIVE up to this timeout in ms. (default: 60000)
183
- */
184
- startupReconnectTimeout?: number
185
-
186
- /**
187
- * A list of multiaddrs that will always be allowed (except if they are in the
188
- * deny list) to open connections to this node even if we've reached maxConnections
189
- */
190
- allow?: string[]
191
-
192
- /**
193
- * A list of multiaddrs that will never be allowed to open connections to
194
- * this node under any circumstances
195
- */
196
- deny?: string[]
197
-
198
- /**
199
- * If more than this many connections are opened per second by a single
200
- * host, reject subsequent connections
201
- */
202
- inboundConnectionThreshold?: number
203
-
204
- /**
205
- * The maximum number of parallel incoming connections allowed that have yet to
206
- * complete the connection upgrade - e.g. choosing connection encryption, muxer, etc
207
- */
208
- maxIncomingPendingConnections?: number
209
- }
40
+ import type { KeyChainInit } from './keychain/index.js'
41
+ import type { NatManagerInit } from './nat-manager.js'
42
+ import type { AddressManagerInit } from './address-manager/index.js'
43
+ import type { PeerRoutingInit } from './peer-routing.js'
44
+ import type { ConnectionManagerInit } from './connection-manager/index.js'
210
45
 
211
46
  /**
212
47
  * For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
@@ -220,18 +55,22 @@ export interface Libp2pInit {
220
55
  /**
221
56
  * Addresses for transport listening and to advertise to the network
222
57
  */
223
- addresses: AddressesConfig
58
+ addresses: AddressManagerInit
224
59
 
225
60
  /**
226
61
  * libp2p Connection Manager configuration
227
62
  */
228
- connectionManager: ConnectionManagerConfig
63
+ connectionManager: ConnectionManagerInit
64
+
65
+ /**
66
+ * A connection gater can deny new connections based on user criteria
67
+ */
229
68
  connectionGater: Partial<ConnectionGater>
230
69
 
231
70
  /**
232
71
  * libp2p transport manager configuration
233
72
  */
234
- transportManager: TransportManagerConfig
73
+ transportManager: TransportManagerInit
235
74
 
236
75
  /**
237
76
  * An optional datastore to persist peer information, DHT records, etc.
@@ -248,13 +87,22 @@ export interface Libp2pInit {
248
87
  /**
249
88
  * libp2p Peer routing service configuration
250
89
  */
251
- peerRouting: PeerRoutingConfig
90
+ peerRouting: PeerRoutingInit
252
91
 
253
92
  /**
254
93
  * keychain configuration
255
94
  */
256
- keychain: KeychainConfig
257
- nat: NatManagerConfig
95
+ keychain: KeyChainInit
96
+
97
+ /**
98
+ * The NAT manager controls uPNP hole punching
99
+ */
100
+ nat: NatManagerInit
101
+
102
+ /**
103
+ * If configured as a relay this node will relay certain
104
+ * types of traffic for other peers
105
+ */
258
106
  relay: RelayConfig
259
107
 
260
108
  /**
@@ -17,7 +17,7 @@ import type { Datastore } from 'interface-datastore'
17
17
 
18
18
  const log = logger('libp2p:keychain')
19
19
 
20
- export interface DekOptions {
20
+ export interface DEKConfig {
21
21
  hash: string
22
22
  salt: string
23
23
  iterationCount: number
@@ -26,7 +26,7 @@ export interface DekOptions {
26
26
 
27
27
  export interface KeyChainInit {
28
28
  pass?: string
29
- dek?: DekOptions
29
+ dek?: DEKConfig
30
30
  }
31
31
 
32
32
  /**
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '0.41.0-19e96cc'
1
+ export const version = '0.41.0-3e53c19'
2
2
  export const name = 'libp2p'