Search in sources :

Example 6 with MessageID

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

the class ChirpTest method setAndGetIdTest.

@Test
public void setAndGetIdTest() {
    MessageID newId = generateMessageID();
    CHIRP.setId(newId);
    assertEquals(newId, CHIRP.getId());
    assertThrows(IllegalArgumentException.class, () -> CHIRP.setId(null));
    assertThrows(IllegalArgumentException.class, () -> CHIRP.setId(EMPTY_MESSAGE_ID));
}
Also used : MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Example 7 with MessageID

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

the class ChirpTest method setAndGetParentId.

@Test
public void setAndGetParentId() {
    MessageID parentId = generateMessageID();
    CHIRP.setParentId(parentId);
    assertEquals(parentId, CHIRP.getParentId());
}
Also used : MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Example 8 with MessageID

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

the class LaoDetailViewModel method sendConsensusElectAccept.

/**
 * Sends a ConsensusElectAccept message.
 *
 * <p>Publish a GeneralMessage containing ConsensusElectAccept data.
 *
 * @param electInstance the corresponding ElectInstance
 * @param accept true if accepted, false if rejected
 */
public void sendConsensusElectAccept(ElectInstance electInstance, boolean accept) {
    MessageID messageId = electInstance.getMessageId();
    Log.d(TAG, "sending a new elect_accept for consensus with messageId : " + messageId + " with value " + accept);
    Lao lao = getCurrentLaoValue();
    if (lao == null) {
        Log.d(TAG, LAO_FAILURE_MESSAGE);
        return;
    }
    ConsensusElectAccept consensusElectAccept = new ConsensusElectAccept(electInstance.getInstanceId(), messageId, accept);
    Log.d(TAG, PUBLISH_MESSAGE);
    Disposable disposable = networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), electInstance.getChannel(), consensusElectAccept).subscribe(() -> Log.d(TAG, "sent an elect_accept successfully"), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_consensus_accept));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) 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) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 9 with MessageID

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

the class Lao method updateElectInstance.

/**
 * Store the given ElectInstance and update all nodes concerned by it.
 *
 * @param electInstance the ElectInstance
 */
public void updateElectInstance(@NonNull ElectInstance electInstance) {
    MessageID messageId = electInstance.getMessageId();
    messageIdToElectInstance.put(messageId, electInstance);
    Map<PublicKey, MessageID> acceptorsToMessageId = electInstance.getAcceptorsToMessageId();
    // add to each node the messageId of the Elect if they accept it
    keyToNode.forEach((key, node) -> {
        if (acceptorsToMessageId.containsKey(key)) {
            node.addMessageIdOfAnAcceptedElect(messageId);
        }
    });
    // add the ElectInstance to the proposer node
    ConsensusNode proposer = keyToNode.get(electInstance.getProposer());
    if (proposer != null) {
        proposer.addElectInstance(electInstance);
    }
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 10 with MessageID

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

the class Lao method updateAllChirps.

/**
 * Update the list of chirps that have been sent in the lao. If the list of chirps contain one
 * with Id prevId, it will remove it from the list then add the new chirp into it.
 *
 * @param prevId the previous id of a chirp
 * @param chirp the chirp
 */
public void updateAllChirps(MessageID prevId, Chirp chirp) {
    if (chirp == null) {
        throw new IllegalArgumentException("The chirp is null");
    }
    allChirps.remove(prevId);
    allChirps.put(chirp.getId(), chirp);
    PublicKey user = chirp.getSender();
    chirpsByUser.computeIfAbsent(user, key -> new ArrayList<>()).add(prevId);
}
Also used : NonNull(androidx.annotation.NonNull) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Hash(com.github.dedis.popstellar.utility.security.Hash) List(java.util.List) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Map(java.util.Map) Optional(java.util.Optional) Comparator(java.util.Comparator) Collections(java.util.Collections) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) ArrayList(java.util.ArrayList)

Aggregations

MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)23 Channel (com.github.dedis.popstellar.model.objects.Channel)10 Lao (com.github.dedis.popstellar.model.objects.Lao)10 LAORepository (com.github.dedis.popstellar.repository.LAORepository)10 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 Test (org.junit.Test)7 Base64DataUtils.generateMessageID (com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID)6 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)4 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)3 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)3 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)3 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)3 AddChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp)3 DeleteChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp)3 Chirp (com.github.dedis.popstellar.model.objects.Chirp)3 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)2 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)2 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)2