-
Notifications
You must be signed in to change notification settings - Fork 37
[WIP] Add secio & move to pull-streams #67
Changes from 3 commits
d1e337e
5ab7db2
56e558e
ea9c93c
784934d
381d3c2
c28b845
42fafd8
6091e94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,12 @@ | |
|
||
const multistream = require('multistream-select') | ||
const Connection = require('interface-connection').Connection | ||
const debug = require('debug') | ||
const log = debug('libp2p:swarm:dial') | ||
|
||
const protocolMuxer = require('./protocol-muxer') | ||
const secio = require('./secio') | ||
const tags = require('./tags') | ||
|
||
module.exports = function dial (swarm) { | ||
return (pi, protocol, callback) => { | ||
|
@@ -19,6 +23,7 @@ module.exports = function dial (swarm) { | |
const proxyConn = new Connection() | ||
|
||
const b58Id = pi.id.toB58String() | ||
log('dialing %s', b58Id) | ||
|
||
if (!swarm.muxedConns[b58Id]) { | ||
if (!swarm.conns[b58Id]) { | ||
|
@@ -44,7 +49,6 @@ module.exports = function dial (swarm) { | |
|
||
function gotWarmedUpConn (conn) { | ||
conn.setPeerInfo(pi) | ||
|
||
attemptMuxerUpgrade(conn, (err, muxer) => { | ||
if (!protocol) { | ||
if (err) { | ||
|
@@ -97,13 +101,24 @@ module.exports = function dial (swarm) { | |
cryptoDial() | ||
|
||
function cryptoDial () { | ||
// currently, no crypto channel is implemented | ||
const ms = new multistream.Dialer() | ||
ms.handle(conn, (err) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
ms.select('/plaintext/1.0.0', cb) | ||
|
||
const id = swarm._peerInfo.id | ||
if (id.privKey == null || swarm.encrypt === false) { | ||
return ms.select(tags.plaintex, cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this typo is what was causing my issue in libp2p-ipfs |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a Swarm option. In the same fashion that we do .connection.reuse(), we should do .connection.crypto(secio) and then check if it has the ingredients necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also, .connection.plaintext(false) to disable plaintext mode There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should this be a method? It's just a matter of setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so that later we can use the method to pick different crypto channels |
||
|
||
ms.select(tags.secio, (err, conn) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
cb(null, secio.create(id, conn)) | ||
}) | ||
}) | ||
} | ||
}) | ||
|
@@ -129,6 +144,7 @@ module.exports = function dial (swarm) { | |
if (err) { | ||
return callback(new Error('multistream not supported')) | ||
} | ||
log('selecting %s', key) | ||
ms.select(key, (err, conn) => { | ||
if (err) { | ||
if (muxers.length === 0) { | ||
|
@@ -139,7 +155,7 @@ module.exports = function dial (swarm) { | |
return | ||
} | ||
|
||
const muxedConn = swarm.muxers[key](conn, false) | ||
const muxedConn = swarm.muxers[key].dial(conn) | ||
swarm.muxedConns[b58Id] = {} | ||
swarm.muxedConns[b58Id].muxer = muxedConn | ||
// should not be needed anymore - swarm.muxedConns[b58Id].conn = conn | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
const SecureSession = require('libp2p-secio').SecureSession | ||
|
||
exports = module.exports | ||
|
||
exports.create = (local, insecure) => { | ||
const session = new SecureSession(local, local.privKey, insecure) | ||
return session.secure | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
secio: '/secio/1.0.0', | ||
plaintext: '/plaintext/1.0.0' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: This will change to 'dialer', once identify CR is applied