@libp2p/interface 2.11.0-6059227cb → 2.11.0-87bc8d4fb

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 (72) 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 +15 -17
  4. package/dist/src/connection-encrypter.d.ts.map +1 -1
  5. package/dist/src/connection-gater.d.ts +2 -1
  6. package/dist/src/connection-gater.d.ts.map +1 -1
  7. package/dist/src/connection.d.ts +233 -36
  8. package/dist/src/connection.d.ts.map +1 -1
  9. package/dist/src/connection.js.map +1 -1
  10. package/dist/src/errors.d.ts +0 -14
  11. package/dist/src/errors.d.ts.map +1 -1
  12. package/dist/src/errors.js +0 -20
  13. package/dist/src/errors.js.map +1 -1
  14. package/dist/src/index.d.ts +5 -35
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +3 -7
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/metrics.d.ts +2 -2
  19. package/dist/src/metrics.d.ts.map +1 -1
  20. package/dist/src/peer-store.d.ts +4 -0
  21. package/dist/src/peer-store.d.ts.map +1 -1
  22. package/dist/src/pubsub.d.ts +248 -0
  23. package/dist/src/pubsub.d.ts.map +1 -0
  24. package/dist/src/pubsub.js +47 -0
  25. package/dist/src/pubsub.js.map +1 -0
  26. package/dist/src/stream-handler.d.ts +13 -12
  27. package/dist/src/stream-handler.d.ts.map +1 -1
  28. package/dist/src/stream-muxer.d.ts +30 -113
  29. package/dist/src/stream-muxer.d.ts.map +1 -1
  30. package/dist/src/topology.d.ts +3 -3
  31. package/dist/src/topology.d.ts.map +1 -1
  32. package/dist/src/transport.d.ts +13 -20
  33. package/dist/src/transport.d.ts.map +1 -1
  34. package/dist/src/transport.js.map +1 -1
  35. package/package.json +6 -4
  36. package/src/connection-encrypter.ts +16 -19
  37. package/src/connection-gater.ts +2 -1
  38. package/src/connection.ts +270 -38
  39. package/src/errors.ts +0 -24
  40. package/src/index.ts +5 -38
  41. package/src/metrics.ts +2 -2
  42. package/src/peer-store.ts +5 -0
  43. package/src/pubsub.ts +286 -0
  44. package/src/stream-handler.ts +15 -14
  45. package/src/stream-muxer.ts +30 -122
  46. package/src/topology.ts +3 -3
  47. package/src/transport.ts +14 -25
  48. package/dist/src/connection-protector.d.ts +0 -9
  49. package/dist/src/connection-protector.d.ts.map +0 -1
  50. package/dist/src/connection-protector.js +0 -2
  51. package/dist/src/connection-protector.js.map +0 -1
  52. package/dist/src/events.d.ts +0 -26
  53. package/dist/src/events.d.ts.map +0 -1
  54. package/dist/src/events.js +0 -36
  55. package/dist/src/events.js.map +0 -1
  56. package/dist/src/message-stream.d.ts +0 -159
  57. package/dist/src/message-stream.d.ts.map +0 -1
  58. package/dist/src/message-stream.js +0 -2
  59. package/dist/src/message-stream.js.map +0 -1
  60. package/dist/src/multiaddr-connection.d.ts +0 -25
  61. package/dist/src/multiaddr-connection.d.ts.map +0 -1
  62. package/dist/src/multiaddr-connection.js +0 -2
  63. package/dist/src/multiaddr-connection.js.map +0 -1
  64. package/dist/src/stream.d.ts +0 -63
  65. package/dist/src/stream.d.ts.map +0 -1
  66. package/dist/src/stream.js +0 -2
  67. package/dist/src/stream.js.map +0 -1
  68. package/src/connection-protector.ts +0 -9
  69. package/src/events.ts +0 -44
  70. package/src/message-stream.ts +0 -183
  71. package/src/multiaddr-connection.ts +0 -27
  72. package/src/stream.ts +0 -70
