import { type Connection } from "https://deno.land/x/smoldot@light-js-deno-v0.6.32/instance/bindings-smoldot-light.d.ts";
Connection to a remote node.
At any time, a connection can be in one of the three following states:
Opening
(initial state)Open
Closed
When in the Opening
or Open
state, the connection can transition to the Closed
state
if the remote closes the connection or refuses the connection altogether. When that
happens, config.onClosed
is called. Once in the Closed
state, the connection cannot
transition back to another state.
Initially in the Opening
state, the connection can transition to the Open
state if the
remote accepts the connection. When that happens, config.onOpen
is called.
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 Closed
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.onClose
or config.onStreamClose
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 onStreamClose
and onMessage
callbacks must not be called again with that substream.
Queues data to be sent on the given connection.
The connection must currently be in the Open
state.
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.