From e57ab7c46d12fa8d0481a6637b0d7a85294e1b1f Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:12:34 +0100 Subject: [PATCH] feat: torrentHost, interface binding --- README.md | 16 +++++++++++++++- index.js | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ed04bc..1d0a10f 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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) @@ -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 diff --git a/index.js b/index.js index b91abfa..193170c 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,8 @@ class LSD extends EventEmitter { this.cookie = `bittorrent-lsd-${this.peerId}` + this._host = opts.host + this.destroyed = false this.annouceIntervalId = null @@ -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(() => {