feat(p2p): files search also

This commit is contained in:
Alexey Kasyanchuk
2018-02-17 20:04:54 +03:00
parent 98f0404869
commit c33f927a7d
4 changed files with 32 additions and 7 deletions

View File

@ -239,7 +239,7 @@ class Spider extends Emiter {
if(this.client && !this.ignore) {
cpuDebug('cpu usage:' + cpuUsage())
if(this.cpuLimit <= 0 || cpuUsage() <= this.cpuLimit + this.cpuInterval) {
// this.client.add(addressPair, infohash);
this.client.add(addressPair, infohash);
}
}
}

View File

@ -264,7 +264,6 @@ tcpServer.listen(config.spiderPort);
tcpServer.on('connection', (socket) => {
socket = new JsonSocket(socket);
socket.on('message', (message) => {
console.log(message)
if(message.type && messageHandlers[message.type])
{
messageHandlers[message.type](message.data, (data) => {
@ -411,7 +410,6 @@ tcpServer.on('connection', (socket) => {
if(navigation.files.min > 0)
where += ' and files > ' + sphinx.escape(navigation.files.min) + ' ';
}
console.log(navigation, where)
let searchList = [];
//args.splice(orderBy && orderBy.length > 0 ? 1 : 0, 1);
@ -432,20 +430,19 @@ tcpServer.on('connection', (socket) => {
recive('searchTorrent', (text, navigation, callback) => {
searchTorrentCall(text, navigation, callback)
p2p.emit('searchTorrent', {text, navigation}, (remote) => {
console.log('remote search responce')
console.log('remote search results', remote && remote.length)
send('remoteSearchTorrent', remote)
})
});
onSocketMessage('searchTorrent', ({text, navigation} = {}, callback) => {
console.log('search remote', text)
if(!text)
return;
searchTorrentCall(text, navigation, (data) => callback(data))
})
recive('searchFiles', function(text, navigation, callback)
const searchFilesCall = function(text, navigation, callback)
{
if(typeof callback != 'function')
return;
@ -532,8 +529,23 @@ tcpServer.on('connection', (socket) => {
callback(Object.values(search));
})
});
}
recive('searchFiles', (text, navigation, callback) => {
searchFilesCall(text, navigation, callback)
p2p.emit('searchFiles', {text, navigation}, (remote) => {
console.log('remote search files results', remote && remote.length)
send('remoteSearchFiles', remote)
})
});
onSocketMessage('searchFiles', ({text, navigation} = {}, callback) => {
if(!text)
return;
searchFilesCall(text, navigation, (data) => callback(data))
})
recive('checkTrackers', function(hash)
{
if(hash.length != 40)