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

Commit 3ad628d

Browse files
dmitriy ryajovdryajov
dmitriy ryajov
authored andcommitted
style: fixing lint issues
1 parent 614951b commit 3ad628d

File tree

7 files changed

+45
-33
lines changed

7 files changed

+45
-33
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"url": "https://github.com/libp2p/js-libp2p-circuit/issues"
3131
},
3232
"homepage": "https://github.com/libp2p/js-libp2p-circuit#readme",
33+
"eslintConfig": {
34+
"extends": [
35+
"./node_modules/aegir/config/eslintrc.yml"
36+
]
37+
},
3338
"devDependencies": {
3439
"aegir": "^10.0.0",
3540
"chai": "^3.5.0",

src/circuit-dialer.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,13 @@ class CircuitDialer {
130130
}
131131

132132
/**
133-
* Create listener
133+
* Create a listener
134134
*
135+
* @param {Function} handler
135136
* @param {any} options
136-
* @param {any} handler
137-
* @returns {Listener}
138-
*
139-
* @memberOf CircuitDialer
137+
* @returns {listener}
140138
*/
141-
createListener (handler) {
139+
createListener (handler, options) {
142140
return createListener(this.swarm, handler)
143141
}
144142

src/circuit.js renamed to src/circuit-relay.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
const pull = require('pull-stream')
44
const lp = require('pull-length-prefixed')
5-
const multiaddr = require('multiaddr')
65
const Peer = require('./peer')
76
const handshake = require('pull-handshake')
8-
const utils = require('./utils')
97
const debug = require('debug')
10-
const includes = require('lodash/includes')
118
const PeerInfo = require('peer-info')
129
const PeerId = require('peer-id')
1310

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

16-
const log = debug('libp2p:circuit:circuit')
17-
log.err = debug('libp2p:circuit:error:circuit')
13+
const log = debug('libp2p:circuit:relay')
14+
log.err = debug('libp2p:circuit:error:relay')
1815

1916
class Circuit {
2017

@@ -36,11 +33,13 @@ class Circuit {
3633
}
3734

3835
/**
36+
* The handler called to process a connection
3937
*
40-
* @param conn
41-
* @param peerInfo
42-
* @param dstAddr
43-
* @param cb
38+
* @param {Connection} conn
39+
* @param {Multiaddr} dstAddr
40+
* @param {Function} cb
41+
*
42+
* @return {void}
4443
*/
4544
handler (conn, dstAddr, cb) {
4645
this._circuit(conn, dstAddr, cb)
@@ -74,6 +73,15 @@ class Circuit {
7473
})
7574
}
7675

76+
/**
77+
* Circuit two peers
78+
*
79+
* @param {Connection} srcConn
80+
* @param {Multiaddr} dstMa
81+
* @param {Function} cb
82+
* @return {void}
83+
* @private
84+
*/
7785
_circuit (srcConn, dstMa, cb) {
7886
this._dialPeer(dstMa, (err, dstConn) => {
7987
if (err) {
@@ -85,6 +93,11 @@ class Circuit {
8593
let shake = stream.handshake
8694

8795
dstConn.getPeerInfo((err, peerInfo) => {
96+
if (err) {
97+
log.err(err)
98+
return cb(err)
99+
}
100+
88101
pull(
89102
pull.values([new Buffer(`/ipfs/${peerInfo.id.toB58String()}`)]),
90103
lp.encode(),
@@ -111,9 +124,8 @@ class Circuit {
111124
dstConn,
112125
stream
113126
)
114-
115127
})
116128
}
117129
}
118130

119-
module.exports = Circuit
131+
module.exports = Circuit

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
'use strict'
2+
13
module.exports = {
2-
Circuit: require('./circuit'),
4+
Circuit: require('./circuit-relay'),
35
CircuitDialer: require('./circuit-dialer'),
46
multicodec: require('./multicodec')
5-
}
7+
}

src/listener.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
const includes = require('lodash/includes')
44
const pull = require('pull-stream')
5-
const Circuit = require('./circuit')
5+
const Circuit = require('./circuit-relay')
66
const multicodec = require('./multicodec')
77
const EE = require('events').EventEmitter
88
const lp = require('pull-length-prefixed')
99
const multiaddr = require('multiaddr')
1010
const handshake = require('pull-handshake')
1111
const Connection = require('interface-connection').Connection
12-
const abortable = require('pull-abortable')
1312

1413
const debug = require('debug')
1514

@@ -76,7 +75,7 @@ module.exports = (swarm, handler) => {
7675

7776
listener.close = (cb) => {
7877
// TODO: should we close/abort connections here?
79-
// spdy-transport throw a `Error: socket hang up`
78+
// spdy-transport throws a `Error: socket hang up`
8079
// on swarm stop right now, could be an existing issue?
8180
swarm.unhandle(multicodec)
8281
listener.emit('close')

src/multicodec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = '/ipfs/relay/circuit/1.0.0'
1+
'use strict'
2+
3+
module.exports = '/ipfs/relay/circuit/1.0.0'

test/index.spec.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33

44
const PeerInfo = require('peer-info')
55
const series = require('async/series')
6-
const parallel = require('async/parallel')
76
const pull = require('pull-stream')
87
const Libp2p = require('libp2p')
98

109
const TCP = require('libp2p-tcp')
1110
const WS = require('libp2p-websockets')
1211
const spdy = require('libp2p-spdy')
1312
const multiplex = require('libp2p-multiplex')
14-
const waterfall = require('async/waterfall')
1513
const secio = require('libp2p-secio')
1614

1715
const expect = require('chai').expect
@@ -91,12 +89,8 @@ describe('test relay', function () {
9189
(cb) => {
9290
dstNode.start(cb)
9391
},
94-
(cb) => srcNode.dialByPeerInfo(relayPeer, (err, conn) => {
95-
cb()
96-
}),
97-
(cb) => dstNode.dialByPeerInfo(relayPeer, (err, conn) => {
98-
cb()
99-
})
92+
(cb) => srcNode.dialByPeerInfo(relayPeer, cb),
93+
(cb) => dstNode.dialByPeerInfo(relayPeer, cb)
10094
], done)
10195

10296
}
@@ -112,7 +106,7 @@ describe('test relay', function () {
112106
(cb) => {
113107
relayNode.stop(cb)
114108
}
115-
], (err) => done()) // TODO: pass err to done once we figure out why spdy is throwing on stop
109+
], () => done()) // TODO: pass err to done once we figure out why spdy is throwing on stop
116110
}
117111

118112
function reverse (protocol, conn) {
@@ -135,7 +129,7 @@ describe('test relay', function () {
135129
pull.values(['hello']),
136130
conn,
137131
pull.collect((err, data) => {
138-
if (err) return cb(err)
132+
if (err) return done(err)
139133

140134
data.forEach((val, i) => {
141135
expect(val.toString()).to.equal(vals[i].split('').reverse().join(''))

0 commit comments

Comments
 (0)