Compare commits

...

7 Commits

Author SHA1 Message Date
3bde9c8bed chore: release version v0.24.4 2019-01-04 10:15:49 -07:00
14e12ee1f1 chore: update contributors 2019-01-04 10:15:48 -07:00
2374929990 chore: update deps
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
2019-01-04 10:11:49 -07:00
26de739bb1 chore: 2019 q1 okrs planning (#293)
* chore: add q1 2019 okr section

* docs: add proposed okr items

* chore: update OKR.md

* chore: remove quic transport

* chore: add thoughts on okr priorities

* chore: add detailed interop tests

* chore: add line for floodsub interop

* chore: move q1 okrs to the google spreadsheet
2018-12-17 12:20:12 +01:00
0f8d6afd8f chore: release version v0.24.3 2018-12-14 17:57:32 +01:00
daa26859e0 chore: update contributors 2018-12-14 17:57:31 +01:00
fdfb7b4e86 fix: not started yet (#297)
* fix: callback when not started rather than throwing asserts

* fix: dont remove transports until the switch has stopped

* test: update connection check logic

* test: fix variable reference

* chore: update switch dep

* chore: update switch dep
2018-12-14 17:54:32 +01:00
9 changed files with 120 additions and 76 deletions

View File

@ -1,3 +1,18 @@
<a name="0.24.4"></a>
## [0.24.4](https://github.com/libp2p/js-libp2p/compare/v0.24.3...v0.24.4) (2019-01-04)
<a name="0.24.3"></a>
## [0.24.3](https://github.com/libp2p/js-libp2p/compare/v0.24.2...v0.24.3) (2018-12-14)
### Bug Fixes
* not started yet ([#297](https://github.com/libp2p/js-libp2p/issues/297)) ([fdfb7b4](https://github.com/libp2p/js-libp2p/commit/fdfb7b4))
<a name="0.24.2"></a>
## [0.24.2](https://github.com/libp2p/js-libp2p/compare/v0.24.1...v0.24.2) (2018-12-04)

4
OKR.md
View File

@ -2,6 +2,10 @@
We try to frame our ongoing work using a process based on quarterly Objectives and Key Results (OKRs). Objectives reflect outcomes that are challenging, but realistic. Results are tangible and measurable.
## 2019 Q1
Find the js-libp2p OKRs for 2019 Q1 at the [2019 Q1 libp2p OKRs Spreadsheet](https://docs.google.com/spreadsheets/d/11GKG1DBRIIAiQnHvLD7_IqWxDGsVdaZFpxJM6NWtXe8/edit#gid=1271182838)
## 2018 Q4
Find the js-libp2p OKRs for 2018 Q4 at the [2018 Q4 libp2p OKRs Spreadsheet](https://docs.google.com/spreadsheets/d/1BYwmbVicgo6_tOHAbgiUXWge8Ej0qR1M_gAUulazmrg/edit#gid=1241853194)

View File

@ -1,6 +1,6 @@
{
"name": "libp2p",
"version": "0.24.2",
"version": "0.24.4",
"description": "JavaScript base class for libp2p bundles",
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
"main": "src/index.js",
@ -50,17 +50,17 @@
"libp2p-connection-manager": "~0.0.2",
"libp2p-floodsub": "~0.15.1",
"libp2p-ping": "~0.8.3",
"libp2p-switch": "~0.41.2",
"libp2p-switch": "~0.41.3",
"libp2p-websockets": "~0.12.0",
"mafmt": "^6.0.2",
"multiaddr": "^5.0.2",
"peer-book": "~0.8.0",
"multiaddr": "^6.0.2",
"peer-book": "~0.9.0",
"peer-id": "~0.12.0",
"peer-info": "~0.14.1"
"peer-info": "~0.15.0"
},
"devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"aegir": "^17.0.1",
"aegir": "^18.0.2",
"chai": "^4.2.0",
"chai-checkmark": "^1.0.1",
"cids": "~0.5.5",
@ -71,15 +71,15 @@
"libp2p-circuit": "~0.3.0",
"libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-kad-dht": "~0.11.1",
"libp2p-kad-dht": "~0.14.2",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.4",
"libp2p-secio": "~0.10.1",
"libp2p-secio": "~0.11.0",
"libp2p-spdy": "~0.13.0",
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.5",
"libp2p-websocket-star": "~0.9.0",
"libp2p-websocket-star-rendezvous": "~0.2.4",
"libp2p-websocket-star": "~0.10.1",
"libp2p-websocket-star-rendezvous": "~0.3.0",
"lodash.times": "^4.3.2",
"nock": "^10.0.2",
"pull-goodbye": "0.0.2",
@ -90,6 +90,7 @@
"wrtc": "~0.3.2"
},
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
"Alan Shaw <alan@tableflip.io>",
"Chris Bratlien <chrisbratlien@gmail.com>",
"Chris Dostert <chrisdostert@users.noreply.github.com>",

View File

@ -2,10 +2,10 @@
const FSM = require('fsm-event')
const EventEmitter = require('events').EventEmitter
const assert = require('assert')
const debug = require('debug')
const log = debug('libp2p')
log.error = debug('libp2p:error')
const errCode = require('err-code')
const each = require('async/each')
const series = require('async/series')
@ -24,7 +24,12 @@ const pubsub = require('./pubsub')
const getPeerInfo = require('./get-peer-info')
const validateConfig = require('./config').validate
const NOT_STARTED_ERROR_MESSAGE = 'The libp2p node is not started yet'
const notStarted = (action, state) => {
return errCode(
new Error(`libp2p cannot ${action} when not started; state is ${state}`),
'ERR_NODE_NOT_STARTED'
)
}
/**
* @fires Node#error Emitted when an error occurs
@ -217,8 +222,6 @@ class Node extends EventEmitter {
* @returns {void}
*/
dial (peer, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
this.dialProtocol(peer, null, callback)
}
@ -233,7 +236,9 @@ class Node extends EventEmitter {
* @returns {void}
*/
dialProtocol (peer, protocol, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
if (!this.isStarted()) {
return callback(notStarted('dial', this.state._state))
}
if (typeof protocol === 'function') {
callback = protocol
@ -261,7 +266,9 @@ class Node extends EventEmitter {
* @returns {void}
*/
dialFSM (peer, protocol, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
if (!this.isStarted()) {
return callback(notStarted('dial', this.state._state))
}
if (typeof protocol === 'function') {
callback = protocol
@ -282,8 +289,6 @@ class Node extends EventEmitter {
}
hangUp (peer, callback) {
assert(this.isStarted(), NOT_STARTED_ERROR_MESSAGE)
this._getPeerInfo(peer, (err, peerInfo) => {
if (err) { return callback(err) }
@ -293,7 +298,7 @@ class Node extends EventEmitter {
ping (peer, callback) {
if (!this.isStarted()) {
return callback(new Error(NOT_STARTED_ERROR_MESSAGE))
return callback(notStarted('ping', this.state._state))
}
this._getPeerInfo(peer, (err, peerInfo) => {
@ -463,13 +468,13 @@ class Node extends EventEmitter {
}
cb()
},
(cb) => {
// Ensures idempotency for restarts
this._switch.transport.removeAll(cb)
},
(cb) => {
this.connectionManager.stop()
this._switch.stop(cb)
},
(cb) => {
// Ensures idempotent restarts
this._switch.transport.removeAll(cb)
}
], (err) => {
if (err) {

View File

@ -114,5 +114,29 @@ describe('libp2p state machine (fsm)', () => {
node.start()
})
it('should not dial when the node is stopped', (done) => {
node.on('stop', () => {
node.dial(null, (err) => {
expect(err).to.exist()
expect(err.code).to.eql('ERR_NODE_NOT_STARTED')
done()
})
})
node.stop()
})
it('should not dial (fsm) when the node is stopped', (done) => {
node.on('stop', () => {
node.dialFSM(null, null, (err) => {
expect(err).to.exist()
expect(err.code).to.eql('ERR_NODE_NOT_STARTED')
done()
})
})
node.stop()
})
})
})

View File

@ -215,7 +215,7 @@ describe('stream muxing', () => {
nodeA.dial(nodeB.peerInfo, (err) => {
expect(err).to.not.exist()
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
cb()
})
},

View File

@ -102,7 +102,7 @@ describe('transports', () => {
function check () {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
done()
}
})
@ -142,7 +142,7 @@ describe('transports', () => {
const peers = nodeA.peerBook.getAll()
expect(err).to.not.exist()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
done()
}
})
@ -153,16 +153,17 @@ describe('transports', () => {
expect(err).to.not.exist()
connFSM.once('muxed', () => {
expect(nodeA._switch.muxedConns).to.have.any.keys(
peerB.id.toB58String()
)
expect(
nodeA._switch.connection.getAllById(peerB.id.toB58String())
).to.have.length(1)
connFSM.once('error', done)
connFSM.once('close', () => {
// ensure the connection is closed
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
peerB.id.toB58String()
])
expect(
nodeA._switch.connection.getAllById(peerB.id.toB58String())
).to.have.length(0)
done()
})
@ -312,7 +313,7 @@ describe('transports', () => {
function check () {
const peers = node1.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
expect(node1._switch.connection.getAll()).to.have.length(0)
done()
}
})
@ -326,7 +327,7 @@ describe('transports', () => {
function check () {
// Verify both nodes are connected to node 3
if (node1._switch.muxedConns[b58Id] && node2._switch.muxedConns[b58Id]) {
if (node1._switch.connection.getAllById(b58Id) && node2._switch.connection.getAllById(b58Id)) {
done()
}
}
@ -417,7 +418,7 @@ describe('transports', () => {
function check () {
const peers = node1.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(node1._switch.muxedConns)).to.have.length(0)
expect(node1._switch.connection.getAll()).to.have.length(0)
done()
}
})
@ -430,8 +431,8 @@ describe('transports', () => {
function check () {
if (++counter === 3) {
expect(Object.keys(node1._switch.muxedConns).length).to.equal(1)
expect(Object.keys(node2._switch.muxedConns).length).to.equal(1)
expect(node1._switch.connection.getAll()).to.have.length(1)
expect(node2._switch.connection.getAll()).to.have.length(1)
done()
}
}

View File

@ -91,14 +91,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
cb()
},
(cb) => {
const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
expect(nodeB._switch.connection.getAll()).to.have.length(0)
cb()
}
], done)
@ -117,15 +116,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
cb()
},
(cb) => {
const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
cb()
}
], () => tryEcho(conn, done))
@ -143,15 +140,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
cb()
},
(cb) => {
const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
expect(nodeB._switch.connection.getAll()).to.have.length(0)
cb()
}
], done)
@ -170,13 +165,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
cb()
},
(cb) => {
const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(1)
expect(nodeA._switch.connection.getAll()).to.have.length(1)
cb()
}
], () => tryEcho(conn, done))
@ -194,13 +189,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA._switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
cb()
},
(cb) => {
const peers = nodeB.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeB._switch.muxedConns)).to.have.length(0)
expect(nodeB._switch.connection.getAll()).to.have.length(0)
cb()
}
], done)
@ -213,16 +208,16 @@ describe('transports', () => {
expect(err).to.not.exist()
connFSM.once('muxed', () => {
expect(nodeA._switch.muxedConns).to.have.any.keys(
nodeB.peerInfo.id.toB58String()
)
expect(
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
).to.have.length(1)
connFSM.once('error', done)
connFSM.once('close', () => {
// ensure the connection is closed
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
nodeB.peerInfo.id.toB58String()
])
expect(
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
).to.have.length(0)
done()
})
@ -235,9 +230,9 @@ describe('transports', () => {
nodeA.dialFSM(nodeB.peerInfo, '/echo/1.0.0', (err, connFSM) => {
expect(err).to.not.exist()
connFSM.once('connection', (conn) => {
expect(nodeA._switch.muxedConns).to.have.all.keys([
nodeB.peerInfo.id.toB58String()
])
expect(
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
).to.have.length(1)
tryEcho(conn, () => {
connFSM.close()
})
@ -245,9 +240,9 @@ describe('transports', () => {
connFSM.once('error', done)
connFSM.once('close', () => {
// ensure the connection is closed
expect(nodeA._switch.muxedConns).to.not.have.any.keys([
nodeB.peerInfo.id.toB58String()
])
expect(
nodeA._switch.connection.getAllById(nodeB.peerInfo.id.toB58String())
).to.have.length(0)
done()
})
})
@ -309,13 +304,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeTCP.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(1)
expect(nodeTCP._switch.connection.getAll()).to.have.length(1)
cb()
},
(cb) => {
const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1)
cb()
}
], done)
@ -333,14 +328,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeTCP.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeTCP._switch.muxedConns)).to.have.length(0)
expect(nodeTCP._switch.connection.getAll()).to.have.length(0)
cb()
},
(cb) => {
const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0)
cb()
}
], done)
@ -360,13 +354,13 @@ describe('transports', () => {
(cb) => {
const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(2)
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(1)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(1)
cb()
},
(cb) => {
const peers = nodeWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(1)
expect(nodeWS._switch.connection.getAll()).to.have.length(1)
cb()
}
], done)
@ -384,14 +378,14 @@ describe('transports', () => {
(cb) => {
const peers = nodeTCPnWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(2)
expect(Object.keys(nodeTCPnWS._switch.muxedConns)).to.have.length(0)
expect(nodeTCPnWS._switch.connection.getAll()).to.have.length(0)
cb()
},
(cb) => {
const peers = nodeWS.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeWS._switch.muxedConns)).to.have.length(0)
expect(nodeWS._switch.connection.getAll()).to.have.length(0)
cb()
}
], done)
@ -516,7 +510,7 @@ describe('transports', () => {
let i = 1;
[nodeAll, otherNode].forEach((node) => {
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
expect(node._switch.connection.getAll()).to.have.length(muxed)
})
callback()
}
@ -678,7 +672,7 @@ describe('transports', () => {
let i = 1;
[nodeAll, otherNode].forEach((node) => {
expect(Object.keys(node.peerBook.getAll())).to.have.length(i-- ? peers : 1)
expect(Object.keys(node._switch.muxedConns)).to.have.length(muxed)
expect(node._switch.connection.getAll()).to.have.length(muxed)
})
done()
}

View File

@ -77,7 +77,7 @@ describe('Turbolence tests', () => {
function check () {
const peers = nodeA.peerBook.getAll()
expect(Object.keys(peers)).to.have.length(1)
expect(Object.keys(nodeA.switch.muxedConns)).to.have.length(0)
expect(nodeA._switch.connection.getAll()).to.have.length(0)
done()
}
})