提交 067ee920 编写于 作者: J João Sousa

Changed the way to detected leader replay attacks. This is now done using the...

Changed the way to detected leader replay attacks. This is now done using the last request submitted to the delivery thread from each client.
上级 ce4445fa
无法预览此类型文件
......@@ -41,9 +41,7 @@ public class ClientData {
private int lastMessageReceived = -1;
private long lastMessageReceivedTime = 0;
private int lastMessageProposed = -1;
private int lastMessageExecuted = -1;
private int lastMessageDelivered = -1;
private RequestList pendingRequests = new RequestList();
//anb: new code to deal with client requests that arrive after their execution
......@@ -91,12 +89,12 @@ public class ClientData {
return orderedRequests;
}
public void setLastMessageExecuted(int lastMessageExecuted) {
this.lastMessageExecuted = lastMessageExecuted;
public void setLastMessageDelivered(int lastMessageDelivered) {
this.lastMessageDelivered = lastMessageDelivered;
}
public int getLastMessageExecuted() {
return lastMessageExecuted;
public int getLastMessageDelivered() {
return lastMessageDelivered;
}
public void setLastMessageReceived(int lastMessageReceived) {
......@@ -106,14 +104,6 @@ public class ClientData {
public int getLastMessageReceived() {
return lastMessageReceived;
}
public void setLastMessageProposed(int lastMessageProposed) {
this.lastMessageProposed = lastMessageProposed;
}
public int getLastMessageProposed() {
return lastMessageProposed;
}
public void setLastMessageReceivedTime(long lastMessageReceivedTime) {
this.lastMessageReceivedTime = lastMessageReceivedTime;
......@@ -144,7 +134,7 @@ public class ClientData {
}
public boolean removeRequest(TOMMessage request) {
lastMessageExecuted = request.getSequence();
lastMessageDelivered = request.getSequence();
boolean result = pendingRequests.remove(request);
//anb: new code to deal with client requests that arrive after their execution
orderedRequests.addLast(request);
......
......@@ -230,13 +230,14 @@ public class ClientsManager {
clientData.clientLock.lock();
//Is this a leader replay attack?
if (!fromClient && clientData.getLastMessageProposed() >= request.getSequence()) {
if (!fromClient && clientData.getSession() == request.getSession() &&
clientData.getLastMessageDelivered() >= request.getSequence()) {
clientData.clientLock.unlock();
logger.warn("Detected a leader replay attack, rejecting request");
return false;
}
request.receptionTime = receptionTime;
request.receptionTimestamp = receptionTimestamp;
......@@ -263,8 +264,7 @@ public class ClientsManager {
if (clientData.getSession() != request.getSession()) {
clientData.setSession(request.getSession());
clientData.setLastMessageReceived(-1);
clientData.setLastMessageExecuted(-1);
clientData.setLastMessageProposed(-1);
clientData.setLastMessageDelivered(-1);
clientData.getOrderedRequests().clear();
clientData.getPendingRequests().clear();
}
......@@ -329,12 +329,6 @@ public class ClientsManager {
/******* END CLIENTDATA CRITICAL SECTION ******/
if (!fromClient && accounted) {
logger.debug("Setting last proposed message for client {} to sequence #{}",request.getSender(), request.getSequence());
clientData.setLastMessageProposed(request.getSequence());
}
clientData.clientLock.unlock();
return accounted;
......@@ -374,7 +368,7 @@ public class ClientsManager {
if (!clientData.removeOrderedRequest(request)) {
logger.debug("Request " + request + " does not exist in pending requests");
}
clientData.setLastMessageExecuted(request.getSequence());
clientData.setLastMessageDelivered(request.getSequence());
/******* END CLIENTDATA CRITICAL SECTION ******/
clientData.clientLock.unlock();
......
......@@ -80,14 +80,7 @@ public final class DeliveryThread extends Thread {
* @param dec Decision established from the consensus
*/
public void delivery(Decision dec) {
if (!containsGoodReconfig(dec)) {
logger.debug("Decision from consensus " + dec.getConsensusId() + " does not contain good reconfiguration");
//set this decision as the last one from this replica
tomLayer.setLastExec(dec.getConsensusId());
//define that end of this execution
tomLayer.setInExec(-1);
} //else if (tomLayer.controller.getStaticConf().getProcessId() == 0) System.exit(0);
try {
decidedLock.lock();
decided.put(dec);
......@@ -102,6 +95,15 @@ public final class DeliveryThread extends Thread {
} catch (Exception e) {
logger.error("Could not insert decision into decided queue",e);
}
if (!containsGoodReconfig(dec)) {
logger.debug("Decision from consensus " + dec.getConsensusId() + " does not contain good reconfiguration");
//set this decision as the last one from this replica
tomLayer.setLastExec(dec.getConsensusId());
//define that end of this execution
tomLayer.setInExec(-1);
} //else if (tomLayer.controller.getStaticConf().getProcessId() == 0) System.exit(0);
}
private boolean containsGoodReconfig(Decision dec) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册