Giter VIP home page Giter VIP logo

bittorrent-dht's Introduction


WebTorrent
WebTorrent

The streaming torrent client. For node.js and the web.

discord ci npm version npm downloads Standard - JavaScript Style Guide

Sponsored by    Socket - JavaScript open source supply chain security    Wormhole

WebTorrent is a streaming torrent client for node.js and the browser. YEP, THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web – so the same code works in both runtimes.

In node.js, this module is a simple torrent client, using TCP and UDP to talk to other torrent clients.

In the browser, WebTorrent uses WebRTC (data channels) for peer-to-peer transport. It can be used without browser plugins, extensions, or installations. It's Just JavaScript™. Note: WebTorrent does not support UDP/TCP peers in browser.

Simply include the webtorrent.min.js script on your page to start fetching files over WebRTC using the BitTorrent protocol, or import WebTorrent from 'webtorrent' with browserify or webpack. See demo apps and code examples below.

jsdelivr download count

To make BitTorrent work over WebRTC (which is the only P2P transport that works on the web) we made some protocol changes. Therefore, a browser-based WebTorrent client or "web peer" can only connect to other clients that support WebTorrent/WebRTC.

To seed files to web peers, use a client that supports WebTorrent, e.g. WebTorrent Desktop, a desktop client with a familiar UI that can connect to web peers, webtorrent-hybrid, a command line program, or Instant.io, a website. Established torrent clients like Vuze have already added WebTorrent support so they can connect to both normal and web peers. We hope other clients will follow.

Network

Features

  • Torrent client for node.js & the browser (same npm package!)
  • Insanely fast
  • Download multiple torrents simultaneously, efficiently
  • Pure Javascript (no native dependencies)
  • Exposes files as streams
    • Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished)
    • Seamlessly switches between sequential and rarest-first piece selection strategy
  • Supports advanced torrent client features
  • Comprehensive test suite (runs completely offline, so it's reliable and fast)
  • Check all the supported BEPs here

Browser/WebRTC environment features

  • WebRTC data channels for lightweight peer-to-peer communication with no plugins
  • No silos. WebTorrent is a P2P network for the entire web. WebTorrent clients running on one domain can connect to clients on any other domain.
  • Stream video torrents into a <video> tag (webm, mkv, mp4, ogv, mov, etc (AV1, H264, HEVC*, VP8, VP9, AAC, FLAC, MP3, OPUS, Vorbis, etc))
  • Supports Chrome, Firefox, Opera and Safari.

Install

To install WebTorrent for use in node or the browser with import WebTorrent from 'webtorrent', run:

npm install webtorrent

To install a webtorrent command line program, run:

npm install webtorrent-cli -g

To install a WebTorrent desktop application for Mac, Windows, or Linux, see WebTorrent Desktop.

Ways to help

Who is using WebTorrent today?

Lots of folks!

WebTorrent API Documentation

Read the full API Documentation.

Usage

WebTorrent is the first BitTorrent client that works in the browser, using open web standards (no plugins, just HTML5 and WebRTC)! It's easy to get started!

In the browser

Downloading a file is simple:
import WebTorrent from 'webtorrent'

const client = new WebTorrent()
const magnetURI = '...'

client.add(magnetURI, torrent => {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  for (const file of torrent.files) {
    document.body.append(file.name)
  }
})
Seeding a file is simple, too:
import dragDrop from 'drag-drop'
import WebTorrent from 'webtorrent'

const client = new WebTorrent()

// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop('body', files => {
  client.seed(files, torrent => {
    console.log('Client is seeding:', torrent.infoHash)
  })
})

There are more examples in docs/get-started.md.

Browserify

WebTorrent works great with browserify, an npm package that lets you use node-style require() to organize your browser code and load modules installed by npm (as seen in the previous examples).

Webpack

WebTorrent also works with webpack, another module bundler. However, webpack requires extra configuration which you can find in the webpack bundle config used by webtorrent.

Or, you can just use the pre-built version via import WebTorrent from 'webtorrent/dist/webtorrent.min.js' and skip the webpack configuration.

Script tag

