@libp2p/interface 2.11.0-8484de8a2 → 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.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/connection-encrypter.d.ts +15 -17
- package/dist/src/connection-encrypter.d.ts.map +1 -1
- package/dist/src/connection-gater.d.ts +2 -1
- package/dist/src/connection-gater.d.ts.map +1 -1
- package/dist/src/connection.d.ts +233 -36
- package/dist/src/connection.d.ts.map +1 -1
- package/dist/src/connection.js.map +1 -1
- package/dist/src/errors.d.ts +0 -32
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +0 -44
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +3 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -7
- package/dist/src/index.js.map +1 -1
- package/dist/src/metrics.d.ts +2 -2
- package/dist/src/metrics.d.ts.map +1 -1
- package/dist/src/pubsub.d.ts +3 -1
- package/dist/src/pubsub.d.ts.map +1 -1
- package/dist/src/pubsub.js.map +1 -1
- package/dist/src/stream-handler.d.ts +13 -2
- package/dist/src/stream-handler.d.ts.map +1 -1
- package/dist/src/stream-muxer.d.ts +30 -113
- package/dist/src/stream-muxer.d.ts.map +1 -1
- package/dist/src/topology.d.ts +2 -2
- package/dist/src/topology.d.ts.map +1 -1
- package/dist/src/transport.d.ts +13 -20
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/transport.js.map +1 -1
- package/package.json +5 -4
- package/src/connection-encrypter.ts +16 -19
- package/src/connection-gater.ts +2 -1
- package/src/connection.ts +270 -38
- package/src/errors.ts +0 -52
- package/src/index.ts +3 -10
- package/src/metrics.ts +2 -2
- package/src/pubsub.ts +3 -1
- package/src/stream-handler.ts +15 -2
- package/src/stream-muxer.ts +30 -122
- package/src/topology.ts +2 -2
- package/src/transport.ts +14 -25
- package/dist/src/connection-protector.d.ts +0 -9
- package/dist/src/connection-protector.d.ts.map +0 -1
- package/dist/src/connection-protector.js +0 -2
- package/dist/src/connection-protector.js.map +0 -1
- package/dist/src/events.d.ts +0 -26
- package/dist/src/events.d.ts.map +0 -1
- package/dist/src/events.js +0 -36
- package/dist/src/events.js.map +0 -1
- package/dist/src/message-stream.d.ts +0 -145
- package/dist/src/message-stream.d.ts.map +0 -1
- package/dist/src/message-stream.js +0 -2
- package/dist/src/message-stream.js.map +0 -1
- package/dist/src/multiaddr-connection.d.ts +0 -25
- package/dist/src/multiaddr-connection.d.ts.map +0 -1
- package/dist/src/multiaddr-connection.js +0 -2
- package/dist/src/multiaddr-connection.js.map +0 -1
- package/dist/src/stream.d.ts +0 -63
- package/dist/src/stream.d.ts.map +0 -1
- package/dist/src/stream.js +0 -2
- package/dist/src/stream.js.map +0 -1
- package/src/connection-protector.ts +0 -9
- package/src/events.ts +0 -44
- package/src/message-stream.ts +0 -168
- package/src/multiaddr-connection.ts +0 -27
- package/src/stream.ts +0 -70
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
package/src/events.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A custom implementation of MessageEvent as the Undici version does too much
|
|
5
|
-
* validation in it's constructor so is very slow.
|
|
6
|
-
*/
|
|
7
|
-
export class StreamMessageEvent extends Event {
|
|
8
|
-
public data: Uint8Array | Uint8ArrayList
|
|
9
|
-
|
|
10
|
-
constructor (data: Uint8Array | Uint8ArrayList, eventInitDict?: EventInit) {
|
|
11
|
-
super('message', eventInitDict)
|
|
12
|
-
|
|
13
|
-
this.data = data
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* An event dispatched when the stream is closed. The `error` property can be
|
|
19
|
-
* inspected to discover if the closing was graceful or not, and the `remote`
|
|
20
|
-
* property shows which end of the stream initiated the closure
|
|
21
|
-
*/
|
|
22
|
-
export class StreamCloseEvent extends Event {
|
|
23
|
-
public error?: Error
|
|
24
|
-
public local?: boolean
|
|
25
|
-
|
|
26
|
-
constructor (local?: boolean, error?: Error, eventInitDict?: EventInit) {
|
|
27
|
-
super('close', eventInitDict)
|
|
28
|
-
|
|
29
|
-
this.error = error
|
|
30
|
-
this.local = local
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class StreamAbortEvent extends StreamCloseEvent {
|
|
35
|
-
constructor (error: Error, eventInitDict?: EventInit) {
|
|
36
|
-
super(true, error, eventInitDict)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export class StreamResetEvent extends StreamCloseEvent {
|
|
41
|
-
constructor (error: Error, eventInitDict?: EventInit) {
|
|
42
|
-
super(false, error, eventInitDict)
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/message-stream.ts
DELETED
|
@@ -1,168 +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 an 'error' event emitted.
|
|
104
|
-
*/
|
|
105
|
-
maxReadBufferLength: number
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* If no data is transmitted over the stream in this many ms, the stream will
|
|
109
|
-
* be aborted with an InactivityTimeoutError
|
|
110
|
-
*/
|
|
111
|
-
inactivityTimeout: number
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* If this property is `true`, the underlying transport has signalled that its
|
|
115
|
-
* write buffer is full and that `.send` should not be called again.
|
|
116
|
-
*
|
|
117
|
-
* A `drain` event will be emitted after which is its safe to call `.send`
|
|
118
|
-
* again to resume sending.
|
|
119
|
-
*/
|
|
120
|
-
writableNeedsDrain: boolean
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Write data to the stream. If the method returns false it means the
|
|
124
|
-
* internal buffer is now full and the caller should wait for the 'drain'
|
|
125
|
-
* event before sending more data.
|
|
126
|
-
*
|
|
127
|
-
* This method may throw if:
|
|
128
|
-
* - The internal send buffer is full
|
|
129
|
-
* - The stream has previously been closed for writing locally or remotely
|
|
130
|
-
*/
|
|
131
|
-
send (data: Uint8Array | Uint8ArrayList): boolean
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Stop accepting new data to send and return a promise that resolves when any
|
|
135
|
-
* unsent data has been written into the underlying resource.
|
|
136
|
-
*/
|
|
137
|
-
close (options?: AbortOptions): Promise<void>
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Stop accepting new data to send, discard any unsent/unread data, and emit a
|
|
141
|
-
* 'close' event with the 'error' property set to the passed error.
|
|
142
|
-
*/
|
|
143
|
-
abort (err: Error): void
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Stop emitting further 'message' events. Any received data will be stored in
|
|
147
|
-
* an internal buffer. If the buffer size reaches `maxReadBufferLength`, the
|
|
148
|
-
* stream will be reset and a StreamAbortEvent emitted.
|
|
149
|
-
*
|
|
150
|
-
* If the underlying resource supports it, the remote peer will be instructed
|
|
151
|
-
* to pause transmission of further data.
|
|
152
|
-
*/
|
|
153
|
-
pause (): void
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Resume emitting 'message' events.
|
|
157
|
-
*
|
|
158
|
-
* If the underlying resource supports it, the remote peer will be informed
|
|
159
|
-
* that it is ok to start sending data again.
|
|
160
|
-
*/
|
|
161
|
-
resume (): void
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Queue the passed data to be emitted as a 'message' event either during the
|
|
165
|
-
* next tick or sooner if data is received from the underlying resource.
|
|
166
|
-
*/
|
|
167
|
-
push (buf: Uint8Array | Uint8ArrayList): void
|
|
168
|
-
}
|
|
@@ -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
|
-
}
|