当前位置: 首页>>代码示例>>Python>>正文


Python Node.replicate方法代码示例

本文整理汇总了Python中dht.node.Node.replicate方法的典型用法代码示例。如果您正苦于以下问题:Python Node.replicate方法的具体用法?Python Node.replicate怎么用?Python Node.replicate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dht.node.Node的用法示例。


在下文中一共展示了Node.replicate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Drogulus

# 需要导入模块: from dht.node import Node [as 别名]
# 或者: from dht.node.Node import replicate [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)
开发者ID:BitPhone,项目名称:drogulus,代码行数:66,代码来源:node.py


注:本文中的dht.node.Node.replicate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。