@libp2p/utils 3.0.13 → 4.0.0-58421e11
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 +3 -3
- package/dist/src/address-sort.d.ts +1 -1
- package/dist/src/ip-port-to-multiaddr.js +1 -1
- package/dist/src/ip-port-to-multiaddr.js.map +1 -1
- package/dist/src/stream-to-ma-conn.d.ts +3 -22
- package/dist/src/stream-to-ma-conn.d.ts.map +1 -1
- package/dist/src/stream-to-ma-conn.js +11 -14
- package/dist/src/stream-to-ma-conn.js.map +1 -1
- package/package.json +12 -106
- package/src/address-sort.ts +1 -1
- package/src/ip-port-to-multiaddr.ts +1 -1
- package/src/stream-to-ma-conn.ts +14 -41
- package/dist/typedoc-urls.json +0 -13
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](http://libp2p.io/)
|
|
4
4
|
[](https://discuss.libp2p.io)
|
|
5
|
-
[](https://codecov.io/gh/libp2p/js-libp2p)
|
|
6
|
+
[](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)
|
|
7
7
|
|
|
8
8
|
> Package to aggregate shared logic and dependencies for the libp2p ecosystem
|
|
9
9
|
|
|
@@ -51,7 +51,7 @@ You can check the [API docs](https://libp2p.github.io/js-libp2p-utils).
|
|
|
51
51
|
|
|
52
52
|
## API Docs
|
|
53
53
|
|
|
54
|
-
- <https://libp2p.github.io/js-libp2p
|
|
54
|
+
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_utils.html>
|
|
55
55
|
|
|
56
56
|
## License
|
|
57
57
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* // ['/ip4/82.41.53.1/tcp/9000', '/ip4/127.0.0.1/tcp/9000']
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
import type { Address } from '@libp2p/interface
|
|
22
|
+
import type { Address } from '@libp2p/interface/peer-store';
|
|
23
23
|
/**
|
|
24
24
|
* Compare function for array.sort().
|
|
25
25
|
* This sort aims to move the private addresses to the end of the array.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address4, Address6 } from '@achingbrain/ip-address';
|
|
2
|
-
import { CodeError } from '@libp2p/
|
|
2
|
+
import { CodeError } from '@libp2p/interface/errors';
|
|
3
3
|
import { logger } from '@libp2p/logger';
|
|
4
4
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
5
5
|
const log = logger('libp2p:ip-port-to-multiaddr');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ip-port-to-multiaddr.js","sourceRoot":"","sources":["../../src/ip-port-to-multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAkB,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnE,MAAM,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,wBAAwB,EAAE,0BAA0B;IACpD,0BAA0B,EAAE,4BAA4B;IACxD,cAAc,EAAE,gBAAgB;CACjC,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,EAAU,EAAE,IAAqB;IAClE,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC1B,MAAM,IAAI,SAAS,CAAC,wBAAwB,EAAE,EAAE,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAA,CAAC,uEAAuE;KAC3J;IAED,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QAC5B,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;KACtB;IAED,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,MAAM,IAAI,SAAS,CAAC,0BAA0B,IAAI,EAAE,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAA;KACzF;IAED,IAAI;QACF,kBAAkB;QAClB,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA,CAAC,6BAA6B;QAC9C,OAAO,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KAC3C;IAAC,MAAM,GAAE;IAEV,IAAI;QACF,kBAAkB;QAClB,MAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC5B,OAAO,GAAG,CAAC,GAAG,EAAE;YACd,CAAC,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,IAAI,EAAE,CAAC;YAC1D,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;KACxC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,GAAG,6CAA6C,EAAE,IAAI,IAAI,EAAE,CAAA;QACxE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QACjB,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;KACnD;AACH,CAAC"}
|
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import type { MultiaddrConnection } from '@libp2p/interface
|
|
1
|
+
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection';
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
-
import type { Duplex, Source } from 'it-stream-types';
|
|
4
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
5
|
-
export interface Timeline {
|
|
6
|
-
/**
|
|
7
|
-
* Connection opening timestamp
|
|
8
|
-
*/
|
|
9
|
-
open: number;
|
|
10
|
-
/**
|
|
11
|
-
* Connection upgraded timestamp
|
|
12
|
-
*/
|
|
13
|
-
upgraded?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Connection closed timestamp
|
|
16
|
-
*/
|
|
17
|
-
close?: number;
|
|
18
|
-
}
|
|
19
|
-
export interface StreamOptions {
|
|
20
|
-
signal?: AbortSignal;
|
|
21
|
-
}
|
|
22
3
|
export interface StreamProperties {
|
|
23
|
-
stream:
|
|
4
|
+
stream: Stream;
|
|
24
5
|
remoteAddr: Multiaddr;
|
|
25
6
|
localAddr: Multiaddr;
|
|
26
7
|
}
|
|
@@ -28,5 +9,5 @@ export interface StreamProperties {
|
|
|
28
9
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
29
10
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
30
11
|
*/
|
|
31
|
-
export declare function streamToMaConnection(props: StreamProperties
|
|
12
|
+
export declare function streamToMaConnection(props: StreamProperties): MultiaddrConnection;
|
|
32
13
|
//# sourceMappingURL=stream-to-ma-conn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.d.ts","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,CAAA;IACrB,SAAS,EAAE,SAAS,CAAA;CACrB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,CAiDlF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger';
|
|
2
|
-
import { abortableSource } from 'abortable-iterator';
|
|
3
2
|
const log = logger('libp2p:stream:converter');
|
|
4
3
|
/**
|
|
5
4
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
6
5
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
7
6
|
*/
|
|
8
|
-
export function streamToMaConnection(props
|
|
7
|
+
export function streamToMaConnection(props) {
|
|
9
8
|
const { stream, remoteAddr } = props;
|
|
10
9
|
const { sink, source } = stream;
|
|
11
10
|
const mapSource = (async function* () {
|
|
@@ -20,12 +19,9 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
20
19
|
}());
|
|
21
20
|
const maConn = {
|
|
22
21
|
async sink(source) {
|
|
23
|
-
if (options.signal != null) {
|
|
24
|
-
source = abortableSource(source, options.signal);
|
|
25
|
-
}
|
|
26
22
|
try {
|
|
27
23
|
await sink(source);
|
|
28
|
-
|
|
24
|
+
close();
|
|
29
25
|
}
|
|
30
26
|
catch (err) {
|
|
31
27
|
// If aborted we can safely ignore
|
|
@@ -37,21 +33,22 @@ export function streamToMaConnection(props, options = {}) {
|
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
},
|
|
40
|
-
source:
|
|
36
|
+
source: mapSource,
|
|
41
37
|
remoteAddr,
|
|
42
38
|
timeline: { open: Date.now(), close: undefined },
|
|
43
|
-
async close() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
async close(options) {
|
|
40
|
+
close();
|
|
41
|
+
await stream.close(options);
|
|
42
|
+
},
|
|
43
|
+
abort(err) {
|
|
44
|
+
close();
|
|
45
|
+
stream.abort(err);
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
|
-
|
|
48
|
+
function close() {
|
|
51
49
|
if (maConn.timeline.close == null) {
|
|
52
50
|
maConn.timeline.close = Date.now();
|
|
53
51
|
}
|
|
54
|
-
await Promise.resolve();
|
|
55
52
|
}
|
|
56
53
|
return maConn;
|
|
57
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"stream-to-ma-conn.js","sourceRoot":"","sources":["../../src/stream-to-ma-conn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAKvC,MAAM,GAAG,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAA;AAQ7C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,KAAuB;IAC3D,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IACpC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAE/B,MAAM,SAAS,GAAG,CAAC,KAAK,SAAU,CAAC;QACjC,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;YAC/B,IAAI,IAAI,YAAY,UAAU,EAAE;gBAC9B,MAAM,IAAI,CAAA;aACX;iBAAM;gBACL,KAAM,CAAC,CAAC,IAAI,CAAA;aACb;SACF;IACH,CAAC,EAAE,CAAC,CAAA;IAEJ,MAAM,MAAM,GAAwB;QAClC,KAAK,CAAC,IAAI,CAAE,MAAM;YAChB,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClB,KAAK,EAAE,CAAA;aACR;YAAC,OAAO,GAAQ,EAAE;gBACjB,kCAAkC;gBAClC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE;oBAC1B,uEAAuE;oBACvE,gEAAgE;oBAChE,uEAAuE;oBACvE,GAAG,CAAC,GAAG,CAAC,CAAA;iBACT;aACF;QACH,CAAC;QACD,MAAM,EAAE,SAAS;QACjB,UAAU;QACV,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;QAChD,KAAK,CAAC,KAAK,CAAE,OAAsB;YACjC,KAAK,EAAE,CAAA;YACP,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;QACD,KAAK,CAAE,GAAU;YACf,KAAK,EAAE,CAAA;YACP,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;KACF,CAAA;IAED,SAAS,KAAK;QACZ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,EAAE;YACjC,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;SACnC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-58421e11",
|
|
4
4
|
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/utils#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/libp2p/js-libp2p
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/libp2p/js-libp2p
|
|
13
|
-
},
|
|
14
|
-
"engines": {
|
|
15
|
-
"node": ">=16.0.0",
|
|
16
|
-
"npm": ">=7.0.0"
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p/issues"
|
|
17
13
|
},
|
|
18
14
|
"type": "module",
|
|
19
15
|
"types": "./dist/src/index.d.ts",
|
|
@@ -75,124 +71,34 @@
|
|
|
75
71
|
"sourceType": "module"
|
|
76
72
|
}
|
|
77
73
|
},
|
|
78
|
-
"release": {
|
|
79
|
-
"branches": [
|
|
80
|
-
"master"
|
|
81
|
-
],
|
|
82
|
-
"plugins": [
|
|
83
|
-
[
|
|
84
|
-
"@semantic-release/commit-analyzer",
|
|
85
|
-
{
|
|
86
|
-
"preset": "conventionalcommits",
|
|
87
|
-
"releaseRules": [
|
|
88
|
-
{
|
|
89
|
-
"breaking": true,
|
|
90
|
-
"release": "major"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"revert": true,
|
|
94
|
-
"release": "patch"
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"type": "feat",
|
|
98
|
-
"release": "minor"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
"type": "fix",
|
|
102
|
-
"release": "patch"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"type": "docs",
|
|
106
|
-
"release": "patch"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
"type": "test",
|
|
110
|
-
"release": "patch"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"type": "deps",
|
|
114
|
-
"release": "patch"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"scope": "no-release",
|
|
118
|
-
"release": false
|
|
119
|
-
}
|
|
120
|
-
]
|
|
121
|
-
}
|
|
122
|
-
],
|
|
123
|
-
[
|
|
124
|
-
"@semantic-release/release-notes-generator",
|
|
125
|
-
{
|
|
126
|
-
"preset": "conventionalcommits",
|
|
127
|
-
"presetConfig": {
|
|
128
|
-
"types": [
|
|
129
|
-
{
|
|
130
|
-
"type": "feat",
|
|
131
|
-
"section": "Features"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"type": "fix",
|
|
135
|
-
"section": "Bug Fixes"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
"type": "chore",
|
|
139
|
-
"section": "Trivial Changes"
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"type": "docs",
|
|
143
|
-
"section": "Documentation"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
"type": "deps",
|
|
147
|
-
"section": "Dependencies"
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
"type": "test",
|
|
151
|
-
"section": "Tests"
|
|
152
|
-
}
|
|
153
|
-
]
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
],
|
|
157
|
-
"@semantic-release/changelog",
|
|
158
|
-
"@semantic-release/npm",
|
|
159
|
-
"@semantic-release/github",
|
|
160
|
-
"@semantic-release/git"
|
|
161
|
-
]
|
|
162
|
-
},
|
|
163
74
|
"scripts": {
|
|
164
75
|
"clean": "aegir clean",
|
|
165
76
|
"lint": "aegir lint",
|
|
166
77
|
"dep-check": "aegir dep-check",
|
|
167
78
|
"build": "aegir build",
|
|
168
|
-
"docs": "aegir docs",
|
|
169
79
|
"test": "aegir test",
|
|
170
80
|
"test:chrome": "aegir test -t browser --cov",
|
|
171
81
|
"test:chrome-webworker": "aegir test -t webworker",
|
|
172
82
|
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
173
83
|
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
174
84
|
"test:node": "aegir test -t node --cov",
|
|
175
|
-
"test:electron-main": "aegir test -t electron-main"
|
|
176
|
-
"release": "aegir release"
|
|
85
|
+
"test:electron-main": "aegir test -t electron-main"
|
|
177
86
|
},
|
|
178
87
|
"dependencies": {
|
|
179
88
|
"@achingbrain/ip-address": "^8.1.0",
|
|
180
|
-
"@libp2p/interface
|
|
181
|
-
"@libp2p/
|
|
182
|
-
"@
|
|
183
|
-
"@libp2p/logger": "^2.0.0",
|
|
184
|
-
"@multiformats/multiaddr": "^12.0.0",
|
|
185
|
-
"abortable-iterator": "^5.0.0",
|
|
89
|
+
"@libp2p/interface": "0.1.0-58421e11",
|
|
90
|
+
"@libp2p/logger": "3.0.0-58421e11",
|
|
91
|
+
"@multiformats/multiaddr": "^12.1.3",
|
|
186
92
|
"is-loopback-addr": "^2.0.1",
|
|
187
93
|
"it-stream-types": "^2.0.1",
|
|
188
94
|
"private-ip": "^3.0.0",
|
|
189
|
-
"uint8arraylist": "^2.3
|
|
95
|
+
"uint8arraylist": "^2.4.3"
|
|
190
96
|
},
|
|
191
97
|
"devDependencies": {
|
|
192
|
-
"aegir": "^40.0.
|
|
98
|
+
"aegir": "^40.0.1",
|
|
193
99
|
"it-all": "^3.0.1",
|
|
194
100
|
"it-pair": "^2.0.6",
|
|
195
|
-
"it-pipe": "^3.0.
|
|
196
|
-
"uint8arrays": "^4.0.
|
|
101
|
+
"it-pipe": "^3.0.1",
|
|
102
|
+
"uint8arrays": "^4.0.4"
|
|
197
103
|
}
|
|
198
104
|
}
|
package/src/address-sort.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address4, Address6 } from '@achingbrain/ip-address'
|
|
2
|
-
import { CodeError } from '@libp2p/
|
|
2
|
+
import { CodeError } from '@libp2p/interface/errors'
|
|
3
3
|
import { logger } from '@libp2p/logger'
|
|
4
4
|
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
|
|
5
5
|
|
package/src/stream-to-ma-conn.ts
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import {
|
|
3
|
-
import type { MultiaddrConnection } from '@libp2p/interface
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interface'
|
|
3
|
+
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection'
|
|
4
4
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
|
-
import type { Duplex, Source } from 'it-stream-types'
|
|
6
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
7
5
|
|
|
8
6
|
const log = logger('libp2p:stream:converter')
|
|
9
7
|
|
|
10
|
-
export interface Timeline {
|
|
11
|
-
/**
|
|
12
|
-
* Connection opening timestamp
|
|
13
|
-
*/
|
|
14
|
-
open: number
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Connection upgraded timestamp
|
|
18
|
-
*/
|
|
19
|
-
upgraded?: number
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Connection closed timestamp
|
|
23
|
-
*/
|
|
24
|
-
close?: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface StreamOptions {
|
|
28
|
-
signal?: AbortSignal
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
8
|
export interface StreamProperties {
|
|
33
|
-
stream:
|
|
9
|
+
stream: Stream
|
|
34
10
|
remoteAddr: Multiaddr
|
|
35
11
|
localAddr: Multiaddr
|
|
36
12
|
}
|
|
@@ -39,7 +15,7 @@ export interface StreamProperties {
|
|
|
39
15
|
* Convert a duplex iterable into a MultiaddrConnection.
|
|
40
16
|
* https://github.com/libp2p/interface-transport#multiaddrconnection
|
|
41
17
|
*/
|
|
42
|
-
export function streamToMaConnection (props: StreamProperties
|
|
18
|
+
export function streamToMaConnection (props: StreamProperties): MultiaddrConnection {
|
|
43
19
|
const { stream, remoteAddr } = props
|
|
44
20
|
const { sink, source } = stream
|
|
45
21
|
|
|
@@ -55,13 +31,9 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
55
31
|
|
|
56
32
|
const maConn: MultiaddrConnection = {
|
|
57
33
|
async sink (source) {
|
|
58
|
-
if (options.signal != null) {
|
|
59
|
-
source = abortableSource(source, options.signal)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
34
|
try {
|
|
63
35
|
await sink(source)
|
|
64
|
-
|
|
36
|
+
close()
|
|
65
37
|
} catch (err: any) {
|
|
66
38
|
// If aborted we can safely ignore
|
|
67
39
|
if (err.type !== 'aborted') {
|
|
@@ -72,22 +44,23 @@ export function streamToMaConnection (props: StreamProperties, options: StreamOp
|
|
|
72
44
|
}
|
|
73
45
|
}
|
|
74
46
|
},
|
|
75
|
-
source:
|
|
47
|
+
source: mapSource,
|
|
76
48
|
remoteAddr,
|
|
77
49
|
timeline: { open: Date.now(), close: undefined },
|
|
78
|
-
async close () {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
async close (options?: AbortOptions) {
|
|
51
|
+
close()
|
|
52
|
+
await stream.close(options)
|
|
53
|
+
},
|
|
54
|
+
abort (err: Error): void {
|
|
55
|
+
close()
|
|
56
|
+
stream.abort(err)
|
|
83
57
|
}
|
|
84
58
|
}
|
|
85
59
|
|
|
86
|
-
|
|
60
|
+
function close (): void {
|
|
87
61
|
if (maConn.timeline.close == null) {
|
|
88
62
|
maConn.timeline.close = Date.now()
|
|
89
63
|
}
|
|
90
|
-
await Promise.resolve()
|
|
91
64
|
}
|
|
92
65
|
|
|
93
66
|
return maConn
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"publicAddressesFirst": "https://libp2p.github.io/js-libp2p-utils/functions/address_sort.publicAddressesFirst.html",
|
|
3
|
-
"something": "https://libp2p.github.io/js-libp2p-utils/functions/address_sort.something.html",
|
|
4
|
-
"arrayEquals": "https://libp2p.github.io/js-libp2p-utils/functions/array_equals.arrayEquals.html",
|
|
5
|
-
"Errors": "https://libp2p.github.io/js-libp2p-utils/variables/ip_port_to_multiaddr.Errors.html",
|
|
6
|
-
"ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p-utils/functions/ip_port_to_multiaddr.ipPortToMultiaddr.html",
|
|
7
|
-
"isLoopback": "https://libp2p.github.io/js-libp2p-utils/functions/multiaddr_is_loopback.isLoopback.html",
|
|
8
|
-
"isPrivate": "https://libp2p.github.io/js-libp2p-utils/functions/multiaddr_is_private.isPrivate.html",
|
|
9
|
-
"StreamOptions": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.StreamOptions.html",
|
|
10
|
-
"StreamProperties": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.StreamProperties.html",
|
|
11
|
-
"Timeline": "https://libp2p.github.io/js-libp2p-utils/interfaces/stream_to_ma_conn.Timeline.html",
|
|
12
|
-
"streamToMaConnection": "https://libp2p.github.io/js-libp2p-utils/functions/stream_to_ma_conn.streamToMaConnection.html"
|
|
13
|
-
}
|