@libp2p/interface 0.0.1-8b0e6bef → 0.0.1-b36ec7f2
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/src/connection/index.d.ts +140 -53
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/index.d.ts +6 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/pubsub/index.d.ts +236 -0
- package/dist/src/pubsub/index.d.ts.map +1 -0
- package/dist/src/pubsub/index.js +36 -0
- package/dist/src/pubsub/index.js.map +1 -0
- package/dist/src/stream-muxer/index.d.ts +6 -2
- package/dist/src/stream-muxer/index.d.ts.map +1 -1
- package/dist/src/stream-muxer/stream.d.ts +80 -21
- package/dist/src/stream-muxer/stream.d.ts.map +1 -1
- package/dist/src/stream-muxer/stream.js +224 -168
- package/dist/src/stream-muxer/stream.js.map +1 -1
- package/package.json +8 -8
- package/src/connection/index.ts +166 -59
- package/src/index.ts +6 -2
- package/src/pubsub/index.ts +269 -0
- package/src/stream-muxer/index.ts +7 -2
- package/src/stream-muxer/stream.ts +295 -186
- package/dist/src/connection/status.d.ts +0 -4
- package/dist/src/connection/status.d.ts.map +0 -1
- package/dist/src/connection/status.js +0 -4
- package/dist/src/connection/status.js.map +0 -1
- package/src/connection/status.ts +0 -4
|
@@ -1,40 +1,27 @@
|
|
|
1
|
-
import type * as Status from './status.js';
|
|
2
1
|
import type { AbortOptions } from '../index.js';
|
|
3
2
|
import type { PeerId } from '../peer-id/index.js';
|
|
4
3
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
5
4
|
import type { Duplex, Source } from 'it-stream-types';
|
|
6
5
|
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
7
6
|
export interface ConnectionTimeline {
|
|
8
|
-
open: number;
|
|
9
|
-
upgraded?: number;
|
|
10
|
-
close?: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Outbound conections are opened by the local node, inbound streams are opened by the remote
|
|
14
|
-
*/
|
|
15
|
-
export type Direction = 'inbound' | 'outbound';
|
|
16
|
-
export interface ConnectionStat {
|
|
17
|
-
/**
|
|
18
|
-
* Outbound conections are opened by the local node, inbound streams are opened by the remote
|
|
19
|
-
*/
|
|
20
|
-
direction: Direction;
|
|
21
|
-
/**
|
|
22
|
-
* Lifecycle times for the connection
|
|
23
|
-
*/
|
|
24
|
-
timeline: ConnectionTimeline;
|
|
25
7
|
/**
|
|
26
|
-
*
|
|
8
|
+
* When the connection was opened
|
|
27
9
|
*/
|
|
28
|
-
|
|
10
|
+
open: number;
|
|
29
11
|
/**
|
|
30
|
-
*
|
|
12
|
+
* When the MultiaddrConnection was upgraded to a Connection - e.g. the type
|
|
13
|
+
* of connection encryption and multiplexing was negotiated.
|
|
31
14
|
*/
|
|
32
|
-
|
|
15
|
+
upgraded?: number;
|
|
33
16
|
/**
|
|
34
|
-
*
|
|
17
|
+
* When the connection was closed.
|
|
35
18
|
*/
|
|
36
|
-
|
|
19
|
+
close?: number;
|
|
37
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Outbound connections are opened by the local node, inbound streams are opened by the remote
|
|
23
|
+
*/
|
|
24
|
+
export type Direction = 'inbound' | 'outbound';
|
|
38
25
|
export interface StreamTimeline {
|
|
39
26
|
/**
|
|
40
27
|
* A timestamp of when the stream was opened
|
|
@@ -56,21 +43,33 @@ export interface StreamTimeline {
|
|
|
56
43
|
* A timestamp of when the stream was reset
|
|
57
44
|
*/
|
|
58
45
|
reset?: number;
|
|
59
|
-
}
|
|
60
|
-
export interface StreamStat {
|
|
61
|
-
/**
|
|
62
|
-
* Outbound streams are opened by the local node, inbound streams are opened by the remote
|
|
63
|
-
*/
|
|
64
|
-
direction: Direction;
|
|
65
|
-
/**
|
|
66
|
-
* Lifecycle times for the stream
|
|
67
|
-
*/
|
|
68
|
-
timeline: StreamTimeline;
|
|
69
46
|
/**
|
|
70
|
-
*
|
|
47
|
+
* A timestamp of when the stream was aborted
|
|
71
48
|
*/
|
|
72
|
-
|
|
49
|
+
abort?: number;
|
|
73
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The states a stream can be in
|
|
53
|
+
*/
|
|
54
|
+
export type StreamStatus = 'open' | 'closing' | 'closed' | 'aborted' | 'reset';
|
|
55
|
+
/**
|
|
56
|
+
* The states the readable end of a stream can be in
|
|
57
|
+
*
|
|
58
|
+
* ready - the readable end is ready for reading
|
|
59
|
+
* closing - the readable end is closing
|
|
60
|
+
* closed - the readable end has closed
|
|
61
|
+
*/
|
|
62
|
+
export type ReadStatus = 'ready' | 'closing' | 'closed';
|
|
63
|
+
/**
|
|
64
|
+
* The states the writable end of a stream can be in
|
|
65
|
+
*
|
|
66
|
+
* ready - the writable end is ready for writing
|
|
67
|
+
* writing - the writable end is in the process of being written to
|
|
68
|
+
* done - the source passed to the `.sink` function yielded all values without error
|
|
69
|
+
* closing - the writable end is closing
|
|
70
|
+
* closed - the writable end has closed
|
|
71
|
+
*/
|
|
72
|
+
export type WriteStatus = 'ready' | 'writing' | 'done' | 'closing' | 'closed';
|
|
74
73
|
/**
|
|
75
74
|
* A Stream is a data channel between two peers that
|
|
76
75
|
* can be written to and read from at both ends.
|
|
@@ -88,7 +87,7 @@ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Ui
|
|
|
88
87
|
*
|
|
89
88
|
* The sink and the source will return normally.
|
|
90
89
|
*/
|
|
91
|
-
close: () => void
|
|
90
|
+
close: (options?: AbortOptions) => Promise<void>;
|
|
92
91
|
/**
|
|
93
92
|
* Closes the stream for **reading**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.
|
|
94
93
|
*
|
|
@@ -96,13 +95,13 @@ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Ui
|
|
|
96
95
|
*
|
|
97
96
|
* The source will return normally, the sink will continue to consume.
|
|
98
97
|
*/
|
|
99
|
-
closeRead: () => void
|
|
98
|
+
closeRead: (options?: AbortOptions) => Promise<void>;
|
|
100
99
|
/**
|
|
101
100
|
* Closes the stream for **writing**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.
|
|
102
101
|
*
|
|
103
102
|
* The source will return normally, the sink will continue to consume.
|
|
104
103
|
*/
|
|
105
|
-
closeWrite: () => void
|
|
104
|
+
closeWrite: (options?: AbortOptions) => Promise<void>;
|
|
106
105
|
/**
|
|
107
106
|
* Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.
|
|
108
107
|
*
|
|
@@ -113,26 +112,38 @@ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Ui
|
|
|
113
112
|
* The sink will return and the source will throw if an error is passed or return normally if not.
|
|
114
113
|
*/
|
|
115
114
|
abort: (err: Error) => void;
|
|
116
|
-
/**
|
|
117
|
-
* Closes the stream *immediately* for **reading** *and* **writing**. This should be called when a *remote error* has occurred.
|
|
118
|
-
*
|
|
119
|
-
* This function is called automatically by the muxer when it receives a `RESET` message from the remote.
|
|
120
|
-
*
|
|
121
|
-
* The sink will return and the source will throw.
|
|
122
|
-
*/
|
|
123
|
-
reset: () => void;
|
|
124
115
|
/**
|
|
125
116
|
* Unique identifier for a stream. Identifiers are not unique across muxers.
|
|
126
117
|
*/
|
|
127
118
|
id: string;
|
|
128
119
|
/**
|
|
129
|
-
*
|
|
120
|
+
* Outbound streams are opened by the local node, inbound streams are opened by the remote
|
|
130
121
|
*/
|
|
131
|
-
|
|
122
|
+
direction: Direction;
|
|
123
|
+
/**
|
|
124
|
+
* Lifecycle times for the stream
|
|
125
|
+
*/
|
|
126
|
+
timeline: StreamTimeline;
|
|
127
|
+
/**
|
|
128
|
+
* Once a protocol has been negotiated for this stream, it will be set on the stat object
|
|
129
|
+
*/
|
|
130
|
+
protocol?: string;
|
|
132
131
|
/**
|
|
133
132
|
* User defined stream metadata
|
|
134
133
|
*/
|
|
135
134
|
metadata: Record<string, any>;
|
|
135
|
+
/**
|
|
136
|
+
* The current status of the stream
|
|
137
|
+
*/
|
|
138
|
+
status: StreamStatus;
|
|
139
|
+
/**
|
|
140
|
+
* The current status of the readable end of the stream
|
|
141
|
+
*/
|
|
142
|
+
readStatus: ReadStatus;
|
|
143
|
+
/**
|
|
144
|
+
* The current status of the writable end of the stream
|
|
145
|
+
*/
|
|
146
|
+
writeStatus: WriteStatus;
|
|
136
147
|
}
|
|
137
148
|
export interface NewStreamOptions extends AbortOptions {
|
|
138
149
|
/**
|
|
@@ -142,6 +153,7 @@ export interface NewStreamOptions extends AbortOptions {
|
|
|
142
153
|
*/
|
|
143
154
|
maxOutboundStreams?: number;
|
|
144
155
|
}
|
|
156
|
+
export type ConnectionStatus = 'open' | 'closing' | 'closed';
|
|
145
157
|
/**
|
|
146
158
|
* A Connection is a high-level representation of a connection
|
|
147
159
|
* to a remote peer that may have been secured by encryption and
|
|
@@ -149,16 +161,67 @@ export interface NewStreamOptions extends AbortOptions {
|
|
|
149
161
|
* between which the connection is made.
|
|
150
162
|
*/
|
|
151
163
|
export interface Connection {
|
|
164
|
+
/**
|
|
165
|
+
* The unique identifier for this connection
|
|
166
|
+
*/
|
|
152
167
|
id: string;
|
|
153
|
-
|
|
168
|
+
/**
|
|
169
|
+
* The address of the remote end of the connection
|
|
170
|
+
*/
|
|
154
171
|
remoteAddr: Multiaddr;
|
|
172
|
+
/**
|
|
173
|
+
* The id of the peer at the remote end of the connection
|
|
174
|
+
*/
|
|
155
175
|
remotePeer: PeerId;
|
|
176
|
+
/**
|
|
177
|
+
* A list of tags applied to this connection
|
|
178
|
+
*/
|
|
156
179
|
tags: string[];
|
|
180
|
+
/**
|
|
181
|
+
* A list of open streams on this connection
|
|
182
|
+
*/
|
|
157
183
|
streams: Stream[];
|
|
158
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Outbound conections are opened by the local node, inbound streams are opened by the remote
|
|
186
|
+
*/
|
|
187
|
+
direction: Direction;
|
|
188
|
+
/**
|
|
189
|
+
* Lifecycle times for the connection
|
|
190
|
+
*/
|
|
191
|
+
timeline: ConnectionTimeline;
|
|
192
|
+
/**
|
|
193
|
+
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
|
|
194
|
+
*/
|
|
195
|
+
multiplexer?: string;
|
|
196
|
+
/**
|
|
197
|
+
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
|
|
198
|
+
*/
|
|
199
|
+
encryption?: string;
|
|
200
|
+
/**
|
|
201
|
+
* The current status of the connection
|
|
202
|
+
*/
|
|
203
|
+
status: ConnectionStatus;
|
|
204
|
+
/**
|
|
205
|
+
* Create a new stream on this connection and negotiate one of the passed protocols
|
|
206
|
+
*/
|
|
207
|
+
newStream: (protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>;
|
|
208
|
+
/**
|
|
209
|
+
* Add a stream to this connection
|
|
210
|
+
*/
|
|
159
211
|
addStream: (stream: Stream) => void;
|
|
212
|
+
/**
|
|
213
|
+
* Remove a stream from this connection
|
|
214
|
+
*/
|
|
160
215
|
removeStream: (id: string) => void;
|
|
161
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Gracefully close the connection. All queued data will be written to the
|
|
218
|
+
* underlying transport.
|
|
219
|
+
*/
|
|
220
|
+
close: (options?: AbortOptions) => Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Immediately close the connection, any queued data will be discarded
|
|
223
|
+
*/
|
|
224
|
+
abort: (err: Error) => void;
|
|
162
225
|
}
|
|
163
226
|
export declare const symbol: unique symbol;
|
|
164
227
|
export declare function isConnection(other: any): other is Connection;
|
|
@@ -171,8 +234,18 @@ export interface ConnectionProtector {
|
|
|
171
234
|
protect: (connection: MultiaddrConnection) => Promise<MultiaddrConnection>;
|
|
172
235
|
}
|
|
173
236
|
export interface MultiaddrConnectionTimeline {
|
|
237
|
+
/**
|
|
238
|
+
* When the connection was opened
|
|
239
|
+
*/
|
|
174
240
|
open: number;
|
|
241
|
+
/**
|
|
242
|
+
* When the MultiaddrConnection was upgraded to a Connection - the type of
|
|
243
|
+
* connection encryption and multiplexing was negotiated.
|
|
244
|
+
*/
|
|
175
245
|
upgraded?: number;
|
|
246
|
+
/**
|
|
247
|
+
* When the connection was closed.
|
|
248
|
+
*/
|
|
176
249
|
close?: number;
|
|
177
250
|
}
|
|
178
251
|
/**
|
|
@@ -181,8 +254,22 @@ export interface MultiaddrConnectionTimeline {
|
|
|
181
254
|
* without encryption or stream multiplexing.
|
|
182
255
|
*/
|
|
183
256
|
export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>> {
|
|
184
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Gracefully close the connection. All queued data will be written to the
|
|
259
|
+
* underlying transport.
|
|
260
|
+
*/
|
|
261
|
+
close: (options?: AbortOptions) => Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Immediately close the connection, any queued data will be discarded
|
|
264
|
+
*/
|
|
265
|
+
abort: (err: Error) => void;
|
|
266
|
+
/**
|
|
267
|
+
* The address of the remote end of the connection
|
|
268
|
+
*/
|
|
185
269
|
remoteAddr: Multiaddr;
|
|
270
|
+
/**
|
|
271
|
+
* When connection lifecycle events occurred
|
|
272
|
+
*/
|
|
186
273
|
timeline: MultiaddrConnectionTimeline;
|
|
187
274
|
}
|
|
188
275
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MA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AAK,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAE3B;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AA4QA,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AAEtD,MAAM,UAAU,YAAY,CAAE,KAAU;IACtC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAChD,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -461,7 +461,11 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ev
|
|
|
461
461
|
*/
|
|
462
462
|
dialProtocol: (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: AbortOptions) => Promise<Stream>;
|
|
463
463
|
/**
|
|
464
|
-
* Attempts to gracefully close an open connection to the given peer. If the
|
|
464
|
+
* Attempts to gracefully close an open connection to the given peer. If the
|
|
465
|
+
* connection is not closed in the grace period, it will be forcefully closed.
|
|
466
|
+
*
|
|
467
|
+
* An AbortSignal can optionally be passed to control when the connection is
|
|
468
|
+
* forcefully closed.
|
|
465
469
|
*
|
|
466
470
|
* @example
|
|
467
471
|
*
|
|
@@ -469,7 +473,7 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ev
|
|
|
469
473
|
* await libp2p.hangUp(remotePeerId)
|
|
470
474
|
* ```
|
|
471
475
|
*/
|
|
472
|
-
hangUp: (peer: PeerId | Multiaddr) => Promise<void>;
|
|
476
|
+
hangUp: (peer: PeerId | Multiaddr, options?: AbortOptions) => Promise<void>;
|
|
473
477
|
/**
|
|
474
478
|
* Sets up [multistream-select routing](https://github.com/multiformats/multistream-select) of protocols to their application handlers. Whenever a stream is opened on one of the provided protocols, the handler will be called. `handle` must be called in order to register a handler and support for a given protocol. This also informs other peers of the protocols you support.
|
|
475
479
|
*
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,C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AAU,CAAC,CAAA;IAE3E;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAA;CACZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;KAC/B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjJ,CAAA"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { Stream } from '../connection/index.js';
|
|
2
|
+
import type { EventEmitter } from '../events.js';
|
|
3
|
+
import type { PeerId } from '../peer-id/index.js';
|
|
4
|
+
import type { Pushable } from 'it-pushable';
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
6
|
+
/**
|
|
7
|
+
* On the producing side:
|
|
8
|
+
* * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
|
9
|
+
*
|
|
10
|
+
* On the consuming side:
|
|
11
|
+
* * Enforce the fields to be present, reject otherwise.
|
|
12
|
+
* * Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare const StrictSign = "StrictSign";
|
|
15
|
+
/**
|
|
16
|
+
* On the producing side:
|
|
17
|
+
* * Build messages without the signature, key, from and seqno fields.
|
|
18
|
+
* * The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty.
|
|
19
|
+
*
|
|
20
|
+
* On the consuming side:
|
|
21
|
+
* * Enforce the fields to be absent, reject otherwise.
|
|
22
|
+
* * Propagate only if the fields are absent, reject otherwise.
|
|
23
|
+
* * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
|
24
|
+
*/
|
|
25
|
+
export declare const StrictNoSign = "StrictNoSign";
|
|
26
|
+
export type SignaturePolicy = typeof StrictSign | typeof StrictNoSign;
|
|
27
|
+
export interface SignedMessage {
|
|
28
|
+
type: 'signed';
|
|
29
|
+
from: PeerId;
|
|
30
|
+
topic: string;
|
|
31
|
+
data: Uint8Array;
|
|
32
|
+
sequenceNumber: bigint;
|
|
33
|
+
signature: Uint8Array;
|
|
34
|
+
key: Uint8Array;
|
|
35
|
+
}
|
|
36
|
+
export interface UnsignedMessage {
|
|
37
|
+
type: 'unsigned';
|
|
38
|
+
topic: string;
|
|
39
|
+
data: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
export type Message = SignedMessage | UnsignedMessage;
|
|
42
|
+
export interface PubSubRPCMessage {
|
|
43
|
+
from?: Uint8Array;
|
|
44
|
+
topic?: string;
|
|
45
|
+
data?: Uint8Array;
|
|
46
|
+
sequenceNumber?: Uint8Array;
|
|
47
|
+
signature?: Uint8Array;
|
|
48
|
+
key?: Uint8Array;
|
|
49
|
+
}
|
|
50
|
+
export interface PubSubRPCSubscription {
|
|
51
|
+
subscribe?: boolean;
|
|
52
|
+
topic?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface PubSubRPC {
|
|
55
|
+
subscriptions: PubSubRPCSubscription[];
|
|
56
|
+
messages: PubSubRPCMessage[];
|
|
57
|
+
}
|
|
58
|
+
export interface PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
59
|
+
id: PeerId;
|
|
60
|
+
protocol: string;
|
|
61
|
+
outboundStream?: Pushable<Uint8ArrayList>;
|
|
62
|
+
inboundStream?: AsyncIterable<Uint8ArrayList>;
|
|
63
|
+
isWritable: boolean;
|
|
64
|
+
close: () => void;
|
|
65
|
+
write: (buf: Uint8Array | Uint8ArrayList) => void;
|
|
66
|
+
attachInboundStream: (stream: Stream) => AsyncIterable<Uint8ArrayList>;
|
|
67
|
+
attachOutboundStream: (stream: Stream) => Promise<Pushable<Uint8ArrayList>>;
|
|
68
|
+
}
|
|
69
|
+
export interface PubSubInit {
|
|
70
|
+
enabled?: boolean;
|
|
71
|
+
multicodecs?: string[];
|
|
72
|
+
/**
|
|
73
|
+
* defines how signatures should be handled
|
|
74
|
+
*/
|
|
75
|
+
globalSignaturePolicy?: SignaturePolicy;
|
|
76
|
+
/**
|
|
77
|
+
* if can relay messages not subscribed
|
|
78
|
+
*/
|
|
79
|
+
canRelayMessage?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* if publish should emit to self, if subscribed
|
|
82
|
+
*/
|
|
83
|
+
emitSelf?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* handle this many incoming pubsub messages concurrently
|
|
86
|
+
*/
|
|
87
|
+
messageProcessingConcurrency?: number;
|
|
88
|
+
/**
|
|
89
|
+
* How many parallel incoming streams to allow on the pubsub protocol per-connection
|
|
90
|
+
*/
|
|
91
|
+
maxInboundStreams?: number;
|
|
92
|
+
/**
|
|
93
|
+
* How many parallel outgoing streams to allow on the pubsub protocol per-connection
|
|
94
|
+
*/
|
|
95
|
+
maxOutboundStreams?: number;
|
|
96
|
+
}
|
|
97
|
+
interface Subscription {
|
|
98
|
+
topic: string;
|
|
99
|
+
subscribe: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface SubscriptionChangeData {
|
|
102
|
+
peerId: PeerId;
|
|
103
|
+
subscriptions: Subscription[];
|
|
104
|
+
}
|
|
105
|
+
export interface PubSubEvents {
|
|
106
|
+
'subscription-change': CustomEvent<SubscriptionChangeData>;
|
|
107
|
+
'message': CustomEvent<Message>;
|
|
108
|
+
}
|
|
109
|
+
export interface PublishResult {
|
|
110
|
+
recipients: PeerId[];
|
|
111
|
+
}
|
|
112
|
+
export declare enum TopicValidatorResult {
|
|
113
|
+
/**
|
|
114
|
+
* The message is considered valid, and it should be delivered and forwarded to the network
|
|
115
|
+
*/
|
|
116
|
+
Accept = "accept",
|
|
117
|
+
/**
|
|
118
|
+
* The message is neither delivered nor forwarded to the network
|
|
119
|
+
*/
|
|
120
|
+
Ignore = "ignore",
|
|
121
|
+
/**
|
|
122
|
+
* The message is considered invalid, and it should be rejected
|
|
123
|
+
*/
|
|
124
|
+
Reject = "reject"
|
|
125
|
+
}
|
|
126
|
+
export interface TopicValidatorFn {
|
|
127
|
+
(peer: PeerId, message: Message): TopicValidatorResult | Promise<TopicValidatorResult>;
|
|
128
|
+
}
|
|
129
|
+
export interface PubSub<Events extends Record<string, any> = PubSubEvents> extends EventEmitter<Events> {
|
|
130
|
+
/**
|
|
131
|
+
* The global signature policy controls whether or not we sill send and receive
|
|
132
|
+
* signed or unsigned messages.
|
|
133
|
+
*
|
|
134
|
+
* Signed messages prevent spoofing message senders and should be preferred to
|
|
135
|
+
* using unsigned messages.
|
|
136
|
+
*/
|
|
137
|
+
globalSignaturePolicy: typeof StrictSign | typeof StrictNoSign;
|
|
138
|
+
/**
|
|
139
|
+
* A list of multicodecs that contain the pubsub protocol name.
|
|
140
|
+
*/
|
|
141
|
+
multicodecs: string[];
|
|
142
|
+
/**
|
|
143
|
+
* Pubsub routers support message validators per topic, which will validate the message
|
|
144
|
+
* before its propagations. They are stored in a map where keys are the topic name and
|
|
145
|
+
* values are the validators.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
*
|
|
149
|
+
* ```js
|
|
150
|
+
* const topic = 'topic'
|
|
151
|
+
* const validateMessage = (msgTopic, msg) => {
|
|
152
|
+
* const input = uint8ArrayToString(msg.data)
|
|
153
|
+
* const validInputs = ['a', 'b', 'c']
|
|
154
|
+
*
|
|
155
|
+
* if (!validInputs.includes(input)) {
|
|
156
|
+
* throw new Error('no valid input received')
|
|
157
|
+
* }
|
|
158
|
+
* }
|
|
159
|
+
* libp2p.pubsub.topicValidators.set(topic, validateMessage)
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
topicValidators: Map<string, TopicValidatorFn>;
|
|
163
|
+
getPeers: () => PeerId[];
|
|
164
|
+
/**
|
|
165
|
+
* Gets a list of topics the node is subscribed to.
|
|
166
|
+
*
|
|
167
|
+
* ```js
|
|
168
|
+
* const topics = libp2p.pubsub.getTopics()
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
getTopics: () => string[];
|
|
172
|
+
/**
|
|
173
|
+
* Subscribes to a pubsub topic.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
*
|
|
177
|
+
* ```js
|
|
178
|
+
* const topic = 'topic'
|
|
179
|
+
* const handler = (msg) => {
|
|
180
|
+
* if (msg.topic === topic) {
|
|
181
|
+
* // msg.data - pubsub data received
|
|
182
|
+
* }
|
|
183
|
+
* }
|
|
184
|
+
*
|
|
185
|
+
* libp2p.pubsub.addEventListener('message', handler)
|
|
186
|
+
* libp2p.pubsub.subscribe(topic)
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
subscribe: (topic: string) => void;
|
|
190
|
+
/**
|
|
191
|
+
* Unsubscribes from a pubsub topic.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
*
|
|
195
|
+
* ```js
|
|
196
|
+
* const topic = 'topic'
|
|
197
|
+
* const handler = (msg) => {
|
|
198
|
+
* // msg.data - pubsub data received
|
|
199
|
+
* }
|
|
200
|
+
*
|
|
201
|
+
* libp2p.pubsub.removeEventListener(topic handler)
|
|
202
|
+
* libp2p.pubsub.unsubscribe(topic)
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
unsubscribe: (topic: string) => void;
|
|
206
|
+
/**
|
|
207
|
+
* Gets a list of the PeerIds that are subscribed to one topic.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
*
|
|
211
|
+
* ```js
|
|
212
|
+
* const peerIds = libp2p.pubsub.getSubscribers(topic)
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
getSubscribers: (topic: string) => PeerId[];
|
|
216
|
+
/**
|
|
217
|
+
* Publishes messages to the given topic.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
*
|
|
221
|
+
* ```js
|
|
222
|
+
* const topic = 'topic'
|
|
223
|
+
* const data = uint8ArrayFromString('data')
|
|
224
|
+
*
|
|
225
|
+
* await libp2p.pubsub.publish(topic, data)
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
publish: (topic: string, data: Uint8Array) => Promise<PublishResult>;
|
|
229
|
+
}
|
|
230
|
+
export interface PeerStreamEvents {
|
|
231
|
+
'stream:inbound': CustomEvent<never>;
|
|
232
|
+
'stream:outbound': CustomEvent<never>;
|
|
233
|
+
'close': CustomEvent<never>;
|
|
234
|
+
}
|
|
235
|
+
export {};
|
|
236
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,eAAe,CAAA;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAA;AAE1C,MAAM,MAAM,eAAe,GAAG,OAAO,UAAU,GAAG,OAAO,YAAY,CAAA;AAErE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,IA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AAC,MAAM,CAAC;IACrG;;;;;;OAMG;IACH,qBAAqB,EAAE,OAAO,UAAU,GAAG,OAAO,YAAY,CAAA;IAE9D;;OAEG;IACH,WAAW,EAAE,MAAM,EAAE,CAAA;IAErB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAE9C,QAAQ,EAAE,MAAM,MAAM,EAAE,CAAA;IAExB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,MAAM,EAAE,CAAA;IAEzB;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAElC;;;;;;;;;;;;;;OAcG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAEpC;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;IAE3C;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;CACrE;AAED,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IACpC,iBAAiB,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IACrC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;CAC5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On the producing side:
|
|
3
|
+
* * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
|
4
|
+
*
|
|
5
|
+
* On the consuming side:
|
|
6
|
+
* * Enforce the fields to be present, reject otherwise.
|
|
7
|
+
* * Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export const StrictSign = 'StrictSign';
|
|
10
|
+
/**
|
|
11
|
+
* On the producing side:
|
|
12
|
+
* * Build messages without the signature, key, from and seqno fields.
|
|
13
|
+
* * The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty.
|
|
14
|
+
*
|
|
15
|
+
* On the consuming side:
|
|
16
|
+
* * Enforce the fields to be absent, reject otherwise.
|
|
17
|
+
* * Propagate only if the fields are absent, reject otherwise.
|
|
18
|
+
* * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
|
19
|
+
*/
|
|
20
|
+
export const StrictNoSign = 'StrictNoSign';
|
|
21
|
+
export var TopicValidatorResult;
|
|
22
|
+
(function (TopicValidatorResult) {
|
|
23
|
+
/**
|
|
24
|
+
* The message is considered valid, and it should be delivered and forwarded to the network
|
|
25
|
+
*/
|
|
26
|
+
TopicValidatorResult["Accept"] = "accept";
|
|
27
|
+
/**
|
|
28
|
+
* The message is neither delivered nor forwarded to the network
|
|
29
|
+
*/
|
|
30
|
+
TopicValidatorResult["Ignore"] = "ignore";
|
|
31
|
+
/**
|
|
32
|
+
* The message is considered invalid, and it should be rejected
|
|
33
|
+
*/
|
|
34
|
+
TopicValidatorResult["Reject"] = "reject";
|
|
35
|
+
})(TopicValidatorResult || (TopicValidatorResult = {}));
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pubsub/index.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAA;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAA;AA6G1C,MAAM,CAAN,IAAY,oBAaX;AAbD,WAAY,oBAAoB;IAC9B;;OAEG;IACH,yCAAiB,CAAA;IACjB;;OAEG;IACH,yCAAiB,CAAA;IACjB;;OAEG;IACH,yCAAiB,CAAA;AACnB,CAAC,EAbW,oBAAoB,KAApB,oBAAoB,QAa/B"}
|
|
@@ -32,9 +32,13 @@ export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array>, Source<U
|
|
|
32
32
|
/**
|
|
33
33
|
* Close or abort all tracked streams and stop the muxer
|
|
34
34
|
*/
|
|
35
|
-
close: (
|
|
35
|
+
close: (options?: AbortOptions) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Close or abort all tracked streams and stop the muxer
|
|
38
|
+
*/
|
|
39
|
+
abort: (err: Error) => void;
|
|
36
40
|
}
|
|
37
|
-
export interface StreamMuxerInit
|
|
41
|
+
export interface StreamMuxerInit {
|
|
38
42
|
/**
|
|
39
43
|
* A callback function invoked every time an incoming stream is opened
|
|
40
44
|
*/
|