mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-13 19:06:27 +00:00
23 lines
640 B
JavaScript
23 lines
640 B
JavaScript
/**
|
|
* Functions and constants needed by both the tracker client and server.
|
|
*/
|
|
|
|
function toUInt32 (n) {
|
|
var buf = new Buffer(4)
|
|
buf.writeUInt32BE(n, 0)
|
|
return buf
|
|
}
|
|
exports.toUInt32 = toUInt32
|
|
|
|
exports.CONNECTION_ID = Buffer.concat([ toUInt32(0x417), toUInt32(0x27101980) ])
|
|
exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 }
|
|
exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 }
|
|
|
|
exports.bytewiseDecodeURIComponent = function (str) {
|
|
return new Buffer(decodeURIComponent(str), 'binary')
|
|
}
|
|
|
|
exports.bytewiseEncodeURIComponent = function (buf) {
|
|
return encodeURIComponent(buf.toString('binary'))
|
|
}
|