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

Commit c799565

Browse files
committed
chore: use libp2p 0.28.x
1 parent 2cf6b49 commit c799565

File tree

23 files changed

+158
-185
lines changed

23 files changed

+158
-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
@@ -31,15 +31,15 @@ module.exports = (common, options) => {
3131
after(() => common.clean())
3232

3333
it('should get a list of node addresses', async () => {
34-
const peerInfos = await ipfsA.swarm.addrs()
35-
expect(peerInfos).to.not.be.empty()
36-
expect(peerInfos).to.be.an('array')
34+
const peers = await ipfsA.swarm.addrs()
35+
expect(peers).to.not.be.empty()
36+
expect(peers).to.be.an('array')
3737

38-
for (const peerInfo of peerInfos) {
39-
expect(CID.isCID(new CID(peerInfo.id))).to.be.true()
40-
expect(peerInfo).to.have.a.property('addrs').that.is.an('array')
38+
for (const peer of peers) {
39+
expect(CID.isCID(new CID(peer.id))).to.be.true()
40+
expect(peer).to.have.a.property('addrs').that.is.an('array')
4141

42-
for (const ma of peerInfo.addrs) {
42+
for (const ma of peer.addrs) {
4343
expect(Multiaddr.isMultiaddr(ma)).to.be.true()
4444
}
4545
}

packages/ipfs/package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"hapi-pino": "^6.1.0",
9797
"hashlru": "^2.3.0",
9898
"interface-datastore": "^0.8.0",
99-
"ipfs-bitswap": "^0.27.1",
99+
"ipfs-bitswap": "ipfs/js-ipfs-bitswap#chore/use-libp2p-0.28",
100100
"ipfs-block": "^0.8.1",
101101
"ipfs-block-service": "^0.16.0",
102102
"ipfs-core-utils": "^0.2.0",
@@ -131,21 +131,21 @@
131131
"iterable-ndjson": "^1.1.0",
132132
"jsondiffpatch": "^0.4.1",
133133
"just-safe-set": "^2.1.0",
134-
"libp2p": "^0.27.2",
135-
"libp2p-bootstrap": "^0.10.3",
134+
"libp2p": "libp2p/js-libp2p#0.28.x",
135+
"libp2p-bootstrap": "^0.11.0",
136136
"libp2p-crypto": "^0.17.1",
137-
"libp2p-delegated-content-routing": "^0.4.4",
138-
"libp2p-delegated-peer-routing": "^0.4.2",
139-
"libp2p-floodsub": "^0.20.0",
140-
"libp2p-gossipsub": "^0.2.3",
141-
"libp2p-kad-dht": "^0.18.3",
137+
"libp2p-delegated-content-routing": "^0.5.0",
138+
"libp2p-delegated-peer-routing": "^0.5.0",
139+
"libp2p-floodsub": "^0.21.0",
140+
"libp2p-gossipsub": "^0.4.0",
141+
"libp2p-kad-dht": "^0.19.1",
142142
"libp2p-keychain": "^0.6.0",
143-
"libp2p-mdns": "^0.13.1",
143+
"libp2p-mdns": "^0.14.1",
144144
"libp2p-mplex": "^0.9.3",
145145
"libp2p-record": "^0.7.0",
146146
"libp2p-secio": "^0.12.2",
147147
"libp2p-tcp": "^0.14.3",
148-
"libp2p-webrtc-star": "^0.17.9",
148+
"libp2p-webrtc-star": "^0.18.0",
149149
"libp2p-websockets": "^0.13.3",
150150
"mafmt": "^7.0.0",
151151
"merge-options": "^2.0.0",
@@ -160,7 +160,6 @@
160160
"p-queue": "^6.1.0",
161161
"parse-duration": "^0.1.2",
162162
"peer-id": "^0.13.5",
163-
"peer-info": "^0.17.0",
164163
"pretty-bytes": "^5.3.0",
165164
"progress": "^2.0.1",
166165
"protons": "^1.0.1",

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
@@ -75,10 +75,10 @@ module.exports = ({ libp2p, repo }) => {
7575
options.maxNumProviders = options.numProviders
7676
}
7777

78-
for await (const peerInfo of libp2p._dht.findProviders(key, options)) {
78+
for await (const peer of libp2p._dht.findProviders(key, options)) {
7979
yield {
80-
id: peerInfo.id.toB58String(),
81-
addrs: peerInfo.multiaddrs.toArray()
80+
id: peer.id.toB58String(),
81+
addrs: peer.addrs
8282
}
8383
}
8484
},
@@ -94,11 +94,11 @@ module.exports = ({ libp2p, repo }) => {
9494
peerId = PeerId.createFromCID(peerId)
9595
}
9696

97-
const peerInfo = await libp2p._dht.findPeer(peerId)
97+
const peer = await libp2p._dht.findPeer(peerId)
9898

9999
return {
100-
id: peerInfo.id.toB58String(),
101-
addrs: peerInfo.multiaddrs.toArray()
100+
id: peer.id.toB58String(),
101+
addrs: peer.addrs
102102
}
103103
},
104104

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

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

6-
module.exports = ({ peerInfo, libp2p }) => {
6+
module.exports = ({ peerId, libp2p }) => {
77
return async function id () { // eslint-disable-line require-await
8-
const id = peerInfo.id.toB58String()
8+
const id = peerId.toB58String()
99
let addresses = []
1010

1111
if (libp2p) {
@@ -15,7 +15,7 @@ module.exports = ({ peerInfo, libp2p }) => {
1515

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

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

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
const log = require('debug')('ipfs:components:init')
44
const PeerId = require('peer-id')
5-
const PeerInfo = require('peer-info')
65
const mergeOptions = require('merge-options')
76
const getDefaultConfig = require('../runtime/config-nodejs.js')
87
const createRepo = require('../runtime/repo-nodejs')
9-
const Keychain = require('libp2p-keychain')
10-
const NoKeychain = require('./no-keychain')
118
const mortice = require('mortice')
129
const { DAGNode } = require('ipld-dag-pb')
1310
const UnixFs = require('ipfs-unixfs')
@@ -79,7 +76,7 @@ module.exports = ({
7976
: await initNewRepo(repo, { ...options, print })
8077

8178
log('peer created')
82-
const peerInfo = new PeerInfo(peerId)
79+
8380
const blockService = new BlockService(repo)
8481
const ipld = new Ipld(getDefaultIpldOptions(blockService, constructorOptions.ipld, log))
8582

@@ -141,7 +138,7 @@ module.exports = ({
141138
// Setup the offline routing for IPNS.
142139
// This is primarily used for offline ipns modifications, such as the initializeKeyspace feature.
143140
const offlineDatastore = new OfflineDatastore(repo)
144-
const ipns = new IPNS(offlineDatastore, repo.datastore, peerInfo, keychain, { pass: options.pass })
141+
const ipns = new IPNS(offlineDatastore, repo.datastore, peerId, keychain, { pass: options.pass })
145142
await ipns.initializeKeyspace(peerId.privKey, emptyDirCid.toString())
146143
}
147144

@@ -157,7 +154,7 @@ module.exports = ({
157154
ipld,
158155
keychain,
159156
object,
160-
peerInfo,
157+
peerId,
161158
pin,
162159
pinManager,
163160
preload,
@@ -189,7 +186,6 @@ async function initNewRepo (repo, { privateKey, emptyRepo, bits, profiles, confi
189186
}
190187

191188
const peerId = await createPeerId({ privateKey, bits, print })
192-
let keychain = new NoKeychain()
193189

194190
log('identity generated')
195191

@@ -200,23 +196,32 @@ async function initNewRepo (repo, { privateKey, emptyRepo, bits, profiles, confi
200196

201197
privateKey = peerId.privKey
202198

203-
config.Keychain = Keychain.generateOptions()
204-
205199
log('peer identity: %s', config.Identity.PeerID)
206200

207201
await repo.init(config)
208202
await repo.open()
209203

210204
log('repo opened')
211205

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

219-
return { peerId, keychain }
224+
return { peerId, keychain: libp2p.keychain }
220225
}
221226

222227
async function initExistingRepo (repo, { config: newConfig, profiles, pass }) {
@@ -232,27 +237,21 @@ async function initExistingRepo (repo, { config: newConfig, profiles, pass }) {
232237
await repo.config.set(config)
233238
}
234239

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

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

255-
return { peerId, keychain }
254+
return { peerId, keychain: libp2p.keychain }
256255
}
257256

258257
function createPeerId ({ privateKey, bits, print }) {
@@ -302,7 +301,7 @@ function createApi ({
302301
ipld,
303302
keychain,
304303
object,
305-
peerInfo,
304+
peerId,
306305
pin,
307306
pinManager,
308307
preload,
@@ -336,7 +335,7 @@ function createApi ({
336335
dns: Components.dns(),
337336
files: Components.files({ ipld, block, blockService, repo, preload, options: constructorOptions }),
338337
get: Components.get({ ipld, preload }),
339-
id: Components.id({ peerInfo }),
338+
id: Components.id({ peerId }),
340339
init: async () => { throw new AlreadyInitializedError() }, // eslint-disable-line require-await
341340
isOnline: Components.isOnline({}),
342341
key: {
@@ -366,7 +365,7 @@ function createApi ({
366365
initOptions,
367366
ipld,
368367
keychain,
369-
peerInfo,
368+
peerId,
370369
pinManager,
371370
preload,
372371
print,
@@ -382,7 +381,7 @@ function createApi ({
382381
addrs: notStarted,
383382
connect: notStarted,
384383
disconnect: notStarted,
385-
localAddrs: Components.swarm.localAddrs({ peerInfo }),
384+
localAddrs: Components.swarm.localAddrs({ multiaddrs: [] }),
386385
peers: notStarted
387386
},
388387
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)