chore: update per feedback

This commit is contained in:
Jacob Heun
2019-12-04 23:22:30 +01:00
parent 98e82df5e1
commit 466b4dfd70
4 changed files with 8 additions and 9 deletions

View File

@ -5,7 +5,7 @@
* The number of tokens requested should be between 1 and the MAX_PER_PEER_DIALS max set in the Dialer. * The number of tokens requested should be between 1 and the MAX_PER_PEER_DIALS max set in the Dialer.
* If the number of available tokens is less than requested, the Dialer may return less than requested. * If the number of available tokens is less than requested, the Dialer may return less than requested.
* The number of tokens a DialRequest obtains reflects the maximum number of parallel Multiaddr Dials it can make. * The number of tokens a DialRequest obtains reflects the maximum number of parallel Multiaddr Dials it can make.
* If no tokens are available a DialRequest should immediately end and throw. This deviates from the existing queue system to avoid queue congestion. * If no tokens are available a DialRequest should immediately end and throw.
* As tokens are limited, DialRequests should be given a prioritized list of Multiaddrs to minimize the potential request time. * As tokens are limited, DialRequests should be given a prioritized list of Multiaddrs to minimize the potential request time.
* Once a Multiaddr Dial has succeeded, all pending dials in that Dial Request should be aborted. * Once a Multiaddr Dial has succeeded, all pending dials in that Dial Request should be aborted.
* If DIAL_TIMEOUT time has elapsed before any one Multiaddr Dial succeeds, all remaining dials in the DialRequest should be aborted. * If DIAL_TIMEOUT time has elapsed before any one Multiaddr Dial succeeds, all remaining dials in the DialRequest should be aborted.

View File

@ -72,6 +72,7 @@ class Dialer {
try { try {
const dialResult = await dialRequest.run({ ...options, signal }) const dialResult = await dialRequest.run({ ...options, signal })
clearTimeout(timeoutId) clearTimeout(timeoutId)
log('dial succeeded to %s', dialResult.remoteAddr)
return dialResult return dialResult
} catch (err) { } catch (err) {
// Error is a timeout // Error is a timeout

View File

@ -27,6 +27,7 @@ const Protector = require('../../src/pnet')
const swarmKeyBuffer = Buffer.from(require('../fixtures/swarm.key')) const swarmKeyBuffer = Buffer.from(require('../fixtures/swarm.key'))
const mockUpgrader = require('../utils/mockUpgrader') const mockUpgrader = require('../utils/mockUpgrader')
const createMockConnection = require('../utils/mockConnection')
const Peers = require('../fixtures/peers') const Peers = require('../fixtures/peers')
const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0') const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0')
@ -160,9 +161,7 @@ describe('Dialing (direct, TCP)', () => {
expect(dialer.tokens).to.have.length(2) expect(dialer.tokens).to.have.length(2)
const deferredDial = pDefer() const deferredDial = pDefer()
sinon.stub(localTM, 'dial').callsFake(async () => { sinon.stub(localTM, 'dial').callsFake(() => deferredDial.promise)
await deferredDial.promise
})
// Perform 3 multiaddr dials // Perform 3 multiaddr dials
dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr]) dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr])
@ -173,7 +172,7 @@ describe('Dialing (direct, TCP)', () => {
// We should have 2 in progress, and 1 waiting // We should have 2 in progress, and 1 waiting
expect(dialer.tokens).to.have.length(0) expect(dialer.tokens).to.have.length(0)
deferredDial.resolve() deferredDial.resolve(await createMockConnection())
// Let the call stack run // Let the call stack run
await delay(0) await delay(0)

View File

@ -27,6 +27,7 @@ const Libp2p = require('../../src')
const Peers = require('../fixtures/peers') const Peers = require('../fixtures/peers')
const { MULTIADDRS_WEBSOCKETS } = require('../fixtures/browser') const { MULTIADDRS_WEBSOCKETS } = require('../fixtures/browser')
const mockUpgrader = require('../utils/mockUpgrader') const mockUpgrader = require('../utils/mockUpgrader')
const createMockConnection = require('../utils/mockConnection')
const unsupportedAddr = multiaddr('/ip4/127.0.0.1/tcp/9999/ws') const unsupportedAddr = multiaddr('/ip4/127.0.0.1/tcp/9999/ws')
const remoteAddr = MULTIADDRS_WEBSOCKETS[0] const remoteAddr = MULTIADDRS_WEBSOCKETS[0]
@ -158,9 +159,7 @@ describe('Dialing (direct, WebSockets)', () => {
expect(dialer.tokens).to.have.length(2) expect(dialer.tokens).to.have.length(2)
const deferredDial = pDefer() const deferredDial = pDefer()
sinon.stub(localTM, 'dial').callsFake(async () => { sinon.stub(localTM, 'dial').callsFake(() => deferredDial.promise)
await deferredDial.promise
})
// Perform 3 multiaddr dials // Perform 3 multiaddr dials
dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr]) dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr])
@ -171,7 +170,7 @@ describe('Dialing (direct, WebSockets)', () => {
// We should have 2 in progress, and 1 waiting // We should have 2 in progress, and 1 waiting
expect(dialer.tokens).to.have.length(0) expect(dialer.tokens).to.have.length(0)
deferredDial.resolve() deferredDial.resolve(await createMockConnection())
// Let the call stack run // Let the call stack run
await delay(0) await delay(0)