本文整理汇总了Python中dht.DHT._on_findNode方法的典型用法代码示例。如果您正苦于以下问题:Python DHT._on_findNode方法的具体用法?Python DHT._on_findNode怎么用?Python DHT._on_findNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.DHT
的用法示例。
在下文中一共展示了DHT._on_findNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import _on_findNode [as 别名]
class CryptoTransportLayer(TransportLayer):
def __init__(self, my_ip, my_port, market_id):
self._log = logging.getLogger('[%s] %s' % (market_id, self.__class__.__name__))
# Connect to database
MONGODB_URI = 'mongodb://localhost:27017'
_dbclient = MongoClient()
self._db = _dbclient.openbazaar
self._market_id = market_id
self.nick_mapping = {}
self._uri = "tcp://%s:%s" % (my_ip, my_port)
# Set up
self._setup_settings()
self._dht = DHT(market_id, self.settings)
self._myself = ec.ECC(pubkey=self.pubkey.decode('hex'), privkey=self.secret.decode('hex'), curve='secp256k1')
TransportLayer.__init__(self, market_id, my_ip, my_port, self.guid)
# Set up callbacks
self.add_callback('ping', self._dht._on_ping)
self.add_callback('findNode', self._findNode)
self.add_callback('findNodeResponse', self._findNodeResponse)
def _findNode(self, msg):
guid = msg['senderGUID']
uri = msg['uri']
pubkey = msg['pubkey']
msg['new_peer'] = CryptoPeerConnection(self, uri, pubkey, guid)
self._dht._on_findNode(msg)
def _findNodeResponse(self, msg):
guid = msg['senderGUID']
uri = msg['uri']
pubkey = msg['pubkey']
#msg['new_peer'] = CryptoPeerConnection(self, uri, pubkey, guid)
self._dht._on_findNodeResponse(self, msg)
def _setup_settings(self):
self.settings = self._db.settings.find_one({'id':"%s" % self._market_id})
if self.settings:
self.nickname = self.settings['nickname'] if self.settings.has_key("nickname") else ""
self.secret = self.settings['secret']
self.pubkey = self.settings['pubkey']
self.guid = self.settings['guid']
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 getCryptoPeer(self, guid, uri, pubkey):
if guid == self.guid:
self._log.info('Trying to get cryptopeer for yourself')
return
peer = CryptoPeerConnection(self, uri, pubkey, guid=guid)
#.........这里部分代码省略.........