Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

feat: callbacks -> async / await #112

Merged
merged 33 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6cf8f71
chore: callbacks -> async / await
dirkmc Apr 2, 2019
65c1888
feat: cancel dials with AbortController
dirkmc Apr 9, 2019
776a524
test: add async/await tests
dirkmc Apr 12, 2019
1ffd549
chore: update README
dirkmc Apr 12, 2019
5009c2c
feat: listen to array of multiaddrs (#104)
jacobheun Apr 22, 2019
02bff18
feat: abort after connect
dirkmc Apr 23, 2019
6bfa500
chore: fix package.json
dirkmc Apr 23, 2019
b108c9f
revert: "feat: listen to array of multiaddrs (#104)"
dirkmc Apr 29, 2019
5869c04
chore: fix travis file
dirkmc Apr 29, 2019
bfbfd07
chore: nicer addr name in README
dirkmc Apr 29, 2019
4c3c811
chore: update packages
dirkmc Apr 29, 2019
5fde9cd
test: fix listen addresses in tests
dirkmc Apr 29, 2019
3ff9ed4
chore: update interface-transport
dirkmc Apr 29, 2019
d9230e8
fix: throw error on write to destroyed socket
dirkmc May 1, 2019
c61e9ea
chore: log errors emited by server handler socket
dirkmc May 1, 2019
a658537
refactor: many refactor, maybe work?
Sep 6, 2019
ebcfdd6
fix: await on upgrade
Sep 8, 2019
a24d847
refactor: simplify connection addresss accessors
Sep 8, 2019
c493d02
fix: remove unused dependencies
Sep 8, 2019
5c6e6af
fix: isValid is a function not a property
Sep 9, 2019
dea67b3
refactor: much refactors
Sep 9, 2019
9c88c26
fix: flatten the network address arrays
jacobheun Sep 10, 2019
989426e
fix: use latest multiaddr to improve filter
jacobheun Sep 10, 2019
a1fe98b
fix: almost all the tests pass
Sep 13, 2019
3e0c844
fix: tests
Sep 14, 2019
153c124
Merge branch 'master' into feat/async-await2
Sep 14, 2019
b2d5286
chore: remove commitlint
jacobheun Sep 16, 2019
588c24d
chore: remove pre push test
jacobheun Sep 16, 2019
ea9ac90
docs: add some jsdocs
jacobheun Sep 16, 2019
e37af10
chore: update dep
jacobheun Sep 16, 2019
b29b368
fix: untrack only needs the close event
jacobheun Sep 16, 2019
208ef89
chore: update interface dep
jacobheun Sep 16, 2019
4a959d8
refactor: assert upgrader presence
jacobheun Sep 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 2 additions & 44 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
docs
**/node_modules/
**/*.log
test/repo-tests*
**/bundle.js

# yarn
yarn.lock

# Logs
logs
*.log

coverage

# 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

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
test/test-data/go-ipfs-repo/LOCK
test/test-data/go-ipfs-repo/LOG
test/test-data/go-ipfs-repo/LOG.old

# while testing npm5
package-lock.json
coverage
.nyc_output
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ os:

before_script:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6'; fi

script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

Expand All @@ -27,7 +28,6 @@ jobs:
os: linux
script:
- npx aegir build --bundlesize
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint

Expand Down
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[![](https://github.com/raw/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)


> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other different transports.
> JavaScript implementation of the TCP module for libp2p. It exposes the [interface-transport](https://github.com/libp2p/interface-connection) for dial/listen. `libp2p-tcp` is a very thin shim that adds support for dialing to a `multiaddr`. This small shim will enable libp2p to use other transports.

## Lead Maintainer

Expand Down Expand Up @@ -41,37 +41,33 @@
```js
const TCP = require('libp2p-tcp')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')
const pipe = require('it-pipe')
const { collect } = require('streaming-iterables')

const mh = multiaddr('/ip4/127.0.0.1/tcp/9090')
const addr = multiaddr('/ip4/127.0.0.1/tcp/9090')

const tcp = new TCP()

const listener = tcp.createListener((socket) => {
console.log('new connection opened')
pull(
pull.values(['hello']),
pipe(
['hello'],
socket
)
})

listener.listen(mh, () => {
console.log('listening')

pull(
tcp.dial(mh),
pull.collect((err, values) => {
if (!err) {
console.log(`Value: ${values.toString()}`)
} else {
console.log(`Error: ${err}`)
}

// Close connection after reading
listener.close()
}),
)
})
await listener.listen(addr)
console.log('listening')

const socket = await tcp.dial(addr)
const values = await pipe(
socket,
collect
)
console.log(`Value: ${values.toString()}`)

// Close connection after reading
await listener.close()
```

Outputs:
Expand All @@ -88,12 +84,12 @@ Value: hello

[![](https://github.com/raw/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)

`libp2p-tcp` accepts TCP addresses both IPFS and non IPFS encapsulated addresses, i.e:
`libp2p-tcp` accepts TCP addresses as both IPFS and non IPFS encapsulated addresses, i.e:

`/ip4/127.0.0.1/tcp/4001`
`/ip4/127.0.0.1/tcp/4001/ipfs/QmHash`

Both for dialing and listening.
(both for dialing and listening)

### Connection

Expand Down
22 changes: 9 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
"release": "aegir release -t node --no-build",
"release-minor": "aegir release -t node --type minor --no-build",
"release-major": "aegir-release -t node --type major --no-build",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --provider coveralls"
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node"
},
"pre-push": [
"lint",
"test"
"lint"
],
"repository": {
"type": "git",
Expand All @@ -38,20 +36,18 @@
"aegir": "^20.0.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"interface-transport": "~0.3.6",
"pull-stream": "^3.6.14"
"interface-transport": "^0.6.1",
"sinon": "^7.3.1"
},
"dependencies": {
"abortable-iterator": "^2.1.0",
"class-is": "^1.1.0",
"debug": "^4.1.1",
"interface-connection": "~0.3.3",
"err-code": "^2.0.0",
"ip-address": "^6.1.0",
"lodash.includes": "^4.3.0",
"lodash.isfunction": "^3.0.9",
"mafmt": "^6.0.7",
"multiaddr": "^6.1.0",
"once": "^1.4.0",
"stream-to-pull-stream": "^1.7.3"
"mafmt": "^6.0.9",
"multiaddr": "^7.1.0",
"stream-to-it": "^0.1.1"
},
"contributors": [
"Alan Shaw <alan@tableflip.io>",
Expand Down
8 changes: 8 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

// p2p multi-address code
exports.CODE_P2P = 421
exports.CODE_CIRCUIT = 290

// Time to wait for a connection to close gracefully before destroying it manually
exports.CLOSE_TIMEOUT = 2000
33 changes: 0 additions & 33 deletions src/get-multiaddr.js

This file was deleted.

Loading