Search in sources :

Example 26 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method sendConsensusElect.

/**
 * Sends a ConsensusElect message.
 *
 * <p>Publish a GeneralMessage containing ConsensusElect data.
 *
 * @param creation the creation time of the consensus
 * @param objId the id of the object the consensus refers to (e.g. election_id)
 * @param type the type of object the consensus refers to (e.g. election)
 * @param property the property the value refers to (e.g. "state")
 * @param value the proposed new value for the property (e.g. "started")
 */
public void sendConsensusElect(long creation, String objId, String type, String property, Object value) {
    Log.d(TAG, String.format("creating a new consensus for type: %s, property: %s, value: %s", type, property, value));
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    Channel channel = lao.getChannel().subChannel("consensus");
    ConsensusElect consensusElect = new ConsensusElect(creation, objId, type, property, value);
    Log.d(TAG, PUBLISH_MESSAGE);
    MessageGeneral msg = new MessageGeneral(keyManager.getMainKeyPair(), consensusElect, gson);
    Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> Log.d(TAG, "created a consensus with message id : " + msg.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_start_election));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ConsensusElect(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Channel(com.github.dedis.popstellar.model.objects.Channel) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)

Example 27 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method openAddWitness.

private void openAddWitness() {
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    witnesses = new HashSet<>(lao.getWitnesses());
    mOpenAddWitness.setValue(new SingleEvent<>(HomeViewModel.HomeViewAction.SCAN));
}
Also used : StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)

Example 28 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LAORepository method getElectionByChannel.

/**
 * Retrieves the Election in a given channel
 *
 * @param channel the channel on which the election was created
 * @return the election corresponding to this channel
 */
public Election getElectionByChannel(Channel channel) {
    Log.d(TAG, "querying election for channel " + channel);
    if (!channel.isElectionChannel())
        throw new IllegalArgumentException("invalid channel for an election : " + channel);
    Lao lao = getLaoByChannel(channel);
    Optional<Election> electionOption = lao.getElection(channel.extractElectionId());
    if (!electionOption.isPresent()) {
        throw new IllegalArgumentException("the election should be present when receiving a result");
    }
    return electionOption.get();
}
Also used : Lao(com.github.dedis.popstellar.model.objects.Lao) Election(com.github.dedis.popstellar.model.objects.Election)

Example 29 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class ConsensusHandler method handleLearn.

public static void handleLearn(HandlerContext context, ConsensusLearn consensusLearn) throws DataHandlingException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(consensusLearn.getMessageId());
    if (!electInstanceOpt.isPresent()) {
        Log.w(TAG, "learn for invalid messageId : " + consensusLearn.getMessageId());
        throw new InvalidMessageIdException(consensusLearn, consensusLearn.getMessageId());
    }
    ElectInstance electInstance = electInstanceOpt.get();
    if (consensusLearn.getLearnValue().isDecision()) {
        electInstance.setState(ElectInstance.State.ACCEPTED);
    }
    lao.updateElectInstance(electInstance);
    laoRepository.updateNodes(lao.getChannel());
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidMessageIdException(com.github.dedis.popstellar.utility.error.InvalidMessageIdException) Lao(com.github.dedis.popstellar.model.objects.Lao)

Example 30 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class ConsensusHandler method handleElect.

/**
 * Process an Elect message.
 *
 * @param context the HandlerContext of the message
 * @param consensusElect the data of the message that was received
 */
public static void handleElect(HandlerContext context, ConsensusElect consensusElect) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    MessageID messageId = context.getMessageId();
    PublicKey senderPk = context.getSenderPk();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Set<PublicKey> nodes = new HashSet<>(lao.getWitnesses());
    nodes.add(lao.getOrganizer());
    ElectInstance electInstance = new ElectInstance(messageId, channel, senderPk, nodes, consensusElect);
    lao.updateElectInstance(electInstance);
    laoRepository.updateNodes(lao.getChannel());
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) HashSet(java.util.HashSet)

Aggregations

Lao (com.github.dedis.popstellar.model.objects.Lao)46 Channel (com.github.dedis.popstellar.model.objects.Channel)31 LAORepository (com.github.dedis.popstellar.repository.LAORepository)24 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)18 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)16 Disposable (io.reactivex.disposables.Disposable)14 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)12 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)11 Election (com.github.dedis.popstellar.model.objects.Election)10 RollCall (com.github.dedis.popstellar.model.objects.RollCall)10 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)9 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)9 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)8 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)8 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)7 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)6 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)6 LAOState (com.github.dedis.popstellar.repository.LAOState)6