Skip to content

Commit 8cf9692

Browse files
authored
refactor: return peer IDs as strings not CIDs (#2729)
Also updates all examples to use the new API. Depends on: - [x] ipfs-inactive/interface-js-ipfs-core#581 - [x] ipfs-inactive/js-ipfs-http-client#1226 - [x] libp2p/js-libp2p#545 BREAKING CHANGE: Where `PeerID`s were previously [CID](https://www.npmjs.com/package/cids)s, now they are Strings - `ipfs.bitswap.stat().peers[n]` is now a String (was a CID) - `ipfs.dht.findPeer().id` is now a String (was a CID) - `ipfs.dht.findProvs()[n].id` is now a String (was a CID) - `ipfs.dht.provide()[n].id` is now a String (was a CID) - `ipfs.dht.put()[n].id` is now a String (was a CID) - `ipfs.dht.query()[n].id` is now a String (was a CID) - `ipfs.id().id` is now a String (was a CID) - `ipfs.id().addresses[n]` are now [Multiaddr](https://www.npmjs.com/package/multiaddr)s (were Strings)
1 parent a96c235 commit 8cf9692

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

index.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

33
const Libp2p = require('libp2p')
4-
const IPFS = require('ipfs')
4+
const IPFS = require('../../')
55
const TCP = require('libp2p-tcp')
66
const MulticastDNS = require('libp2p-mdns')
7-
const WebSocketStar = require('libp2p-websocket-star')
87
const Bootstrap = require('libp2p-bootstrap')
98
const SPDY = require('libp2p-spdy')
109
const KadDHT = require('libp2p-kad-dht')
11-
const MPLEX = require('pull-mplex')
10+
const MPLEX = require('libp2p-mplex')
1211
const SECIO = require('libp2p-secio')
1312

1413
/**
@@ -32,11 +31,6 @@ const libp2pBundle = (opts) => {
3231
const peerBook = opts.peerBook
3332
const bootstrapList = opts.config.Bootstrap
3433

35-
// Create our WebSocketStar transport and give it our PeerId, straight from the ipfs node
36-
const wsstar = new WebSocketStar({
37-
id: peerInfo.id
38-
})
39-
4034
// Build and return our libp2p node
4135
return new Libp2p({
4236
peerInfo,
@@ -49,8 +43,7 @@ const libp2pBundle = (opts) => {
4943
},
5044
modules: {
5145
transport: [
52-
TCP,
53-
wsstar
46+
TCP
5447
],
5548
streamMuxer: [
5649
MPLEX,
@@ -61,8 +54,7 @@ const libp2pBundle = (opts) => {
6154
],
6255
peerDiscovery: [
6356
MulticastDNS,
64-
Bootstrap,
65-
wsstar.discovery
57+
Bootstrap
6658
],
6759
dht: KadDHT
6860
},

package.json

+9-11
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12-
"ipfs": "file:../../",
13-
"libp2p": "^0.26.2",
14-
"libp2p-bootstrap": "~0.9.7",
15-
"libp2p-kad-dht": "~0.16.0",
16-
"libp2p-mdns": "~0.12.2",
17-
"libp2p-secio": "~0.11.1",
18-
"libp2p-spdy": "~0.13.3",
19-
"libp2p-tcp": "~0.13.0",
20-
"libp2p-websocket-star": "~0.10.2",
21-
"pull-mplex": "~0.1.0"
12+
"libp2p": "^0.27.0-rc.0",
13+
"libp2p-bootstrap": "^0.10.3",
14+
"libp2p-kad-dht": "^0.18.3",
15+
"libp2p-mdns": "^0.13.1",
16+
"libp2p-mplex": "^0.9.3",
17+
"libp2p-secio": "^0.12.2",
18+
"libp2p-spdy": "^0.13.3",
19+
"libp2p-tcp": "^0.14.3"
2220
},
2321
"devDependencies": {
24-
"execa": "^3.2.0"
22+
"execa": "^4.0.0"
2523
}
2624
}

test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ const execa = require('execa')
55
const Libp2p = require('libp2p')
66
const TCP = require('libp2p-tcp')
77
const SPDY = require('libp2p-spdy')
8-
const MPLEX = require('pull-mplex')
8+
const MPLEX = require('libp2p-mplex')
99
const SECIO = require('libp2p-secio')
1010
const PeerInfo = require('peer-info')
1111
const PeerId = require('peer-id')
1212
const multiaddr = require('multiaddr')
13-
const promisify = require('promisify-es6')
14-
const PeerBook = require('peer-book')
1513

1614
async function test () {
1715
let output = ''
@@ -31,12 +29,11 @@ async function test () {
3129

3230
console.info('Dialling', address)
3331

34-
const peerInfo = new PeerInfo(await promisify(PeerId.create)())
32+
const peerInfo = new PeerInfo(await PeerId.create())
3533
peerInfo.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/0'))
3634

3735
const libp2p = new Libp2p({
3836
peerInfo,
39-
peerBook: new PeerBook(),
4037
modules: {
4138
transport: [
4239
TCP

0 commit comments

Comments
 (0)