Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d0144fd

Browse files
committed
chore: use libp2p 0.28.x
1 parent f7dd1c1 commit d0144fd

File tree

23 files changed

+160
-185
lines changed

23 files changed

+160
-185
lines changed

packages/interface-ipfs-core/src/swarm/addrs.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ module.exports = (common, options) => {
3838
})
3939

4040
it('should get a list of node addresses', async () => {
41-
const peerInfos = await ipfsA.swarm.addrs()
42-
expect(peerInfos).to.not.be.empty()
43-
expect(peerInfos).to.be.an('array')
41+
const peers = await ipfsA.swarm.addrs()
42+
expect(peers).to.not.be.empty()
43+
expect(peers).to.be.an('array')
4444

45-
for (const peerInfo of peerInfos) {
46-
expect(CID.isCID(new CID(peerInfo.id))).to.be.true()
47-
expect(peerInfo).to.have.a.property('addrs').that.is.an('array')
45+
for (const peer of peers) {
46+
expect(CID.isCID(new CID(peer.id))).to.be.true()
47+
expect(peer).to.have.a.property('addrs').that.is.an('array')
4848

49-
for (const ma of peerInfo.addrs) {
49+
for (const ma of peer.addrs) {
5050
expect(Multiaddr.isMultiaddr(ma)).to.be.true()
5151
}
5252
}

packages/ipfs/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@
9393
"hapi-pino": "^6.1.0",
9494
"hashlru": "^2.3.0",
9595
"interface-datastore": "^1.0.2",
96-
"ipfs-bitswap": "^1.0.0",
96+
"ipfs-bitswap": "ipfs/js-ipfs-bitswap#chore/use-libp2p-0.28",
9797
"ipfs-block-service": "^0.17.1",
9898
"ipfs-core-utils": "^0.2.3",
99-
"ipfs-http-client": "^44.1.0",
99+
"ipfs-http-client": "44.0.3",
100100
"ipfs-http-response": "^0.5.0",
101101
"ipfs-repo": "^3.0.0",
102102
"ipfs-unixfs": "^1.0.2",
@@ -129,21 +129,21 @@
129129
"iterable-ndjson": "^1.1.0",
130130
"jsondiffpatch": "^0.4.1",
131131
"just-safe-set": "^2.1.0",
132-
"libp2p": "^0.27.7",
133-
"libp2p-bootstrap": "^0.10.3",
132+
"libp2p": "^0.28.0-rc.0",
133+
"libp2p-bootstrap": "^0.11.0",
134134
"libp2p-crypto": "^0.17.6",
135-
"libp2p-delegated-content-routing": "^0.4.4",
136-
"libp2p-delegated-peer-routing": "^0.4.2",
137-
"libp2p-floodsub": "^0.20.0",
138-
"libp2p-gossipsub": "^0.3.0",
139-
"libp2p-kad-dht": "^0.18.7",
135+
"libp2p-delegated-content-routing": "^0.5.0",
136+
"libp2p-delegated-peer-routing": "^0.5.0",
137+
"libp2p-floodsub": "^0.21.0",
138+
"libp2p-gossipsub": "^0.4.0",
139+
"libp2p-kad-dht": "^0.19.1",
140140
"libp2p-keychain": "^0.6.0",
141-
"libp2p-mdns": "^0.13.1",
141+
"libp2p-mdns": "^0.14.1",
142142
"libp2p-mplex": "^0.9.3",
143143
"libp2p-record": "^0.7.3",
144144
"libp2p-secio": "^0.12.2",
145145
"libp2p-tcp": "^0.14.5",
146-
"libp2p-webrtc-star": "^0.17.10",
146+
"libp2p-webrtc-star": "^0.18.0",
147147
"libp2p-websockets": "^0.13.3",
148148
"mafmt": "^7.0.0",
149149
"merge-options": "^2.0.0",

packages/ipfs/src/cli/daemon.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Daemon {
6060
}
6161
}
6262

63-
function getLibp2p ({ libp2pOptions, options, config, peerInfo }) {
63+
function getLibp2p ({ libp2pOptions, options, config, peerId }) {
6464
// Attempt to use any of the WebRTC versions available globally
6565
let electronWebRTC
6666
let wrtc
@@ -98,7 +98,7 @@ function getLibp2p ({ libp2pOptions, options, config, peerInfo }) {
9898
}
9999

100100
libp2pOptions.modules.contentRouting = libp2pOptions.modules.contentRouting || []
101-
libp2pOptions.modules.contentRouting.push(new DelegatedContentRouter(peerInfo.id, delegatedApiOptions))
101+
libp2pOptions.modules.contentRouting.push(new DelegatedContentRouter(peerId, delegatedApiOptions))
102102

103103
libp2pOptions.modules.peerRouting = libp2pOptions.modules.peerRouting || []
104104
libp2pOptions.modules.peerRouting.push(new DelegatedPeerRouter(delegatedApiOptions))

packages/ipfs/src/core/components/dht.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ module.exports = ({ libp2p, repo }) => {
7777
options.maxNumProviders = options.numProviders
7878
}
7979

80-
for await (const peerInfo of libp2p._dht.findProviders(key, options)) {
80+
for await (const peer of libp2p._dht.findProviders(key, options)) {
8181
yield {
82-
id: peerInfo.id.toB58String(),
83-
addrs: peerInfo.multiaddrs.toArray()
82+
id: peer.id.toB58String(),
83+
addrs: peer.addrs
8484
}
8585
}
8686
}),
@@ -96,11 +96,11 @@ module.exports = ({ libp2p, repo }) => {
9696
peerId = PeerId.createFromCID(peerId)
9797
}
9898

99-
const peerInfo = await libp2p._dht.findPeer(peerId)
99+
const peer = await libp2p._dht.findPeer(peerId)
100100

101101
return {
102-
id: peerInfo.id.toB58String(),
103-
addrs: peerInfo.multiaddrs.toArray()
102+
id: peer.id.toB58String(),
103+
addrs: peer.addrs
104104
}
105105
}),
106106

packages/ipfs/src/core/components/id.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const pkgversion = require('../../../package.json').version
44
const multiaddr = require('multiaddr')
55
const { withTimeoutOption } = require('../utils')
66

7-
module.exports = ({ peerInfo, libp2p }) => {
7+
module.exports = ({ peerId, libp2p }) => {
88
return withTimeoutOption(async function id () { // eslint-disable-line require-await
9-
const id = peerInfo.id.toB58String()
9+
const id = peerId.toB58String()
1010
let addresses = []
1111

1212
if (libp2p) {
@@ -16,7 +16,7 @@ module.exports = ({ peerInfo, libp2p }) => {
1616

1717
return {
1818
id,
19-
publicKey: peerInfo.id.pubKey.bytes.toString('base64'),
19+
publicKey: peerId.pubKey.bytes.toString('base64'),
2020
addresses: addresses
2121
.map(ma => {
2222
const str = ma.toString()

packages/ipfs/src/core/components/init.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
const log = require('debug')('ipfs:components:init')
44
const PeerId = require('peer-id')
55
const { Buffer } = require('buffer')
6-
const PeerInfo = require('peer-info')
6+
77
const mergeOptions = require('merge-options')
88
const getDefaultConfig = require('../runtime/config-nodejs.js')
99
const createRepo = require('../runtime/repo-nodejs')
10-
const Keychain = require('libp2p-keychain')
11-
const NoKeychain = require('./no-keychain')
1210
const mortice = require('mortice')
1311
const { DAGNode } = require('ipld-dag-pb')
1412
const UnixFs = require('ipfs-unixfs')
@@ -80,7 +78,7 @@ module.exports = ({
8078
: await initNewRepo(repo, { ...options, print })
8179

8280
log('peer created')
83-
const peerInfo = new PeerInfo(peerId)
81+
8482
const blockService = new BlockService(repo)
8583
const ipld = new Ipld(getDefaultIpldOptions(blockService, constructorOptions.ipld, log))
8684

@@ -142,7 +140,7 @@ module.exports = ({
142140
// Setup the offline routing for IPNS.
143141
// This is primarily used for offline ipns modifications, such as the initializeKeyspace feature.
144142
const offlineDatastore = new OfflineDatastore(repo)
145-
const ipns = new IPNS(offlineDatastore, repo.datastore, peerInfo, keychain, { pass: options.pass })
143+
const ipns = new IPNS(offlineDatastore, repo.datastore, peerId, keychain, { pass: options.pass })
146144
await ipns.initializeKeyspace(peerId.privKey, emptyDirCid.toString())
147145
}
148146

@@ -158,7 +156,7 @@ module.exports = ({
158156
ipld,
159157
keychain,
160158
object,
161-
peerInfo,
159+
peerId,
162160
pin,
163161
pinManager,
164162
preload,
@@ -190,7 +188,6 @@ async function initNewRepo (repo, { privateKey, emptyRepo, bits, profiles, confi
190188
}
191189

192190
const peerId = await createPeerId({ privateKey, bits, print })
193-
let keychain = new NoKeychain()
194191

195192
log('identity generated')
196193

@@ -201,23 +198,32 @@ async function initNewRepo (repo, { privateKey, emptyRepo, bits, profiles, confi
201198

202199
privateKey = peerId.privKey
203200

204-
config.Keychain = Keychain.generateOptions()
205-
206201
log('peer identity: %s', config.Identity.PeerID)
207202

208203
await repo.init(config)
209204
await repo.open()
210205

211206
log('repo opened')
212207

213-
if (pass) {
214-
log('creating keychain')
215-
const keychainOptions = { passPhrase: pass, ...config.Keychain }
216-
keychain = new Keychain(repo.keys, keychainOptions)
217-
await keychain.importPeer('self', { privKey: privateKey })
208+
// Create libp2p for Keychain creation
209+
const libp2p = Components.libp2p({
210+
peerId,
211+
repo,
212+
config,
213+
keychainConfig: {
214+
pass
215+
}
216+
})
217+
218+
if (libp2p.keychain && libp2p.keychain.opts) {
219+
await libp2p.loadKeychain()
220+
221+
await repo.config.set('Keychain', {
222+
dek: libp2p.keychain.opts.dek
223+
})
218224
}
219225

220-
return { peerId, keychain }
226+
return { peerId, keychain: libp2p.keychain }
221227
}
222228

223229
async function initExistingRepo (repo, { config: newConfig, profiles, pass }) {
@@ -233,27 +239,21 @@ async function initExistingRepo (repo, { config: newConfig, profiles, pass }) {
233239
await repo.config.set(config)
234240
}
235241

236-
let keychain = new NoKeychain()
237-
238-
if (pass) {
239-
const keychainOptions = { passPhrase: pass, ...config.Keychain }
240-
keychain = new Keychain(repo.keys, keychainOptions)
241-
log('keychain constructed')
242-
}
243-
244242
const peerId = await PeerId.createFromPrivKey(config.Identity.PrivKey)
245243

246-
// Import the private key as 'self', if needed.
247-
if (pass) {
248-
try {
249-
await keychain.findKeyByName('self')
250-
} catch (err) {
251-
log('Creating "self" key')
252-
await keychain.importPeer('self', peerId)
244+
const libp2p = Components.libp2p({
245+
peerId,
246+
repo,
247+
config,
248+
keychainConfig: {
249+
pass,
250+
...config.Keychain
253251
}
254-
}
252+
})
253+
254+
libp2p.keychain && await libp2p.loadKeychain()
255255

256-
return { peerId, keychain }
256+
return { peerId, keychain: libp2p.keychain }
257257
}
258258

259259
function createPeerId ({ privateKey, bits, print }) {
@@ -303,7 +303,7 @@ function createApi ({
303303
ipld,
304304
keychain,
305305
object,
306-
peerInfo,
306+
peerId,
307307
pin,
308308
pinManager,
309309
preload,
@@ -337,7 +337,7 @@ function createApi ({
337337
dns: Components.dns(),
338338
files: Components.files({ ipld, block, blockService, repo, preload, options: constructorOptions }),
339339
get: Components.get({ ipld, preload }),
340-
id: Components.id({ peerInfo }),
340+
id: Components.id({ peerId }),
341341
init: async () => { throw new AlreadyInitializedError() }, // eslint-disable-line require-await
342342
isOnline: Components.isOnline({}),
343343
key: {
@@ -367,7 +367,7 @@ function createApi ({
367367
initOptions,
368368
ipld,
369369
keychain,
370-
peerInfo,
370+
peerId,
371371
pinManager,
372372
preload,
373373
print,
@@ -383,7 +383,7 @@ function createApi ({
383383
addrs: notStarted,
384384
connect: notStarted,
385385
disconnect: notStarted,
386-
localAddrs: Components.swarm.localAddrs({ peerInfo }),
386+
localAddrs: Components.swarm.localAddrs({ multiaddrs: [] }),
387387
peers: notStarted
388388
},
389389
version: Components.version({ repo })

packages/ipfs/src/core/components/libp2p.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,37 @@ const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs')
77

88
module.exports = ({
99
options,
10-
peerInfo,
10+
peerId,
11+
multiaddrs = [],
1112
repo,
13+
keychainConfig = {},
1214
config
1315
}) => {
1416
options = options || {}
1517
config = config || {}
1618

17-
const { datastore } = repo
18-
const libp2pOptions = getLibp2pOptions({ options, config, datastore, peerInfo })
19+
const { datastore, keys } = repo
20+
21+
const libp2pOptions = getLibp2pOptions({
22+
options,
23+
config,
24+
datastore,
25+
keys,
26+
keychainConfig,
27+
peerId,
28+
multiaddrs
29+
})
1930

2031
if (typeof options.libp2p === 'function') {
21-
return options.libp2p({ libp2pOptions, options, config, datastore, peerInfo })
32+
return options.libp2p({ libp2pOptions, options, config, datastore, peerId })
2233
}
2334

2435
// Required inline to reduce startup time
2536
const Libp2p = require('libp2p')
2637
return new Libp2p(mergeOptions(libp2pOptions, get(options, 'libp2p', {})))
2738
}
2839

29-
function getLibp2pOptions ({ options, config, datastore, peerInfo }) {
40+
function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, peerId, multiaddrs }) {
3041
const getPubsubRouter = () => {
3142
const router = get(config, 'Pubsub.Router') || 'gossipsub'
3243

@@ -39,7 +50,7 @@ function getLibp2pOptions ({ options, config, datastore, peerInfo }) {
3950

4051
const libp2pDefaults = {
4152
datastore,
42-
peerInfo,
53+
peerId: peerId,
4354
modules: {}
4455
}
4556

@@ -80,12 +91,19 @@ function getLibp2pOptions ({ options, config, datastore, peerInfo }) {
8091
get(config, 'Pubsub.Enabled', true))
8192
}
8293
},
94+
addresses: {
95+
listen: multiaddrs
96+
},
8397
connectionManager: get(options, 'connectionManager', {
8498
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater',
8599
get(config, 'Swarm.ConnMgr.HighWater')),
86100
minConnections: get(options, 'config.Swarm.ConnMgr.LowWater',
87101
get(config, 'Swarm.ConnMgr.LowWater'))
88-
})
102+
}),
103+
keychain: {
104+
datastore: keys,
105+
...keychainConfig
106+
}
89107
}
90108

91109
// Required inline to reduce startup time

packages/ipfs/src/core/components/name/publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const { resolvePath } = require('./utils')
2121
* @param {IPFS} self
2222
* @returns {Object}
2323
*/
24-
module.exports = ({ ipns, dag, peerInfo, isOnline, keychain, options: constructorOptions }) => {
24+
module.exports = ({ ipns, dag, peerId, isOnline, keychain, options: constructorOptions }) => {
2525
const lookupKey = async keyName => {
2626
if (keyName === 'self') {
27-
return peerInfo.id.privKey
27+
return peerId.privKey
2828
}
2929

3030
try {

0 commit comments

Comments
 (0)