Skip to content

Commit e57ab7c

Browse files
committed
feat: torrentHost, interface binding
1 parent bb52003 commit e57ab7c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# bittorrent-lsd [![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/bittorrent-lsd/actions/workflows/ci.yml/badge.svg?branch=master
4+
45
[ci-url]: https://github.com/webtorrent/bittorrent-lsd/actions/workflows/ci.yml
6+
57
[npm-image]: https://img.shields.io/npm/v/bittorrent-lsd.svg
8+
69
[npm-url]: https://npmjs.org/package/bittorrent-lsd
10+
711
[downloads-image]: https://img.shields.io/npm/dm/bittorrent-lsd.svg
12+
813
[downloads-url]: https://npmjs.org/package/bittorrent-lsd
14+
915
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
16+
1017
[standard-url]: https://standardjs.com
1118

1219
### Local Service Discovery (BEP14) implementation.
@@ -27,7 +34,8 @@ npm install bittorrent-lsd
2734
const opts = {
2835
peerId: new Buffer('01234567890123456789'), // hex string or Buffer
2936
infoHash: new Buffer('01234567890123456789'), // hex string or Buffer
30-
port: common.randomPort() // torrent client port
37+
port: common.randomPort(), // torrent client port
38+
host: '0.0.0.0' // torrent client host or network interface to bind to
3139
}
3240
3341
const lsd = new LSD(opts)
@@ -45,23 +53,29 @@ lsd.destroy()
4553
## api
4654

4755
### `lsd = new LSD([opts])`
56+
4857
Create a new `lsd` instance.
4958

5059
### `lsd.start()`
60+
5161
Start listening and sending (every 5 minutes) for local network announces.
5262

5363
### `lsd.destroy([callback])`
64+
5465
Destroy the LSD. Closes the socket and cleans up resources.
5566

5667
## events
5768

5869
### `lsd.on('peer', (peerAddress, infoHash) => { ... })`
70+
5971
Emitted when a potential peer is found. `peerAddress` is of the form `host:port`. `infoHash` is the torrent info hash.
6072

6173
### `lsd.on('warning', (err) => { ... })`
74+
6275
Emitted when the LSD gets an unexpected message.
6376

6477
### `lsd.on('error', (err) => { ... })`
78+
6579
Emitted when the LSD has a fatal error.
6680

6781
## license

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class LSD extends EventEmitter {
3333

3434
this.cookie = `bittorrent-lsd-${this.peerId}`
3535

36+
this._host = opts.host
37+
3638
this.destroyed = false
3739
this.annouceIntervalId = null
3840

@@ -139,7 +141,7 @@ class LSD extends EventEmitter {
139141

140142
start () {
141143
debug('start')
142-
this.server.bind(LSD_PORT)
144+
this.server.bind(LSD_PORT, this._host)
143145
this._announce()
144146

145147
this.annouceIntervalId = setInterval(() => {

0 commit comments

Comments
 (0)