Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latest libp2p (new API) #168

Merged
merged 3 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@
},
"homepage": "https://github.com/ipfs/js-ipfs-bitswap#readme",
"devDependencies": {
"aegir": "^12.4.0",
"aegir": "^13.0.0",
"benchmark": "^2.1.4",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"ipfs-repo": "~0.18.7",
"libp2p": "~0.15.2",
"libp2p-kad-dht": "~0.6.3",
"libp2p": "~0.16.5",
"libp2p-kad-dht": "~0.8.0",
"libp2p-multiplex": "~0.5.1",
"libp2p-secio": "~0.9.1",
"libp2p-tcp": "~0.11.2",
"libp2p-secio": "~0.9.2",
"libp2p-tcp": "~0.11.5",
"lodash": "^4.17.5",
"lodash.range": "^3.2.0",
"lodash.without": "^4.4.0",
"multiaddr": "^3.0.2",
"ncp": "^2.0.0",
"peer-book": "~0.5.4",
"peer-id": "~0.10.5",
"peer-id": "~0.10.6",
"peer-info": "~0.11.6",
"pre-commit": "^1.2.2",
"rimraf": "^2.6.2",
Expand Down
4 changes: 2 additions & 2 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ class Network {
// Dial to the peer and try to use the most recent Bitswap
_dialPeer (peer, callback) {
// Attempt Bitswap 1.1.0
this.libp2p.dial(peer, BITSWAP110, (err, conn) => {
this.libp2p.dialProtocol(peer, BITSWAP110, (err, conn) => {
if (err) {
// Attempt Bitswap 1.0.0
this.libp2p.dial(peer, BITSWAP100, (err, conn) => {
this.libp2p.dialProtocol(peer, BITSWAP100, (err, conn) => {
if (err) { return callback(err) }

callback(null, conn, BITSWAP100)
Expand Down
4 changes: 2 additions & 2 deletions test/network/gen-bitswap-network.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ describe('gen Bitswap network', function () {
expect(err).to.not.exist()
nodeArr.forEach((node) => {
expect(
Object.keys(node.libp2p.swarm.conns)
Object.keys(node.libp2p.switch.conns)
).to.be.empty()

expect(
Object.keys(node.libp2p.swarm.muxedConns)
Object.keys(node.libp2p.switch.muxedConns)
).to.have.length(n - 1)
})

Expand Down
4 changes: 2 additions & 2 deletions test/network/network.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('network', () => {
expect(err).to.not.exist()
}

p2pA.dial(p2pB.peerInfo, '/ipfs/bitswap/1.0.0', (err, conn) => {
p2pA.dialProtocol(p2pB.peerInfo, '/ipfs/bitswap/1.0.0', (err, conn) => {
expect(err).to.not.exist()

pull(
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('network', () => {
expect(err).to.not.exist()
}

p2pA.dial(p2pB.peerInfo, '/ipfs/bitswap/1.1.0', (err, conn) => {
p2pA.dialProtocol(p2pB.peerInfo, '/ipfs/bitswap/1.1.0', (err, conn) => {
expect(err).to.not.exist()

pull(
Expand Down
9 changes: 7 additions & 2 deletions test/swarms.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const stats = require('stats-lite')
const distributionTest = require('./utils/distribution-test')
const test = it

describe('swarms', () => {
describe.skip('swarms', () => {
const print = Boolean(process.env.PRINT)

after(() => {
Expand All @@ -15,26 +15,31 @@ describe('swarms', () => {

test('2 nodes, 2 blocks', function (done) {
this.timeout(10 * 1000)

maybePrint('2 nodes, 2 blocks', distributionTest(2, 2, done))
})

test('10 nodes, 2 blocks', function (done) {
this.timeout(30 * 1000)

maybePrint('10 nodes, 2 blocks', distributionTest(10, 2, done))
})

test.only('10 nodes, 10 blocks', function (done) {
test('10 nodes, 10 blocks', function (done) {
this.timeout(30 * 1000)

maybePrint('10 nodes, 10 blocks', distributionTest(10, 10, 1, done))
})

test('10 nodes, 20 blocks', function (done) {
this.timeout(30 * 1000)

maybePrint('10 nodes, 20 blocks', distributionTest(10, 20, done))
})

test('50 nodes, 2 blocks', function (done) {
this.timeout(600 * 1000)

maybePrint('50 nodes, 2 blocks', distributionTest(50, 2, done))
})

Expand Down
7 changes: 3 additions & 4 deletions test/types/message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const expect = chai.expect
const protons = require('protons')
const map = require('async/map')
const CID = require('cids')
const isNode = require('detect-node')
const _ = require('lodash')
const Buffer = require('safe-buffer').Buffer
const loadFixture = require('aegir/fixtures')
const testDataPath = (isNode ? '../' : '') + 'fixtures/serialized-from-go'
const rawMessageFullWantlist = loadFixture(__dirname, testDataPath + '/bitswap110-message-full-wantlist')
const rawMessageOneBlock = loadFixture(__dirname, testDataPath + '/bitswap110-message-one-block')
const testDataPath = 'test/fixtures/serialized-from-go'
const rawMessageFullWantlist = loadFixture(testDataPath + '/bitswap110-message-full-wantlist')
const rawMessageOneBlock = loadFixture(testDataPath + '/bitswap110-message-one-block')

const pbm = protons(require('../../src/types/message/message.proto'))

Expand Down
5 changes: 4 additions & 1 deletion test/utils/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ exports.mockLibp2pNode = () => {
findProviders: (cid, timeout, callback) => callback(null, [])
},
on () {},
dial (peer, protocol, callback) {
dial (peer, callback) {
setImmediate(() => callback())
},
dialProtocol (peer, protocol, callback) {
setImmediate(() => callback())
},
swarm: {
Expand Down