Update peer discovery code for protocol 1.3
This commit is contained in:
parent
9d02b03ab1
commit
d2e8fe7fa1
@ -18,7 +18,7 @@ from functools import partial
|
|||||||
from aiorpcx import ClientSession, RPCError, SOCKSProxy, ConnectionError
|
from aiorpcx import ClientSession, RPCError, SOCKSProxy, ConnectionError
|
||||||
|
|
||||||
from electrumx.lib.peer import Peer
|
from electrumx.lib.peer import Peer
|
||||||
from electrumx.lib.util import ConnectionLogger, class_logger
|
from electrumx.lib.util import ConnectionLogger, class_logger, protocol_tuple
|
||||||
|
|
||||||
|
|
||||||
PEER_GOOD, PEER_STALE, PEER_NEVER, PEER_BAD = range(4)
|
PEER_GOOD, PEER_STALE, PEER_NEVER, PEER_BAD = range(4)
|
||||||
@ -101,20 +101,18 @@ class PeerSession(ClientSession):
|
|||||||
|
|
||||||
def on_version(self, request):
|
def on_version(self, request):
|
||||||
'''Handle the response to the version message.'''
|
'''Handle the response to the version message.'''
|
||||||
if not self.is_good(request, (list, str)):
|
if not self.is_good(request, list):
|
||||||
return
|
return
|
||||||
|
|
||||||
result = request.result()
|
result = request.result()
|
||||||
if isinstance(result, str):
|
# Protocol version 1.1 returns a pair with the version first
|
||||||
version = result
|
if len(result) != 2 or not all(isinstance(x, str) for x in result):
|
||||||
else:
|
self.fail(request, 'result array bad format')
|
||||||
# Protocol version 1.1 returns a pair with the version first
|
return
|
||||||
if len(result) < 2 or not isinstance(result[0], str):
|
version = result[0]
|
||||||
self.fail(request, 'result array bad format')
|
|
||||||
return
|
|
||||||
version = result[0]
|
|
||||||
self.peer.server_version = version
|
self.peer.server_version = version
|
||||||
self.peer.features['server_version'] = version
|
self.peer.features['server_version'] = version
|
||||||
|
self.ptuple = protocol_tuple(result[1])
|
||||||
|
|
||||||
for method, on_done in [
|
for method, on_done in [
|
||||||
('blockchain.headers.subscribe', self.on_height),
|
('blockchain.headers.subscribe', self.on_height),
|
||||||
@ -146,7 +144,10 @@ class PeerSession(ClientSession):
|
|||||||
result = request.result()
|
result = request.result()
|
||||||
controller = self.peer_mgr.controller
|
controller = self.peer_mgr.controller
|
||||||
our_height = controller.bp.db_height
|
our_height = controller.bp.db_height
|
||||||
their_height = result.get('block_height')
|
if self.ptuple < (1, 3):
|
||||||
|
their_height = result.get('block_height')
|
||||||
|
else:
|
||||||
|
their_height = result.get('height')
|
||||||
if not isinstance(their_height, int):
|
if not isinstance(their_height, int):
|
||||||
self.bad('invalid height {}'.format(their_height))
|
self.bad('invalid height {}'.format(their_height))
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user