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

Commit 036eaf6

Browse files
committed
Merge pull request #189 from ipfs/feat/peer-book
move to peer-book
2 parents 5c26fae + ca9e77d commit 036eaf6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"lodash.get": "^4.2.1",
7575
"lodash.set": "^4.0.0",
7676
"multiaddr": "^1.3.0",
77+
"peer-book": "0.1.0",
7778
"peer-id": "^0.6.6",
7879
"peer-info": "^0.6.2",
7980
"ronin": "^0.3.11",

src/core/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const importer = require('ipfs-data-importing').import
1313
const libp2p = require('libp2p-ipfs')
1414
const init = require('./init')
1515
const IPFSRepo = require('ipfs-repo')
16+
const PeerBook = require('peer-book')
1617

1718
exports = module.exports = IPFS
1819

@@ -29,7 +30,7 @@ function IPFS (repo) {
2930
const dagS = new DAGService(blockS)
3031
var peerInfo
3132
var libp2pNode
32-
var peerInfoBook = {}
33+
const peerInfoBook = new PeerBook()
3334

3435
this.load = (callback) => {
3536
repo.exists((err, exists) => {
@@ -339,7 +340,7 @@ function IPFS (repo) {
339340
return callback(OFFLINE_ERROR)
340341
}
341342

342-
callback(null, peerInfoBook)
343+
callback(null, peerInfoBook.getAll())
343344
},
344345
// all the addrs we know
345346
addrs: (callback) => {
@@ -371,7 +372,7 @@ function IPFS (repo) {
371372
ma = ma.toString().replace(/\/ipfs\/(.*)/, '') // FIXME remove this when multiaddr supports ipfs
372373

373374
peer.multiaddr.add(multiaddr(ma))
374-
peerInfoBook[peer.id.toB58String()] = peer
375+
peerInfoBook.put(peer)
375376

376377
libp2pNode.swarm.dial(peer, (err) => {
377378
callback(err, id)

0 commit comments

Comments
 (0)