497 Commits

Author SHA1 Message Date
Alex Potsides
e6f646ed36
chore: update deps (#1285) 2022-07-01 18:33:17 +02:00
Alex Potsides
5af93883ce
chore: update deps (#1284)
Update libp2p deps
2022-06-29 06:59:51 +01:00
Alex Potsides
2836acc90f
fix: use keep-alive tag to reconnect to peers on startup (#1278)
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.
2022-06-28 08:05:16 +01:00
Alex Potsides
b1b2b216da
feat!: use tag values to choose which connections to close (#1276)
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
2022-06-27 15:34:03 +01:00
dependabot[bot]
b270527c8f
chore(deps-dev): bump @libp2p/webrtc-star from 2.0.1 to 3.0.0 (#1266)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-24 13:33:37 +01:00
dependabot[bot]
a5077cbc6b
chore(deps-dev): bump @chainsafe/libp2p-noise from 6.2.0 to 7.0.1 (#1272)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-24 13:16:32 +01:00
Alex Potsides
de30c2cec7
feat!: limit protocol streams per-connection (#1255)
* 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
2022-06-17 15:46:31 +02:00
Alex Potsides
d4dd664071
feat!: update libp2p interfaces (#1252)
BREAKING CHANGE: uses new single-issue libp2p interface modules
2022-06-15 18:30:39 +01:00
github-actions[bot]
13d95b413c
chore: release 0.37.3 (#1237)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-06-10 07:49:49 +01:00
Alex Potsides
3babbbd75a
chore: update ipfs-http-client (#1234)
Updates to ESM version of ipfs-http-client
2022-06-06 15:04:00 +01:00
github-actions[bot]
893f8c280f
chore: release 0.37.2 (#1232)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-05-31 17:45:54 +01:00
github-actions[bot]
4c0c2c6d3e
chore: release 0.37.1 (#1220)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-05-26 08:30:50 +01:00
Alex Potsides
a1220d22f5
fix: time out slow reads (#1227)
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.
2022-05-25 18:15:21 +01:00
Alex Potsides
b09eb8fc53
fix: explicitly close streams when connnections close (#1221)
Make sure we don't leave streams open.

Updates all deps to close multiplexed streams when closing connections.
2022-05-23 13:45:20 +01:00
Alex Potsides
d5386df684
fix: do upnp hole punch after startup (#1217)
The transport manager configures it's addresses during the `start`
phase so access them during `afterStart` so they'll be ready for use.
2022-05-18 13:19:31 +01:00
github-actions[bot]
7678156cf3
chore: release 0.37.0 (#1178)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-05-16 12:10:31 +01:00
Alex Potsides
31480603f3
fix: simplify pnet exports (#1213)
Export the key generator from `libp2p/pnet`
2022-05-16 10:07:32 +01:00
Alex Potsides
4837430d8b
fix: encode enums correctly (#1210)
Updates protons and regenerates protobuf code to encode enums correctly
2022-05-10 12:35:33 +01:00
Alex Potsides
da3d19b309
fix: update interfaces (#1207)
Update to the latest interfaces version
2022-05-04 16:03:43 +01:00
Alex Potsides
a15254fdd4
fix: update to new interfaces (#1206)
Notably removes the `Dialer` interface as the `ConnectionManager` is now in charge of managing connections.
2022-05-04 10:19:04 +01:00
tuyennhv
d16817ca44
fix: emit peer:connect after all (#1171)
**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
2022-04-22 20:56:47 +01:00
Alex Potsides
fab4f1385c
fix: update pubsub interfaces (#1194)
Update to latest version of pubsub interface
2022-04-22 20:49:35 +01:00
Alex Potsides
5397137c65
fix: use placeholder dht/pubsub (#1193)
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.
2022-04-21 15:46:06 +01:00
Alex Potsides
1b9bab68ed
chore: update deps (#1190) 2022-04-14 08:05:43 +01:00
Alex Potsides
c64a586a20
chore: update aegir to the latest version (#1186)
Removes boilerplate config that is no longer necessary
2022-04-09 09:26:25 +01:00
Alex Potsides
cc60cfde1a
fix: add transport manager to exports map and fix docs (#1182)
Addresses PR comments from #1172 - fixes syntax of examples in docs, adds the transport manager to the exports map and renames fault tolerance enum for consistency.
2022-03-29 15:39:50 +01:00
Alex Potsides
8cca8e4bfc
fix: update deps (#1181)
Update to released versions of interop suite and webrtc-direct
2022-03-28 16:09:43 +01:00
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
github-actions[bot]
bad9e8c0ff
chore: release 0.36.2 (#1147)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-01-26 11:03:09 +00:00
github-actions[bot]
fc12973344
chore: release 0.36.1 (#1145)
### [0.36.1](https://www.github.com/libp2p/js-libp2p/compare/v0.36.0...v0.36.1) (2022-01-25)


### Bug Fixes

* await unhandle of protocols ([#1144](https://www.github.com/libp2p/js-libp2p/issues/1144)) ([d44bd90](d44bd9094f))
---

This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-01-25 20:09:03 +00:00
github-actions[bot]
831ed39701
chore: release 0.36.0 (#1127)
## [0.36.0](https://www.github.com/libp2p/js-libp2p/compare/v0.35.8...v0.36.0) (2022-01-25)

### ⚠ BREAKING CHANGES

* abort-controller dep is gone from dependency tree
* `libp2p.handle`, `libp2p.registrar.register` and the peerstore methods have become async

### Features

* add fetch protocol ([#1036](https://www.github.com/libp2p/js-libp2p/issues/1036)) ([d8ceb0b](d8ceb0bc66))
* async peerstore backed by datastores ([#1058](https://www.github.com/libp2p/js-libp2p/issues/1058)) ([978eb36](978eb3676f))
* connection gater ([#1142](https://www.github.com/libp2p/js-libp2p/issues/1142)) ([ff32eba](ff32eba6a0))


### Bug Fixes

* cache build artefacts ([#1091](https://www.github.com/libp2p/js-libp2p/issues/1091)) ([5043cd5](5043cd5643))
* catch errors during identify ([#1138](https://www.github.com/libp2p/js-libp2p/issues/1138)) ([12f1bb0](12f1bb0aee))
* import uint8arrays package in example ([#1083](https://www.github.com/libp2p/js-libp2p/issues/1083)) ([c3700f5](c3700f55d5))
* make tests more reliable ([#1139](https://www.github.com/libp2p/js-libp2p/issues/1139)) ([b7e8706](b7e87066a6))
* prevent auto-dialer from dialing self ([#1104](https://www.github.com/libp2p/js-libp2p/issues/1104)) ([9b22c6e](9b22c6e2f9))
* remove abort-controller dep ([#1095](https://www.github.com/libp2p/js-libp2p/issues/1095)) ([0a4dc54](0a4dc54d08))
* try all peer addresses when dialing a relay ([#1140](https://www.github.com/libp2p/js-libp2p/issues/1140)) ([63aa480](63aa480800))
* update any-signal and timeout-abort-controller ([#1128](https://www.github.com/libp2p/js-libp2p/issues/1128)) ([e0354b4](e0354b4c6b))
* update multistream select ([#1136](https://www.github.com/libp2p/js-libp2p/issues/1136)) ([00e4959](00e49592a3))
* update node-forge ([#1133](https://www.github.com/libp2p/js-libp2p/issues/1133)) ([a4bba35](a4bba35948))
---

This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-01-25 16:43:46 +00:00
Alex Potsides
ff32eba6a0
feat: connection gater (#1142)
Port of https://github.com/libp2p/go-libp2p-core/blob/master/connmgr/gater.go

Adds a new configuration key `connectionGater` which allows denying the dialing of certain peers, individual multiaddrs and the creation of connections at certain points in the connection flow.

Fixes: https://github.com/libp2p/js-libp2p/issues/175
Refs: https://github.com/libp2p/js-libp2p/issues/744
Refs: https://github.com/libp2p/js-libp2p/issues/769

Co-authored-by: mzdws <8580712+mzdws@user.noreply.gitee.com>
2022-01-25 16:27:01 +00:00
Robert Kiel
9b22c6e2f9
fix: prevent auto-dialer from dialing self (#1104)
Co-authored-by: Robert Kiel <robert.kiel@hoprnet.io>
Co-authored-by: achingbrain <alex@achingbrain.net>
2022-01-24 17:59:14 +00:00
Spencer T Brody
d8ceb0bc66
feat: add fetch protocol (#1036)
Adds three methods to implement the `/libp2p/fetch/0.0.1` protocol:

* `libp2p.fetch(peerId, key) => Promise<Uint8Array>`
* `libp2p.fetchService.registerLookupFunction(prefix, lookupFunction)`
* `libp2p.fetchService.unRegisterLookupFunction(prefix, [lookupFunction])`

Co-authored-by: achingbrain <alex@achingbrain.net>
2022-01-24 17:07:11 +00:00
Alex Potsides
00e49592a3
fix: update multistream select (#1136)
It has types now so the ignore can be removed.
2022-01-21 18:13:33 +00:00
Alex Potsides
a4bba35948
fix: update node-forge (#1133)
Upgrade to 1v of node-forge
2022-01-20 19:23:24 +00:00
Alex Potsides
85e23eb1cb
chore: unpack node_module cache before rc publish (#1132) 2022-01-20 15:21:42 +00:00
Alex Potsides
e0354b4c6b
fix: update any-signal and timeout-abort-controller (#1128)
Updates deps to remove abort controller dep

BREAKING CHANGE: abort-controller dep is gone from dependency tree
2022-01-20 14:17:41 +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
0a4dc54d08
fix: remove abort-controller dep (#1095)
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.
2022-01-20 12:02:13 +00:00
Vasco Santos
4cadbad102
chore: remove pubsub dev deps (#1107) 2022-01-07 11:40:05 +01: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
achingbrain
61bf546c46 chore: update contributors 2021-12-29 11:00:11 +01:00
Vasco Santos
4070dcdf55 chore: update contributors 2021-12-24 14:51:51 +00:00
achingbrain
0c3ed0a4ac chore: update contributors 2021-12-18 07:55:26 +01:00
Alex Potsides
a642ad2a03
chore(deps-dev): bump libp2p-floodsub from 0.27.1 to 0.28.0 (#1062)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-15 09:30:49 +00:00
achingbrain
fe0d9828bb chore: update contributors 2021-12-15 09:28:04 +00:00
achingbrain
76f4ea5e8a chore: update contributors 2021-12-15 08:18:44 +00:00
achingbrain
f8e8023aed chore: update contributors 2021-12-13 09:03:54 +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