本文整理汇总了Python中dht.DHT.start方法的典型用法代码示例。如果您正苦于以下问题:Python DHT.start方法的具体用法?Python DHT.start怎么用?Python DHT.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.DHT
的用法示例。
在下文中一共展示了DHT.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import start [as 别名]
#.........这里部分代码省略.........
else:
self.nickname = 'Default'
self._generate_new_keypair()
self.settings = self._db.settings.find_one({'id':"%s" % self._market_id})
self._log.debug('Retrieved Settings: %s', self.settings)
def _generate_new_keypair(self):
# Generate new keypair
key = ec.ECC(curve='secp256k1')
self.secret = key.get_privkey().encode('hex')
pubkey = key.get_pubkey()
signedPubkey = key.sign(pubkey)
self.pubkey = pubkey.encode('hex')
self._myself = key
# Generate a node ID by ripemd160 hashing the signed pubkey
guid = hashlib.new('ripemd160')
guid.update(signedPubkey)
self.guid = guid.digest().encode('hex')
self._db.settings.update({"id":'%s' % self._market_id}, {"$set": {"secret":self.secret, "pubkey":self.pubkey, "guid":self.guid}}, True)
def join_network(self, seed_uri):
self.listen(self.pubkey) # Turn on zmq socket
if seed_uri:
self._log.info('Initializing Seed Peer(s): [%s]' % seed_uri)
seed_peer = CryptoPeerConnection(self, seed_uri)
self._dht.start(seed_peer)
def get_crypto_peer(self, guid, uri, pubkey=None):
if guid == self.guid:
self._log.info('Trying to get cryptopeer for yourself')
return
peer = CryptoPeerConnection(self, uri, pubkey, guid=guid)
return peer
def addCryptoPeer(self, peer):
peerExists = False
for idx, aPeer in enumerate(self._activePeers):
if aPeer._guid == peer._guid or aPeer._pub == peer._pub or aPeer._address == peer._address:
self._log.info('guids or pubkey match')
peerExists = True
if peer._pub and aPeer._pub == '':
self._log.info('no pubkey')
aPeer._pub = peer._pub
self._activePeers[idx] = aPeer
if not peerExists and peer._guid != self._guid:
self._log.info('Adding crypto peer %s' % peer._pub)
self._routingTable.addContact(peer)
print peer
self._dht.add_active_peer(self, (peer._pub, peer._address, peer._guid))