forked from LBRYCommunity/lbry-sdk
Merge branch 'fix-remove-contact'
This commit is contained in:
commit
5919271966
3 changed files with 9 additions and 11 deletions
|
@ -16,7 +16,7 @@ at anytime.
|
||||||
* Fixed slow startup for nodes with many lbry files
|
* Fixed slow startup for nodes with many lbry files
|
||||||
* Fixed setting the external ip on startup
|
* Fixed setting the external ip on startup
|
||||||
* Fixed session startup not blocking on joining the dht
|
* 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 lbryid length validation
|
||||||
* Fixed an old print statement that polluted logs
|
* Fixed an old print statement that polluted logs
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import random
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
import constants
|
import constants
|
||||||
import kbucket
|
import kbucket
|
||||||
|
import protocol
|
||||||
from interface import IRoutingTable
|
from interface import IRoutingTable
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -76,17 +77,13 @@ class TreeRoutingTable(object):
|
||||||
# the k-bucket. This implementation follows section
|
# the k-bucket. This implementation follows section
|
||||||
# 2.2 regarding this point.
|
# 2.2 regarding this point.
|
||||||
|
|
||||||
def replaceContact(failure):
|
def replaceContact(failure, deadContactID):
|
||||||
""" Callback for the deferred PING RPC to see if the head
|
""" Callback for the deferred PING RPC to see if the head
|
||||||
node in the k-bucket is still responding
|
node in the k-bucket is still responding
|
||||||
|
|
||||||
@type failure: twisted.python.failure.Failure
|
@type failure: twisted.python.failure.Failure
|
||||||
"""
|
"""
|
||||||
# 'failure' is a Failure with an error message in the format:
|
failure.trap(protocol.TimeoutError)
|
||||||
# "Timeout connecting to <node id hex>"
|
|
||||||
error_message = failure.getErrorMessage()
|
|
||||||
deadContactID = error_message[22:].decode('hex')
|
|
||||||
|
|
||||||
if len(deadContactID) != constants.key_bits / 8:
|
if len(deadContactID) != constants.key_bits / 8:
|
||||||
raise ValueError("invalid contact id")
|
raise ValueError("invalid contact id")
|
||||||
log.debug("Replacing dead contact: %s", deadContactID.encode('hex'))
|
log.debug("Replacing dead contact: %s", deadContactID.encode('hex'))
|
||||||
|
@ -104,7 +101,7 @@ class TreeRoutingTable(object):
|
||||||
df = head_contact.ping()
|
df = head_contact.ping()
|
||||||
# If there's an error (i.e. timeout), remove the head
|
# If there's an error (i.e. timeout), remove the head
|
||||||
# contact, and append the new one
|
# contact, and append the new one
|
||||||
df.addErrback(replaceContact)
|
df.addErrback(replaceContact, head_contact.id)
|
||||||
|
|
||||||
def findCloseNodes(self, key, count, _rpcNodeID=None):
|
def findCloseNodes(self, key, count, _rpcNodeID=None):
|
||||||
""" Finds a number of known nodes closest to the node/value with the
|
""" Finds a number of known nodes closest to the node/value with the
|
||||||
|
|
Loading…
Add table
Reference in a new issue