Skip to content

Commit

Permalink
Merge pull request #16 from ipfs/update/latest-libp2p-ipfs
Browse files Browse the repository at this point in the history
Update to latest libp2p-ipfs
  • Loading branch information
daviddias committed May 29, 2016
2 parents 636a587 + beffebc commit e294cf1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme",
"devDependencies": {
"abstract-blob-store": "^3.2.0",
"aegir": "^3.1.0",
"aegir": "^3.2.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.1.2",
"ipfs-repo": "^0.8.0",
"libp2p-ipfs": "^0.9.0",
"libp2p-ipfs": "^0.10.0",
"lodash": "^4.11.2",
"multiaddr": "^2.0.2",
"ncp": "^2.0.0",
Expand All @@ -63,4 +63,4 @@
"David Dias <daviddias.p@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>"
]
}
}
6 changes: 3 additions & 3 deletions src/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ module.exports = class Network {
this._onPeerMux = this._onPeerMux.bind(this)
this._onPeerMuxClosed = this._onPeerMuxClosed.bind(this)

this.libp2p.swarm.handle(PROTOCOL_IDENTIFIER, this._onConnection)
this.libp2p.handle(PROTOCOL_IDENTIFIER, this._onConnection)

this.libp2p.swarm.on('peer-mux-established', this._onPeerMux)

this.libp2p.swarm.on('peer-mux-closed', this._onPeerMuxClosed)
}

stop () {
this.libp2p.swarm.unhandle(PROTOCOL_IDENTIFIER)
this.libp2p.unhandle(PROTOCOL_IDENTIFIER)
this.libp2p.swarm.removeEventListener('peer-mux-established', this._onPeerMux)

this.libp2p.swarm.removeEventListener('peer-mux-closed', this._onPeerMuxClosed)
Expand Down Expand Up @@ -86,7 +86,7 @@ module.exports = class Network {
return done(err)
}

const conn = this.libp2p.swarm.dial(peerInfo, PROTOCOL_IDENTIFIER, (err) => {
this.libp2p.dialByPeerInfo(peerInfo, PROTOCOL_IDENTIFIER, (err, conn) => {
if (err) {
return done(err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const makeBlock = () => new Block(`hello world ${Math.random()}`)

module.exports = (repo) => {
const libp2pMock = {
handle: function () {},
swarm: {
handle: function () {},
muxedConns: {},
on: function () {}
}
Expand Down
30 changes: 17 additions & 13 deletions test/network/network.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const Block = require('ipfs-block')
const Network = require('../../src/network')
const Message = require('../../src/message')

describe('network', () => {
describe('network', function () {
this.timeout(15 * 1000)

let libp2pNodeA
let libp2pNodeB
let peerInfoA
Expand All @@ -27,18 +29,21 @@ describe('network', () => {
peerInfoA = new PeerInfo()
peerInfoB = new PeerInfo()

peerInfoA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/10100'))
peerInfoB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/10500'))
peerInfoA.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/10100/ipfs/' + peerInfoA.id.toB58String()))
console.log('peerA', peerInfoA.id.toB58String())

peerInfoB.multiaddr.add(multiaddr('/ip4/127.0.0.1/tcp/10500/ipfs/' + peerInfoB.id.toB58String()))
console.log('peerB', peerInfoB.id.toB58String())

peerBookA = new PeerBook()
peerBookB = new PeerBook()

peerBookA.put(peerInfoB)
peerBookB.put(peerInfoA)

libp2pNodeA = new libp2p.Node(peerInfoA)
libp2pNodeA = new libp2p.Node(peerInfoA, peerBookA)
libp2pNodeA.start(started)
libp2pNodeB = new libp2p.Node(peerInfoB)
libp2pNodeB = new libp2p.Node(peerInfoB, peerBookB)
libp2pNodeB.start(started)

function started () {
Expand All @@ -50,8 +55,8 @@ describe('network', () => {

after((done) => {
let counter = 0
libp2pNodeA.swarm.close(stopped)
libp2pNodeB.swarm.close(stopped)
libp2pNodeA.stop(stopped)
libp2pNodeB.stop(stopped)

function stopped () {
if (++counter === 2) {
Expand Down Expand Up @@ -109,7 +114,7 @@ describe('network', () => {
}
}

libp2pNodeA.swarm.dial(peerInfoB, (err) => {
libp2pNodeA.dialByPeerInfo(peerInfoB, (err) => {
expect(err).to.not.exist
})

Expand Down Expand Up @@ -145,13 +150,12 @@ describe('network', () => {
expect(err).to.not.exist
}

const conn = libp2pNodeA.swarm.dial(peerInfoB, '/ipfs/bitswap/1.0.0', (err) => {
libp2pNodeA.dialByPeerInfo(peerInfoB, '/ipfs/bitswap/1.0.0', (err, conn) => {
const msgEncoded = msg.toProto()
conn.write(msgEncoded)
conn.end()
expect(err).to.not.exist
})

const msgEncoded = msg.toProto()
conn.write(msgEncoded)
conn.end()
})

it('sendMessage', (done) => {
Expand Down
12 changes: 7 additions & 5 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const async = require('async')
const _ = require('lodash')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const PeerBook = require('peer-book')
// const PeerBook = require('peer-book')
const multiaddr = require('multiaddr')
const Bitswap = require('../src')
const libp2p = require('libp2p-ipfs')
Expand Down Expand Up @@ -100,8 +100,10 @@ exports.genBitswapNetwork = (n, callback) => {
// create PeerInfo and libp2p.Node for each
_.range(n).forEach((i) => {
const p = new PeerInfo()
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/' + (basePort + i))
const mh2 = multiaddr('/ip4/127.0.0.1/tcp/' + (basePort + i + 2000) + '/ws')
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/' + (basePort + i) +
'/ipfs/' + p.id.toB58String())
const mh2 = multiaddr('/ip4/127.0.0.1/tcp/' + (basePort + i + 2000) + '/ws' +
'/ipfs/' + p.id.toB58String())

p.multiaddr.add(mh1)
p.multiaddr.add(mh2)
Expand All @@ -112,7 +114,7 @@ exports.genBitswapNetwork = (n, callback) => {

// create PeerBook and populate peerBook
netArray.forEach((net, i) => {
const pb = new PeerBook()
const pb = netArray[i].libp2p.peerBook
netArray.forEach((net, j) => {
if (i === j) {
return
Expand Down Expand Up @@ -155,7 +157,7 @@ exports.genBitswapNetwork = (n, callback) => {
to.peerInfo.id.toB58String()) {
return cbJ()
}
from.libp2p.swarm.dial(to.peerInfo, cbJ)
from.libp2p.dialByPeerInfo(to.peerInfo, cbJ)
}, (err) => {
if (err) {
throw err
Expand Down

0 comments on commit e294cf1

Please sign in to comment.