+12
-2
@@ -26,3 +26,12 @@ #!/usr/bin/env node | ||
| var PING = new Buffer([0]) | ||
| var ping = function() { | ||
| sock.send(PING, 0, PING.length, hp.split(':')[1] || 23232, hp.split(':')[0]) | ||
| } | ||
| sock.once('message', function (message, rinfo) { | ||
| if (message.length === 1 && message[0] === 0) return // ping | ||
| setInterval(ping, 5000) | ||
| // quick'n'dirty - first message is from the hole puncher | ||
@@ -37,2 +46,3 @@ | ||
| sock.on('message', function (message, rinfo) { | ||
| if (message.length === 1 && message[0] === 0) return // ping | ||
| if (peers.indexOf(rinfo.address + ':' + rinfo.port) === -1) peers.push(rinfo.address + ':' + rinfo.port) | ||
@@ -46,6 +56,6 @@ console.log('[%s:%d] %s', rinfo.address, rinfo.port, message.toString().trim()) | ||
| peers.forEach(function (peer) { | ||
| sock.send(data, 0, data.length, Number(peer.split(':')[1]), peer.split(':')[0], console.log) | ||
| sock.send(data, 0, data.length, Number(peer.split(':')[1]), peer.split(':')[0]) | ||
| }) | ||
| }) | ||
| sock.send(channel, 0, channel.length, hp.split(':')[1] || 23232, hp.split(':')[0]) | ||
| sock.send(channel, 0, channel.length, hp.split(':')[1] || 23232, hp.split(':')[0]) |
+23
-5
@@ -21,2 +21,4 @@ #!/usr/bin/env node | ||
| var PING = new Buffer([0]) | ||
| sock.on('error', function (err) { | ||
@@ -27,6 +29,22 @@ console.log('error: %s', err.message) | ||
| sock.on('message', function (message, rinfo) { | ||
| var id = rinfo.address + ':' + rinfo.port | ||
| if (message.length === 1 && message[0] === 0) { | ||
| Object.keys(pairs).some(function(ch) { | ||
| var clear = function() { | ||
| delete pairs[ch] | ||
| } | ||
| if (pairs[ch][id]) { | ||
| clearTimeout(timeouts[ch]) | ||
| timeouts[ch] = setTimeout(clear, 10 * 1000) | ||
| sock.send(PING, 0, PING.length, rinfo.port, rinfo.address) | ||
| return true | ||
| } | ||
| }) | ||
| return | ||
| } | ||
| var channel = message.toString() | ||
| var id = rinfo.address + ':' + rinfo.port | ||
| console.log('remembering %s (%s) for a while', id, channel) | ||
@@ -41,6 +59,6 @@ | ||
| clearTimeout(timeouts[id]) | ||
| timeouts[id] = setTimeout(clear, 60 * 1000) | ||
| clearTimeout(timeouts[channel]) | ||
| timeouts[channel] = setTimeout(clear, 10 * 1000) | ||
| var buf = string2compact(Object.keys(pairs[channel])) | ||
| var buf = string2compact(Object.keys(pairs[channel]).slice(0, 100)) | ||
| sock.send(buf, 0, buf.length, rinfo.port, rinfo.address) | ||
@@ -47,0 +65,0 @@ }) |
+1
-1
| { | ||
| "name": "telephone", | ||
| "version": "1.1.0", | ||
| "version": "1.2.0", | ||
| "description": "Like that Lada Gaga song except it is p2p chat over udp.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
6173
13.14%94
28.77%