Search in sources :

Example 16 with MessageID

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));
}
Also used : Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidDataException(com.github.dedis.popstellar.utility.error.InvalidDataException) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) Lao(com.github.dedis.popstellar.model.objects.Lao) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 17 with MessageID

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));
}
Also used : ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) Base64DataUtils.generatePublicKey(com.github.dedis.popstellar.testutils.Base64DataUtils.generatePublicKey) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Example 18 with MessageID

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));
}
Also used : MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) Test(org.junit.Test)

Example 19 with MessageID

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);
        }
    });
}
Also used : MessageID(com.github.dedis.popstellar.model.objects.security.MessageID)

Example 20 with MessageID

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);
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) 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)

Aggregations

MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)23 Channel (com.github.dedis.popstellar.model.objects.Channel)10 Lao (com.github.dedis.popstellar.model.objects.Lao)10 LAORepository (com.github.dedis.popstellar.repository.LAORepository)10 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 Test (org.junit.Test)7 Base64DataUtils.generateMessageID (com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID)6 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)4 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)4 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)3 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)3 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)3 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)3 AddChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp)3 DeleteChirp (com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp)3 Chirp (com.github.dedis.popstellar.model.objects.Chirp)3 RollCall (com.github.dedis.popstellar.model.objects.RollCall)3 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 ConsensusNode (com.github.dedis.popstellar.model.objects.ConsensusNode)2