Comparing version 0.0.2 to 0.0.3
42
index.js
var punch = require('./punch'); | ||
var stun = require('./stun'); | ||
exports.connect = (irc, to, rinfo) => new Promise((res, rej) => | ||
exports.connect = (irc, to, rinfo, punchTime) => new Promise((res, rej) => | ||
stun('stun.ucsb.edu').then(socket => { | ||
@@ -19,3 +19,3 @@ var onrinfo = (rinfo) => { | ||
if (rinfo) { | ||
socket.linfo.punchTime = rinfo.punchTime = Date.now() + 10000; | ||
socket.linfo.punchTime = rinfo.punchTime = Date.now() + (punchTime || 10000); | ||
onrinfo(rinfo); | ||
@@ -35,29 +35,17 @@ } else { | ||
exports.Socket = function (_socket, lport, rport, onrecv) { | ||
this._socket = _socket; | ||
exports.send = (socket, msg, lport, rport) => { | ||
var buf = new Buffer(4); | ||
buf.writeUInt16BE(lport, 0); | ||
buf.writeUInt16BE(rport, 2); | ||
socket.send(Buffer.concat([buf, msg]), socket.rinfo.port, socket.rinfo.address); | ||
}; | ||
this.sendBuf = new Buffer(4); | ||
this.sendBuf.writeUInt16LE(lport, 0); | ||
this.sendBuf.writeUInt16LE(rport, 2); | ||
this.recvBuf = new Buffer(4); | ||
this.recvBuf.writeUInt16LE(rport, 0); | ||
this.recvBuf.writeUInt16LE(lport, 2); | ||
this.recvNum = this.recvBuf.readUInt32LE(0); | ||
this.onrecv = onrecv; | ||
this.onmsg = (msg) => { | ||
if (msg.length > 4 && msg.slice(0, 4).readUInt32LE(0) === this.recvNum) | ||
this.onrecv(msg.slice(4)); | ||
}; | ||
this._socket.on('message', this.onmsg); | ||
this._socket.on('error', () => { | ||
this._socket.removeListener('message', this.onmsg); | ||
exports.onrecv = (socket, cb) => { | ||
socket.on('message', (msg) => { | ||
if (msg.length <= 4) | ||
return ; | ||
var rport = msg.readUInt16BE(0); | ||
var lport = msg.readUInt16BE(2); | ||
cb(msg.slice(4), lport, rport); | ||
}); | ||
}; | ||
exports.Socket.prototype.send = function (msg) { | ||
this._socket.send(Buffer.concat(this.sendBuf, msg), | ||
this._socket.rinfo.port, this._socket.rinfo.address); | ||
}; |
{ | ||
"name": "anygram", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
30
punch.js
@@ -30,16 +30,20 @@ var code = ':P'; | ||
for (var epoch = 0; epoch < 3; ++epoch) { | ||
for (var i = 0; i <= 300; ++i) { | ||
setTimeout(((i) => () => { | ||
if (socket.rinfo.pong) return ; | ||
if (socket.linfo.type === 'Symmetric') { | ||
send(socket); | ||
} else { | ||
send(socket, socket.rinfo.port + i); | ||
send(socket, socket.rinfo.port - i); | ||
} | ||
})(i), 3 * i + 1000 * epoch); | ||
setTimeout(() => { | ||
if (socket.rinfo.pong) return ; | ||
for (var epoch = 0; epoch < 3; ++epoch) { | ||
for (var i = 0; i <= 300; ++i) { | ||
setTimeout(((i) => () => { | ||
if (socket.rinfo.pong) return ; | ||
if (socket.linfo.type === 'Symmetric') { | ||
send(socket); | ||
} else { | ||
send(socket, socket.rinfo.port + i); | ||
send(socket, socket.rinfo.port - i); | ||
} | ||
})(i), 3 * i + 1000 * epoch); | ||
} | ||
} | ||
} | ||
setTimeout(() => rej('UDP hole punching failed'), 3000); | ||
setTimeout(() => rej('UDP hole punching failed'), 3000); | ||
}, 1000); | ||
}); |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
26225
11
167
4