@libp2p/interface 2.10.5 → 2.11.0-0f68898e6

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.
Files changed (69) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +4 -4
  3. package/dist/src/connection-encrypter.d.ts +17 -9
  4. package/dist/src/connection-encrypter.d.ts.map +1 -1
  5. package/dist/src/connection-gater.d.ts +1 -2
  6. package/dist/src/connection-gater.d.ts.map +1 -1
  7. package/dist/src/connection-protector.d.ts +9 -0
  8. package/dist/src/connection-protector.d.ts.map +1 -0
  9. package/dist/src/connection-protector.js +2 -0
  10. package/dist/src/connection-protector.js.map +1 -0
  11. package/dist/src/connection.d.ts +36 -233
  12. package/dist/src/connection.d.ts.map +1 -1
  13. package/dist/src/connection.js.map +1 -1
  14. package/dist/src/errors.d.ts +32 -0
  15. package/dist/src/errors.d.ts.map +1 -1
  16. package/dist/src/errors.js +44 -0
  17. package/dist/src/errors.js.map +1 -1
  18. package/dist/src/events.d.ts +26 -0
  19. package/dist/src/events.d.ts.map +1 -0
  20. package/dist/src/events.js +36 -0
  21. package/dist/src/events.js.map +1 -0
  22. package/dist/src/index.d.ts +41 -3
  23. package/dist/src/index.d.ts.map +1 -1
  24. package/dist/src/index.js +7 -2
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/message-stream.d.ts +146 -0
  27. package/dist/src/message-stream.d.ts.map +1 -0
  28. package/dist/src/message-stream.js +2 -0
  29. package/dist/src/message-stream.js.map +1 -0
  30. package/dist/src/metrics.d.ts +2 -2
  31. package/dist/src/metrics.d.ts.map +1 -1
  32. package/dist/src/multiaddr-connection.d.ts +25 -0
  33. package/dist/src/multiaddr-connection.d.ts.map +1 -0
  34. package/dist/src/multiaddr-connection.js +2 -0
  35. package/dist/src/multiaddr-connection.js.map +1 -0
  36. package/dist/src/pubsub.d.ts +1 -3
  37. package/dist/src/pubsub.d.ts.map +1 -1
  38. package/dist/src/pubsub.js.map +1 -1
  39. package/dist/src/stream-handler.d.ts +2 -13
  40. package/dist/src/stream-handler.d.ts.map +1 -1
  41. package/dist/src/stream-muxer.d.ts +115 -27
  42. package/dist/src/stream-muxer.d.ts.map +1 -1
  43. package/dist/src/stream.d.ts +63 -0
  44. package/dist/src/stream.d.ts.map +1 -0
  45. package/dist/src/stream.js +2 -0
  46. package/dist/src/stream.js.map +1 -0
  47. package/dist/src/topology.d.ts +2 -2
  48. package/dist/src/topology.d.ts.map +1 -1
  49. package/dist/src/transport.d.ts +20 -13
  50. package/dist/src/transport.d.ts.map +1 -1
  51. package/dist/src/transport.js.map +1 -1
  52. package/package.json +1 -2
  53. package/src/connection-encrypter.ts +19 -9
  54. package/src/connection-gater.ts +1 -2
  55. package/src/connection-protector.ts +9 -0
  56. package/src/connection.ts +38 -270
  57. package/src/errors.ts +52 -0
  58. package/src/events.ts +44 -0
  59. package/src/index.ts +46 -3
  60. package/src/message-stream.ts +169 -0
  61. package/src/metrics.ts +2 -2
  62. package/src/multiaddr-connection.ts +27 -0
  63. package/src/pubsub.ts +1 -3
  64. package/src/stream-handler.ts +2 -15
  65. package/src/stream-muxer.ts +126 -28
  66. package/src/stream.ts +70 -0
  67. package/src/topology.ts +2 -2
  68. package/src/transport.ts +25 -14
  69. package/dist/typedoc-urls.json +0 -222
