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

add required methods by the consumers of the conn obj, to the conn interface #4

Merged
merged 1 commit into from
Jun 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
29 changes: 29 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

test
61 changes: 54 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
interface-connection
==================

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)

> A test suite and interface you can use to implement a connection. A connection is understood as something that offers mechanism for writing and reading data, back pressure, half and full duplex streams. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer.

Expand All @@ -11,12 +12,16 @@ Publishing a test suite as a module lets multiple modules all ensure compatibili

The API is presented with both Node.js and Go primitives, however, there is not actual limitations for it to be extended for any other language, pushing forward the cross compatibility and interop through diferent stacks.

> **IMPORTANT** - Tests are still not finished nor the interface


# Modules that implement the interface

- [node-libp2p-tcp](https://github.com/diasdavid/node-libp2p-tcp)
- [js-libp2p-tcp](https://github.com/diasdavid/node-libp2p-tcp)
- [js-libp2p-webrtc-star](https://github.com/diasdavid/js-libp2p-webrtc-star)
- [js-libp2p-websockets](https://github.com/diasdavid/js-libp2p-websockets)
- [js-libp2p-utp](https://github.com/diasdavid/js-libp2p-utp)
- [webrtc-explorer](https://github.com/diasdavid/webrtc-explorer)
- [js-libp2p-spdy](https://github.com/diasdavid/js-libp2p-spdy)
- [js-libp2p-multiplex](https://github.com/diasdavid/js-libp2p-multiplex)
- [js-libp2p-secio](https://github.com/ipfs/js-libp2p-secio)

# Badge

Expand Down Expand Up @@ -53,9 +58,51 @@ tests(tape, common)

A valid (read: that follows this abstraction) connection, must implement the following API.

notes:
**Table of contents:**

- type: `Connection`
- `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

- `JavaScript` - `conn.getObservedAddrs(callback)`

This method retrieves the observed addresses we get from the underlying transport, if any.

`callback` should follow the follow `function (err, multiaddrs) {}`, where `multiaddrs` is an array of [multiaddr](https://github.com/jbenet/multiaddr).

### Get the PeerInfo

- `JavaScript` - `conn.getPeerInfo(callback)`

This method retrieves the a Peer Info object that contains information about the peer that this conn connects to.

`callback` should follow the `function (err, peerInfo) {}` signature, where peerInfo is a object of type [Peer Info](https://github.com/diasdavid/js-peer-info)

### Set the PeerInfo

- `JavaScript` - `conn.setPeerInfo(peerInfo)`
j
This method stores a reference to the peerInfo Object that contains information about the peer that this conn connects to.

`peerInfo` is a object of type [Peer Info](https://github.com/diasdavid/js-peer-info)

---

notes:
- should follow the remaining Duplex stream operations
- should have backpressure into account
- should enable half duplex streams (close from one side, but still open for the other)
- should support full duplex
- tests should be performed by passing two streams

18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
"name": "interface-connection",
"version": "0.0.3",
"description": "A test suite and interface you can use to implement a connection interface.",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"lint": "aegir-lint",
"build": "aegir-build",
"test": "exit 0",
"release": "aegir-release",
"release-minor": "aegir-release --type minor",
"release-major": "aegir-release --type major"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "https://github.com/diasdavid/interface-connection.git"
Expand All @@ -16,6 +30,10 @@
},
"homepage": "https://github.com/diasdavid/interface-connection",
"dependencies": {
"duplexify": "^3.4.3",
"timed-tape": "^0.1.0"
},
"devDependencies": {
"aegir": "^3.2.0"
}
}
53 changes: 53 additions & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict'

const util = require('util')
const Duplexify = require('duplexify')

module.exports = Connection

util.inherits(Connection, Duplexify)

function Connection (conn) {
if (!(this instanceof Connection)) {
return new Connection(conn)
}

Duplexify.call(this)

let peerInfo

this.getPeerInfo = (callback) => {
if (conn.getPeerInfo) {
return conn.getPeerInfo(callback)
}

if (!peerInfo) {
return callback(new Error('Peer Info not set yet'))
}

callback(null, peerInfo)
}

this.setPeerInfo = (_peerInfo) => {
if (conn.setPeerInfo) {
return conn.setPeerInfo(_peerInfo)
}
peerInfo = _peerInfo
}

this.getObservedAddrs = (callback) => {
if (conn.getObservedAddrs) {
return conn.getObservedAddrs(callback)
}
callback(null, [])
}

this.setInnerConn = (conn) => {
this.setReadable(conn)
this.setWritable(conn)
}

if (conn) {
this.setInnerConn(conn)
}
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict'

exports.connection = require('./connection.js')
exports.Connection = require('./connection.js')
3 changes: 3 additions & 0 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

// so that aegir does not burp