WebTorrent is also available as a standalone script (webtorrent.min.js) which exposes WebTorrent on the window object, so it can be used with just a script tag:

<script type='module'>
  import WebTorrent from 'webtorrent.min.js'
</script>

The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare and MaxCDN) for easy inclusion on your site:

<script type='module'>
  import WebTorrent from 'https://esm.sh/webtorrent'
</script>
Chrome App

If you want to use WebTorrent in a Chrome App, you can include the following script:

<script type='module'>
  import WebTorrent from 'webtorrent.chromeapp.js'
</script>

Be sure to enable the chrome.sockets.udp and chrome.sockets.tcp permissions!

In Node.js

WebTorrent also works in node.js, using the same npm package! It's mad science!

NOTE: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, use webtorrent-hybrid which includes WebRTC support for node.

As a command line app

WebTorrent is also available as a command line app. Here's how to use it:

$ npm install webtorrent-cli -g
$ webtorrent --help

To download a torrent:

$ webtorrent magnet_uri

To stream a torrent to a device like AirPlay or Chromecast, just pass a flag:

$ webtorrent magnet_uri --airplay

There are many supported streaming options:

--airplay               Apple TV
--chromecast            Chromecast
--mplayer               MPlayer
--mpv                   MPV
--omx [jack]            omx [default: hdmi]
--vlc                   VLC
--xbmc                  XBMC
--stdout                standard out [implies --quiet]

In addition to magnet uris, WebTorrent supports many ways to specify a torrent.

Talks about WebTorrent

Modules

Most of the active development is happening inside of small npm packages which are used by WebTorrent.

The Node Way™

"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from "how I write modules"

node.js is shiny

Modules

These are the main modules that make up WebTorrent:

module tests version description
webtorrent torrent client (this module)
bittorrent-dht distributed hash table client
bittorrent-peerid identify client name/version
bittorrent-protocol bittorrent protocol stream
bittorrent-tracker bittorrent tracker server/client
bittorrent-lsd bittorrent local service discovery
create-torrent create .torrent files
magnet-uri parse magnet uris
parse-torrent parse torrent identifiers
torrent-discovery find peers via dht, tracker, and lsd
ut_metadata metadata for magnet uris (protocol extension)
ut_pex peer discovery (protocol extension)

Enable debug logs

In node, enable debug logs by setting the DEBUG environment variable to the name of the module you want to debug (e.g. bittorrent-protocol, or * to print all logs).

DEBUG=* webtorrent

In the browser, enable debug logs by running this in the developer console:

localStorage.setItem('debug', '*')

Disable by running this:

localStorage.removeItem('debug')

License

MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.

bittorrent-dht's People

Contributors

alexandergugel avatar arestov avatar bobrenjc93 avatar chr15m avatar cjb avatar diegorbaquero avatar emilbayes avatar feross avatar greenkeeper[bot] avatar greenkeeperio-bot avatar hackerkid avatar ivantodorovich avatar jimmywarting avatar king-11 avatar luoyetx avatar mafintosh avatar metamystical avatar mihv avatar mvayngrib avatar nazar-pc avatar omgimalexis avatar renovate-bot avatar renovate[bot] avatar robertkowalski avatar semantic-release-bot avatar thaunknown avatar thomasyuan avatar transitive-bullshit avatar trentlarson avatar xaiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bittorrent-dht's Issues

Allow to listen to an alternate IP address

Transmission allow to choose on which IP will transit all the traffic.
Would be nice to allow such feature in your library.
I hacked it but I'd like it to be clean and usable by torrent-search
Thanks

Export for found peers

I haven't found a way to access the retrieved peers from the dht module.
I think one should be able to access all found peers via dht.getPeers() or something.

Only store values when the key is "close" to our own

Right now, we're naively storing any values the network asks us to. This is a potential source of DOS.

"In these networks, a node A only forwards a lookup on key k to another node B if |B−k| < |A−k|, where “−” represents XOR in Kademlia". This approach means we need to have a way to estimate the network size, or at least look at our own table to decide if there are better/closer nodes that could store the key/value instead.

