def connectNewRemote(self, txn, remoteName, nodeOrClientObj, addRemote=True): verkey = cryptonymToHex(txn[TARGET_NYM]) nodeHa = (txn[DATA][NODE_IP], txn[DATA][NODE_PORT]) cliHa = (txn[DATA][CLIENT_IP], txn[DATA][CLIENT_PORT]) if addRemote: try: # Override any keys found, reason being the scenario where # before this node comes to know about the other node, the other # node tries to connect to it. initRemoteKeep(self.name, remoteName, self.basedirpath, verkey, override=True) except Exception as ex: logger.error( "Exception while initializing keep for remote {}".format( ex)) if self.isNode: nodeOrClientObj.nodeReg[remoteName] = HA(*nodeHa) nodeOrClientObj.cliNodeReg[remoteName + CLIENT_STACK_SUFFIX] = HA(*cliHa) logger.debug("{} adding new node {} with HA {}".format( self.name, remoteName, nodeHa)) else: nodeOrClientObj.nodeReg[remoteName] = HA(*cliHa) logger.debug("{} adding new node {} with HA {}".format( self.name, remoteName, cliHa))
def addNewNodeAndConnect(self, txn): """ Add a new node to remote keep and connect to it. """ verkey, pubkey = hexlify(base64_decode(txn[TARGET_NYM].encode())), \ txn[DATA][PUBKEY] nodeName = txn[DATA][ALIAS] nodeHa = (txn[DATA][NODE_IP], txn[DATA][NODE_PORT]) try: initRemoteKeep(self.name, nodeName, self.basedirpath, pubkey, verkey) except Exception as ex: logger.debug("Exception while initializing keep for remote {}". format(ex)) self.node.nodestack.nodeReg[nodeName] = HA(*nodeHa)
def addRemoteKeysFromLedger(self, keys): for remoteName, key in keys.items(): # If its a client then remoteName should be suffixed with # CLIENT_STACK_SUFFIX if not self.isNode: remoteName += CLIENT_STACK_SUFFIX try: # Override any keys found, reason being the scenario where # before this node comes to know about the other node, the other # node tries to connect to it. # Do it only for Nodes, not for Clients! if self.isNode: initRemoteKeep(self.name, remoteName, self.basedirpath, key, override=True) except Exception as ex: logger.error( "Exception while initializing keep for remote {}".format( ex))
def stackKeysChanged(self, txn, remoteName, nodeOrClientObj): logger.debug("{} clearing remote role data in keep of {}".format( nodeOrClientObj.nodestack.name, remoteName)) nodeOrClientObj.nodestack.keep.clearRemoteRoleData(remoteName) logger.debug("{} removing remote {}".format(nodeOrClientObj, remoteName)) # Removing remote so that the nodestack will attempt to connect rid = self.removeRemote(nodeOrClientObj.nodestack, remoteName) verkey = txn[VERKEY] try: # Override any keys found initRemoteKeep(self.name, remoteName, self.basedirpath, verkey, override=True) except Exception as ex: logger.error( "Exception while initializing keep for remote {}".format(ex)) return rid
def getStackParamsAndNodeReg(self, name, basedirpath, nodeRegistry=None, ha=None, cliname=None, cliha=None): nstack = None cstack = None nodeReg = OrderedDict() for _, txn in self.poolTxnStore.getAllTxn().items(): if txn[TXN_TYPE] == NEW_NODE: verkey, pubkey = hexlify( base64_decode(txn[TARGET_NYM].encode())), \ txn[DATA][PUBKEY] nodeName = txn[DATA][ALIAS] nodeHa = (txn[DATA][NODE_IP], txn[DATA][NODE_PORT]) nodeReg[nodeName] = HA(*nodeHa) if nodeName == name: nstack = dict(name=name, ha=HA('0.0.0.0', txn[DATA][NODE_PORT]), main=True, auto=AutoMode.never) cstack = dict(name=nodeName + CLIENT_STACK_SUFFIX, ha=HA('0.0.0.0', txn[DATA][CLIENT_PORT]), main=True, auto=AutoMode.always) if basedirpath: nstack['basedirpath'] = basedirpath cstack['basedirpath'] = basedirpath else: try: initRemoteKeep(name, nodeName, basedirpath, pubkey, verkey) except Exception as ex: print(ex) elif txn[TXN_TYPE] in (NEW_STEWARD, NEW_CLIENT) \ and self.config.clientBootStrategy == \ ClientBootStrategy.PoolTxn: self.addNewRole(txn) return nstack, cstack, nodeReg