feat(announce): add more debug log info

This commit is contained in:
OldHawk
2018-05-15 13:24:14 +08:00
parent cc0bf02045
commit 51a2f1bd57
6 changed files with 64 additions and 29 deletions

View File

@@ -3,8 +3,10 @@
var path = require('path'),
chalk = require('chalk'),
logger = require('./logger'),
mongoose = require('mongoose'),
loggerAnnounce = require('./loggerAnnounce'),
moment = require('moment'),
objectId = require('mongodb').ObjectId,
config = require(path.resolve('./config/config'));
var appConfig = config.meanTorrentConfig.app;
@@ -30,10 +32,12 @@ module.exports.info = function (obj, section = undefined, colorFunction = undefi
var userPrefix = '';
if (isAnnounce && !announceConfig.debugAnnounceUser.debugAll) {
if (user) {
if (!announceConfig.debugAnnounceUser.ids.includes(user._id.toString())) {
var id = (('_id' in user) ? user._id.toString() : user.toString());
if (!announceConfig.debugAnnounceUser.ids.includes(id)) {
return;
} else {
userPrefix = ' - ' + user.displayName + ' - ' + user._id.toString();
userPrefix = ' - ' + (user.displayName || '-') + ' - ' + id;
}
}
}

View File

@@ -275,8 +275,8 @@ exports.announce = function (req, res) {
torrent data include peers
---------------------------------------------------------------*/
function (done) {
mtDebug.debugRed('user _id : ' + req.passkeyuser._id.toString(), 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('torrent info_hash : ' + query.info_hash, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.passkeyuser._id = ' + req.passkeyuser._id.toString(), 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.torrent.info_hash = ' + query.info_hash, 'ANNOUNCE', true, req.passkeyuser);
Torrent.findOne({
info_hash: query.info_hash
})
@@ -490,8 +490,9 @@ exports.announce = function (req, res) {
}
getCurrentPeer(function () {
mtDebug.debugRed('req.currentPeer.isNewCreated = ' + req.currentPeer.isNewCreated, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.currentPeer._id = ' + req.currentPeer._id.toString(), 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.currentPeer.isNewCreated = ' + req.currentPeer.isNewCreated, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.currentPeer._id = ' + req.currentPeer._id.toString(), 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('req.currentPeer.torrent._id = ' + req.currentPeer.torrent._id, 'ANNOUNCE', true, req.passkeyuser);
done(null);
});
},
@@ -508,11 +509,11 @@ exports.announce = function (req, res) {
var scount = getSelfSeederCount();
if (lcount > announceConfig.announceCheck.maxLeechNumberPerUserPerTorrent && !req.seeder) {
mtDebug.debugRed('getSelfLeecherCount = ' + lcount, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('getSelfLeecherCount = ' + lcount, 'ANNOUNCE', true, req.passkeyuser);
removeCurrPeer();
done(180);
} else if (scount > announceConfig.announceCheck.maxSeedNumberPerUserPerTorrent && req.seeder) {
mtDebug.debugRed('getSelfSeederCount = ' + scount, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('getSelfSeederCount = ' + scount, 'ANNOUNCE', true, req.passkeyuser);
removeCurrPeer();
done(181);
} else {
@@ -919,7 +920,7 @@ exports.announce = function (req, res) {
mtDebug.debug(peerBuffer, 'ANNOUNCE', true, req.passkeyuser);
}
done(null, 'done');
done(null);
},
/**
@@ -937,6 +938,8 @@ exports.announce = function (req, res) {
if (req.completeTorrent) {
req.completeTorrent.globalUpdateMethod(true);
}
done(null, 'done');
}
], function (err, reason) {
if (err) {
@@ -1249,8 +1252,8 @@ exports.announce = function (req, res) {
if (!req.seeder && event(query.event) !== EVENT_STOPPED && event(query.event) !== EVENT_COMPLETED) {
mtDebug.debugGreen('---------------GET PEERS LIST----------------', 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('want count = ' + count, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('peers.length = ' + peers.length, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('want.count = ' + count, 'ANNOUNCE', true, req.passkeyuser);
mtDebug.debugRed('peers.length = ' + peers.length, 'ANNOUNCE', true, req.passkeyuser);
var p;
var bc;

View File

@@ -103,10 +103,14 @@ CompleteSchema.methods.globalUpdateMethod = function (findThenUpdate, cb) {
if (findThenUpdate) {
this.model('Complete').findById(this._id, function (err, c) {
c.refreshat = Date.now();
c.save(function (err, nc) {
if (cb) cb(nc || this);
});
if (c) {
c.refreshat = Date.now();
c.save(function (err, nc) {
if (cb) cb(nc || this);
});
} else {
if (cb) cb(this);
}
});
} else {
this.refreshat = Date.now();

View File

@@ -3,9 +3,13 @@
/**
* Module dependencies
*/
var mongoose = require('mongoose'),
var path = require('path'),
config = require(path.resolve('./config/config')),
mongoose = require('mongoose'),
Schema = mongoose.Schema;
var mtDebug = require(path.resolve('./config/lib/debug'));
/**
* Peer Schema
*/
@@ -107,17 +111,23 @@ PeerSchema.pre('save', function (next) {
* globalUpdateMethod
*/
PeerSchema.methods.globalUpdateMethod = function (findThenUpdate, cb) {
mtDebug.debugGreen('---------------GLOBAL UPDATE PEER DATA----------------', 'ANNOUNCE', true, this.user);
if (typeof findThenUpdate === 'function') {
cb = findThenUpdate;
findThenUpdate = false;
}
if (findThenUpdate) {
this.model('Peer').findById(this._id, function (err, p) {
p.refreshat = Date.now();
p.save(function (err, np) {
if (cb) cb(np || this);
});
this.model('Peer').findById(this._id).populate('torrent').exec(function (err, p) {
if (p) {
p.refreshat = Date.now();
p.save(function (err, np) {
if (cb) cb(np || this);
});
} else {
if (cb) cb(this);
}
});
} else {
this.refreshat = Date.now();
@@ -139,6 +149,7 @@ function countRatio(p) {
} else {
p.peer_ratio = Math.round((p.peer_uploaded / p.peer_downloaded) * 100) / 100;
}
mtDebug.debugRed('peer_ratio = ' + p.peer_ratio, 'ANNOUNCE', true, p.user);
}
/**
@@ -148,9 +159,14 @@ function countRatio(p) {
function countPercent(p) {
if (p.peer_status === 'seeder') {
p.peer_percent = 100;
mtDebug.debugRed('peer_percent = ' + p.peer_percent, 'ANNOUNCE', true, p.user);
} else {
// p.peer_percent = (Math.round((p.peer_downloaded / (p.peer_downloaded + p.peer_left)) * 10000) / 100) || 0;
mtDebug.debugRed('p.torrent._id = ' + p.torrent._id, 'ANNOUNCE', true, p.user);
mtDebug.debugRed('p.torrent.torrent_size = ' + p.torrent.torrent_size, 'ANNOUNCE', true, p.user);
mtDebug.debugRed('p.peer_left = ' + p.peer_left, 'ANNOUNCE', true, p.user);
p.peer_percent = Math.round((p.torrent.torrent_size - p.peer_left) / p.torrent.torrent_size * 10000) / 100;
mtDebug.debugRed('peer_percent = ' + p.peer_percent, 'ANNOUNCE', true, p.user);
}
}

View File

@@ -253,10 +253,14 @@ TorrentSchema.methods.globalUpdateMethod = function (findThenUpdate, cb) {
if (findThenUpdate) {
this.model('Torrent').findById(this._id, function (err, t) {
t.refreshat = Date.now();
t.save(function (err, nt) {
if (cb) cb(nt || this);
});
if (t) {
t.refreshat = Date.now();
t.save(function (err, nt) {
if (cb) cb(nt || this);
});
} else {
if (cb) cb(this);
}
});
} else {
this.refreshat = Date.now();

View File

@@ -466,10 +466,14 @@ UserSchema.methods.globalUpdateMethod = function (findThenUpdate, cb) {
if (findThenUpdate) {
this.model('User').findById(this._id, function (err, u) {
u.refreshat = Date.now();
u.save(function (err, nu) {
if (cb) cb(nu || this);
});
if (u) {
u.refreshat = Date.now();
u.save(function (err, nu) {
if (cb) cb(nu || this);
});
} else {
if (cb) cb(this);
}
});
} else {
this.refreshat = Date.now();