fix(search): show torrent page from remote peer
This commit is contained in:
@ -204,6 +204,13 @@ class p2p {
|
||||
return
|
||||
return peers.map(peer => ({address: peer.address, port: peer.port}))
|
||||
}
|
||||
|
||||
find(peer)
|
||||
{
|
||||
return this.peersList().find((localPeer) => {
|
||||
return localPeer.address === peer.address
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = p2p
|
@ -321,14 +321,31 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
});
|
||||
});
|
||||
|
||||
recive('torrent', function(hash, options, callback)
|
||||
{
|
||||
const onTorrent = (hash, options, callback) => {
|
||||
if(hash.length != 40)
|
||||
return;
|
||||
|
||||
if(typeof callback != 'function')
|
||||
return;
|
||||
|
||||
// remote request
|
||||
if(options.peer)
|
||||
{
|
||||
console.log('remote torrent request to peer')
|
||||
const peer = p2p.find(options.peer)
|
||||
if(!peer)
|
||||
{
|
||||
callback(undefined)
|
||||
return;
|
||||
}
|
||||
delete options.peer;
|
||||
peer.emit('torrent', {hash, options}, (data) => {
|
||||
console.log('remote torrent result')
|
||||
callback(data)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
sphinx.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) {
|
||||
if(!rows || rows.length == 0) {
|
||||
callback(undefined)
|
||||
@ -357,7 +374,15 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
send('downloading', torrent.infoHash)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
recive('torrent', onTorrent);
|
||||
p2p.on('torrent', ({hash, options} = {}, callback) => {
|
||||
if(!hash)
|
||||
return;
|
||||
|
||||
onTorrent(hash, options, (data) => callback(data))
|
||||
})
|
||||
|
||||
const searchTorrentCall = function(text, navigation, callback)
|
||||
{
|
||||
|
Reference in New Issue
Block a user