diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..229031f --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# 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 + +dist +package-lock.json diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..00a160d --- /dev/null +++ b/.npmignore @@ -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 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c7f74c1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,40 @@ +language: node_js +cache: npm +stages: + - check + - test + - cov + +node_js: + - '10' + - '12' + +os: + - linux + - osx + - windows + +script: npx nyc -s npm run test:node -- --bail +after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov + +jobs: + include: + - stage: check + script: + - npx aegir dep-check + - npm run lint + + - stage: test + name: chrome + addons: + chrome: stable + script: npx aegir test -t browser -t webworker + + - stage: test + name: firefox + addons: + firefox: latest + script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless + +notifications: + email: false diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..53e87fa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,115 @@ + +## [0.4.1](https://github.com/libp2p/interface-connection/compare/v0.4.0...v0.4.1) (2019-10-17) + + +### Features + +* add support for timeline proxying ([#31](https://github.com/libp2p/interface-connection/issues/31)) ([541bf83](https://github.com/libp2p/interface-connection/commit/541bf83)) + + + + +# [0.4.0](https://github.com/libp2p/interface-connection/compare/v0.3.3...v0.4.0) (2019-09-27) + + +### Code Refactoring + +* API changes and switch to async iterators ([#29](https://github.com/libp2p/interface-connection/issues/29)) ([bf5c646](https://github.com/libp2p/interface-connection/commit/bf5c646)) + + +### BREAKING CHANGES + +* all the callbacks in the provided API were removed and each function uses async/await. Additionally, pull-streams are no longer being used. See the README for new usage. + + + + +## [0.3.3](https://github.com/libp2p/interface-connection/compare/v0.3.1...v0.3.3) (2018-11-29) + + + + +## [0.3.1](https://github.com/libp2p/interface-connection/compare/v0.3.0...v0.3.1) (2017-02-09) + + + + +# [0.3.0](https://github.com/libp2p/interface-connection/compare/v0.2.1...v0.3.0) (2016-11-03) + + +### Features + +* async crypto + sauce labs + aegir 9 ([b40114c](https://github.com/libp2p/interface-connection/commit/b40114c)) + + + + +## [0.2.1](https://github.com/libp2p/interface-connection/compare/v0.2.0...v0.2.1) (2016-09-05) + + +### Bug Fixes + +* **package.json:** point to right main ([84cd2ca](https://github.com/libp2p/interface-connection/commit/84cd2ca)) + + + + +# [0.2.0](https://github.com/libp2p/interface-connection/compare/v0.1.8...v0.2.0) (2016-09-05) + + +### Bug Fixes + +* **deps:** fix package.json ([e0f7db3](https://github.com/libp2p/interface-connection/commit/e0f7db3)) + + +### Features + +* **connection:** migrate to pull-streams ([ed5727a](https://github.com/libp2p/interface-connection/commit/ed5727a)) + + + + +## [0.1.8](https://github.com/libp2p/interface-connection/compare/v0.1.7...v0.1.8) (2016-08-03) + + + + +## [0.1.7](https://github.com/libp2p/interface-connection/compare/v0.1.6...v0.1.7) (2016-06-27) + + + + +## [0.1.6](https://github.com/libp2p/interface-connection/compare/v0.1.5...v0.1.6) (2016-06-23) + + + + +## [0.1.5](https://github.com/libp2p/interface-connection/compare/v0.1.4...v0.1.5) (2016-06-23) + + + + +## [0.1.4](https://github.com/libp2p/interface-connection/compare/v0.1.3...v0.1.4) (2016-06-23) + + + + +## [0.1.3](https://github.com/libp2p/interface-connection/compare/v0.1.0...v0.1.3) (2016-06-16) + + + + +# [0.1.0](https://github.com/libp2p/interface-connection/compare/v0.0.3...v0.1.0) (2016-06-16) + + + + +## [0.0.3](https://github.com/libp2p/interface-connection/compare/v0.0.1...v0.0.3) (2015-12-12) + + + + +## 0.0.1 (2015-09-17) + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..59a33ba --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 David Dias + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6b8246 --- /dev/null +++ b/README.md @@ -0,0 +1,262 @@ +interface-connection +================== + +[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai) +[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) +[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p) +[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io) +[![](https://img.shields.io/codecov/c/github/libp2p/interface-connection.svg?style=flat-square)](https://codecov.io/gh/libp2p/interface-connection) +[![](https://img.shields.io/travis/libp2p/interface-connection.svg?style=flat-square)](https://travis-ci.com/libp2p/interface-connection) +[![Dependency Status](https://david-dm.org/libp2p/interface-connection.svg?style=flat-square)](https://david-dm.org/libp2p/interface-connection) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) + +This is a test suite and interface you can use to implement a connection. The connection interface contains all the metadata associated with it, as well as an array of the streams opened through this connection. In the same way as the connection, a stream contains properties with its metadata, plus an iterable duplex object that offers a mechanism for writing and reading data, with back pressure. This module and test suite were heavily inspired by abstract-blob-store and interface-stream-muxer. + +The primary goal of this module is to enable developers to pick, swap or upgrade their connection without losing the same API expectations and mechanisms such as back pressure and the ability to half close a connection. + +Publishing a test suite as a module lets multiple modules ensure compatibility since they use the same test suite. + +## Lead Maintainer + +[Jacob Heun](https://github.com/jacobheun/) + +## Usage + +### Connection + +Before creating a connection from a transport compatible with `libp2p` it is important to understand some concepts: + +- **socket**: the underlying raw duplex connection between two nodes. It is created by the transports during a dial/listen. +- **[multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection)**: an abstraction over the socket to allow it to work with multiaddr addresses. It is a duplex connection that transports create to wrap the socket before passing to an upgrader that turns it into a standard connection (see below). +- **connection**: a connection between two _peers_ that has built in multiplexing and info about the connected peer. It is created from a [multiaddr connection](https://github.com/libp2p/interface-transport#multiaddrconnection) by an upgrader. The upgrader uses multistream-select to add secio and multiplexing and returns this object. +- **stream**: a muxed duplex channel of the `connection`. Each connection may have many streams. + +A connection stands for the libp2p communication duplex layer between two nodes. It is **not** the underlying raw transport duplex layer (socket), such as a TCP socket, but an abstracted layer that sits on top of the raw socket. + +This helps ensuring that the transport is responsible for socket management, while also allowing the application layer to handle the connection management. + +### Test suite + +#### JS + +```js +describe('your connection', () => { + require('interface-connection/src/tests')({ + async setup () { + return YourConnection + }, + async teardown () { + // cleanup resources created by setup() + } + }) +}) +``` + +#### Go + +> WIP + +## API + +### Connection + +A valid connection (one that follows this abstraction), must implement the following API: + +- type: `Connection` +```js +new Connection({ + localAddr, + remoteAddr, + localPeer, + remotePeer, + newStream, + close, + getStreams, + stat: { + direction, + timeline: { + open, + upgraded + }, + multiplexer, + encryption + } +}) +``` + - ` conn.localAddr` + - ` conn.remoteAddr` + - ` conn.localPeer` + - ` conn.remotePeer` + - ` conn.stat` + - ` conn.registry` + - `Array conn.streams` + - `Promise conn.newStream(Array)` + - ` conn.removeStream(id)` + - ` conn.addStream(stream, protocol, metadata)` + - `Promise<> conn.close()` + +It can be obtained as follows: + +```js +const { Connection } = require('interface-connection') + +const conn = new Connection({ + localAddr: maConn.localAddr, + remoteAddr: maConn.remoteAddr, + localPeer: this._peerId, + remotePeer, + newStream, + close: err => maConn.close(err), + getStreams, + stats: { + direction: 'outbound', + timeline: { + open: maConn.timeline.open, + upgraded: Date.now() + }, + multiplexer, + encryption + } +}) +``` + +#### Creating a connection instance + +- `JavaScript` - `const conn = new Connection({localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, direction, multiplexer, encryption})` + +Creates a new Connection instance. + +`localAddr` is the [multiaddr](https://github.com/multiformats/multiaddr) address used by the local peer to reach the remote. +`remoteAddr` is the [multiaddr](https://github.com/multiformats/multiaddr) address used to communicate with the remote peer. +`localPeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the local peer. +`remotePeer` is the [PeerId](https://github.com/libp2p/js-peer-id) of the remote peer. +`newStream` is the `function` responsible for getting a new muxed+multistream-selected stream. +`close` is the `function` responsible for closing the raw connection. +`getStreams` is the `function` responsible for getting the streams muxed within the connection. +`stats` is an `object` with the metadata of the connection. It contains: +- `direction` is a `string` indicating whether the connection is `inbound` or `outbound`. +- `timeline` is an `object` with the relevant events timestamps of the connection (`open`, `upgraded` and `closed`; the `closed` will be added when the connection is closed). +- `multiplexer` is a `string` with the connection multiplexing codec (optional). +- `encryption` is a `string` with the connection encryption method identifier (optional). + +#### Create a new stream + +- `JavaScript` - `conn.newStream(protocols)` + +Create a new stream within the connection. + +`protocols` is an array of the intended protocol to use (by order of preference). Example: `[/echo/1.0.0]` + +It returns a `Promise` with an object with the following properties: + +```js +{ + stream, + protocol +} +``` + +The stream property contains the muxed stream, while the protocol contains the protocol codec used by the stream. + +#### Add stream metadata + +- `JavaScript` - `conn.addStream(stream, { protocol, ...metadata })` + +Add a new stream to the connection registry. + +`stream` is a muxed stream. +`protocol` is the string codec for the protocol used by the stream. Example: `/echo/1.0.0` +`metadata` is an object containing any additional, optional, stream metadata that you wish to track (such as its `tags`). + +#### Remove a from the registry + +- `JavaScript` - `conn.removeStream(id)` + +Removes the stream with the given id from the connection registry. + +`id` is the unique id of the stream for this connection. + + +#### Close connection + +- `JavaScript` - `conn.close()` + +This method closes the connection to the remote peer, as well as all the streams muxed within the connection. + +It returns a `Promise`. + +#### Connection identifier + +- `JavaScript` - `conn.id` + +This property contains the identifier of the connection. + +#### Connection streams registry + +- `JavaScript` - `conn.registry` + +This property contains a map with the muxed streams indexed by their id. This registry contains the protocol used by the stream, as well as its metadata. + +#### Remote peer + +- `JavaScript` - `conn.remotePeer` + +This property contains the remote `peer-id` of this connection. + +#### Local peer + +- `JavaScript` - `conn.localPeer` + +This property contains the local `peer-id` of this connection. + +#### Get the connection Streams + +- `JavaScript` - `conn.streams` + +This getter returns all the muxed streams within the connection. + +It returns an `Array`. + +#### Remote address + +- `JavaScript` - `conn.remoteAddr` + +This getter returns the `remote` [multiaddr](https://github.com/multiformats/multiaddr) address. + +#### Local address + +- `JavaScript` - `conn.localAddr` + +This getter returns the `local` [multiaddr](https://github.com/multiformats/multiaddr) address. + +#### Stat + +- `JavaScript` - `conn.stat` + +This getter returns an `Object` with the metadata of the connection, as follows: + +- `status`: + +This property contains the status of the connection. It can be either `open`, `closing` or `closed`. Once the connection is created it is in an `open` status. When a `conn.close()` happens, the status will change to `closing` and finally, after all the connection streams are properly closed, the status will be `closed`. + +- `timeline`: + +This property contains an object with the `open`, `upgraded` and `close` timestamps of the connection. Note that, the `close` timestamp is `undefined` until the connection is closed. + +- `direction`: + +This property contains the direction of the peer in the connection. It can be `inbound` or `outbound`. + +- `multiplexer`: + +This property contains the `multiplexing` codec being used in the connection. + +- `encryption`: + +This property contains the encryption method being used in the connection. It is `undefined` if the connection is not encrypted. + +#### Tags + +- `JavaScript` - `conn.tags` + +This property contains an array of tags associated with the connection. New tags can be pushed to this array during the connection's lifetime. diff --git a/img/badge.png b/img/badge.png new file mode 100644 index 0000000..a79ca44 Binary files /dev/null and b/img/badge.png differ diff --git a/img/badge.sketch b/img/badge.sketch new file mode 100644 index 0000000..a4c4a43 Binary files /dev/null and b/img/badge.sketch differ diff --git a/img/badge.svg b/img/badge.svg new file mode 100644 index 0000000..a240ced --- /dev/null +++ b/img/badge.svg @@ -0,0 +1,19 @@ + + + + badge + Created with Sketch. + + + + + + Connectio + n + + + Compatibl + e + + + \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..def4ae6 --- /dev/null +++ b/package.json @@ -0,0 +1,66 @@ +{ + "name": "interface-connection", + "version": "0.4.1", + "description": "A test suite and interface you can use to implement a connection interface.", + "leadMaintainer": "Jacob Heun ", + "main": "src/index.js", + "files": [ + "dist", + "src" + ], + "scripts": { + "lint": "aegir lint", + "build": "aegir build", + "test": "aegir test", + "test:node": "aegir test -t node", + "test:browser": "aegir test -t browser -t webworker", + "release": "aegir release", + "release-minor": "aegir release --type minor", + "release-major": "aegir release --type major" + }, + "pre-push": [ + "lint" + ], + "repository": { + "type": "git", + "url": "https://github.com/libp2p/interface-connection.git" + }, + "keywords": [ + "IPFS" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/libp2p/interface-connection/issues" + }, + "homepage": "https://github.com/libp2p/interface-connection", + "dependencies": { + "abortable-iterator": "^2.1.0", + "chai": "^4.2.0", + "class-is": "^1.1.0", + "dirty-chai": "^2.0.1", + "err-code": "^2.0.0", + "multiaddr": "^7.1.0", + "peer-id": "~0.13.2", + "sinon": "^7.5.0" + }, + "devDependencies": { + "aegir": "^20.2.0", + "it-pair": "^1.0.0", + "it-pipe": "^1.0.1", + "mocha": "^6.2.0" + }, + "engines": { + "node": ">=10.0.0", + "npm": ">=6.0.0" + }, + "contributors": [ + "David Dias ", + "Friedel Ziegelmayer ", + "Greenkeeper ", + "Jacob Heun ", + "James Ray <16969914+jamesray1@users.noreply.github.com>", + "Pau Ramon Revilla ", + "Richard Littauer ", + "Vasco Santos " + ] +} diff --git a/src/connection.js b/src/connection.js new file mode 100644 index 0000000..71ba299 --- /dev/null +++ b/src/connection.js @@ -0,0 +1,196 @@ +'use strict' + +const PeerId = require('peer-id') +const multiaddr = require('multiaddr') + +const withIs = require('class-is') + +const assert = require('assert') +const errCode = require('err-code') + +/** + * An implementation of the js-libp2p connection. + * Any libp2p transport should use an upgrader to return this connection. + */ +class Connection { + /** + * Creates an instance of Connection. + * @param {object} properties properties of the connection. + * @param {multiaddr} properties.localAddr local multiaddr of the connection. + * @param {multiaddr} properties.remoteAddr remote multiaddr of the connection. + * @param {PeerId} properties.localPeer local peer-id. + * @param {PeerId} properties.remotePeer remote peer-id. + * @param {function} properties.newStream new stream muxer function. + * @param {function} properties.close close raw connection function. + * @param {function} properties.getStreams get streams from muxer function. + * @param {object} properties.stat metadata of the connection. + * @param {string} properties.stat.direction connection establishment direction ("inbound" or "outbound"). + * @param {object} properties.stat.timeline connection relevant events timestamp. + * @param {string} properties.stat.timeline.open connection opening timestamp. + * @param {string} properties.stat.timeline.upgraded connection upgraded timestamp. + * @param {string} [properties.stat.multiplexer] connection multiplexing identifier. + * @param {string} [properties.stat.encryption] connection encryption method identifier. + */ + constructor ({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }) { + assert(multiaddr.isMultiaddr(localAddr), 'localAddr must be an instance of multiaddr') + assert(multiaddr.isMultiaddr(remoteAddr), 'remoteAddr must be an instance of multiaddr') + assert(PeerId.isPeerId(localPeer), 'localPeer must be an instance of peer-id') + assert(PeerId.isPeerId(remotePeer), 'remotePeer must be an instance of peer-id') + assert(typeof newStream === 'function', 'new stream must be a function') + assert(typeof close === 'function', 'close must be a function') + assert(typeof getStreams === 'function', 'getStreams must be a function') + assert(stat, 'connection metadata object must be provided') + assert(stat.direction === 'inbound' || stat.direction === 'outbound', 'direction must be "inbound" or "outbound"') + assert(stat.timeline, 'connection timeline object must be provided in the stat object') + assert(stat.timeline.open, 'connection open timestamp must be provided') + assert(stat.timeline.upgraded, 'connection upgraded timestamp must be provided') + + /** + * Connection identifier. + */ + this.id = (parseInt(Math.random() * 1e9)).toString(36) + Date.now() + + /** + * Observed multiaddr of the local peer + */ + this.localAddr = localAddr + + /** + * Observed multiaddr of the remote peer + */ + this.remoteAddr = remoteAddr + + /** + * Local peer id. + */ + this.localPeer = localPeer + + /** + * Remote peer id. + */ + this.remotePeer = remotePeer + + /** + * Connection metadata. + */ + this._stat = { + ...stat, + status: 'open' + } + + /** + * Reference to the new stream function of the multiplexer + */ + this._newStream = newStream + + /** + * Reference to the close function of the raw connection + */ + this._close = close + + /** + * Reference to the getStreams function of the muxer + */ + this._getStreams = getStreams + + /** + * Connection streams registry + */ + this.registry = new Map() + + /** + * User provided tags + */ + this.tags = [] + } + + /** + * Get connection metadata + * @return {Object} + */ + get stat () { + return this._stat + } + + /** + * Get all the streams of the muxer. + * @return {Array<*>} + */ + get streams () { + return this._getStreams() + } + + /** + * Create a new stream from this connection + * @param {string[]} protocols intended protocol for the stream + * @return {Promise} with muxed+multistream-selected stream and selected protocol + */ + async newStream (protocols) { + if (this.stat.status === 'closing') { + throw errCode(new Error('the connection is being closed'), 'ERR_CONNECTION_BEING_CLOSED') + } + + if (this.stat.status === 'closed') { + throw errCode(new Error('the connection is closed'), 'ERR_CONNECTION_CLOSED') + } + + if (!Array.isArray(protocols)) protocols = [protocols] + + const { stream, protocol } = await this._newStream(protocols) + + this.addStream(stream, protocol) + + return { + stream, + protocol + } + } + + /** + * Add a stream when it is opened to the registry. + * @param {*} muxedStream a muxed stream + * @param {object} properties the stream properties to be registered + * @param {string} properties.protocol the protocol used by the stream + * @param {object} properties.metadata metadata of the stream + * @return {void} + */ + addStream (muxedStream, { protocol, metadata = {} }) { + // Add metadata for the stream + this.registry.set(muxedStream.id, { + protocol, + ...metadata + }) + } + + /** + * Remove stream registry after it is closed. + * @param {string} id identifier of the stream + */ + removeStream (id) { + this.registry.delete(id) + } + + /** + * Close the connection. + * @return {Promise} + */ + async close () { + if (this.stat.status === 'closed') { + return + } + + if (this._closing) { + return this._closing + } + + this.stat.status = 'closing' + + // Close raw connection + this._closing = await this._close() + + this._stat.timeline.close = Date.now() + this.stat.status = 'closed' + } +} + +module.exports = withIs(Connection, { className: 'Connection', symbolName: '@libp2p/interface-connection/connection' }) diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..c4c79fd --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +'use strict' + +exports.Connection = require('./connection') diff --git a/src/tests.js b/src/tests.js new file mode 100644 index 0000000..8a80dae --- /dev/null +++ b/src/tests.js @@ -0,0 +1,9 @@ +/* eslint-env mocha */ + +'use strict' + +const connectionSuite = require('../test/connection') + +module.exports = (test) => { + connectionSuite(test) +} diff --git a/test/compliance.spec.js b/test/compliance.spec.js new file mode 100644 index 0000000..decbdd2 --- /dev/null +++ b/test/compliance.spec.js @@ -0,0 +1,65 @@ +/* eslint-env mocha */ +'use strict' + +const tests = require('../src/tests') +const Connection = require('../src/connection') +const peers = require('./utils/peers') +const PeerId = require('peer-id') +const multiaddr = require('multiaddr') +const pair = require('it-pair') + +describe('compliance tests', () => { + tests({ + /** + * Test setup. `properties` allows the compliance test to override + * certain values for testing. + * @param {*} properties + */ + async setup (properties) { + const localAddr = multiaddr('/ip4/127.0.0.1/tcp/8080') + const remoteAddr = multiaddr('/ip4/127.0.0.1/tcp/8081') + const [localPeer, remotePeer] = await Promise.all([ + PeerId.createFromJSON(peers[0]), + PeerId.createFromJSON(peers[1]) + ]) + const openStreams = [] + let streamId = 0 + + return new Connection({ + localPeer, + remotePeer, + localAddr, + remoteAddr, + stat: { + timeline: { + open: Date.now() - 10, + upgraded: Date.now() + }, + direction: 'outbound', + encryption: '/secio/1.0.0', + multiplexer: '/mplex/6.7.0' + }, + newStream: (protocols) => { + const id = streamId++ + const stream = pair() + + stream.close = () => stream.sink([]) + stream.id = id + + openStreams.push(stream) + + return { + stream, + protocol: protocols[0] + } + }, + close: () => {}, + getStreams: () => openStreams, + ...properties + }) + }, + async teardown () { + // cleanup resources created by setup() + } + }) +}) diff --git a/test/connection.js b/test/connection.js new file mode 100644 index 0000000..267760f --- /dev/null +++ b/test/connection.js @@ -0,0 +1,166 @@ +/* eslint-env mocha */ + +'use strict' + +const chai = require('chai') +const expect = chai.expect +chai.use(require('dirty-chai')) +const sinon = require('sinon') + +module.exports = (test) => { + describe('connection', () => { + describe('open connection', () => { + let connection + + beforeEach(async () => { + connection = await test.setup() + if (!connection) throw new Error('missing connection') + }) + + afterEach(async () => { + await connection.close() + await test.teardown() + }) + + it('should have properties set', () => { + expect(connection.id).to.exist() + expect(connection.localPeer).to.exist() + expect(connection.remotePeer).to.exist() + expect(connection.localAddr).to.exist() + expect(connection.remoteAddr).to.exist() + expect(connection.stat.status).to.equal('open') + expect(connection.stat.timeline.open).to.exist() + expect(connection.stat.timeline.upgraded).to.exist() + expect(connection.stat.timeline.close).to.not.exist() + expect(connection.stat.direction).to.exist() + expect(connection.streams).to.eql([]) + expect(connection.tags).to.eql([]) + }) + + it('should get the metadata of an open connection', () => { + const stat = connection.stat + + expect(stat.status).to.equal('open') + expect(stat.direction).to.exist() + expect(stat.timeline.open).to.exist() + expect(stat.timeline.upgraded).to.exist() + expect(stat.timeline.close).to.not.exist() + }) + + it('should return an empty array of streams', () => { + const streams = connection.streams + + expect(streams).to.eql([]) + }) + + it('should be able to create a new stream', async () => { + const protocolToUse = '/echo/0.0.1' + const { stream, protocol } = await connection.newStream(protocolToUse) + + expect(protocol).to.equal(protocolToUse) + + const connStreams = await connection.streams + + expect(stream).to.exist() + expect(connStreams).to.exist() + expect(connStreams).to.have.lengthOf(1) + expect(connStreams[0]).to.equal(stream) + }) + }) + + describe('close connection', () => { + let connection + let timelineProxy + const proxyHandler = { + set () { + return Reflect.set(...arguments) + } + } + + beforeEach(async () => { + timelineProxy = new Proxy({ + open: Date.now() - 10, + upgraded: Date.now() + }, proxyHandler) + + connection = await test.setup({ + stat: { + timeline: timelineProxy, + direction: 'outbound', + encryption: '/crypto/1.0.0', + multiplexer: '/muxer/1.0.0' + } + }) + if (!connection) throw new Error('missing connection') + }) + + afterEach(async () => { + await test.teardown() + }) + + it('should be able to close the connection after being created', async () => { + expect(connection.stat.timeline.close).to.not.exist() + await connection.close() + + expect(connection.stat.timeline.close).to.exist() + expect(connection.stat.status).to.equal('closed') + }) + + it('should be able to close the connection after opening a stream', async () => { + // Open stream + const protocol = '/echo/0.0.1' + await connection.newStream(protocol) + + // Close connection + expect(connection.stat.timeline.close).to.not.exist() + await connection.close() + + expect(connection.stat.timeline.close).to.exist() + expect(connection.stat.status).to.equal('closed') + }) + + it('should support a proxy on the timeline', async () => { + sinon.spy(proxyHandler, 'set') + expect(connection.stat.timeline.close).to.not.exist() + + await connection.close() + expect(proxyHandler.set.callCount).to.equal(1) + const [obj, key, value] = proxyHandler.set.getCall(0).args + expect(obj).to.eql(connection.stat.timeline) + expect(key).to.equal('close') + expect(value).to.be.a('number').that.equals(connection.stat.timeline.close) + }) + + it('should fail to create a new stream if the connection is closing', async () => { + expect(connection.stat.timeline.close).to.not.exist() + connection.close() + + try { + const protocol = '/echo/0.0.1' + await connection.newStream(protocol) + } catch (err) { + expect(err).to.exist() + return + } + + throw new Error('should fail to create a new stream if the connection is closing') + }) + + it('should fail to create a new stream if the connection is closed', async () => { + expect(connection.stat.timeline.close).to.not.exist() + await connection.close() + + try { + const protocol = '/echo/0.0.1' + await connection.newStream(protocol) + } catch (err) { + expect(err).to.exist() + expect(err.code).to.equal('ERR_CONNECTION_CLOSED') + return + } + + throw new Error('should fail to create a new stream if the connection is closing') + }) + }) + }) +} diff --git a/test/utils/peers.js b/test/utils/peers.js new file mode 100644 index 0000000..fad0d23 --- /dev/null +++ b/test/utils/peers.js @@ -0,0 +1,27 @@ +'use strict' + +module.exports = [{ + id: 'QmNMMAqSxPetRS1cVMmutW5BCN1qQQyEr4u98kUvZjcfEw', + privKey: 'CAASpQkwggShAgEAAoIBAQDPek2aeHMa0blL42RTKd6xgtkk4Zkldvq4LHxzcag5uXepiQzWANEUvoD3KcUTmMRmx14PvsxdLCNst7S2JSa0R2n5wSRs14zGy6892lx4H4tLBD1KSpQlJ6vabYM1CJhIQRG90BtzDPrJ/X1iJ2HA0PPDz0Mflam2QUMDDrU0IuV2m7gSCJ5r4EmMs3U0xnH/1gShkVx4ir0WUdoWf5KQUJOmLn1clTRHYPv4KL9A/E38+imNAXfkH3c2T7DrCcYRkZSpK+WecjMsH1dCX15hhhggNqfp3iulO1tGPxHjm7PDGTPUjpCWKpD5e50sLqsUwexac1ja6ktMfszIR+FPAgMBAAECggEAB2H2uPRoRCAKU+T3gO4QeoiJaYKNjIO7UCplE0aMEeHDnEjAKC1HQ1G0DRdzZ8sb0fxuIGlNpFMZv5iZ2ZFg2zFfV//DaAwTek9tIOpQOAYHUtgHxkj5FIlg2BjlflGb+ZY3J2XsVB+2HNHkUEXOeKn2wpTxcoJE07NmywkO8Zfr1OL5oPxOPlRN1gI4ffYH2LbfaQVtRhwONR2+fs5ISfubk5iKso6BX4moMYkxubYwZbpucvKKi/rIjUA3SK86wdCUnno1KbDfdXS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