Or, we could take Transmission's approach of storing anything we're asked to, but capping the number of hashes the client is willing to track.

/* The maximum number of peers we store for a given hash. */
#ifndef DHT_MAX_PEERS
#define DHT_MAX_PEERS 2048
#endif

/* The maximum number of hashes we're willing to track. */
#ifndef DHT_MAX_HASHES
#define DHT_MAX_HASHES 16384
#endif

Do now throw, are throw?

I was just reading through the code and I notice that there were lots of error handling in the code. nice but Isn't it frown upon to throw errors in npm packages.. in stead you should past it as the first argument of the callback.

Stricter type checking of messages

Have a validation function for each message type. Validate each message before processing it. This would help to move all the type checking out of the main codebase (where it's sort of an afterthought now) and make it more rigorous.

Should help to prevent future security issues like #87

cc @mafintosh

API for fetched peers for fast download recovering

Using one instance of dht we can add torrent, than after receiving infodicionary stop it/ remove it. And than add it again. But torrent can't just get dht.peers[infoHash] since it is not array of strings but converted by string2compact array. So it's better to have array of strings besides to compactPeerInfo and have index to check it before adding of peer to this array.
Also index can be used to speed up of adding and removing of peers (replace following code)

var exists = peers.some(function (peer) {
    return bufferEqual(peer, compactPeerInfo)
  })

https://github.com/feross/bittorrent-dht/blob/master/client.js#L327

'nodeId' parameter on dht.addNode is required

But on the documentation it's say it optional.

Example:

dht = new DHT({bootstrap: false})
dht.addNode('127.0.0.1:20000') // throws an error!
TypeError: First argument needs to be a number, array or string.
    at new Buffer (buffer.js:188:15)
    at idToBuffer (node_modules\bittorrent-dht\client.js:1196:12)
    at DHT.addNode (node_modules\bittorrent-dht\client.js:278:12)
    ...

Consider refusing to store nodes/peers with local IP addresses

If the DHT returns nodes or peers with local IP addresses, should we store them? That means that a remote attacker can make the DHT or bittorrent peer connect to local services. Is this unsafe?

Local IP ranges:
192.168.0.0 - 192.168.255.255 (65,536 IP addresses)
172.16.0.0 - 172.31.255.255 (1,048,576 IP addresses)
10.0.0.0 - 10.255.255.255 (16,777,216 IP addresses)

Localhost:
127.0.0.1

DHT Vote

Does anyone know how utorrent implements the "vote" system over the DHT?

I looked online but there is next to nothing about it.

Some information:
http://lists.ibiblio.org/pipermail/bittorrent/2011-January/002413.html

http://arxiv.org/ftp/arxiv/papers/1305/1305.0711.pdf

You get a message something like this:

{ a:
   { id: '907050177fb05376db71ce066663819503eb0a9a',
     target: '546d6d0e5aacfae66299f26a300a428c497b23b5',
     token: '5b3f3de3d4f5ba42721dac14b2076dc64bc829da',
     vote: 0 },
  q: 'vote',
  t: '+=\u0000\u0000',
  v: 'UT??',
  y: 'q' }

The only thing I dont get it the target They say its sha1(info-hash + "rating") but i dont know. So the rating 1-5 and 0 been the query for votes. So if a infohash has 5 votes ranging from 1 to 5 would you receive 5 responses?

Has anyone played around with this?

DNS lookup: uv__close: Assertion `fd > -1' failed

Reporting this in case someone else has the problem but this might be specific to my uses.

Maybe related to joyent/libuv#1210

Node version v0.11.9, I did not check the fix for the above bug.

While performing successive lookup in the DHT as explained here: https://github.com/Ayms/torrent-live#findspies it appears that after some time the DNS lookup for the bootstrap nodes does resolve "less and less" until contacts are returned as an empty array.

Then the following error fires:

../deps/uv/src/unix/core.c:413: uv__close: Assertion `fd > -1' failed.

Deactivating the dns lookup does "resolve" the issue.

Not sure if it's a libuv or dns issue, maybe you can close it for now.

Chrome app

How do I use bittorrent-dht in a chrome packaged app. The DNS module does browserify properly.

Should we add ourselves to the peers for an infohash we've announced?

tl;dr When we receive a get_peers for an infohash we have announced, should we include ourselves as a peer? Currently we don't, and I'm not sure whether it's a bug.

Long version:

I've noticed that when one peer receives a get_peers for an infohash it published itself, it returns the K closest nodes instead of itself as a peer. So the upshot is that the only way an announce works is if:

node A announces
node B hears the announce
node C calls get_peers, and node A is returned to node C by node B

Whereas if only two nodes were online, it'd be:

node A announces
node C starts up, calls get_peers, node A receives the get_peers but does not include itself as a peer, so the download can not proceed

Any idea if this is a bug, vs. me misunderstanding the protocol? If it's a bug, is the fix to call _addPeer() for ourselves when we announce?

Bad Argument and Allocation failed

Hi guys, I have a algorithm that check the peers on a torrent, after sometime this error happen:

TypeError: Bad argument
    at new Buffer (buffer.js:194:21)
    at idToBuffer (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:1302:12)
    at DHT._addNode (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:336:12)
    at DHT._onData (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:714:10)
    at Socket.emit (events.js:98:17)
    at UDP.onMessage (dgram.js:440:8)

buffer.js:194
      this.parent = new SlowBuffer(this.length);
                    ^
TypeError: Bad argument
    at new Buffer (buffer.js:194:21)
    at idToBuffer (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:1302:12)
    at DHT._addNode (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:336:12)
    at DHT._onData (/home/dhseja/torrent_crawl/node_modules/bittorrent-dht/client.js:714:10)
    at Socket.emit (events.js:98:17)
    at UDP.onMessage (dgram.js:440:8)
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory

Here is the algorithm:

// checker.js
var torrentStream = require('torrent-stream');
var Discovery = require('torrent-discovery');
var DHT = require('bittorrent-dht');
var parseTorrent = require('parse-torrent');
var hat = require('hat');
var Promise = require('bluebird');


module.exports = function(magnet) {
  return new Promise(function(done) {

    var torrent = parseTorrent(magnet);

    var peers = 0;
    var dht = new DHT();
    dht.lookup(torrent.infoHash);
    var discovery = new Discovery({
      peerId: hat(160),
      port: 6000,
      dht: dht
    });

    try {
      discovery.setTorrent(torrent);
      discovery.on('peer', function() {
        peers++;
      });
    }catch(error) {
      console.log(error);
    }




    setTimeout(function() {
      discovery.stop();
      dht.destroy();
      discovery = undefined;
      done(peers);
    }, 60 * 1000);
  });
}

An example of use:

var checker = require('./checker.js');

checker("magnet:?xt=urn:btih:").then(function(peers) {
 console.log("Peers on this torrent: "+peers);
});

Any idea?
Thanks in advance.

BEP44: storing arbitrary data in the DHT

BEP44 is very exciting because it introduces mutable content signed with a public key. With mutable hashes, applications like twitter-style feeds can be built on the DHT which may prove very useful for projects like ssb. libtorrent and utorrent already have support for dht_store but I'm not sure if anybody is using this feature in the wild yet.

I started implementing this BEP on top of the bittorrent-client plugin system, but it doesn't make much sense to implement on top of bittorrent-client because couples strongly with the dht implementation.

destroy an in-progress `lookup`

I want to download 5 torrents by magnet links in same time. I suppose that I should use 1 bittorrent-dht instance instead of 5 (please fix me if this wrong).

So i will do following

var infoHashes = [..., ..., ...];
//infoHashes.length == 5

var table = dht();

table.on('peer', function(peer, infoHash){
    //do something
});
table.on('ready', function() {
    infoHashes.forEach(function(infoHash){
        table.lookup(infoHash);
    })
});

I want to completely stop downloading infoHashes[2]. What I need to do to destroy lookup for infoHashes[2]?

Remove console statements

Could we maybe remove the console.log(...) stuff from this module and maybe use a debug module instead? I would be happy to contribute a PR.

Accept responses even after timeout

No point to throwing them away, especially if they contain new nodes or peers.

Can we actually use the response, even without the original callback in the self.transactions object?

BEP42: Pick node ID based on external IP (DHT security extension)

We have been looking at securing the DHT, making it harder to attack (especially with sybils). One thing we’re implementing to support this is requiring DHT nodes to calculate their node ID based on their external IP, with some flexibility to support NATs and such. More info on Node ID enforcement can be found here.

Crash on DHT put

(Seen on @substack's dht-store branch, but filing here.)

  bittorrent-dht [2f01a3c] put from 98.100.36.218:6881 +1ms

/home/cjb/gittorrent/node_modules/bittorrent-dht/node_modules/k-bucket/index.js:225
    if ((id.length <= bytesDescribedByBitIndex)
           ^
TypeError: Cannot read property 'length' of undefined
    at KBucket.determineBucket (/home/cjb/gittorrent/node_modules/bittorrent-dht/node_modules/k-bucket/index.js:225:12)
    at KBucket.get (/home/cjb/gittorrent/node_modules/bittorrent-dht/node_modules/k-bucket/index.js:258:18)
    at DHT._onPut (/home/cjb/gittorrent/node_modules/bittorrent-dht/client.js:486:27)
    at DHT._onQuery (/home/cjb/gittorrent/node_modules/bittorrent-dht/client.js:1052:30)
    at DHT._onData (/home/cjb/gittorrent/node_modules/bittorrent-dht/client.js:1036:10)
    at Socket.EventEmitter.emit (events.js:98:17)
    at UDP.onMessage (dgram.js:440:8)

I don't control this node, so have no idea what they were doing :)

improve dht.put api

im currently having to handle dht.put like this:

    dht.put({v: new Buffer('hello world')}, function (errors, hash) {
      if (errors) {
        errors.forEach(function (e) {
          console.log(e)
        })
      }
      console.log(hash)
    })

however, I find the errors array not that useful for the following reasons:

  • there will almost always be errors, since not all clients on the dht support bep44. for example:
{ [Error: 204 Unknown query type.] address: '95.211.211.152:6881' }
{ [Error: 202 Server Error] address: '121.40.163.12:6881' }
{ [Error: query timed out] address: '24.43.1.206:27935' }
{ [Error: query timed out] address: '105.107.66.81:8037' }
{ [Error: query timed out] address: '93.47.84.119:49670' }
{ [Error: query timed out] address: '145.167.133.38:32995' }
{ [Error: query timed out] address: '82.250.244.230:38754' }
{ [Error: query timed out] address: '5.79.212.119:62470' }
{ [Error: query timed out] address: '179.164.228.17:22828' }
{ [Error: query timed out] address: '27.208.33.164:9101' }
{ [Error: query timed out] address: '94.128.247.247:15718' }
{ [Error: query timed out] address: '81.246.190.143:3612' }
{ [Error: query timed out] address: '103.240.161.164:9097' }
{ [Error: query timed out] address: '172.101.33.37:18667' }
{ [Error: query timed out] address: '46.188.123.196:21985' }
  • i have no way of knowing if any of the peers actually stored my key if all I get are the ones who didn't. IMO it should give you back all the successful ones too. there's no way to know how many peers it tried to store it on currently.

other API suggestions welcome!

no results for infohash lookup

The following code snippet yields no peers for the lookup query. no peer is printed to stdout. IF i use the same DHT object for announce and lookup, the correct IP is found. However when creating a new DHT object, the IP is not found.

Am i misusing the library or is this expected behavior and why?

Thanks!

var DHT = require("bittorrent-dht")

var ih = "46f9e9a430f839e7acd76733d649b885985cff4b"
var dht =  new DHT()

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


dht.on('ready', function () {
  console.log("dht is ready")

  dht.announce(ih, 6666, function (r) {
    var otherDHT = new DHT()

    console.log("announce result is " + r)

    otherDHT.listen(20001, function () {
    })
    otherDHT.on('ready', function () {
      console.log("other dht is ready")

      otherDHT.lookup(ih, function (err, r) {
      })
      otherDHT.on('peer', function (addr, ih, from) {
        console.log("got peer " + addr)
      })
    })
  })
})

lookup with 3+ DHTs fails occasionally (non-deterministically)

Edit: I guess for 2 it doesn't work because nodes don't know their own ips

I wanted to see if how many DHT instances with each other in their routing tables were enough to do announce + successful lookup. I hoped 2, but as a DHT node never returns itself as a peer, this appears to be impossible. Is this by design? 4+ are usually enough, but not always, which makes me think there's some race condition.

test('test announce+lookup with different quantities of DHTs', function (t) {
  var from = 2;
  var to = 10;

  t.plan(to - from + 1);

  for (var i = from; i <= to; i++) {
    (function(numInstances) {      
      findPeers(numInstances, t, function(err) {
        if (err) t.error(err)
        else t.pass('Success with ' + numInstances + ' instances')
      });
    })(i)
  }
})

/**
 *  Initialize [numInstances] dhts, have one announce an infoHash and another perform a lookup
 *  Times out after a while
 */
function findPeers(numInstances, t, cb) {
  var timeoutId = setTimeout(function() {
    cleanup(new Error('Timed out for ' + numInstances + ' instances'))
  }, 5000);

  var infoHash = common.randomId()
  var dhts = [];

  for (var i = 0; i < numInstances; i++) {
    var dht = new DHT({ bootstrap: false });
    dhts.push(dht);
    common.failOnWarningOrError(dht, t);
  }

  // wait till everyone's listening
  parallel(dhts.map(function(dht) {
    return function(cb) {
      dht.listen(function(port) {
        cb(null, port);
      })
    }
  }), function(err, ports) {
    // add each other to routing tables
    makeFriends(dhts);
    dhts[0].announce(infoHash, 9999, function() {
      dhts[1].lookup(infoHash)      
    })
  })


  dhts[1].on('peer', function(addr, hash) {
    if (hash === infoHash.toString('hex')) {
      cleanup()
    }
  })

  function cleanup(err) {
    parallel(dhts.map(function(dht) {
      return dht.destroy.bind(dht)
    }), function() {
      clearTimeout(timeoutId)
      cb(err)
    })
  }
}

/**
 *  Adds every dht in [dhts] to every other dht's routing table
 */
function makeFriends(dhts) {
  for (var i = 0; i < dhts.length; i++) {
    for (var j = i + 1; j < dhts.length; j++) {
      var d1 = dhts[i]
      var d2 = dhts[j]
      d1.addNode('127.0.0.1:' + d2.port, d2.nodeId)
      d2.addNode('127.0.0.1:' + d1.port, d1.nodeId)
    }
  }
}

crash

hello,

after some time, i got this error :

buffer.js:98
const ui8 = new Uint8Array(size);
^

RangeError: Invalid typed array length
at new Uint8Array (native)
at allocate (buffer.js:98:17)
at new Buffer (buffer.js:49:12)
at idToBuffer (/root/scripts/tracker/node_modules/bittorrent-dht/client.js:1639:12)
at DHT._addNode (/root/scripts/tracker/node_modules/bittorrent-dht/client.js:630:12)
at DHT._onData (/root/scripts/tracker/node_modules/bittorrent-dht/client.js:1025:10)
at emitTwo (events.js:87:13)
at Socket.emit (events.js:172:7)
at UDP.onMessage (dgram.js:481:8)

any idea ?

Best regards,
tsukasagenesis

Metadata gathering speedup question

How I can start exchanging of peers with passed to bittorrent-dht peers from outside?

e.g. a:

  1. I got some peers 2) I cached them 2) I destroyed bittorrent-dht instance 3) I start new bittorrent-dht instance after 30 minutes and want to pass it cached peers

  2. app does not have metadata (infoDictionary), but has infoHash.
    App got some peers from trackers, but did not get any from DHT (even with BOOTSTRAP_NODES help).

