🌊 Instalar y Configurar bittorrent-tracker
bittorrent-tracker es una implementación open source de BitTorrent tracker, client y server escrita en Node.js. Un BitTorrent tracker es un servicio web que responde a solicitudes de clientes BitTorrent, incluyendo métricas para mantener estadísticas del torrent y proporcionar listas de pares (peers).
Prerrequisitos
- Node.js 16.0.0+ o superior (
npm install -g node@latest) - NPM instalado globalmente
- Port disponible: 8000 (HTTP), 8001 (UDP), 8002 (WebSocket) por defecto
- Memoria RAM mínima: 256MB
- Disco: 100MB libres para dependencias
Instalación con npm
Instalación Local
# Crear directorio de proyecto
cd /var/www/bittorrent-tracker || mkdir -p /var/www/bittorrent-tracker && cd /var/www/bittorrent-tracker
# Inicializar npm (opcional, para proyectos locales)
npm init -y
# Instalar bittorrent-tracker
npm install bittorrent-tracker
Instalación Global
npm install -g bittorrent-tracker
Configuración del Servidor
Método 1: Usando el módulo npm (Recomendado)
// server.js - Configuración completa
import { Server } from 'bittorrent-tracker'
// Or import Server from 'bittorrent-tracker/server'
const server = new Server({
udp: true, // enable udp server? [default=true]
http: true, // enable http server? [default=true]
ws: true, // enable websocket server? [default=true]
stats: true, // enable web-based statistics? [default=true]
trustProxy: false, // enable trusting x-forwarded-for header for remote IP [default=false]
filter: function (infoHash, params, cb) {
// Blacklist/whitelist function para permitir/denegar torrents
const allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa')
if (allowed) {
cb(null)
} else {
cb(new Error('disallowed torrent'))
}
}
})
// Internal http, udp, and websocket servers exposed as public properties.
server.http
server.udp
server.ws
server.on('error', function (err) {
// fatal server error!
console.log(err.message)
})
server.on('warning', function (err) {
// client sent bad data. probably not a problem, just a buggy client.
console.log(err.message)
})
server.on('listening', function () {
// fired when all requested servers are listening
const httpAddr = server.http.address()
const httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost'
const httpPort = httpAddr.port
console.log(`HTTP tracker: http://${httpHost}:${httpPort}/announce`)
const udpAddr = server.udp.address()
const udpHost = udpAddr.address
const udpPort = udpAddr.port
console.log(`UDP tracker: udp://${udpHost}:${udpPort}`)
const wsAddr = server.ws.address()
const wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost'
const wsPort = wsAddr.port
console.log(`WebSocket tracker: ws://${wsHost}:${wsPort}`)
})
// start tracker server listening!
const port = 8000
const hostname = '0.0.0.0' // Listen on all interfaces
server.listen(port, hostname, () => {
console.log(`bittorrent-tracker v11.2.3 running on ${hostname}:${port}`)
})
Método 2: CLI Global (Más Simple)
# Instalar globalmente
npm install -g bittorrent-tracker
# Iniciar tracker con opciones
bittorrent-tracker --port 8000 --http --udp --ws --trust-proxy
Opciones CLI Disponibles
$ bittorrent-tracker --help
bittorrent-tracker - Start a bittorrent tracker server
Usage: bittorrent-tracker [OPTIONS]
Options:
-p, --port [number] change the port [default: 8000]
--trust-proxy trust 'x-forwarded-for' header from reverse proxy
--interval client announce interval (ms) [default: 600000]
--http enable http server
--udp enable udp server
--ws enable websocket server
-q, --quiet only show error output
-s, --silent show no output at all (overrides QUIET)
-v, --version print the current version
Despliegue con Docker
Docker Image: jarylc/bittorrent-tracker (Minimal Alpine)
# docker-compose.yml
version: '3.8'
services:
bittorrent-tracker:
image: jarylc/bittorrent-tracker
container_name: bittorrent-tracker
ports:
- "8000:8000"
environment:
- PORT=8000
- HTTP=1
- UDP=1
- WS=1
- STATS=1
- INTERVAL=600000
- TRUST_PROXY=0
- QUIET=1
- SILENT=0
restart: unless-stopped
networks:
- torrent-network
# Ejecutar directamente
docker run -d \
--name bittorrent-tracker \
-e PORT=8000 \
-e HTTP=1 \
-e UDP=1 \
-e WS=1 \
-e STATS=1 \
-e INTERVAL=600000 \
-e TRUST_PROXY=0 \
-e QUIET=1 \
-e SILENT=0 \
-p 8000:8000 \
--restart unless-stopped \
jarylc/bittorrent-tracker
Docker Image: siestacat/bittorrent-tracker
version: '3.8'
services:
bittorrent-tracker:
image: siestacat/bittorrent-tracker
container_name: bittorrent-tracker-siestacat
ports:
- "8000:8000"
environment:
- PORT=8000
- HTTP=1
- UDP=1
- WS=1
- STATS=1
restart: unless-stopped
Verificación Posterior
Comprobación HTTP Tracker
# Verificar que el tracker está escuchando
curl -I http://localhost:8000/announce
# Response: HTTP/1.1 200 OK
# Verificar estadísticas web
open http://localhost:8000/stats
# Obtener datos JSON de estadísticas
curl http://localhost:8000/stats.json | jq .
Comprobación UDP Tracker
# Verificar UDP endpoint (requiere cliente BitTorrent)
dig udp://localhost:8001/announce
Comprobación WebSocket Tracker
# Usar ws o wscat para verificar WebSocket
curl -N http://localhost:8002/ws
Monitoreo y Estadísticas
Web Interface /stats
Accede a http://<host>:8000/stats para ver la interfaz web de estadísticas del tracker.
JSON API /stats.json
// Obtener información sobre todos los torrents en el tracker
const stats = await fetch('http://localhost:8000/stats.json').then(r => r.json())
console.log(stats)
// Acceder a torrents específicos
Object.keys(server.torrents).forEach(infoHash => {
const torrent = server.torrents[infoHash]
console.log(`Torrent: ${infoHash}`)
console.log(`Seeders: ${torrent.complete}`)
console.log(`Leechers: ${torrent.incomplete}`)
})
Seguridad y Configuración de Proxy
Configurar trustProxy para Reverse Proxy
Si estás detrás de un reverse proxy (nginx, Apache), debes configurar trustProxy:
const server = new Server({
trustProxy: true, // Habilitar confianza en x-forwarded-for
filter: function(infoHash, params, cb) {
// Verificar IP real del cliente desde el proxy
const clientIP = params.headers['x-forwarded-for'] || params.remoteAddress
// Bloquear IPs no deseadas (ejemplo: bloquear redes internas)
if (!clientIP.startsWith('192.168.') && !clientIP.startsWith('10.')) {
cb(null) // Permitir solo IPs externas
} else {
cb(new Error('Access denied from internal network'))
}
}
})
Configuración Nginx para bittorrent-tracker
server {
listen 80;
server_name tracker.local;
# Habilitar proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 60s;
}
}
Backup, Actualización y Rollback
Backup de Configuración
# Backup completo del tracker
tar -czf bittorrent-tracker-backup-$(date +%Y%m%d-%H%M%S).tar.gz \
/var/www/bittorrent-tracker
# Backup de configuración específica
cp server.js server.js.backup.$(date +%Y%m%d)
Actualización a Nueva Versión
# Actualizar npm package
npm install bittorrent-tracker@latest
# O actualizar globalmente
npm update -g bittorrent-tracker
# Reiniciar el tracker
node server.js
Rollback a Versión Anterior
# Restaurar desde backup
tar -xzf bittorrent-tracker-backup-20261005-143029.tar.gz \
-C /var/www/bittorrent-tracker
# O restaurar configuración específica
cp server.js.backup.20261004 server.js
Errores Habituales y Soluciones
Error: Port Already in Use
# Solución: Cambiar el puerto o matar el proceso
lsof -i :8000
kill -9 <PID>
# O usar un puerto diferente
bittorrent-tracker --port 8080
Error: Server Not Listening
// Verificar que el servidor está escuchando
server.on('listening', () => {
console.log('Tracker is listening')
})
server.on('error', (err) => {
console.error('Tracker error:', err.message)
})
Error: Filter Rejected All Torrents
// Solución: Asegurar que el filter permita al menos un torrent
filter: function(infoHash, params, cb) {
// Permitir todos los torrents por defecto
cb(null)
}
// O permitir torrents específicos
const allowedTorrents = ['aaa67059ed6bd08362da625b3ae77f6f4a075aaa']
filter: function(infoHash, params, cb) {
if (allowedTorrents.includes(infoHash)) {
cb(null)
} else {
cb(new Error('disallowed torrent'))
}
}
Error: UDP Tracker Not Working
# Verificar que UDP está habilitado
bittorrent-tracker --http --udp --ws
# O verificar en la configuración del Server
const server = new Server({
udp: true, // Asegurar que esto sea true
http: true,
ws: true
})
FAQ
¿Qué es bittorrent-tracker?
Es una implementación open source de BitTorrent tracker, client y server escrita en Node.js que permite crear servidores de tracking para torrents. Soporta HTTP trackers, UDP trackers (BEP 15), WebTorrent trackers (BEP forthcoming).
¿Para quién está diseñado?
Desarrolladores que necesitan implementar trackers personalizados, proyectos WebTorrent, aplicaciones P2P y sistemas de distribución de contenido.
¿Cómo instalarlo?
npm install bittorrent-tracker
¿Soporta Docker?
Sí, existen múltiples imágenes Docker disponibles: jarylc/bittorrent-tracker (minimal Alpine), siestacat/bittorrent-tracker, Quoorex/docker-bittorrent-tracker.
¿Qué protocolos soporta?
HTTP trackers, UDP trackers (BEP 15), WebTorrent trackers (BEP forthcoming). Soporta IPv4 e IPv6.
¿Cómo verificar que funciona?
# Verificar HTTP tracker
curl http://localhost:8000/stats.json
# Verificar estadísticas web
open http://localhost:8000/stats
Enlaces Internos Contextuales
- WebTorrent - Cliente que utiliza bittorrent-tracker
- peerflix - Cliente de torrent que utiliza bittorrent-tracker
- bittorrent-dht - DHT implementation complementaria
Fuentes Verificadas
- GitHub: webtorrent/bittorrent-tracker
- npmjs.com: bittorrent-tracker
- Docker Hub: jarylc/bittorrent-tracker
- SelfHost Directory: bittorrent-tracker
Verificación
Fecha de verificación: 2026-10-05
Versión verificada: v11.2.3
Fuentes primarias: GitHub webtorrent/bittorrent-tracker, npmjs.com, Docker Hub