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

Commit

Permalink
fix: incorrect import name Stop -> Hop and making tests pass again
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov committed Jun 4, 2017
1 parent b08d5bb commit 3f07259
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
16 changes: 15 additions & 1 deletion src/circuit/hop.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const once = require('once')
const utilsFactory = require('./utils')
const StreamHandler = require('./stream-handler')
const waterfall = require('async/waterfall')
const assignInWith = require('lodash/assignInWith')

const multicodec = require('./../multicodec')

Expand All @@ -33,7 +34,16 @@ class Hop extends EE {
*/
constructor (options) {
super()
this.config = Object.assign({active: false}, options)
this.config = assignInWith(
{
active: false,
enabled: false
},
options,
(orig, src) => {
typeof src === 'undefined' ? false : src
})

this.swarm = null
this.active = this.config.active
}
Expand Down Expand Up @@ -98,6 +108,10 @@ class Hop extends EE {
* @return {void}
*/
mount (swarm) {
if (!this.config.enabled) {
return
}

this.swarm = swarm
utils = utilsFactory(swarm)
this.swarm.handle(multicodec.hop, (proto, conn) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

module.exports = {
Stop: require('./circuit/hop'),
Hop: require('./circuit/hop'),
Dialer: require('./dialer'),
multicodec: require('./multicodec'),
tag: 'Circuit'
Expand Down
17 changes: 3 additions & 14 deletions test/hop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const expect = require('chai').expect

describe('relay', function () {
describe(`handle circuit requests`, function () {
const relay = sinon.createStubInstance(Hop)
const dialer = sinon.createStubInstance(Dialer)

let relay
let swarm
let fromConn
let toConn
Expand Down Expand Up @@ -55,13 +55,9 @@ describe('relay', function () {
cb()
}
], () => {
relay.mount.callThrough()
relay.emit.callThrough()
relay.on.callThrough()
relay._readDstAddr.callThrough()
relay._readSrcAddr.callThrough()
relay._writeErr.callThrough()
relay = new Hop({enabled: true})
relay.mount(swarm) // mount the swarm
relay._circuit = sinon.stub()
relay._circuit.callsArg(3, null, toConn)

dialer.relayConns = new Map()
Expand All @@ -71,14 +67,7 @@ describe('relay', function () {
})

afterEach(() => {
relay.mount.reset()
relay.emit.reset()
relay.on.reset()
relay._circuit.reset()
relay._readDstAddr.reset()
relay._readSrcAddr.reset()
relay._readSrcAddr.reset()
dialer.negotiateRelay.reset()
})

it(`handle a valid circuit request`, function (done) {
Expand Down

0 comments on commit 3f07259

Please sign in to comment.