async def discovery_loop(self): """ Handle poping of nodes in discovery stack :return: """ while self.continue_crawling(): try: await asyncio.sleep(1) peer = self._discovery_stack.pop() except IndexError: await asyncio.sleep(2) else: node, updated = self._processor.update_peer(self.currency, peer) if not node: self._logger.debug("New node found : {0}".format(peer.pubkey[:5])) try: connector = NodeConnector.from_peer(self.currency, peer, self._app.parameters) node = connector.node self._processor.insert_node(connector.node) self.new_node_found.emit(node) except InvalidNodeCurrency as e: self._logger.debug(str(e)) if self._blockchain_service.initialized(): self._processor.handle_success(node) try: identity = await self._identities_service.find_from_pubkey(node.pubkey) identity = await self._identities_service.load_requirements(identity) node.member = identity.member node.uid = identity.uid self._processor.update_node(node) self.node_changed.emit(node) except errors.DuniterError as e: self._logger.error(e.message)
async def discovery_loop(self): """ Handle poping of nodes in discovery stack :return: """ while self.continue_crawling(): try: await asyncio.sleep(1) peer = self._discovery_stack.pop() except IndexError: await asyncio.sleep(2) else: node, updated = self._processor.update_peer( self.currency, peer) if not node: self._logger.debug("New node found : {0}".format( peer.pubkey[:5])) try: connector = NodeConnector.from_peer( self.currency, peer, self._app.parameters) node = connector.node self._processor.insert_node(connector.node) await connector.init_session() connector.refresh(manual=True) self.add_connector(connector) self.new_node_found.emit(node) except InvalidNodeCurrency as e: self._logger.debug(str(e)) if node and updated and self._blockchain_service.initialized(): try: connector = next(conn for conn in self._connectors if conn.node == node) except StopIteration: self._logger.warning( "A node not associated to" " a connector was encoutered : {:}".format( node.pubkey[:7])) else: connector.refresh_summary() try: identity = await self._identities_service.find_from_pubkey( node.pubkey) identity = await self._identities_service.load_requirements( identity) node.member = identity.member node.uid = identity.uid self._processor.update_node(node) self.node_changed.emit(node) except errors.DuniterError as e: self._logger.error(e.message)
def test_from_peer(): peer = Peer.from_signed_raw("""Version: 2 Type: Peer Currency: meta_brouzouf PublicKey: 8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU Block: 48698-000005E0F228038E4DDD4F6CA4ACB01EC88FBAF8 Endpoints: BASIC_MERKLED_API duniter.inso.ovh 80 82o1sNCh1bLpUXU6nacbK48HBcA9Eu2sPkL1/3c2GtDPxBUZd2U2sb7DxwJ54n6ce9G0Oy7nd1hCxN3fS0oADw== """) connector = NodeConnector.from_peer('meta_brouzouf', peer, None) assert connector.node.pubkey == "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" assert connector.node.endpoints[0].inline() == "BASIC_MERKLED_API duniter.inso.ovh 80" assert connector.node.currency == "meta_brouzouf"
def test_from_peer(): peer = Peer.from_signed_raw("""Version: 2 Type: Peer Currency: meta_brouzouf PublicKey: 8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU Block: 48698-000005E0F228038E4DDD4F6CA4ACB01EC88FBAF8 Endpoints: BASIC_MERKLED_API duniter.inso.ovh 80 82o1sNCh1bLpUXU6nacbK48HBcA9Eu2sPkL1/3c2GtDPxBUZd2U2sb7DxwJ54n6ce9G0Oy7nd1hCxN3fS0oADw== """) connector = NodeConnector.from_peer('meta_brouzouf', peer, None) assert connector.node.pubkey == "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU" assert connector.node.endpoints[0].inline( ) == "BASIC_MERKLED_API duniter.inso.ovh 80" assert connector.node.currency == "meta_brouzouf"
def load(cls, app, currency, node_processor, blockchain_service, identities_service): """ Create a new network with all known nodes :param sakia.app.Application app: Sakia application :param str currency: The currency of this service :param sakia.data.processors.NodeProcessor node_processor: The nodes processor :return: """ connectors = [] for node in node_processor.nodes(currency): connectors.append(NodeConnector(node, app.parameters)) network = cls(app, currency, node_processor, connectors, blockchain_service, identities_service) return network