feat(p2p): files search also
This commit is contained in:
parent
98f0404869
commit
c33f927a7d
@ -87,6 +87,7 @@
|
|||||||
"iconv-lite": "^0.4.19",
|
"iconv-lite": "^0.4.19",
|
||||||
"ipaddr.js": "^1.5.4",
|
"ipaddr.js": "^1.5.4",
|
||||||
"json-socket": "^0.3.0",
|
"json-socket": "^0.3.0",
|
||||||
|
"lodash": "^4.17.5",
|
||||||
"material-ui": "^0.20.0",
|
"material-ui": "^0.20.0",
|
||||||
"moment": "^2.20.1",
|
"moment": "^2.20.1",
|
||||||
"mysql": "^2.15.0",
|
"mysql": "^2.15.0",
|
||||||
|
@ -17,6 +17,8 @@ import MenuItem from 'material-ui/MenuItem';
|
|||||||
|
|
||||||
import formatBytes from './format-bytes'
|
import formatBytes from './format-bytes'
|
||||||
|
|
||||||
|
import _ from 'lodash'
|
||||||
|
|
||||||
let session;
|
let session;
|
||||||
|
|
||||||
class TorrentsStatistic extends Component {
|
class TorrentsStatistic extends Component {
|
||||||
@ -217,9 +219,16 @@ export default class Search extends Component {
|
|||||||
window.torrentSocket.on('newStatistic', this.newStatisticFunc);
|
window.torrentSocket.on('newStatistic', this.newStatisticFunc);
|
||||||
|
|
||||||
this.remoteSearchTorrent = (torrents) => {
|
this.remoteSearchTorrent = (torrents) => {
|
||||||
console.log(torrents)
|
this.searchTorrents = _.unionBy(this.searchTorrents, torrents, 'hash')
|
||||||
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
window.torrentSocket.on('remoteSearchTorrent', this.remoteSearchTorrent);
|
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()
|
componentWillUnmount()
|
||||||
{
|
{
|
||||||
@ -229,6 +238,9 @@ export default class Search extends Component {
|
|||||||
if(this.remoteSearchTorrent)
|
if(this.remoteSearchTorrent)
|
||||||
window.torrentSocket.off('remoteSearchTorrent', this.remoteSearchTorrent);
|
window.torrentSocket.off('remoteSearchTorrent', this.remoteSearchTorrent);
|
||||||
|
|
||||||
|
if(this.remoteSearchFiles)
|
||||||
|
window.torrentSocket.off('remoteSearchFiles', this.remoteSearchFiles);
|
||||||
|
|
||||||
session = {
|
session = {
|
||||||
searchTorrents: this.searchTorrents,
|
searchTorrents: this.searchTorrents,
|
||||||
searchFiles: this.searchFiles,
|
searchFiles: this.searchFiles,
|
||||||
|
@ -239,7 +239,7 @@ class Spider extends Emiter {
|
|||||||
if(this.client && !this.ignore) {
|
if(this.client && !this.ignore) {
|
||||||
cpuDebug('cpu usage:' + cpuUsage())
|
cpuDebug('cpu usage:' + cpuUsage())
|
||||||
if(this.cpuLimit <= 0 || cpuUsage() <= this.cpuLimit + this.cpuInterval) {
|
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) => {
|
tcpServer.on('connection', (socket) => {
|
||||||
socket = new JsonSocket(socket);
|
socket = new JsonSocket(socket);
|
||||||
socket.on('message', (message) => {
|
socket.on('message', (message) => {
|
||||||
console.log(message)
|
|
||||||
if(message.type && messageHandlers[message.type])
|
if(message.type && messageHandlers[message.type])
|
||||||
{
|
{
|
||||||
messageHandlers[message.type](message.data, (data) => {
|
messageHandlers[message.type](message.data, (data) => {
|
||||||
@ -411,7 +410,6 @@ tcpServer.on('connection', (socket) => {
|
|||||||
if(navigation.files.min > 0)
|
if(navigation.files.min > 0)
|
||||||
where += ' and files > ' + sphinx.escape(navigation.files.min) + ' ';
|
where += ' and files > ' + sphinx.escape(navigation.files.min) + ' ';
|
||||||
}
|
}
|
||||||
console.log(navigation, where)
|
|
||||||
|
|
||||||
let searchList = [];
|
let searchList = [];
|
||||||
//args.splice(orderBy && orderBy.length > 0 ? 1 : 0, 1);
|
//args.splice(orderBy && orderBy.length > 0 ? 1 : 0, 1);
|
||||||
@ -432,20 +430,19 @@ tcpServer.on('connection', (socket) => {
|
|||||||
recive('searchTorrent', (text, navigation, callback) => {
|
recive('searchTorrent', (text, navigation, callback) => {
|
||||||
searchTorrentCall(text, navigation, callback)
|
searchTorrentCall(text, navigation, callback)
|
||||||
p2p.emit('searchTorrent', {text, navigation}, (remote) => {
|
p2p.emit('searchTorrent', {text, navigation}, (remote) => {
|
||||||
console.log('remote search responce')
|
console.log('remote search results', remote && remote.length)
|
||||||
send('remoteSearchTorrent', remote)
|
send('remoteSearchTorrent', remote)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
onSocketMessage('searchTorrent', ({text, navigation} = {}, callback) => {
|
onSocketMessage('searchTorrent', ({text, navigation} = {}, callback) => {
|
||||||
console.log('search remote', text)
|
|
||||||
if(!text)
|
if(!text)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
searchTorrentCall(text, navigation, (data) => callback(data))
|
searchTorrentCall(text, navigation, (data) => callback(data))
|
||||||
})
|
})
|
||||||
|
|
||||||
recive('searchFiles', function(text, navigation, callback)
|
const searchFilesCall = function(text, navigation, callback)
|
||||||
{
|
{
|
||||||
if(typeof callback != 'function')
|
if(typeof callback != 'function')
|
||||||
return;
|
return;
|
||||||
@ -532,8 +529,23 @@ tcpServer.on('connection', (socket) => {
|
|||||||
callback(Object.values(search));
|
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)
|
recive('checkTrackers', function(hash)
|
||||||
{
|
{
|
||||||
if(hash.length != 40)
|
if(hash.length != 40)
|
||||||
|
Loading…
Reference in New Issue
Block a user