Esempio n. 1
0
var dht = new DHT({
    // TODO remove it for working with the real life nodes
    bootstrap: ['127.0.0.1:52163']
});

console.log('Starting...');

dht.listen(function (port) {
    console.log('now listening on port ' + port);

    dht.on('ready', function () {
        console.log('Ready, running lookup...');

        var hash = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33';
        //var port = 23134;

        dht.lookup(hash, function() {

            console.log('Lookup finished. Announcing peer with hash ' + hash)
            dht.announce(hash, port, function(error){
                console.log('Announced: ' + hash + ' on port ' + port + ', error: ' + error);
            });
        });
    })
})


dht.on('peer', function (addr, hash, from) {
  console.log('found potential peer ' + addr + ' through ' + from + ', hash: ' + hash)
});

dht.on('announce', function (addr, hash) {
Esempio n. 2
0
var dht = new DHT()
var infohashReceived
var check = false
var minutes = 1
var announceInterval = minutes * 60 * 1000

// Load the DHT Manager class for access via JS.
var DHTClass = Java.type('com.turn.ttorrent.client.DHTManager')

// Get the infohash from the torrent.
infohashReceived = DHTClass.getHash()
console.log('RECEIVED INFOHASH ' + infohashReceived)

// Start listening.
dht.listen(20000, function () {
  	console.log('\nDHT LISTENING\n')
})

// When connected, start to look for peers.
dht.on('ready', function () {
	dht.lookup(infohashReceived, function(){
		// Do the announce right after the lookup
		dht.announce(infohashReceived, 55555, null)
		console.log('FIRST ANNOUNCE PERFORMED')
		
		setInterval(function(){
			dht.announce(infohashReceived, 55555, null)
			console.log('ANNOUNCE PERFORMED')
		}, announceInterval)
	})
})
Esempio n. 3
0
})

*/

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

//var uri = 'magnet:?xt=urn:btih:e3811b9539cacff680e418124272177c47477157'
//var parsed = magnet(uri)

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

var dht = new DHT()

dht.listen(20001, function () {
  console.log('now listening')
})

dht.on('ready', function () {
  // DHT is ready to use (i.e. the routing table contains at least K nodes, discovered
  // via the bootstrap nodes)
   console.log("dht  readyn")
  // find peers for the given torrent info hash
  dht.lookup(hash)
})

dht.on('peer', function (addr, hash, from) {
  console.log('found potential peer ' + addr + ' through ' + from)
})

Esempio n. 4
0
var Q = require('q')
var DHT = require('bittorrent-dht')
var utils = require('tradle-utils')
var helper = require('./helper')
var baseConfig = require('../conf/config')
baseConfig.checkReplication = 5000
baseConfig.storage = false

var data = [
  'bill',
  'ted',
  'rufus'
].map(Buffer)

var coordinator = new DHT({ bootstrap: false })
coordinator.listen(testReplication)

// testReplication(true)

function testReplication (external) {
  test('replication across all keepers', function (t) {
    var numInstances = 3
    var numPlanned = data.length * numInstances
    var timeoutId = setTimeout(function () {
      t.fail('Timed out')
      t.end()
    }, 100000 * Math.ceil(numPlanned / 100))

    var infoHashes = []
    var keepers
    var tasks = data.map(function (d, i) {
Esempio n. 5
0
var DHT = require('bittorrent-dht')
var dht = new DHT()

var tid = setTimeout(function () {
  process.exit(1)
}, 10000)

dht.on('peer', function (peer, hash, from) {
  console.log('found a peer ' + peer.host)
  found = true
})

dht.listen(20000)
dht.lookup('e3811b9539cacff680e418124272177c47477157')

dht.once('peer', function () {
  setTimeout(function () {
    dht.destroy()
    clearTimeout(tid)
  }, 1000)
})