mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-03-16 21:10:54 +00:00
add required methods by the consumers of the conn obj, to the conn interface
This commit is contained in:
parent
0f710752d9
commit
e6d0b81f63
3
.gitignore
vendored
3
.gitignore
vendored
@ -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
.npmignore
Normal file
29
.npmignore
Normal file
@ -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
README.md
61
README.md
@ -1,7 +1,8 @@
|
||||
interface-connection
|
||||
==================
|
||||
|
||||
[](http://ipn.io) [](http://webchat.freenode.net/?channels=%23ipfs)
|
||||
[](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 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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
package.json
18
package.json
@ -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"
|
||||
@ -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
src/connection.js
Normal file
53
src/connection.js
Normal file
@ -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
src/index.js
Normal file
4
src/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
'use strict'
|
||||
|
||||
exports.connection = require('./connection.js')
|
||||
exports.Connection = require('./connection.js')
|
3
test/test.spec.js
Normal file
3
test/test.spec.js
Normal file
@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
|
||||
// so that aegir does not burp
|
Loading…
x
Reference in New Issue
Block a user