Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: torrentHost, interface binding #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading