diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..0d0b1c99 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1 @@ +_extends: .github diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 910c8cfd..822d21cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: ${{ runner.node }} + node-version: ${{ matrix.node }} - run: npm install - run: npm run build --if-present - run: npm test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6098b8e6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + branches: + - master + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 + - name: Cache + uses: actions/cache@v2 + with: + path: ~/.npm + key: ${{ runner.os }}-npm-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-npm- + - name: Install dependencies + run: npm i + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npx semantic-release diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..504afef8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..ec458177 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +## [9.17.1](https://github.com/webtorrent/bittorrent-tracker/compare/v9.17.0...v9.17.1) (2021-06-15) + + +### Bug Fixes + +* add package-lock ([0e486b0](https://github.com/webtorrent/bittorrent-tracker/commit/0e486b09d80d30e1c13d4624e29c4251000d4092)) +* **deps:** update dependency bn.js to ^5.2.0 ([2d36e4a](https://github.com/webtorrent/bittorrent-tracker/commit/2d36e4ae60b1bac51773f2dca81c1a158b51cb28)) +* **deps:** update dependency chrome-dgram to ^3.0.6 ([a82aaaa](https://github.com/webtorrent/bittorrent-tracker/commit/a82aaaa31963a0d9adb640166f417142c5d7b970)) +* **deps:** update dependency run-parallel to ^1.2.0 ([fcf25ed](https://github.com/webtorrent/bittorrent-tracker/commit/fcf25ed40e1fd64e630b10a0281bc09604b901d3)) +* **deps:** update dependency run-series to ^1.1.9 ([fa2c33f](https://github.com/webtorrent/bittorrent-tracker/commit/fa2c33fc91f8ef0a47d0f40b7a046ae179ee328a)) +* **deps:** update dependency simple-websocket to ^9.1.0 ([96fedbd](https://github.com/webtorrent/bittorrent-tracker/commit/96fedbdf56ddcf6627eb373a33589db885cb4fb7)) +* **deps:** update dependency ws to ^7.4.5 ([6ad7ead](https://github.com/webtorrent/bittorrent-tracker/commit/6ad7ead994e5cb99980a406aea908e4b9ff6151c)) +* **deps:** update webtorrent ([1e8d47d](https://github.com/webtorrent/bittorrent-tracker/commit/1e8d47dcd8f5f53b42aa75265a129f950d16feef)) +* UDP url parsing ([8e24a8c](https://github.com/webtorrent/bittorrent-tracker/commit/8e24a8c97b55bbaaf2c92a496d1cd30b0c008934)) diff --git a/client.js b/client.js index fabbf63f..75bdf26d 100644 --- a/client.js +++ b/client.js @@ -86,7 +86,7 @@ class Client extends EventEmitter { .map(announceUrl => { let parsedUrl try { - parsedUrl = new URL(announceUrl) + parsedUrl = common.parseUrl(announceUrl) } catch (err) { nextTickWarn(new Error(`Invalid tracker URL: ${announceUrl}`)) return null diff --git a/lib/client/udp-tracker.js b/lib/client/udp-tracker.js index 0f4c0e4f..093ed4c8 100644 --- a/lib/client/udp-tracker.js +++ b/lib/client/udp-tracker.js @@ -74,20 +74,7 @@ class UDPTracker extends Tracker { const self = this if (!opts) opts = {} - // HACK: Fix for WHATWG URL object not parsing non-standard URL schemes like - // 'udp:'. Just replace it with 'http:' since we only need the `hostname` - // and `port` properties. - // - // Note: Only affects Chrome and Firefox. Works fine in Node.js, Safari, and - // Edge. - // - // Note: UDP trackers aren't used in the normal browser build, but they are - // used in a Chrome App build (i.e. by Brave Browser). - // - // Bug reports: - // - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880 - // - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505 - let { hostname, port } = new URL(this.announceUrl.replace(/^udp:/, 'http:')) + let { hostname, port } = common.parseUrl(this.announceUrl) if (port === '') port = 80 let transactionId = genTransactionId() diff --git a/lib/common.js b/lib/common.js index 4e0e039f..105f43ad 100644 --- a/lib/common.js +++ b/lib/common.js @@ -19,5 +19,31 @@ exports.hexToBinary = function (str) { return Buffer.from(str, 'hex').toString('binary') } +// HACK: Fix for WHATWG URL object not parsing non-standard URL schemes like +// 'udp:'. Just replace it with 'http:' since we only need a few properties. +// +// Note: Only affects Chrome and Firefox. Works fine in Node.js, Safari, and +// Edge. +// +// Note: UDP trackers aren't used in the normal browser build, but they are +// used in a Chrome App build (i.e. by Brave Browser). +// +// Bug reports: +// - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880 +// - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505 +exports.parseUrl = function (str) { + const url = new URL(str.replace(/^udp:/, 'http:')) + + if (str.match(/^udp:/)) { + Object.defineProperties(url, { + href: { value: url.href.replace(/^http/, 'udp') }, + protocol: { value: url.protocol.replace(/^http/, 'udp') }, + origin: { value: url.origin.replace(/^http/, 'udp') } + }) + } + + return url +} + const config = require('./common-node') Object.assign(exports, config) diff --git a/package.json b/package.json index 30507662..5d62545b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bittorrent-tracker", "description": "Simple, robust, BitTorrent tracker (client & server) implementation", - "version": "9.17.0", + "version": "9.17.1", "author": { "name": "WebTorrent LLC", "email": "feross@webtorrent.io", @@ -25,33 +25,35 @@ }, "dependencies": { "bencode": "^2.0.1", - "bittorrent-peerid": "^1.3.2", - "bn.js": "^5.1.1", - "chrome-dgram": "^3.0.4", + "bittorrent-peerid": "^1.3.3", + "bn.js": "^5.2.0", + "chrome-dgram": "^3.0.6", "compact2string": "^1.4.1", "debug": "^4.1.1", "ip": "^1.1.5", "lru": "^3.1.0", "minimist": "^1.2.5", "once": "^1.4.0", - "queue-microtask": "^1.2.2", + "queue-microtask": "^1.2.3", "random-iterate": "^1.0.1", "randombytes": "^2.1.0", - "run-parallel": "^1.1.9", - "run-series": "^1.1.8", + "run-parallel": "^1.2.0", + "run-series": "^1.1.9", "simple-get": "^4.0.0", - "simple-peer": "^9.7.1", - "simple-websocket": "^9.0.0", + "simple-peer": "^9.11.0", + "simple-websocket": "^9.1.0", "string2compact": "^1.3.0", "unordered-array-remove": "^1.0.2", - "ws": "^7.3.0" + "ws": "^7.4.5" }, "devDependencies": { - "magnet-uri": "^5.2.4", + "@webtorrent/semantic-release-config": "^1.0.5", + "magnet-uri": "6.2.0", + "semantic-release": "^17.4.3", "standard": "*", - "tape": "^5.0.0", - "webtorrent-fixtures": "^1.7.3", - "wrtc": "^0.4.4" + "tape": "5.2.2", + "webtorrent-fixtures": "1.7.3", + "wrtc": "0.4.7" }, "engines": { "node": ">=10" @@ -69,8 +71,8 @@ "license": "MIT", "main": "index.js", "optionalDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "bufferutil": "^4.0.3", + "utf-8-validate": "^5.0.5" }, "repository": { "type": "git", @@ -93,5 +95,13 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "renovate": { + "extends": [ + "github>webtorrent/renovate-config" + ] + }, + "release": { + "extends": "@webtorrent/semantic-release-config" + } } diff --git a/test/client.js b/test/client.js index 829574d4..c34a27b6 100644 --- a/test/client.js +++ b/test/client.js @@ -534,10 +534,34 @@ test('http: invalid tracker port', function (t) { testUnsupportedTracker(t, 'http://127.0.0.1:69691337/announce') }) +test('http: invalid tracker url', function (t) { + testUnsupportedTracker(t, 'http:') +}) + +test('http: invalid tracker url with slash', function (t) { + testUnsupportedTracker(t, 'http://') +}) + test('udp: invalid tracker port', function (t) { testUnsupportedTracker(t, 'udp://127.0.0.1:69691337') }) +test('udp: invalid tracker url', function (t) { + testUnsupportedTracker(t, 'udp:') +}) + +test('udp: invalid tracker url with slash', function (t) { + testUnsupportedTracker(t, 'udp://') +}) + test('ws: invalid tracker port', function (t) { testUnsupportedTracker(t, 'ws://127.0.0.1:69691337') }) + +test('ws: invalid tracker url', function (t) { + testUnsupportedTracker(t, 'ws:') +}) + +test('ws: invalid tracker url with slash', function (t) { + testUnsupportedTracker(t, 'ws://') +})