本文整理汇总了Python中dht.DHT.iterativeStore方法的典型用法代码示例。如果您正苦于以下问题:Python DHT.iterativeStore方法的具体用法?Python DHT.iterativeStore怎么用?Python DHT.iterativeStore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.DHT
的用法示例。
在下文中一共展示了DHT.iterativeStore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import iterativeStore [as 别名]
#.........这里部分代码省略.........
)
def respond_pubkey_if_mine(self, nickname, ident_pubkey):
if ident_pubkey != self.pubkey:
self.log.info("Public key does not match your identity")
return
# Return signed pubkey
pubkey = self.cryptor.pubkey # XXX: A Cryptor does not have such a field.
ec_key = obelisk.EllipticCurveKey()
ec_key.set_secret(self.secret)
digest = obelisk.Hash(pubkey)
signature = ec_key.sign(digest)
# Send array of nickname, pubkey, signature to transport layer
self.send(proto_response_pubkey(nickname, pubkey, signature))
def send(self, data, send_to=None, callback=None):
self.log.debug("Outgoing Data: %s %s", data, send_to)
# Directed message
if send_to is not None:
peer = self.dht.routingTable.getContact(send_to)
if peer is None:
for activePeer in self.dht.activePeers:
if activePeer.guid == send_to:
peer = activePeer
break
if peer:
self.log.debug('Directed Data (%s): %s', send_to, data)
try:
peer.send(data, callback=callback)
except Exception as e:
self.log.error('Not sending message directly to peer %s', e)
else:
self.log.error('No peer found')
else:
# FindKey and then send
for peer in self.dht.activePeers:
try:
routing_peer = self.dht.routingTable.getContact(peer.guid)
if routing_peer is None:
self.dht.routingTable.addContact(peer)
routing_peer = peer
data['senderGUID'] = self.guid
data['pubkey'] = self.pubkey
def cb(msg):
self.log.debug('Message Back: \n%s', pformat(msg))
routing_peer.send(data, cb)
except Exception:
self.log.info("Error sending over peer!")
traceback.print_exc()
def _on_message(self, msg):
# here goes the application callbacks
# we get a "clean" msg which is a dict holding whatever
pubkey = msg.get('pubkey')
uri = msg.get('uri')
guid = msg.get('senderGUID')
nickname = msg.get('senderNick')[:120]
self.log.info('On Message: %s', json.dumps(msg, ensure_ascii=False))
self.dht.add_peer(self, uri, pubkey, guid, nickname)
t = Thread(target=self.trigger_callbacks, args=(msg['type'], msg,))
t.start()
def store(self, *args, **kwargs):
"""
Store or republish data.
Refer to the dht module (iterativeStore()) for further details.
"""
self.dht.iterativeStore(*args, **kwargs)
def shutdown(self):
print "CryptoTransportLayer.shutdown()!"
print "Notice: explicit DHT Shutdown not implemented."
try:
if self.bitmessage_api is not None:
self.bitmessage_api.close()
except Exception as e:
# It might not even be open; we can't do much more on our
# way out if exception is thrown here.
self.log.error(
"Could not shutdown bitmessage_api's ServerProxy: %s", e.message
)