347 Commits

Author SHA1 Message Date
Alex Potsides
978eb3676f
feat: async peerstore backed by datastores (#1058)
We have a peerstore that keeps all data for all observed peers in memory with no eviction.

This is fine when you don't discover many peers but when using the DHT you encounter a significant number of peers so our peer storage grows and grows over time.

We have a persistent peer store, but it just periodically writes peers into the datastore to be read at startup, still keeping them in memory.

It also means a restart doesn't give you any temporary reprieve from the memory leak as the previously observed peer data is read into memory at startup.

This change refactors the peerstore to use a datastore by default, reading and writing peer info as it arrives.  It can be configured with a MemoryDatastore if desired.

It was necessary to change the peerstore and *book interfaces to be asynchronous since the datastore api is asynchronous.

BREAKING CHANGE: `libp2p.handle`, `libp2p.registrar.register` and the peerstore methods have become async
2022-01-20 12:03:35 +00:00
Alex Potsides
d2b7ec0f6b
fix: look for final peer event instead of peer response (#1092)
`FINAL_PEER` means we found the peer, `PEER_RESPONSE` means a peer
responded to our query.
2021-12-29 10:56:56 +01:00
Alex Potsides
79b3cfc6ad
fix: do not wait for autodial start (#1089)
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.
2021-12-29 10:55:48 +01:00
Alex Potsides
f18fc80b70
fix: increase listeners on any-signal (#1084)
Increase the number of listeners we allow on the actual signal we pass along, instead of the signal we pass into any-signal.
2021-12-29 10:51:26 +01:00
Alex Potsides
b4b432406e
fix: record tracked map clears (#1085)
Record the size of a map after we `.clear()` it.
2021-12-27 07:14:27 +01:00
tuyennhv
cb0d7d6c99
fix: type definitions for big dialrequest and persistent peerstore (#1078)
Signed-off-by: Tuyen Nguyen <vutuyen2636@gmail.com>
2021-12-24 15:46:00 +01:00
Alex Potsides
b425fa1230
fix: add tracked map (#1069)
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.
2021-12-21 15:51:06 +01:00
Alex Potsides
09a0f940df
fix: increase the maxlisteners for timeout controllers (#1065)
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.
2021-12-18 07:34:27 +01:00
achingbrain
c8e1b08c19 chore: typo 2021-12-15 09:25:40 +00:00
Alex Potsides
2f0b311df7
feat: allow per-component metrics to be collected (#1061)
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.
2021-12-15 08:03:09 +00:00
Alex Potsides
bdc9f16d0c
fix: clean up pending dial targets (#1059)
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.
2021-12-10 12:42:09 +00:00
Alex Potsides
1b46f47fdb
chore: run node tests in ci (#1057)
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.
2021-12-08 08:38:17 +00:00
Robert Kiel
3b683e7156
fix: fix uncaught promise rejection when finding peers (#1044)
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>
2021-12-07 17:51:48 +00:00
Alex Potsides
b25e0fe531
fix: make error codes consistent (#1054)
Sometimes they are `NOT_FOUND`, sometimes `ERR_NOT_FOUND`, etc.

Move all error codes into `errors.js` and reference them from there.
2021-12-07 14:42:10 +00:00
Alex Potsides
cbaa5a2ef3
chore: switch to nat api (#1052)
@motrix/nat-api is a fork, nat-api has the fix from https://github.com/alxhotel/nat-api/pull/25
2021-12-07 09:37:12 +00:00
Alex Potsides
b70fb43427
fix: increase maxlisteners on event target (#1050)
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
2021-12-06 20:54:44 +01:00
Alex Potsides
91c2ec9856
fix: do not let closest peers run forever (#1047)
The DHT takes a `signal` not a timeout so if a timeout is passed,
create a `TimeoutController` that will abort the query after the
timeout.
2021-12-03 15:47:30 +00:00
Alex Potsides
9cbf36fcb5
chore: update peer id and libp2p crypto (#1042)
BREAKING CHANGE: requires node 15+
2021-12-02 10:11:23 +00:00
Alex Potsides
3a9d5f64d9
fix: stop dht before connection manager (#1041)
Stop the dht before the connection manager, otherwise in-flight eviction pings fail and we move on to the next one when we should just abort them all.

Also pulls in the fix from #1039 and splits the auto-dialler out from the connection manager as during shutdown it can get into a weird state where it's simultaneously killing and creating connections so stop auto-dialling things before we cause connections to dip below the low watermark by killing existing connections.

Fixes: https://github.com/ipfs/js-ipfs/issues/3923
2021-11-30 18:07:57 +00:00
Alex Potsides
2f598eba09
feat: update dht (#1009)
Changes dht creation to use factory function and updates docs

BREAKING CHANGE: libp2p-kad-dht has a new event-based API which is exposed as `_dht`
2021-11-25 16:32:19 +00:00
Alex Potsides
3bed7b4cb2
chore: update aegir (#1027)
Updates aegir, fixes all new linting errors.
2021-11-19 08:02:24 +00:00
Vasco Santos
77d7cb8f08
fix: private ip ts compile has no call signatures (#1020) 2021-11-12 10:34:44 +01:00
Alex Potsides
83734ef520
chore: update datastore (#990)
`interface-datastore` now only contains the interface definition,
`datastore-core` has the various implementations.

BREAKING CHANGE: datastore implementations provided to libp2p must be compliant with interface-datastore@6.0.0
2021-09-24 10:24:29 +02:00
Vasco Santos
0f389a7828 chore: update uint8arrays 2021-08-20 09:13:21 +02:00
greenSnot
ef24fabf02
feat: custom protocol name (#962)
Co-authored-by: mzdws <8580712+mzdws@user.noreply.gitee.com>
2021-08-13 16:21:50 +02:00
Vasco Santos
af723b355e
fix: do not allow dial to large number of multiaddrs (#954) 2021-07-09 08:46:24 +02:00
Alex Potsides
13cf476148
chore: update to new multiformats (#948)
BREAKING CHANGE: uses the CID class from the new multiformats module

Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
2021-07-09 08:43:34 +02:00
Vasco Santos
b291bc06ec
fix: dialer leaking resources after stopping (#947)
* fix: dialer leaking resources after stopping

* chore: add error code to test
2021-06-14 09:19:23 +02:00
Alex Potsides
2a6a635f13
chore: remove ipfs-utils dep (#953)
* chore: remove ipfs-utils dep

We only use it for the env detection, so use [wherearewe](https://www.npmjs.com/package/wherearewe)
instead which is that, but pulled out into a tiny module.

The `TextDecoder` class is global everywhere we support so we don't
need to pull it in from `ipfs-utils` and it's been removed from v8
anyway.

* chore: update ipfs-http-client
2021-06-11 10:01:40 +02:00
zeim839
478963ad2d
feat: keychain rotate passphrase (#944)
Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-05-27 10:30:19 +02:00
Alex Potsides
818d2b2a98
fix: store remote agent and protocol version during identify (#943) 2021-05-12 19:11:17 +02:00
zeim839
a79c6b50d7
fix: peerRouting.findPeer() trying to find self (#941)
* throw error if node attempts to find itself

Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-05-12 16:46:20 +02:00
Vasco Santos
b5a9eb2087
fix: moving averages record types (#935) 2021-04-30 15:42:34 +02:00
Vasco Santos
302bb90058
fix: event emitter and interfaces types for discovery and routing (#934) 2021-04-30 13:20:12 +02:00
Vasco Santos
ac370fc967
fix: address book guarantees no replicated entries are added (#927) 2021-04-27 17:14:48 +02:00
Vasco Santos
88b04156bf
fix: keychain optional pw and use interfaces for validators and selectors instead (#924) 2021-04-22 09:53:55 +02:00
Alex Potsides
086b0ec0df
fix: demand pubsub subclass instead of pubsub instance (#922)
Changes the `Libp2pModules.pubsub` property to be a class that maybe
extends `PubsubBaseProtocol` instead of an instance of that class.
2021-04-21 14:55:21 +02:00
Vasco Santos
cc1f4af879
fix: dht configuration selectors and validators (#919) 2021-04-21 13:28:37 +02:00
Vasco Santos
44463b9145 fix: address book should not emit peer event if no addresses are known #887 2021-04-21 09:14:01 +02:00
Alex Potsides
975e77991e
fix: add clientMode dht arg and upgrade interface-datastore (#918) 2021-04-20 17:11:23 +02:00
Vasco Santos
b043bca607
fix: specify pbjs root (#917) 2021-04-20 16:25:48 +02:00
Vasco Santos
3ffeb4ebe6 chore: apply suggestions from code review
Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
2021-04-20 11:41:50 +02:00
Vasco Santos
06e8f3dd42
fix: do not add abort signals to useless addresses (#913) 2021-04-20 09:31:16 +02:00
Alex Potsides
2af692fb4d
fix: remove inline arg types from function definitions (#916)
Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
2021-04-19 14:08:00 +02:00
Alex Potsides
3d0a79eff3
fix: metrics stats and moving averages types (#915)
* fix: give stats initial values

Otherwise the compiler cannot derive the type and thinks `stats.snapshot` returns `{}`

* fix: add type shape to moving averages as well
2021-04-16 17:10:22 +02:00
Vasco Santos
21c9aeecb1
fix: dial protocol should throw if no protocol is provided (#914)
BREAKING CHANGE: dialProtocol does not return connection when no protocols are provided
2021-04-16 15:49:57 +02:00
Vasco Santos
828a32d4f5 chore: add jsdoc 2021-04-15 14:38:25 +02:00
Vasco Santos
b4fb9b7bf2 fix: address book should not emit peer event if no addresses are known 2021-04-15 14:19:59 +02:00
Vasco Santos
8506414ea1
chore: config types and dependencies update (#904)
BREAKING CHANGES:

top level types were updated, multiaddr@9.0.0 is used, dialer and keychain internal property names changed and connectionManager minPeers is not supported anymore
2021-04-15 09:40:02 +02:00
Alex Potsides
a7128f07ec
fix: the API of es6-promisify is not the same as promisify-es6 (#905) 2021-03-26 18:13:07 +01:00