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 3.0.1 to 3.0.2

83

index.js

@@ -33,4 +33,5 @@ import Debug from 'debug'

* @param {Number} opts.trackerPort port used for the tracker
* @param {String} opts.dhtHost host used for the dht
* @param {String} opts.trackerHost host used for the tracker
* @param {String} opts.address address used for the dht and the tracker
* @param {String} opts.host host used for server
* @param {Number} opts.port port used for server
* @param {String} opts.domain domain name that will be used

@@ -59,2 +60,3 @@ * @param {Boolean} opts.trustProxy trust 'x-forwarded-for' header from reverse proxy

// this.memLimit = 1700000000
this.domain = opts.domain || null
this.timer = opts.timer || 1 * 60 * 1000

@@ -64,4 +66,8 @@ this.relayTimer = opts.relayTimer ? opts.relayTimer : 5 * 60 * 1000

this.TRACKERPORT = opts.trackerPort || 16969
this.DHTHOST = opts.dhtHost || '0.0.0.0'
this.TRACKERHOST = opts.trackerHost || '0.0.0.0'
this.ADDRESS = opts.address || '0.0.0.0'
this.host = opts.host
if(!this.host){
throw new Error('must have host')
}
this.port = opts.port || this.TRACKERPORT
this.hashes = (() => {if(!opts.hashes){return [];}return Array.isArray(opts.hashes) ? opts.hashes : opts.hashes.split(',');})()

@@ -83,8 +89,6 @@ if(!this.hashes.length){

}
this.domain = opts.domain || null
this.id = crypto.createHash('sha1').update(nanoid()).digest('hex')
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.dht = {host: this.ADDRESS, port: this.DHTPORT}
this.tracker = {host: this.ADDRESS, port: this.TRACKERPORT}
this.id = crypto.createHash('sha1').update(this.host + ':' + this.port).digest('hex')
this.web = `ws://${this.domain || this.host}:${this.port}`
this.status = {cpu: 0, memory: 0, state: 1}

@@ -103,7 +107,5 @@ this.trackers = {}

debug('listening')
self.tracker = self.http.address()
self.web = `ws://${self.domain || self.tracker.address}:${self.tracker.port}`
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}))
self.trackers[socket].send(JSON.stringify({action: 'web', address: self.ADDRESS, tracker: self.tracker, dht: self.dht, domain: self.domain, host: self.host, port: self.port, web: self.web, id: self.id}))
}

@@ -349,13 +351,17 @@ }

// this.tracker[infoHash][ws-link]
const relay = `ws://${peer.host}:${peer.port}/relay/`
// const announce = `ws://${link}/announce/`
const con = new WebSocket(relay + self.id)
// con.relay = relay
// con.announce = announce
con.active = true
// con.link = link
con.relays = [infoHash]
con.hashes = []
// this.trackers[id] = con
self.onRelaySocketConnection(con)
const id = crypto.createHash('sha1').update(peer.host + ':' + peer.port).digest('hex')
if(!self.trackers[id]){
const relay = `ws://${peer.host}:${peer.port}/relay/`
// const announce = `ws://${link}/announce/`
const con = new WebSocket(relay + self.id)
// con.relay = relay
// con.announce = announce
con.active = true
// con.link = link
con.relays = [infoHash]
con.hashes = []
con.id = id
// this.trackers[id] = con
self.onRelaySocketConnection(con)
}
// finish the rest

@@ -451,6 +457,6 @@ })

if(!this.relay.listening){
this.relay.listen(this.DHTPORT, this.DHTHOST)
this.relay.listen(this.DHTPORT, this.ADDRESS)
}
if(!this.http.listening){
this.http.listen(this.TRACKERPORT, this.TRACKERHOST)
this.http.listen(this.TRACKERPORT, this.ADDRESS)
}

@@ -468,3 +474,3 @@ if(cb){

// this.http.on('close', this.http.onClose)
this.http.listen(this.TRACKERPORT, this.TRACKERHOST)
this.http.listen(this.TRACKERPORT, this.ADDRESS)
}

@@ -528,4 +534,4 @@ }

socket.onOpen = function(){
// self.trackers[socket.id] = socket
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'}))
self.trackers[socket.id] = socket
socket.send(JSON.stringify({id: self.id, address: self.ADDRESS, tracker: self.tracker, web: self.web, host: self.host, port: self.port, dht: self.dht, domain: self.domain, relays: self.relays, hashes: self.hashes, action: 'session'}))
}

@@ -545,2 +551,5 @@ socket.onError = function(err){

socket.tracker = message.tracker
socket.address = message.address
socket.port = message.port
socket.host = message.host
socket.web = message.web

@@ -550,6 +559,2 @@ socket.dht = message.dht

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){

@@ -592,14 +597,2 @@ if(self.relays.includes(messageRelay)){

}
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
}
}

@@ -606,0 +599,0 @@ if(message.action === 'status'){

{
"name": "bittorrent-relay",
"description": "Uses the mainline dht to relay requests to other trackers in a swarm",
"version": "3.0.1",
"version": "3.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