libp2p 3.1.7 → 3.2.0-90100be0c
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 +13 -13
- package/dist/index.min.js.map +4 -4
- package/dist/src/connection-manager/dial-queue.d.ts +2 -2
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +1 -1
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +3 -3
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +3 -0
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection.d.ts.map +1 -1
- package/dist/src/connection.js +11 -1
- package/dist/src/connection.js.map +1 -1
- package/dist/src/get-peer.d.ts +2 -2
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/libp2p.d.ts +3 -3
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js.map +1 -1
- 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/package.json +11 -11
- package/src/connection-manager/dial-queue.ts +3 -3
- package/src/connection-manager/index.ts +8 -3
- package/src/connection.ts +15 -2
- package/src/get-peer.ts +2 -2
- package/src/libp2p.ts +3 -3
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -24
|
@@ -12,7 +12,7 @@ import { ReconnectQueue } from './reconnect-queue.js'
|
|
|
12
12
|
import { dnsaddrResolver } from './resolvers/index.ts'
|
|
13
13
|
import { findExistingConnection, multiaddrToIpNet } from './utils.js'
|
|
14
14
|
import type { IpNet } from '@chainsafe/netmask'
|
|
15
|
-
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, Metrics, PeerId, PeerStore, Startable, PendingDialStatus, PeerRouting, IsDialableOptions, MultiaddrResolver, Stream, NewStreamOptions } from '@libp2p/interface'
|
|
15
|
+
import type { PendingDial, AddressSorter, Libp2pEvents, AbortOptions, ComponentLogger, Logger, Connection, MultiaddrConnection, ConnectionGater, Metrics, PeerId, PeerStore, Startable, PendingDialStatus, PeerRouting, IsDialableOptions, MultiaddrResolver, Stream, NewStreamOptions, DialTarget } from '@libp2p/interface'
|
|
16
16
|
import type { ConnectionManager, OpenConnectionOptions, TransportManager } from '@libp2p/interface-internal'
|
|
17
17
|
import type { JobStatus } from '@libp2p/utils'
|
|
18
18
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
@@ -523,7 +523,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
523
523
|
return this.connections
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
async openConnection (peerIdOrMultiaddr:
|
|
526
|
+
async openConnection (peerIdOrMultiaddr: DialTarget, options: OpenConnectionOptions = {}): Promise<Connection> {
|
|
527
527
|
if (!this.started) {
|
|
528
528
|
throw new NotStartedError('Not started')
|
|
529
529
|
}
|
|
@@ -532,6 +532,7 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
532
532
|
|
|
533
533
|
try {
|
|
534
534
|
options.signal?.throwIfAborted()
|
|
535
|
+
options?.onProgress?.(new CustomProgressEvent('connection:open', peerIdOrMultiaddr))
|
|
535
536
|
|
|
536
537
|
const { peerId, multiaddrs } = getPeerAddress(peerIdOrMultiaddr)
|
|
537
538
|
|
|
@@ -547,6 +548,8 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
547
548
|
this.log('had an existing connection to %p as %a', peerId, existingConnection.remoteAddr)
|
|
548
549
|
|
|
549
550
|
options.onProgress?.(new CustomProgressEvent('dial-queue:already-connected'))
|
|
551
|
+
options.onProgress?.(new CustomProgressEvent('connection:opened', existingConnection))
|
|
552
|
+
|
|
550
553
|
return existingConnection
|
|
551
554
|
}
|
|
552
555
|
}
|
|
@@ -590,13 +593,15 @@ export class DefaultConnectionManager implements ConnectionManager, Startable {
|
|
|
590
593
|
peerConnections.push(connection)
|
|
591
594
|
}
|
|
592
595
|
|
|
596
|
+
options.onProgress?.(new CustomProgressEvent('connection:opened', connection))
|
|
597
|
+
|
|
593
598
|
return connection
|
|
594
599
|
} finally {
|
|
595
600
|
this.outboundPendingConnections--
|
|
596
601
|
}
|
|
597
602
|
}
|
|
598
603
|
|
|
599
|
-
async openStream (peerIdOrMultiaddr:
|
|
604
|
+
async openStream (peerIdOrMultiaddr: DialTarget, protocol: string | string[], options: OpenConnectionOptions & NewStreamOptions = {}): Promise<Stream> {
|
|
600
605
|
const connection = await this.openConnection(peerIdOrMultiaddr, options)
|
|
601
606
|
|
|
602
607
|
return connection.newStream(protocol, options)
|
package/src/connection.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { connectionSymbol, LimitedConnectionError, ConnectionClosedError, TooMan
|
|
|
2
2
|
import * as mss from '@libp2p/multistream-select'
|
|
3
3
|
import { CODE_P2P } from '@multiformats/multiaddr'
|
|
4
4
|
import { setMaxListeners, TypedEventEmitter } from 'main-event'
|
|
5
|
+
import { CustomProgressEvent } from 'progress-events'
|
|
5
6
|
import { CONNECTION_CLOSE_TIMEOUT, PROTOCOL_NEGOTIATION_TIMEOUT } from './connection-manager/constants.defaults.ts'
|
|
6
7
|
import { isDirect } from './connection-manager/utils.ts'
|
|
7
8
|
import { MuxerUnavailableError } from './errors.ts'
|
|
8
9
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from './registrar.ts'
|
|
9
|
-
import type { AbortOptions, Logger, MessageStreamDirection, Connection as ConnectionInterface, Stream, NewStreamOptions, PeerId, ConnectionLimits, StreamMuxer, Metrics, PeerStore, MultiaddrConnection, MessageStreamEvents, MultiaddrConnectionTimeline, ConnectionStatus, MessageStream, StreamMiddleware } from '@libp2p/interface'
|
|
10
|
+
import type { AbortOptions, Logger, MessageStreamDirection, Connection as ConnectionInterface, Stream, NewStreamOptions, PeerId, ConnectionLimits, StreamMuxer, Metrics, PeerStore, MultiaddrConnection, MessageStreamEvents, MultiaddrConnectionTimeline, ConnectionStatus, MessageStream, StreamMiddleware, OpenStreamEvent, OpenedStreamEvent } from '@libp2p/interface'
|
|
10
11
|
import type { Registrar } from '@libp2p/interface-internal'
|
|
11
12
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
12
13
|
|
|
@@ -125,6 +126,11 @@ export class Connection extends TypedEventEmitter<MessageStreamEvents> implement
|
|
|
125
126
|
protocols = [protocols]
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
options.onProgress?.(new CustomProgressEvent<OpenStreamEvent>('connection:open-stream', {
|
|
130
|
+
connection: this,
|
|
131
|
+
protocols
|
|
132
|
+
}))
|
|
133
|
+
|
|
128
134
|
this.log.trace('starting new stream for protocols %s', protocols)
|
|
129
135
|
const muxedStream = await this.muxer.createStream({
|
|
130
136
|
...options,
|
|
@@ -179,7 +185,14 @@ export class Connection extends TypedEventEmitter<MessageStreamEvents> implement
|
|
|
179
185
|
|
|
180
186
|
const middleware = this.components.registrar.getMiddleware(muxedStream.protocol)
|
|
181
187
|
|
|
182
|
-
|
|
188
|
+
const stream = await this.runMiddlewareChain(muxedStream, this, middleware)
|
|
189
|
+
|
|
190
|
+
options.onProgress?.(new CustomProgressEvent<OpenedStreamEvent>('connection:opened-stream', {
|
|
191
|
+
connection: this,
|
|
192
|
+
stream
|
|
193
|
+
}))
|
|
194
|
+
|
|
195
|
+
return stream
|
|
183
196
|
} catch (err: any) {
|
|
184
197
|
if (muxedStream.status === 'open') {
|
|
185
198
|
muxedStream.abort(err)
|
package/src/get-peer.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { InvalidMultiaddrError, InvalidParametersError, isPeerId } from '@libp2p
|
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
3
3
|
import { CODE_P2P, isMultiaddr } from '@multiformats/multiaddr'
|
|
4
4
|
import { PEER_ID } from '@multiformats/multiaddr-matcher'
|
|
5
|
-
import type { PeerId } from '@libp2p/interface'
|
|
5
|
+
import type { DialTarget, PeerId } from '@libp2p/interface'
|
|
6
6
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
7
7
|
|
|
8
8
|
export interface PeerAddress {
|
|
@@ -14,7 +14,7 @@ export interface PeerAddress {
|
|
|
14
14
|
* Extracts a PeerId and/or multiaddr from the passed PeerId or Multiaddr or an
|
|
15
15
|
* array of Multiaddrs
|
|
16
16
|
*/
|
|
17
|
-
export function getPeerAddress (peer:
|
|
17
|
+
export function getPeerAddress (peer: DialTarget): PeerAddress {
|
|
18
18
|
if (isPeerId(peer)) {
|
|
19
19
|
return { peerId: peer, multiaddrs: [] }
|
|
20
20
|
}
|
package/src/libp2p.ts
CHANGED
|
@@ -24,7 +24,7 @@ import { userAgent } from './user-agent.js'
|
|
|
24
24
|
import * as pkg from './version.js'
|
|
25
25
|
import type { Components } from './components.js'
|
|
26
26
|
import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js'
|
|
27
|
-
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection,
|
|
27
|
+
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey, StreamHandler, StreamHandlerOptions, StreamMiddleware, DialTarget, DialProtocolOptions } from '@libp2p/interface'
|
|
28
28
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
29
29
|
|
|
30
30
|
export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2pInterface<T> {
|
|
@@ -286,7 +286,7 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter
|
|
|
286
286
|
return Array.from(peerSet)
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
async dial (peer:
|
|
289
|
+
async dial (peer: DialTarget, options: DialOptions = {}): Promise<Connection> {
|
|
290
290
|
return this.components.connectionManager.openConnection(peer, {
|
|
291
291
|
// ensure any userland dials take top priority in the queue
|
|
292
292
|
priority: 75,
|
|
@@ -294,7 +294,7 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter
|
|
|
294
294
|
})
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
async dialProtocol (peer:
|
|
297
|
+
async dialProtocol (peer: DialTarget, protocols: string | string[], options: DialProtocolOptions = {}): Promise<Stream> {
|
|
298
298
|
if (protocols == null) {
|
|
299
299
|
throw new InvalidParametersError('no protocols were provided to open a stream')
|
|
300
300
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '3.
|
|
1
|
+
export const version = '3.2.0-90100be0c'
|
|
2
2
|
export const name = 'js-libp2p'
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AddressFilter": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressFilter.html",
|
|
3
|
-
"AddressManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.AddressManagerInit.html",
|
|
4
|
-
"ConnectionManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionManagerInit.html",
|
|
5
|
-
"ConnectionMonitorInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.ConnectionMonitorInit.html",
|
|
6
|
-
"Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
7
|
-
".:Libp2pInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2pInit.html",
|
|
8
|
-
"TransportManagerInit": "https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.TransportManagerInit.html",
|
|
9
|
-
"Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
10
|
-
".:Libp2pOptions": "https://libp2p.github.io/js-libp2p/types/libp2p.index.Libp2pOptions.html",
|
|
11
|
-
"ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
12
|
-
".:ServiceFactoryMap": "https://libp2p.github.io/js-libp2p/types/libp2p.index.ServiceFactoryMap.html",
|
|
13
|
-
"dnsaddrResolver": "https://libp2p.github.io/js-libp2p/variables/libp2p.index.dnsaddrResolver.html",
|
|
14
|
-
"createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
15
|
-
".:createLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.createLibp2p.html",
|
|
16
|
-
"isLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.isLibp2p.html",
|
|
17
|
-
".:isLibp2p": "https://libp2p.github.io/js-libp2p/functions/libp2p.index.isLibp2p.html",
|
|
18
|
-
"userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
19
|
-
"./user-agent:userAgent": "https://libp2p.github.io/js-libp2p/functions/libp2p.user-agent.userAgent.html",
|
|
20
|
-
"name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
21
|
-
"./version:name": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.name.html",
|
|
22
|
-
"version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html",
|
|
23
|
-
"./version:version": "https://libp2p.github.io/js-libp2p/variables/libp2p.version.version.html"
|
|
24
|
-
}
|