Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anygram

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anygram - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

a.tgz

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,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);
});
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