Browse Source

peers.py: attempt to bind the right local IP address

Fixes #822, #825
patch-2
Neil Booth 6 years ago
parent
commit
a614e4f4cb
  1. 13
      electrumx/server/peers.py

13
electrumx/server/peers.py

@ -255,20 +255,19 @@ class PeerManager:
if kind == 'SSL':
kwargs['ssl'] = ssl.SSLContext(ssl.PROTOCOL_TLS)
if self.env.report_services:
local_addr_host = self.env.report_services[0].host
else:
local_addr_host = None
if self.env.force_proxy or peer.is_tor:
if not self.proxy:
return
kwargs['proxy'] = self.proxy
kwargs['resolve'] = not peer.is_tor
elif local_addr_host:
else:
# Use our listening Host/IP for outgoing non-proxy
# connections so our peers see the correct source.
kwargs['local_addr'] = (str(local_addr_host), None)
local_hosts = {service.host for service in self.env.services
if isinstance(service.host, (IPv4Address, IPv6Address))
and service.protocol != 'rpc'}
if local_hosts:
kwargs['local_addr'] = (str(local_hosts.pop()), None)
peer_text = f'[{peer}:{port} {kind}]'
try:

Loading…
Cancel
Save