From 5aa74ee25d47f79f9c90a6cb7a1f3fb7ce55e2d0 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 18 May 2016 22:54:22 +0100 Subject: [PATCH] plaintext proto to be compatible with go-ipfs --- src/dial.js | 14 +++++++++++++- src/index.js | 6 ++++++ test/08-swarm-without-muxing.node.js | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/dial.js b/src/dial.js index 31d73d8df5..9bc3df2ccd 100644 --- a/src/dial.js +++ b/src/dial.js @@ -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) + }) + } }) } } diff --git a/src/index.js b/src/index.js index c8886073c8..f1aa5069e7 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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] diff --git a/test/08-swarm-without-muxing.node.js b/test/08-swarm-without-muxing.node.js index 0fc1b5708e..525ccd5d94 100644 --- a/test/08-swarm-without-muxing.node.js +++ b/test/08-swarm-without-muxing.node.js @@ -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() })