fix lbry id for dead contact to replace in _IterativeFindHelper

This commit is contained in:
Jack Robison 2017-10-24 14:55:20 -04:00
parent bbc960aaf9
commit 0b771c16ba
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF

View file

@ -753,10 +753,11 @@ class _IterativeFindHelper(object):
if testContact not in self.shortlist: if testContact not in self.shortlist:
self.shortlist.append(testContact) self.shortlist.append(testContact)
def removeFromShortlist(self, failure): def removeFromShortlist(self, failure, deadContactID):
""" @type failure: twisted.python.failure.Failure """ """ @type failure: twisted.python.failure.Failure """
failure.trap(protocol.TimeoutError) failure.trap(protocol.TimeoutError)
deadContactID = failure.getErrorMessage() if len(deadContactID) != constants.key_bits / 8:
raise ValueError("invalid lbry id")
if deadContactID in self.shortlist: if deadContactID in self.shortlist:
self.shortlist.remove(deadContactID) self.shortlist.remove(deadContactID)
return deadContactID return deadContactID
@ -826,7 +827,7 @@ class _IterativeFindHelper(object):
rpcMethod = getattr(contact, self.rpc) rpcMethod = getattr(contact, self.rpc)
df = rpcMethod(self.key, rawResponse=True) df = rpcMethod(self.key, rawResponse=True)
df.addCallback(self.extendShortlist) df.addCallback(self.extendShortlist)
df.addErrback(self.removeFromShortlist) df.addErrback(self.removeFromShortlist, contact.id)
df.addCallback(self.cancelActiveProbe) df.addCallback(self.cancelActiveProbe)
df.addErrback(lambda _: log.exception('Failed to contact %s', contact)) df.addErrback(lambda _: log.exception('Failed to contact %s', contact))
self.already_contacted.append(contact.id) self.already_contacted.append(contact.id)