From a18b617d949299a377f77892cc9e5ce7be92eb49 Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:04:09 +0100 Subject: [PATCH] feat: torrentHost, interface binding --- README.md | 18 +++++++++++++----- index.js | 7 +++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dcb3abc8..17812df6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ # torrent-discovery [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] [ci-image]: https://github.com/webtorrent/torrent-discovery/actions/workflows/ci.yml/badge.svg + [ci-url]: https://github.com/webtorrent/torrent-discovery/actions/workflows/ci.yml + [npm-image]: https://img.shields.io/npm/v/torrent-discovery.svg + [npm-url]: https://npmjs.org/package/torrent-discovery + [downloads-image]: https://img.shields.io/npm/dm/torrent-discovery.svg + [downloads-url]: https://npmjs.org/package/torrent-discovery + [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg + [standard-url]: https://standardjs.com ### Discover BitTorrent and WebTorrent peers @@ -15,10 +22,10 @@ This module bundles [bittorrent-tracker](https://www.npmjs.com/package/bittorren ## features -- simple API -- find peers from trackers, DHT, and LSD -- automatically announces, so other peers can discover us -- can start finding peers with just an info hash, before full metadata is available +* simple API +* find peers from trackers, DHT, and LSD +* automatically announces, so other peers can discover us +* can start finding peers with just an info hash, before full metadata is available This module also **works in the browser** with [browserify](http://browserify.org). In that context, it discovers [WebTorrent](http://webtorrent.io) (WebRTC) peers. @@ -39,7 +46,8 @@ Create a new peer discovery instance. Required options are: { infoHash: '', // as hex string or Buffer peerId: '', // as hex string or Buffer - port: 0 // torrent client port (only required in node) + port: 0, // torrent client port (only required in node) + host: '0.0.0.0' // torrent client host or network interface to bind to } ``` diff --git a/index.js b/index.js index 27a7f047..c439e9f4 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ class Discovery extends EventEmitter { ? opts.infoHash.toLowerCase() : opts.infoHash.toString('hex') this._port = opts.port // torrent port + this._host = opts.host this._userAgent = opts.userAgent // User-Agent header for http requests this.destroyed = false @@ -58,7 +59,7 @@ class Discovery extends EventEmitter { const dht = new DHT(opts) dht.on('warning', this._onWarning) dht.on('error', this._onError) - dht.listen(port) + dht.listen(port, this._host) this._internalDHT = true return dht } @@ -169,6 +170,7 @@ class Discovery extends EventEmitter { announce: this._announce, peerId: this.peerId, port: this._port, + host: this._host, userAgent: this._userAgent }) @@ -209,7 +211,8 @@ class Discovery extends EventEmitter { const opts = Object.assign({}, { infoHash: this.infoHash, peerId: this.peerId, - port: this._port + port: this._port, + host: this._host }) const lsd = new LSD(opts)