This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connection): migrate to pull-streams
- Loading branch information
1 parent
d4d6d55
commit ed5727a
Showing
7 changed files
with
44 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "interface-connection", | ||
"version": "0.1.8", | ||
"description": "A test suite and interface you can use to implement a connection interface.", | ||
"main": "lib/index.js", | ||
"main": "src/index.js", | ||
"jsnext:main": "src/index.js", | ||
"scripts": { | ||
"lint": "aegir-lint", | ||
|
@@ -30,8 +30,8 @@ | |
}, | ||
"homepage": "https://github.com/diasdavid/interface-connection", | ||
"dependencies": { | ||
"duplexify": "diasdavid/duplexify#a22bcdf", | ||
"timed-tape": "^0.1.1" | ||
"pull-defer": "^0.2.2", | ||
}, | ||
"devDependencies": { | ||
"aegir": "^6.0.1" | ||
|
@@ -40,4 +40,4 @@ | |
"David Dias <[email protected]>", | ||
"Pau Ramon Revilla <[email protected]>" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} 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) { | ||
this.conn.resolve(conn) | ||
if (info) { | ||
this.info = info | ||
} else { | ||
this.info = conn | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
This file was deleted.
Oops, something went wrong.