use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class RollCallHandler method handleOpenRollCall.
/**
* Process an OpenRollCall message.
*
* @param context the HandlerContext of the message
* @param openRollCall the message that was received
*/
public static void handleOpenRollCall(HandlerContext context, OpenRollCall openRollCall) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Lao lao = laoRepository.getLaoByChannel(channel);
Log.d(TAG, "handleOpenRollCall: " + channel + " msg=" + openRollCall);
String updateId = openRollCall.getUpdateId();
String opens = openRollCall.getOpens();
Optional<RollCall> rollCallOptional = lao.getRollCall(opens);
if (!rollCallOptional.isPresent()) {
Log.w(TAG, "Cannot find roll call to open : " + opens);
throw new InvalidDataException(openRollCall, "open id", opens);
}
RollCall rollCall = rollCallOptional.get();
rollCall.setStart(openRollCall.getOpenedAt());
rollCall.setState(EventState.OPENED);
// We might be opening a closed one
rollCall.setEnd(0);
rollCall.setId(updateId);
lao.updateRollCall(opens, rollCall);
lao.updateWitnessMessage(messageId, openRollCallWitnessMessage(messageId, rollCall));
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class ElectInstanceTest method acceptorsResponsesTest.
@Test
public void acceptorsResponsesTest() {
MessageID messageId1 = generateMessageID();
MessageID messageId2 = generateMessageID();
String instanceId = electInstance.getInstanceId();
ConsensusElectAccept electAccept = new ConsensusElectAccept(instanceId, electMessageId, true);
ConsensusElectAccept electReject = new ConsensusElectAccept(instanceId, electMessageId, false);
electInstance.addElectAccept(node2, messageId1, electAccept);
electInstance.addElectAccept(node2, messageId2, electReject);
Map<PublicKey, MessageID> messageIds = electInstance.getAcceptorsToMessageId();
assertEquals(1, messageIds.size());
assertEquals(messageId1, messageIds.get(node2));
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class LaoTest method setAndGetModificationIdTest.
@Test
public void setAndGetModificationIdTest() {
MessageID id = generateMessageID();
LAO_1.setModificationId(id);
assertThat(LAO_1.getModificationId(), is(id));
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class SocialMediaHomeFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setupSendButton();
setupListViewAdapter();
setupListUpdate();
setupSwipeRefresh();
// Subscribe to "open send" event
mSocialMediaViewModel.getOpenSendEvent().observe(getViewLifecycleOwner(), booleanEvent -> {
Boolean event = booleanEvent.getContentIfNotHandled();
if (event != null) {
setupSocialMediaSendFragment();
}
});
// Subscribe to "delete chirp" event
mSocialMediaViewModel.getDeleteChirpEvent().observe(getViewLifecycleOwner(), messageIDEvent -> {
MessageID chirpId = messageIDEvent.getContentIfNotHandled();
if (chirpId != null) {
deleteChirp(chirpId);
}
});
}
use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class ChirpHandler method handleChirpAdd.
/**
* Process an AddChirp message.
*
* @param context the HandlerContext of the message
* @param addChirp the data of the message that was received
*/
public static void handleChirpAdd(HandlerContext context, AddChirp addChirp) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
PublicKey senderPk = context.getSenderPk();
Lao lao = laoRepository.getLaoByChannel(channel);
Chirp chirp = new Chirp(messageId);
chirp.setChannel(channel);
chirp.setSender(senderPk);
chirp.setText(addChirp.getText());
chirp.setTimestamp(addChirp.getTimestamp());
chirp.setParentId(addChirp.getParentId().orElse(new MessageID("")));
lao.updateAllChirps(messageId, chirp);
}
Aggregations