Search in sources :

Example 1 with PendingUpdate

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);
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) PendingUpdate(com.github.dedis.popstellar.model.objects.PendingUpdate) LAORepository(com.github.dedis.popstellar.repository.LAORepository) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) DataHandlingException(com.github.dedis.popstellar.utility.error.DataHandlingException) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Aggregations

CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)1 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)1 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 PendingUpdate (com.github.dedis.popstellar.model.objects.PendingUpdate)1 WitnessMessage (com.github.dedis.popstellar.model.objects.WitnessMessage)1 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1 DataHandlingException (com.github.dedis.popstellar.utility.error.DataHandlingException)1