bittorrent-relay
Advanced tools
Comparing version 2.0.3 to 2.0.4
46
index.js
@@ -100,5 +100,5 @@ import Debug from 'debug' | ||
self.web = `ws://${self.domain || self.tracker.address}:${self.tracker.port}` | ||
for(const socket in this.trackers){ | ||
if(this.trackers[socket].readyState === 1){ | ||
this.trackers[socket].send(JSON.stringify({action: 'web', tracker: self.tracker, dht: self.dht, domain: self.domain, web: self.web, trackerHost: self.TRACKERHOST, trackerPort: self.TRACKERPORT, dhtHost: self.DHTHOST, dhtPort: self.DHTPORT})) | ||
for(const socket in self.trackers){ | ||
if(self.trackers[socket].readyState === 1){ | ||
self.trackers[socket].send(JSON.stringify({action: 'web', tracker: self.tracker, dht: self.dht, domain: self.domain, web: self.web, trackerHost: self.TRACKERHOST, trackerPort: self.TRACKERPORT, dhtHost: self.DHTHOST, dhtPort: self.DHTPORT})) | ||
} | ||
@@ -112,3 +112,3 @@ } | ||
const infoHashes = Object.keys(this.torrents) | ||
const infoHashes = Object.keys(self.torrents) | ||
let activeTorrents = 0 | ||
@@ -169,3 +169,3 @@ const allPeers = {} | ||
infoHashes.forEach(infoHash => { | ||
const peers = this.torrents[infoHash].peers | ||
const peers = self.torrents[infoHash].peers | ||
const keys = peers.keys | ||
@@ -242,7 +242,7 @@ if (keys.length > 0) activeTorrents++ | ||
res.setHeader('Content-Type', 'application/json') | ||
res.end(JSON.stringify(this.sendTo)) | ||
res.end(JSON.stringify(self.sendTo)) | ||
} else if(req.method === 'GET' && req.url.startsWith('/i/')){ | ||
const test = req.url.replace('/i/', '') | ||
res.setHeader('Content-Type', 'application/json') | ||
res.end(this.sendTo[test] ? JSON.stringify(this.sendTo[test]) : JSON.stringify([])) | ||
res.end(self.sendTo[test] ? JSON.stringify(self.sendTo[test]) : JSON.stringify([])) | ||
} else { | ||
@@ -283,5 +283,5 @@ res.setHeader('Content-Type', 'application/json') | ||
if(action === 'announce'){ | ||
if(this.status.state !== 1 && this.sendTo[hash] && this.sendTo[hash].length){ | ||
if(self.status.state !== 1 && self.sendTo[hash] && self.sendTo[hash].length){ | ||
// send them tracker url that is usable then close the socket | ||
socket.send(JSON.stringify({action: 'relay', tracker: this.sendTo[hash][Math.floor(Math.random() * this.sendTo[hash].length)]})) | ||
socket.send(JSON.stringify({action: 'relay', tracker: self.sendTo[hash][Math.floor(Math.random() * self.sendTo[hash].length)]})) | ||
socket.terminate() | ||
@@ -291,6 +291,6 @@ } else { | ||
socket.upgradeReq = req | ||
this.onWebSocketConnection(socket) | ||
self.onWebSocketConnection(socket) | ||
} | ||
} else if(action === 'relay'){ | ||
if(this.trackers[hash]){ | ||
if(self.trackers[hash]){ | ||
socket.terminate() | ||
@@ -302,3 +302,3 @@ } else { | ||
socket.hashes = [] | ||
this.onRelaySocketConnection(socket) | ||
self.onRelaySocketConnection(socket) | ||
} | ||
@@ -317,3 +317,3 @@ } else { | ||
this.ws.onListening = () => { | ||
this.ws.listening = true | ||
self.ws.listening = true | ||
self.emit('listening', 'ws') | ||
@@ -353,5 +353,5 @@ } | ||
const id = crypto.createHash('sha1').update(link).digest('hex') | ||
if(this.trackers[id]){ | ||
if(!this.trackers[id].relays.includes(infoHash)){ | ||
this.trackers[id].relays.push(infoHash) | ||
if(self.trackers[id]){ | ||
if(!self.trackers[id].relays.includes(infoHash)){ | ||
self.trackers[id].relays.push(infoHash) | ||
} | ||
@@ -370,3 +370,3 @@ } else { | ||
// this.trackers[id] = con | ||
this.onRelaySocketConnection(con) | ||
self.onRelaySocketConnection(con) | ||
} | ||
@@ -387,12 +387,14 @@ // finish the rest | ||
}, this.relayTimer) | ||
this.intervalActive = setInterval(() => { | ||
for(const test in self.trackers){ | ||
if(!self.trackers[test].active){ | ||
self.trackers[test].terminate() | ||
for(const test in this.trackers){ | ||
if(!this.trackers[test].active){ | ||
this.trackers[test].terminate() | ||
continue | ||
} | ||
self.trackers[test].active = false | ||
self.trackers[test].send(JSON.stringify({action: 'ping'})) | ||
this.trackers[test].active = false | ||
this.trackers[test].send(JSON.stringify({action: 'ping'})) | ||
} | ||
}, this.timer) | ||
this.intervalUsage(60000) | ||
@@ -399,0 +401,0 @@ } |
{ | ||
"name": "bittorrent-relay", | ||
"description": "Uses the mainline dht to relay requests to other trackers in a swarm", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"bin": { | ||
@@ -6,0 +6,0 @@ "bittorrent-relay": "./bin/cmd.js" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48011