use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class RollCallHandlerTest method testHandleOpenRollCall.
@Test
public void testHandleOpenRollCall() throws DataHandlingException {
// Create the open Roll Call message
OpenRollCall openRollCall = new OpenRollCall(CREATE_LAO.getId(), rollCall.getId(), rollCall.getStart(), EventState.CREATED);
MessageGeneral message = new MessageGeneral(SENDER_KEY, openRollCall, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the Roll Call is present with state OPENED and the correct ID
Optional<RollCall> rollCallOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getRollCall(openRollCall.getUpdateId());
assertTrue(rollCallOpt.isPresent());
assertEquals(EventState.OPENED, rollCallOpt.get().getState());
assertEquals(openRollCall.getUpdateId(), rollCallOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = openRollCallWitnessMessage(message.getMessageId(), rollCallOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class LaoDetailViewModel method signMessage.
public void signMessage(WitnessMessage witnessMessage) {
Log.d(TAG, "signing message with ID " + witnessMessage.getMessageId());
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel();
try {
KeyPair mainKey = keyManager.getMainKeyPair();
// generate the signature of the message
Signature signature = mainKey.sign(witnessMessage.getMessageId());
Log.d(TAG, PUBLISH_MESSAGE);
WitnessMessageSignature signatureMessage = new WitnessMessageSignature(witnessMessage.getMessageId(), signature);
disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, signatureMessage).subscribe(() -> Log.d(TAG, "Verifying the signature of message with id: " + witnessMessage.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_sign_message)));
} catch (GeneralSecurityException e) {
Log.d(TAG, PK_FAILURE_MESSAGE, e);
}
}
use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class LaoHandler method handleUpdateLao.
/**
* Process an UpdateLao message.
*
* @param context the HandlerContext of the message
* @param updateLao the message that was received
*/
public static void handleUpdateLao(HandlerContext context, UpdateLao updateLao) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Log.d(TAG, " Receive Update Lao Broadcast msg=" + updateLao);
Lao lao = laoRepository.getLaoByChannel(channel);
if (lao.getLastModified() > updateLao.getLastModified()) {
// the current state we have is more up to date
throw new DataHandlingException(updateLao, "The current Lao is more up to date than the update lao message");
}
WitnessMessage message;
if (!updateLao.getName().equals(lao.getName())) {
message = updateLaoNameWitnessMessage(messageId, updateLao, lao);
} else if (!updateLao.getWitnesses().equals(lao.getWitnesses())) {
message = updateLaoWitnessesWitnessMessage(messageId, updateLao, lao);
} else {
Log.d(TAG, "Cannot set the witness message title to update lao");
throw new DataHandlingException(updateLao, "Cannot set the witness message title to update lao");
}
lao.updateWitnessMessage(messageId, message);
if (!lao.getWitnesses().isEmpty()) {
// We send a pending update only if there are already some witness that need to sign this
// UpdateLao
lao.getPendingUpdates().add(new PendingUpdate(updateLao.getLastModified(), messageId));
}
laoRepository.updateNodes(channel);
}
use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class LaoHandler method updateLaoWitnessesWitnessMessage.
public static WitnessMessage updateLaoWitnessesWitnessMessage(MessageID messageId, UpdateLao updateLao, Lao lao) {
WitnessMessage message = new WitnessMessage(messageId);
List<PublicKey> tempList = new ArrayList<>(updateLao.getWitnesses());
message.setTitle("Update Lao Witnesses");
message.setDescription("Lao Name : " + lao.getName() + "\n" + "Message ID : " + messageId + "\n" + "New Witness ID : " + tempList.get(tempList.size() - 1));
return message;
}
use of com.github.dedis.popstellar.model.objects.WitnessMessage in project popstellar by dedis.
the class ElectionHandlerTest method testHandleElectionSetup.
@Test
public void testHandleElectionSetup() throws DataHandlingException {
// Create the setup Election message
ElectionSetup electionSetup = new ElectionSetup("election 2", election.getCreation(), election.getStartTimestamp(), election.getEndTimestamp(), Collections.singletonList(electionQuestion.getVotingMethod()), Collections.singletonList(electionQuestion.getWriteIn()), Collections.singletonList(electionQuestion.getBallotOptions()), Collections.singletonList(electionQuestion.getQuestion()), lao.getId());
MessageGeneral message = new MessageGeneral(SENDER_KEY, electionSetup, GSON);
// Call the message handler
messageHandler.handleMessage(laoRepository, messageSender, LAO_CHANNEL, message);
// Check the Election is present with state OPENED and the correct ID
Optional<Election> electionOpt = laoRepository.getLaoByChannel(LAO_CHANNEL).getElection(electionSetup.getId());
assertTrue(electionOpt.isPresent());
assertEquals(EventState.OPENED, electionOpt.get().getState());
assertEquals(electionSetup.getId(), electionOpt.get().getId());
// Check the WitnessMessage has been created
Optional<WitnessMessage> witnessMessage = laoRepository.getLaoByChannel(LAO_CHANNEL).getWitnessMessage(message.getMessageId());
assertTrue(witnessMessage.isPresent());
// Check the Witness message contains the expected title and description
WitnessMessage expectedMessage = electionSetupWitnessMessage(message.getMessageId(), electionOpt.get());
assertEquals(expectedMessage.getTitle(), witnessMessage.get().getTitle());
assertEquals(expectedMessage.getDescription(), witnessMessage.get().getDescription());
}
Aggregations