mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-04 05:31:51 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
1a550bac26 | |||
51c5594d49 | |||
d5476caee1 | |||
4b211f5cd6 | |||
433188f182 | |||
f3de45d198 | |||
2afaed5f2a | |||
308dead134 | |||
1c8603b721 | |||
c883475a4f | |||
515c6a32ec | |||
a107e1da57 | |||
2ec97b3c8c | |||
cb449a6c5c | |||
1773efecdf |
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,5 +25,3 @@ build/Release
|
|||||||
# Dependency directory
|
# Dependency directory
|
||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
docs
|
|
@ -26,5 +26,4 @@ build/Release
|
|||||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
test
|
test
|
||||||
docs
|
|
31
package.json
31
package.json
@ -1,15 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-tcp",
|
"name": "libp2p-tcp",
|
||||||
"version": "0.9.1",
|
"version": "0.9.3",
|
||||||
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
"description": "Node.js implementation of the TCP module that libp2p uses, which implements the interface-connection and interface-transport interfaces",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "aegir-lint",
|
"lint": "aegir-lint",
|
||||||
"test": "aegir-test --env node",
|
"test": "aegir-test --env node",
|
||||||
"docs": "aegir-docs",
|
"release": "aegir-release --env no-build",
|
||||||
"release": "aegir-release --env no-build --docs",
|
"release-minor": "aegir-release --type minor --env no-build",
|
||||||
"release-minor": "aegir-release --type minor --env no-build --docs",
|
"release-major": "aegir-release --type major --env no-build",
|
||||||
"release-major": "aegir-release --type major --env no-build --docs",
|
|
||||||
"coverage": "aegir-coverage",
|
"coverage": "aegir-coverage",
|
||||||
"coverage-publish": "aegir-coverage publish"
|
"coverage-publish": "aegir-coverage publish"
|
||||||
},
|
},
|
||||||
@ -34,28 +33,30 @@
|
|||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^9.2.0",
|
"interface-transport": "~0.3.3",
|
||||||
|
"aegir": "^10.0.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"interface-transport": "^0.3.3",
|
|
||||||
"lodash.isfunction": "^3.0.8",
|
"lodash.isfunction": "^3.0.8",
|
||||||
"pre-commit": "^1.1.3",
|
"pre-commit": "^1.2.2",
|
||||||
"pull-stream": "^3.5.0"
|
"pull-stream": "^3.5.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"interface-connection": "0.3.0",
|
"interface-connection": "~0.3.0",
|
||||||
"ip-address": "^5.8.2",
|
"ip-address": "^5.8.6",
|
||||||
"lodash.includes": "^4.3.0",
|
"lodash.includes": "^4.3.0",
|
||||||
"mafmt": "^2.1.2",
|
"lodash.isfunction": "^3.0.8",
|
||||||
"multiaddr": "^2.1.1",
|
"mafmt": "^2.1.6",
|
||||||
|
"multiaddr": "^2.2.1",
|
||||||
"stream-to-pull-stream": "^1.7.2"
|
"stream-to-pull-stream": "^1.7.2"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
"Evan Schwartz <evan.mark.schwartz@gmail.com>",
|
"Evan Schwartz <evan.mark.schwartz@gmail.com>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
|
"Greenkeeper <support@greenkeeper.io>",
|
||||||
"João Antunes <j.goncalo.antunes@gmail.com>",
|
"João Antunes <j.goncalo.antunes@gmail.com>",
|
||||||
|
"Prashanth Chandra <coolshanth94@gmail.com>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
"Stephen Whitmore <stephen.whitmore@gmail.com>"
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
39
src/index.js
39
src/index.js
@ -11,32 +11,21 @@ const log = debug('libp2p:tcp:dial')
|
|||||||
|
|
||||||
const createListener = require('./listener')
|
const createListener = require('./listener')
|
||||||
|
|
||||||
/**
|
module.exports = class TCP {
|
||||||
*
|
dial (ma, options, cb) {
|
||||||
*/
|
|
||||||
class TCP {
|
|
||||||
/**
|
|
||||||
* Dial to another peer.
|
|
||||||
*
|
|
||||||
* @param {Multiaddr} ma - The address of the peer we want to dial to.
|
|
||||||
* @param {Object} [options={}]
|
|
||||||
* @param {function(Error?, Array<Multiaddr>?)} [callback]
|
|
||||||
* @returns {Connection}
|
|
||||||
*/
|
|
||||||
dial (ma, options, callback) {
|
|
||||||
if (isFunction(options)) {
|
if (isFunction(options)) {
|
||||||
callback = options
|
cb = options
|
||||||
options = {}
|
options = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!callback) {
|
if (!cb) {
|
||||||
callback = () => {}
|
cb = () => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cOpts = ma.toOptions()
|
const cOpts = ma.toOptions()
|
||||||
log('Connecting to %s %s', cOpts.port, cOpts.host)
|
log('Connecting to %s %s', cOpts.port, cOpts.host)
|
||||||
|
|
||||||
const rawSocket = net.connect(cOpts, callback)
|
const rawSocket = net.connect(cOpts, cb)
|
||||||
|
|
||||||
rawSocket.once('timeout', () => {
|
rawSocket.once('timeout', () => {
|
||||||
log('timeout')
|
log('timeout')
|
||||||
@ -54,13 +43,6 @@ class TCP {
|
|||||||
return conn
|
return conn
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Listen for incoming `TCP` connetions.
|
|
||||||
*
|
|
||||||
* @param {Object} [options={}]
|
|
||||||
* @param {function(Connection)} [handler] - Called with newly incomin connections.
|
|
||||||
* @returns {Listener}
|
|
||||||
*/
|
|
||||||
createListener (options, handler) {
|
createListener (options, handler) {
|
||||||
if (isFunction(options)) {
|
if (isFunction(options)) {
|
||||||
handler = options
|
handler = options
|
||||||
@ -72,13 +54,6 @@ class TCP {
|
|||||||
return createListener(handler)
|
return createListener(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter a list of multiaddrs for those which contain
|
|
||||||
* valid `TCP` addresses.
|
|
||||||
*
|
|
||||||
* @param {Multiaddr|Array<Multiaddr>} multiaddrs
|
|
||||||
* @returns {Array<Multiaddr>}
|
|
||||||
*/
|
|
||||||
filter (multiaddrs) {
|
filter (multiaddrs) {
|
||||||
if (!Array.isArray(multiaddrs)) {
|
if (!Array.isArray(multiaddrs)) {
|
||||||
multiaddrs = [multiaddrs]
|
multiaddrs = [multiaddrs]
|
||||||
@ -91,5 +66,3 @@ class TCP {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TCP
|
|
||||||
|
@ -15,49 +15,7 @@ const getMultiaddr = require('./get-multiaddr')
|
|||||||
const IPFS_CODE = 421
|
const IPFS_CODE = 421
|
||||||
const CLOSE_TIMEOUT = 2000
|
const CLOSE_TIMEOUT = 2000
|
||||||
|
|
||||||
/**
|
|
||||||
* Listening for incoming connections.
|
|
||||||
*
|
|
||||||
* @event listening
|
|
||||||
* @instance
|
|
||||||
* @memberof Listener
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The server closes.
|
|
||||||
*
|
|
||||||
* @event close
|
|
||||||
* @instance
|
|
||||||
* @memberof Listener
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* New connection established.
|
|
||||||
*
|
|
||||||
* @event connection
|
|
||||||
* @instance
|
|
||||||
* @type {Connection}
|
|
||||||
* @memberof Listener
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The underlying server encountered an error.
|
|
||||||
*
|
|
||||||
* @event error
|
|
||||||
* @instance
|
|
||||||
* @type {Error}
|
|
||||||
* @memberof Listener
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = (handler) => {
|
module.exports = (handler) => {
|
||||||
/**
|
|
||||||
* @alias Listener
|
|
||||||
* @type {Eventemitter}
|
|
||||||
* @fires Listener#listening
|
|
||||||
* @fires Listener#close
|
|
||||||
* @fires Listener#connection
|
|
||||||
* @fires Listener#error
|
|
||||||
*/
|
|
||||||
const listener = new EventEmitter()
|
const listener = new EventEmitter()
|
||||||
|
|
||||||
const server = net.createServer((socket) => {
|
const server = net.createServer((socket) => {
|
||||||
|
Reference in New Issue
Block a user