@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,183 +0,0 @@
1
- import type { Logger, StreamCloseEvent, StreamMessageEvent, TypedEventTarget, AbortOptions } from './index.js'
2
- import type { Uint8ArrayList } from 'uint8arraylist'
3
-
4
- /**
5
- * The direction of the message stream
6
- */
7
- export type MessageStreamDirection = 'inbound' | 'outbound'
8
-
9
- /**
10
- * The states a message stream can be in
11
- */
12
- export type MessageStreamStatus = 'open' | 'closing' | 'closed' | 'aborted' | 'reset'
13
-
14
- /**
15
- * The states the readable end of a message stream can be in
16
- */
17
- export type MessageStreamReadStatus = 'readable' | 'paused' | 'closing' | 'closed'
18
-
19
- /**
20
- * The states the writable end of a message stream can be in
21
- */
22
- export type MessageStreamWriteStatus = 'writable' | 'closing' | 'closed'
23
-
24
- /**
25
- * An object that records the times of various events
26
- */
27
- export interface MessageStreamTimeline {
28
- /**
29
- * A timestamp of when the message stream was opened
30
- */
31
- open: number
32
-
33
- /**
34
- * A timestamp of when the message stream was closed for both reading and
35
- * writing by both ends of the stream
36
- */
37
- close?: number
38
- }
39
-
40
- export interface MessageStreamEvents {
41
- /**
42
- * Data was received from the remote end of the message stream
43
- */
44
- message: StreamMessageEvent
45
-
46
- /**
47
- * The local send buffer has emptied and the stream may be written to once
48
- * more, unless it is currently closing.
49
- */
50
- drain: Event
51
-
52
- /**
53
- * The underlying resource is closed - no further events will be emitted and
54
- * the stream cannot be used to send or receive any more data.
55
- *
56
- * When the `.error` field is set, the `local` property of the event will be
57
- * `true` value if the `.abort` was invoked, otherwise it means a remote error
58
- * occurred and the peer sent a reset signal.
59
- */
60
- close: StreamCloseEvent
61
-
62
- /**
63
- * Where the stream implementation supports half-closing, it may emit this
64
- * event when the remote end of the stream closes it's writable end.
65
- *
66
- * After this event is received no further 'message' events will be emitted
67
- * though the stream can still be written to, if it has not been closed at
68
- * this end.
69
- */
70
- remoteCloseWrite: Event
71
-
72
- /**
73
- * The outgoing write queue emptied - there are no more bytes queued for
74
- * sending to the remote end of the stream.
75
- */
76
- idle: Event
77
- }
78
-
79
- export interface MessageStream<Timeline extends MessageStreamTimeline = MessageStreamTimeline> extends TypedEventTarget<MessageStreamEvents>, AsyncIterable<Uint8Array | Uint8ArrayList> {
80
- /**
81
- * The current status of the message stream
82
- */
83
- status: MessageStreamStatus
84
-
85
- /**
86
- * Timestamps of when stream events occurred
87
- */
88
- timeline: Timeline
89
-
90
- /**
91
- * A logging implementation that can be used to log stream-specific messages
92
- */
93
- log: Logger
94
-
95
- /**
96
- * Whether this stream is inbound or outbound
97
- */
98
- direction: MessageStreamDirection
99
-
100
- /**
101
- * The maximum number of bytes to store when paused. If receipt of more bytes
102
- * from the remote end of the stream causes the buffer size to exceed this
103
- * value the stream will be reset and a 'close' event emitted.
104
- *
105
- * This value can be changed at runtime.
106
- */
107
- maxReadBufferLength: number
108
-
109
- /**
110
- * When the `.send` method returns false it means that the underlying resource
111
- * has signalled that it's write buffer is full. If the user continues to call
112
- * `.send`, outgoing bytes are stored in an internal buffer until the
113
- * underlying resource signals that it can accept more data.
114
- *
115
- * If the size of that internal buffer exceed this value the stream will be
116
- * reset and a 'close' event emitted.
117
- *
118
- * This value can be changed at runtime.
119
- */
120
- maxWriteBufferLength?: number
121
-
122
- /**
123
- * If no data is transmitted over the stream in this many ms, the stream will
124
- * be aborted with an InactivityTimeoutError
125
- */
126
- inactivityTimeout: number
127
-
128
- /**
129
- * If this property is `true`, the underlying transport has signalled that its
130
- * write buffer is full and that `.send` should not be called again.
131
- *
132
- * A `drain` event will be emitted after which is its safe to call `.send`
133
- * again to resume sending.
134
- */
135
- writableNeedsDrain: boolean
136
-
137
- /**
138
- * Write data to the stream. If the method returns false it means the
139
- * internal buffer is now full and the caller should wait for the 'drain'
140
- * event before sending more data.
141
- *
142
- * This method may throw if:
143
- * - The internal send buffer is full
144
- * - The stream has previously been closed for writing locally or remotely
145
- */
146
- send (data: Uint8Array | Uint8ArrayList): boolean
147
-
148
- /**
149
- * Stop accepting new data to send and return a promise that resolves when any
150
- * unsent data has been written into the underlying resource.
151
- */
152
- close (options?: AbortOptions): Promise<void>
153
-
154
- /**
155
- * Stop accepting new data to send, discard any unsent/unread data, and emit a
156
- * 'close' event with the 'error' property set to the passed error.
157
- */
158
- abort (err: Error): void
159
-
160
- /**
161
- * Stop emitting further 'message' events. Any received data will be stored in
162
- * an internal buffer. If the buffer size reaches `maxReadBufferLength`, the
163
- * stream will be reset and a StreamAbortEvent emitted.
164
- *
165
- * If the underlying resource supports it, the remote peer will be instructed
166
- * to pause transmission of further data.
167
- */
168
- pause (): void
169
-
170
- /**
171
- * Resume emitting 'message' events.
172
- *
173
- * If the underlying resource supports it, the remote peer will be informed
174
- * that it is ok to start sending data again.
175
- */
176
- resume (): void
177
-
178
- /**
179
- * Queue the passed data to be emitted as a 'message' event either during the
180
- * next tick or sooner if data is received from the underlying resource.
181
- */
182
- push (buf: Uint8Array | Uint8ArrayList): void
183
- }
@@ -1,27 +0,0 @@
1
- import type { MessageStream, MessageStreamTimeline } from './message-stream.ts'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
-
4
- export interface MultiaddrConnectionTimeline extends MessageStreamTimeline {
5
- /**
6
- * When the MultiaddrConnection was upgraded to a Connection - the type of
7
- * connection encryption and multiplexing was negotiated.
8
- */
9
- upgraded?: number
10
- }
11
-
12
- /**
13
- * A MultiaddrConnection is returned by a transport after dialing a peer. It is
14
- * a low-level primitive and is the raw connection, typically without encryption
15
- * or stream multiplexing.
16
- */
17
- export interface MultiaddrConnection extends MessageStream<MultiaddrConnectionTimeline> {
18
- /**
19
- * The address of the remote end of the connection
20
- */
21
- remoteAddr: Multiaddr
22
-
23
- /**
24
- * When stream life cycle events occurred
25
- */
26
- timeline: MultiaddrConnectionTimeline
27
- }
package/src/stream.ts DELETED
@@ -1,70 +0,0 @@
1
- import type { AbortOptions } from './index.ts'
2
- import type { MessageStream, MessageStreamReadStatus, MessageStreamWriteStatus } from './message-stream.js'
3
-
4
- /**
5
- * A Stream is a lightweight data channel between two peers that can be written
6
- * to and read from at both ends.
7
- *
8
- * It is half-closable - that is in order for it to be closed fully and any
9
- * associated memory reclaimed, both ends must close their writeable end of the
10
- * stream.
11
- *
12
- * It's also possible to close the readable end of the stream, but this depends
13
- * on the underlying stream muxer supporting this operation which not all do.
14
- */
15
- export interface Stream extends MessageStream {
16
- /**
17
- * Unique identifier for a stream. Identifiers are not unique across muxers.
18
- */
19
- id: string
20
-
21
- /**
22
- * The protocol negotiated for this stream
23
- */
24
- protocol: string
25
-
26
- /**
27
- * The status of the readable end of the stream
28
- */
29
- readStatus: MessageStreamReadStatus
30
-
31
- /**
32
- * The status of the writable end of the stream
33
- */
34
- writeStatus: MessageStreamWriteStatus
35
-
36
- /**
37
- * The status of the readable end of the remote end of the stream - n.b. this
38
- * requires the underlying stream transport to support sending STOP_SENDING
39
- * messages or similar.
40
- */
41
- remoteReadStatus: MessageStreamReadStatus
42
-
43
- /**
44
- * The status of the writable end of the remote end of the stream
45
- */
46
- remoteWriteStatus: MessageStreamWriteStatus
47
-
48
- /**
49
- * Close stream for writing and return a promise that resolves once any
50
- * pending data has been passed to the underlying transport.
51
- *
52
- * Note that the stream itself will remain readable until the remote end also
53
- * closes it's writable end.
54
- *
55
- * To close without waiting for the remote, call `.abort` instead. If you want
56
- * to wait for data to be sent first, ensure if the `.writableStatus` property
57
- * is not 'paused', if it is, wait for a `drain` event before aborting.
58
- */
59
- close (options?: AbortOptions): Promise<void>
60
-
61
- /**
62
- * Send a message to the remote end of the stream informing them that any
63
- * incoming data will be discarded so they should stop sending.
64
- *
65
- * This requires the underlying resource to support this operation - for
66
- * example the QUIC, WebTransport, WebRTC transports do but anything
67
- * multiplexed using Yamux or Mplex do not.
68
- */
69
- closeRead(options?: AbortOptions): Promise<void>
70
- }