mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-15 11:56:25 +00:00
Merge pull request #275 from webtorrent/feross-patch-1
server: Improve style of announce/filter logic
This commit is contained in:
commit
b3400a9eb1
40
server.js
40
server.js
@ -657,31 +657,35 @@ Server.prototype._onRequest = function (params, cb) {
|
|||||||
Server.prototype._onAnnounce = function (params, cb) {
|
Server.prototype._onAnnounce = function (params, cb) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
self.getSwarm(params.info_hash, function (err, swarm) {
|
if (self._filter) {
|
||||||
if (err) return cb(err)
|
self._filter(params.info_hash, params, function (err) {
|
||||||
|
// Presence of `err` means that this announce request is disallowed
|
||||||
|
if (err) return cb(err)
|
||||||
|
|
||||||
if (self._filter) {
|
getOrCreateSwarm(function (err, swarm) {
|
||||||
self._filter(params.info_hash, params, function (err) {
|
if (err) return cb(err)
|
||||||
// Precense of err means that this torrent or user is disallowd
|
announce(swarm)
|
||||||
if (err) cb(err)
|
|
||||||
else {
|
|
||||||
if (swarm) announce(swarm)
|
|
||||||
else createSwarm()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else {
|
})
|
||||||
if (swarm) announce(swarm)
|
} else {
|
||||||
else createSwarm()
|
getOrCreateSwarm(function (err, swarm) {
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function createSwarm () {
|
|
||||||
self.createSwarm(params.info_hash, function (err, swarm) {
|
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
announce(swarm)
|
announce(swarm)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get existing swarm, or create one if one does not exist
|
||||||
|
function getOrCreateSwarm (cb) {
|
||||||
|
self.getSwarm(params.info_hash, function (err, swarm) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
if (swarm) return cb(null, swarm)
|
||||||
|
self.createSwarm(params.info_hash, function (err, swarm) {
|
||||||
|
if (err) return cb(err)
|
||||||
|
cb(null, swarm)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function announce (swarm) {
|
function announce (swarm) {
|
||||||
if (!params.event || params.event === 'empty') params.event = 'update'
|
if (!params.event || params.event === 'empty') params.event = 'update'
|
||||||
swarm.announce(params, function (err, response) {
|
swarm.announce(params, function (err, response) {
|
||||||
|
Loading…
Reference in New Issue
Block a user