Skip to content

Commit 2d37acd

Browse files
committed
feat: torrentHost, interface binding
1 parent 527b34a commit 2d37acd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# torrent-discovery [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
22

33
[ci-image]: https://github.com/webtorrent/torrent-discovery/actions/workflows/ci.yml/badge.svg
4+
45
[ci-url]: https://github.com/webtorrent/torrent-discovery/actions/workflows/ci.yml
6+
57
[npm-image]: https://img.shields.io/npm/v/torrent-discovery.svg
8+
69
[npm-url]: https://npmjs.org/package/torrent-discovery
10+
711
[downloads-image]: https://img.shields.io/npm/dm/torrent-discovery.svg
12+
813
[downloads-url]: https://npmjs.org/package/torrent-discovery
14+
915
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
16+
1017
[standard-url]: https://standardjs.com
1118

1219
### Discover BitTorrent and WebTorrent peers
@@ -15,10 +22,10 @@ This module bundles [bittorrent-tracker](https://www.npmjs.com/package/bittorren
1522

1623
## features
1724

18-
- simple API
19-
- find peers from trackers, DHT, and LSD
20-
- automatically announces, so other peers can discover us
21-
- can start finding peers with just an info hash, before full metadata is available
25+
* simple API
26+
* find peers from trackers, DHT, and LSD
27+
* automatically announces, so other peers can discover us
28+
* can start finding peers with just an info hash, before full metadata is available
2229

2330
This module also **works in the browser** with [browserify](http://browserify.org). In
2431
that context, it discovers [WebTorrent](http://webtorrent.io) (WebRTC) peers.
@@ -39,7 +46,8 @@ Create a new peer discovery instance. Required options are:
3946
{
4047
infoHash: '', // as hex string or Buffer
4148
peerId: '', // as hex string or Buffer
42-
port: 0 // torrent client port (only required in node)
49+
port: 0, // torrent client port (only required in node)
50+
host: '0.0.0.0' // torrent client host or network interface to bind to
4351
}
4452
```
4553

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Discovery extends EventEmitter {
2323
? opts.infoHash.toLowerCase()
2424
: opts.infoHash.toString('hex')
2525
this._port = opts.port // torrent port
26+
this._host = opts.host || '::'
2627
this._userAgent = opts.userAgent // User-Agent header for http requests
2728

2829
this.destroyed = false
@@ -58,7 +59,7 @@ class Discovery extends EventEmitter {
5859
const dht = new DHT(opts)
5960
dht.on('warning', this._onWarning)
6061
dht.on('error', this._onError)
61-
dht.listen(port)
62+
dht.listen(port, this._host)
6263
this._internalDHT = true
6364
return dht
6465
}
@@ -169,6 +170,7 @@ class Discovery extends EventEmitter {
169170
announce: this._announce,
170171
peerId: this.peerId,
171172
port: this._port,
173+
host: this._host,
172174
userAgent: this._userAgent
173175
})
174176

@@ -209,7 +211,8 @@ class Discovery extends EventEmitter {
209211
const opts = Object.assign({}, {
210212
infoHash: this.infoHash,
211213
peerId: this.peerId,
212-
port: this._port
214+
port: this._port,
215+
host: this._host
213216
})
214217

215218
const lsd = new LSD(opts)

0 commit comments

Comments
 (0)