本文整理汇总了Python中address.Address.__hash__方法的典型用法代码示例。如果您正苦于以下问题:Python Address.__hash__方法的具体用法?Python Address.__hash__怎么用?Python Address.__hash__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address.Address
的用法示例。
在下文中一共展示了Address.__hash__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Local
# 需要导入模块: from address import Address [as 别名]
# 或者: from address.Address import __hash__ [as 别名]
#.........这里部分代码省略.........
inrange(remote.id(), self.predecessor().id(1), self.id()) or \
not self.predecessor().ping():
self.predecessor_ = remote
@repeat_and_sleep(FIX_FINGERS_INT)
def fix_fingers(self):
# Randomly select an entry in finger_ table and update its value
self.log("fix_fingers")
i = random.randrange(LOGSIZE - 1) + 1
self.finger_[i] = self.find_successor(self.id(1<<i))
# Keep calling us
return True
@repeat_and_sleep(UPDATE_SUCCESSORS_INT)
@retry_on_socket_error(UPDATE_SUCCESSORS_RET)
def update_successors(self):
self.log("update successor")
suc = self.successor()
# if we are not alone in the ring, calculate
if suc.id() != self.id():
successors = [suc]
suc_list = suc.get_successors()
if suc_list and len(suc_list):
successors += suc_list
# if everything worked, we update
self.successors_ = successors
return True
def get_successors(self):
self.log("get_successors")
return [(node.address_.ip, node.address_.port) for node in self.successors_[:N_SUCCESSORS-1]]
def id(self, offset = 0):
return (self.address_.__hash__() + offset) % SIZE
def successor(self):
# We make sure to return an existing successor, there `might`
# be redundance between finger_[0] and successors_[0], but
# it doesn't harm
for remote in [self.finger_[0]] + self.successors_:
#print remote.address_
if remote.ping():
self.finger_[0] = remote
return remote
print("No successor available, aborting")
self.shutdown_ = True
sys.exit(-1)
def predecessor(self):
return self.predecessor_
#@retry_on_socket_error(FIND_SUCCESSOR_RET)
def find_successor(self, id):
# The successor of a key can be us iff
# - we have a pred(n)
# - id is in (pred(n), n]
self.log("find_successor")
if self.predecessor() and \
inrange(id, self.predecessor().id(1), self.id(1)):
return self
node = self.find_predecessor(id)
return node.successor()
#@retry_on_socket_error(FIND_PREDECESSOR_RET)
def find_predecessor(self, id):
self.log("find_predecessor")