Bootstrap timeout just fires once

If a boostrap timeout occurs, the boostrap process is retried but no other timeout is set in case the boostrap process does not succeed again.

DHT crawling

Hi just a quick question. Is there anyway I can crawl the bittorrent dht using this package. I have seen various implementations but they do not use this package. I am just stuck on how i can acquire the infohash of the swarm of various bittorrent peers. I have 0.05 BTC available for an appropriate solution Any help would be much appreciated. Cheers.

Persisting a unique DHT for different lookup and updating the routing table

Am I reading the code wrongly or it is not possible right now to create once a dht and persist it for different lookup, as well as updating the routing table continuously (and testing the nodes)? (as far as I see the routing table is supposed to be recreated for each lookup)

I saw #16 but apparently the fix is to bootstrap the dht at creation.

Is it on purpose, or in the TODO list?

Race condition with publicAddresses

Hi, I'm seeing a race that leads to announces only happening on private IPs instead of public ones:

  bittorrent-dht [2ab538e] announce 5fbfea8de70ddc686dafdd24b690893f98eb9475 30000 +3ms
debug: in self.localAddresses.forEach with 10.20.30.3
  bittorrent-dht [2ab538e] addPeer 10.20.30.3:30000 5fbfea8de70ddc686dafdd24b690893f98eb9475 +2ms
  bittorrent-dht [2ab538e] announce end 5fbfea8de70ddc686dafdd24b690893f98eb9475 30000 +0ms
