mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-07-03 07:01:37 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
79428f3e62 | |||
8a394b5286 | |||
b7f73bcda1 | |||
8b44aa28ee | |||
ded1f6831c | |||
5ef24695fc |
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,9 @@ docs
|
|||||||
test/repo-tests*
|
test/repo-tests*
|
||||||
**/bundle.js
|
**/bundle.js
|
||||||
|
|
||||||
|
# yarn
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
*.log
|
*.log
|
||||||
|
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
<a name="0.12.0"></a>
|
||||||
|
# [0.12.0](https://github.com/libp2p/js-libp2p-tcp/compare/v0.11.6...v0.12.0) (2018-04-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add class-is module ([ded1f68](https://github.com/libp2p/js-libp2p-tcp/commit/ded1f68))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.11.6"></a>
|
<a name="0.11.6"></a>
|
||||||
## [0.11.6](https://github.com/libp2p/js-libp2p-tcp/compare/v0.11.5...v0.11.6) (2018-02-20)
|
## [0.11.6](https://github.com/libp2p/js-libp2p-tcp/compare/v0.11.5...v0.11.6) (2018-02-20)
|
||||||
|
|
||||||
|
25
README.md
25
README.md
@ -39,12 +39,11 @@ const TCP = require('libp2p-tcp')
|
|||||||
const multiaddr = require('multiaddr')
|
const multiaddr = require('multiaddr')
|
||||||
const pull = require('pull-stream')
|
const pull = require('pull-stream')
|
||||||
|
|
||||||
const mh1 = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
|
||||||
const mh2 = multiaddr('/ip6/::/tcp/9092')
|
|
||||||
|
|
||||||
const tcp = new TCP()
|
const tcp = new TCP()
|
||||||
|
|
||||||
const listener = tcp.createListener(mh1, (socket) => {
|
const listener = tcp.createListener((socket) => {
|
||||||
console.log('new connection opened')
|
console.log('new connection opened')
|
||||||
pull(
|
pull(
|
||||||
pull.values(['hello']),
|
pull.values(['hello']),
|
||||||
@ -52,15 +51,21 @@ const listener = tcp.createListener(mh1, (socket) => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
listener.listen(() => {
|
listener.listen(mh, () => {
|
||||||
console.log('listening')
|
console.log('listening')
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
tcp.dial(mh1),
|
tcp.dial(mh),
|
||||||
pull.log,
|
pull.collect((err, values) => {
|
||||||
pull.onEnd(() => {
|
if (!err) {
|
||||||
tcp.close()
|
console.log(`Value: ${values.toString()}`)
|
||||||
})
|
} else {
|
||||||
|
console.log(`Error: ${err}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close connection after reading
|
||||||
|
listener.close()
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@ -70,7 +75,7 @@ Outputs:
|
|||||||
```sh
|
```sh
|
||||||
listening
|
listening
|
||||||
new connection opened
|
new connection opened
|
||||||
hello
|
Value: hello
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p-tcp",
|
"name": "libp2p-tcp",
|
||||||
"version": "0.11.6",
|
"version": "0.12.0",
|
||||||
"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": {
|
||||||
@ -34,29 +34,32 @@
|
|||||||
"npm": ">=3.0.0"
|
"npm": ">=3.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^13.0.5",
|
"aegir": "^13.0.6",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
"dirty-chai": "^2.0.1",
|
"dirty-chai": "^2.0.1",
|
||||||
"interface-transport": "~0.3.5",
|
"interface-transport": "~0.3.6",
|
||||||
"lodash.isfunction": "^3.0.9",
|
"lodash.isfunction": "^3.0.9",
|
||||||
"pre-commit": "^1.2.2",
|
"pre-commit": "^1.2.2",
|
||||||
"pull-stream": "^3.6.2"
|
"pull-stream": "^3.6.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"class-is": "^1.1.0",
|
||||||
"debug": "^3.1.0",
|
"debug": "^3.1.0",
|
||||||
"interface-connection": "~0.3.2",
|
"interface-connection": "~0.3.2",
|
||||||
"ip-address": "^5.8.9",
|
"ip-address": "^5.8.9",
|
||||||
"lodash.includes": "^4.3.0",
|
"lodash.includes": "^4.3.0",
|
||||||
"lodash.isfunction": "^3.0.9",
|
"lodash.isfunction": "^3.0.9",
|
||||||
"mafmt": "^4.0.0",
|
"mafmt": "^6.0.0",
|
||||||
"multiaddr": "^3.0.2",
|
"multiaddr": "^4.0.0",
|
||||||
"once": "^1.4.0",
|
"once": "^1.4.0",
|
||||||
"stream-to-pull-stream": "^1.7.2"
|
"stream-to-pull-stream": "^1.7.2"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Alan Shaw <alan@tableflip.io>",
|
"Alan Shaw <alan@tableflip.io>",
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
|
"Diogo Silva <fsdiogo@gmail.com>",
|
||||||
"Dmitriy Ryajov <dryajov@gmail.com>",
|
"Dmitriy Ryajov <dryajov@gmail.com>",
|
||||||
|
"Drew Stone <drewstone329@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>",
|
"Greenkeeper <support@greenkeeper.io>",
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
const net = require('net')
|
const net = require('net')
|
||||||
const toPull = require('stream-to-pull-stream')
|
const toPull = require('stream-to-pull-stream')
|
||||||
const mafmt = require('mafmt')
|
const mafmt = require('mafmt')
|
||||||
|
const withIs = require('class-is')
|
||||||
const includes = require('lodash.includes')
|
const includes = require('lodash.includes')
|
||||||
const isFunction = require('lodash.isfunction')
|
const isFunction = require('lodash.isfunction')
|
||||||
const Connection = require('interface-connection').Connection
|
const Connection = require('interface-connection').Connection
|
||||||
@ -81,4 +82,4 @@ class TCP {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TCP
|
module.exports = withIs(TCP, { className: 'TCP', symbolName: '@libp2p/js-libp2p-tcp/tcp' })
|
||||||
|
@ -89,7 +89,7 @@ describe('Connection Wrap', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('dial error', (done) => {
|
it('dial error', (done) => {
|
||||||
tcp.dial(multiaddr('/ip4/999.0.0.1/tcp/1234'), (err) => {
|
tcp.dial(multiaddr('/ip4/127.0.0.1/tcp/22234'), (err) => {
|
||||||
expect(err).to.exist()
|
expect(err).to.exist()
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user