Skip to content

Commit

Permalink
fix(p2p): situation when ignoring yourself address is very slow
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Mar 5, 2018
1 parent 0d76dea commit d55c8f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/background/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class p2p {
// nothing
} else {
console.log('ignore local address', iface.address);
this.ignoreAddresses.push(iface.address)
this.ignore(iface.address)
}
++alias;
});
Expand Down Expand Up @@ -152,6 +152,7 @@ class p2p {
clearTimeout(protocolTimeout)
// add to peers
address.emit = emit
address.disconnect = () => rawSocket.destroy()
this.size++;
this.send('peer', this.size)
console.log('new peer', address)
Expand Down Expand Up @@ -211,6 +212,19 @@ class p2p {
return localPeer.address === peer.address
})
}

ignore(address)
{
this.ignoreAddresses.push(address)
// close all connected peers (if they connected already)
this.peers.forEach(peer => {
if(peer.address !== address)
return

if(peer.disconnect)
peer.disconnect()
})
}
}

module.exports = p2p
4 changes: 2 additions & 2 deletions src/background/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ checkInternet((connected) => {
stunServer.close()

console.log('p2p stun ignore my address', address)
p2p.ignoreAddresses.push(address)
p2p.ignore(address)
})
stunServer.send(stunRequest, 19302, 'stun.l.google.com')
})
Expand Down Expand Up @@ -1165,7 +1165,7 @@ if(config.upnp)
return

console.log('p2p upnp ignore my address', ip)
p2p.ignoreAddresses.push(ip)
p2p.ignore(ip)
});
}

Expand Down

0 comments on commit d55c8f2

Please sign in to comment.