libp2p 0.44.0-97b473ad → 0.44.0-e3deaa40
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 +27 -27
- package/dist/src/address-manager/index.d.ts +4 -4
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +9 -6
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +15 -13
- 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 +7 -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 +3 -1
- 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 -2
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +3 -0
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +5 -4
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +3 -0
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +11 -6
- 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 +16 -23
- 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 +18 -4
- 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 +18 -12
- 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/index.d.ts +16 -48
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +200 -198
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +11 -62
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js +0 -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 -195
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +7 -6
- 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/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +0 -1
- package/dist/src/pnet/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 +27 -11
- 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 +36 -55
- 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/package.json +59 -43
- package/src/address-manager/index.ts +12 -8
- package/src/autonat/index.ts +14 -13
- package/src/circuit-relay/server/advert-service.ts +2 -2
- package/src/circuit-relay/server/index.ts +7 -3
- package/src/circuit-relay/transport/discovery.ts +3 -1
- package/src/circuit-relay/transport/index.ts +10 -2
- package/src/circuit-relay/transport/listener.ts +8 -4
- package/src/circuit-relay/transport/reservation-store.ts +14 -6
- 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 +8 -14
- package/src/connection-manager/auto-dial.ts +24 -5
- package/src/connection-manager/connection-pruner.ts +28 -8
- package/src/connection-manager/dial-queue.ts +21 -19
- 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/index.ts +235 -225
- package/src/index.ts +12 -70
- package/src/insecure/index.ts +4 -5
- package/src/libp2p.ts +139 -259
- package/src/peer-routing.ts +10 -8
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/pnet/index.ts +0 -1
- package/src/registrar.ts +31 -27
- package/src/transport-manager.ts +36 -14
- package/src/upgrader.ts +59 -64
- package/src/{nat-manager.ts → upnp-nat/index.ts} +15 -16
- 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,23 @@ 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
35
|
import type { PeerRoutingInit } from './peer-routing.js'
|
|
45
36
|
import type { ConnectionManagerInit } from './connection-manager/index.js'
|
|
46
|
-
import type {
|
|
37
|
+
import type { PersistentPeerStoreInit } from '@libp2p/peer-store'
|
|
38
|
+
|
|
39
|
+
export type ServiceFactoryMap<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
40
|
+
[Property in keyof T]: (components: Components) => T[Property]
|
|
41
|
+
}
|
|
47
42
|
|
|
48
43
|
/**
|
|
49
44
|
* For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
|
50
45
|
*/
|
|
51
|
-
export interface Libp2pInit {
|
|
46
|
+
export interface Libp2pInit<T extends ServiceMap = {}> {
|
|
52
47
|
/**
|
|
53
48
|
* peerId instance (it will be created if not provided)
|
|
54
49
|
*/
|
|
@@ -84,7 +79,7 @@ export interface Libp2pInit {
|
|
|
84
79
|
/**
|
|
85
80
|
* libp2p PeerStore configuration
|
|
86
81
|
*/
|
|
87
|
-
peerStore:
|
|
82
|
+
peerStore: PersistentPeerStoreInit
|
|
88
83
|
|
|
89
84
|
/**
|
|
90
85
|
* libp2p Peer routing service configuration
|
|
@@ -96,37 +91,6 @@ export interface Libp2pInit {
|
|
|
96
91
|
*/
|
|
97
92
|
keychain: KeyChainInit
|
|
98
93
|
|
|
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
94
|
/**
|
|
131
95
|
* An array that must include at least 1 compliant transport
|
|
132
96
|
*/
|
|
@@ -137,47 +101,25 @@ export interface Libp2pInit {
|
|
|
137
101
|
peerRouters?: Array<(components: Components) => PeerRouting>
|
|
138
102
|
contentRouters?: Array<(components: Components) => ContentRouting>
|
|
139
103
|
|
|
140
|
-
/**
|
|
141
|
-
* Pass a DHT implementation to enable DHT operations
|
|
142
|
-
*/
|
|
143
|
-
dht?: (components: Components) => DualDHT
|
|
144
|
-
|
|
145
104
|
/**
|
|
146
105
|
* A Metrics implementation can be supplied to collect metrics on this node
|
|
147
106
|
*/
|
|
148
107
|
metrics?: (components: Components) => Metrics
|
|
149
108
|
|
|
150
|
-
/**
|
|
151
|
-
* If a PubSub implmentation is supplied, PubSub operations will become available
|
|
152
|
-
*/
|
|
153
|
-
pubsub?: (components: Components) => PubSub
|
|
154
|
-
|
|
155
109
|
/**
|
|
156
110
|
* A ConnectionProtector can be used to create a secure overlay on top of the network using pre-shared keys
|
|
157
111
|
*/
|
|
158
112
|
connectionProtector?: (components: Components) => ConnectionProtector
|
|
159
|
-
}
|
|
160
113
|
|
|
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
114
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* ```js
|
|
169
|
-
* libp2p.addEventListener('peer:discovery', (event) => {
|
|
170
|
-
* const peerInfo = event.detail
|
|
171
|
-
* // ...
|
|
172
|
-
* })
|
|
173
|
-
* ```
|
|
115
|
+
* Arbitrary libp2p modules
|
|
174
116
|
*/
|
|
175
|
-
|
|
117
|
+
services: ServiceFactoryMap<T>
|
|
176
118
|
}
|
|
177
119
|
|
|
178
120
|
export type { Libp2p }
|
|
179
121
|
|
|
180
|
-
export type Libp2pOptions = RecursivePartial<Libp2pInit
|
|
122
|
+
export type Libp2pOptions<T extends ServiceMap = {}> = RecursivePartial<Libp2pInit<T>> & { start?: boolean }
|
|
181
123
|
|
|
182
124
|
/**
|
|
183
125
|
* Returns a new instance of the Libp2p interface, generating a new PeerId
|
|
@@ -204,7 +146,7 @@ export type Libp2pOptions = RecursivePartial<Libp2pInit> & { start?: boolean }
|
|
|
204
146
|
* const libp2p = await createLibp2p(options)
|
|
205
147
|
* ```
|
|
206
148
|
*/
|
|
207
|
-
export async function createLibp2p (options: Libp2pOptions): Promise<Libp2p
|
|
149
|
+
export async function createLibp2p <T extends ServiceMap = {}> (options: Libp2pOptions<T>): Promise<Libp2p<T>> {
|
|
208
150
|
const node = await createLibp2pNode(options)
|
|
209
151
|
|
|
210
152
|
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,8 +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> {
|
|
50
|
-
// @ts-expect-error - remove after https://github.com/libp2p/js-libp2p/pull/1674
|
|
49
|
+
async function encrypt (localId: PeerId, conn: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remoteId?: PeerId): Promise<SecuredConnection> {
|
|
51
50
|
const shake = handshake(conn)
|
|
52
51
|
|
|
53
52
|
let type = KeyType.RSA
|
|
@@ -125,11 +124,11 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
125
124
|
class Plaintext implements ConnectionEncrypter {
|
|
126
125
|
public protocol: string = PROTOCOL
|
|
127
126
|
|
|
128
|
-
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> {
|
|
129
128
|
return await encrypt(localId, conn, remoteId)
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
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> {
|
|
133
132
|
return await encrypt(localId, conn, remoteId)
|
|
134
133
|
}
|
|
135
134
|
}
|