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

Commit

Permalink
feat(transport): use parallel limited dialer (#195)
Browse files Browse the repository at this point in the history
* feat(transport): use parallel limited dialer
  • Loading branch information
dignifiedquire authored and dryajov committed Apr 2, 2017
1 parent cbd2a32 commit fd8f237
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <[email protected]>"
]
}
}
17 changes: 17 additions & 0 deletions src/transport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const parallel = require('async/parallel')
const queue = require('async/queue')
const timeout = require('async/timeout')
const once = require('once')
const debug = require('debug')
const log = debug('libp2p:swarm:transport')
Expand All @@ -14,6 +16,12 @@ const defaultPerPeerRateLimit = 8
// the amount of time a single dial has to succeed
const dialTimeout = 10 * 1000

// number of concurrent outbound dials to make per peer, same as go-libp2p-swarm
const defaultPerPeerRateLimit = 8

// the amount of time a single dial has to succeed
const dialTimeout = 10 * 1000

module.exports = function (swarm) {
const dialer = new LimitDialer(defaultPerPeerRateLimit, dialTimeout)

Expand Down Expand Up @@ -130,4 +138,13 @@ function dialables (tp, multiaddrs) {
return tp.filter(multiaddrs)
}

function dialWithTimeout (transport, multiaddr, maxTimeout, callback) {
timeout((cb) => {
const conn = transport.dial(multiaddr, (err) => {
log('dialed')
cb(err, conn)
})
}, maxTimeout)(callback)
}

function noop () {}
Empty file added test/01-transport-tcp.node.js
Empty file.

0 comments on commit fd8f237

Please sign in to comment.