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

bittorrent-relay

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bittorrent-relay - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

72

index.js

@@ -82,12 +82,8 @@ import Debug from 'debug'

this.id = crypto.createHash('sha1').update(`${this.DHTHOST}:${this.DHTPORT}`).digest('hex')
// this.web = {host: '', port: ''}
this.address = `ws://${this.domain || this.TRACKERHOST}:${this.TRACKERPORT}`
this.dht = {host: this.DHTHOST, port: this.DHTPORT}
this.tracker = {host: this.TRACKERHOST, port: this.TRACKERPORT}
this.web = `ws://${this.domain || this.TRACKERHOST}:${this.TRACKERPORT}`
this.status = {cpu: 0, memory: 0, state: 1}
// this.guards = new Set()
this.trackers = {}
// this.infohashes = {}
// this.infohashRefs = {}
// this.trackerRefs = {}
this.sendTo = {}
this.hashes.forEach((data) => {this.sendTo[data] = []})

@@ -103,7 +99,7 @@

debug('listening')
const test = self.http.address()
self.address = `ws://${self.domain || test.address}:${test.port}`
self.tracker = self.http.address()
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: 'address', domain: self.domain, host: test.address, port: test.port, address: self.address}))
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}))
}

@@ -328,2 +324,3 @@ }

this.relay.onListening = () => {
self.dht = self.relay.address()
self.emit('listening', 'relay')

@@ -533,3 +530,3 @@ }

self.trackers[socket.id] = socket
socket.send(JSON.stringify({id: self.id, address: self.address, domain: self.domain, host: self.DHTHOST, port: self.DHTPORT, relays: self.relays, hashes: self.hashes, action: 'session'}))
socket.send(JSON.stringify({id: self.id, tracker: self.tracker, trackerHost: self.TRACKERHOST, trackerPort: self.TRACKERPORT, dhtHost: self.DHTHOST, dhtPort: self.DHTPORT, web: self.web, dht: self.dht, domain: self.domain, relays: self.relays, hashes: self.hashes, action: 'session'}))
}

@@ -543,11 +540,15 @@ socket.onError = function(err){

if(message.action === 'session'){
if(socket.id !== message.id || socket.id !== crypto.createHash('sha1').update(`${message.host}:${message.port}`).digest('hex')){
if(socket.id !== message.id || socket.id !== crypto.createHash('sha1').update(`${message.dhtHost}:${message.dhtPort}`).digest('hex')){
socket.terminate()
}
socket.domain = message.domain
socket.address = message.address
socket.relay = message.address + '/relay'
socket.announce = message.address + '/announce'
socket.dhtHost = message.host
socket.dhtPort = message.port
socket.tracker = message.tracker
socket.web = message.web
socket.dht = message.dht
socket.relay = message.web + '/relay'
socket.announce = message.web + '/announce'
socket.dhtHost = message.dhtHost
socket.dhtPort = message.dhtPort
socket.trackerHost = message.trackerHost
socket.trackerPort = message.trackerPort
for(const messageRelay of message.relays){

@@ -568,17 +569,36 @@ if(self.relays.includes(messageRelay)){

}
if(message.action === 'address'){
if(message.action === 'web'){
if(socket.domain !== message.domain){
socket.domain = message.domain
}
if(socket.address !== message.address){
socket.address = message.address
socket.relay = message.address + '/relay'
socket.announce = message.address + '/announce'
if(socket.tracker.address !== message.tracker.address || socket.tracker.port !== message.tracker.port){
socket.tracker = message.tracker
}
if(socket.trackerHost !== message.host){
socket.trackerHost = message.host
if(socket.dht.address !== message.dht.address || socket.dht.port !== message.dht.port){
socket.dht = message.dht
}
if(socket.trackerPort !== message.port){
socket.trackerPort = message.port
if(socket.web !== message.web){
for(const messageHash of socket.hashes){
const useLink = socket.announce + '/' + messageHash
if(self.sendTo[messageHash].includes(useLink)){
self.sendTo[messageHash].splice(self.sendTo[messageHash].indexOf(useLink), 1)
self.sendTo[messageHash].push(message.web + '/announce/' + messageHash)
}
}
socket.web = message.web
socket.relay = message.web + '/relay'
socket.announce = message.web + '/announce'
}
if(socket.trackerHost !== message.trackerHost){
socket.trackerHost = message.trackerHost
}
if(socket.trackerPort !== message.trackerPort){
socket.trackerPort = message.trackerPort
}
if(socket.dhtHost !== message.dhtHost){
socket.dhtHost = message.dhtHost
}
if(socket.dhtPort !== message.dhtPort){
socket.dhtPort = message.dhtPort
}
}

@@ -585,0 +605,0 @@ if(message.action === 'status'){

{
"name": "bittorrent-relay",
"description": "Uses the mainline dht to relay requests to other trackers in a swarm",
"version": "2.0.1",
"version": "2.0.2",
"bin": {

@@ -6,0 +6,0 @@ "bittorrent-relay": "./bin/cmd.js"

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