Package bftsmart.tom.core
Class TOMLayer
- java.lang.Object
-
- java.lang.Thread
-
- bftsmart.tom.core.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
-
-
Field Summary
Fields Modifier and Type Field Description AcceptoracceptorBatchBuilderbbClientsManagerclientsManagerStore requests received but still not orderedServerViewControllercontrollerExecutionManagerexecManagerjava.security.MessageDigestmdRequestsTimerrequestsTimerManage timers for pending requestsStateManagerstateManager
-
Constructor Summary
Constructors Constructor Description TOMLayer(ExecutionManager manager, ServiceReplica receiver, Recoverable recoverer, Acceptor a, ServerCommunicationSystem cs, ServerViewController controller, RequestVerifier verifier)Creates a new instance of TOMulticastLayer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TOMMessage[]checkProposedValue(byte[] proposedValue, boolean addToClientManager)Verify if the value being proposed for a epoch is valid.byte[]computeHash(byte[] data)Computes an hash for a TOM messagebyte[]createPropose(Decision dec)Creates a value to be proposed to the acceptors.voiddecided(Decision dec)Called by the current consensus instance, to notify the TOM layer that a value was decidedvoidforwardRequestToLeader(TOMMessage request)ServerCommunicationSystemgetCommunication()Retrieve Communication system between replicasDeliveryThreadgetDeliveryThread()intgetInExec()Gets the ID of the consensus currently beign executedintgetLastExec()Gets the ID of the consensus which was established as the last executedStateManagergetStateManager()SynchronizergetSynchronizer()voidimAmTheLeader()booleanisChangingLeader()booleanisRetrievingState()voidloadPublicKey(int target)voidprocessOutOfContext()voidrequestReceived(TOMMessage msg, boolean fromClient)This method is invoked by the communication system to deliver a request.voidrun()This is the main code for this thread.voidsetInExec(int inEx)Sets which consensus is being executed at the momentvoidsetLastExec(int last)Sets which consensus was the last to be executedvoidsetNoExec()voidshutdown()java.security.SignedObjectsign(java.io.Serializable obj)booleanverifySignature(java.security.SignedObject so, int sender)Verifies the signature of a signed objectvoidwaitForPaxosToFinish()This method blocks until the PaW algorithm is finished-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
execManager
public ExecutionManager execManager
-
acceptor
public Acceptor acceptor
-
stateManager
public StateManager stateManager
-
requestsTimer
public RequestsTimer requestsTimer
Manage timers for pending requests
-
clientsManager
public ClientsManager clientsManager
Store requests received but still not ordered
-
md
public java.security.MessageDigest md
-
bb
public BatchBuilder bb
-
controller
public ServerViewController controller
-
-
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 managerreceiver- Object that receives requests from clientsrecoverer- Object of a class implementing Recoverable interface for the state managementa- Acceptor role of the PaW algorithmcs- Communication system between replicascontroller- Reconfiguration Managerverifier- 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 verifiedsender- 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:
requestReceivedin interfaceRequestReceiver- Parameters:
msg- The request being receivedfromClient- 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:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.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 proposedaddToClientManager- 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()
-
getStateManager
public StateManager getStateManager()
-
getSynchronizer
public Synchronizer getSynchronizer()
-
getDeliveryThread
public DeliveryThread getDeliveryThread()
-
shutdown
public void shutdown()
-
-