145 Commits

Author SHA1 Message Date
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
Rakesh Shrestha
5934b13cce
Protocol muxing docs explanation (#1165)
* update examples

* prettier to single quotes

* protocol-muxing bidirectional code explanation

Co-authored-by: aomini daiki <rakesh.shrestha@hazesoft.co>
2022-05-24 10:34:22 -05: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
31480603f3
fix: simplify pnet exports (#1213)
Export the key generator from `libp2p/pnet`
2022-05-16 10:07:32 +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
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
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
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
Rakesh Shrestha
3cfe4bbfac
docs: update auto relay example code usage (#1163)
Co-authored-by: aomini daiki <rakesh.shrestha@hazesoft.co>
2022-02-28 17:46:56 +01:00
Aleksei
6a3e37f250
chore: update js-interfaces URL in examples/transports README (#1150) 2022-02-01 10:11:19 +01:00
Alex Potsides
0264eb62ee
chore: update example tests (#1126)
Remove some of the redundancy in the example tests
2022-01-20 13:33:01 +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
Tim Daubenschütz
c3700f55d5
fix: import uint8arrays package in example (#1083) 2022-01-14 16:33:17 +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
Alan Smithee
51dabb1724
chore: pubsub example subscribe returns void (#1048)
Seems like the correct return type of `Libp2p.pubsub.subscribe` is `void`, so the `await` can be removed: ae21299ade/src/pubsub-adapter.js (L29)
2021-12-06 21:12:38 +01: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
eacd7e8f76
chore: update deps (#1038) 2021-11-26 16:00:47 +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
Alan Smithee
443a102528
docs: minor corrections to discovery-mechanisms readme (#1030) 2021-11-21 23:18:45 +01:00
Alex Potsides
3bed7b4cb2
chore: update aegir (#1027)
Updates aegir, fixes all new linting errors.
2021-11-19 08:02:24 +00:00
TheStarBoys
01a8b8da9b
chore: example docs for auto-relay with correct port 2021-11-12 10:50:11 +01:00
Vasco Santos
3d25ff7fd0 chore: use new libp2p-noise 2021-08-20 09:13:21 +02:00
Vasco Santos
0f389a7828 chore: update uint8arrays 2021-08-20 09:13:21 +02:00
Vasco Santos
3b33fb4b73 fix: browser example ci 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
755eb909f2 chore: update gossipsub dep for example 2021-06-13 21:42:36 +02:00
Vasco Santos
afe0f854e8 chore: use node 16 2021-06-13 21:42:36 +02:00
Vasco Santos
2c4b567b00 chore: restructure pubsub tests 2021-06-13 21:42:36 +02:00
Franck Royer
cd152f122f
chore: add secure websockets example (#930)
* Add Secure WebSockets example

* Make dial accept self-signed cert
2021-06-11 09:45:47 +02:00
Vasco Santos
d8ba284883
fix: chat example with new multiaddr (#946) 2021-05-28 13:46:08 +02:00
Franck Royer
6456a0fff8
chore: browser example dependencies must be installed at the root first (#921)
Fixes #920
2021-04-21 10:45:50 +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
Philipp Muens
03b34cac7d
docs: fix link to connection encryption example (#894) 2021-03-02 13:07:52 +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
Miguel Mota
4ee3e1973b
chore: minor grammar fixes on discovery example (#890) 2021-02-18 11:36:35 +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
Kevin Lacker
f06e06a006
chore: update bootstrapers example url 2021-01-28 11:06:11 +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