def handle_client_command(self, givencommand, sendcount=1, prepare=False):
        """handle received command
        - if it has been received before check if it has been executed
        -- if it has been executed send the result
        -- if it has not been executed yet send INPROGRESS
        - if this request has not been received before initiate a Paxos round for the command"""
        if not self.isleader:
            if self.debug: self.logger.write("Error", "Should not have come here: Called to handle client command but not Leader.")
            clientreply = create_message(MSG_CLIENTREPLY, self.me,
                                         {FLD_REPLY: '',
                                          FLD_REPLYCODE: CR_REJECTED,
                                          FLD_INRESPONSETO: givencommand.clientcommandnumber})
            if self.debug: self.logger.write("State", "Rejecting clientrequest: %s" % str(clientreply))
            conn = self.connectionpool.get_connection_by_peer(givencommand.client)
            if conn is not None:
                conn.send(clientreply)
            else:
                if self.debug: self.logger.write("Error", "Cannot create connection to client")
            return

        if sendcount > 0 and (givencommand.client,
                              givencommand.clientcommandnumber) in self.receivedclientrequests:
            if self.debug: self.logger.write("State", "Client request received previously:")
            if self.debug: self.logger.write("State", "Client: %s Commandnumber: %s Replicas: %s"
                                             % (str(givencommand.client),
                                                str(givencommand.clientcommandnumber),
                                                str(self.replicas)))
            # Check if the request has been executed
            if givencommand in self.executed:
                # send REPLY
                clientreply = create_message(MSG_CLIENTREPLY, self.me,
                                             {FLD_REPLY: self.executed[givencommand][EXC_RESULT],
                                              FLD_REPLYCODE: self.executed[givencommand][EXC_RCODE],
                                              FLD_INRESPONSETO: givencommand.clientcommandnumber})
                if self.debug: self.logger.write("State", "Sending Clientreply: %s" % str(clientreply))
            # Check if the request is somewhere in the Paxos pipeline
            elif givencommand in self.pendingcommandset or \
                    givencommand in self.proposalset or \
                    givencommand in self.decisionset:
                # send INPROGRESS
                clientreply = create_message(MSG_CLIENTREPLY, self.me,
                                             {FLD_REPLY: '',
                                              FLD_REPLYCODE: CR_INPROGRESS,
                                              FLD_INRESPONSETO: givencommand.clientcommandnumber})
                if self.debug: self.logger.write("State", "Sending INPROGRESS: %s\nReplicas: %s"
                                  % (str(clientreply),str(self.replicas)))
            conn = self.connectionpool.get_connection_by_peer(givencommand.client)
            if conn is not None:
                conn.send(clientreply)
            else:
                if self.debug: self.logger.write("Error", "Cannot create connection to client")
        else:
            # The caller haven't received this command before
            self.receivedclientrequests[(givencommand.client,
                                         givencommand.clientcommandnumber)] = givencommand
            if self.debug: self.logger.write("State",
                                             "Initiating command. Leader is active: %s" % self.active)
            self.pick_commandnumber_add_to_pending(givencommand)
            self.issue_pending_commands()
dataset/ETHPy150Open denizalti/concoord/concoord/replica.py/Replica.handle_client_command/original