• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libp2p / js-libp2p-railing / 309

pending completion
309

Pull #74

travis-ci

web-flow
Add test for malformed multiaddr
Pull Request #74: add more error handling for malformed bootstrap multiaddr

4 of 8 branches covered (50.0%)

27 of 31 relevant lines covered (87.1%)

15.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.1
/../src/index.js
1
'use strict'
2

3
const PeerId = require('peer-id')
2✔
4
const PeerInfo = require('peer-info')
2✔
5
const multiaddr = require('multiaddr')
2✔
6
const EventEmitter = require('events').EventEmitter
2✔
7
const debug = require('debug')
2✔
8
const setImmediate = require('async/setImmediate')
2✔
9

10
const log = debug('libp2p:railing')
2✔
11
log.error = debug('libp2p:railing:error')
2✔
12

13
class Railing extends EventEmitter {
14
  constructor (bootstrapers) {
15
    super()
4✔
16
    this.bootstrapers = bootstrapers
4✔
17
    this.interval = null
4✔
18
  }
19

20
  start (callback) {
21
    setImmediate(() => callback())
4✔
22
    if (this.interval) { return }
4!
23

24
    this.interval = setInterval(() => {
4✔
25
      this.bootstrapers.forEach((candidate) => {
6✔
26
        let ma
44✔
27

28
        try {
44✔
29
          ma = multiaddr(candidate)
44✔
30
        } catch (err) {
31
          return log.error('Invalid multiaddr', err)
2✔
32
        }
33

34
        const peerIdB58Str = ma.getPeerId()
42✔
35
        if (!peerIdB58Str) { return log.error('Unable to resolve bootstrap peer id') }
42✔
36

37
        const peerId = PeerId.createFromB58String(peerIdB58Str)
40✔
38

39
        PeerInfo.create(peerId, (err, peerInfo) => {
40✔
40
          if (err) { return log.error('Invalid bootstrap peer id', err) }
40!
41

42
          peerInfo.multiaddrs.add(ma)
40✔
43

44
          this.emit('peer', peerInfo)
40✔
45
        })
46
      })
47
    }, 10000)
48
  }
49

50
  stop (callback) {
51
    setImmediate(callback)
×
52
    if (this.interval) {
×
53
      clearInterval(this.interval)
×
54
      this.interval = null
×
55
    }
56
  }
57
}
58

59
module.exports = Railing
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc