107 lines
4.0 KiB
Markdown
Raw Normal View History

2015-12-11 20:38:40 -08:00
interface-connection
2015-09-16 17:32:10 +01:00
==================
[![](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/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
2015-09-16 17:32:10 +01:00
2018-06-25 21:06:39 +10:00
This is 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.
2015-09-16 17:32:10 +01:00
2018-06-25 21:06:39 +10:00
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.
2015-09-16 17:32:10 +01:00
Publishing a test suite as a module lets multiple modules all ensure compatibility since they use the same test suite.
2018-06-25 21:06:39 +10:00
The API is presented with both Node.js and Go primitives, however, there is no actual limitations for it to be extended to any other language, pushing forward the cross compatibility and interop through diferent stacks.
2015-09-16 17:32:10 +01:00
## Lead Maintainer
[Jacob Heun](https://github.com/jacobheun/)
2015-09-16 17:32:10 +01:00
# Modules that implement the interface
- [js-libp2p-tcp](https://github.com/libp2p/js-libp2p-tcp)
- [js-libp2p-webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star)
- [js-libp2p-websockets](https://github.com/libp2p/js-libp2p-websockets)
- [js-libp2p-utp](https://github.com/libp2p/js-libp2p-utp)
- [webrtc-explorer](https://github.com/diasdavid/webrtc-explorer)
- [js-libp2p-spdy](https://github.com/libp2p/js-libp2p-spdy)
- [js-libp2p-multiplex](https://github.com/libp2p/js-libp2p-multiplex)
- [js-libp2p-secio](https://github.com/libp2p/js-libp2p-secio)
2015-09-16 17:32:10 +01:00
# Badge
2015-12-11 20:38:40 -08:00
Include this badge in your readme if you make a module that is compatible with the interface-connection API. You can validate this by running the tests.
2015-09-16 17:32:10 +01:00
2015-12-11 20:38:40 -08:00
![](https://raw.githubusercontent.com/diasdavid/interface-connection/master/img/badge.png)
2015-09-16 17:32:10 +01:00
# How to use the battery of tests
## Node.js
```
var tape = require('tape')
2015-12-11 20:38:40 -08:00
var tests = require('interface-connection/tests')
var YourConnectionHandler = require('../src')
2015-09-16 17:32:10 +01:00
var common = {
setup: function (t, cb) {
cb(null, YourConnectionHandler)
2015-09-16 17:32:10 +01:00
},
teardown: function (t, cb) {
cb()
}
}
tests(tape, common)
```
## Go
> WIP
# API
A valid (read: that follows this abstraction) connection, must implement the following API.
**Table of contents:**
- type: `Connection`
- `conn.getObservedAddrs(callback)`
- `conn.getPeerInfo(callback)`
- `conn.setPeerInfo(peerInfo)`
- `...`
### 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/multiformats/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/libp2p/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
2015-09-16 17:32:10 +01:00
- 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