-
Notifications
You must be signed in to change notification settings - Fork 10
Changes from all commits
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 |
---|---|---|
@@ -1,56 +1,60 @@ | ||
'use strict' | ||
|
||
const util = require('util') | ||
const Duplexify = require('duplexify') | ||
const defer = require('pull-defer/duplex') | ||
|
||
module.exports = Connection | ||
module.exports = class Connection { | ||
constructor (conn, info) { | ||
this.peerInfo = null | ||
this.conn = defer() | ||
|
||
util.inherits(Connection, Duplexify) | ||
|
||
function Connection (conn) { | ||
if (!(this instanceof Connection)) { | ||
return new Connection(conn) | ||
if (conn) { | ||
this.setInnerConn(conn, info) | ||
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. I understand you like 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 that's a good thing in my opinion, calling a function and creating an instance should be two different things. |
||
} else if (info) { | ||
this.info = info | ||
} | ||
} | ||
|
||
Duplexify.call(this) | ||
get source () { | ||
return this.conn.source | ||
} | ||
|
||
let peerInfo | ||
get sink () { | ||
return this.conn.sink | ||
} | ||
|
||
this.getPeerInfo = (callback) => { | ||
if (conn && conn.getPeerInfo) { | ||
return conn.getPeerInfo(callback) | ||
getPeerInfo (callback) { | ||
if (this.info && this.info.getPeerInfo) { | ||
return this.info.getPeerInfo(callback) | ||
} | ||
|
||
if (!peerInfo) { | ||
if (!this.peerInfo) { | ||
return callback(new Error('Peer Info not set yet')) | ||
} | ||
|
||
callback(null, peerInfo) | ||
callback(null, this.peerInfo) | ||
} | ||
|
||
this.setPeerInfo = (_peerInfo) => { | ||
if (conn && conn.setPeerInfo) { | ||
return conn.setPeerInfo(_peerInfo) | ||
setPeerInfo (peerInfo) { | ||
if (this.info && this.info.setPeerInfo) { | ||
return this.info.setPeerInfo(peerInfo) | ||
} | ||
peerInfo = _peerInfo | ||
|
||
this.peerInfo = peerInfo | ||
} | ||
|
||
this.getObservedAddrs = (callback) => { | ||
if (conn && conn.getObservedAddrs) { | ||
return conn.getObservedAddrs(callback) | ||
getObservedAddrs (callback) { | ||
if (this.info && this.info.getObservedAddrs) { | ||
return this.info.getObservedAddrs(callback) | ||
} | ||
callback(null, []) | ||
} | ||
|
||
this.setInnerConn = (_conn) => { | ||
conn = _conn | ||
this.setReadable(conn) | ||
this.setWritable(conn) | ||
} | ||
|
||
// .destroy is implemented by Duplexify | ||
|
||
if (conn) { | ||
this.setInnerConn(conn) | ||
setInnerConn (conn, info) { | ||
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 do we need to pass info as an argument? It should be able to get it through 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.
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. You mean things like: https://github.com/multiformats/js-multistream/pull/19/files#diff-0ef79b038534cac22e85e5b18ba0e546R49, this is because that Kind of sad that we loose that clean abstraction. I would rather patch them (similar to the way we do it in stream muxing)
`` 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. It's really not possible to fix as far as I understand. 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. Roger, what I mean is that I would love that conn.setInnerConn still only accepts one argument, and then if we have to do stiching, we do it after. Because it seems to be something specific to Multistream 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. That's why it handles only one argument as well, so that in most cases you can just pass in the single one, and if you need to you can pass both. |
||
this.conn.resolve(conn) | ||
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. what is this 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.
|
||
if (info) { | ||
this.info = info | ||
} else { | ||
this.info = conn | ||
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. setting the 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. see above 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. Either way, calling it 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.
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. infoConn (or baseConn) and a good comment in that function explaining why it exists, for now :) |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
'use strict' | ||
|
||
exports.connection = require('./connection.js') | ||
exports.Connection = require('./connection.js') | ||
exports.Connection = require('./connection') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict' | ||
|
||
var timed = require('timed-tape') | ||
|
||
module.exports = function (test, common) { | ||
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. I was just thinking that our way to test connections can be a common that returns 'conn pairs' that are connected, so that every data flowing can be tested + we can do the wrapping tests. It would be a great addition. 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. Not sure I understand 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. Similar to https://github.com/ipfs/interface-ipfs-core/blob/master/src/generic.js#L18-L30, where instead of returning an instance, it returns a thing that create instances, in this case, it expects to return 2 Connection instances that are connected (like pull-pair) so that tests can be run on top of them. 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. Makes sense, once there are actual tests in here :D 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. Then we can repurpose a bunch of libp2p-tcp tests to there :) |
||
|
This file was deleted.
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.