def __init__(self, node, ha=None, cliname=None, cliha=None): self.node = node self.name = node.name self.config = node.config self.genesis_dir = node.genesis_dir self.keys_dir = node.keys_dir self._ledger = None self._id = None TxnStackManager.__init__(self, self.name, node.genesis_dir, node.keys_dir, isNode=True) self.state = self.loadState() self.reqHandler = self.getPoolReqHandler() self.initPoolState() self._load_nodes_order_from_ledger() self.nstack, self.cstack, self.nodeReg, self.cliNodeReg = \ self.getStackParamsAndNodeReg(self.name, self.keys_dir, ha=ha, cliname=cliname, cliha=cliha) self._dataFieldsValidators = ( (NODE_IP, self._isIpAddressValid), (CLIENT_IP, self._isIpAddressValid), (NODE_PORT, self._isPortValid), (CLIENT_PORT, self._isPortValid), )
def __init__(self, node, ha=None, cliname=None, cliha=None): self.node = node self.name = node.name self.config = node.config self.basedirpath = node.basedirpath self._ledger = None TxnStackManager.__init__(self, self.name, self.basedirpath, isNode=True) self.nstack, self.cstack, self.nodeReg, self.cliNodeReg = \ self.getStackParamsAndNodeReg(self.name, self.basedirpath, ha=ha, cliname=cliname, cliha=cliha)
def __init__(self): self._ledgerFile = None TxnStackManager.__init__(self, self.name, self.genesis_dir, self.keys_dir, isNode=False) _, cliNodeReg, nodeKeys = self.parseLedgerForHaAndKeys(self.ledger) self.nodeReg = cliNodeReg self.addRemoteKeysFromLedger(nodeKeys) # Temporary place for keeping node transactions while this client is # discovering. Key is sequence number and value is dictionary where key # is the name of the node and value is the transaction. Transaction # should be applied in increasing order of sequence numbers. self.tempNodeTxns = {} # type: Dict[int, Dict[str, Dict]]
def __init__(self): self._ledgerFile = None self._ledgerLocation = None TxnStackManager.__init__(self, self.name, self.basedirpath, isNode=False) _, cliNodeReg, nodeKeys = self.parseLedgerForHaAndKeys(self.ledger) self.nodeReg = cliNodeReg self.addRemoteKeysFromLedger(nodeKeys) # Temporary place for keeping node transactions while this client is # discovering. Key is sequence number and value is dictionary where key # is the name of the node and value is the transaction. Transaction # should be applied in increasing order of sequence numbers. self.tempNodeTxns = {} # type: Dict[int, Dict[str, Dict]]
def migrate_all(): node_name = get_node_name() if node_name is None: logger.error("Could not get node name") return False ledger = get_pool_ledger(node_name) nodeReg, _, _ = TxnStackManager.parseLedgerForHaAndKeys(ledger) if nodeReg is None: logger.error("Empty node registry returned by stack manager") return False if node_name not in nodeReg: logger.error("Node registry does not contain node {}".format(node_name)) return False ha = nodeReg[node_name] if ha is None: logger.error("Empty HA for node {}".format(node_name)) return False logger.info("HA for {}: {}".format(node_name, ha)) try: append_ips_to_env(ha.host) except Exception: logger.error(traceback.print_exc()) logger.error("Could not append node and client IPs to indy env file") return False return True
def nodeServicesChanged(self, txn): nodeNym = txn[TARGET_NYM] _, nodeInfo = self.getNodeInfoFromLedger(nodeNym) nodeName = nodeInfo[DATA][ALIAS] oldServices = set(nodeInfo[DATA].get(SERVICES, [])) newServices = set(txn[DATA].get(SERVICES, [])) if oldServices == newServices: logger.debug( "Node {} not changing {} since it is same as existing".format( nodeNym, SERVICES)) return else: if self.name != nodeName: if VALIDATOR in newServices.difference(oldServices): # If validator service is enabled self.updateNodeTxns(nodeInfo, txn) self.connectNewRemote(nodeInfo, nodeName, self.node) self.node.nodeJoined(txn) if VALIDATOR in oldServices.difference(newServices): # If validator service is disabled del self.node.nodeReg[nodeName] del self.node.cliNodeReg[nodeName + CLIENT_STACK_SUFFIX] try: rid = TxnStackManager.removeRemote( self.node.nodestack, nodeName) if rid: self.node.nodestack.outBoxes.pop(rid, None) except RemoteNotFound: logger.debug( '{} did not find remote {} to remove'.format( self, nodeName)) self.node.nodeLeft(txn) self.node_about_to_be_disconnected(nodeName)
def nodeServicesChanged(self, txn_data): nodeNym = txn_data[TARGET_NYM] _, nodeInfo = self.getNodeInfoFromLedger(nodeNym) remoteName = nodeInfo[DATA][ALIAS] + CLIENT_STACK_SUFFIX oldServices = set(nodeInfo[DATA].get(SERVICES, [])) newServices = set(txn_data[DATA].get(SERVICES, [])) if oldServices == newServices: logger.debug( "Client {} not changing {} since it is same as existing" .format(nodeNym, SERVICES)) return else: if VALIDATOR in newServices.difference(oldServices): # If validator service is enabled self.updateNodeTxns(nodeInfo, txn_data) self.connectNewRemote(nodeInfo, remoteName, self) if VALIDATOR in oldServices.difference(newServices): # If validator service is disabled del self.nodeReg[remoteName] try: rid = TxnStackManager.removeRemote( self.nodestack, remoteName) if rid: self.nodestack.outBoxes.pop(rid, None) except RemoteNotFound: logger.info('{} did not find remote {} to remove'.format(self, remoteName))
def test_parse_non_base58_txn_type_field_raises_descriptive_error( tdirWithLedger, tdir): with pytest.raises(ValueError) as excinfo: ledger = Ledger(CompactMerkleTree(), dataDir=tdir) _, _, nodeKeys = TxnStackManager.parseLedgerForHaAndKeys(ledger) assert ("verkey" in str(excinfo.value)) ledger.stop()
def test_pool_file_is_invalid_raises_SystemExit_has_descriptive_error( tdir_for_func): """ Test that that invalid pool_transaction file raises the proper exception (INDY-150) """ ledger = DummyLedger(CompactMerkleTree(), dataDir=tdir_for_func) with pytest.raises(SystemExit) as excinfo: _, _, nodeKeys = TxnStackManager.parseLedgerForHaAndKeys(ledger) assert excinfo.value.code == errMsg ledger.stop()
def test_parse_identifier_non_base58_txn_type_field_raises_SystemExit_has_descriptive_error( invalid_identifier_tdir, tdir_for_func): """ Test that invalid base58 IDENTIFIER in pool_transaction raises the proper exception (INDY-150) """ with pytest.raises(SystemExit) as excinfo: ledger = Ledger(CompactMerkleTree(), dataDir=tdir_for_func) _, _, nodeKeys = TxnStackManager.parseLedgerForHaAndKeys(ledger) assert excinfo.value.code == errMsg2 ledger.stop()
def test_parse_verkey_non_base58_txn_type_field_raises_SystemExit_has_descriptive_error( invalid_verkey_tdir, tdir_for_func): """ Test that invalid base58 TARGET_NYM in pool_transaction raises the proper exception (INDY-150) """ with pytest.raises(SystemExit) as excinfo: ledger = Ledger(CompactMerkleTree(), dataDir=tdir_for_func) _, _, nodeKeys = TxnStackManager.parseLedgerForHaAndKeys(ledger) assert excinfo.value.code == 'Invalid verkey. Rebuild pool transactions.' ledger.stop()
def nodeServicesChanged(self, txn_data) -> bool: nodeNym = txn_data[TARGET_NYM] nodeName = self.getNodeName(nodeNym) oldServices = set(self._ordered_node_services.get(nodeNym, [])) newServices = set(txn_data[DATA].get(SERVICES, [])) if oldServices == newServices: logger.info( "Node {} not changing {} since it is same as existing".format( nodeNym, SERVICES)) return False node_count_changed = False if VALIDATOR in newServices.difference(oldServices): node_count_changed = True # If validator service is enabled node_info = self.write_manager.get_node_data(nodeNym) self.node.nodeReg[nodeName] = HA(node_info[NODE_IP], node_info[NODE_PORT]) self.node.cliNodeReg[nodeName + CLIENT_STACK_SUFFIX] = HA( node_info[CLIENT_IP], node_info[CLIENT_PORT]) self.updateNodeTxns({ DATA: node_info, }, txn_data) if self.name != nodeName: self.connectNewRemote({ DATA: node_info, TARGET_NYM: nodeNym }, nodeName, self.node) else: logger.debug("{} adding itself to node registry".format( self.name)) if VALIDATOR in oldServices.difference(newServices): node_count_changed = True # If validator service is disabled del self.node.nodeReg[nodeName] del self.node.cliNodeReg[nodeName + CLIENT_STACK_SUFFIX] if self.name != nodeName: try: rid = TxnStackManager.removeRemote(self.node.nodestack, nodeName) if rid: self.node.nodestack.outBoxes.pop(rid, None) except RemoteNotFound: logger.info('{} did not find remote {} to remove'.format( self, nodeName)) self.node_about_to_be_disconnected(nodeName) return node_count_changed
def __init__(self, node, ledger, state, reqHandler, ha=None, cliname=None, cliha=None): self.node = node self.name = node.name self.config = node.config self.genesis_dir = node.genesis_dir self.keys_dir = node.keys_dir self.ledger = ledger self._id = None TxnStackManager.__init__( self, self.name, node.keys_dir, isNode=True) self.state = state self.reqHandler = reqHandler self._load_nodes_order_from_ledger() self.nstack, self.cstack, self.nodeReg, self.cliNodeReg = \ self.getStackParamsAndNodeReg(self.name, self.keys_dir, ha=ha, cliname=cliname, cliha=cliha) self._dataFieldsValidators = ( (NODE_IP, self._isIpAddressValid), (CLIENT_IP, self._isIpAddressValid), (NODE_PORT, self._isPortValid), (CLIENT_PORT, self._isPortValid), )
def nodeServicesChanged(self, txn_data): nodeNym = txn_data[TARGET_NYM] nodeName = self.getNodeName(nodeNym) oldServices = set(self._ordered_node_services.get(nodeNym, [])) newServices = set(txn_data[DATA].get(SERVICES, [])) if oldServices == newServices: logger.info("Node {} not changing {} since it is same as existing".format(nodeNym, SERVICES)) return else: if VALIDATOR in newServices.difference(oldServices): # If validator service is enabled node_info = self.reqHandler.getNodeData(nodeNym) self.node.nodeReg[nodeName] = HA(node_info[NODE_IP], node_info[NODE_PORT]) self.node.cliNodeReg[nodeName + CLIENT_STACK_SUFFIX] = HA(node_info[CLIENT_IP], node_info[CLIENT_PORT]) self.updateNodeTxns({DATA: node_info, }, txn_data) self.node.nodeJoined(txn_data) if self.name != nodeName: self.connectNewRemote({DATA: node_info, TARGET_NYM: nodeNym}, nodeName, self.node) if VALIDATOR in oldServices.difference(newServices): # If validator service is disabled del self.node.nodeReg[nodeName] del self.node.cliNodeReg[nodeName + CLIENT_STACK_SUFFIX] self.node.nodeLeft(txn_data) if self.name != nodeName: try: rid = TxnStackManager.removeRemote( self.node.nodestack, nodeName) if rid: self.node.nodestack.outBoxes.pop(rid, None) except RemoteNotFound: logger.info('{} did not find remote {} to remove'.format(self, nodeName)) self.node_about_to_be_disconnected(nodeName)