Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 510b458

Browse files
committed
Merge pull request #60 from diasdavid/feat/crypto-not-crypto
plaintext proto to be compatible with go-ipfs
2 parents d991c47 + 5aa74ee commit 510b458

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/dial.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,19 @@ module.exports = function dial (swarm) {
8484
}
8585
return nextTransport(tKeys.shift())
8686
}
87-
cb(null, conn)
87+
88+
cryptoDial()
89+
90+
function cryptoDial () {
91+
// currently, js-libp2p-swarm doesn't implement any crypto
92+
const ms = new multistream.Dialer()
93+
ms.handle(conn, (err) => {
94+
if (err) {
95+
return cb(err)
96+
}
97+
ms.select('/plaintext/1.0.0', cb)
98+
})
99+
}
88100
})
89101
}
90102
}

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const contains = require('lodash.contains')
88
const transport = require('./transport')
99
const connection = require('./connection')
1010
const dial = require('./dial')
11+
const connHandler = require('./default-handler')
1112

1213
exports = module.exports = Swarm
1314

@@ -86,6 +87,11 @@ function Swarm (peerInfo) {
8687
this.protocols[protocol] = handler
8788
}
8889

90+
// our crypto handshake :)
91+
this.handle('/plaintext/1.0.0', (conn) => {
92+
connHandler(this.protocols, conn)
93+
})
94+
8995
this.unhandle = (protocol, handler) => {
9096
if (this.protocols[protocol]) {
9197
delete this.protocols[protocol]

test/08-swarm-without-muxing.node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('high level API - 1st without stream multiplexing (on TCP)', function (
4747
swarmB.handle('/bananas/1.0.0', (conn) => {
4848
conn.pipe(conn)
4949
})
50-
expect(Object.keys(swarmB.protocols).length).to.equal(1)
50+
expect(Object.keys(swarmB.protocols).length).to.equal(2)
5151
done()
5252
})
5353

0 commit comments

Comments
 (0)