feat: make libp2p a state machine (#257)

* docs: add events to readme
This commit is contained in:
Jacob Heun
2018-10-19 17:37:34 +02:00
committed by GitHub
parent 686379efb0
commit 0b75f99d75
19 changed files with 519 additions and 109 deletions

View File

@ -185,7 +185,7 @@ describe('transports', () => {
})
it('nodeA.hangUp nodeB using PeerId (third)', (done) => {
nodeA.hangUp(nodeB.peerInfo.multiaddrs.toArray()[0], (err) => {
nodeA.hangUp(nodeB.peerInfo.id, (err) => {
expect(err).to.not.exist()
setTimeout(check, 500)
@ -207,6 +207,51 @@ describe('transports', () => {
}
})
})
it('.dialFSM check conn and close', (done) => {
nodeA.dialFSM(nodeB.peerInfo, (err, connFSM) => {
expect(err).to.not.exist()
connFSM.once('muxed', () => {
expect(nodeA._switch.muxedConns).to.have.any.keys(
nodeB.peerInfo.id.toB58String()
)
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()
])
done()
})
connFSM.close()
})
})
})
it('.dialFSM with a protocol, do an echo and close', (done) => {
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()
])
tryEcho(conn, () => {
connFSM.close()
})
})
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()
])
done()
})
})
})
})
describe('TCP + WebSockets', () => {