use of com.github.dedis.popstellar.model.objects.PendingUpdate in project popstellar by dedis.
the class LaoHandler method handleUpdateLao.
/**
* Process an UpdateLao message.
*
* @param context the HandlerContext of the message
* @param updateLao the message that was received
*/
public static void handleUpdateLao(HandlerContext context, UpdateLao updateLao) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Log.d(TAG, " Receive Update Lao Broadcast msg=" + updateLao);
Lao lao = laoRepository.getLaoByChannel(channel);
if (lao.getLastModified() > updateLao.getLastModified()) {
// the current state we have is more up to date
throw new DataHandlingException(updateLao, "The current Lao is more up to date than the update lao message");
}
WitnessMessage message;
if (!updateLao.getName().equals(lao.getName())) {
message = updateLaoNameWitnessMessage(messageId, updateLao, lao);
} else if (!updateLao.getWitnesses().equals(lao.getWitnesses())) {
message = updateLaoWitnessesWitnessMessage(messageId, updateLao, lao);
} else {
Log.d(TAG, "Cannot set the witness message title to update lao");
throw new DataHandlingException(updateLao, "Cannot set the witness message title to update lao");
}
lao.updateWitnessMessage(messageId, message);
if (!lao.getWitnesses().isEmpty()) {
// We send a pending update only if there are already some witness that need to sign this
// UpdateLao
lao.getPendingUpdates().add(new PendingUpdate(updateLao.getLastModified(), messageId));
}
laoRepository.updateNodes(channel);
}
Aggregations