From 0b771c16ba058d3919b2bac482f4d725473a72fa Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 24 Oct 2017 14:55:20 -0400 Subject: [PATCH 1/3] fix lbry id for dead contact to replace in _IterativeFindHelper --- lbrynet/dht/node.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 2dfa71fea..c77dc27c8 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -753,10 +753,11 @@ class _IterativeFindHelper(object): if testContact not in self.shortlist: self.shortlist.append(testContact) - def removeFromShortlist(self, failure): + def removeFromShortlist(self, failure, deadContactID): """ @type failure: twisted.python.failure.Failure """ failure.trap(protocol.TimeoutError) - deadContactID = failure.getErrorMessage() + if len(deadContactID) != constants.key_bits / 8: + raise ValueError("invalid lbry id") if deadContactID in self.shortlist: self.shortlist.remove(deadContactID) return deadContactID @@ -826,7 +827,7 @@ class _IterativeFindHelper(object): rpcMethod = getattr(contact, self.rpc) df = rpcMethod(self.key, rawResponse=True) df.addCallback(self.extendShortlist) - df.addErrback(self.removeFromShortlist) + df.addErrback(self.removeFromShortlist, contact.id) df.addCallback(self.cancelActiveProbe) df.addErrback(lambda _: log.exception('Failed to contact %s', contact)) self.already_contacted.append(contact.id) From 9479179259e601ac04bd0eaaa5b03370cbb774ed Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 24 Oct 2017 19:17:17 -0400 Subject: [PATCH 2/3] avoid future contact id parsing bugs by passing the contact id as an arg --- lbrynet/dht/routingtable.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lbrynet/dht/routingtable.py b/lbrynet/dht/routingtable.py index 13d0bb802..8f3661f49 100644 --- a/lbrynet/dht/routingtable.py +++ b/lbrynet/dht/routingtable.py @@ -10,6 +10,7 @@ import random from zope.interface import implements import constants import kbucket +import protocol from interface import IRoutingTable import logging @@ -76,17 +77,13 @@ class TreeRoutingTable(object): # the k-bucket. This implementation follows section # 2.2 regarding this point. - def replaceContact(failure): + def replaceContact(failure, deadContactID): """ Callback for the deferred PING RPC to see if the head node in the k-bucket is still responding @type failure: twisted.python.failure.Failure """ - # 'failure' is a Failure with an error message in the format: - # "Timeout connecting to " - error_message = failure.getErrorMessage() - deadContactID = error_message[22:].decode('hex') - + failure.trap(protocol.TimeoutError) if len(deadContactID) != constants.key_bits / 8: raise ValueError("invalid contact id") log.debug("Replacing dead contact: %s", deadContactID.encode('hex')) @@ -104,7 +101,7 @@ class TreeRoutingTable(object): df = head_contact.ping() # If there's an error (i.e. timeout), remove the head # contact, and append the new one - df.addErrback(replaceContact) + df.addErrback(replaceContact, head_contact.id) def findCloseNodes(self, key, count, _rpcNodeID=None): """ Finds a number of known nodes closest to the node/value with the From 5bc856932dd8a84f446ae9d8d2fe6ee47ec67306 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Tue, 24 Oct 2017 19:18:13 -0400 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec64216ba..be48489f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ at anytime. * Fixed slow startup for nodes with many lbry files * Fixed setting the external ip on startup * Fixed session startup not blocking on joining the dht - * Fixed a bug that prevented replacing dht contacts + * Fixed several parsing bugs that prevented replacing dead dht contacts * Fixed lbryid length validation * Fixed an old print statement that polluted logs