Use our listening Host/IP for outgoing connections also (#226)

Explicitely set the local IP for outgoing connections, if we're listening
on only one Hostname or IP (of a multi-IP machine). This makes sure our
peers see our outgoing connections coming from the same IP that we're
listening on when we have a specific HOST= configured.

For machines with more than one IP this avoids source-destination
mismatch errors when advertizing our peer. Resolves kyuupichan/electrumx#225
This commit is contained in:
mmouse- 2017-08-21 00:47:05 +02:00 committed by Neil
parent 59d8421c87
commit 69c1535d13

View File

@ -560,9 +560,11 @@ class PeerManager(util.LoggedClass):
create_connection = self.proxy.create_connection
else:
create_connection = self.loop.create_connection
local_addr = (self.env.host, None) if self.env.host else None
protocol_factory = partial(PeerSession, peer, self, kind)
coro = create_connection(protocol_factory, peer.host, port, ssl=sslc)
coro = create_connection(protocol_factory, peer.host, port, ssl=sslc, local_addr=local_addr)
callback = partial(self.connection_done, peer, port_pairs)
self.ensure_future(coro, callback)