@@ -1,8 +1,88 @@
1
- import type { Direction, Stream } from './connection.js';
2
- import type { AbortOptions } from './index.js';
3
- import type { Duplex } from 'it-stream-types';
4
- import type { Uint8ArrayList } from 'uint8arraylist';
5
- export interface StreamMuxerFactory {
1
+ import type { Stream, TypedEventTarget, MessageStream } from './index.js';
2
+ import type { AbortOptions } from '@multiformats/multiaddr';
3
+ /**
4
+ * User-facing message stream muxer options
5
+ */
6
+ export interface StreamMuxerOptions<MuxedStreamOptions extends StreamOptions = StreamOptions> {
7
+ /**
8
+ * Configuration options for each outgoing/incoming stream
9
+ */
10
+ streamOptions?: MuxedStreamOptions;
11
+ /**
12
+ * libp2p is notified of incoming streams via the muxer's 'stream' event.
13
+ *
14
+ * During connection establishment there may be a small window where a muxer
15
+ * starts to process incoming stream data before a listener has been added for
16
+ * the 'stream' event.
17
+ *
18
+ * If no handler is registered for this event incoming streams can be missed
19
+ * so when this is the case muxers queue streams internally as "early
20
+ * streams", and will defer emitting the 'stream' event until after a listener
21
+ * has been registered.
22
+ *
23
+ * Allowing an unlimited amount of early streams can cause excessive memory
24
+ * consumption so this setting controls how many early streams to store when
25
+ * no 'stream' listener has been registered.
26
+ *
27
+ * If more streams than this are opened before a listener is added the muxed
28
+ * connection will be reset.
29
+ *
30
+ * @default 10
31
+ */
32
+ maxEarlyStreams?: number;
33
+ /**
34
+ * Maximum size of a message in bytes that we'll send on a stream - this
35
+ * ensures that a single stream doesn't hog a connection
36
+ *
37
+ * @default 65_536
38
+ */
39
+ maxMessageSize?: number;
40
+ /**
41
+ * Maximum number of concurrent inbound streams that we accept - if the peer
42
+ * tries to open more streams, those will be reset immediately
43
+ *
44
+ * @default 1_000
45
+ */
46
+ maxInboundStreams?: number;
47
+ /**
48
+ * Maximum number of concurrent outbound streams that we accept - if the
49
+ * application tries to open more streams, the call to `newStream` will throw
50
+ *
51
+ * @default 1_000
52
+ */
53
+ maxOutboundStreams?: number;
54
+ }
55
+ /**
56
+ * User-facing message stream options
57
+ */
58
+ export interface StreamOptions {
59
+ /**
60
+ * If no data is sent or received in this number of ms the stream will be
61
+ * reset and an 'error' event emitted.
62
+ *
63
+ * @default 120_000
64
+ */
65
+ inactivityTimeout?: number;
66
+ /**
67
+ * The maximum number of bytes to store when paused or before a 'message'
68
+ * event handler is added.
69
+ *
70
+ * If the internal buffer overflows this value the stream will be reset.
71
+ *
72
+ * @default 4_194_304
73
+ */
74
+ maxReadBufferLength?: number;
75
+ /**
76
+ * The maximum number of bytes to store when the remote end of the stream is
77
+ * applying backpressure, or when it is slow to accept new bytes.
78
+ *
79
+ * If the internal buffer overflows this value the stream will be reset.
80
+ *
81
+ * @default Infinity
82
+ */
83
+ maxWriteBufferLength?: number;
84
+ }
85
+ export interface StreamMuxerFactory<Muxer extends StreamMuxer = StreamMuxer> {
6
86
  /**
7
87
  * The protocol used to select this muxer during connection opening
8
88
  */
@@ -10,46 +90,54 @@ export interface StreamMuxerFactory {
10
90
  /**
11
91
  * Creates a new stream muxer to be used with a new connection
12
92
  */
13
- createStreamMuxer(init?: StreamMuxerInit): StreamMuxer;
93
+ createStreamMuxer(maConn: MessageStream): Muxer;
14
94
  }
95
+ export interface StreamMuxerEvents<MuxedStream extends Stream = Stream> {
96
+ /**
97
+ * An incoming stream was created
98
+ */
99
+ stream: CustomEvent<MuxedStream>;
100
+ }
101
+ export interface CreateStreamOptions extends AbortOptions, StreamOptions {
102
+ /**
103
+ * If a single protocol was requested and the muxer has support for this,
104
+ * pre-negotiate the protocol using this value, otherwise multistream-select
105
+ * will be run over the stream after opening.
106
+ */
107
+ protocol?: string;
108
+ }
109
+ export type StreamMuxerStatus = 'open' | 'closing' | 'closed';
15
110
  /**
16
111
  * A libp2p stream muxer
17
112
  */
18
- export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
113
+ export interface StreamMuxer<MuxedStream extends Stream = Stream> extends TypedEventTarget<StreamMuxerEvents<MuxedStream>> {
19
114
  /**
20
115
  * The protocol used to select this muxer during connection opening
21
116
  */
22
117
  protocol: string;
23
118
  /**
24
- * A list of streams that are currently open. Closed streams will not be returned.
119
+ * A list of streams that are currently open
25
120
  */
26
- readonly streams: Stream[];
121
+ streams: MuxedStream[];
27
122
  /**
28
- * Initiate a new stream with the given name. If no name is
29
- * provided, the id of the stream will be used.
123
+ * The status of the muxer
30
124
  */
31
- newStream(name?: string): Stream | Promise<Stream>;
125
+ status: StreamMuxerStatus;
32
126
  /**
33
- * Close or abort all tracked streams and stop the muxer
127
+ * Create a new stream
34
128
  */
35
- close(options?: AbortOptions): Promise<void>;
129
+ createStream(options?: CreateStreamOptions): MuxedStream | Promise<MuxedStream>;
36
130
  /**
37
- * Close or abort all tracked streams and stop the muxer
131
+ * Immediately close the muxer, abort every open stream and discard any
132
+ * unsent/unread data.
38
133
  */
39
134
  abort(err: Error): void;
40
- }
41
- export interface StreamMuxerInit {
42
- /**
43
- * A callback function invoked every time an incoming stream is opened
44
- */
45
- onIncomingStream?(stream: Stream): void;
46
- /**
47
- * A callback function invoke every time a stream ends
48
- */
49
- onStreamEnd?(stream: Stream): void;
50
135
  /**
51
- * Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote
136
+ * Gracefully close the muxer. All open streams will be gracefully closed, and
137
+ * the returned promise will either resolve when any/all unsent data has been
138
+ * sent, or it will reject if the passed abort signal fires before this
139
+ * happens.
52
140
  */
53
- direction?: Direction;
141
+ close(options?: AbortOptions): Promise<void>;
54
142
  }
55
143
  //# sourceMappingURL=stream-muxer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream-muxer.d.ts","sourceRoot":"","sources":["../../src/stream-muxer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,iBAAiB,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,WAAW,CAAA;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,MAAM,CAAC,cAAc,CAAC,UAAU,GAAG,cAAc,CAAC,CAAC;IACtF;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAA;IAC1B;;;OAGG;IACH,SAAS,CA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oB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,kBAAkB,CAAC,KAAK,SAAS,WAAW,GAAG,WAAW;IACzE;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,KAAK,CAAA;CAChD;AAED,MAAM,WAAW,iBAAiB,CAAC,WAAW,SAAS,MAAM,GAAG,MAAM;IACpE;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,mBAAoB,SAAQ,YAAY,EAAE,aAAa;IACtE;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,WAAW,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,gBAAgB,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACxH;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,OAAO,EAAE,WAAW,EAAE,CAAA;IAEtB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAA;IAEzB;;OAEG;IACH,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;IAE/E;;;OAGG;IACH,KAAK,CAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAA;IAExB;;;;;OAKG;IACH,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9C"}
@@ -0,0 +1,63 @@
1
+ import type { AbortOptions } from './index.ts';
2
+ import type { MessageStream, MessageStreamReadStatus, MessageStreamWriteStatus } from './message-stream.js';
3
+ /**
4
+ * A Stream is a lightweight data channel between two peers that can be written
5
+ * to and read from at both ends.
6
+ *
7
+ * It is half-closable - that is in order for it to be closed fully and any
8
+ * associated memory reclaimed, both ends must close their writeable end of the
9
+ * stream.
10
+ *
11
+ * It's also possible to close the readable end of the stream, but this depends
12
+ * on the underlying stream muxer supporting this operation which not all do.
13
+ */
14
+ export interface Stream extends MessageStream {
15
+ /**
16
+ * Unique identifier for a stream. Identifiers are not unique across muxers.
17
+ */
18
+ id: string;
19
+ /**
20
+ * The protocol negotiated for this stream
21
+ */
22
+ protocol: string;
23
+ /**
24
+ * The status of the readable end of the stream
25
+ */
26
+ readStatus: MessageStreamReadStatus;
27
+ /**
28
+ * The status of the writable end of the stream
29
+ */
30
+ writeStatus: MessageStreamWriteStatus;
31
+ /**
32
+ * The status of the readable end of the remote end of the stream - n.b. this
33
+ * requires the underlying stream transport to support sending STOP_SENDING
34
+ * messages or similar.
35
+ */
36
+ remoteReadStatus: MessageStreamReadStatus;
37
+ /**
38
+ * The status of the writable end of the remote end of the stream
39
+ */
40
+ remoteWriteStatus: MessageStreamWriteStatus;
41
+ /**
42
+ * Close stream for writing and return a promise that resolves once any
43
+ * pending data has been passed to the underlying transport.
44
+ *
45
+ * Note that the stream itself will remain readable until the remote end also
46
+ * closes it's writable end.
47
+ *
48
+ * To close without waiting for the remote, call `.abort` instead. If you want
49
+ * to wait for data to be sent first, ensure if the `.writableStatus` property
50
+ * is not 'paused', if it is, wait for a `drain` event before aborting.
51
+ */
52
+ close(options?: AbortOptions): Promise<void>;
53
+ /**
54
+ * Send a message to the remote end of the stream informing them that any
55
+ * incoming data will be discarded so they should stop sending.
56
+ *
57
+ * This requires the underlying resource to support this operation - for
58
+ * example the QUIC, WebTransport, WebRTC transports do but anything
59
+ * multiplexed using Yamux or Mplex do not.
60
+ */
61
+ closeRead(options?: AbortOptions): Promise<void>;
62
+ }
63
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE3G;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAO,SAAQ,aAAa;IAC3C;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,UAAU,EAAE,uBAAuB,CAAA;IAEnC;;OAEG;IACH,WAAW,EAAE,wBAAwB,CAAA;IAErC;;;;OAIG;IACH,gBAAgB,EAAE,uBAAuB,CAAA;IAEzC;;OAEG;IACH,iBAAiB,EAAE,wBAAwB,CAAA;IAE3C;;;;;;;;;;OAUG;IACH,KAAK,CAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7C;;;;;;;OAOG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":""}
@@ -36,11 +36,11 @@ export interface Topology {
36
36
  * Invoked when a new connection is opened to a peer that supports the
37
37
  * registered protocol
38
38
  */
39
- onConnect?(peerId: PeerId, conn: Connection): void;
39
+ onConnect?(peerId: PeerId, conn: Connection): void | Promise<void>;
40
40
  /**
41
41
  * Invoked when the last connection to a peer that supports the registered
42
42
  * protocol closes
43
43
  */
44
- onDisconnect?(peerId: PeerId): void;
44
+ onDisconnect?(peerId: PeerId): void | Promise<void>;
45
45
  }
46
46
  //# sourceMappingURL=topology.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"topology.d.ts","sourceRoot":"","sources":["../../src/topology.ts"],"names":[],"mappings":"AA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M,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElE;;;OAGG;IACH,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACpD"}
@@ -1,6 +1,4 @@
1
- import type { Connection, ConnectionLimits, MultiaddrConnection } from './connection.js';
2
- import type { AbortOptions, ClearableSignal, ConnectionEncrypter } from './index.js';
3
- import type { StreamMuxerFactory } from './stream-muxer.js';
1
+ import type { AbortOptions, ClearableSignal, ConnectionEncrypter, MultiaddrConnection, Connection, ConnectionLimits, StreamMuxerFactory, PeerId } from './index.js';
4
2
  import type { Multiaddr } from '@multiformats/multiaddr';
5
3
  import type { TypedEventTarget } from 'main-event';
6
4
  import type { ProgressOptions, ProgressEvent } from 'progress-events';
@@ -114,14 +112,6 @@ export declare enum FaultTolerance {
114
112
  * Options accepted by the upgrader during connection establishment
115
113
  */
116
114
  export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {
117
- /**
118
- * If true the invoking transport is expected to implement it's own encryption
119
- * and an encryption protocol will not attempted to be negotiated via
120
- * multi-stream select
121
- *
122
- * @default false
123
- */
124
- skipEncryption?: boolean;
125
115
  /**
126
116
  * If true no connection protection will be performed on the connection.
127
117
  */
@@ -147,18 +137,35 @@ export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent =
147
137
  */
148
138
  initiator?: boolean;
149
139
  }
140
+ /**
141
+ * Options accepted by the upgrader during connection establishment
142
+ */
143
+ export interface UpgraderWithoutEncryptionOptions extends UpgraderOptions {
144
+ /**
145
+ * If true the invoking transport is expected to implement it's own encryption
146
+ * and an encryption protocol will not attempted to be negotiated via
147
+ * multi-stream select
148
+ */
149
+ skipEncryption: true;
150
+ /**
151
+ * If `skipEncryption` is true, a remote PeerId must be supplied
152
+ */
153
+ remotePeer: PeerId;
154
+ }
150
155
  export type InboundConnectionUpgradeEvents = ProgressEvent<'upgrader:encrypt-inbound-connection'> | ProgressEvent<'upgrader:multiplex-inbound-connection'>;
151
156
  export type OutboundConnectionUpgradeEvents = ProgressEvent<'upgrader:encrypt-outbound-connection'> | ProgressEvent<'upgrader:multiplex-outbound-connection'>;
152
157
  export interface Upgrader {
153
158
  /**
154
159
  * Upgrades an outbound connection created by the `dial` method of a transport
155
160
  */
156
- upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>;
161
+ upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>;
162
+ upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<Connection>;
157
163
  /**
158
164
  * Upgrades an inbound connection received by a transport listener and
159
165
  * notifies other libp2p components about the new connection
160
166
  */
161
- upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>;
167
+ upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>;
168
+ upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<void>;
162
169
  /**
163
170
  * Used by transports that perform part of the upgrade process themselves and
164
171
  * do some async work. This allows configuring inbound upgrade timeouts from a
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAA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CAAA;IAE/D;;OAEG;IACH,eAAe,IAAK,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IAEnD;;OAEG;IACH,uBAAuB,IAAK,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;CAC7D"}
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAgDA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AA8D9D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,KAAW;IACtC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB;;OAEG;IACH,6DAAa,CAAA;IAEb;;OAEG;IACH,2DAAQ,CAAA;AACV,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB"}
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAiDA,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAA;AA8D9D;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,KAAW;IACtC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB;;OAEG;IACH,6DAAa,CAAA;IAEb;;OAEG;IACH,2DAAQ,CAAA;AACV,CAAC,EAVW,cAAc,KAAd,cAAc,QAUzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface",
3
- "version": "2.10.5",
3
+ "version": "2.11.0-0f68898e6",
4
4
  "description": "The interface implemented by a libp2p node",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface#readme",
@@ -44,7 +44,6 @@
44
44
  "@multiformats/dns": "^1.0.6",
45
45
  "@multiformats/multiaddr": "^12.4.4",
46
46
  "it-pushable": "^3.2.3",
47
- "it-stream-types": "^2.0.2",
48
47
  "main-event": "^1.0.1",
49
48
  "multiformats": "^13.3.6",
50
49
  "progress-events": "^1.0.1",
@@ -1,8 +1,4 @@
1
- import type { MultiaddrConnection } from './connection.js'
2
- import type { AbortOptions, StreamMuxerFactory } from './index.js'
3
- import type { PeerId } from './peer-id.js'
4
- import type { Duplex } from 'it-stream-types'
5
- import type { Uint8ArrayList } from 'uint8arraylist'
1
+ import type { AbortOptions, StreamMuxerFactory, PeerId, MessageStream } from './index.js'
6
2
 
7
3
  /**
8
4
  * If the remote PeerId is known and passed as an option, the securing operation
@@ -10,6 +6,9 @@ import type { Uint8ArrayList } from 'uint8arraylist'
10
6
  * corresponds to the public key the remote PeerId is derived from.
11
7
  */
12
8
  export interface SecureConnectionOptions extends AbortOptions {
9
+ /**
10
+ * This will be set if the remote peer is known in advance
11
+ */
13
12
  remotePeer?: PeerId
14
13
 
15
14
  /**
@@ -33,19 +32,30 @@ export interface ConnectionEncrypter<Extension = unknown> {
33
32
  * pass it for extra verification, otherwise it will be determined during
34
33
  * the handshake.
35
34
  */
36
- secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
35
+ secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
37
36
 
38
37
  /**
39
38
  * Decrypt incoming data. If the remote PeerId is known,
40
39
  * pass it for extra verification, otherwise it will be determined during
41
40
  * the handshake
42
41
  */
43
- secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
42
+ secureInbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
44
43
  }
45
44
 
46
- export interface SecuredConnection<Stream = any, Extension = unknown> {
47
- conn: Stream
45
+ export interface SecuredConnection<Extension = unknown> {
46
+ /**
47
+ * The decrypted data stream
48
+ */
49
+ connection: MessageStream
50
+
51
+ /**
52
+ * Any extension data transferred as part of the encryption handshake
53
+ */
48
54
  remoteExtensions?: Extension
55
+
56
+ /**
57
+ * The identifier of the remote peer
58
+ */
49
59
  remotePeer: PeerId
50
60
 
51
61
  /**
@@ -1,5 +1,4 @@
1
- import type { MultiaddrConnection } from './connection.js'
2
- import type { PeerId } from './peer-id.js'
1
+ import type { MultiaddrConnection, PeerId } from './index.js'
3
2
  import type { Multiaddr } from '@multiformats/multiaddr'
4
3
 
5
4
  export interface ConnectionGater {
@@ -0,0 +1,9 @@
1
+ import type { AbortOptions, MessageStream } from './index.ts'
2
+
3
+ export interface ConnectionProtector {
4
+ /**
5
+ * Takes a MessageStream and creates a private encryption stream between
6
+ * the two peers from the shared key the Protector instance was created with.
7
+ */
8
+ protect (connection: MessageStream, options?: AbortOptions): Promise<MessageStream>
9
+ }