mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-03-16 21:10:54 +00:00
This commit is contained in:
parent
4a571f1ac1
commit
97f3bf5f81
38
README.md
38
README.md
@ -1,15 +1,15 @@
|
||||
abstract-connection
|
||||
abstract-transport
|
||||
===================
|
||||
|
||||
[](http://ipn.io) [](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.
|
||||
|
||||
@ -21,9 +21,9 @@ 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.
|
||||
|
||||

|
||||

|
||||
|
||||
# How to use the battery of tests
|
||||
|
||||
@ -31,12 +31,12 @@ Include this badge in your readme if you make a module that is compatible with t
|
||||
|
||||
```
|
||||
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()
|
||||
@ -52,27 +52,27 @@ 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
|
||||
|
||||
@ -80,13 +80,13 @@ Options are the properties this listener must have access in order to properly l
|
||||
|
||||
- `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
|
||||
|
||||
|
BIN
img/badge.png
BIN
img/badge.png
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
img/badge.sketch
BIN
img/badge.sketch
Binary file not shown.
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 9.5 KiB |
12
package.json
12
package.json
@ -1,10 +1,10 @@
|
||||
{
|
||||
"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"
|
||||
@ -12,9 +12,9 @@
|
||||
"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",
|
||||
|
@ -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 () {
|
||||
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user