Skip to content

Commit

Permalink
fix(p2p): some ignoring of local addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Mar 2, 2018
1 parent 3b8a70c commit 835038b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/background/p2p.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const config = require('./config');
const net = require('net')
const JsonSocket = require('json-socket')
const os = require('os');

class p2p {
peers = []
Expand All @@ -14,7 +15,11 @@ class p2p {
this.tcpServer = net.createServer();
this.tcpServer.on('connection', (socket) => {
// try to setup back connection
this.add(socket.address())
const address = socket.address()
if(address.family == 'IPv4')
{
this.add(address)
}

socket = new JsonSocket(socket);
socket.on('error', (err) => {})
Expand All @@ -39,6 +44,25 @@ class p2p {
protocol: 'rats'
})
})

// ignore local addresses
const ifaces = os.networkInterfaces();
Object.keys(ifaces).forEach((ifname) => {
let alias = 0;
ifaces[ifname].forEach((iface) => {
if ('IPv4' !== iface.family || iface.internal !== false) {
return;
}

if (alias >= 1) {
// nothing
} else {
console.log('ignore local address', iface.address);
this.ignoreAddresses.push(iface.address)
}
++alias;
});
});
}

listen() {
Expand Down

0 comments on commit 835038b

Please sign in to comment.