/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bftsmart.tom.core;
import bftsmart.communication.ServerCommunicationSystem;
import bftsmart.consensus.Decision;
import bftsmart.consensus.Epoch;
import bftsmart.consensus.Consensus;
import bftsmart.consensus.TimestampValuePair;
import bftsmart.consensus.messages.ConsensusMessage;
import bftsmart.consensus.messages.MessageFactory;
import bftsmart.consensus.roles.Acceptor;
import bftsmart.reconfiguration.ServerViewController;
import bftsmart.statemanagement.StateManager;
import bftsmart.tom.core.messages.TOMMessage;
import bftsmart.tom.leaderchange.RequestsTimer;
import bftsmart.tom.leaderchange.CollectData;
import bftsmart.tom.leaderchange.LCManager;
import bftsmart.tom.leaderchange.LCMessage;
import bftsmart.tom.leaderchange.CertifiedDecision;
import bftsmart.tom.util.BatchBuilder;
import bftsmart.tom.util.BatchReader;
import bftsmart.tom.util.TOMUtil;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.MessageDigest;
import java.security.SignedObject;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* This class implements the synchronization phase described in
* Joao Sousa's 'From Byzantine Consensus to BFT state machine replication: a latency-optimal transformation' (May 2012)
*
* This class implements all optimizations described at the end of the paper
*
* @author joao
*/
public class Synchronizer {
private Logger logger = LoggerFactory.getLogger(this.getClass());
// out of context messages related to the leader change are stored here
private final HashSet<LCMessage> outOfContextLC;
// Manager of the leader change
private final LCManager lcManager;
//Total order layer
private final TOMLayer tom;
// Stuff from TOMLayer that this object needs
private final RequestsTimer requestsTimer;
private final ExecutionManager execManager;
private final ServerViewController controller;
private final BatchBuilder bb;
private final ServerCommunicationSystem communication;
private final StateManager stateManager;
private final Acceptor acceptor;
private final MessageDigest md;
// Attributes to temporarely store synchronization info
// if state transfer is required for synchronization
private int tempRegency = -1;
private CertifiedDecision tempLastHighestCID = null;
private HashSet<SignedObject> tempSignedCollects = null;
private byte[] tempPropose = null;
private int tempBatchSize = -1;
private boolean tempIAmLeader = false;
public Synchronizer(TOMLayer tom) {
this.tom = tom;
this.requestsTimer = this.tom.requestsTimer;
this.execManager = this.tom.execManager;
this.controller = this.tom.controller;
this.bb = this.tom.bb;
this.communication = this.tom.getCommunication();
this.stateManager = this.tom.stateManager;
this.acceptor = this.tom.acceptor;
this.md = this.tom.md;
this.outOfContextLC = new HashSet<>();
this.lcManager = new LCManager(this.tom,this.controller, this.md);
}
public LCManager getLCManager() {
return lcManager;
}
/**
* This method is called when there is a timeout and the request has already
* been forwarded to the leader
*
* @param requestList List of requests that the replica wanted to order but
* didn't manage to
*/
public void triggerTimeout(List<TOMMessage> requestList) {
ObjectOutputStream out = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int regency = lcManager.getNextReg();
requestsTimer.stopTimer();
requestsTimer.Enabled(false);
// still not in the leader change phase?
if (lcManager.getNextReg() == lcManager.getLastReg()) {
lcManager.setNextReg(lcManager.getLastReg() + 1); // define next timestamp
regency = lcManager.getNextReg(); // update variable
// store messages to be ordered
lcManager.setCurrentRequestTimedOut(requestList);
// store information about messages that I'm going to send
lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());
//execManager.stop(); // stop consensus execution
//Get requests that timed out and the requests received in STOP messages
//and add those STOPed requests to the client manager
addSTOPedRequestsToClientManager();
List<TOMMessage> messages = getRequestsToRelay();
try { // serialize content to send in STOP message
out = new ObjectOutputStream(bos);
if (messages != null && messages.size() > 0) {
//TODO: If this is null, then there was no timeout nor STOP messages.
//What to do?
byte[] serialized = bb.makeBatch(messages, 0, 0, controller.getStaticConf().getUseSignatures() == 1);
out.writeBoolean(true);
out.writeObject(serialized);
} else {
out.writeBoolean(false);
logger.warn("Strange... did not include any request in my STOP message for regency " + regency);
}
out.flush();
bos.flush();
byte[] payload = bos.toByteArray();
out.close();
bos.close();
// send STOP-message
logger.info("Sending STOP message to install regency " + regency + " with " + (messages != null ? messages.size() : 0) + " request(s) to relay");
LCMessage stop = new LCMessage(this.controller.getStaticConf().getProcessId(), TOMUtil.STOP, regency, payload);
requestsTimer.setSTOP(regency, stop); // make replica re-transmit the stop message until a new regency is installed
communication.send(this.controller.getCurrentViewOtherAcceptors(), stop);
} catch (IOException ex) {
logger.error("Could not serialize STOP message", ex);
} finally {
try {
out.close();
bos.close();
} catch (IOException ex) {
logger.error("Could not serialize STOP message", ex);
}
}
}
processOutOfContextSTOPs(regency); // the replica might have received STOPs
// that were out of context at the time they
// were received, but now can be processed
startSynchronization(regency); // evaluate STOP messages
}
// Processes STOP messages that were not process upon reception, because they were
// ahead of the replica's expected regency
private void processOutOfContextSTOPs(int regency) {
logger.debug("Checking if there are out of context STOPs for regency " + regency);
Set<LCMessage> stops = getOutOfContextLC(TOMUtil.STOP, regency);
if (stops.size() > 0) {
logger.info("Processing " + stops.size() + " out of context STOPs for regency " + regency);
} else {
lo
没有合适的资源?快使用搜索试试~ 我知道了~
BFT-Smart.rar_BFT-Smart 测试工程_bft-smart
共299个文件
class:157个
java:127个
jar:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 79 浏览量
2022-09-20
11:45:50
上传
评论
收藏 8.92MB RAR 举报
温馨提示
完整Eclipse BFT-SMart工程
资源推荐
资源详情
资源评论
收起资源包目录
BFT-Smart.rar_BFT-Smart 测试工程_bft-smart (299个子文件)
Synchronizer.class 26KB
LCManager.class 21KB
TOMLayer.class 18KB
NettyClientServerCommunicationSystemClientSide.class 18KB
ServiceReplica.class 17KB
ServersCommunicationLayer.class 15KB
DurableStateManager.class 14KB
NettyClientServerCommunicationSystemServerSide.class 14KB
StandardStateManager.class 13KB
Acceptor.class 12KB
ServerConnection.class 12KB
ServiceProxy.class 12KB
StateManager.class 12KB
ExecutionManager.class 11KB
ThroughputLatencyServer.class 11KB
DeliveryThread.class 11KB
ClientsManager.class 11KB
TOMConfiguration.class 11KB
DefaultRecoverable.class 11KB
DurableStateLog.class 11KB
DurabilityCoordinator.class 11KB
FileRecoverer.class 10KB
DefaultSingleRecoverable.class 10KB
ServerViewController.class 10KB
DiskStateLog.class 9KB
Configuration.class 9KB
MapClient.class 8KB
RequestsTimer.class 8KB
Epoch.class 8KB
AsynchServiceProxy.class 8KB
MapServer.class 7KB
TOMMessage.class 7KB
RSAKeyLoader.class 7KB
Consensus.class 7KB
TOMUtil.class 7KB
YCSBServer.class 6KB
SunECKeyLoader.class 6KB
ThroughputLatencyClient$Client.class 6KB
ECDSAKeyLoader.class 6KB
ViewManager.class 6KB
AsyncLatencyClient$Client.class 6KB
ServerCommunicationSystem.class 6KB
YCSBMessage.class 5KB
NettyTOMMessageDecoder.class 5KB
DefaultApplicationState.class 5KB
HostsConfig.class 5KB
YCSBClient.class 5KB
ClientData.class 4KB
MessageHandler.class 4KB
ThroughputLatencyClient.class 4KB
TOMSender.class 4KB
StateLog.class 4KB
MessageContext.class 4KB
CSTState.class 4KB
Test.class 4KB
ShutdownHookThread.class 4KB
BatchBuilder.class 4KB
AsyncLatencyClient.class 4KB
ECDSAKeyPairGenerator.class 3KB
ReplyThread.class 3KB
ReconfigureRequest.class 3KB
CounterServer.class 3KB
MapInteractiveClient.class 3KB
RSAKeyPairGenerator.class 3KB
NettyClientServerCommunicationSystemClientSide$SyncListener.class 3KB
View.class 3KB
ViewController.class 3KB
ServerConnection$ReceiverThread.class 3KB
Reconfiguration.class 3KB
ConsensusMessage.class 3KB
DefaultViewStorage.class 3KB
RequestList.class 3KB
SignatureTest.class 3KB
AsyncLatencyClient$Client$1.class 3KB
ServerConnection$TTPReceiverThread.class 3KB
TimestampValuePair.class 3KB
CollectData.class 3KB
Decision.class 3KB
View.class 3KB
BatchReader.class 2KB
CommandsInfo.class 2KB
NettyTOMMessageEncoder.class 2KB
SMMessage.class 2KB
StateSenderServer.class 2KB
ServiceProxy$HashResponseController.class 2KB
ServiceReplica$2.class 2KB
Storage.class 2KB
NettyClientPipelineFactory.class 2KB
NettyServerPipelineFactory.class 2KB
CertifiedDecision.class 2KB
TOMMessageType.class 2KB
CounterClient.class 2KB
ReconfigureReply.class 2KB
CSTRequestF1.class 2KB
NettyClientServerCommunicationSystemClientSide$1.class 2KB
DefaultReplier.class 2KB
NettyClientServerCommunicationSystemServerSide$1.class 2KB
ClientViewController.class 2KB
ServerConnection$SenderThread.class 2KB
TestViewSerialization.class 2KB
共 299 条
- 1
- 2
- 3
资源评论
邓凌佳
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功