Search in sources :

Example 11 with PublicKey

use of com.github.dedis.popstellar.model.objects.security.PublicKey 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 12 with PublicKey

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

the class Lao method setWitnesses.

public void setWitnesses(Set<PublicKey> witnesses) {
    if (witnesses == null) {
        throw new IllegalArgumentException("The witnesses set is null");
    }
    for (PublicKey witness : witnesses) {
        if (witness == null) {
            throw new IllegalArgumentException("One of the witnesses in the set is null");
        }
    }
    this.witnesses = witnesses;
    witnesses.forEach(w -> keyToNode.computeIfAbsent(w, ConsensusNode::new));
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey)

Example 13 with PublicKey

use of com.github.dedis.popstellar.model.objects.security.PublicKey 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)

Example 14 with PublicKey

use of com.github.dedis.popstellar.model.objects.security.PublicKey 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)

Example 15 with PublicKey

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

the class LaoHandler method handleCreateLao.

/**
 * Process a CreateLao message.
 *
 * @param context the HandlerContext of the message
 * @param createLao the message that was received
 */
public static void handleCreateLao(HandlerContext context, CreateLao createLao) {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Log.d(TAG, "handleCreateLao: channel " + channel + ", msg=" + createLao);
    Lao lao = laoRepository.getLaoByChannel(channel);
    lao.setName(createLao.getName());
    lao.setCreation(createLao.getCreation());
    lao.setLastModified(createLao.getCreation());
    lao.setOrganizer(createLao.getOrganizer());
    lao.setId(createLao.getId());
    lao.setWitnesses(new HashSet<>(createLao.getWitnesses()));
    PublicKey publicKey = context.getKeyManager().getMainPublicKey();
    if (lao.getOrganizer().equals(publicKey) || lao.getWitnesses().contains(publicKey)) {
        context.getMessageSender().subscribe(lao.getChannel().subChannel("consensus")).subscribe();
    }
    laoRepository.updateNodes(channel);
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Channel(com.github.dedis.popstellar.model.objects.Channel) 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)

Aggregations

PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)21 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)8 Channel (com.github.dedis.popstellar.model.objects.Channel)6 Lao (com.github.dedis.popstellar.model.objects.Lao)6 LAORepository (com.github.dedis.popstellar.repository.LAORepository)6 Test (org.junit.Test)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)3 Base64DataUtils.generatePublicKey (com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey)3 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)2 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)2 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 Chirp (com.github.dedis.popstellar.model.objects.Chirp)2 KeyPair (com.github.dedis.popstellar.model.objects.security.KeyPair)2 InvalidMessageIdException (com.github.dedis.popstellar.utility.error.InvalidMessageIdException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 DateUtils.getRelativeTimeSpanString (android.text.format.DateUtils.getRelativeTimeSpanString)1 ImageButton (android.widget.ImageButton)1