Skip to content

Commit

Permalink
Merge pull request libp2p#60 from diasdavid/feat/crypto-not-crypto
Browse files Browse the repository at this point in the history
plaintext proto to be compatible with go-ipfs
  • Loading branch information
daviddias committed May 18, 2016
2 parents d991c47 + 5aa74ee commit 510b458
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/dial.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@ module.exports = function dial (swarm) {
}
return nextTransport(tKeys.shift())
}
cb(null, conn)

cryptoDial()

function cryptoDial () {
// currently, js-libp2p-swarm doesn't implement any crypto
const ms = new multistream.Dialer()
ms.handle(conn, (err) => {
if (err) {
return cb(err)
}
ms.select('/plaintext/1.0.0', cb)
})
}
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const contains = require('lodash.contains')
const transport = require('./transport')
const connection = require('./connection')
const dial = require('./dial')
const connHandler = require('./default-handler')

exports = module.exports = Swarm

Expand Down Expand Up @@ -86,6 +87,11 @@ function Swarm (peerInfo) {
this.protocols[protocol] = handler
}

// our crypto handshake :)
this.handle('/plaintext/1.0.0', (conn) => {
connHandler(this.protocols, conn)
})

this.unhandle = (protocol, handler) => {
if (this.protocols[protocol]) {
delete this.protocols[protocol]
Expand Down
2 changes: 1 addition & 1 deletion test/08-swarm-without-muxing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
swarmB.handle('/bananas/1.0.0', (conn) => {
conn.pipe(conn)
})
expect(Object.keys(swarmB.protocols).length).to.equal(1)
expect(Object.keys(swarmB.protocols).length).to.equal(2)
done()
})

Expand Down

0 comments on commit 510b458

Please sign in to comment.