Skip to content
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
12 changes: 6 additions & 6 deletions lib/client/http-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ class HTTPTracker extends Tracker {
} catch (err) {
return cb(new Error(`Error decoding tracker response: ${err.message}`))
}
const failure = data['failure reason']
const failure = data['failure reason'] && Buffer.from(data['failure reason']).toString()
if (failure) {
debug(`failure from ${requestUrl} (${failure})`)
return cb(new Error(failure))
}

const warning = data['warning message']
const warning = data['warning message'] && Buffer.from(data['warning message']).toString()
if (warning) {
debug(`warning from ${requestUrl} (${warning})`)
self.client.emit('warning', new Error(warning))
Expand Down Expand Up @@ -194,10 +194,10 @@ class HTTPTracker extends Tracker {
this.client.emit('update', response)

let addrs
if (Buffer.isBuffer(data.peers)) {
if (ArrayBuffer.isView(data.peers)) {
// tracker returned compact response
try {
addrs = compact2string.multi(data.peers)
addrs = compact2string.multi(Buffer.from(data.peers))
} catch (err) {
return this.client.emit('warning', err)
}
Expand All @@ -211,10 +211,10 @@ class HTTPTracker extends Tracker {
})
}

if (Buffer.isBuffer(data.peers6)) {
if (ArrayBuffer.isView(data.peers6)) {
// tracker returned compact response
try {
addrs = compact2string.multi6(data.peers6)
addrs = compact2string.multi6(Buffer.from(data.peers6))
} catch (err) {
return this.client.emit('warning', err)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"type": "module",
"dependencies": {
"bencode": "^3.0.0",
"bencode": "^3.0.3",
"bittorrent-peerid": "^1.3.3",
"bn.js": "^5.2.0",
"chrome-dgram": "^3.0.6",
Expand Down
4 changes: 2 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class Server extends EventEmitter {
}

createSwarm (infoHash, cb) {
if (Buffer.isBuffer(infoHash)) infoHash = infoHash.toString('hex')
if (ArrayBuffer.isView(infoHash)) infoHash = infoHash.toString('hex')

process.nextTick(() => {
const swarm = this.torrents[infoHash] = new Server.Swarm(infoHash, this)
Expand All @@ -360,7 +360,7 @@ class Server extends EventEmitter {
}

getSwarm (infoHash, cb) {
if (Buffer.isBuffer(infoHash)) infoHash = infoHash.toString('hex')
if (ArrayBuffer.isView(infoHash)) infoHash = infoHash.toString('hex')

process.nextTick(() => {
cb(null, this.torrents[infoHash])
Expand Down
2 changes: 1 addition & 1 deletion test/request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function testRequestHandler (t, serverType) {

client1.once('update', data => {
t.equal(data.complete, 246)
t.equal(data.extraData.toString(), 'hi')
t.equal(Buffer.from(data.extraData).toString(), 'hi')

client1.destroy(() => {
t.pass('client1 destroyed')
Expand Down