var DHT = require('bittorrent-dht')
var magnet = require('magnet-uri')

var uri = 'magnet:?xt=urn:btih:4a7b842632ca42cdd3c8d54017a8da756839b84d&dn=D0112-Chacha.Choudhary.Sabu.Kaale.Tapu.Mein.pdf&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
var parsed = magnet(uri)

//console.log(parsed.infoHash) // 'e3811b9539cacff680e418124272177c47477157'

var dht = new DHT()

dht.listen(20000, function () {
  console.log('now listening')
  //console.log(dht.address());
})

dht.on('peer', function (peer, infoHash, from) {
  //console.log(peer);
  console.log(from);
  
  console.log('found potential peer ' + peer.host + ':' + peer.port + ' through ' + from.address + ':' + from.port)
})

//find peers for the given torrent info hash
dht.lookup(parsed.infoHash)

// dht.on('node', function (node) { 
//   console.log(node); 
//  })

//  dht.on('announce', function (peer, infoHash) { 
//    console.log(peer);
//    console.log(infoHash)
//   })
