libp2p 2.10.0 → 3.0.0-049bfa0fa
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/README.md +39 -37
- package/dist/index.min.js +14 -17
- package/dist/index.min.js.map +4 -4
- package/dist/src/address-manager/dns-mappings.d.ts +1 -2
- package/dist/src/address-manager/dns-mappings.d.ts.map +1 -1
- package/dist/src/address-manager/dns-mappings.js +39 -43
- package/dist/src/address-manager/dns-mappings.js.map +1 -1
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +31 -14
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/ip-mappings.d.ts +1 -0
- package/dist/src/address-manager/ip-mappings.d.ts.map +1 -1
- package/dist/src/address-manager/ip-mappings.js +51 -40
- package/dist/src/address-manager/ip-mappings.js.map +1 -1
- package/dist/src/address-manager/observed-addresses.d.ts.map +1 -1
- package/dist/src/address-manager/observed-addresses.js +1 -3
- package/dist/src/address-manager/observed-addresses.js.map +1 -1
- package/dist/src/address-manager/transport-addresses.d.ts.map +1 -1
- package/dist/src/address-manager/transport-addresses.js +6 -8
- package/dist/src/address-manager/transport-addresses.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
- package/dist/src/config/connection-gater.browser.js +8 -22
- package/dist/src/config/connection-gater.browser.js.map +1 -1
- package/dist/src/config/connection-gater.d.ts.map +1 -1
- package/dist/src/config/connection-gater.js +1 -12
- package/dist/src/config/connection-gater.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +3 -22
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/address-sorter.d.ts.map +1 -1
- package/dist/src/connection-manager/address-sorter.js +1 -2
- package/dist/src/connection-manager/address-sorter.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +7 -3
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/constants.defaults.d.ts +4 -0
- package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.js +4 -0
- package/dist/src/connection-manager/constants.defaults.js.map +1 -1
- 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 +11 -23
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +10 -18
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +44 -26
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/reconnect-queue.js +1 -1
- package/dist/src/connection-manager/reconnect-queue.js.map +1 -1
- package/dist/src/connection-manager/utils.d.ts +31 -3
- package/dist/src/connection-manager/utils.d.ts.map +1 -1
- package/dist/src/connection-manager/utils.js +99 -18
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/connection-monitor.d.ts +1 -1
- package/dist/src/connection-monitor.d.ts.map +1 -1
- package/dist/src/connection-monitor.js +2 -3
- package/dist/src/connection-monitor.js.map +1 -1
- package/dist/src/connection.d.ts +14 -9
- package/dist/src/connection.d.ts.map +1 -1
- package/dist/src/connection.js +118 -139
- package/dist/src/connection.js.map +1 -1
- package/dist/src/get-peer.js +3 -3
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +2 -2
- package/dist/src/libp2p.d.ts +3 -1
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +13 -7
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.js +1 -1
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/random-walk.d.ts.map +1 -1
- package/dist/src/random-walk.js +13 -3
- package/dist/src/random-walk.js.map +1 -1
- package/dist/src/registrar.d.ts +8 -4
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +66 -46
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.js +15 -2
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +26 -16
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +88 -122
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +25 -0
- package/dist/src/utils.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/package.json +27 -30
- package/src/address-manager/dns-mappings.ts +50 -50
- package/src/address-manager/index.ts +37 -17
- package/src/address-manager/ip-mappings.ts +64 -44
- package/src/address-manager/observed-addresses.ts +1 -3
- package/src/address-manager/transport-addresses.ts +7 -9
- package/src/config/connection-gater.browser.ts +8 -24
- package/src/config/connection-gater.ts +1 -12
- package/src/config.ts +3 -25
- package/src/connection-manager/address-sorter.ts +1 -2
- package/src/connection-manager/connection-pruner.ts +8 -3
- package/src/connection-manager/constants.defaults.ts +5 -0
- package/src/connection-manager/dial-queue.ts +12 -27
- package/src/connection-manager/index.ts +60 -45
- package/src/connection-manager/reconnect-queue.ts +1 -1
- package/src/connection-manager/utils.ts +129 -21
- package/src/connection-monitor.ts +3 -4
- package/src/connection.ts +142 -179
- package/src/get-peer.ts +3 -3
- package/src/index.ts +2 -2
- package/src/libp2p.ts +16 -9
- package/src/peer-routing.ts +1 -1
- package/src/random-walk.ts +13 -3
- package/src/registrar.ts +87 -61
- package/src/transport-manager.ts +18 -2
- package/src/upgrader.ts +132 -149
- package/src/utils.ts +31 -0
- package/src/version.ts +1 -1
- package/dist/typedoc-urls.json +0 -24
package/dist/src/connection.js
CHANGED
|
@@ -1,94 +1,96 @@
|
|
|
1
|
-
import { connectionSymbol, LimitedConnectionError, ConnectionClosedError,
|
|
1
|
+
import { connectionSymbol, LimitedConnectionError, ConnectionClosedError, TooManyOutboundProtocolStreamsError, TooManyInboundProtocolStreamsError, StreamCloseEvent } from '@libp2p/interface';
|
|
2
2
|
import * as mss from '@libp2p/multistream-select';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { CODE_P2P } from '@multiformats/multiaddr';
|
|
4
|
+
import { setMaxListeners, TypedEventEmitter } from 'main-event';
|
|
5
|
+
import { CONNECTION_CLOSE_TIMEOUT, PROTOCOL_NEGOTIATION_TIMEOUT } from "./connection-manager/constants.defaults.js";
|
|
6
|
+
import { isDirect } from "./connection-manager/utils.js";
|
|
5
7
|
import { MuxerUnavailableError } from "./errors.js";
|
|
6
8
|
import { DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS } from "./registrar.js";
|
|
7
|
-
const CLOSE_TIMEOUT = 500;
|
|
8
9
|
/**
|
|
9
10
|
* An implementation of the js-libp2p connection.
|
|
10
11
|
* Any libp2p transport should use an upgrader to return this connection.
|
|
11
12
|
*/
|
|
12
|
-
export class Connection {
|
|
13
|
+
export class Connection extends TypedEventEmitter {
|
|
13
14
|
id;
|
|
14
15
|
remoteAddr;
|
|
15
16
|
remotePeer;
|
|
16
17
|
direction;
|
|
17
18
|
timeline;
|
|
19
|
+
direct;
|
|
18
20
|
multiplexer;
|
|
19
21
|
encryption;
|
|
20
|
-
status;
|
|
21
22
|
limits;
|
|
22
23
|
log;
|
|
23
|
-
tags;
|
|
24
24
|
maConn;
|
|
25
25
|
muxer;
|
|
26
26
|
components;
|
|
27
27
|
outboundStreamProtocolNegotiationTimeout;
|
|
28
28
|
inboundStreamProtocolNegotiationTimeout;
|
|
29
|
+
closeTimeout;
|
|
29
30
|
constructor(components, init) {
|
|
31
|
+
super();
|
|
30
32
|
this.components = components;
|
|
31
33
|
this.id = init.id;
|
|
32
34
|
this.remoteAddr = init.maConn.remoteAddr;
|
|
33
35
|
this.remotePeer = init.remotePeer;
|
|
34
36
|
this.direction = init.direction ?? 'outbound';
|
|
35
|
-
this.status = 'open';
|
|
36
37
|
this.timeline = init.maConn.timeline;
|
|
37
|
-
this.encryption = init.
|
|
38
|
+
this.encryption = init.cryptoProtocol;
|
|
38
39
|
this.limits = init.limits;
|
|
39
40
|
this.maConn = init.maConn;
|
|
40
41
|
this.log = init.maConn.log;
|
|
41
42
|
this.outboundStreamProtocolNegotiationTimeout = init.outboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT;
|
|
42
43
|
this.inboundStreamProtocolNegotiationTimeout = init.inboundStreamProtocolNegotiationTimeout ?? PROTOCOL_NEGOTIATION_TIMEOUT;
|
|
43
|
-
|
|
44
|
+
this.closeTimeout = init.closeTimeout ?? CONNECTION_CLOSE_TIMEOUT;
|
|
45
|
+
this.direct = isDirect(init.maConn.remoteAddr);
|
|
46
|
+
this.onIncomingStream = this.onIncomingStream.bind(this);
|
|
47
|
+
if (this.remoteAddr.getComponents().find(component => component.code === CODE_P2P) == null) {
|
|
44
48
|
this.remoteAddr = this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`);
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
this.muxer
|
|
50
|
-
direction: this.direction,
|
|
51
|
-
log: this.log,
|
|
52
|
-
// Run anytime a remote stream is created
|
|
53
|
-
onIncomingStream: (stream) => {
|
|
54
|
-
this.onIncomingStream(stream);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
// Pipe all data through the muxer
|
|
58
|
-
void Promise.all([
|
|
59
|
-
this.muxer.sink(this.maConn.source),
|
|
60
|
-
this.maConn.sink(this.muxer.source)
|
|
61
|
-
]).catch(err => {
|
|
62
|
-
this.log.error('error piping data through muxer - %e', err);
|
|
63
|
-
});
|
|
50
|
+
if (init.muxer != null) {
|
|
51
|
+
this.multiplexer = init.muxer.protocol;
|
|
52
|
+
this.muxer = init.muxer;
|
|
53
|
+
this.muxer.addEventListener('stream', this.onIncomingStream);
|
|
64
54
|
}
|
|
55
|
+
this.maConn.addEventListener('close', (evt) => {
|
|
56
|
+
this.dispatchEvent(new StreamCloseEvent(evt.local, evt.error));
|
|
57
|
+
});
|
|
65
58
|
}
|
|
66
59
|
[Symbol.toStringTag] = 'Connection';
|
|
67
60
|
[connectionSymbol] = true;
|
|
68
61
|
get streams() {
|
|
69
62
|
return this.muxer?.streams ?? [];
|
|
70
63
|
}
|
|
64
|
+
get status() {
|
|
65
|
+
return this.maConn.status;
|
|
66
|
+
}
|
|
71
67
|
/**
|
|
72
68
|
* Create a new stream over this connection
|
|
73
69
|
*/
|
|
74
70
|
newStream = async (protocols, options = {}) => {
|
|
75
|
-
if (this.
|
|
76
|
-
throw new
|
|
71
|
+
if (this.muxer == null) {
|
|
72
|
+
throw new MuxerUnavailableError('Connection is not multiplexed');
|
|
77
73
|
}
|
|
78
|
-
if (this.status
|
|
79
|
-
throw new ConnectionClosedError(
|
|
74
|
+
if (this.muxer.status !== 'open') {
|
|
75
|
+
throw new ConnectionClosedError(`The connection muxer is "${this.muxer.status}" and not "open"`);
|
|
80
76
|
}
|
|
81
|
-
if (
|
|
82
|
-
|
|
77
|
+
if (this.maConn.status !== 'open') {
|
|
78
|
+
throw new ConnectionClosedError(`The connection is "${this.status}" and not "open"`);
|
|
83
79
|
}
|
|
84
80
|
if (this.limits != null && options?.runOnLimitedConnection !== true) {
|
|
85
81
|
throw new LimitedConnectionError('Cannot open protocol stream on limited connection');
|
|
86
82
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
83
|
+
if (!Array.isArray(protocols)) {
|
|
84
|
+
protocols = [protocols];
|
|
89
85
|
}
|
|
90
86
|
this.log.trace('starting new stream for protocols %s', protocols);
|
|
91
|
-
const muxedStream = await this.muxer.
|
|
87
|
+
const muxedStream = await this.muxer.createStream({
|
|
88
|
+
...options,
|
|
89
|
+
// most underlying transports only support negotiating a single protocol
|
|
90
|
+
// so only pass the early protocol if a single protocol has been requested
|
|
91
|
+
// otherwise fall back to mss
|
|
92
|
+
protocol: protocols.length === 1 ? protocols[0] : undefined
|
|
93
|
+
});
|
|
92
94
|
this.log.trace('started new stream %s for protocols %s', muxedStream.id, protocols);
|
|
93
95
|
try {
|
|
94
96
|
if (options.signal == null) {
|
|
@@ -100,153 +102,128 @@ export class Connection {
|
|
|
100
102
|
signal
|
|
101
103
|
};
|
|
102
104
|
}
|
|
103
|
-
muxedStream.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
log
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
if (muxedStream.protocol === '') {
|
|
106
|
+
muxedStream.log.trace('selecting protocol from protocols %s', protocols);
|
|
107
|
+
muxedStream.protocol = await mss.select(muxedStream, protocols, options);
|
|
108
|
+
muxedStream.log('negotiated protocol %s', muxedStream.protocol);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
muxedStream.log('pre-negotiated protocol %s', muxedStream.protocol);
|
|
112
|
+
}
|
|
113
|
+
const outgoingLimit = findOutgoingStreamLimit(muxedStream.protocol, this.components.registrar, options);
|
|
114
|
+
const streamCount = countStreams(muxedStream.protocol, 'outbound', this);
|
|
115
|
+
if (streamCount > outgoingLimit) {
|
|
116
|
+
const err = new TooManyOutboundProtocolStreamsError(`Too many outbound protocol streams for protocol "${muxedStream.protocol}" - ${streamCount}/${outgoingLimit}`);
|
|
114
117
|
muxedStream.abort(err);
|
|
115
118
|
throw err;
|
|
116
119
|
}
|
|
117
120
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
118
121
|
// the peer store should ensure that the peer is registered with that protocol
|
|
119
122
|
await this.components.peerStore.merge(this.remotePeer, {
|
|
120
|
-
protocols: [protocol]
|
|
123
|
+
protocols: [muxedStream.protocol]
|
|
121
124
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
muxedStream
|
|
125
|
-
muxedStream.sink = stream.sink;
|
|
126
|
-
muxedStream.protocol = protocol;
|
|
127
|
-
// allow closing the write end of a not-yet-negotiated stream
|
|
128
|
-
if (stream.closeWrite != null) {
|
|
129
|
-
muxedStream.closeWrite = stream.closeWrite;
|
|
130
|
-
}
|
|
131
|
-
// allow closing the read end of a not-yet-negotiated stream
|
|
132
|
-
if (stream.closeRead != null) {
|
|
133
|
-
muxedStream.closeRead = stream.closeRead;
|
|
134
|
-
}
|
|
135
|
-
// make sure we don't try to negotiate a stream we are closing
|
|
136
|
-
if (stream.close != null) {
|
|
137
|
-
muxedStream.close = stream.close;
|
|
138
|
-
}
|
|
139
|
-
this.components.metrics?.trackProtocolStream(muxedStream, this);
|
|
140
|
-
muxedStream.direction = 'outbound';
|
|
141
|
-
return muxedStream;
|
|
125
|
+
this.components.metrics?.trackProtocolStream(muxedStream);
|
|
126
|
+
const middleware = this.components.registrar.getMiddleware(muxedStream.protocol);
|
|
127
|
+
return await this.runMiddlewareChain(muxedStream, this, middleware);
|
|
142
128
|
}
|
|
143
129
|
catch (err) {
|
|
144
|
-
|
|
145
|
-
if (muxedStream.timeline.close == null) {
|
|
130
|
+
if (muxedStream.status === 'open') {
|
|
146
131
|
muxedStream.abort(err);
|
|
147
132
|
}
|
|
133
|
+
else {
|
|
134
|
+
this.log.error('could not create new outbound stream on connection %s %a for protocols %s - %e', this.direction === 'inbound' ? 'from' : 'to', this.remoteAddr, protocols, err);
|
|
135
|
+
}
|
|
148
136
|
throw err;
|
|
149
137
|
}
|
|
150
138
|
};
|
|
151
|
-
onIncomingStream(
|
|
139
|
+
async onIncomingStream(evt) {
|
|
140
|
+
const muxedStream = evt.detail;
|
|
152
141
|
const signal = AbortSignal.timeout(this.inboundStreamProtocolNegotiationTimeout);
|
|
153
142
|
setMaxListeners(Infinity, signal);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const incomingLimit = findIncomingStreamLimit(protocol, this.components.registrar);
|
|
164
|
-
const streamCount = countStreams(protocol, 'inbound', this);
|
|
165
|
-
if (streamCount === incomingLimit) {
|
|
166
|
-
const err = new TooManyInboundProtocolStreamsError(`Too many inbound protocol streams for protocol "${protocol}" - limit ${incomingLimit}`);
|
|
167
|
-
muxedStream.abort(err);
|
|
168
|
-
throw err;
|
|
169
|
-
}
|
|
170
|
-
// after the handshake the returned stream can have early data so override
|
|
171
|
-
// the source/sink
|
|
172
|
-
muxedStream.source = stream.source;
|
|
173
|
-
muxedStream.sink = stream.sink;
|
|
174
|
-
muxedStream.protocol = protocol;
|
|
175
|
-
// allow closing the write end of a not-yet-negotiated stream
|
|
176
|
-
if (stream.closeWrite != null) {
|
|
177
|
-
muxedStream.closeWrite = stream.closeWrite;
|
|
143
|
+
muxedStream.log('start protocol negotiation, timing out after %dms', this.inboundStreamProtocolNegotiationTimeout);
|
|
144
|
+
try {
|
|
145
|
+
if (muxedStream.protocol === '') {
|
|
146
|
+
const protocols = this.components.registrar.getProtocols();
|
|
147
|
+
muxedStream.log.trace('selecting protocol from protocols %s', protocols);
|
|
148
|
+
muxedStream.protocol = await mss.handle(muxedStream, protocols, {
|
|
149
|
+
signal
|
|
150
|
+
});
|
|
151
|
+
muxedStream.log('negotiated protocol %s', muxedStream.protocol);
|
|
178
152
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
muxedStream.closeRead = stream.closeRead;
|
|
153
|
+
else {
|
|
154
|
+
muxedStream.log('pre-negotiated protocol %s', muxedStream.protocol);
|
|
182
155
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
156
|
+
const incomingLimit = findIncomingStreamLimit(muxedStream.protocol, this.components.registrar);
|
|
157
|
+
const streamCount = countStreams(muxedStream.protocol, 'inbound', this);
|
|
158
|
+
if (streamCount > incomingLimit) {
|
|
159
|
+
throw new TooManyInboundProtocolStreamsError(`Too many inbound protocol streams for protocol "${muxedStream.protocol}" - limit ${incomingLimit}`);
|
|
186
160
|
}
|
|
187
161
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
|
188
162
|
// the peer store should ensure that the peer is registered with that protocol
|
|
189
163
|
await this.components.peerStore.merge(this.remotePeer, {
|
|
190
|
-
protocols: [protocol]
|
|
164
|
+
protocols: [muxedStream.protocol]
|
|
191
165
|
}, {
|
|
192
166
|
signal
|
|
193
167
|
});
|
|
194
|
-
this.components.metrics?.trackProtocolStream(muxedStream
|
|
195
|
-
const { handler, options } = this.components.registrar.getHandler(protocol);
|
|
168
|
+
this.components.metrics?.trackProtocolStream(muxedStream);
|
|
169
|
+
const { handler, options } = this.components.registrar.getHandler(muxedStream.protocol);
|
|
196
170
|
if (this.limits != null && options.runOnLimitedConnection !== true) {
|
|
197
171
|
throw new LimitedConnectionError('Cannot open protocol stream on limited connection');
|
|
198
172
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
173
|
+
const middleware = this.components.registrar.getMiddleware(muxedStream.protocol);
|
|
174
|
+
middleware.push(async (stream, connection, next) => {
|
|
175
|
+
await handler(stream, connection);
|
|
176
|
+
next(stream, connection);
|
|
177
|
+
});
|
|
178
|
+
await this.runMiddlewareChain(muxedStream, this, middleware);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
203
181
|
muxedStream.abort(err);
|
|
204
|
-
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async runMiddlewareChain(stream, connection, middleware) {
|
|
185
|
+
for (let i = 0; i < middleware.length; i++) {
|
|
186
|
+
const mw = middleware[i];
|
|
187
|
+
stream.log.trace('running middleware', i, mw);
|
|
188
|
+
// eslint-disable-next-line no-loop-func
|
|
189
|
+
await new Promise((resolve, reject) => {
|
|
190
|
+
try {
|
|
191
|
+
const result = mw(stream, connection, (s, c) => {
|
|
192
|
+
stream = s;
|
|
193
|
+
connection = c;
|
|
194
|
+
resolve();
|
|
195
|
+
});
|
|
196
|
+
if (result instanceof Promise) {
|
|
197
|
+
result.catch(reject);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
reject(err);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
stream.log.trace('ran middleware', i, mw);
|
|
205
|
+
}
|
|
206
|
+
return stream;
|
|
205
207
|
}
|
|
206
208
|
/**
|
|
207
209
|
* Close the connection
|
|
208
210
|
*/
|
|
209
211
|
async close(options = {}) {
|
|
210
|
-
if (this.status === 'closed' || this.status === 'closing') {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
212
|
this.log('closing connection to %a', this.remoteAddr);
|
|
214
|
-
this.status = 'closing';
|
|
215
213
|
if (options.signal == null) {
|
|
216
|
-
const signal = AbortSignal.timeout(
|
|
214
|
+
const signal = AbortSignal.timeout(this.closeTimeout);
|
|
217
215
|
setMaxListeners(Infinity, signal);
|
|
218
216
|
options = {
|
|
219
217
|
...options,
|
|
220
218
|
signal
|
|
221
219
|
};
|
|
222
220
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// ensure remaining streams are closed gracefully
|
|
226
|
-
await this.muxer?.close(options);
|
|
227
|
-
// close the underlying transport
|
|
228
|
-
await this.maConn.close(options);
|
|
229
|
-
this.log.trace('updating timeline with close time');
|
|
230
|
-
this.status = 'closed';
|
|
231
|
-
this.timeline.close = Date.now();
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
this.log.error('error encountered during graceful close of connection to %a', this.remoteAddr, err);
|
|
235
|
-
this.abort(err);
|
|
236
|
-
}
|
|
221
|
+
await this.muxer?.close(options);
|
|
222
|
+
await this.maConn.close(options);
|
|
237
223
|
}
|
|
238
224
|
abort(err) {
|
|
239
|
-
if (this.status === 'closed') {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
this.log.error('aborting connection to %a due to error', this.remoteAddr, err);
|
|
243
|
-
this.status = 'closing';
|
|
244
|
-
// ensure remaining streams are aborted
|
|
245
225
|
this.muxer?.abort(err);
|
|
246
|
-
// abort the underlying transport
|
|
247
226
|
this.maConn.abort(err);
|
|
248
|
-
this.status = 'closed';
|
|
249
|
-
this.timeline.close = Date.now();
|
|
250
227
|
}
|
|
251
228
|
}
|
|
252
229
|
export function createConnection(components, init) {
|
|
@@ -255,7 +232,9 @@ export function createConnection(components, init) {
|
|
|
255
232
|
function findIncomingStreamLimit(protocol, registrar) {
|
|
256
233
|
try {
|
|
257
234
|
const { options } = registrar.getHandler(protocol);
|
|
258
|
-
|
|
235
|
+
if (options.maxInboundStreams != null) {
|
|
236
|
+
return options.maxInboundStreams;
|
|
237
|
+
}
|
|
259
238
|
}
|
|
260
239
|
catch (err) {
|
|
261
240
|
if (err.name !== 'UnhandledProtocolError') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,mCAAmC,EAAE,kCAAkC,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC9L,OAAO,KAAK,GAAG,MAAM,4BAA4B,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,4CAA4C,CAAA;AACnH,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAA;AAyB1F;;;GAGG;AACH,MAAM,OAAO,UA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@@
|
|
|
1
1
|
import { InvalidMultiaddrError, InvalidParametersError, isPeerId } from '@libp2p/interface';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
|
-
import { isMultiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import { CODE_P2P, isMultiaddr } from '@multiformats/multiaddr';
|
|
4
4
|
import { PEER_ID } from '@multiformats/multiaddr-matcher';
|
|
5
5
|
/**
|
|
6
6
|
* Extracts a PeerId and/or multiaddr from the passed PeerId or Multiaddr or an
|
|
@@ -13,14 +13,14 @@ export function getPeerAddress(peer) {
|
|
|
13
13
|
let multiaddrs = Array.isArray(peer) ? peer : [peer];
|
|
14
14
|
let peerId;
|
|
15
15
|
if (multiaddrs.length > 0) {
|
|
16
|
-
const peerIdStr = multiaddrs[0].
|
|
16
|
+
const peerIdStr = multiaddrs[0].getComponents().findLast(c => c.code === CODE_P2P)?.value;
|
|
17
17
|
peerId = peerIdStr == null ? undefined : peerIdFromString(peerIdStr);
|
|
18
18
|
// ensure PeerId is either not set or is consistent
|
|
19
19
|
multiaddrs.forEach(ma => {
|
|
20
20
|
if (!isMultiaddr(ma)) {
|
|
21
21
|
throw new InvalidMultiaddrError('Invalid multiaddr');
|
|
22
22
|
}
|
|
23
|
-
const maPeerIdStr = ma.
|
|
23
|
+
const maPeerIdStr = ma.getComponents().findLast(c => c.code === CODE_P2P)?.value;
|
|
24
24
|
if (maPeerIdStr == null) {
|
|
25
25
|
if (peerId != null) {
|
|
26
26
|
throw new InvalidParametersError('Multiaddrs must all have the same peer id or have no peer id');
|
package/dist/src/get-peer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-peer.js","sourceRoot":"","sources":["../../src/get-peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,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AM,WAAW,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,KAAK,CAAA;YAEhF,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;gBACxB,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;oBACnB,MAAM,IAAI,sBAAsB,CAAC,8DAA8D,CAAC,CAAA;gBAClG,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAA;gBAE9C,IAAI,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;oBACtC,MAAM,IAAI,sBAAsB,CAAC,8DAA8D,CAAC,CAAA;gBAClG,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,4EAA4E;IAC5E,sCAAsC;IACtC,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QAClC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,MAAM;QACN,UAAU;KACX,CAAA;AACH,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -155,8 +155,8 @@ export type Libp2pOptions<T extends ServiceMap = ServiceMap> = Libp2pInit<T> & {
|
|
|
155
155
|
* import { createLibp2p } from 'libp2p'
|
|
156
156
|
* import { tcp } from '@libp2p/tcp'
|
|
157
157
|
* import { mplex } from '@libp2p/mplex'
|
|
158
|
-
* import { noise } from '@
|
|
159
|
-
* import { yamux } from '@
|
|
158
|
+
* import { noise } from '@libp2p/noise'
|
|
159
|
+
* import { yamux } from '@libp2p/yamux'
|
|
160
160
|
*
|
|
161
161
|
* // specify options
|
|
162
162
|
* const options = {
|
package/dist/src/index.js
CHANGED
|
@@ -30,8 +30,8 @@ export { dnsaddrResolver } from "./connection-manager/resolvers/index.js";
|
|
|
30
30
|
* import { createLibp2p } from 'libp2p'
|
|
31
31
|
* import { tcp } from '@libp2p/tcp'
|
|
32
32
|
* import { mplex } from '@libp2p/mplex'
|
|
33
|
-
* import { noise } from '@
|
|
34
|
-
* import { yamux } from '@
|
|
33
|
+
* import { noise } from '@libp2p/noise'
|
|
34
|
+
* import { yamux } from '@libp2p/yamux'
|
|
35
35
|
*
|
|
36
36
|
* // specify options
|
|
37
37
|
* const options = {
|
package/dist/src/libp2p.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypedEventEmitter } from 'main-event';
|
|
2
2
|
import type { Components } from './components.js';
|
|
3
3
|
import type { Libp2p as Libp2pInterface, Libp2pInit } from './index.js';
|
|
4
|
-
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey, StreamHandler, StreamHandlerOptions } from '@libp2p/interface';
|
|
4
|
+
import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology, Libp2pStatus, IsDialableOptions, DialOptions, PublicKey, Ed25519PeerId, Secp256k1PeerId, RSAPublicKey, RSAPeerId, URLPeerId, Ed25519PublicKey, Secp256k1PublicKey, StreamHandler, StreamHandlerOptions, StreamMiddleware } from '@libp2p/interface';
|
|
5
5
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
6
|
export declare class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter<Libp2pEvents> implements Libp2pInterface<T> {
|
|
7
7
|
#private;
|
|
@@ -47,6 +47,8 @@ export declare class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEven
|
|
|
47
47
|
unhandle(protocols: string[] | string, options?: AbortOptions): Promise<void>;
|
|
48
48
|
register(protocol: string, topology: Topology, options?: AbortOptions): Promise<string>;
|
|
49
49
|
unregister(id: string): void;
|
|
50
|
+
use(protocol: string, middleware: StreamMiddleware | StreamMiddleware[]): void;
|
|
51
|
+
unuse(protocol: string): void;
|
|
50
52
|
isDialable(multiaddr: Multiaddr, options?: IsDialableOptions): Promise<boolean>;
|
|
51
53
|
}
|
|
52
54
|
//# sourceMappingURL=libp2p.d.ts.map
|
package/dist/src/libp2p.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAA;AAgB/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,IAAI,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAU,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAY,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAA;AAgB/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAA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Q,CAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9E,QAAQ,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9F,UAAU,CAAE,EAAE,EAAE,MAAM,GAAG,IAAI;IAI7B,GAAG,CAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,GAAG,IAAI;IAI/E,KAAK,CAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAIxB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;CAqB3F"}
|
package/dist/src/libp2p.js
CHANGED
|
@@ -4,7 +4,7 @@ import { defaultLogger } from '@libp2p/logger';
|
|
|
4
4
|
import { PeerSet } from '@libp2p/peer-collections';
|
|
5
5
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
6
6
|
import { persistentPeerStore } from '@libp2p/peer-store';
|
|
7
|
-
import { isMultiaddr } from '@multiformats/multiaddr';
|
|
7
|
+
import { CODE_P2P, isMultiaddr } from '@multiformats/multiaddr';
|
|
8
8
|
import { MemoryDatastore } from 'datastore-core/memory';
|
|
9
9
|
import { TypedEventEmitter, setMaxListeners } from 'main-event';
|
|
10
10
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
@@ -97,8 +97,9 @@ export class Libp2p extends TypedEventEmitter {
|
|
|
97
97
|
connectionEncrypters: (init.connectionEncrypters ?? []).map((fn, index) => this.configureComponent(`connection-encryption-${index}`, fn(this.components))),
|
|
98
98
|
streamMuxers: (init.streamMuxers ?? []).map((fn, index) => this.configureComponent(`stream-muxers-${index}`, fn(this.components))),
|
|
99
99
|
inboundUpgradeTimeout: init.connectionManager?.inboundUpgradeTimeout,
|
|
100
|
-
inboundStreamProtocolNegotiationTimeout: init.connectionManager?.inboundStreamProtocolNegotiationTimeout
|
|
101
|
-
outboundStreamProtocolNegotiationTimeout: init.connectionManager?.outboundStreamProtocolNegotiationTimeout
|
|
100
|
+
inboundStreamProtocolNegotiationTimeout: init.connectionManager?.inboundStreamProtocolNegotiationTimeout,
|
|
101
|
+
outboundStreamProtocolNegotiationTimeout: init.connectionManager?.outboundStreamProtocolNegotiationTimeout,
|
|
102
|
+
connectionCloseTimeout: init.connectionManager?.connectionCloseTimeout
|
|
102
103
|
});
|
|
103
104
|
// Setup the transport manager
|
|
104
105
|
this.configureComponent('transportManager', new DefaultTransportManager(this.components, init.transportManager));
|
|
@@ -187,7 +188,7 @@ export class Libp2p extends TypedEventEmitter {
|
|
|
187
188
|
await this.components.afterStart?.();
|
|
188
189
|
this.status = 'started';
|
|
189
190
|
this.safeDispatchEvent('start', { detail: this });
|
|
190
|
-
this.log('libp2p has started');
|
|
191
|
+
this.log('libp2p has started with peer id %p', this.peerId);
|
|
191
192
|
}
|
|
192
193
|
catch (err) {
|
|
193
194
|
this.log.error('An error occurred starting libp2p', err);
|
|
@@ -241,8 +242,7 @@ export class Libp2p extends TypedEventEmitter {
|
|
|
241
242
|
if (protocols.length === 0) {
|
|
242
243
|
throw new InvalidParametersError('no protocols were provided to open a stream');
|
|
243
244
|
}
|
|
244
|
-
|
|
245
|
-
return connection.newStream(protocols, options);
|
|
245
|
+
return this.components.connectionManager.openStream(peer, protocols, options);
|
|
246
246
|
}
|
|
247
247
|
getMultiaddrs() {
|
|
248
248
|
return this.components.addressManager.getAddresses();
|
|
@@ -252,7 +252,7 @@ export class Libp2p extends TypedEventEmitter {
|
|
|
252
252
|
}
|
|
253
253
|
async hangUp(peer, options = {}) {
|
|
254
254
|
if (isMultiaddr(peer)) {
|
|
255
|
-
peer = peerIdFromString(peer.
|
|
255
|
+
peer = peerIdFromString(peer.getComponents().findLast(c => c.code === CODE_P2P)?.value ?? '');
|
|
256
256
|
}
|
|
257
257
|
await this.components.connectionManager.closeConnections(peer, options);
|
|
258
258
|
}
|
|
@@ -307,6 +307,12 @@ export class Libp2p extends TypedEventEmitter {
|
|
|
307
307
|
unregister(id) {
|
|
308
308
|
this.components.registrar.unregister(id);
|
|
309
309
|
}
|
|
310
|
+
use(protocol, middleware) {
|
|
311
|
+
this.components.registrar.use(protocol, Array.isArray(middleware) ? middleware : [middleware]);
|
|
312
|
+
}
|
|
313
|
+
unuse(protocol) {
|
|
314
|
+
this.components.registrar.unuse(protocol);
|
|
315
|
+
}
|
|
310
316
|
async isDialable(multiaddr, options = {}) {
|
|
311
317
|
return this.components.connectionManager.isDialable(multiaddr, options);
|
|
312
318
|
}
|