Commit Graph

127 Commits

Author SHA1 Message Date
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
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
676cee2947 docs: update websockets import var (#1274) 2022-06-24 14:33:28 +02:00
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
d4dd664071 feat!: update libp2p interfaces (#1252)
BREAKING CHANGE: uses new single-issue libp2p interface modules
2022-06-15 18:30:39 +01:00
824720fb8f fix: reduce identify message size limit (#1230)
Adds a config option to specify a maximum message size we'll accept
for an Identify message.

The default is 8KB, the same as go-libp2p - previously we fell back
to the default `maxMessageLength` option of `it-length-prefixed`
which is 4MB.

Also adds a default timeout for reading responses to identify
requests which is used if an AbortSignal is not passed in.

The default timeout also aligns with go-libp2p.
2022-05-31 17:10:40 +01:00
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
1f5d5c2de1 Added pubsub to the TOC (#1215) 2022-05-16 13:22:41 -05:00
f2fd4e30ff docs: add migration guide (#1214)
Adds migration guide for `libp2p@0.37.x`
2022-05-16 10:58:56 +01:00
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
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
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
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
b7e87066a6 fix: make tests more reliable (#1139)
Try to use only public functions and properties to verify test behaviour
2022-01-21 12:58:31 +00:00
96d3461393 docs: Include loadkeychain in the index (#1087) 2022-01-10 11:56:08 +01:00
5e5d11ec19 docs: fix import of datastore-level (#1086) 2022-01-08 17:57:37 +01:00
c4a442788b docs: update example config ipfs links (#1077) 2021-12-22 17:03:03 +01:00
70a4bb9451 docs: peerstore configuration datastore fixed 2021-12-22 14:15:18 +01:00
1f1bbc0ee6 docs: naming error in the documentation (#1056)
Changed LevelStore to LevelDatastore
2021-12-07 21:05:33 +00:00
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
bb0ca28195 docs: update connection link in API docs (#1024)
Fixes #1018

The issue was caused when the repo [js-libp2p-interfaces](https://github.com/libp2p/js-libp2p-interfaces) was renamed and refactored in this [commit](946348f7f8)
2021-11-16 15:55:00 +00:00
a335fda852 docs: fix datastore link (#999) 2021-09-27 12:42:53 +02:00
43e3af0c12 chore: add migration guide to 0.33 (#997) 2021-09-24 11:33:59 +02:00
97107c4ef7 chore: update datastore usage in CONFIGURATION.md (#982)
Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-08-31 11:51:51 +02:00
ef24fabf02 feat: custom protocol name (#962)
Co-authored-by: mzdws <8580712+mzdws@user.noreply.gitee.com>
2021-08-13 16:21:50 +02:00
67b97e32da chore: add migration guide to 0.32 (#957) 2021-07-15 12:34:15 +02:00
af723b355e fix: do not allow dial to large number of multiaddrs (#954) 2021-07-09 08:46:24 +02:00
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
2959794796 chore: add more details on DHT configuration in CONFIGURATION.md (#951) 2021-06-10 09:06:26 +02:00
2068c845cb chore: configuration format fix 2021-06-07 11:50:21 +02:00
890dd05941 replaced libp2p with node (#942)
Co-authored-by: zeim839 <kassissahil@gmail.com>
2021-05-12 16:47:29 +02:00
f860ffb3e7 chore: add migration guide to 0.31 (#912) 2021-04-30 09:30:41 +02:00
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
c3e147df6b chore: delegates config md properties for client (#903) 2021-03-24 09:35:17 +01:00
9941414a91 chore: update delegates config docs to use http client (#853) 2021-02-11 11:42:10 +01:00
0a6bc0d101 feat: add UPnP NAT manager (#810)
* feat: add uPnP nat manager

Adds a really basic nat manager that attempts to use UPnP to punch
a hole through your router for any IPV4 tcp addresses you have
configured.

Adds any configured addresses to the node's observed addresses list
and adds observed addresses to `libp2p.multiaddrs` so we exchange
them with peers when performing `identify` and people can dial you.

Adds configuration options under `config.nat`

Hole punching is async to not affect start up time.

Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
2021-01-27 14:55:26 +01:00
d60922b799 docs: Add bootstrap to custom peer discovery (#859) 2021-01-15 10:27:23 +01:00
bc05083207 docs: production guide base setup (#804) 2020-12-16 13:56:41 +01:00
7809e6444e chore: auto relay configuration example with noise (#828) 2020-12-16 13:56:41 +01:00
7d76ba1367 docs: migration 0.29 to 0.30 (#808) 2020-12-16 13:56:41 +01:00
baedf3fe5a feat: discover and connect to closest peers (#798) 2020-12-16 13:56:41 +01:00
585ad52b4c feat: custom dialer addr sorter (#792)
* feat: custom dialer addr sorter

* chore: use libp2p utils sorter via addressBook getMultiaddrsForPeer

* chore: use new libp2p utils

* chore: apply suggestions from code review

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-12-16 13:56:41 +01:00
e50c6abcf2 chore: update pubsub (#801)
BREAKING CHANGE: pubsub signing policy properties were changed according to libp2p-interfaces changes to a single property. The emitSelf option default value was also modified to match the routers value
2020-12-16 13:56:41 +01:00
5758db8ea9 chore: remove noAnnounce from address manager 2020-12-16 13:56:41 +01:00
ef9d3ca2c6 feat: custom announce filter 2020-12-16 13:56:41 +01:00
97e3633f47 chore: store self protocols in protobook (#760) 2020-12-16 13:56:41 +01:00
ee23fb9508 chore: apply suggestions from code review
Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-12-16 13:56:41 +01:00
11a46ea71e chore: add configuration docs for auto relay and hop service 2020-12-16 13:56:41 +01:00
43eda43f06 chore: create signed peer record on new listen addresses in transport manager 2020-12-16 13:56:41 +01:00
7b93ece7f2 chore: use listening events to create self peer record on updates 2020-12-16 13:56:41 +01:00