Don't send private ip addresses on pex

This commit is contained in:
shortcutme 2018-01-30 13:58:01 +01:00
parent a6f86329c5
commit c2edbb30b5
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
5 changed files with 28 additions and 5 deletions

View file

@ -996,7 +996,7 @@ class Site(object):
return connected
# Return: Probably peers verified to be connectable recently
def getConnectablePeers(self, need_num=5, ignore=[]):
def getConnectablePeers(self, need_num=5, ignore=[], allow_private=True):
peers = self.peers.values()
found = []
for peer in peers:
@ -1009,12 +1009,19 @@ class Site(object):
if time.time() - peer.connection.last_recv_time > 60 * 60 * 2: # Last message more than 2 hours ago
peer.connection = None # Cleanup: Dead connection
continue
if not allow_private and helper.isPrivateIp(peer.ip):
continue
found.append(peer)
if len(found) >= need_num:
break # Found requested number of peers
if len(found) < need_num: # Return not that good peers
found = [peer for peer in peers if not peer.key.endswith(":0") and peer.key not in ignore][0:need_num - len(found)]
found = [
peer for peer in peers
if not peer.key.endswith(":0") and
peer.key not in ignore and
(allow_private or not helper.isPrivateIp(peer.ip))
][0:need_num - len(found)]
return found