bittorrent-nodeid
Advanced tools
Comparing version 0.1.1 to 1.0.0
42
index.js
var crc32c; | ||
var binary=false; | ||
@@ -9,29 +8,29 @@ try { | ||
crc32c=require("sse4_crc32"); | ||
} catch(ee) { | ||
crc32c=require('./node_modules/js_crc32c.js'); //modified crc32c for binary format | ||
binary=true; | ||
}; | ||
} catch(ee) {} | ||
}; | ||
var generate_id=function(ip,rand) { //rand 0-255 | ||
//124.31.75.21 | ||
//5fbfbf f10c5d6a4ec8a88e4c6ab4c28b95eee4 01 rand 1 | ||
var c; | ||
var id=new Buffer(20); | ||
var buf=new Buffer(4); | ||
ip=(new Buffer(ip.split('.'))).readUInt32BE(); | ||
buf.writeUInt32BE(((ip & 0x030f3fff) | (rand << 29))>>>0); | ||
var c=crc32c.calculate(buf,0); | ||
id[0]=(c>>24)&0xff; | ||
id[1]=(c>>16)&0xff; | ||
id[2]=((c>>8)&0xf8)|(parseInt(Math.random()*255)&0x7); | ||
for (var i=3;i<19;i++) {id[i]=parseInt(Math.random()*255);} | ||
id[19]=rand; | ||
return id; | ||
}; | ||
/* Other implementation | ||
var generate_id=function(ip,rand) { //rand 0-255 | ||
var id=new Buffer(20); | ||
var mask=[0x03,0x0f,0x3f,0xff]; | ||
ip=ip.split('.'); | ||
//7c,1f,4b,15 | ||
ip.forEach(function(val,i) {ip[i]&=mask[i]}); | ||
ip=ip.map(function(val,i) {return val&mask[i]}); | ||
var r=rand&0x7; | ||
//0,f,b,15 | ||
ip[0]|=r<<5; | ||
//20,f,b,15 | ||
//crc_optimal<32, 0x1EDC6F41, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc; | ||
if (binary) { | ||
c=crc32c.calculate(String.fromCharCode.apply(null,ip),0); | ||
} else { | ||
c=crc32c.calculate(new Buffer(String.fromCharCode.apply(null,ip), 'binary'),0); | ||
}; | ||
console.log(c.toString(16)); | ||
//5fbfbdb2 | ||
var c=crc32c.calculate(new Buffer(ip),0); | ||
id[0]=(c>>24)&0xff; | ||
@@ -42,5 +41,6 @@ id[1]=(c>>16)&0xff; | ||
id[19]=rand; | ||
console.log(id.toString('hex')); | ||
return id; | ||
}; | ||
*/ | ||
module.exports=generate_id; |
{ | ||
"name": "bittorrent-nodeid", | ||
"description": "BEP42 DHT security extension implementation", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"author": "Aymeric Vitte <contact@peersm.com> (http://www.peersm.com)", | ||
@@ -6,0 +6,0 @@ "homepage": "http://torrent-live.org", |
@@ -12,4 +12,2 @@ bittorrent-nodeID | ||
It does include fast-crc32c in node_modules slightly modified to handle the binary format (see the explaination below) but you can link to npm directly: | ||
npm install bittorrent-nodeid | ||
@@ -32,5 +30,5 @@ | ||
Where ip is the ip address representation in network byte order. | ||
Where ip is the ip address representation in network bytes order. | ||
For ip 124.31.75.21, the calculation with a random number set to 1 will be ``crc32c((0x7c1f4b15 & 0x030f3fff) | (1 << 29))``, so ``crc32c(0x200f0b15)`` which is computed as ``crc32c('ABCD')`` where ABCD are the characters corresponding to the ascii code of each byte, the current implementations do process crc32c progessively byte by byte (then crc32c('A'), crc32c('B', previous result), etc). | ||
For ip 124.31.75.21, the calculation with a random number set to 1 will be ``crc32c((0x7c1f4b15 & 0x030f3fff) | (1 << 29))``, so ``crc32c(0x200f0b15)`` which is computed as ``crc32c(new Buffer('200f0b15','hex'))`` or ``crc32c(new Buffer([0x20,0xf,0xb,0x15]))`` or ``crc32c('ABCD')`` where ABCD are the characters corresponding to the ascii code of each byte. | ||
@@ -41,4 +39,2 @@ In javascript a character outside of the normal ascii range like 'Á' will be interpreted as utf8 ``0xc381`` and ``crc32c.calculate('Á')`` will give ``b1cf5bcd`` | ||
This implementation does follow the existing ones (uTorrent, libtorrent, bootstrap-dht) using the second method. | ||
## Related projects : | ||
@@ -45,0 +41,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
5615
38
49