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 #61

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
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
Loading