debug: in publicAddress with 192.34.86.36
[publicAddress is added to self.localAddresses here, too late for the announce's forEach loop over self.localAddresses]

(I wonder why we're announcing on private IPs anyway?)

EventEmitter warns about possible memory leak when running concurrent DHT instances

For testing purposes, I attempted to run the following code (CoffeeScript):

BTDHT = require "bittorrent-dht"

dht1 = new BTDHT()
dht1.on "ready", -> console.log("dht1 ready"); dht1.lookup("dht-test")
    .on "peer", (addr, hash) -> console.log("Found peer for #{hash} at #{addr} on dht1")
    .listen 20000, -> console.log("dht1 listening")

dht2 = new BTDHT()
dht2.on "ready", -> console.log("dht2 ready"); dht2.lookup("dht-test")
    .on "peer", (addr, hash) -> console.log("Found peer for #{hash} at #{addr} on dht2")
    .listen 20000, -> console.log("dht2 listening")

Compiled Javascript is as follows:

(function() {
  var BTDHT, dht1, dht2;

  BTDHT = require("bittorrent-dht");

  dht1 = new BTDHT();

  dht1.on("ready", function() {
    console.log("dht1 ready");
    return dht1.lookup("dht-test");
  }).on("peer", function(addr, hash) {
    return console.log("Found peer for " + hash + " at " + addr + " on dht1");
  }).listen(20000, function() {
    return console.log("dht1 listening");
  });

  dht2 = new BTDHT();

  dht2.on("ready", function() {
    console.log("dht2 ready");
    return dht2.lookup("dht-test");
  }).on("peer", function(addr, hash) {
    return console.log("Found peer for " + hash + " at " + addr + " on dht2");
  }).listen(20000, function() {
    return console.log("dht2 listening");
  });

}).call(this);

... and that resulted in this:

dht1 listening
dht2 listening
dht2 ready
dht1 ready
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
  at DHT.EventEmitter.addListener (events.js:160:15)
  at /home/sven/projects/syncy/node_modules/bittorrent-dht/client.js:330:10
  at /home/sven/projects/syncy/node_modules/bittorrent-dht/client.js:395:5
  at done (/home/sven/projects/syncy/node_modules/bittorrent-dht/node_modules/run-parallel/index.js:15:13)
  at /home/sven/projects/syncy/node_modules/bittorrent-dht/client.js:388:9
  at asyncCallback (dns.js:68:16)
  at Object.onanswer [as oncomplete] (dns.js:119:9)

I cannot reproduce the issue when commenting out the second instance, it only appears to happen with 2 (or more?) instances. I've successfully reproduced the issue on another system as well.

Affected configurations:

  • openSUSE 12.3 x64, Node.js v0.10.26, bittorrent-dht 1.1.1
  • Debian 7 x64, Node.js v0.10.26, bittorrent-dht 1.1.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.