示例#1
0
    def _got_expected(self, msg, sender):
        def drop(identifier, reqId, register):
            key = (identifier, reqId)
            if key in register:
                received = register[key][0]
                if sender in received:
                    received.remove(sender)
                if not received:
                    register.pop(key)

        if msg[OP_FIELD_NAME] == REQACK:
            drop(get_reply_identifier(msg), get_reply_reqId(msg),
                 self.expectingAcksFor)
        elif msg[OP_FIELD_NAME] == REPLY:
            drop(get_reply_identifier(msg[f.RESULT.nm]),
                 get_reply_reqId(msg[f.RESULT.nm]), self.expectingAcksFor)
            drop(get_reply_identifier(msg[f.RESULT.nm]),
                 get_reply_reqId(msg[f.RESULT.nm]), self.expectingRepliesFor)
        elif msg[OP_FIELD_NAME] in (REQNACK, REJECT):
            drop(get_reply_identifier(msg), get_reply_reqId(msg),
                 self.expectingAcksFor)
            drop(get_reply_identifier(msg), get_reply_reqId(msg),
                 self.expectingRepliesFor)
        else:
            raise RuntimeError("{} cannot retry {}".format(self, msg))

        if not self.expectingAcksFor and not self.expectingRepliesFor:
            self._stop_expecting()
示例#2
0
 def handleIncomingReply(self, observer_name, reqId, frm, result,
                         numReplies):
     """
     Called by an external entity, like a Client, to notify of incoming
     replies
     :return:
     """
     preparedReq = self._prepared.get(get_reply_identifier(result), reqId)
     if not preparedReq:
         raise RuntimeError('no matching prepared value for {},{}'.format(
             get_reply_identifier(result), reqId))
     typ = get_reply_txntype(result)
     if typ and typ in self.replyHandler:
         self.replyHandler[typ](result, preparedReq)
示例#3
0
 def handleIncomingReply(self, observer_name, reqId, frm, result,
                         numReplies):
     """
     Called by an external entity, like a Client, to notify of incoming
     replies
     :return:
     """
     preparedReq = self._prepared.get(get_reply_identifier(result), reqId)
     if not preparedReq:
         raise RuntimeError('no matching prepared value for {},{}'.
                            format(get_reply_identifier(result), reqId))
     typ = get_reply_txntype(result)
     if typ and typ in self.replyHandler:
         self.replyHandler[typ](result, preparedReq)
示例#4
0
    def getRepliesFromAllNodes(self, identifier: str, reqId: int):
        """
        Accepts a request ID and return a list of results from all the nodes
        for that request

        :param identifier: identifier of the entity making the request
        :param reqId: Request ID
        :return: list of request results from all nodes
        """
        return {
            frm: msg
            for msg, frm in self.inBox if msg[OP_FIELD_NAME] == REPLY
            and get_reply_reqId(msg[f.RESULT.nm]) == reqId
            and get_reply_identifier(msg[f.RESULT.nm]) == identifier
        }
示例#5
0
    def handleOneNodeMsg(self, wrappedMsg, excludeFromCli=None) -> None:
        """
        Handles single message from a node, and appends it to a queue
        :param wrappedMsg: Reply received by the client from the node
        """
        self.inBox.append(wrappedMsg)
        msg, frm = wrappedMsg
        # Do not print result of transaction type `POOL_LEDGER_TXNS` on the CLI
        ledgerTxnTypes = (POOL_LEDGER_TXNS, LEDGER_STATUS, CONSISTENCY_PROOF,
                          CATCHUP_REP)
        printOnCli = not excludeFromCli and msg.get(OP_FIELD_NAME) not \
            in ledgerTxnTypes
        logger.info("Client {} got msg from node {}: {}".format(
            self.name, frm, msg),
                    extra={"cli": printOnCli})
        if OP_FIELD_NAME in msg:
            if msg[OP_FIELD_NAME] in ledgerTxnTypes and self.ledger:
                cMsg = node_message_factory.get_instance(**msg)
                if msg[OP_FIELD_NAME] == POOL_LEDGER_TXNS:
                    self.poolTxnReceived(cMsg, frm)
                if msg[OP_FIELD_NAME] == LEDGER_STATUS:
                    self.ledgerManager.processLedgerStatus(cMsg, frm)
                if msg[OP_FIELD_NAME] == CONSISTENCY_PROOF:
                    self.ledgerManager.processConsistencyProof(cMsg, frm)
                if msg[OP_FIELD_NAME] == CATCHUP_REP:
                    self.ledgerManager.processCatchupRep(cMsg, frm)
            elif msg[OP_FIELD_NAME] == REQACK:
                self.reqRepStore.addAck(msg, frm)
                self._got_expected(msg, frm)
            elif msg[OP_FIELD_NAME] == REQNACK:
                self.reqRepStore.addNack(msg, frm)
                self._got_expected(msg, frm)
            elif msg[OP_FIELD_NAME] == REJECT:
                self.reqRepStore.addReject(msg, frm)
                self._got_expected(msg, frm)
            elif msg[OP_FIELD_NAME] == REPLY:
                result = msg[f.RESULT.nm]
                identifier = get_reply_identifier(result)
                reqId = get_reply_reqId(result)
                numReplies = self.reqRepStore.addReply(identifier, reqId, frm,
                                                       result)

                self._got_expected(msg, frm)
                self.postReplyRecvd(identifier, reqId, frm, result, numReplies)