The `AbortController` class is supported by browsers and node 14+ - we only support node 16+ (e.g. LTS+Current) so the `abort-controller` module isn't needed any more.
When we've previously seen loads of peers and stored them in the
datastore we'll try to dial them as part of starting the autodial
component.
If we or our peers have bad network connections this can make
starting a libp2p node take ages so don't wait for a round of auto
dialing before considering the component started.
Small refactor of the component stats - adds a `TrackedMap` which encapsulates updating the metrics and means we don't need to null guard on `this._metrics` everywhere.
If metrics are not enabled a regular `Map` is used.
We use timeout controllers to ensure we're not dialling peers forever but we can end up registering lots of listeners for the `abort` event when peers have a lot of addresses.
In node this means we see an unhelpful `MaxListenersExceededWarning` in the console warning of a potential memory leak.
Increase the max number of listeners on the signal to silence the warning.
Implements the idea from #1060 - allows us to get some insight into what's happening in a libp2p node out side of just bandwidth stats.
Configures a few default metrics if metrics are enabled - current connections, the state of the dial queue, etc.
Also makes the `Metrics` class not depend on the `ConnectionManager` class, otherwise we can't collect simple metrics from the connection manager class due to the circular dependency.
If the `Promise.race` throws, execution of the function is terminated so the pending dial target is never removed from the map and we leak memory.
This can happen when there are invalid multiaddrs or when a peer reports more dialable addresses than the threshold.
Instead wrap the `Promise.race` in a `try/finally` which will always remove the pending dial target in the event of success or failure.
Looks like this project stopped running the `test:node` npm script when it was migrated to gh actions.
Re-enable it and fix all the related test failures.
Do not abort all attempts to find peers when `findPeers` on one router throws synchronously
Co-authored-by: Robert Kiel <robert.kiel@hoprnet.io>
Co-authored-by: achingbrain <alex@achingbrain.net>
Sometimes you encounter peers with lots of addresses. When this happens
you can attach more than 10x event listeners to the abort signal we
use to abort all the dials - this causes node to print a warning
which is misleading.
This PR increases the default number of listeners on the signal.
Fixes#900