Browse Source

aiorpcX 0.17 fixes (#804)

proxy_peername() to proxy_address() for is_tor()

also use NetAddress for on_add_peer()
patch-2
Shane M 6 years ago
committed by Neil
parent
commit
a2c4902c5e
  1. 12
      electrumx/server/peers.py
  2. 8
      electrumx/server/session.py

12
electrumx/server/peers.py

@ -472,14 +472,14 @@ class PeerManager:
'''Add a peer passed by the admin over LocalRPC.''' '''Add a peer passed by the admin over LocalRPC.'''
await self._note_peers([Peer.from_real_name(real_name, 'RPC')]) await self._note_peers([Peer.from_real_name(real_name, 'RPC')])
async def on_add_peer(self, features, source_info): async def on_add_peer(self, features, source_addr):
'''Add a peer (but only if the peer resolves to the source).''' '''Add a peer (but only if the peer resolves to the source).'''
if self.env.peer_discovery != self.env.PD_ON: if self.env.peer_discovery != self.env.PD_ON:
return False return False
if not source_info: if not source_addr:
self.logger.info('ignored add_peer request: no source info') self.logger.info('ignored add_peer request: no source info')
return False return False
source = source_info[0] source = str(source_addr.host)
peers = Peer.peers_from_features(features, source) peers = Peer.peers_from_features(features, source)
if not peers: if not peers:
self.logger.info('ignored add_peer request: no peers given') self.logger.info('ignored add_peer request: no peers given')
@ -557,10 +557,10 @@ class PeerManager:
return [peer.to_tuple() for peer in peers] return [peer.to_tuple() for peer in peers]
def proxy_peername(self): def proxy_address(self):
'''Return the peername of the proxy, if there is a proxy, otherwise '''Return the NetAddress of the proxy, if there is a proxy, otherwise
None.''' None.'''
return self.proxy.peername if self.proxy else None return self.proxy.address if self.proxy else None
def rpc_data(self): def rpc_data(self):
'''Peer data for the peers RPC method.''' '''Peer data for the peers RPC method.'''

8
electrumx/server/session.py

@ -989,7 +989,7 @@ class ElectrumX(SessionBase):
'''Add a peer (but only if the peer resolves to the source).''' '''Add a peer (but only if the peer resolves to the source).'''
self.is_peer = True self.is_peer = True
self.bump_cost(100.0) self.bump_cost(100.0)
return await self.peer_mgr.on_add_peer(features, self.remote_address_string(for_log=False)) return await self.peer_mgr.on_add_peer(features, self.remote_address())
async def peers_subscribe(self): async def peers_subscribe(self):
'''Return the server peers as a list of (ip, host, details) tuples.''' '''Return the server peers as a list of (ip, host, details) tuples.'''
@ -1169,10 +1169,10 @@ class ElectrumX(SessionBase):
def is_tor(self): def is_tor(self):
'''Try to detect if the connection is to a tor hidden service we are '''Try to detect if the connection is to a tor hidden service we are
running.''' running.'''
peername = self.peer_mgr.proxy_peername() proxy_address = self.peer_mgr.proxy_address()
if not peername: if not proxy_address:
return False return False
return self.remote_address().host == peername[0] return self.remote_address().host == proxy_address.host
async def replaced_banner(self, banner): async def replaced_banner(self, banner):
network_info = await self.daemon_request('getnetworkinfo') network_info = await self.daemon_request('getnetworkinfo')

Loading…
Cancel
Save