@@ -1 +1 @@
1
- {"version":3,"file":"topology.d.ts","sourceRoot":"","sources":["../../src/topology.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAE1C;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;IAC7B,GAAG,CAAE,MAAM,EAAE,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earableSignal, ConnectionEncrypter, MultiaddrConnection, Connection, ConnectionLimits, StreamMuxerFactory, PeerId } from './index.js';
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';
2
4
  import type { Multiaddr } from '@multiformats/multiaddr';
3
5
  import type { TypedEventTarget } from 'main-event';
4
6
  import type { ProgressOptions, ProgressEvent } from 'progress-events';
@@ -112,6 +114,14 @@ export declare enum FaultTolerance {
112
114
  * Options accepted by the upgrader during connection establishment
113
115
  */
114
116
  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;
115
125
  /**
116
126
  * If true no connection protection will be performed on the connection.
117
127
  */
@@ -137,35 +147,18 @@ export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent =
137
147
  */
138
148
  initiator?: boolean;
139
149
  }
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
- }
155
150
  export type InboundConnectionUpgradeEvents = ProgressEvent<'upgrader:encrypt-inbound-connection'> | ProgressEvent<'upgrader:multiplex-inbound-connection'>;
156
151
  export type OutboundConnectionUpgradeEvents = ProgressEvent<'upgrader:encrypt-outbound-connection'> | ProgressEvent<'upgrader:multiplex-outbound-connection'>;
157
152
  export interface Upgrader {
158
153
  /**
159
154
  * Upgrades an outbound connection created by the `dial` method of a transport
160
155
  */
161
- upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>;
162
- upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<Connection>;
156
+ upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>;
163
157
  /**
164
158
  * Upgrades an inbound connection received by a transport listener and
165
159
  * notifies other libp2p components about the new connection
166
160
  */
167
- upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>;
168
- upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<void>;
161
+ upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>;
169
162
  /**
170
163
  * Used by transports that perform part of the upgrade process themselves and
171
164
  * 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,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnK,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,SAAS,EAAE,WAAW,CAAA;IAEtB;;OAEG;IACH,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAA;IAEzB;;;OAGG;IACH,KAAK,EAAE,WAAW,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ings":"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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface",
3
- "version": "2.11.0-6059227cb",
3
+ "version": "2.11.0-87bc8d4fb",
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",
@@ -42,14 +42,16 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@multiformats/dns": "^1.0.6",
45
- "@multiformats/multiaddr": "^13.0.1",
45
+ "@multiformats/multiaddr": "^12.4.4",
46
+ "it-pushable": "^3.2.3",
47
+ "it-stream-types": "^2.0.2",
46
48
  "main-event": "^1.0.1",
47
- "multiformats": "^13.4.0",
49
+ "multiformats": "^13.3.6",
48
50
  "progress-events": "^1.0.1",
49
51
  "uint8arraylist": "^2.4.8"
50
52
  },
51
53
  "devDependencies": {
52
- "aegir": "^47.0.22"
54
+ "aegir": "^47.0.14"
53
55
  },
54
56
  "sideEffects": false
55
57
  }
@@ -1,4 +1,8 @@
1
- import type { AbortOptions, StreamMuxerFactory, PeerId, MessageStream } from './index.js'
1
+ import type { MultiaddrConnection } from './connection.js'
2
+ import type { AbortOptions, Logger, 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'
2
6
 
3
7
  /**
4
8
  * If the remote PeerId is known and passed as an option, the securing operation
@@ -6,9 +10,6 @@ import type { AbortOptions, StreamMuxerFactory, PeerId, MessageStream } from './
6
10
  * corresponds to the public key the remote PeerId is derived from.
7
11
  */
8
12
  export interface SecureConnectionOptions extends AbortOptions {
9
- /**
10
- * This will be set if the remote peer is known in advance
11
- */
12
13
  remotePeer?: PeerId
13
14
 
14
15
  /**
@@ -20,6 +21,13 @@ export interface SecureConnectionOptions extends AbortOptions {
20
21
  skipStreamMuxerNegotiation?: boolean
21
22
  }
22
23
 
24
+ /**
25
+ * A stream with an optional logger
26
+ */
27
+ export interface SecurableStream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
28
+ log?: Logger
29
+ }
30
+
23
31
  /**
24
32
  * A libp2p connection encrypter module must be compliant to this interface
25
33
  * to ensure all exchanged data between two peers is encrypted.
@@ -32,30 +40,19 @@ export interface ConnectionEncrypter<Extension = unknown> {
32
40
  * pass it for extra verification, otherwise it will be determined during
33
41
  * the handshake.
34
42
  */
35
- secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
43
+ secureOutbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
36
44
 
37
45
  /**
38
46
  * Decrypt incoming data. If the remote PeerId is known,
39
47
  * pass it for extra verification, otherwise it will be determined during
40
48
  * the handshake
41
49
  */
42
- secureInbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection<Extension>>
50
+ secureInbound <Stream extends SecurableStream = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>
43
51
  }
44
52
 
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
- */
53
+ export interface SecuredConnection<Stream = any, Extension = unknown> {
54
+ conn: Stream
54
55
  remoteExtensions?: Extension
55
-
56
- /**
57
- * The identifier of the remote peer
58
- */
59
56
  remotePeer: PeerId
60
57
 
61
58
  /**
@@ -1,4 +1,5 @@
1
- import type { MultiaddrConnection, PeerId } from './index.js'
1
+ import type { MultiaddrConnection } from './connection.js'
2
+ import type { PeerId } from './peer-id.js'
2
3
  import type { Multiaddr } from '@multiformats/multiaddr'
3
4
 
4
5
  export interface ConnectionGater {
package/src/connection.ts CHANGED
@@ -1,29 +1,179 @@
1
- import type { AbortOptions, Logger, TypedEventTarget, Stream, MessageStreamEvents, PeerId, MultiaddrConnectionTimeline, MessageStreamStatus, MessageStreamDirection } from './index.js'
1
+ import type { AbortOptions, Logger } from './index.js'
2
+ import type { PeerId } from './peer-id.js'
2
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
+ import type { Duplex, Source } from 'it-stream-types'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
3
6
 
4
- export type ConnectionStatus = MessageStreamStatus
7
+ export interface ConnectionTimeline {
8
+ /**
9
+ * When the connection was opened
10
+ */
11
+ open: number
12
+
13
+ /**
14
+ * When the MultiaddrConnection was upgraded to a Connection - e.g. the type
15
+ * of connection encryption and multiplexing was negotiated.
16
+ */
17
+ upgraded?: number
18
+
19
+ /**
20
+ * When the connection was closed.
21
+ */
22
+ close?: number
23
+ }
5
24
 
6
25
  /**
7
- * Connection limits are present on connections that are only allowed to
8
- * transfer a certain amount of bytes or be open for a certain number
9
- * of seconds.
26
+ * Outbound connections are opened by the local node, inbound streams are opened by the remote
27
+ */
28
+ export type Direction = 'inbound' | 'outbound'
29
+
30
+ export interface StreamTimeline {
31
+ /**
32
+ * A timestamp of when the stream was opened
33
+ */
34
+ open: number
35
+
36
+ /**
37
+ * A timestamp of when the stream was closed for both reading and writing
38
+ */
39
+ close?: number
40
+
41
+ /**
42
+ * A timestamp of when the stream was closed for reading
43
+ */
44
+ closeRead?: number
45
+
46
+ /**
47
+ * A timestamp of when the stream was closed for writing
48
+ */
49
+ closeWrite?: number
50
+
51
+ /**
52
+ * A timestamp of when the stream was reset
53
+ */
54
+ reset?: number
55
+
56
+ /**
57
+ * A timestamp of when the stream was aborted
58
+ */
59
+ abort?: number
60
+ }
61
+
62
+ /**
63
+ * The states a stream can be in
64
+ */
65
+ export type StreamStatus = 'open' | 'closing' | 'closed' | 'aborted' | 'reset'
66
+
67
+ /**
68
+ * The states the readable end of a stream can be in
10
69
  *
11
- * These limits are applied by Circuit Relay v2 servers, for example and
12
- * the connection will normally be closed abruptly if the limits are
13
- * exceeded.
70
+ * ready - the readable end is ready for reading
71
+ * closing - the readable end is closing
72
+ * closed - the readable end has closed
14
73
  */
15
- export interface ConnectionLimits {
74
+ export type ReadStatus = 'ready' | 'closing' | 'closed'
75
+
76
+ /**
77
+ * The states the writable end of a stream can be in
78
+ *
79
+ * ready - the writable end is ready for writing
80
+ * writing - the writable end is in the process of being written to
81
+ * done - the source passed to the `.sink` function yielded all values without error
82
+ * closing - the writable end is closing
83
+ * closed - the writable end has closed
84
+ */
85
+ export type WriteStatus = 'ready' | 'writing' | 'done' | 'closing' | 'closed'
86
+
87
+ /**
88
+ * A Stream is a data channel between two peers that
89
+ * can be written to and read from at both ends.
90
+ *
91
+ * It may be encrypted and multiplexed depending on the
92
+ * configuration of the nodes.
93
+ */
94
+ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>, Promise<void>> {
16
95
  /**
17
- * If present this is the number of bytes remaining that may be
18
- * transferred over this connection
96
+ * Closes the stream for **reading** *and* **writing**.
97
+ *
98
+ * Any buffered data in the source can still be consumed and the stream will end normally.
99
+ *
100
+ * This will cause a `CLOSE` message to be sent to the remote, *unless* the sink has already ended.
101
+ *
102
+ * The sink and the source will return normally.
19
103
  */
20
- bytes?: bigint
104
+ close(options?: AbortOptions): Promise<void>
21
105
 
22
106
  /**
23
- * If present this is the number of seconds that this connection will
24
- * remain open for
107
+ * 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.
108
+ *
109
+ * This function is called automatically by the muxer when it receives a `CLOSE` message from the remote.
110
+ *
111
+ * The source will return normally, the sink will continue to consume.
25
112
  */
26
- seconds?: number
113
+ closeRead(options?: AbortOptions): Promise<void>
114
+
115
+ /**
116
+ * 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.
117
+ *
118
+ * The source will return normally, the sink will continue to consume.
119
+ */
120
+ closeWrite(options?: AbortOptions): Promise<void>
121
+
122
+ /**
123
+ * Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.
124
+ *
125
+ * Note, if called without an error any buffered data in the source can still be consumed and the stream will end normally.
126
+ *
127
+ * This will cause a `RESET` message to be sent to the remote, *unless* the sink has already ended.
128
+ *
129
+ * The sink will return and the source will throw.
130
+ */
131
+ abort(err: Error): void
132
+
133
+ /**
134
+ * Unique identifier for a stream. Identifiers are not unique across muxers.
135
+ */
136
+ id: string
137
+
138
+ /**
139
+ * Outbound streams are opened by the local node, inbound streams are opened by the remote
140
+ */
141
+ direction: Direction
142
+
143
+ /**
144
+ * Lifecycle times for the stream
145
+ */
146
+ timeline: StreamTimeline
147
+
148
+ /**
149
+ * The protocol negotiated for this stream
150
+ */
151
+ protocol?: string
152
+
153
+ /**
154
+ * User defined stream metadata
155
+ */
156
+ metadata: Record<string, any>
157
+
158
+ /**
159
+ * The current status of the stream
160
+ */
161
+ status: StreamStatus
162
+
163
+ /**
164
+ * The current status of the readable end of the stream
165
+ */
166
+ readStatus: ReadStatus
167
+
168
+ /**
169
+ * The current status of the writable end of the stream
170
+ */
171
+ writeStatus: WriteStatus
172
+
173
+ /**
174
+ * The stream logger
175
+ */
176
+ log: Logger
27
177
  }
28
178
 
29
179
  export interface NewStreamOptions extends AbortOptions {
@@ -36,11 +186,10 @@ export interface NewStreamOptions extends AbortOptions {
36
186
 
37
187
  /**
38
188
  * Opt-in to running over a limited connection - one that has restrictions
39
- * on the amount of data that may be transferred or how long it may be open
40
- * for.
189
+ * on the amount of data that may be transferred or how long it may be open for.
41
190
  *
42
- * These limits are typically enforced by a relay server, if the protocol will
43
- * be transferring a lot of data or the stream will be open for a long time
191
+ * These limits are typically enforced by a relay server, if the protocol
192
+ * will be transferring a lot of data or the stream will be open for a long time
44
193
  * consider upgrading to a direct connection before opening the stream.
45
194
  *
46
195
  * @default false
@@ -75,13 +224,38 @@ export interface NewStreamOptions extends AbortOptions {
75
224
  negotiateFully?: boolean
76
225
  }
77
226
 
227
+ export type ConnectionStatus = 'open' | 'closing' | 'closed'
228
+
229
+ /**
230
+ * Connection limits are present on connections that are only allowed to
231
+ * transfer a certain amount of bytes or be open for a certain number
232
+ * of seconds.
233
+ *
234
+ * These limits are applied by Circuit Relay v2 servers, for example and
235
+ * the connection will normally be closed abruptly if the limits are
236
+ * exceeded.
237
+ */
238
+ export interface ConnectionLimits {
239
+ /**
240
+ * If present this is the number of bytes remaining that may be
241
+ * transferred over this connection
242
+ */
243
+ bytes?: bigint
244
+
245
+ /**
246
+ * If present this is the number of seconds that this connection will
247
+ * remain open for
248
+ */
249
+ seconds?: number
250
+ }
251
+
78
252
  /**
79
253
  * A Connection is a high-level representation of a connection
80
254
  * to a remote peer that may have been secured by encryption and
81
255
  * multiplexed, depending on the configuration of the nodes
82
256
  * between which the connection is made.
83
257
  */
84
- export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, 'drain' | 'message'>> {
258
+ export interface Connection {
85
259
  /**
86
260
  * The unique identifier for this connection
87
261
  */
@@ -97,6 +271,11 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
97
271
  */
98
272
  remotePeer: PeerId
99
273
 
274
+ /**
275
+ * A list of tags applied to this connection
276
+ */
277
+ tags: string[]
278
+
100
279
  /**
101
280
  * A list of open streams on this connection
102
281
  */
@@ -105,12 +284,12 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
105
284
  /**
106
285
  * Outbound connections are opened by the local node, inbound streams are opened by the remote
107
286
  */
108
- direction: MessageStreamDirection
287
+ direction: Direction
109
288
 
110
289
  /**
111
- * When stream life cycle events occurred
290
+ * Lifecycle times for the connection
112
291
  */
113
- timeline: MultiaddrConnectionTimeline
292
+ timeline: ConnectionTimeline
114
293
 
115
294
  /**
116
295
  * The multiplexer negotiated for this connection
@@ -127,11 +306,6 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
127
306
  */
128
307
  status: ConnectionStatus
129
308
 
130
- /**
131
- * Whether this connection is direct or, for example, is via a relay
132
- */
133
- direct: boolean
134
-
135
309
  /**
136
310
  * If present, this connection has limits applied to it, perhaps by an
137
311
  * intermediate relay. Once the limits have been reached the connection will
@@ -146,28 +320,26 @@ export interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, '
146
320
  */
147
321
  rtt?: number
148
322
 
149
- /**
150
- * The connection logger, used to log connection-specific information
151
- */
152
- log: Logger
153
-
154
323
  /**
155
324
  * Create a new stream on this connection and negotiate one of the passed protocols
156
325
  */
157
326
  newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>
158
327
 
159
328
  /**
160
- * Gracefully close the connection. The returned promise will resolve when all
161
- * queued data has been written to the underlying transport. Any unread data
162
- * will still be emitted as a 'message' event.
329
+ * Gracefully close the connection. All queued data will be written to the
330
+ * underlying transport.
163
331
  */
164
332
  close(options?: AbortOptions): Promise<void>
165
333
 
166
334
  /**
167
- * Immediately close the connection. Any data queued to be sent or read will
168
- * be discarded.
335
+ * Immediately close the connection, any queued data will be discarded
169
336
  */
170
337
  abort(err: Error): void
338
+
339
+ /**
340
+ * The connection logger
341
+ */
342
+ log: Logger
171
343
  }
172
344
 
173
345
  export const connectionSymbol = Symbol.for('@libp2p/connection')
@@ -175,3 +347,63 @@ export const connectionSymbol = Symbol.for('@libp2p/connection')
175
347
  export function isConnection (other: any): other is Connection {
176
348
  return other != null && Boolean(other[connectionSymbol])
177
349
  }
350
+
351
+ export interface ConnectionProtector {
352
+ /**
353
+ * Takes a given Connection and creates a private encryption stream
354
+ * between its two peers from the PSK the Protector instance was
355
+ * created with.
356
+ */
357
+ protect(connection: MultiaddrConnection, options?: AbortOptions): Promise<MultiaddrConnection>
358
+ }
359
+
360
+ export interface MultiaddrConnectionTimeline {
361
+ /**
362
+ * When the connection was opened
363
+ */
364
+ open: number
365
+
366
+ /**
367
+ * When the MultiaddrConnection was upgraded to a Connection - the type of
368
+ * connection encryption and multiplexing was negotiated.
369
+ */
370
+ upgraded?: number
371
+
372
+ /**
373
+ * When the connection was closed.
374
+ */
375
+ close?: number
376
+ }
377
+
378
+ /**
379
+ * A MultiaddrConnection is returned by transports after dialing
380
+ * a peer. It is a low-level primitive and is the raw connection
381
+ * without encryption or stream multiplexing.
382
+ */
383
+ export interface MultiaddrConnection extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
384
+ /**
385
+ * Gracefully close the connection. All queued data will be written to the
386
+ * underlying transport.
387
+ */
388
+ close(options?: AbortOptions): Promise<void>
389
+
390
+ /**
391
+ * Immediately close the connection, any queued data will be discarded
392
+ */
393
+ abort(err: Error): void
394
+
395
+ /**
396
+ * The address of the remote end of the connection
397
+ */
398
+ remoteAddr: Multiaddr
399
+
400
+ /**
401
+ * When connection life cycle events occurred
402
+ */
403
+ timeline: MultiaddrConnectionTimeline
404
+
405
+ /**
406
+ * The multiaddr connection logger
407
+ */
408
+ log: Logger
409
+ }
package/src/errors.ts CHANGED
@@ -144,18 +144,6 @@ export class StreamResetError extends Error {
144
144
  }
145
145
  }
146
146
 
147
- /**
148
- * Thrown when a protocol stream is aborted locally
149
- */
150
- export class StreamAbortedError extends Error {
151
- static name = 'StreamAbortedError'
152
-
153
- constructor (message = 'The stream has been aborted') {
154
- super(message)
155
- this.name = 'StreamAbortedError'
156
- }
157
- }
158
-
159
147
  /**
160
148
  * Thrown when a stream is in an invalid state
161
149
  */
@@ -168,18 +156,6 @@ export class StreamStateError extends Error {
168
156
  }
169
157
  }
170
158
 
171
- /**
172
- * Thrown when a stream buffer is full
173
- */
174
- export class StreamBufferError extends Error {
175
- static name = 'StreamBufferError'
176
-
177
- constructor (message = 'The stream buffer was full') {
178
- super(message)
179
- this.name = 'StreamBufferError'
180
- }
181
- }
182
-
183
159
  /**
184
160
  * Thrown when a value could not be found
185
161
  */