libp2p 0.44.0 → 0.45.0
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.
- package/dist/index.min.js +30 -30
- package/dist/src/address-manager/index.d.ts +8 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +37 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/utils.d.ts +2 -0
- package/dist/src/address-manager/utils.d.ts.map +1 -0
- package/dist/src/address-manager/utils.js +12 -0
- package/dist/src/address-manager/utils.js.map +1 -0
- package/dist/src/autonat/constants.d.ts +16 -2
- package/dist/src/autonat/constants.d.ts.map +1 -1
- package/dist/src/autonat/constants.js +16 -2
- package/dist/src/autonat/constants.js.map +1 -1
- package/dist/src/autonat/index.d.ts +12 -33
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +36 -30
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/advert-service.js +2 -2
- package/dist/src/circuit-relay/server/advert-service.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +10 -3
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +4 -2
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts +3 -0
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +6 -4
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +30 -26
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +5 -4
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +37 -30
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/components.d.ts +6 -63
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -164
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -62
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -0
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +36 -13
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +4 -0
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +23 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +2 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +36 -14
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +8 -7
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +23 -34
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +7 -42
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +3 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +7 -9
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/identify.d.ts +53 -0
- package/dist/src/identify/identify.d.ts.map +1 -0
- package/dist/src/identify/identify.js +405 -0
- package/dist/src/identify/identify.js.map +1 -0
- package/dist/src/identify/index.d.ts +12 -58
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +5 -388
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +13 -68
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +11 -42
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +137 -196
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -2
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +27 -25
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +11 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +19 -10
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +15 -10
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +39 -48
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/typedoc-urls.json +25 -10
- package/package.json +61 -45
- package/src/address-manager/index.ts +50 -8
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/constants.ts +17 -2
- package/src/autonat/index.ts +53 -45
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +11 -3
- package/src/circuit-relay/transport/discovery.ts +5 -3
- package/src/circuit-relay/transport/index.ts +9 -4
- package/src/circuit-relay/transport/listener.ts +38 -28
- package/src/circuit-relay/transport/reservation-store.ts +34 -20
- package/src/components.ts +71 -234
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -64
- package/src/connection-manager/auto-dial.ts +44 -15
- package/src/connection-manager/connection-pruner.ts +28 -8
- package/src/connection-manager/dial-queue.ts +41 -21
- package/src/connection-manager/index.ts +31 -43
- package/src/content-routing/index.ts +7 -55
- package/src/content-routing/utils.ts +3 -1
- package/src/fetch/index.ts +51 -14
- package/src/identify/identify.ts +518 -0
- package/src/identify/index.ts +17 -507
- package/src/index.ts +14 -77
- package/src/insecure/index.ts +4 -4
- package/src/libp2p.ts +139 -260
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +27 -13
- package/src/upgrader.ts +62 -58
- package/src/{nat-manager.ts → upnp-nat/index.ts} +16 -17
- package/src/version.ts +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/dist/src/peer-record-updater.d.ts +0 -24
- package/dist/src/peer-record-updater.d.ts.map +0 -1
- package/dist/src/peer-record-updater.js +0 -44
- package/dist/src/peer-record-updater.js.map +0 -1
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
- package/src/peer-record-updater.ts +0 -65
package/src/index.ts
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
import { createLibp2pNode } from './libp2p.js'
|
|
18
18
|
import type { RecursivePartial } from '@libp2p/interfaces'
|
|
19
19
|
import type { TransportManagerInit } from './transport-manager.js'
|
|
20
|
-
import type { IdentifyServiceInit } from './identify/index.js'
|
|
21
|
-
import type { DualDHT } from '@libp2p/interface-dht'
|
|
22
20
|
import type { Datastore } from 'interface-datastore'
|
|
23
|
-
import type { PeerStoreInit } from '@libp2p/interface-peer-store'
|
|
24
21
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
25
22
|
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery'
|
|
26
23
|
import type { ConnectionProtector } from '@libp2p/interface-connection'
|
|
@@ -30,25 +27,22 @@ import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
|
|
|
30
27
|
import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter'
|
|
31
28
|
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
32
29
|
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
33
|
-
import type { PubSub } from '@libp2p/interface-pubsub'
|
|
34
30
|
import type { Metrics } from '@libp2p/interface-metrics'
|
|
35
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
36
|
-
import type { PingServiceInit } from './ping/index.js'
|
|
37
|
-
import type { FetchServiceInit } from './fetch/index.js'
|
|
38
|
-
import type { AutonatServiceInit } from './autonat/index.js'
|
|
39
31
|
import type { Components } from './components.js'
|
|
40
|
-
import type { Libp2p } from '@libp2p/interface-libp2p'
|
|
32
|
+
import type { Libp2p, ServiceMap } from '@libp2p/interface-libp2p'
|
|
41
33
|
import type { KeyChainInit } from '@libp2p/keychain'
|
|
42
|
-
import type { NatManagerInit } from './nat-manager.js'
|
|
43
34
|
import type { AddressManagerInit } from './address-manager/index.js'
|
|
44
|
-
import type { PeerRoutingInit } from './peer-routing.js'
|
|
45
35
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
46
|
-
import type {
|
|
36
|
+
import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
|
|
37
|
+
|
|
38
|
+
export type ServiceFactoryMap<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
39
|
+
[Property in keyof T]: (components: Components) => T[Property]
|
|
40
|
+
}
|
|
47
41
|
|
|
48
42
|
/**
|
|
49
43
|
* For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
|
50
44
|
*/
|
|
51
|
-
export interface Libp2pInit {
|
|
45
|
+
export interface Libp2pInit<T extends ServiceMap = {}> {
|
|
52
46
|
/**
|
|
53
47
|
* peerId instance (it will be created if not provided)
|
|
54
48
|
*/
|
|
@@ -84,49 +78,13 @@ export interface Libp2pInit {
|
|
|
84
78
|
/**
|
|
85
79
|
* libp2p PeerStore configuration
|
|
86
80
|
*/
|
|
87
|
-
peerStore:
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* libp2p Peer routing service configuration
|
|
91
|
-
*/
|
|
92
|
-
peerRouting: PeerRoutingInit
|
|
81
|
+
peerStore: PersistentPeerStoreInit
|
|
93
82
|
|
|
94
83
|
/**
|
|
95
84
|
* keychain configuration
|
|
96
85
|
*/
|
|
97
86
|
keychain: KeyChainInit
|
|
98
87
|
|
|
99
|
-
/**
|
|
100
|
-
* The NAT manager controls uPNP hole punching
|
|
101
|
-
*/
|
|
102
|
-
nat: NatManagerInit
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* If configured as a relay this node will relay certain
|
|
106
|
-
* types of traffic for other peers
|
|
107
|
-
*/
|
|
108
|
-
relay: (components: Components) => CircuitRelayService
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* identify protocol options
|
|
112
|
-
*/
|
|
113
|
-
identify: IdentifyServiceInit
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* ping protocol options
|
|
117
|
-
*/
|
|
118
|
-
ping: PingServiceInit
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* fetch protocol options
|
|
122
|
-
*/
|
|
123
|
-
fetch: FetchServiceInit
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* autonat protocol options
|
|
127
|
-
*/
|
|
128
|
-
autonat: AutonatServiceInit
|
|
129
|
-
|
|
130
88
|
/**
|
|
131
89
|
* An array that must include at least 1 compliant transport
|
|
132
90
|
*/
|
|
@@ -137,47 +95,25 @@ export interface Libp2pInit {
|
|
|
137
95
|
peerRouters?: Array<(components: Components) => PeerRouting>
|
|
138
96
|
contentRouters?: Array<(components: Components) => ContentRouting>
|
|
139
97
|
|
|
140
|
-
/**
|
|
141
|
-
* Pass a DHT implementation to enable DHT operations
|
|
142
|
-
*/
|
|
143
|
-
dht?: (components: Components) => DualDHT
|
|
144
|
-
|
|
145
98
|
/**
|
|
146
99
|
* A Metrics implementation can be supplied to collect metrics on this node
|
|
147
100
|
*/
|
|
148
101
|
metrics?: (components: Components) => Metrics
|
|
149
102
|
|
|
150
|
-
/**
|
|
151
|
-
* If a PubSub implmentation is supplied, PubSub operations will become available
|
|
152
|
-
*/
|
|
153
|
-
pubsub?: (components: Components) => PubSub
|
|
154
|
-
|
|
155
103
|
/**
|
|
156
104
|
* A ConnectionProtector can be used to create a secure overlay on top of the network using pre-shared keys
|
|
157
105
|
*/
|
|
158
106
|
connectionProtector?: (components: Components) => ConnectionProtector
|
|
159
|
-
}
|
|
160
107
|
|
|
161
|
-
/**
|
|
162
|
-
* Once you have a libp2p instance, you can listen to several events it emits, so that you can be notified of relevant network events.
|
|
163
|
-
*/
|
|
164
|
-
export interface Libp2pEvents {
|
|
165
108
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* ```js
|
|
169
|
-
* libp2p.addEventListener('peer:discovery', (event) => {
|
|
170
|
-
* const peerInfo = event.detail
|
|
171
|
-
* // ...
|
|
172
|
-
* })
|
|
173
|
-
* ```
|
|
109
|
+
* Arbitrary libp2p modules
|
|
174
110
|
*/
|
|
175
|
-
|
|
111
|
+
services: ServiceFactoryMap<T>
|
|
176
112
|
}
|
|
177
113
|
|
|
178
114
|
export type { Libp2p }
|
|
179
115
|
|
|
180
|
-
export type Libp2pOptions = RecursivePartial<Libp2pInit
|
|
116
|
+
export type Libp2pOptions<T extends ServiceMap = {}> = RecursivePartial<Libp2pInit<T>> & { start?: boolean }
|
|
181
117
|
|
|
182
118
|
/**
|
|
183
119
|
* Returns a new instance of the Libp2p interface, generating a new PeerId
|
|
@@ -192,11 +128,12 @@ export type Libp2pOptions = RecursivePartial<Libp2pInit> & { start?: boolean }
|
|
|
192
128
|
* import { tcp } from '@libp2p/tcp'
|
|
193
129
|
* import { mplex } from '@libp2p/mplex'
|
|
194
130
|
* import { noise } from '@chainsafe/libp2p-noise'
|
|
131
|
+
* import { yamux } from '@chainsafe/libp2p-yamux'
|
|
195
132
|
*
|
|
196
133
|
* // specify options
|
|
197
134
|
* const options = {
|
|
198
135
|
* transports: [tcp()],
|
|
199
|
-
* streamMuxers: [mplex()],
|
|
136
|
+
* streamMuxers: [yamux(), mplex()],
|
|
200
137
|
* connectionEncryption: [noise()]
|
|
201
138
|
* }
|
|
202
139
|
*
|
|
@@ -204,7 +141,7 @@ export type Libp2pOptions = RecursivePartial<Libp2pInit> & { start?: boolean }
|
|
|
204
141
|
* const libp2p = await createLibp2p(options)
|
|
205
142
|
* ```
|
|
206
143
|
*/
|
|
207
|
-
export async function createLibp2p (options: Libp2pOptions): Promise<Libp2p
|
|
144
|
+
export async function createLibp2p <T extends ServiceMap = {}> (options: Libp2pOptions<T>): Promise<Libp2p<T>> {
|
|
208
145
|
const node = await createLibp2pNode(options)
|
|
209
146
|
|
|
210
147
|
if (options.start !== false) {
|
package/src/insecure/index.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { Exchange, KeyType } from './pb/proto.js'
|
|
|
30
30
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
31
31
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
32
32
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
33
|
-
import type { Duplex } from 'it-stream-types'
|
|
33
|
+
import type { Duplex, Source } from 'it-stream-types'
|
|
34
34
|
import map from 'it-map'
|
|
35
35
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
36
36
|
|
|
@@ -46,7 +46,7 @@ function lpEncodeExchange (exchange: Exchange): Uint8ArrayList {
|
|
|
46
46
|
/**
|
|
47
47
|
* Encrypt connection
|
|
48
48
|
*/
|
|
49
|
-
async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
49
|
+
async function encrypt (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
50
50
|
const shake = handshake(conn)
|
|
51
51
|
|
|
52
52
|
let type = KeyType.RSA
|
|
@@ -124,11 +124,11 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
124
124
|
class Plaintext implements ConnectionEncrypter {
|
|
125
125
|
public protocol: string = PROTOCOL
|
|
126
126
|
|
|
127
|
-
async secureInbound (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
127
|
+
async secureInbound (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
128
128
|
return await encrypt(localId, conn, remoteId)
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
async secureOutbound (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
131
|
+
async secureOutbound (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
132
132
|
return await encrypt(localId, conn, remoteId)
|
|
133
133
|
}
|
|
134
134
|
}
|