import { type Connection } from "https://deno.land/x/smoldot2@light-js-deno-v2.0.31/internals/client.d.ts";
Connection to a remote node.
At any time, a connection can be in one of the following states:
Open
(initial state)Reset
When in the Open
state, the connection can transition to the Reset
state if the remote
closes the connection or refuses the connection altogether. When that happens, config.onReset
is called. Once in the Reset
state, the connection cannot transition back to Open
.
When in the Open
state, the connection can receive messages. When a message is received,
config.onMessage
is called.
Methods
Transitions the connection or one of its substreams to the Reset
state.
If the connection is of type "single-stream", the whole connection must be shut down.
If the connection is of type "multi-stream", a streamId
can be provided, in which case
only the given substream is shut down.
The config.onReset
or config.onStreamReset
callbacks are not called.
The transition is performed in the background.
If the whole connection is to be shut down, none of the callbacks passed to the Config
must be called again. If only a substream is shut down, the onStreamReset
and onMessage
callbacks must not be called again with that substream.
Queues data to be sent on the given connection.
The connection and stream must currently be in the Open
state.
The number of bytes must never exceed the number of "writable bytes" of the stream.
onWritableBytes
can be used in order to notify that more writable bytes are available.
The streamId
must be provided if and only if the connection is of type "multi-stream".
It indicates which substream to send the data on.
Must not be called after closeSend
has been called.
Closes the writing side of the given stream of the given connection.
Never called for connection types where this isn't possible to implement (i.e. WebSocket and WebRTC at the moment).
The connection and stream must currently be in the Open
state.
Implicitly sets the "writable bytes" of the stream to zero.
The streamId
must be provided if and only if the connection is of type "multi-stream".
It indicates which substream to send the data on.
Must only be called once per stream.
Start opening an additional outbound substream on the given connection.
The state of the connection must be Open
. This function must only be called for
connections of type "multi-stream".
The onStreamOpened
callback must later be called with an outbound direction.
Note that no mechanism exists in this API to handle the situation where a substream fails to open, as this is not supposed to happen. If you need to handle such a situation, either try again opening a substream again or reset the entire connection.