libp2p 2.9.0 → 2.10.0-8484de8a2
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 -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 +40 -44
- 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 +3 -9
- package/dist/src/config/connection-gater.browser.js.map +1 -1
- package/dist/src/config.js +1 -1
- 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 +13 -25
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +10 -2
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +45 -27
- 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 +62 -0
- package/dist/src/connection.d.ts.map +1 -0
- package/dist/src/connection.js +239 -0
- package/dist/src/connection.js.map +1 -0
- 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.map +1 -1
- package/dist/src/libp2p.js +5 -5
- 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 +3 -3
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +50 -41
- 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 +27 -25
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +97 -336
- 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 +26 -30
- package/src/address-manager/dns-mappings.ts +51 -51
- 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 +3 -12
- package/src/config.ts +1 -1
- 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 +14 -29
- package/src/connection-manager/index.ts +62 -29
- 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 +316 -0
- package/src/get-peer.ts +3 -3
- package/src/index.ts +2 -2
- package/src/libp2p.ts +5 -6
- package/src/peer-routing.ts +1 -1
- package/src/random-walk.ts +13 -3
- package/src/registrar.ts +67 -54
- package/src/transport-manager.ts +18 -2
- package/src/upgrader.ts +143 -421
- package/src/utils.ts +31 -0
- package/src/version.ts +1 -1
- package/dist/src/connection/index.d.ts +0 -84
- package/dist/src/connection/index.d.ts.map +0 -1
- package/dist/src/connection/index.js +0 -144
- package/dist/src/connection/index.js.map +0 -1
- package/dist/typedoc-urls.json +0 -24
- package/src/connection/index.ts +0 -199
package/src/utils.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MessageStream } from '@libp2p/interface'
|
|
2
|
+
|
|
3
|
+
export function redirect (channelA: MessageStream, channelB: MessageStream): void {
|
|
4
|
+
channelA.addEventListener('message', (evt) => {
|
|
5
|
+
const sendMore = channelB.send(evt.data)
|
|
6
|
+
|
|
7
|
+
if (sendMore === false) {
|
|
8
|
+
channelA.pause()
|
|
9
|
+
|
|
10
|
+
channelA.addEventListener('drain', () => {
|
|
11
|
+
channelA.resume()
|
|
12
|
+
}, {
|
|
13
|
+
once: true
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
channelB.addEventListener('message', (evt) => {
|
|
19
|
+
const sendMore = channelA.send(evt.data)
|
|
20
|
+
|
|
21
|
+
if (sendMore === false) {
|
|
22
|
+
channelB.pause()
|
|
23
|
+
|
|
24
|
+
channelB.addEventListener('drain', () => {
|
|
25
|
+
channelB.resume()
|
|
26
|
+
}, {
|
|
27
|
+
once: true
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.10.0-8484de8a2'
|
|
2
2
|
export const name = 'js-libp2p'
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { connectionSymbol } from '@libp2p/interface';
|
|
2
|
-
import type { AbortOptions, Logger, ComponentLogger, Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions, PeerId, ConnectionLimits } from '@libp2p/interface';
|
|
3
|
-
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
4
|
-
interface ConnectionInit {
|
|
5
|
-
remoteAddr: Multiaddr;
|
|
6
|
-
remotePeer: PeerId;
|
|
7
|
-
newStream(protocols: string[], options?: AbortOptions): Promise<Stream>;
|
|
8
|
-
close(options?: AbortOptions): Promise<void>;
|
|
9
|
-
abort(err: Error): void;
|
|
10
|
-
getStreams(): Stream[];
|
|
11
|
-
status: ConnectionStatus;
|
|
12
|
-
direction: Direction;
|
|
13
|
-
timeline: ConnectionTimeline;
|
|
14
|
-
multiplexer?: string;
|
|
15
|
-
encryption?: string;
|
|
16
|
-
limits?: ConnectionLimits;
|
|
17
|
-
logger: ComponentLogger;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* An implementation of the js-libp2p connection.
|
|
21
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
22
|
-
*/
|
|
23
|
-
export declare class ConnectionImpl implements Connection {
|
|
24
|
-
/**
|
|
25
|
-
* Connection identifier.
|
|
26
|
-
*/
|
|
27
|
-
readonly id: string;
|
|
28
|
-
/**
|
|
29
|
-
* Observed multiaddr of the remote peer
|
|
30
|
-
*/
|
|
31
|
-
readonly remoteAddr: Multiaddr;
|
|
32
|
-
/**
|
|
33
|
-
* Remote peer id
|
|
34
|
-
*/
|
|
35
|
-
readonly remotePeer: PeerId;
|
|
36
|
-
direction: Direction;
|
|
37
|
-
timeline: ConnectionTimeline;
|
|
38
|
-
multiplexer?: string;
|
|
39
|
-
encryption?: string;
|
|
40
|
-
status: ConnectionStatus;
|
|
41
|
-
limits?: ConnectionLimits;
|
|
42
|
-
readonly log: Logger;
|
|
43
|
-
/**
|
|
44
|
-
* User provided tags
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
tags: string[];
|
|
48
|
-
/**
|
|
49
|
-
* Reference to the new stream function of the multiplexer
|
|
50
|
-
*/
|
|
51
|
-
private readonly _newStream;
|
|
52
|
-
/**
|
|
53
|
-
* Reference to the close function of the raw connection
|
|
54
|
-
*/
|
|
55
|
-
private readonly _close;
|
|
56
|
-
private readonly _abort;
|
|
57
|
-
/**
|
|
58
|
-
* Reference to the getStreams function of the muxer
|
|
59
|
-
*/
|
|
60
|
-
private readonly _getStreams;
|
|
61
|
-
/**
|
|
62
|
-
* An implementation of the js-libp2p connection.
|
|
63
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
64
|
-
*/
|
|
65
|
-
constructor(init: ConnectionInit);
|
|
66
|
-
readonly [Symbol.toStringTag] = "Connection";
|
|
67
|
-
readonly [connectionSymbol] = true;
|
|
68
|
-
/**
|
|
69
|
-
* Get all the streams of the muxer
|
|
70
|
-
*/
|
|
71
|
-
get streams(): Stream[];
|
|
72
|
-
/**
|
|
73
|
-
* Create a new stream from this connection
|
|
74
|
-
*/
|
|
75
|
-
newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>;
|
|
76
|
-
/**
|
|
77
|
-
* Close the connection
|
|
78
|
-
*/
|
|
79
|
-
close(options?: AbortOptions): Promise<void>;
|
|
80
|
-
abort(err: Error): void;
|
|
81
|
-
}
|
|
82
|
-
export declare function createConnection(init: ConnectionInit): Connection;
|
|
83
|
-
export {};
|
|
84
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAyE,MAAM,mBAAmB,CAAA;AAE3H,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAC/L,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,UAAU,cAAc;IACtB,UAAU,EAAE,SAAS,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C,KAAK,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAA;IACvB,UAAU,IAAI,MAAM,EAAE,CAAA;IACtB,MAAM,EAAE,gBAAgB,CAAA;IACxB,SAAS,EAAE,SAAS,CAAA;IACpB,QAAQ,EAAE,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AAO,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmCvD,KAAK,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI;CAezB;AAED,wBAAgB,gBAAgB,CAAE,IAAI,EAAE,cAAc,GAAG,UAAU,CAElE"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { connectionSymbol, LimitedConnectionError, ConnectionClosedError, ConnectionClosingError } from '@libp2p/interface';
|
|
2
|
-
import { setMaxListeners } from 'main-event';
|
|
3
|
-
const CLOSE_TIMEOUT = 500;
|
|
4
|
-
/**
|
|
5
|
-
* An implementation of the js-libp2p connection.
|
|
6
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
7
|
-
*/
|
|
8
|
-
export class ConnectionImpl {
|
|
9
|
-
/**
|
|
10
|
-
* Connection identifier.
|
|
11
|
-
*/
|
|
12
|
-
id;
|
|
13
|
-
/**
|
|
14
|
-
* Observed multiaddr of the remote peer
|
|
15
|
-
*/
|
|
16
|
-
remoteAddr;
|
|
17
|
-
/**
|
|
18
|
-
* Remote peer id
|
|
19
|
-
*/
|
|
20
|
-
remotePeer;
|
|
21
|
-
direction;
|
|
22
|
-
timeline;
|
|
23
|
-
multiplexer;
|
|
24
|
-
encryption;
|
|
25
|
-
status;
|
|
26
|
-
limits;
|
|
27
|
-
log;
|
|
28
|
-
/**
|
|
29
|
-
* User provided tags
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
tags;
|
|
33
|
-
/**
|
|
34
|
-
* Reference to the new stream function of the multiplexer
|
|
35
|
-
*/
|
|
36
|
-
_newStream;
|
|
37
|
-
/**
|
|
38
|
-
* Reference to the close function of the raw connection
|
|
39
|
-
*/
|
|
40
|
-
_close;
|
|
41
|
-
_abort;
|
|
42
|
-
/**
|
|
43
|
-
* Reference to the getStreams function of the muxer
|
|
44
|
-
*/
|
|
45
|
-
_getStreams;
|
|
46
|
-
/**
|
|
47
|
-
* An implementation of the js-libp2p connection.
|
|
48
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
49
|
-
*/
|
|
50
|
-
constructor(init) {
|
|
51
|
-
const { remoteAddr, remotePeer, newStream, close, abort, getStreams } = init;
|
|
52
|
-
this.id = `${(parseInt(String(Math.random() * 1e9))).toString(36)}${Date.now()}`;
|
|
53
|
-
this.remoteAddr = remoteAddr;
|
|
54
|
-
this.remotePeer = remotePeer;
|
|
55
|
-
this.direction = init.direction;
|
|
56
|
-
this.status = 'open';
|
|
57
|
-
this.timeline = init.timeline;
|
|
58
|
-
this.multiplexer = init.multiplexer;
|
|
59
|
-
this.encryption = init.encryption;
|
|
60
|
-
this.limits = init.limits;
|
|
61
|
-
this.log = init.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`);
|
|
62
|
-
if (this.remoteAddr.getPeerId() == null) {
|
|
63
|
-
this.remoteAddr = this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`);
|
|
64
|
-
}
|
|
65
|
-
this._newStream = newStream;
|
|
66
|
-
this._close = close;
|
|
67
|
-
this._abort = abort;
|
|
68
|
-
this._getStreams = getStreams;
|
|
69
|
-
this.tags = [];
|
|
70
|
-
}
|
|
71
|
-
[Symbol.toStringTag] = 'Connection';
|
|
72
|
-
[connectionSymbol] = true;
|
|
73
|
-
/**
|
|
74
|
-
* Get all the streams of the muxer
|
|
75
|
-
*/
|
|
76
|
-
get streams() {
|
|
77
|
-
return this._getStreams();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Create a new stream from this connection
|
|
81
|
-
*/
|
|
82
|
-
async newStream(protocols, options) {
|
|
83
|
-
if (this.status === 'closing') {
|
|
84
|
-
throw new ConnectionClosingError('the connection is being closed');
|
|
85
|
-
}
|
|
86
|
-
if (this.status === 'closed') {
|
|
87
|
-
throw new ConnectionClosedError('the connection is closed');
|
|
88
|
-
}
|
|
89
|
-
if (!Array.isArray(protocols)) {
|
|
90
|
-
protocols = [protocols];
|
|
91
|
-
}
|
|
92
|
-
if (this.limits != null && options?.runOnLimitedConnection !== true) {
|
|
93
|
-
throw new LimitedConnectionError('Cannot open protocol stream on limited connection');
|
|
94
|
-
}
|
|
95
|
-
const stream = await this._newStream(protocols, options);
|
|
96
|
-
stream.direction = 'outbound';
|
|
97
|
-
return stream;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Close the connection
|
|
101
|
-
*/
|
|
102
|
-
async close(options = {}) {
|
|
103
|
-
if (this.status === 'closed' || this.status === 'closing') {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
this.log('closing connection to %a', this.remoteAddr);
|
|
107
|
-
this.status = 'closing';
|
|
108
|
-
if (options.signal == null) {
|
|
109
|
-
const signal = AbortSignal.timeout(CLOSE_TIMEOUT);
|
|
110
|
-
setMaxListeners(Infinity, signal);
|
|
111
|
-
options = {
|
|
112
|
-
...options,
|
|
113
|
-
signal
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
try {
|
|
117
|
-
this.log.trace('closing underlying transport');
|
|
118
|
-
// close raw connection
|
|
119
|
-
await this._close(options);
|
|
120
|
-
this.log.trace('updating timeline with close time');
|
|
121
|
-
this.status = 'closed';
|
|
122
|
-
this.timeline.close = Date.now();
|
|
123
|
-
}
|
|
124
|
-
catch (err) {
|
|
125
|
-
this.log.error('error encountered during graceful close of connection to %a', this.remoteAddr, err);
|
|
126
|
-
this.abort(err);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
abort(err) {
|
|
130
|
-
if (this.status === 'closed') {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
this.log.error('aborting connection to %a due to error', this.remoteAddr, err);
|
|
134
|
-
this.status = 'closing';
|
|
135
|
-
// Abort raw connection
|
|
136
|
-
this._abort(err);
|
|
137
|
-
this.status = 'closed';
|
|
138
|
-
this.timeline.close = Date.now();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export function createConnection(init) {
|
|
142
|
-
return new ConnectionImpl(init);
|
|
143
|
-
}
|
|
144
|
-
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CAAC,MAAM,GAAG,QAAQ,CAAA;YACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAClC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6DAA6D,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;YACnG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IAED,KAAK,CAAE,GAAU;QACf,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAM;QACR,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAE9E,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;QAEvB,uBAAuB;QACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAEhB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAA;QACtB,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAClC,CAAC;CACF;AAED,MAAM,UAAU,gBAAgB,CAAE,IAAoB;IACpD,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC"}
|
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
|
-
}
|
package/src/connection/index.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { connectionSymbol, LimitedConnectionError, ConnectionClosedError, ConnectionClosingError } from '@libp2p/interface'
|
|
2
|
-
import { setMaxListeners } from 'main-event'
|
|
3
|
-
import type { AbortOptions, Logger, ComponentLogger, Direction, Connection, Stream, ConnectionTimeline, ConnectionStatus, NewStreamOptions, PeerId, ConnectionLimits } from '@libp2p/interface'
|
|
4
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
|
-
|
|
6
|
-
const CLOSE_TIMEOUT = 500
|
|
7
|
-
|
|
8
|
-
interface ConnectionInit {
|
|
9
|
-
remoteAddr: Multiaddr
|
|
10
|
-
remotePeer: PeerId
|
|
11
|
-
newStream(protocols: string[], options?: AbortOptions): Promise<Stream>
|
|
12
|
-
close(options?: AbortOptions): Promise<void>
|
|
13
|
-
abort(err: Error): void
|
|
14
|
-
getStreams(): Stream[]
|
|
15
|
-
status: ConnectionStatus
|
|
16
|
-
direction: Direction
|
|
17
|
-
timeline: ConnectionTimeline
|
|
18
|
-
multiplexer?: string
|
|
19
|
-
encryption?: string
|
|
20
|
-
limits?: ConnectionLimits
|
|
21
|
-
logger: ComponentLogger
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* An implementation of the js-libp2p connection.
|
|
26
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
27
|
-
*/
|
|
28
|
-
export class ConnectionImpl implements Connection {
|
|
29
|
-
/**
|
|
30
|
-
* Connection identifier.
|
|
31
|
-
*/
|
|
32
|
-
public readonly id: string
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Observed multiaddr of the remote peer
|
|
36
|
-
*/
|
|
37
|
-
public readonly remoteAddr: Multiaddr
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Remote peer id
|
|
41
|
-
*/
|
|
42
|
-
public readonly remotePeer: PeerId
|
|
43
|
-
|
|
44
|
-
public direction: Direction
|
|
45
|
-
public timeline: ConnectionTimeline
|
|
46
|
-
public multiplexer?: string
|
|
47
|
-
public encryption?: string
|
|
48
|
-
public status: ConnectionStatus
|
|
49
|
-
public limits?: ConnectionLimits
|
|
50
|
-
public readonly log: Logger
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* User provided tags
|
|
54
|
-
*
|
|
55
|
-
*/
|
|
56
|
-
public tags: string[]
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Reference to the new stream function of the multiplexer
|
|
60
|
-
*/
|
|
61
|
-
private readonly _newStream: (protocols: string[], options?: NewStreamOptions) => Promise<Stream>
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Reference to the close function of the raw connection
|
|
65
|
-
*/
|
|
66
|
-
private readonly _close: (options?: AbortOptions) => Promise<void>
|
|
67
|
-
|
|
68
|
-
private readonly _abort: (err: Error) => void
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Reference to the getStreams function of the muxer
|
|
72
|
-
*/
|
|
73
|
-
private readonly _getStreams: () => Stream[]
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* An implementation of the js-libp2p connection.
|
|
77
|
-
* Any libp2p transport should use an upgrader to return this connection.
|
|
78
|
-
*/
|
|
79
|
-
constructor (init: ConnectionInit) {
|
|
80
|
-
const { remoteAddr, remotePeer, newStream, close, abort, getStreams } = init
|
|
81
|
-
|
|
82
|
-
this.id = `${(parseInt(String(Math.random() * 1e9))).toString(36)}${Date.now()}`
|
|
83
|
-
this.remoteAddr = remoteAddr
|
|
84
|
-
this.remotePeer = remotePeer
|
|
85
|
-
this.direction = init.direction
|
|
86
|
-
this.status = 'open'
|
|
87
|
-
this.timeline = init.timeline
|
|
88
|
-
this.multiplexer = init.multiplexer
|
|
89
|
-
this.encryption = init.encryption
|
|
90
|
-
this.limits = init.limits
|
|
91
|
-
this.log = init.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`)
|
|
92
|
-
|
|
93
|
-
if (this.remoteAddr.getPeerId() == null) {
|
|
94
|
-
this.remoteAddr = this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this._newStream = newStream
|
|
98
|
-
this._close = close
|
|
99
|
-
this._abort = abort
|
|
100
|
-
this._getStreams = getStreams
|
|
101
|
-
this.tags = []
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
readonly [Symbol.toStringTag] = 'Connection'
|
|
105
|
-
|
|
106
|
-
readonly [connectionSymbol] = true
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Get all the streams of the muxer
|
|
110
|
-
*/
|
|
111
|
-
get streams (): Stream[] {
|
|
112
|
-
return this._getStreams()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Create a new stream from this connection
|
|
117
|
-
*/
|
|
118
|
-
async newStream (protocols: string | string[], options?: NewStreamOptions): Promise<Stream> {
|
|
119
|
-
if (this.status === 'closing') {
|
|
120
|
-
throw new ConnectionClosingError('the connection is being closed')
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (this.status === 'closed') {
|
|
124
|
-
throw new ConnectionClosedError('the connection is closed')
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!Array.isArray(protocols)) {
|
|
128
|
-
protocols = [protocols]
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (this.limits != null && options?.runOnLimitedConnection !== true) {
|
|
132
|
-
throw new LimitedConnectionError('Cannot open protocol stream on limited connection')
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const stream = await this._newStream(protocols, options)
|
|
136
|
-
|
|
137
|
-
stream.direction = 'outbound'
|
|
138
|
-
|
|
139
|
-
return stream
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Close the connection
|
|
144
|
-
*/
|
|
145
|
-
async close (options: AbortOptions = {}): Promise<void> {
|
|
146
|
-
if (this.status === 'closed' || this.status === 'closing') {
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
this.log('closing connection to %a', this.remoteAddr)
|
|
151
|
-
|
|
152
|
-
this.status = 'closing'
|
|
153
|
-
|
|
154
|
-
if (options.signal == null) {
|
|
155
|
-
const signal = AbortSignal.timeout(CLOSE_TIMEOUT)
|
|
156
|
-
setMaxListeners(Infinity, signal)
|
|
157
|
-
|
|
158
|
-
options = {
|
|
159
|
-
...options,
|
|
160
|
-
signal
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
this.log.trace('closing underlying transport')
|
|
166
|
-
|
|
167
|
-
// close raw connection
|
|
168
|
-
await this._close(options)
|
|
169
|
-
|
|
170
|
-
this.log.trace('updating timeline with close time')
|
|
171
|
-
|
|
172
|
-
this.status = 'closed'
|
|
173
|
-
this.timeline.close = Date.now()
|
|
174
|
-
} catch (err: any) {
|
|
175
|
-
this.log.error('error encountered during graceful close of connection to %a', this.remoteAddr, err)
|
|
176
|
-
this.abort(err)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
abort (err: Error): void {
|
|
181
|
-
if (this.status === 'closed') {
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
this.log.error('aborting connection to %a due to error', this.remoteAddr, err)
|
|
186
|
-
|
|
187
|
-
this.status = 'closing'
|
|
188
|
-
|
|
189
|
-
// Abort raw connection
|
|
190
|
-
this._abort(err)
|
|
191
|
-
|
|
192
|
-
this.status = 'closed'
|
|
193
|
-
this.timeline.close = Date.now()
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function createConnection (init: ConnectionInit): Connection {
|
|
198
|
-
return new ConnectionImpl(init)
|
|
199
|
-
}
|