Skip to content
Merged
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
40 changes: 22 additions & 18 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,31 +657,35 @@ Server.prototype._onRequest = function (params, cb) {
Server.prototype._onAnnounce = function (params, cb) {
var self = this

self.getSwarm(params.info_hash, function (err, swarm) {
if (err) return cb(err)
if (self._filter) {
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) {
self._filter(params.info_hash, params, function (err) {
// Precense of err means that this torrent or user is disallowd
if (err) cb(err)
else {
if (swarm) announce(swarm)
else createSwarm()
}
getOrCreateSwarm(function (err, swarm) {
if (err) return cb(err)
announce(swarm)
})
} else {
if (swarm) announce(swarm)
else createSwarm()
}
})

function createSwarm () {
self.createSwarm(params.info_hash, function (err, swarm) {
})
} else {
getOrCreateSwarm(function (err, swarm) {
if (err) return cb(err)
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) {
if (!params.event || params.event === 'empty') params.event = 'update'
swarm.announce(params, function (err, response) {
Expand Down