@libp2p/daemon-protocol 7.0.6 → 8.0.0-334f91bdc
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/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/daemon-protocol",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-334f91bdc",
|
|
4
4
|
"description": "Communication protocol between libp2p daemons and clients",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
7
|
-
"homepage": "https://github.com/libp2p/js-libp2p
|
|
7
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/libp2p-daemon-protocol#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/libp2p/js-libp2p
|
|
10
|
+
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/libp2p/js-libp2p
|
|
13
|
+
"url": "https://github.com/libp2p/js-libp2p/issues"
|
|
14
14
|
},
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public",
|
|
@@ -54,117 +54,21 @@
|
|
|
54
54
|
"import": "./dist/src/upgrader.js"
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
"release": {
|
|
58
|
-
"branches": [
|
|
59
|
-
"main"
|
|
60
|
-
],
|
|
61
|
-
"plugins": [
|
|
62
|
-
[
|
|
63
|
-
"@semantic-release/commit-analyzer",
|
|
64
|
-
{
|
|
65
|
-
"preset": "conventionalcommits",
|
|
66
|
-
"releaseRules": [
|
|
67
|
-
{
|
|
68
|
-
"breaking": true,
|
|
69
|
-
"release": "major"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"revert": true,
|
|
73
|
-
"release": "patch"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
"type": "feat",
|
|
77
|
-
"release": "minor"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"type": "fix",
|
|
81
|
-
"release": "patch"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"type": "docs",
|
|
85
|
-
"release": "patch"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
"type": "test",
|
|
89
|
-
"release": "patch"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"type": "deps",
|
|
93
|
-
"release": "patch"
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
"scope": "no-release",
|
|
97
|
-
"release": false
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
[
|
|
103
|
-
"@semantic-release/release-notes-generator",
|
|
104
|
-
{
|
|
105
|
-
"preset": "conventionalcommits",
|
|
106
|
-
"presetConfig": {
|
|
107
|
-
"types": [
|
|
108
|
-
{
|
|
109
|
-
"type": "feat",
|
|
110
|
-
"section": "Features"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"type": "fix",
|
|
114
|
-
"section": "Bug Fixes"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"type": "chore",
|
|
118
|
-
"section": "Trivial Changes"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
"type": "docs",
|
|
122
|
-
"section": "Documentation"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"type": "deps",
|
|
126
|
-
"section": "Dependencies"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"type": "test",
|
|
130
|
-
"section": "Tests"
|
|
131
|
-
}
|
|
132
|
-
]
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
"@semantic-release/changelog",
|
|
137
|
-
"@semantic-release/npm",
|
|
138
|
-
"@semantic-release/github",
|
|
139
|
-
[
|
|
140
|
-
"@semantic-release/git",
|
|
141
|
-
{
|
|
142
|
-
"assets": [
|
|
143
|
-
"CHANGELOG.md",
|
|
144
|
-
"package.json"
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
57
|
"scripts": {
|
|
151
58
|
"clean": "aegir clean",
|
|
152
59
|
"lint": "aegir lint",
|
|
153
60
|
"generate": "protons ./src/index.proto",
|
|
154
61
|
"build": "aegir build",
|
|
155
|
-
"dep-check": "aegir dep-check"
|
|
156
|
-
"release": "aegir release"
|
|
62
|
+
"dep-check": "aegir dep-check"
|
|
157
63
|
},
|
|
158
64
|
"dependencies": {
|
|
159
|
-
"@libp2p/interface": "
|
|
160
|
-
"@libp2p/logger": "^5.1.21",
|
|
65
|
+
"@libp2p/interface": "3.0.0-334f91bdc",
|
|
161
66
|
"any-signal": "^4.1.1",
|
|
162
|
-
"it-length-prefixed-stream": "^2.0.3",
|
|
163
67
|
"protons-runtime": "^5.6.0",
|
|
164
68
|
"uint8arraylist": "^2.4.8"
|
|
165
69
|
},
|
|
166
70
|
"devDependencies": {
|
|
167
|
-
"aegir": "^47.0.
|
|
71
|
+
"aegir": "^47.0.22",
|
|
168
72
|
"protons": "^7.7.0"
|
|
169
73
|
}
|
|
170
74
|
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { MultiaddrConnection } from '@libp2p/interface';
|
|
2
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
-
export interface StreamHandlerOptions {
|
|
4
|
-
stream: MultiaddrConnection;
|
|
5
|
-
maxLength?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare class StreamHandler {
|
|
8
|
-
private readonly stream;
|
|
9
|
-
private readonly lp;
|
|
10
|
-
/**
|
|
11
|
-
* Create a stream handler for connection
|
|
12
|
-
*/
|
|
13
|
-
constructor(opts: StreamHandlerOptions);
|
|
14
|
-
/**
|
|
15
|
-
* Read and decode message
|
|
16
|
-
*/
|
|
17
|
-
read(): Promise<Uint8ArrayList | undefined>;
|
|
18
|
-
write(msg: Uint8Array | Uint8ArrayList): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Return the handshake rest stream and invalidate handler
|
|
21
|
-
*/
|
|
22
|
-
rest(): MultiaddrConnection;
|
|
23
|
-
/**
|
|
24
|
-
* Close the stream
|
|
25
|
-
*/
|
|
26
|
-
close(): Promise<void>;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=stream-handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../src/stream-handler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,mBAAmB,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,EAAE,CAA2C;IAE9D;;OAEG;gBACU,IAAI,EAAE,oBAAoB;IAOvC;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAQ5C,KAAK,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7D;;OAEG;IACH,IAAI,IAAK,mBAAmB;IAI5B;;OAEG;IACG,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;CAI9B"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
|
-
import { lpStream } from 'it-length-prefixed-stream';
|
|
3
|
-
const log = logger('libp2p:daemon-protocol:stream-handler');
|
|
4
|
-
export class StreamHandler {
|
|
5
|
-
stream;
|
|
6
|
-
lp;
|
|
7
|
-
/**
|
|
8
|
-
* Create a stream handler for connection
|
|
9
|
-
*/
|
|
10
|
-
constructor(opts) {
|
|
11
|
-
const { stream, maxLength } = opts;
|
|
12
|
-
this.stream = stream;
|
|
13
|
-
this.lp = lpStream(this.stream, { maxDataLength: maxLength ?? 4096 });
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Read and decode message
|
|
17
|
-
*/
|
|
18
|
-
async read() {
|
|
19
|
-
try {
|
|
20
|
-
return await this.lp.read();
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
log.error('read received no value', err);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async write(msg) {
|
|
27
|
-
log('write message');
|
|
28
|
-
await this.lp.write(msg);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Return the handshake rest stream and invalidate handler
|
|
32
|
-
*/
|
|
33
|
-
rest() {
|
|
34
|
-
return this.lp.unwrap();
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Close the stream
|
|
38
|
-
*/
|
|
39
|
-
async close() {
|
|
40
|
-
log('closing the stream');
|
|
41
|
-
await this.rest().close();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//# sourceMappingURL=stream-handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.js","sourceRoot":"","sources":["../../src/stream-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAKpD,MAAM,GAAG,GAAG,MAAM,CAAC,uCAAuC,CAAC,CAAA;AAO3D,MAAM,OAAO,aAAa;IACP,MAAM,CAAqB;IAC3B,EAAE,CAA2C;IAE9D;;OAEG;IACH,YAAa,IAA0B;QACrC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAElC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,SAAS,IAAI,IAAI,EAAE,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAE,GAAgC;QAC3C,GAAG,CAAC,eAAe,CAAC,CAAA;QACpB,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,CAAA;IACzB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,GAAG,CAAC,oBAAoB,CAAC,CAAA;QACzB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;CACF"}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"codec": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.ConnectRequest.codec.html",
|
|
3
|
-
".:codec": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.StreamOpenRequest.codec.html",
|
|
4
|
-
"decode": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.ConnectRequest.decode.html",
|
|
5
|
-
".:decode": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.StreamOpenRequest.decode.html",
|
|
6
|
-
"encode": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.ConnectRequest.encode.html",
|
|
7
|
-
".:encode": "https://libp2p.github.io/js-libp2p-daemon/functions/_libp2p_daemon-protocol.index.StreamOpenRequest.encode.html",
|
|
8
|
-
"Type": "https://libp2p.github.io/js-libp2p-daemon/enums/_libp2p_daemon-protocol.index.ConnManagerRequest.Type.html",
|
|
9
|
-
".:Type": "https://libp2p.github.io/js-libp2p-daemon/enums/_libp2p_daemon-protocol.index.Response.Type.html",
|
|
10
|
-
"ConnectRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ConnectRequest.html",
|
|
11
|
-
".:ConnectRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ConnectRequest.html",
|
|
12
|
-
"ConnManagerRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ConnManagerRequest.html",
|
|
13
|
-
".:ConnManagerRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ConnManagerRequest.html",
|
|
14
|
-
"DHTRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DHTRequest.html",
|
|
15
|
-
".:DHTRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DHTRequest.html",
|
|
16
|
-
"DHTResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DHTResponse.html",
|
|
17
|
-
".:DHTResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DHTResponse.html",
|
|
18
|
-
"DisconnectRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DisconnectRequest.html",
|
|
19
|
-
".:DisconnectRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.DisconnectRequest.html",
|
|
20
|
-
"ErrorResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ErrorResponse.html",
|
|
21
|
-
".:ErrorResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.ErrorResponse.html",
|
|
22
|
-
"IdentifyResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.IdentifyResponse.html",
|
|
23
|
-
".:IdentifyResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.IdentifyResponse.html",
|
|
24
|
-
"PeerInfo": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerInfo.html",
|
|
25
|
-
".:PeerInfo": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerInfo.html",
|
|
26
|
-
"PeerstoreRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerstoreRequest.html",
|
|
27
|
-
".:PeerstoreRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerstoreRequest.html",
|
|
28
|
-
"PeerstoreResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerstoreResponse.html",
|
|
29
|
-
".:PeerstoreResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PeerstoreResponse.html",
|
|
30
|
-
"PSMessage": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSMessage.html",
|
|
31
|
-
".:PSMessage": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSMessage.html",
|
|
32
|
-
"PSRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSRequest.html",
|
|
33
|
-
".:PSRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSRequest.html",
|
|
34
|
-
"PSResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSResponse.html",
|
|
35
|
-
".:PSResponse": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.PSResponse.html",
|
|
36
|
-
"Request": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.Request.html",
|
|
37
|
-
".:Request": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.Request.html",
|
|
38
|
-
"Response": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.Response.html",
|
|
39
|
-
".:Response": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.Response.html",
|
|
40
|
-
"StreamHandlerRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamHandlerRequest.html",
|
|
41
|
-
".:StreamHandlerRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamHandlerRequest.html",
|
|
42
|
-
"StreamInfo": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamInfo.html",
|
|
43
|
-
".:StreamInfo": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamInfo.html",
|
|
44
|
-
"StreamOpenRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamOpenRequest.html",
|
|
45
|
-
".:StreamOpenRequest": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.index.StreamOpenRequest.html",
|
|
46
|
-
"StreamHandler": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon-protocol.stream-handler.StreamHandler.html",
|
|
47
|
-
"./stream-handler:StreamHandler": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon-protocol.stream-handler.StreamHandler.html",
|
|
48
|
-
"StreamHandlerOptions": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.stream-handler.StreamHandlerOptions.html",
|
|
49
|
-
"./stream-handler:StreamHandlerOptions": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.stream-handler.StreamHandlerOptions.html",
|
|
50
|
-
"PassThroughUpgrader": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon-protocol.upgrader.PassThroughUpgrader.html",
|
|
51
|
-
"./upgrader:PassThroughUpgrader": "https://libp2p.github.io/js-libp2p-daemon/classes/_libp2p_daemon-protocol.upgrader.PassThroughUpgrader.html",
|
|
52
|
-
"OnConnection": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.upgrader.OnConnection.html",
|
|
53
|
-
"./upgrader:OnConnection": "https://libp2p.github.io/js-libp2p-daemon/interfaces/_libp2p_daemon-protocol.upgrader.OnConnection.html"
|
|
54
|
-
}
|
package/src/stream-handler.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { lpStream } from 'it-length-prefixed-stream'
|
|
3
|
-
import type { MultiaddrConnection } from '@libp2p/interface'
|
|
4
|
-
import type { LengthPrefixedStream } from 'it-length-prefixed-stream'
|
|
5
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
6
|
-
|
|
7
|
-
const log = logger('libp2p:daemon-protocol:stream-handler')
|
|
8
|
-
|
|
9
|
-
export interface StreamHandlerOptions {
|
|
10
|
-
stream: MultiaddrConnection
|
|
11
|
-
maxLength?: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class StreamHandler {
|
|
15
|
-
private readonly stream: MultiaddrConnection
|
|
16
|
-
private readonly lp: LengthPrefixedStream<MultiaddrConnection>
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a stream handler for connection
|
|
20
|
-
*/
|
|
21
|
-
constructor (opts: StreamHandlerOptions) {
|
|
22
|
-
const { stream, maxLength } = opts
|
|
23
|
-
|
|
24
|
-
this.stream = stream
|
|
25
|
-
this.lp = lpStream(this.stream, { maxDataLength: maxLength ?? 4096 })
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Read and decode message
|
|
30
|
-
*/
|
|
31
|
-
async read (): Promise<Uint8ArrayList | undefined> {
|
|
32
|
-
try {
|
|
33
|
-
return await this.lp.read()
|
|
34
|
-
} catch (err) {
|
|
35
|
-
log.error('read received no value', err)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async write (msg: Uint8Array | Uint8ArrayList): Promise<void> {
|
|
40
|
-
log('write message')
|
|
41
|
-
await this.lp.write(msg)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Return the handshake rest stream and invalidate handler
|
|
46
|
-
*/
|
|
47
|
-
rest (): MultiaddrConnection {
|
|
48
|
-
return this.lp.unwrap()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Close the stream
|
|
53
|
-
*/
|
|
54
|
-
async close (): Promise<void> {
|
|
55
|
-
log('closing the stream')
|
|
56
|
-
await this.rest().close()
|
|
57
|
-
}
|
|
58
|
-
}
|