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 bb52003 commit e57ab7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# bittorrent-lsd [![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/bittorrent-lsd/actions/workflows/ci.yml/badge.svg?branch=master

[ci-url]: https://github.com/webtorrent/bittorrent-lsd/actions/workflows/ci.yml

[npm-image]: https://img.shields.io/npm/v/bittorrent-lsd.svg

[npm-url]: https://npmjs.org/package/bittorrent-lsd

[downloads-image]: https://img.shields.io/npm/dm/bittorrent-lsd.svg

[downloads-url]: https://npmjs.org/package/bittorrent-lsd

[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg

[standard-url]: https://standardjs.com

### Local Service Discovery (BEP14) implementation.
Expand All @@ -27,7 +34,8 @@ npm install bittorrent-lsd
const opts = {
peerId: new Buffer('01234567890123456789'), // hex string or Buffer
infoHash: new Buffer('01234567890123456789'), // hex string or Buffer
port: common.randomPort() // torrent client port
port: common.randomPort(), // torrent client port
host: '0.0.0.0' // torrent client host or network interface to bind to
}
const lsd = new LSD(opts)
Expand All @@ -45,23 +53,29 @@ lsd.destroy()
## api

### `lsd = new LSD([opts])`

Create a new `lsd` instance.

### `lsd.start()`

Start listening and sending (every 5 minutes) for local network announces.

### `lsd.destroy([callback])`

Destroy the LSD. Closes the socket and cleans up resources.

## events

### `lsd.on('peer', (peerAddress, infoHash) => { ... })`

Emitted when a potential peer is found. `peerAddress` is of the form `host:port`. `infoHash` is the torrent info hash.

### `lsd.on('warning', (err) => { ... })`

Emitted when the LSD gets an unexpected message.

### `lsd.on('error', (err) => { ... })`

Emitted when the LSD has a fatal error.

## license
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class LSD extends EventEmitter {

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

this._host = opts.host

this.destroyed = false
this.annouceIntervalId = null

Expand Down Expand Up @@ -139,7 +141,7 @@ class LSD extends EventEmitter {

start () {
debug('start')
this.server.bind(LSD_PORT)
this.server.bind(LSD_PORT, this._host)
this._announce()

this.annouceIntervalId = setInterval(() => {
Expand Down

0 comments on commit e57ab7c

Please sign in to comment.