feat(p2p): files search also
This commit is contained in:
parent
98f0404869
commit
c33f927a7d
@ -87,6 +87,7 @@
|
||||
"iconv-lite": "^0.4.19",
|
||||
"ipaddr.js": "^1.5.4",
|
||||
"json-socket": "^0.3.0",
|
||||
"lodash": "^4.17.5",
|
||||
"material-ui": "^0.20.0",
|
||||
"moment": "^2.20.1",
|
||||
"mysql": "^2.15.0",
|
||||
|
@ -17,6 +17,8 @@ import MenuItem from 'material-ui/MenuItem';
|
||||
|
||||
import formatBytes from './format-bytes'
|
||||
|
||||
import _ from 'lodash'
|
||||
|
||||
let session;
|
||||
|
||||
class TorrentsStatistic extends Component {
|
||||
@ -217,9 +219,16 @@ export default class Search extends Component {
|
||||
window.torrentSocket.on('newStatistic', this.newStatisticFunc);
|
||||
|
||||
this.remoteSearchTorrent = (torrents) => {
|
||||
console.log(torrents)
|
||||
this.searchTorrents = _.unionBy(this.searchTorrents, torrents, 'hash')
|
||||
this.forceUpdate();
|
||||
}
|
||||
window.torrentSocket.on('remoteSearchTorrent', this.remoteSearchTorrent);
|
||||
|
||||
this.remoteSearchFiles = (torrents) => {
|
||||
this.searchFiles = _.unionBy(this.searchFiles, torrents, 'hash')
|
||||
this.forceUpdate();
|
||||
}
|
||||
window.torrentSocket.on('remoteSearchFiles', this.remoteSearchFiles);
|
||||
}
|
||||
componentWillUnmount()
|
||||
{
|
||||
@ -229,6 +238,9 @@ export default class Search extends Component {
|
||||
if(this.remoteSearchTorrent)
|
||||
window.torrentSocket.off('remoteSearchTorrent', this.remoteSearchTorrent);
|
||||
|
||||
if(this.remoteSearchFiles)
|
||||
window.torrentSocket.off('remoteSearchFiles', this.remoteSearchFiles);
|
||||
|
||||
session = {
|
||||
searchTorrents: this.searchTorrents,
|
||||
searchFiles: this.searchFiles,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user