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

Commit e5179d5

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

File tree

23 files changed

+20871
-121
lines changed

23 files changed

+20871
-121
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-lock.json

Lines changed: 20760 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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')
@@ -79,7 +78,6 @@ module.exports = ({
7978
: await initNewRepo(repo, { ...options, print })
8079

8180
log('peer created')
82-
const peerInfo = new PeerInfo(peerId)
8381
const blockService = new BlockService(repo)
8482
const ipld = new Ipld(getDefaultIpldOptions(blockService, constructorOptions.ipld, log))
8583

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

@@ -157,7 +155,7 @@ module.exports = ({
157155
ipld,
158156
keychain,
159157
object,
160-
peerInfo,
158+
peerId,
161159
pin,
162160
pinManager,
163161
preload,
@@ -302,7 +300,7 @@ function createApi ({
302300
ipld,
303301
keychain,
304302
object,
305-
peerInfo,
303+
peerId,
306304
pin,
307305
pinManager,
308306
preload,
@@ -336,7 +334,7 @@ function createApi ({
336334
dns: Components.dns(),
337335
files: Components.files({ ipld, block, blockService, repo, preload, options: constructorOptions }),
338336
get: Components.get({ ipld, preload }),
339-
id: Components.id({ peerInfo }),
337+
id: Components.id({ peerId }),
340338
init: async () => { throw new AlreadyInitializedError() }, // eslint-disable-line require-await
341339
isOnline: Components.isOnline({}),
342340
key: {
@@ -366,7 +364,7 @@ function createApi ({
366364
initOptions,
367365
ipld,
368366
keychain,
369-
peerInfo,
367+
peerId,
370368
pinManager,
371369
preload,
372370
print,
@@ -382,7 +380,7 @@ function createApi ({
382380
addrs: notStarted,
383381
connect: notStarted,
384382
disconnect: notStarted,
385-
localAddrs: Components.swarm.localAddrs({ peerInfo }),
383+
localAddrs: Components.swarm.localAddrs({ multiaddrs: [] }),
386384
peers: notStarted
387385
},
388386
version: Components.version({ repo })

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

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

88
module.exports = ({
99
options,
10-
peerInfo,
10+
peerId,
11+
multiaddrs = [],
1112
repo,
1213
config
1314
}) => {
1415
options = options || {}
1516
config = config || {}
1617

1718
const { datastore } = repo
18-
const libp2pOptions = getLibp2pOptions({ options, config, datastore, peerInfo })
19+
const libp2pOptions = getLibp2pOptions({ options, config, datastore, peerId, multiaddrs })
1920

2021
if (typeof options.libp2p === 'function') {
21-
return options.libp2p({ libp2pOptions, options, config, datastore, peerInfo })
22+
return options.libp2p({ libp2pOptions, options, config, datastore, peerId })
2223
}
2324

2425
// Required inline to reduce startup time
2526
const Libp2p = require('libp2p')
2627
return new Libp2p(mergeOptions(libp2pOptions, get(options, 'libp2p', {})))
2728
}
2829

29-
function getLibp2pOptions ({ options, config, datastore, peerInfo }) {
30+
function getLibp2pOptions ({ options, config, datastore, peerId, multiaddrs }) {
3031
const getPubsubRouter = () => {
3132
const router = get(config, 'Pubsub.Router') || 'gossipsub'
3233

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

4041
const libp2pDefaults = {
4142
datastore,
42-
peerInfo,
43+
peerId: peerId,
4344
modules: {}
4445
}
4546

@@ -80,6 +81,9 @@ function getLibp2pOptions ({ options, config, datastore, peerInfo }) {
8081
get(config, 'Pubsub.Enabled', true))
8182
}
8283
},
84+
addresses: {
85+
listen: multiaddrs
86+
},
8387
connectionManager: get(options, 'connectionManager', {
8488
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater',
8589
get(config, 'Swarm.ConnMgr.HighWater')),

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 {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const appendRemainder = async (result, remainder) => {
3131
* @param {IPFS} self
3232
* @returns {Object}
3333
*/
34-
module.exports = ({ dns, ipns, peerInfo, isOnline, options: constructorOptions }) => {
34+
module.exports = ({ dns, ipns, peerId, isOnline, options: constructorOptions }) => {
3535
/**
3636
* Given a key, query the DHT for its best value.
3737
*
@@ -57,7 +57,7 @@ module.exports = ({ dns, ipns, peerInfo, isOnline, options: constructorOptions }
5757

5858
// Set node id as name for being resolved, if it is not received
5959
if (!name) {
60-
name = peerInfo.id.toB58String()
60+
name = peerId.toB58String()
6161
}
6262

6363
if (!name.startsWith('/ipns/')) {

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ module.exports = ({ libp2p }) => {
1212
peerId = PeerId.createFromCID(peerId)
1313
}
1414

15-
let peerInfo
16-
if (libp2p.peerStore.has(peerId)) {
17-
peerInfo = libp2p.peerStore.get(peerId)
18-
} else {
15+
let peer = libp2p.peerStore.get(peerId)
16+
17+
if (!peer) {
1918
yield { ...basePacket, text: `Looking up peer ${peerId}` }
20-
peerInfo = await libp2p.peerRouting.findPeer(peerId)
19+
peer = await libp2p.peerRouting.findPeer(peerId)
2120
}
2221

23-
yield { ...basePacket, text: `PING ${peerInfo.id.toB58String()}` }
22+
yield { ...basePacket, text: `PING ${peer.id.toB58String()}` }
2423

2524
let packetCount = 0
2625
let totalTime = 0
2726

2827
for (let i = 0; i < options.count; i++) {
2928
try {
30-
const time = await libp2p.ping(peerInfo)
29+
const time = await libp2p.ping(peer.id)
3130
totalTime += time
3231
packetCount++
3332
yield { ...basePacket, time }

0 commit comments

Comments
 (0)