本文整理汇总了Python中dht.DHT.add_active_peer方法的典型用法代码示例。如果您正苦于以下问题:Python DHT.add_active_peer方法的具体用法?Python DHT.add_active_peer怎么用?Python DHT.add_active_peer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dht.DHT
的用法示例。
在下文中一共展示了DHT.add_active_peer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import add_active_peer [as 别名]
#.........这里部分代码省略.........
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))
# Return data array with details from the crypto file
# TODO: This needs to be protected better; potentially encrypted file or DB
@staticmethod
def load_crypto_details(store_file):
with open(store_file) as f:
data = json.loads(f.read())
assert "nickname" in data
assert "secret" in data
assert "pubkey" in data
assert len(data["secret"]) == 2 * 32
assert len(data["pubkey"]) == 2 * 33
return data["nickname"], data["secret"].decode("hex"), \
data["pubkey"].decode("hex")
def get_profile(self):
peers = {}
self.settings = self._db.settings.find_one({'id':"%s" % self._market_id})
for uri, peer in self._peers.iteritems():
if peer._pub:
peers[uri] = peer._pub.encode('hex')
return {'uri': self._uri, 'pub': self._myself.get_pubkey().encode('hex'),'nickname': self.nickname,
'peers': peers}
def respond_pubkey_if_mine(self, nickname, ident_pubkey):
if ident_pubkey != self.pubkey:
示例2: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import add_active_peer [as 别名]
#.........这里部分代码省略.........
return peer
def get_crypto_peer(self, guid, uri, pubkey=None, nickname=None):
if guid == self.guid:
self._log.info('Trying to get crypto peer for yourself')
return
self._log.info('%s %s %s %s' % (guid, uri, pubkey, nickname))
peer = CryptoPeerConnection(self, uri, pubkey, guid=guid, nickname=nickname)
return peer
def addCryptoPeer(self, peer_to_add):
foundOutdatedPeer = False
for idx, peer in enumerate(self._dht._activePeers):
if (peer._address, peer._guid, peer._pub) == (peer_to_add._address, peer_to_add._guid, peer_to_add._pub):
self._log.info('Found existing peer, not adding.')
return
if peer._guid == peer_to_add._guid or peer._pub == peer_to_add._pub or peer._address == peer_to_add._address:
foundOutdatedPeer = True
self._log.info('Found an outdated peer')
# Update existing peer
self._activePeers[idx] = peer_to_add
if not foundOutdatedPeer and peer_to_add._guid != self._guid:
self._log.info('Adding crypto peer at %s' % peer_to_add._nickname)
self._dht.add_active_peer(self, (peer_to_add._pub, peer_to_add._address, peer_to_add._guid, peer_to_add._nickname))
# Return data array with details from the crypto file
# TODO: This needs to be protected better; potentially encrypted file or DB
@staticmethod
def load_crypto_details(store_file):
with open(store_file) as f:
data = json.loads(f.read())
assert "nickname" in data
assert "secret" in data
assert "pubkey" in data
assert len(data["secret"]) == 2 * 32
assert len(data["pubkey"]) == 2 * 33
return data["nickname"], data["secret"].decode("hex"), \
data["pubkey"].decode("hex")
def get_profile(self):
peers = {}
self.settings = self._db.settings.find_one({'id':"%s" % self._market_id})
for uri, peer in self._peers.iteritems():
if peer._pub:
peers[uri] = peer._pub.encode('hex')
return {'uri': self._uri, 'pub': self._myself.get_pubkey().encode('hex'),'nickname': self._nickname,
'peers': peers}
def respond_pubkey_if_mine(self, nickname, ident_pubkey):
if ident_pubkey != self.pubkey:
示例3: CryptoTransportLayer
# 需要导入模块: from dht import DHT [as 别名]
# 或者: from dht.DHT import add_active_peer [as 别名]
#.........这里部分代码省略.........
peer = CryptoPeerConnection(self, uri, callback=cb)
return 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_to_add):
foundOutdatedPeer = False
for idx, peer in enumerate(self._dht._activePeers):
if (peer._address, peer._guid, peer._pub) == (peer_to_add._address, peer_to_add._guid, peer_to_add._pub):
self._log.info('Found existing peer, not adding.')
return
if peer._guid == peer_to_add._guid or peer._pub == peer_to_add._pub or peer._address == peer_to_add._address:
foundOutdatedPeer = True
self._log.info('Found an outdated peer')
# Update existing peer
self._activePeers[idx] = peer_to_add
if not foundOutdatedPeer and peer_to_add._guid != self._guid:
self._log.info('Adding crypto peer at %s' % peer_to_add._address)
self._dht.add_active_peer(self, (peer_to_add._pub, peer_to_add._address, peer_to_add._guid))
# Return data array with details from the crypto file
# TODO: This needs to be protected better; potentially encrypted file or DB
@staticmethod
def load_crypto_details(store_file):
with open(store_file) as f:
data = json.loads(f.read())
assert "nickname" in data
assert "secret" in data
assert "pubkey" in data
assert len(data["secret"]) == 2 * 32
assert len(data["pubkey"]) == 2 * 33
return data["nickname"], data["secret"].decode("hex"), \
data["pubkey"].decode("hex")
def get_profile(self):
peers = {}
self.settings = self._db.settings.find_one({'id':"%s" % self._market_id})
for uri, peer in self._peers.iteritems():
if peer._pub:
peers[uri] = peer._pub.encode('hex')
return {'uri': self._uri, 'pub': self._myself.get_pubkey().encode('hex'),'nickname': self.nickname,
'peers': peers}
def respond_pubkey_if_mine(self, nickname, ident_pubkey):
if ident_pubkey != self.pubkey: