torrent-properties
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -11,3 +11,3 @@ const WebTorrentProperties = require('./extend') | ||
client.uploadProp({address: '50105b102fa4e5c666fbdb218393aee25d295c4c1de0e45c814e1ec1fa47c6cc', secret: '928d3dec6b3aa7fe51a553f77d3a87c4ff5fbf4692c03e458996afce754d882950105b102fa4e5c666fbdb218393aee25d295c4c1de0e45c814e1ec1fa47c6cc'}, 3, false, path.resolve('./test1'), {}, (torrent, data) => { | ||
client.uploadProp({address: '50105b102fa4e5c666fbdb218393aee25d295c4c1de0e45c814e1ec1fa47c6cc', secret: '928d3dec6b3aa7fe51a553f77d3a87c4ff5fbf4692c03e458996afce754d882950105b102fa4e5c666fbdb218393aee25d295c4c1de0e45c814e1ec1fa47c6cc'}, 6, true, path.resolve('./test6'), {}, (torrent, data) => { | ||
console.log(torrent.address, torrent.infoHash, torrent.seq, torrent.own) | ||
@@ -14,0 +14,0 @@ console.log(data.address, data.infoHash, data.seq, data.own) |
35
index.js
@@ -63,3 +63,3 @@ const DHT = require('bittorrent-dht') | ||
async keepItUpdated(){ | ||
for(let i = 0;this.check.length;i++){ | ||
for(let i = 0;i < this.check.length;i++){ | ||
let res = await new Promise((resolve, reject) => { | ||
@@ -75,6 +75,6 @@ this.current(this.check[i].address, (error, data) => { | ||
if(res){ | ||
if(res.getData.v && res.getData.v.ih){ | ||
this.check[i].infoHash = res.getData.v.ih.toString('hex') | ||
if(Buffer.isBuffer(res.getData.v)){ | ||
this.check[i].infoHash = res.getData.v.toString('hex') | ||
} | ||
if(res.getData.seq){ | ||
if(typeof(res.getData.seq) === 'number'){ | ||
this.check[i].seq = res.getData.seq | ||
@@ -102,6 +102,4 @@ } | ||
} | ||
fs.writeFileSync('./data', JSON.stringify(this.check.map(main => {return {address: main.address, infoHash: main.infoHash, seq: main.seq, isActive: main.isActive}}))) | ||
setTimeout(() => { | ||
this.keepItUpdated() | ||
}, 3600000) | ||
fs.writeFileSync('./data', JSON.stringify(this.check.map(main => {return {address: main.address, infoHash: main.infoHash, seq: main.seq, isActive: main.isActive, own: main.own}}))) | ||
setTimeout(() => {this.keepItUpdated()}, 3600000) | ||
} | ||
@@ -187,5 +185,10 @@ | ||
} else if(res){ | ||
const infoHash = res.v.ih.toString('hex') | ||
const seq = res.seq ? res.seq : 0 | ||
if(!Buffer.isBuffer(res.v) || typeof(res.seq) !== 'number'){ | ||
return callback(new Error('data has invalid values')) | ||
} | ||
const infoHash = res.v.toString('hex') | ||
const seq = res.seq | ||
if(manage){ | ||
@@ -221,3 +224,3 @@ if(propertyData){ | ||
if(!seq || typeof(seq) !== 'number'){ | ||
seq = 1 | ||
seq = 0 | ||
} | ||
@@ -230,7 +233,7 @@ if((!keypair) || (!keypair.address || !keypair.secret)){ | ||
propertyData = this.getProperty(keypair.address, true) | ||
if(propertyData && propertyData.infoHash === infoHash){ | ||
return callback(new Error('address key is already attached to this infoHash')) | ||
} | ||
if(propertyData && propertyData.seq){ | ||
if(propertyData){ | ||
seq = propertyData.seq + 1 | ||
if(propertyData.infoHash === infoHash){ | ||
return callback(new Error('address key is already attached to this infoHash')) | ||
} | ||
} | ||
@@ -241,3 +244,3 @@ } | ||
const buffSecKey = Buffer.from(keypair.secret, 'hex') | ||
const getData = {k: buffAddKey, v: {ih: Buffer.from(infoHash, 'hex')}, seq, sign: (buf) => {return sign(buf, buffAddKey, buffSecKey)}} | ||
const getData = {k: buffAddKey, v: Buffer.from(infoHash, 'hex'), seq, sign: (buf) => {return sign(buf, buffAddKey, buffSecKey)}} | ||
@@ -244,0 +247,0 @@ this.dht.put(getData, (putErr, hash, number) => { |
{ | ||
"name": "torrent-properties", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "BEP 46", | ||
@@ -5,0 +5,0 @@ "main": "index.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
14129
346
6