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