Class TOMLayer

  • All Implemented Interfaces:
    RequestReceiver, java.lang.Runnable

    public final class TOMLayer
    extends java.lang.Thread
    implements RequestReceiver
    This class implements the state machine replication protocol described in Joao Sousa's 'From Byzantine Consensus to BFT state machine replication: a latency-optimal transformation' (May 2012) The synchronization phase described in the paper is implemented in the Synchronizer class
    • Constructor Detail

      • TOMLayer

        public TOMLayer​(ExecutionManager manager,
                        ServiceReplica receiver,
                        Recoverable recoverer,
                        Acceptor a,
                        ServerCommunicationSystem cs,
                        ServerViewController controller,
                        RequestVerifier verifier)
        Creates a new instance of TOMulticastLayer
        Parameters:
        manager - Execution manager
        receiver - Object that receives requests from clients
        recoverer - Object of a class implementing Recoverable interface for the state management
        a - Acceptor role of the PaW algorithm
        cs - Communication system between replicas
        controller - Reconfiguration Manager
        verifier - Implementation of predicate used to verify client requests
    • Method Detail

      • computeHash

        public byte[] computeHash​(byte[] data)
        Computes an hash for a TOM message
        Parameters:
        data - Data from which to generate the hash
        Returns:
        Hash for the specified TOM message
      • sign

        public java.security.SignedObject sign​(java.io.Serializable obj)
      • loadPublicKey

        public void loadPublicKey​(int target)
      • verifySignature

        public boolean verifySignature​(java.security.SignedObject so,
                                       int sender)
        Verifies the signature of a signed object
        Parameters:
        so - Signed object to be verified
        sender - Replica id that supposedly signed this object
        Returns:
        True if the signature is valid, false otherwise
      • getCommunication

        public ServerCommunicationSystem getCommunication()
        Retrieve Communication system between replicas
        Returns:
        Communication system between replicas
      • imAmTheLeader

        public void imAmTheLeader()
      • setLastExec

        public void setLastExec​(int last)
        Sets which consensus was the last to be executed
        Parameters:
        last - ID of the consensus which was last to be executed
      • getLastExec

        public int getLastExec()
        Gets the ID of the consensus which was established as the last executed
        Returns:
        ID of the consensus which was established as the last executed
      • setInExec

        public void setInExec​(int inEx)
        Sets which consensus is being executed at the moment
        Parameters:
        inEx - ID of the consensus being executed at the moment
      • waitForPaxosToFinish

        public void waitForPaxosToFinish()
        This method blocks until the PaW algorithm is finished
      • getInExec

        public int getInExec()
        Gets the ID of the consensus currently beign executed
        Returns:
        ID of the consensus currently beign executed (if no consensus ir executing, -1 is returned)
      • requestReceived

        public void requestReceived​(TOMMessage msg,
                                    boolean fromClient)
        This method is invoked by the communication system to deliver a request. It assumes that the communication system delivers the message in FIFO order.
        Specified by:
        requestReceived in interface RequestReceiver
        Parameters:
        msg - The request being received
        fromClient - Whether the request was received from a client or was part of a forwarded message
      • createPropose

        public byte[] createPropose​(Decision dec)
        Creates a value to be proposed to the acceptors. Invoked if this replica is the leader
        Parameters:
        dec - Object that will eventually hold the decided value
        Returns:
        A value to be proposed to the acceptors
      • run

        public void run()
        This is the main code for this thread. It basically waits until this replica becomes the leader, and when so, proposes a value to the other acceptors
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • decided

        public void decided​(Decision dec)
        Called by the current consensus instance, to notify the TOM layer that a value was decided
        Parameters:
        dec - The decision of the consensus
      • checkProposedValue

        public TOMMessage[] checkProposedValue​(byte[] proposedValue,
                                               boolean addToClientManager)
        Verify if the value being proposed for a epoch is valid. It verifies the client signature of all batch requests. TODO: verify timestamps and nonces
        Parameters:
        proposedValue - the value being proposed
        addToClientManager - add the requests to the client manager
        Returns:
        Valid messages contained in the proposed value
      • forwardRequestToLeader

        public void forwardRequestToLeader​(TOMMessage request)
      • isRetrievingState

        public boolean isRetrievingState()
      • isChangingLeader

        public boolean isChangingLeader()
      • setNoExec

        public void setNoExec()
      • processOutOfContext

        public void processOutOfContext()
      • shutdown

        public void shutdown()