Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Revert listen() with array of addresses #51

Merged
merged 1 commit into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ A valid transport (one that follows the interface defined) must implement the fo
- event: 'close'
- event: 'connection'
- event: 'error'
- `<Promise> listener.listen(Array<multiaddr>)`
- `<Promise> listener.listen(multiaddr)`
- `listener.getAddrs()`
- `<Promise> listener.close([options])`

Expand Down Expand Up @@ -173,11 +173,11 @@ The listener object created may emit the following events:

### Start a listener

- `JavaScript` - `await listener.listen(Array<multiaddr>)`
- `JavaScript` - `await listener.listen(multiaddr)`

This method puts the listener in `listening` mode, waiting for incoming connections.

`Array<multiaddr>` is an array of the addresses that the listener should bind to.
`multiaddr` is the address that the listener should bind to.

### Get listener addrs

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@
},
"homepage": "https://github.com/libp2p/interface-transport",
"devDependencies": {
"aegir": "^18.2.2"
"aegir": "^17.0.1",
"dirty-chai": "^2.0.1"
},
"dependencies": {
"abort-controller": "^3.0.0",
"async-iterator-to-pull-stream": "^1.3.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"interface-connection": "~0.3.3",
"it-goodbye": "^2.0.0",
"it-pipe": "^1.0.0",
"multiaddr": "^6.0.6",
"multiaddr": "^5.0.2",
"pull-stream": "^3.6.9",
"streaming-iterables": "^4.0.2"
},
Expand Down
14 changes: 1 addition & 13 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ class AbortError extends Error {
}
}

class AllListenersFailedError extends Error {
constructor () {
super('All listeners failed to listen on any addresses, please verify the addresses you provided are correct')
this.code = AllListenersFailedError.code
}

static get code () {
return 'ERR_ALL_LISTENERS_FAILED'
}
}

module.exports = {
AbortError,
AllListenersFailedError
AbortError
}
33 changes: 4 additions & 29 deletions src/listen-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const expect = chai.expect
chai.use(dirtyChai)

const pipe = require('it-pipe')
const { collect } = require('streaming-iterables')

module.exports = (common) => {
describe('listen', () => {
Expand All @@ -23,31 +22,7 @@ module.exports = (common) => {

it('simple', async () => {
const listener = transport.createListener((conn) => {})
await listener.listen([addrs[0]])
await listener.close()
})

it('listen on multiple addresses', async () => {
// create an echo listener
const listener = transport.createListener((conn) => pipe(conn, conn))
await listener.listen(addrs.slice(0, 2))

// Connect on both addresses
const [socket1, socket2] = await Promise.all([
transport.dial(addrs[0]),
transport.dial(addrs[1])
])

const data = Buffer.from('hi there')
const results = await pipe(
[data], // [data] -> socket1
socket1, // socket1 -> server (echo) -> socket1 -> socket2
socket2, // socket2 -> server (echo) -> socket2 -> collect
collect
)

expect(results).to.eql([data])

await listener.listen(addrs[0])
await listener.close()
})

Expand All @@ -60,7 +35,7 @@ module.exports = (common) => {
const listener = transport.createListener((conn) => pipe(conn, conn))

// Listen
await listener.listen([addrs[0]])
await listener.listen(addrs[0])

// Create two connections to the listener
const socket1 = await transport.dial(addrs[0])
Expand Down Expand Up @@ -91,7 +66,7 @@ module.exports = (common) => {
})

;(async () => {
await listener.listen([addrs[0]])
await listener.listen(addrs[0])
await transport.dial(addrs[0])
})()
})
Expand Down Expand Up @@ -120,7 +95,7 @@ module.exports = (common) => {
listener.on('close', done)

;(async () => {
await listener.listen([addrs[0]])
await listener.listen(addrs[0])
await listener.close()
})()
})
Expand Down