mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-16 04:16:25 +00:00
2959c2cea6
Use the new Buffer APIs from Node v6 for added security. For example, `Buffer.from()` will throw if passed a number, unlike `Buffer()` which allocated UNINITIALIZED memory in that case. Use the `safe-buffer` package for compatibility with previous versions of Node.js, including v4.x, v0.12, and v0.10. https://github.com/feross/safe-buffer
27 lines
589 B
JavaScript
27 lines
589 B
JavaScript
/**
|
|
* Functions/constants needed by both the client and server.
|
|
*/
|
|
|
|
var Buffer = require('safe-buffer').Buffer
|
|
var extend = require('xtend/mutable')
|
|
|
|
exports.DEFAULT_ANNOUNCE_PEERS = 50
|
|
exports.MAX_ANNOUNCE_PEERS = 82
|
|
|
|
exports.binaryToHex = function (str) {
|
|
if (typeof str !== 'string') {
|
|
str = String(str)
|
|
}
|
|
return Buffer.from(str, 'binary').toString('hex')
|
|
}
|
|
|
|
exports.hexToBinary = function (str) {
|
|
if (typeof str !== 'string') {
|
|
str = String(str)
|
|
}
|
|
return Buffer.from(str, 'hex').toString('binary')
|
|
}
|
|
|
|
var config = require('./common-node')
|
|
extend(exports, config)
|