Skip to content

Commit

Permalink
chore: use libp2p 0.28.x (#3019)
Browse files Browse the repository at this point in the history
This PR updates libp2p usage to `0.28.x`. 

The biggest impact in `js-ipfs` is the deprecation of `PeerInfo`, which creates breaking changes in several parts of the libp2p API.

For more information you can check the libp2p migration guide and release notes:

- [libp2p/js-libp2p/doc/migrations/v0.27-v.28.md](https://github.com/libp2p/js-libp2p/blob/master/doc/migrations/v0.27-v.28.md)
- [libp2p/js-libp2p#603](libp2p/js-libp2p#603)

BREAKING CHANGES:

- `.libp2p` property of `ipfs` nodes now supports 0.28.x libp2p API
- `PeerInfo` is no longer exported from `require('ipfs')`
  • Loading branch information
vasco-santos committed Jun 8, 2020
1 parent 10d6839 commit 457ce1c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ const IPFS = require('ipfs')
const TCP = require('libp2p-tcp')
const MulticastDNS = require('libp2p-mdns')
const Bootstrap = require('libp2p-bootstrap')
const SPDY = require('libp2p-spdy')
const KadDHT = require('libp2p-kad-dht')
const MPLEX = require('libp2p-mplex')
const SECIO = require('libp2p-secio')

/**
* Options for the libp2p bundle
* @typedef {Object} libp2pBundle~options
* @property {PeerInfo} peerInfo - The PeerInfo of the IPFS node
* @property {PeerBook} peerBook - The PeerBook of the IPFS node
* @property {PeerId} peerId - The PeerId of the IPFS node
* @property {Object} config - The config of the IPFS node
* @property {Object} options - The options given to the IPFS node
*/
Expand All @@ -27,15 +25,16 @@ const SECIO = require('libp2p-secio')
*/
const libp2pBundle = (opts) => {
// Set convenience variables to clearly showcase some of the useful things that are available
const peerInfo = opts.peerInfo
const peerBook = opts.peerBook
const peerId = opts.peerId
const bootstrapList = opts.config.Bootstrap

// Build and return our libp2p node
// n.b. for full configuration options, see https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md
return new Libp2p({
peerInfo,
peerBook,
peerId,
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
},
// Lets limit the connection managers peers and have it check peer health less frequently
connectionManager: {
minPeers: 25,
Expand All @@ -47,8 +46,7 @@ const libp2pBundle = (opts) => {
TCP
],
streamMuxer: [
MPLEX,
SPDY
MPLEX
],
connEncryption: [
SECIO
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"license": "MIT",
"dependencies": {
"ipfs": "^0.46.0",
"libp2p": "^0.27.7",
"libp2p-bootstrap": "^0.10.3",
"libp2p-kad-dht": "^0.18.7",
"libp2p-mdns": "^0.13.1",
"libp2p-mplex": "^0.9.3",
"libp2p-secio": "^0.12.2",
"libp2p-spdy": "^0.13.3",
"libp2p": "^0.28.0",
"libp2p-bootstrap": "^0.11.0",
"libp2p-kad-dht": "^0.19.5",
"libp2p-mdns": "^0.14.1",
"libp2p-mplex": "^0.9.5",
"libp2p-secio": "^0.12.4",
"libp2p-tcp": "^0.14.5"
},
"devDependencies": {
Expand Down
15 changes: 6 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ const path = require('path')
const execa = require('execa')
const Libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const SPDY = require('libp2p-spdy')
const MPLEX = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')

async function test () {
let output = ''
Expand All @@ -29,18 +26,18 @@ async function test () {

console.info('Dialling', address)

const peerInfo = new PeerInfo(await PeerId.create())
peerInfo.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/0'))

const peerId = await PeerId.create()
const libp2p = new Libp2p({
peerInfo,
peerId,
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
},
modules: {
transport: [
TCP
],
streamMuxer: [
MPLEX,
SPDY
MPLEX
],
connEncryption: [
SECIO
Expand Down

0 comments on commit 457ce1c

Please sign in to comment.