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 1.0.4 to 1.0.5

84

index.js

@@ -82,6 +82,5 @@ import Debug from 'debug'

this.domain = opts.domain || null
this.host = null
this.port = null
this.id = null
this.address = null
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.status = {cpu: 0, memory: 0, state: 1}

@@ -105,10 +104,8 @@ // this.guards = new Set()

debug('listening')
if(!self.address){
const test = self.http.address()
self.host = test.address
self.port = test.port
self.id = crypto.createHash('sha1').update(`${test.address}:${test.port}`).digest('hex')
self.address = `ws://${self.domain || test.address}:${test.port}`
// self.status.id = self.id
// self.status.address = self.address
const test = self.http.address()
self.address = `ws://${self.domain || test.address}:${test.port}`
for(const socket in this.trackers){
if(this.trackers[socket].readyState === 1){
this.trackers[socket].send(JSON.stringify({action: 'address', host: self.domain || test.address, port: test.port, address: self.address}))
}
}

@@ -280,8 +277,16 @@ self.talkToRelay()

// else handle websockets as usual
let action = req.url.slice(0, req.url.lastIndexOf('/')).slice(1)
let hash = req.url.slice(req.url.lastIndexOf('/')).slice(1)
if(!action || !hash || action === hash || action === '/' || hash === '/'){
socket.terminate()
} else {
if(action === '/relay'){
try {
const action = req.url.slice(0, req.url.lastIndexOf('/')).slice(1)
const hash = req.url.slice(req.url.lastIndexOf('/')).slice(1)
if(action === 'announce'){
if(this.status.state !== 1 && this.sendTo[hash] && this.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.terminate()
} else {
// use regular socket function from bittorrent-tracker
socket.upgradeReq = req
this.onWebSocketConnection(socket)
}
} else if(action === 'relay'){
if(this.trackers[hash]){

@@ -296,15 +301,8 @@ socket.terminate()

}
} else if(action === '/announce'){
if(this.status.state !== 1 && this.sendTo[hash] && this.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.terminate()
} else {
// use regular socket function from bittorrent-tracker
socket.upgradeReq = req
this.onWebSocketConnection(socket)
}
} else {
socket.terminate()
throw new Error('invalid path')
}
} catch (error) {
socket.send(JSON.stringify({action: 'failure reason', error: error.message}))
socket.terminate()
}

@@ -322,9 +320,2 @@ }

this.ws.on('connection', this.ws.onConnection)
this.ws.address = () => {
if(this.http.listening){
return this.http.address()
} else {
return null
}
}

@@ -509,3 +500,3 @@ // this.intervalUsage(60000)

self.trackers[socket.id] = socket
socket.send(JSON.stringify({id: self.id, address: self.address, host: self.host, port: self.port, relays: self.relays, hashes: self.hashes, action: 'session'}))
socket.send(JSON.stringify({id: self.id, address: self.address, host: self.DHTHOST, port: self.DHTPORT, relays: self.relays, hashes: self.hashes, action: 'session'}))
}

@@ -519,3 +510,3 @@ socket.onError = function(err){

if(message.action === 'session'){
if(socket.id !== message.id){
if(socket.id !== message.id || socket.id !== crypto.createHash('sha1').update(`${message.host}:${message.port}`).digest('hex')){
socket.terminate()

@@ -526,4 +517,4 @@ }

socket.announce = message.address + '/announce'
socket.host = message.host
socket.port = message.port
socket.dhtHost = message.host
socket.dhtPort = message.port
for(const messageRelay of message.relays){

@@ -544,2 +535,15 @@ if(self.relays.includes(messageRelay)){

}
if(message.action === 'address'){
if(socket.address !== message.address){
socket.address = message.address
socket.relay = message.address + '/relay'
socket.announce = message.address + '/announce'
}
if(socket.trackerHost !== message.host){
socket.trackerHost = message.host
}
if(socket.trackerPort !== message.port){
socket.trackerPort = message.port
}
}
if(message.action === 'status'){

@@ -546,0 +550,0 @@ if(message.state === 1){

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

@@ -20,3 +20,2 @@ "bittorrent-tracker": "./bin/cmd.js"

"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"ip": "^1.1.5",

@@ -23,0 +22,0 @@ "lru": "^3.1.0",

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