feat(search): add remote torrents in db via dht and search requests

This commit is contained in:
Alexey Kasyanchuk
2018-07-28 14:56:46 +03:00
parent b48ac7f973
commit c6bef2f94a
4 changed files with 77 additions and 7 deletions

View File

@ -54,4 +54,33 @@ torrentClient.loadSession = (sessionFile) => {
}
})
}
const metaHashes = {}
torrentClient.dht.on('peer', (peer, infoHash) => {
const hash = infoHash.toString('hex')
if(!(hash in metaHashes))
return
if(torrentClient._downloader)
{
torrentClient._downloader(peer, infoHash, (...data) => {
if(metaHashes[hash])
metaHashes[hash](...data)
delete metaHashes[hash]
})
}
else
{
delete metaHashes[hash]
}
})
torrentClient.getMetadata = (hash, callback) => {
hash = hash.toLowerCase()
torrentClient.dht.lookup(hash)
metaHashes[hash] = callback
}
module.exports = torrentClient