Compare commits

..

10 Commits

3 changed files with 51 additions and 15 deletions

View File

@ -1,3 +1,21 @@
<a name="0.8.0"></a>
# [0.8.0](https://github.com/libp2p/js-libp2p/compare/v0.7.0...v0.8.0) (2017-03-31)
### Bug Fixes
* addition of ipfs id appendix must come before transport filtering ([291e79f](https://github.com/libp2p/js-libp2p/commit/291e79f))
* avoid deleting nodes from peerBook ([300936f](https://github.com/libp2p/js-libp2p/commit/300936f))
* correct method on peer-book ([031ecb3](https://github.com/libp2p/js-libp2p/commit/031ecb3))
### Features
* append peer id to multiaddr if not there ([59ea9c3](https://github.com/libp2p/js-libp2p/commit/59ea9c3))
* not remove peer from peerBook on disconnect ([a4b41b0](https://github.com/libp2p/js-libp2p/commit/a4b41b0))
<a name="0.7.0"></a>
# [0.7.0](https://github.com/libp2p/js-libp2p/compare/v0.6.2...v0.7.0) (2017-03-29)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p",
"version": "0.7.0",
"version": "0.8.0",
"description": "JavaScript Skeleton for libp2p bundles",
"main": "src/index.js",
"scripts": {
@ -41,11 +41,12 @@
},
"dependencies": {
"libp2p-ping": "~0.3.2",
"libp2p-swarm": "~0.28.0",
"libp2p-swarm": "~0.29.0",
"mafmt": "^2.1.8",
"multiaddr": "^2.3.0",
"peer-book": "~0.3.2",
"peer-id": "~0.8.5",
"peer-info": "~0.8.5"
"peer-book": "~0.4.0",
"peer-id": "~0.8.6",
"peer-info": "~0.9.2"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",

View File

@ -3,6 +3,7 @@
const Swarm = require('libp2p-swarm')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const mafmt = require('mafmt')
const PeerBook = require('peer-book')
const multiaddr = require('multiaddr')
const EventEmitter = require('events').EventEmitter
@ -25,7 +26,7 @@ class Node extends EventEmitter {
this.peerBook = _peerBook || new PeerBook()
this.isOnline = false
this.swarm = new Swarm(this.peerInfo)
this.swarm = new Swarm(this.peerInfo, this.peerBook)
// Attach stream multiplexers
if (this.modules.connection.muxer) {
@ -38,8 +39,8 @@ class Node extends EventEmitter {
// If muxer exists, we can use Identify
this.swarm.connection.reuse()
// Received incommind dial and muxer upgrade happened, reuse this
// muxed connection
// Received incommind dial and muxer upgrade happened,
// reuse this muxed connection
this.swarm.on('peer-mux-established', (peerInfo) => {
this.emit('peer:connect', peerInfo)
this.peerBook.put(peerInfo)
@ -47,7 +48,6 @@ class Node extends EventEmitter {
this.swarm.on('peer-mux-closed', (peerInfo) => {
this.emit('peer:disconnect', peerInfo)
this.peerBook.removeByB58String(peerInfo.id.toB58String())
})
}
@ -91,7 +91,19 @@ class Node extends EventEmitter {
let transports = this.modules.transport
transports = Array.isArray(transports) ? transports : [transports]
const multiaddrs = this.peerInfo.multiaddrs
// so that we can have webrtc-star addrs without adding manually the id
const maOld = []
const maNew = []
this.peerInfo.multiaddrs.forEach((ma) => {
if (!mafmt.IPFS.matches(ma)) {
maOld.push(ma)
maNew.push(ma.encapsulate('/ipfs/' + this.peerInfo.id.toB58String()))
}
})
this.peerInfo.multiaddrs.replace(maOld, maNew)
const multiaddrs = this.peerInfo.multiaddrs.toArray()
transports.forEach((transport) => {
if (transport.filter(multiaddrs).length > 0) {
@ -152,13 +164,19 @@ class Node extends EventEmitter {
dial (peer, protocol, callback) {
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
const peerInfo = this._getPeerInfo(peer)
if (typeof protocol === 'function') {
callback = protocol
protocol = undefined
}
let peerInfo
try {
peerInfo = this._getPeerInfo(peer)
} catch (err) {
return callback(err)
}
this.swarm.dial(peerInfo, protocol, (err, conn) => {
if (err) {
return callback(err)
@ -172,7 +190,6 @@ class Node extends EventEmitter {
assert(this.isOn(), OFFLINE_ERROR_MESSAGE)
const peerInfo = this._getPeerInfo(peer)
this.peerBook.removeByB58String(peerInfo.id.toB58String())
this.swarm.hangUp(peerInfo, callback)
}
@ -194,15 +211,15 @@ class Node extends EventEmitter {
} else if (multiaddr.isMultiaddr(peer)) {
const peerIdB58Str = peer.getPeerId()
try {
p = this.peerBook.getByB58String(peerIdB58Str)
p = this.peerBook.get(peerIdB58Str)
} catch (err) {
p = new PeerInfo(PeerId.createFromB58String(peerIdB58Str))
}
p.multiaddr.add(peer)
p.multiaddrs.add(peer)
} else if (PeerId.isPeerId(peer)) {
const peerIdB58Str = peer.toB58String()
try {
p = this.peerBook.getByB58String(peerIdB58Str)
p = this.peerBook.get(peerIdB58Str)
} catch (err) {
// TODO this is where PeerRouting comes into place
throw new Error('No knowledge about: ' + peerIdB58Str)