Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
feat(connection): move to pull-streams
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Aug 10, 2016
1 parent 13ba515 commit 9037566
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ A valid (read: that follows this abstraction) connection, must implement the fol
- `conn.getObservedAddrs(callback)`
- `conn.getPeerInfo(callback)`
- `conn.setPeerInfo(peerInfo)`
- `conn.destroy`
- `conn.write`
- `conn.read`
- `conn.pipe`
- `conn.end`
- `conn.pause`
- `conn.resume`
- `conn.destroy`
- `...`

### Get the Observed Addresses of the peer in the other end
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -30,14 +30,14 @@
},
"homepage": "https://github.com/diasdavid/interface-connection",
"dependencies": {
"duplexify": "diasdavid/duplexify#a22bcdf",
"pull-defer": "^0.2.2",
"timed-tape": "^0.1.0"
},
"devDependencies": {
"aegir": "^4.0.0"
"aegir": "^6.0.1"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
"Pau Ramon Revilla <masylum@gmail.com>"
]
}
}
39 changes: 25 additions & 14 deletions src/connection.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
'use strict'

const defer = require('pull-defer/duplex')

module.exports = class Connection {
constructor (conn) {
constructor (conn, info) {
this.peerInfo = null
this.conn = conn
this.conn = defer()

if (conn) {
this.setInnerConn(conn, info)
}
}

get source () {
return this.conn && this.conn.source
return this.conn.source
}

get sink () {
return this.conn && this.conn.sink
return this.conn.sink
}

getPeerInfo (callback) {
if (this.conn && this.conn.getPeerInfo) {
return this.conn.getPeerInfo(callback)
if (this.info && this.info.getPeerInfo) {
return this.info.getPeerInfo(callback)
}

if (!this.peerInfo) {
Expand All @@ -26,22 +32,27 @@ module.exports = class Connection {
callback(null, this.peerInfo)
}

setPeerInfo (_peerInfo) {
if (this.conn && this.conn.setPeerInfo) {
return this.conn.setPeerInfo(_peerInfo)
setPeerInfo (peerInfo) {
if (this.info && this.info.setPeerInfo) {
return this.info.setPeerInfo(peerInfo)
}

this.peerInfo = _peerInfo
this.peerInfo = peerInfo
}

getObservedAddrs (callback) {
if (this.conn && this.conn.getObservedAddrs) {
return this.conn.getObservedAddrs(callback)
if (this.info && this.info.getObservedAddrs) {
return this.info.getObservedAddrs(callback)
}
callback(null, [])
}

setInnerConn (_conn) {
this.conn = _conn
setInnerConn (conn, info) {
this.conn.resolve(conn)
if (info) {
this.info = info
} else {
this.info = conn
}
}
}

0 comments on commit 9037566

Please sign in to comment.