Skip to content

Commit 221e542

Browse files
authored
Merge branch 'webtorrent:master' into cjs
2 parents 90d0608 + a4f956e commit 221e542

35 files changed

+683
-504
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
os:
1313
- ubuntu-latest
1414
node:
15-
- '14'
15+
- '18'
1616
steps:
1717
- uses: actions/checkout@v3
1818
- uses: actions/setup-node@v3

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup Node.js
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: 14
20+
node-version: 18
2121
- name: Cache
2222
uses: actions/cache@v3
2323
with:

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
pull-requests: write
1313

1414
steps:
15-
- uses: actions/stale@v5
15+
- uses: actions/stale@v8
1616
with:
1717
repo-token: ${{ secrets.GITHUB_TOKEN }}
1818
stale-issue-message: 'Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?'

AUTHORS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,10 @@
6161
- Ryan Finnie ([email protected])
6262
6363
- Paul Sharypov ([email protected])
64+
65+
- Tom Snelling ([email protected])
66+
67+
- Arsène Fougerouse ([email protected])
68+
- Brad Marsden ([email protected])
6469

6570
#### Generated by tools/update-authors.sh.

CHANGELOG.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,140 @@
1+
## [11.0.2](https://github.com/webtorrent/bittorrent-tracker/compare/v11.0.1...v11.0.2) (2024-03-12)
2+
3+
4+
### Bug Fixes
5+
6+
* **parse-http:** ignore announcements from peers with invalid announcement ports. ([#513](https://github.com/webtorrent/bittorrent-tracker/issues/513)) ([fe75272](https://github.com/webtorrent/bittorrent-tracker/commit/fe75272d51653e626583689081afb0b7aeadb84f))
7+
8+
## [11.0.1](https://github.com/webtorrent/bittorrent-tracker/compare/v11.0.0...v11.0.1) (2024-01-16)
9+
10+
11+
### Bug Fixes
12+
13+
* update build badge url ([#506](https://github.com/webtorrent/bittorrent-tracker/issues/506)) ([3f59b58](https://github.com/webtorrent/bittorrent-tracker/commit/3f59b58a020ea8c0926be135471a6666fe8e8b21))
14+
15+
# [11.0.0](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.12...v11.0.0) (2023-10-31)
16+
17+
18+
### Features
19+
20+
* **major:** drop simple-get ([#443](https://github.com/webtorrent/bittorrent-tracker/issues/443)) ([bce64e1](https://github.com/webtorrent/bittorrent-tracker/commit/bce64e155df6ff9fa605898cbf7498bf76188d8b))
21+
22+
23+
### BREAKING CHANGES
24+
25+
* **major:** drop simple-get
26+
27+
* perf: drop simple-get
28+
29+
* feat: undici agent and socks
30+
31+
* fix: undici as dev dependency
32+
33+
* feat: require user passed proxy objects for http and ws
34+
35+
* chore: include undici for tests
36+
37+
## [10.0.12](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.11...v10.0.12) (2023-08-09)
38+
39+
40+
### Bug Fixes
41+
42+
* **deps:** update dependency bencode to v4 ([#487](https://github.com/webtorrent/bittorrent-tracker/issues/487)) ([aeccf9c](https://github.com/webtorrent/bittorrent-tracker/commit/aeccf9c1c4b9115fd23b4fe1a0ab990b5add0f17))
43+
44+
## [10.0.11](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.10...v10.0.11) (2023-08-01)
45+
46+
47+
### Bug Fixes
48+
49+
* mangled scrape infohashes ([#486](https://github.com/webtorrent/bittorrent-tracker/issues/486)) ([11cce83](https://github.com/webtorrent/bittorrent-tracker/commit/11cce83ddd858813f5684da8a116de4bee6e518b))
50+
51+
## [10.0.10](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.9...v10.0.10) (2023-06-16)
52+
53+
54+
### Performance Improvements
55+
56+
* use simple-peer/lite ([#475](https://github.com/webtorrent/bittorrent-tracker/issues/475)) ([5b8db06](https://github.com/webtorrent/bittorrent-tracker/commit/5b8db067e48cc81796728ff538d7ff6efafc59b8))
57+
58+
## [10.0.9](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.8...v10.0.9) (2023-06-16)
59+
60+
61+
### Performance Improvements
62+
63+
* use peer/lite ([#474](https://github.com/webtorrent/bittorrent-tracker/issues/474)) ([7c845f0](https://github.com/webtorrent/bittorrent-tracker/commit/7c845f030d07b1bf7060ab880b790ee85a8c7ac0))
64+
65+
## [10.0.8](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.7...v10.0.8) (2023-06-07)
66+
67+
68+
### Bug Fixes
69+
70+
* bigInt ([#472](https://github.com/webtorrent/bittorrent-tracker/issues/472)) ([d7061f7](https://github.com/webtorrent/bittorrent-tracker/commit/d7061f73b2ebff072e064971a5960749a7335bae))
71+
72+
## [10.0.7](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.6...v10.0.7) (2023-06-05)
73+
74+
75+
### Bug Fixes
76+
77+
* imports ([#471](https://github.com/webtorrent/bittorrent-tracker/issues/471)) ([a12022a](https://github.com/webtorrent/bittorrent-tracker/commit/a12022ac2c81d7fa3ecb81163852161e64199cf4))
78+
79+
## [10.0.6](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.5...v10.0.6) (2023-05-27)
80+
81+
82+
### Bug Fixes
83+
84+
* replace simple-peer with maintained one ([#466](https://github.com/webtorrent/bittorrent-tracker/issues/466)) ([3b2dedb](https://github.com/webtorrent/bittorrent-tracker/commit/3b2dedb4151615831ca12d3d0a830354b1c04e68))
85+
86+
## [10.0.5](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.4...v10.0.5) (2023-05-27)
87+
88+
89+
### Bug Fixes
90+
91+
* only stringify views ([#467](https://github.com/webtorrent/bittorrent-tracker/issues/467)) ([52f5502](https://github.com/webtorrent/bittorrent-tracker/commit/52f55020f38894e4d45e12c87184540d8b0acad3))
92+
93+
## [10.0.4](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.3...v10.0.4) (2023-05-26)
94+
95+
96+
### Bug Fixes
97+
98+
* drop buffer ([#465](https://github.com/webtorrent/bittorrent-tracker/issues/465)) ([c99eb89](https://github.com/webtorrent/bittorrent-tracker/commit/c99eb892088ef3c67ea5bf014dfdd86799251a7e))
99+
100+
## [10.0.3](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.2...v10.0.3) (2023-05-25)
101+
102+
103+
### Performance Improvements
104+
105+
* replace simple websocket with maintained one ([#464](https://github.com/webtorrent/bittorrent-tracker/issues/464)) ([3f01c29](https://github.com/webtorrent/bittorrent-tracker/commit/3f01c29122efd726d805673da82f43ce5592b793))
106+
107+
## [10.0.2](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.1...v10.0.2) (2023-02-01)
108+
109+
110+
### Bug Fixes
111+
112+
* **deps:** update dependency ws to v8 ([#448](https://github.com/webtorrent/bittorrent-tracker/issues/448)) ([2209d4f](https://github.com/webtorrent/bittorrent-tracker/commit/2209d4f21bdee10e575c1728c3accf7bd34380c9)), closes [#449](https://github.com/webtorrent/bittorrent-tracker/issues/449)
113+
114+
## [10.0.1](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.0...v10.0.1) (2022-12-07)
115+
116+
117+
### Bug Fixes
118+
119+
* **deps:** update dependency bencode to v3 ([#434](https://github.com/webtorrent/bittorrent-tracker/issues/434)) [skip ci] ([926ceee](https://github.com/webtorrent/bittorrent-tracker/commit/926ceee0bac6dfe49877566aaa3cf645689492d1))
120+
* **deps:** update dependency string2compact to v2 ([#437](https://github.com/webtorrent/bittorrent-tracker/issues/437)) ([9be843c](https://github.com/webtorrent/bittorrent-tracker/commit/9be843c5e46ac2ab518187bf0d348e1e69e8633d))
121+
122+
# [10.0.0](https://github.com/webtorrent/bittorrent-tracker/compare/v9.19.0...v10.0.0) (2022-12-05)
123+
124+
125+
### Features
126+
127+
* esm ([#431](https://github.com/webtorrent/bittorrent-tracker/issues/431)) ([e6d3189](https://github.com/webtorrent/bittorrent-tracker/commit/e6d3189edf1a170197a799b97d84c632692b394f))
128+
129+
130+
### BREAKING CHANGES
131+
132+
* ESM only
133+
134+
* feat: esm
135+
136+
* fix: linter oops
137+
1138
# [9.19.0](https://github.com/webtorrent/bittorrent-tracker/compare/v9.18.6...v9.19.0) (2022-06-01)
2139

3140

README.md

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bittorrent-tracker [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
22

3-
[ci-image]: https://img.shields.io/github/workflow/status/webtorrent/bittorrent-tracker/ci/master
3+
[ci-image]: https://img.shields.io/github/actions/workflow/status/webtorrent/bittorrent-tracker/ci.yml
44
[ci-url]: https://github.com/webtorrent/bittorrent-tracker/actions
55
[npm-image]: https://img.shields.io/npm/v/bittorrent-tracker.svg
66
[npm-url]: https://npmjs.org/package/bittorrent-tracker
@@ -55,16 +55,16 @@ npm install bittorrent-tracker
5555
To connect to a tracker, just do this:
5656

5757
```js
58-
var Client = require('bittorrent-tracker')
58+
import Client from 'bittorrent-tracker'
5959

60-
var requiredOpts = {
60+
const requiredOpts = {
6161
infoHash: new Buffer('012345678901234567890'), // hex string or Buffer
6262
peerId: new Buffer('01234567890123456789'), // hex string or Buffer
6363
announce: [], // list of tracker server urls
6464
port: 6881 // torrent client port, (in browser, optional)
6565
}
6666

67-
var optionalOpts = {
67+
const optionalOpts = {
6868
// RTCPeerConnection config object (only used in browser)
6969
rtcConfig: {},
7070
// User-Agent header for http requests
@@ -81,47 +81,24 @@ var optionalOpts = {
8181
customParam: 'blah' // custom parameters supported
8282
}
8383
},
84-
// Proxy config object
84+
// Proxy options (used to proxy requests in node)
8585
proxyOpts: {
86-
// Socks proxy options (used to proxy requests in node)
87-
socksProxy: {
88-
// Configuration from socks module (https://github.com/JoshGlazebrook/socks)
89-
proxy: {
90-
// IP Address of Proxy (Required)
91-
ipaddress: "1.2.3.4",
92-
// TCP Port of Proxy (Required)
93-
port: 1080,
94-
// Proxy Type [4, 5] (Required)
95-
// Note: 4 works for both 4 and 4a.
96-
// Type 4 does not support UDP association relay
97-
type: 5,
98-
99-
// SOCKS 4 Specific:
100-
101-
// UserId used when making a SOCKS 4/4a request. (Optional)
102-
userid: "someuserid",
103-
104-
// SOCKS 5 Specific:
105-
106-
// Authentication used for SOCKS 5 (when it's required) (Optional)
107-
authentication: {
108-
username: "Josh",
109-
password: "somepassword"
110-
}
111-
},
112-
113-
// Amount of time to wait for a connection to be established. (Optional)
114-
// - defaults to 10000ms (10 seconds)
115-
timeout: 10000
116-
},
117-
// NodeJS HTTP agents (used to proxy HTTP and Websocket requests in node)
118-
// Populated with Socks.Agent if socksProxy is provided
119-
httpAgent: {},
120-
httpsAgent: {}
86+
// For WSS trackers this is always a http.Agent
87+
// For UDP trackers this is an object of options for the Socks Connection
88+
// For HTTP trackers this is either an undici Agent if using Node16 or later, or http.Agent if using versions prior to Node 16, ex:
89+
// import Socks from 'socks'
90+
// proxyOpts.socksProxy = new Socks.Agent(optionsObject, isHttps)
91+
// or if using Node 16 or later
92+
// import { socksDispatcher } from 'fetch-socks'
93+
// proxyOpts.socksProxy = socksDispatcher(optionsObject)
94+
socksProxy: new SocksProxy(socksOptionsObject),
95+
// Populated with socksProxy if it's provided
96+
httpAgent: new http.Agent(agentOptionsObject),
97+
httpsAgent: new https.Agent(agentOptionsObject)
12198
},
12299
}
123100

124-
var client = new Client(requiredOpts)
101+
const client = new Client(requiredOpts)
125102

126103
client.on('error', function (err) {
127104
// fatal client error!
@@ -182,7 +159,7 @@ client.on('scrape', function (data) {
182159
To start a BitTorrent tracker server to track swarms of peers:
183160

184161
```js
185-
const Server = require('bittorrent-tracker').Server
162+
import { Server } from 'bittorrent-tracker'
186163

187164
const server = new Server({
188165
udp: true, // enable udp server? [default=true]
@@ -289,7 +266,7 @@ The http server will handle requests for the following paths: `/announce`, `/scr
289266
Scraping multiple torrent info is possible with a static `Client.scrape` method:
290267

291268
```js
292-
var Client = require('bittorrent-tracker')
269+
import Client from 'bittorrent-tracker'
293270
Client.scrape({ announce: announceUrl, infoHash: [ infoHash1, infoHash2 ]}, function (err, results) {
294271
results[infoHash1].announce
295272
results[infoHash1].infoHash

bin/cmd.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const minimist = require('minimist')
4-
const Server = require('../').Server
3+
import minimist from 'minimist'
4+
import { Server } from '../index.js'
55

66
const argv = minimist(process.argv.slice(2), {
77
alias: {

client.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
const debug = require('debug')('bittorrent-tracker:client')
2-
const EventEmitter = require('events')
3-
const once = require('once')
4-
const parallel = require('run-parallel')
5-
const Peer = require('simple-peer')
6-
const queueMicrotask = require('queue-microtask')
7-
8-
const common = require('./lib/common')
9-
const HTTPTracker = require('./lib/client/http-tracker') // empty object in browser
10-
const UDPTracker = require('./lib/client/udp-tracker') // empty object in browser
11-
const WebSocketTracker = require('./lib/client/websocket-tracker')
1+
import Debug from 'debug'
2+
import EventEmitter from 'events'
3+
import once from 'once'
4+
import parallel from 'run-parallel'
5+
import Peer from '@thaunknown/simple-peer/lite.js'
6+
import queueMicrotask from 'queue-microtask'
7+
import { hex2arr, hex2bin, text2arr, arr2hex, arr2text } from 'uint8-util'
8+
9+
import common from './lib/common.js'
10+
import HTTPTracker from './lib/client/http-tracker.js' // empty object in browser
11+
import UDPTracker from './lib/client/udp-tracker.js' // empty object in browser
12+
import WebSocketTracker from './lib/client/websocket-tracker.js'
13+
14+
const debug = Debug('bittorrent-tracker:client')
1215

1316
/**
1417
* BitTorrent tracker client.
1518
*
1619
* Find torrent peers, to help a torrent client participate in a torrent swarm.
1720
*
1821
* @param {Object} opts options object
19-
* @param {string|Buffer} opts.infoHash torrent info hash
20-
* @param {string|Buffer} opts.peerId peer id
22+
* @param {string|Uint8Array} opts.infoHash torrent info hash
23+
* @param {string|Uint8Array} opts.peerId peer id
2124
* @param {string|Array.<string>} opts.announce announce
2225
* @param {number} opts.port torrent client listening port
2326
* @param {function} opts.getAnnounceOpts callback to provide data to tracker
@@ -37,15 +40,15 @@ class Client extends EventEmitter {
3740

3841
this.peerId = typeof opts.peerId === 'string'
3942
? opts.peerId
40-
: opts.peerId.toString('hex')
41-
this._peerIdBuffer = Buffer.from(this.peerId, 'hex')
42-
this._peerIdBinary = this._peerIdBuffer.toString('binary')
43+
: arr2hex(opts.peerId)
44+
this._peerIdBuffer = hex2arr(this.peerId)
45+
this._peerIdBinary = hex2bin(this.peerId)
4346

4447
this.infoHash = typeof opts.infoHash === 'string'
4548
? opts.infoHash.toLowerCase()
46-
: opts.infoHash.toString('hex')
47-
this._infoHashBuffer = Buffer.from(this.infoHash, 'hex')
48-
this._infoHashBinary = this._infoHashBuffer.toString('binary')
49+
: arr2hex(opts.infoHash)
50+
this._infoHashBuffer = hex2arr(this.infoHash)
51+
this._infoHashBinary = hex2bin(this.infoHash)
4952

5053
debug('new client %s', this.infoHash)
5154

@@ -67,7 +70,7 @@ class Client extends EventEmitter {
6770

6871
// Remove trailing slash from trackers to catch duplicates
6972
announce = announce.map(announceUrl => {
70-
announceUrl = announceUrl.toString()
73+
if (ArrayBuffer.isView(announceUrl)) announceUrl = arr2text(announceUrl)
7174
if (announceUrl[announceUrl.length - 1] === '/') {
7275
announceUrl = announceUrl.substring(0, announceUrl.length - 1)
7376
}
@@ -258,7 +261,7 @@ Client.scrape = (opts, cb) => {
258261

259262
const clientOpts = Object.assign({}, opts, {
260263
infoHash: Array.isArray(opts.infoHash) ? opts.infoHash[0] : opts.infoHash,
261-
peerId: Buffer.from('01234567890123456789'), // dummy value
264+
peerId: text2arr('01234567890123456789'), // dummy value
262265
port: 6881 // dummy value
263266
})
264267

@@ -282,11 +285,8 @@ Client.scrape = (opts, cb) => {
282285
}
283286
})
284287

285-
opts.infoHash = Array.isArray(opts.infoHash)
286-
? opts.infoHash.map(infoHash => Buffer.from(infoHash, 'hex'))
287-
: Buffer.from(opts.infoHash, 'hex')
288288
client.scrape({ infoHash: opts.infoHash })
289289
return client
290290
}
291291

292-
module.exports = Client
292+
export default Client

examples/express-embed/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const Server = require('../..').Server
4-
const express = require('express')
3+
import { Server } from '../../index.js'
4+
import express from 'express'
55
const app = express()
66

77
// https://wiki.theory.org/BitTorrentSpecification#peer_id

0 commit comments

Comments
 (0)