本文整理汇总了Python中drogulus.dht.routingtable.RoutingTable._replacement_cache[cache_key]方法的典型用法代码示例。如果您正苦于以下问题:Python RoutingTable._replacement_cache[cache_key]方法的具体用法?Python RoutingTable._replacement_cache[cache_key]怎么用?Python RoutingTable._replacement_cache[cache_key]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类drogulus.dht.routingtable.RoutingTable
的用法示例。
在下文中一共展示了RoutingTable._replacement_cache[cache_key]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove_contact_with_cached_replacement
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _replacement_cache[cache_key] [as 别名]
def test_remove_contact_with_cached_replacement(self):
"""
Ensures that the removed contact is replaced by the most up-to-date
contact in the affected k-bucket's cache.
"""
parent_node_id = hex((2 ** 512) + 1)[2:]
r = RoutingTable(parent_node_id)
cache_key = (r._buckets[0].range_min, r._buckets[0].range_max)
contact1 = PeerNode(PUBLIC_KEY, self.version,
'netstring://192.168.0.1:9999/', 0)
contact2 = PeerNode(BAD_PUBLIC_KEY, self.version,
'netstring://192.168.0.1:9999/', 0)
r.add_contact(contact1)
r.add_contact(contact2)
contact2.failed_RPCs = constants.ALLOWED_RPC_FAILS
# Add something into the cache.
contact3 = PeerNode(PUBLIC_KEY + 'foo', self.version,
'netstring://192.168.0.1:9999/', 0)
contact3.network_id = '3'
r._replacement_cache[cache_key] = [contact3, ]
# Sanity check
self.assertEqual(len(r._buckets[0]), 2)
self.assertEqual(len(r._replacement_cache[cache_key]), 1)
r.remove_contact(BAD_PUBLIC_KEY)
self.assertEqual(len(r._buckets[0]), 2)
self.assertEqual(contact1, r._buckets[0]._contacts[0])
self.assertEqual(contact3, r._buckets[0]._contacts[1])
self.assertEqual(len(r._replacement_cache[cache_key]), 0)
示例2: test_remove_contact_removes_from_replacement_cache
# 需要导入模块: from drogulus.dht.routingtable import RoutingTable [as 别名]
# 或者: from drogulus.dht.routingtable.RoutingTable import _replacement_cache[cache_key] [as 别名]
def test_remove_contact_removes_from_replacement_cache(self):
"""
Ensures that if a contact is signalled to be removed it is also cleared
from the replacement_cache that would otherwise be another route for
it to be re-added to the routing table.
"""
parent_node_id = 'deadbeef'
r = RoutingTable(parent_node_id)
contact1 = PeerNode(PUBLIC_KEY, self.version,
'netstring://192.168.0.1:9999/', 0)
contact2 = PeerNode(BAD_PUBLIC_KEY, self.version,
'netstring://192.168.0.1:9999/', 0)
r.add_contact(contact1)
r.add_contact(contact2)
cache_key = (r._buckets[0].range_min, r._buckets[0].range_max)
r._replacement_cache[cache_key] = []
r._replacement_cache[cache_key].append(contact2)
# Sanity check
self.assertEqual(len(r._buckets[0]), 2)
self.assertEqual(len(r._replacement_cache[cache_key]), 1)
r.remove_contact(BAD_PUBLIC_KEY, forced=True)
self.assertEqual(len(r._buckets[0]), 1)
self.assertNotIn(contact2, r._replacement_cache[cache_key])