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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Sep 17, 2015
1 parent 4a571f1 commit 97f3bf5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
38 changes: 19 additions & 19 deletions README.md
@@ -1,15 +1,15 @@
abstract-connection
abstract-transport
===================

[![](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 a dial+listen interface
> A test suite and interface you can use to implement a transport. A transport is understood as something that offers a dial+listen interface
The primary goal of this module is to enable developers to pick and swap their Record Store module as they see fit for their libp2p installation, without having to go through shims or compatibility issues. This module and test suite were heavily inspired by abstract-blob-store and abstract-stream-muxer.

Publishing a test suite as a module lets multiple modules all ensure compatibility since they use the same test suite.

The purpose of this abstraction is not to reinvent any wheels when it comes to dialing and listening to connections, instead, it tries to uniform several transports through a shimmed interface.
The purpose of this abstraction is not to reinvent any wheels when it comes to dialing and listening to transports, instead, it tries to uniform several transports through a shimmed interface.

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.

Expand All @@ -21,22 +21,22 @@ note: for any new given implementation that adds one more option to the multiadd

# Badge

Include this badge in your readme if you make a module that is compatible with the abstract-connection API. You can validate this by running the tests.
Include this badge in your readme if you make a module that is compatible with the abstract-transport API. You can validate this by running the tests.

![](https://raw.githubusercontent.com/diasdavid/abstract-connection/master/img/badge.png)
![](https://raw.githubusercontent.com/diasdavid/abstract-transport/master/img/badge.png)

# How to use the battery of tests

## Node.js

```
var tape = require('tape')
var tests = require('abstract-connection/tests')
var YourConnectionHandler = require('../src')
var tests = require('abstract-transport/tests')
var YourTransportHandler = require('../src')
var common = {
setup: function (t, cb) {
cb(null, YourConnectionHandler)
cb(null, YourTransportHandler)
},
teardown: function (t, cb) {
cb()
Expand All @@ -52,41 +52,41 @@ tests(tape, common)
# API

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

### Dialing to another Peer

- `Node.js` var stream = conn.dial(multiaddr, [options])
- `Node.js` var stream = transport.dial(multiaddr, [options])

This method dials a connection to the Peer referenced by the peerInfo object.
This method dials a transport to the Peer referenced by the peerInfo object.

multiaddr must be of the type [`multiaddr`](http://npmjs.org/multiaddr).

`stream` must implements the [abstract-transport](https://github.com/diasdavid/abstract-transport) interface.
`stream` must implements the [abstract-connection](https://github.com/diasdavid/abstract-connection) interface.

`[options]` are not mandatory fields for all the implementations that might be passed for certain implementations for them to work (e.g. a Signalling Server for a WebRTC transport/connection implementation)
`[options]` are not mandatory fields for all the implementations that might be passed for certain implementations for them to work (e.g. a Signalling Server for a WebRTC transport implementation)

### Listening for incoming connections from other Peers
### Listening for incoming transports from other Peers

- `Node.js` var listener = conn.createListener(options, function (stream) {})
- `Node.js` var listener = transport.createListener(options, function (stream) {})

This method waits and listens for incoming connections by other peers.
This method waits and listens for incoming transports by other peers.

`stream` must be a stream that implements the [abstract-transport](https://github.com/diasdavid/abstract-transport) interface.
`stream` must be a stream that implements the [abstract-connection](https://github.com/diasdavid/abstract-connection) interface.

Options are the properties this listener must have access in order to properly listen on a given transport/socket

### Start listening

- `Node.js` listener.listen(options, [callback])

This method opens the listener to start listening for incoming connections
This method opens the listener to start listening for incoming transports

### Close an active listener

- `Node.js` listener.close([callback])

This method closes the listener so that no more connections can be open
This method closes the listener so that no more connections can be open on this transport instance

`callback` is function that gets called when the listener is closed. It is optional

Binary file modified img/badge.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/badge.sketch
Binary file not shown.
8 changes: 4 additions & 4 deletions img/badge.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions package.json
@@ -1,20 +1,20 @@
{
"name": "abstract-connection",
"version": "0.1.0",
"description": "A test suite and interface you can use to implement a connection.",
"name": "abstract-transport",
"version": "0.0.0",
"description": "A test suite and interface you can use to implement a transport.",
"repository": {
"type": "git",
"url": "https://github.com/diasdavid/abstract-connection.git"
"url": "https://github.com/diasdavid/abstract-transport.git"
},
"keywords": [
"IPFS"
],
"author": "David Dias <daviddias@ipfs.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/diasdavid/abstract-connection/issues"
"url": "https://github.com/diasdavid/abstract-transport/issues"
},
"homepage": "https://github.com/diasdavid/abstract-connection",
"homepage": "https://github.com/diasdavid/abstract-transport",
"devDependencies": {},
"dependencies": {
"multiaddr": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/base-test.js
Expand Up @@ -2,13 +2,13 @@ var multiaddr = require('multiaddr')

module.exports.all = function (test, common) {
test('a test', function (t) {
common.setup(test, function (err, conn) {
common.setup(test, function (err, transport) {
t.plan(5)
t.ifError(err)

var maddr = multiaddr('/ip4/127.0.0.1/tcp/9050')

var listener = conn.createListener(function (stream) {
var listener = transport.createListener(function (stream) {
t.pass('received incoming connection')
stream.end()
listener.close(function () {
Expand All @@ -19,7 +19,7 @@ module.exports.all = function (test, common) {

listener.listen(maddr.nodeAddress().port, function () {
t.pass('started listening')
var stream = conn.dial(maddr, {
var stream = transport.dial(maddr, {
ready: function () {
t.pass('dialed successfuly')
stream.end()
Expand Down

0 comments on commit 97f3bf5

Please sign in to comment.