Skip to content

Commit

Permalink
feat: torrentHost, interface binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed Nov 16, 2024
1 parent 527b34a commit a18b617
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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
}
```

Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -169,6 +170,7 @@ class Discovery extends EventEmitter {
announce: this._announce,
peerId: this.peerId,
port: this._port,
host: this._host,
userAgent: this._userAgent
})

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a18b617

Please sign in to comment.