43 Commits

Author SHA1 Message Date
Alex Potsides
199395de4d
feat: convert to typescript (#1172)
Converts this module to typescript.

- Ecosystem modules renamed from (e.g.) `libp2p-tcp` to `@libp2p/tcp`
- Ecosystem module now have named exports
- Configuration has been updated, now pass instances of modules instead of classes:
- Some configuration keys have been renamed to make them more descriptive.  `transport` -> `transports`, `connEncryption` -> `connectionEncryption`.  In general where we pass multiple things, the key is now plural, e.g. `streamMuxer` -> `streamMuxers`, `contentRouting` -> `contentRouters`, etc.  Where we are configuring a singleton the config key is singular, e.g. `connProtector` -> `connectionProtector` etc.
- Properties of the `modules` config key have been moved to the root
- Properties of the `config` config key have been moved to the root
```js
// before
import Libp2p from 'libp2p'
import TCP from 'libp2p-tcp'

await Libp2p.create({
  modules: {
    transport: [
      TCP
    ],
  }
  config: {
    transport: {
      [TCP.tag]: {
        foo: 'bar'
      }
    },
    relay: {
      enabled: true,
      hop: {
        enabled: true,
        active: true
      }
    }
  }
})
```
```js
// after
import { createLibp2p } from 'libp2p'
import { TCP } from '@libp2p/tcp'

await createLibp2p({
  transports: [
    new TCP({ foo: 'bar' })
  ],
  relay: {
    enabled: true,
    hop: {
      enabled: true,
      active: true
    }
  }
})
```
- Use of `enabled` flag has been reduced - previously you could pass a module but disable it with config.  Now if you don't want a feature, just don't pass an implementation.   Eg:
```js
// before
await Libp2p.create({
  modules: {
    transport: [
      TCP
    ],
    pubsub: Gossipsub
  },
  config: {
    pubsub: {
      enabled: false
    }
  }
})
```
```js
// after
await createLibp2p({
  transports: [
    new TCP()
  ]
})
```
- `.multiaddrs` renamed to `.getMultiaddrs()` because it's not a property accessor, work is done by that method to calculate announce addresses, observed addresses, etc
- `/p2p/${peerId}` is now appended to all addresses returned by `.getMultiaddrs()` so they can be used opaquely (every consumer has to append the peer ID to the address to actually use it otherwise).  If you need low-level unadulterated addresses, call methods on the address manager.

BREAKING CHANGE: types are no longer hand crafted, this module is now ESM only
2022-03-28 14:30:27 +01:00
achingbrain
fc43db750d chore: fix build on webworkers 2022-01-20 17:33:58 +00:00
achingbrain
bf1fc325b6 chore: add registry 2022-01-20 17:21:48 +00:00
achingbrain
79b356a313 chore: update var name 2022-01-20 16:52:30 +00:00
achingbrain
54e77221eb chore: fix publish command 2022-01-20 16:27:01 +00:00
Alex Potsides
85e23eb1cb
chore: unpack node_module cache before rc publish (#1132) 2022-01-20 15:21:42 +00:00
Alex Potsides
cbd9bad86d
chore: run test after build (#1130)
Run CI tests and check at the same time
2022-01-20 14:52:31 +00:00
Alex Potsides
75b922dc21
chore: checkout code and set up node for publishing rc (#1131)
Need to run the checkout and setup-node actions before publishing an RC.
2022-01-20 14:52:12 +00:00
Alex Potsides
280bb1b1f6
chore: autopublish next version (#1129)
If we aren't releasing a version on a given release run, publish an rc under the `next` tag instead.
2022-01-20 14:24:06 +00:00
achingbrain
a0bfe8b534 chore: restore correct cache 2022-01-20 13:32:25 +00:00
Alex Potsides
2963b852db
chore: add automated releases (#1124)
Adds release-please github action to create gated releases and a release issue that tracks all issues that will be in a release.
2022-01-20 13:19:38 +00:00
Alex Potsides
13d45de376
chore: add missing cache dir (#1125)
Fixes ci config
2022-01-20 12:37:52 +00:00
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
5043cd5643
fix: cache build artefacts (#1091)
To speed up the build and make it more reliable, cache the node_modules
folder, dist, etc and re-use on each step.
2021-12-29 15:06:58 +01:00
Vasco Santos
d1c48dcbed
fix: main ci (#1079) 2021-12-24 11:18:09 +01: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
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
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
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
3fb424914f
chore: fix examples (#1026)
Uses npm to install deps for examples.

We can put yarn back when we remove `node-fetch@2.x` from ipfs-utils, or when
yarn can download tarball dependencies reliably.

This either needs:

1. https://github.com/node-fetch/node-fetch/pull/1172 merging
2. Swap node-fetch for undici
3. Drop CJS support (node-fetch 3 has the above fix but is ESM-only)
2021-11-19 07:26:38 +00:00
Vasco Santos
f8e3cf10b0
chore: add dependabot (#968) 2021-08-26 12:02:28 +02:00
Vasco Santos
fe63990a16
chore: libp2p interop job needs exit for aegir (#971) 2021-08-26 11:19:13 +02:00
Vasco Santos
ba2b4d4b28
fix: uint8arrays is a dep (#964) 2021-08-16 17:54:24 +02:00
Vasco Santos
a07fb7960b chore: update action setup node 2021-08-12 15:15:13 +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
afe0f854e8 chore: use node 16 2021-06-13 21:42:36 +02:00
Vasco Santos
052aad4e06 chore: use node 15 in ci 2021-06-13 21:42:36 +02:00
Vasco Santos
d372a68692
chore: add github issue templates (#938) 2021-05-05 15:06:56 +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
Vasco Santos
5f702f3481
fix: conn mgr access to moving averages record object (#897)
* fix: conn mgr access to moving averages record object

* chore: remove node 12

* chore: add parcel workaround
2021-03-09 16:51:41 +01:00
Aleksei
9c67364caa
Add an example of webrtc-direct (#868)
Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
2021-02-25 16:34:02 +01:00
Vasco Santos
46cb46188a
chore: add discovery example with relay and pubsub discovery (#855) 2021-02-11 11:37:11 +01:00
Vasco Santos
1af8472dc6
chore: add transports example (#851) 2021-02-11 11:12:23 +01:00
Vasco Santos
f6a4cad827
chore: add pubsub example tests (#850) 2021-02-10 21:00:40 +01:00
Vasco Santos
b1079474de
chore: add protocol and stream muxing example tests (#849) 2021-02-10 15:40:19 +01:00
Vasco Santos
a150ea60c5
chore: add peer and content routing example tests (#848) 2021-02-08 11:03:42 +01:00
Vasco Santos
748b552876
chore: pnet example test (#845) 2021-01-22 10:24:15 +01:00
Vasco Santos
67067c97d5
chore: connection encryption example test (#843) 2021-01-21 09:27:27 +01:00
Vasco Santos
f45cd1c4b5
chore: echo example test (#842) 2021-01-20 10:46:04 +01:00
Vasco Santos
0a02207116
chore: add discovery example tests (#841) 2021-01-19 11:02:56 +01:00
Vasco Santos
0b854a949f
chore: add browser example test (#846) 2021-01-19 09:57:56 +01:00
Vasco Santos
77e8273a64
chore: add chat example (#840) 2021-01-18 11:15:02 +01:00
Vasco Santos
169bb806a7 chore: add typedefs (#802) 2020-12-16 13:56:41 +01:00