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);
}
}
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));
}
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);
}
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());
}
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);
}
Aggregations