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

fix: reduce bundle size #40

Merged
merged 1 commit into from
Jan 10, 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
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"dirkmc <dirk@mccormick.cx>"
],
"devDependencies": {
"aegir": "^18.0.2",
"assert": "^1.4.1",
"aegir": "^18.0.3",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"libp2p": "~0.24.3",
Expand All @@ -59,17 +58,17 @@
},
"dependencies": {
"async": "^2.6.1",
"debug": "^4.1.1",
"defaults-deep": "~0.2.4",
"interface-connection": "~0.3.3",
"mafmt": "^6.0.3",
"multiaddr": "^6.0.2",
"multistream-select": "~0.14.3",
"peer-id": "~0.12.1",
"peer-info": "~0.15.0",
"debug": "^4.1.0",
"interface-connection": "~0.3.2",
"mafmt": "^6.0.4",
"multiaddr": "^6.0.3",
"once": "^1.4.0",
"peer-id": "~0.12.2",
"peer-info": "~0.15.1",
"protons": "^1.0.1",
"pull-abortable": "^4.1.1",
"pull-handshake": "^1.1.4",
"pull-length-prefixed": "^1.3.1",
"pull-pair": "^1.1.0",
"pull-stream": "^3.6.9"
}
}
3 changes: 1 addition & 2 deletions src/circuit/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const once = require('once')
const PeerId = require('peer-id')
const waterfall = require('async/waterfall')
const isFunction = require('lodash.isfunction')
const multiaddr = require('multiaddr')

