Since we don't wait for successful reconnection to existing peers,
the peerstore can be closed while we're accessing it since we might
be shut down right after we've started up, e.g. during test runs so
just log any reconnect errors instead of throwing.
* fix: add successful stream peer to protobook
If a protocol stream has been successfully negotiated and is to be
psased to the application, the peerstore should ensure that the peer is
registerd with that protocol.
* fix: upgrader test fix
Updates all deps needed to support passing lists of byte arrays where they have been created from multiple input buffers.
When reading multiplexed data, all messages arrive in length-prefixed buffers, which means the first few bytes tell the consumer how many bytes long next chunk will be.
One length prefixed chunk can be delivered in several payloads from the underlying network transport. The first payload can also include the length prefix and some or all of the data, so we stitch these together in a `Uint8ArrayList` to avoid having to concatenate `Uint8Array`s together.
Previously once we'd received enough bytes to satisfy the length prefix we'd concatenate the bytes together, but this is a potentially expensive operation where transports have small message sizes so instead just pass the `Uint8ArrayList` to the consumer and let them decide wether to concatenate or not as some consumers will be smart enough to operate on lists of `Uint8Array`s instead of always requiring a contiguous block of memory.
BREAKING CHANGE: Streams are now `Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array>`
- If a stream is opened that exceeds inbound/outbound limits, reset that stream (if it is incoming) or abort and throw (if it is outgoing)
- Make the error message more helpful (say which protocol has breached the limit)
- Increase the default stream limits so we don't trigger this by accident when a remote dials us with a protocol we don't support
Make sure we don't potentially wait forever during incoming circuit relay handshakes.
Adds a timeout option to the hop config to control how long we will wait.
If no `agentVersion` is provided for the Identify protocol, the default `AGENT_VERSION` will now be set to
* `js-libp2p/<libp2p.version> UserAgent=<process.version>` when running in Node.js
* `js-libp2p/<libp2p.version> UserAgent=<navigator.userAgent>` when running in the browser (also when running in a webworker)
Fixes#686
Supersedes #1240
Co-authored-by: Kevin Westphal <westphal@consider-it.de>
Co-authored-by: Kevin <56823591+6d7a@users.noreply.github.com>
Ensure that we don't wait forever for upgrading an inbound connection
to occur.
Note that transports should return an AbortableSource when passed an
AbortSignal so outbound connections to not need the same fix.
Also adds default timeouts for the ping, fetch, and identify protocols.
Instead of trying to connect to every peer in the peer store when
we start a node, only connect to the peers that have been marked
with a `keep-alive` tag.
Uses peer tag values to select low-value connections to prune when we have too many connections open.
BREAKING CHANGE: `connectionManager.peerValue` has been removed, use `peerStore.tagPeer` instead
Now that we need to build ts to js a build step is necessary.
Add it to the instructions where we are telling people to clone the repo first.
Refs: #1273
* feat: limit protocol streams per-connection
Uses the `maxInboundStreams` and `maxOutboundStreams` of the `registrar.handle`
opts to limit the number of concurrent streams open on each connection
on a per-protocol basis.
Both values default to 1 so some tuning will be necessary to set
appropriate values for some protocols.
* chore: make error codes consistent
* chore: fix up examples
If an error is thrown during the initial stages of setting up a multiplexed stream, ensure we close the stream to free up any resources associated with it.
Adds a config option to specify a maximum message size we'll accept
for an Identify message.
The default is 8KB, the same as go-libp2p - previously we fell back
to the default `maxMessageLength` option of `it-length-prefixed`
which is 4MB.
Also adds a default timeout for reading responses to identify
requests which is used if an AbortSignal is not passed in.
The default timeout also aligns with go-libp2p.
There are a few places in the codebase where we send/receive data from the network without timeouts/abort controllers which means the user has to wait for the underlying socket to timeout which can take a long time depending on the platform, if at all.
This change ensures we can time out while running identify (both flavours), ping and fetch and adds tests to ensure there are no regressions.
**Motivation**
In lodestar, when we handle "peer:connect" event, we dial the peer which gives another "peer:connect" event and it causes other issues
**Motivation**
In `onConnect` function, "peer:connect" event should be emitted after we add connection to the `connections` map so that when app dial the peer in "peer:connect" event handler, it uses the same/existing connection
Instead of making the `.dht` and `.pubsub` properties optional, use dummy implementations that throw exceptions if they are not configured.
This way we don't have to null guard everywhere they are accessed.