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


Python Node.from_id_26方法代码示例

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


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

示例1: on_response_received

# 需要导入模块: from dht.node import Node [as 别名]
# 或者: from dht.node.Node import from_id_26 [as 别名]
    def on_response_received(self, transaction):
        # Update the id of the remote node.
        transaction.response_node.id_20 = transaction.response["r"]["id"]

        # Add the node that reponded to us. We most likely already have this one.
        self._server.remote_nodes.add(transaction.response_node)

        # A find_node or get_peers response may carry extra nodes.
        if transaction.query["q"] == "find_node" or transaction.query["q"] == "get_peers":
            nodes = transaction.response["r"].get("nodes", "")

            for i in xrange(0, len(nodes), 26):
                id_26 = nodes[i : i + 26]
                if not self._server.remote_nodes.get_node(id_26):
                    self._server.remote_nodes.add(Node.from_id_26(id_26))
开发者ID:romain-gilliotte,项目名称:dht-client,代码行数:17,代码来源:node_store.py

示例2: _receiver

# 需要导入模块: from dht.node import Node [as 别名]
# 或者: from dht.node.Node import from_id_26 [as 别名]
    def _receiver(self):
        """
        Run in a different thread, and have as only goal to receive messages,
        parse them, and put them into a thread safe queue for further handling
        """
        while True:
            try:
                # Receive message
                raw_message, connect_info = self._sock.recvfrom(4096)
                message = bdecode(raw_message)
#                print "Received f " + str(connect_info) + ":\t" + str(message)

                # This is a query from another peer.
                if message['y'] == 'q':
                    # Retrieve or create source node.
                    id_26 = message['a']['id'] + socket.inet_aton(connect_info[0]) + struct.pack(r'!H', connect_info[1])
                    source_node = self.remote_nodes.get_node(id_26) or Node.from_id_26(id_26)

                    transaction = Transaction(query=message, query_node=source_node, response_node=self.node) # create transaction
                    self._running_transactions[transaction.id] = transaction # Add it to running transactions

                    for handler in self.on_query_received:
                        handler(transaction)  # Notify listeners

                elif message['y'] == 'e':
                    raise Exception

                # This is a response to a transaction we started.
                elif message['y'] == 'r':
                    transaction = self._running_transactions.pop(message["t"]) # pop transaction
                    transaction.response = message

                    for handler in self.on_response_received:
                        handler(transaction)  # Notify listeners

                else:
                    raise Exception

            except socket.timeout:
                pass
            except BTFailure:
                pass
            except:
                print traceback.format_exc()
开发者ID:romain-gilliotte,项目名称:dht-client,代码行数:46,代码来源:dht_server.py


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