const Connection = require('interface-connection').Connection
Expand Down Expand Up @@ -138,7 +137,7 @@ class Dialer {
* @private
*/
_dialPeer (dstMa, relay, cb) {
if (isFunction(relay)) {
if (typeof relay === 'function') {
cb = relay
relay = null
}
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/hop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const debug = require('debug')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
Expand Down
11 changes: 7 additions & 4 deletions src/circuit/stream-handler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict'

const pull = require('pull-stream')
const values = require('pull-stream/sources/values')
const collect = require('pull-stream/sinks/collect')
const empty = require('pull-stream/sources/empty')
const pull = require('pull-stream/pull')
const lp = require('pull-length-prefixed')
const handshake = require('pull-handshake')

Expand Down Expand Up @@ -78,9 +81,9 @@ class StreamHandler {
}

pull(
pull.values([msg]),
values([msg]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
if (err) {
log.err(err)
this.shake.abort(err)
Expand Down Expand Up @@ -128,7 +131,7 @@ class StreamHandler {

// close stream
pull(
pull.empty(),
empty(),
this.rest()
)
}
Expand Down
16 changes: 9 additions & 7 deletions test/dialer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const multiaddr = require('multiaddr')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const waterfall = require('async/waterfall')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const asyncMap = require('pull-stream/throughs/async-map')
const pair = require('pull-pair/duplex')
const pb = require('pull-protocol-buffers')

Expand Down Expand Up @@ -98,7 +100,7 @@ describe(`dialer tests`, function () {
it(`should handle successful CAN_HOP`, (done) => {
dialer._dialRelay.callsFake((_, cb) => {
pull(
pull.values([{
values([{
type: proto.CircuitRelay.type.HOP,
code: proto.CircuitRelay.Status.SUCCESS
}]),
Expand All @@ -118,7 +120,7 @@ describe(`dialer tests`, function () {
it(`should handle failed CAN_HOP`, function (done) {
dialer._dialRelay.callsFake((_, cb) => {
pull(
pull.values([{
values([{
type: proto.CircuitRelay.type.HOP,
code: proto.CircuitRelay.Status.HOP_CANT_SPEAK_RELAY
}]),
Expand Down Expand Up @@ -226,7 +228,7 @@ describe(`dialer tests`, function () {
pull(
p[0],
pb.decode(proto.CircuitRelay),
pull.asyncMap((msg, cb) => {
asyncMap((msg, cb) => {
expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer)
cb(null, {
type: proto.CircuitRelay.Type.STATUS,
Expand All @@ -247,7 +249,7 @@ describe(`dialer tests`, function () {
pull(
p[0],
pb.decode(proto.CircuitRelay),
pull.asyncMap((msg, cb) => {
asyncMap((msg, cb) => {
expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer)
cb(null, {
type: proto.CircuitRelay.Type.STATUS,
Expand All @@ -273,7 +275,7 @@ describe(`dialer tests`, function () {
pull(
p[0],
pb.decode(proto.CircuitRelay),
pull.asyncMap((msg, cb) => {
asyncMap((msg, cb) => {
expect(msg.dstPeer.addrs[0]).to.deep.equal(dstMa.buffer)
cb(null, {
type: proto.CircuitRelay.Type.STATUS,
Expand All @@ -297,7 +299,7 @@ describe(`dialer tests`, function () {
dialer._dialRelay.callsFake((_, cb) => {
cb(null, conn)
pull(
pull.values([{
values([{
type: proto.CircuitRelay.Type.STATUS,
code: proto.CircuitRelay.Status.MALFORMED_MESSAGE
}]),
Expand Down
16 changes: 9 additions & 7 deletions test/hop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const waterfall = require('async/waterfall')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const collect = require('pull-stream/sinks/collect')
const lp = require('pull-length-prefixed')
const proto = require('../src/protocol')
const StreamHandler = require('../src/circuit/stream-handler')
Expand Down Expand Up @@ -359,19 +361,19 @@ describe('relay', () => {

it('should create circuit', (done) => {
pull(
pull.values([proto.CircuitRelay.encode({
values([proto.CircuitRelay.encode({
type: proto.CircuitRelay.Type.STATUS,
code: proto.CircuitRelay.Status.SUCCESS
})]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()

encoded.forEach((e) => dstShake.write(e))
pull(
pull.values([Buffer.from('hello')]),
values([Buffer.from('hello')]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()

encoded.forEach((e) => srcShake.write(e))
Expand Down Expand Up @@ -414,12 +416,12 @@ describe('relay', () => {
})

pull(
pull.values([proto.CircuitRelay.encode({
values([proto.CircuitRelay.encode({
type: proto.CircuitRelay.Type.STATUS,
code: proto.CircuitRelay.Status.STOP_RELAY_REFUSED
})]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()

encoded.forEach((e) => dstShake.write(e))
Expand Down
24 changes: 13 additions & 11 deletions test/listener.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const handshake = require('pull-handshake')
const Connection = require('interface-connection').Connection
const proto = require('../src/protocol')
const lp = require('pull-length-prefixed')
const pull = require('pull-stream')
const pull = require('pull-stream/pull')
const values = require('pull-stream/sources/values')
const collect = require('pull-stream/sinks/collect')
const multicodec = require('../src/multicodec')

const chai = require('chai')
Expand Down Expand Up @@ -89,9 +91,9 @@ describe('listener', function () {
}

pull(
pull.values([proto.CircuitRelay.encode(relayMsg)]),
values([proto.CircuitRelay.encode(relayMsg)]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
})
Expand Down Expand Up @@ -126,9 +128,9 @@ describe('listener', function () {
}

pull(
pull.values([proto.CircuitRelay.encode(relayMsg)]),
values([proto.CircuitRelay.encode(relayMsg)]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
})
Expand Down Expand Up @@ -161,9 +163,9 @@ describe('listener', function () {
})

pull(
pull.values([proto.CircuitRelay.encode(relayMsg)]),
values([proto.CircuitRelay.encode(relayMsg)]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
})
Expand Down Expand Up @@ -198,9 +200,9 @@ describe('listener', function () {
}

pull(
pull.values([proto.CircuitRelay.encode(relayMsg)]),
values([proto.CircuitRelay.encode(relayMsg)]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
})
Expand All @@ -223,9 +225,9 @@ describe('listener', function () {
}

pull(
pull.values([Buffer.from([relayMsg])]),
values([Buffer.from([relayMsg])]),
lp.encode(),
pull.collect((err, encoded) => {
collect((err, encoded) => {
expect(err).to.not.exist()
encoded.forEach((e) => shake.write(e))
}),
Expand Down