From ca9e77d6b76c35465adf652c45e0d7b81d996552 Mon Sep 17 00:00:00 2001 From: David Dias Date: Sat, 30 Apr 2016 12:23:49 +0200 Subject: [PATCH] move to peer-book --- package.json | 3 ++- src/core/index.js | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c7a3ef91eb..eb669ec0c2 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "lodash.get": "^4.2.1", "lodash.set": "^4.0.0", "multiaddr": "^1.3.0", + "peer-book": "0.1.0", "peer-id": "^0.6.6", "peer-info": "^0.6.2", "ronin": "^0.3.11", @@ -111,4 +112,4 @@ "kumavis ", "nginnever " ] -} \ No newline at end of file +} diff --git a/src/core/index.js b/src/core/index.js index 570b87b01b..474ade13fa 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -13,6 +13,7 @@ const importer = require('ipfs-data-importing').import const libp2p = require('libp2p-ipfs') const init = require('./init') const IPFSRepo = require('ipfs-repo') +const PeerBook = require('peer-book') exports = module.exports = IPFS @@ -29,7 +30,7 @@ function IPFS (repo) { const dagS = new DAGService(blockS) var peerInfo var libp2pNode - var peerInfoBook = {} + const peerInfoBook = new PeerBook() this.load = (callback) => { repo.exists((err, exists) => { @@ -339,7 +340,7 @@ function IPFS (repo) { return callback(OFFLINE_ERROR) } - callback(null, peerInfoBook) + callback(null, peerInfoBook.getAll()) }, // all the addrs we know addrs: (callback) => { @@ -371,7 +372,7 @@ function IPFS (repo) { ma = ma.toString().replace(/\/ipfs\/(.*)/, '') // FIXME remove this when multiaddr supports ipfs peer.multiaddr.add(multiaddr(ma)) - peerInfoBook[peer.id.toB58String()] = peer + peerInfoBook.put(peer) libp2pNode.swarm.dial(peer, (err) => { callback(err, id)