本文整理汇总了Python中dht.node.Node.retrieve方法的典型用法代码示例。如果您正苦于以下问题:Python Node.retrieve方法的具体用法?Python Node.retrieve怎么用?Python Node.retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.node.Node
的用法示例。
在下文中一共展示了Node.retrieve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Drogulus
# 需要导入模块: from dht.node import Node [as 别名]
# 或者: from dht.node.Node import retrieve [as 别名]
class Drogulus(object):
"""
Represents a node in the Drogulus distributed hash table. This is the
class that generally should be instantiated.
"""
def __init__(self, private_key, public_key, alias=None):
self.private_key = private_key
self.public_key = public_key
self._node = Node()
if alias:
self.alias = alias
else:
self.alias = {}
def join(self):
"""
Causes the node to join the distributed hash table. Returns a deferred
that fires when the operation is complete.
"""
pass
def whois(self, public_key):
"""
Given the public key of an entity that uses the drogulus will return a
deferred that fires when information about them stored in the DHT is
retrieved.
"""
return self.get(public_key, None)
def get(self, public_key, key_name):
"""
Gets the value associated with a compound key made of the passed in
public key and meaningful key name. Returns a deferred that fires when
the value is retrieved.
"""
target = construct_key(public_key, key_name)
return self._node.retrieve(target)
def set(self, key_name, value, duplicate=DUPLICATION_COUNT, meta=None,
expires=EXPIRY_DURATION):
"""
Stores a value at a compound key made from the local node's public key
and the passed in meaningful key name. Returns a deferred that fires
when the value has been stored to duplicate number of nodes. An
optional meta dictionary and expires duration (to be added to the
current time) can also be specified.
"""
timestamp = time.time()
if meta is None:
meta = {}
if expires < 1:
expires = -1
else:
expires = timestamp + expires
signature = generate_signature(value, timestamp, expires, key_name,
meta, self.private_key)
return self._node.replicate(self.public_key, key_name, value,
timestamp, expires, meta, signature,
duplicate)