Skip to content

Commit

Permalink
fix: regex redudant escape and test fix for multiple interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Rodríguez Baquero committed Jul 22, 2021
1 parent 0d6590e commit 5027585
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class LSD extends EventEmitter {

const parsedAnnounce = this._parseAnnounce(msg.toString())

if (parsedAnnounce == null) return
if (parsedAnnounce === null) return
if (parsedAnnounce.cookie === this.cookie) return

parsedAnnounce.infoHash.forEach(infoHash => {
Expand All @@ -70,7 +70,7 @@ class LSD extends EventEmitter {

_parseAnnounce (announce) {
const checkHost = (host) => {
return /^(239.192.152.143|\[ff15::efc0:988f\]):6771$/.test(host)
return /^(239.192.152.143|\[ff15::efc0:988f]):6771$/.test(host)
}

const checkPort = (port) => {
Expand Down
6 changes: 3 additions & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ test('should emit peer when receiving a valid announce', t => {
})

lsd.on('peer', (peerAddress, infoHash) => {
const ip = Object.values(os.networkInterfaces())
const addresses = Object.values(os.networkInterfaces())
.flatMap(i => i)
.filter(i => !i.internal && i.family === 'IPv4')
.reduce((acc, cur) => cur.address, '')
.map(i => `${i.address}:${port}`)

t.equal(peerAddress, `${ip}:${port}`)
t.ok(addresses.includes(peerAddress))
t.equal(infoHash, infoHash)

lsd.destroy(() => t.end())
Expand Down

0 comments on commit 5027585

Please sign in to comment.