Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bittorrent-tracker

Package Overview
Dependencies
Maintainers
9
Versions
257
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bittorrent-tracker - npm Package Compare versions

Comparing version 10.0.12 to 11.0.0

1

AUTHORS.md

@@ -66,3 +66,4 @@ # Authors

- Tom Snelling (tomsnelling8@gmail.com)
- Cas_ (6506529+ThaUnknown@users.noreply.github.com)
#### Generated by tools/update-authors.sh.

@@ -0,1 +1,23 @@

# [11.0.0](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.12...v11.0.0) (2023-10-31)
### Features
* **major:** drop simple-get ([#443](https://github.com/webtorrent/bittorrent-tracker/issues/443)) ([bce64e1](https://github.com/webtorrent/bittorrent-tracker/commit/bce64e155df6ff9fa605898cbf7498bf76188d8b))
### BREAKING CHANGES
* **major:** drop simple-get
* perf: drop simple-get
* feat: undici agent and socks
* fix: undici as dev dependency
* feat: require user passed proxy objects for http and ws
* chore: include undici for tests
## [10.0.12](https://github.com/webtorrent/bittorrent-tracker/compare/v10.0.11...v10.0.12) (2023-08-09)

@@ -2,0 +24,0 @@

108

lib/client/http-tracker.js
import arrayRemove from 'unordered-array-remove'
import bencode from 'bencode'
import clone from 'clone'
import Debug from 'debug'
import get from 'simple-get'
import Socks from 'socks'
import fetch from 'cross-fetch-ponyfill'
import { bin2hex, hex2bin, arr2text, text2arr, arr2hex } from 'uint8-util'

@@ -16,2 +14,10 @@

function abortTimeout (ms) {
const controller = new AbortController()
setTimeout(() => {
controller.abort()
}, ms).unref?.()
return controller
}
/**

@@ -116,4 +122,3 @@ * HTTP torrent tracker client (for an individual tracker)

_request (requestUrl, params, cb) {
const self = this
async _request (requestUrl, params, cb) {
const parsedUrl = new URL(requestUrl + (requestUrl.indexOf('?') === -1 ? '?' : '&') + common.querystringStringify(params))

@@ -124,59 +129,62 @@ let agent

if (!agent && this.client._proxyOpts.socksProxy) {
agent = new Socks.Agent(clone(this.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'https:'))
agent = this.client._proxyOpts.socksProxy
}
}
this.cleanupFns.push(cleanup)
let request = get.concat({
url: parsedUrl.toString(),
agent,
timeout: common.REQUEST_TIMEOUT,
headers: {
'user-agent': this.client._userAgent || ''
const cleanup = () => {
if (!controller.signal.aborted) {
arrayRemove(this.cleanupFns, this.cleanupFns.indexOf(cleanup))
controller.abort()
controller = null
}
}, onResponse)
function cleanup () {
if (request) {
arrayRemove(self.cleanupFns, self.cleanupFns.indexOf(cleanup))
request.abort()
request = null
}
if (self.maybeDestroyCleanup) self.maybeDestroyCleanup()
if (this.maybeDestroyCleanup) this.maybeDestroyCleanup()
}
function onResponse (err, res, data) {
cleanup()
if (self.destroyed) return
this.cleanupFns.push(cleanup)
let res
let controller = abortTimeout(common.REQUEST_TIMEOUT)
try {
res = await fetch(parsedUrl.toString(), {
agent,
signal: controller.signal,
dispatcher: agent,
headers: {
'user-agent': this.client._userAgent || ''
}
})
} catch (err) {
if (err) return cb(err)
if (res.statusCode !== 200) {
return cb(new Error(`Non-200 response code ${res.statusCode} from ${self.announceUrl}`))
}
if (!data || data.length === 0) {
return cb(new Error(`Invalid tracker response from${self.announceUrl}`))
}
}
let data = new Uint8Array(await res.arrayBuffer())
cleanup()
if (this.destroyed) return
try {
data = bencode.decode(data)
} catch (err) {
return cb(new Error(`Error decoding tracker response: ${err.message}`))
}
const failure = data['failure reason'] && arr2text(data['failure reason'])
if (failure) {
debug(`failure from ${requestUrl} (${failure})`)
return cb(new Error(failure))
}
if (res.status !== 200) {
return cb(new Error(`Non-200 response code ${res.statusCode} from ${this.announceUrl}`))
}
if (!data || data.length === 0) {
return cb(new Error(`Invalid tracker response from${this.announceUrl}`))
}
const warning = data['warning message'] && arr2text(data['warning message'])
if (warning) {
debug(`warning from ${requestUrl} (${warning})`)
self.client.emit('warning', new Error(warning))
}
try {
data = bencode.decode(data)
} catch (err) {
return cb(new Error(`Error decoding tracker response: ${err.message}`))
}
const failure = data['failure reason'] && arr2text(data['failure reason'])
if (failure) {
debug(`failure from ${requestUrl} (${failure})`)
return cb(new Error(failure))
}
debug(`response from ${requestUrl}`)
const warning = data['warning message'] && arr2text(data['warning message'])
if (warning) {
debug(`warning from ${requestUrl} (${warning})`)
this.client.emit('warning', new Error(warning))
}
cb(null, data)
}
debug(`response from ${requestUrl}`)
cb(null, data)
}

@@ -183,0 +191,0 @@

@@ -1,6 +0,4 @@

import clone from 'clone'
import Debug from 'debug'
import Peer from '@thaunknown/simple-peer/lite.js'
import Socket from '@thaunknown/simple-websocket'
import Socks from 'socks'
import { arr2text, arr2hex, hex2bin, bin2hex, randomBytes } from 'uint8-util'

@@ -188,3 +186,3 @@

if (!agent && this.client._proxyOpts.socksProxy) {
agent = new Socks.Agent(clone(this.client._proxyOpts.socksProxy), (parsedUrl.protocol === 'wss:'))
agent = this.client._proxyOpts.socksProxy
}

@@ -191,0 +189,0 @@ }

{
"name": "bittorrent-tracker",
"description": "Simple, robust, BitTorrent tracker (client & server) implementation",
"version": "10.0.12",
"version": "11.0.0",
"author": {

@@ -37,2 +37,3 @@ "name": "WebTorrent LLC",

"compact2string": "^1.4.1",
"cross-fetch-ponyfill": "^1.0.1",
"debug": "^4.1.1",

@@ -47,3 +48,2 @@ "ip": "^1.1.5",

"run-series": "^1.1.9",
"simple-get": "^4.0.0",
"socks": "^2.0.0",

@@ -59,5 +59,6 @@ "string2compact": "^2.0.0",

"magnet-uri": "7.0.5",
"semantic-release": "21.0.7",
"semantic-release": "21.1.2",
"standard": "*",
"tape": "5.6.6",
"tape": "5.7.2",
"undici": "^5.27.0",
"webtorrent-fixtures": "2.0.2",

@@ -64,0 +65,0 @@ "wrtc": "0.4.7"

@@ -58,5 +58,5 @@ # bittorrent-tracker [![ci][ci-image]][ci-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

```js
var Client = require('bittorrent-tracker')
import Client from 'bittorrent-tracker'
var requiredOpts = {
const requiredOpts = {
infoHash: new Buffer('012345678901234567890'), // hex string or Buffer

@@ -68,3 +68,3 @@ peerId: new Buffer('01234567890123456789'), // hex string or Buffer

var optionalOpts = {
const optionalOpts = {
// RTCPeerConnection config object (only used in browser)

@@ -86,43 +86,20 @@ rtcConfig: {},

},
// Proxy config object
// Proxy options (used to proxy requests in node)
proxyOpts: {
// Socks proxy options (used to proxy requests in node)
socksProxy: {
// Configuration from socks module (https://github.com/JoshGlazebrook/socks)
proxy: {
// IP Address of Proxy (Required)
ipaddress: "1.2.3.4",
// TCP Port of Proxy (Required)
port: 1080,
// Proxy Type [4, 5] (Required)
// Note: 4 works for both 4 and 4a.
// Type 4 does not support UDP association relay
type: 5,
// SOCKS 4 Specific:
// UserId used when making a SOCKS 4/4a request. (Optional)
userid: "someuserid",
// SOCKS 5 Specific:
// Authentication used for SOCKS 5 (when it's required) (Optional)
authentication: {
username: "Josh",
password: "somepassword"
}
},
// Amount of time to wait for a connection to be established. (Optional)
// - defaults to 10000ms (10 seconds)
timeout: 10000
},
// NodeJS HTTP agents (used to proxy HTTP and Websocket requests in node)
// Populated with Socks.Agent if socksProxy is provided
httpAgent: {},
httpsAgent: {}
// For WSS trackers this is always a http.Agent
// For UDP trackers this is an object of options for the Socks Connection
// 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:
// import Socks from 'socks'
// proxyOpts.socksProxy = new Socks.Agent(optionsObject, isHttps)
// or if using Node 16 or later
// import { socksDispatcher } from 'fetch-socks'
// proxyOpts.socksProxy = socksDispatcher(optionsObject)
socksProxy: new SocksProxy(socksOptionsObject),
// Populated with socksProxy if it's provided
httpAgent: new http.Agent(agentOptionsObject),
httpsAgent: new https.Agent(agentOptionsObject)
},
}
var client = new Client(requiredOpts)
const client = new Client(requiredOpts)

@@ -188,3 +165,3 @@ client.on('error', function (err) {

```js
const Server = require('bittorrent-tracker').Server
import { Server } from 'bittorrent-tracker'

@@ -296,3 +273,3 @@ const server = new Server({

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

@@ -299,0 +276,0 @@ results[infoHash1].announce

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc