Search in sources :

Example 11 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class ConsensusHandler method handleConsensusFailure.

public static void handleConsensusFailure(HandlerContext context, ConsensusFailure failure) throws InvalidMessageIdException {
    LAORepository laoRepository = context.getLaoRepository();
    Channel channel = context.getChannel();
    Lao lao = laoRepository.getLaoByChannel(channel);
    Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(failure.getMessageId());
    if (!electInstanceOpt.isPresent()) {
        Log.w(TAG, "Failure for invalid messageId : " + failure.getMessageId());
        throw new InvalidMessageIdException(failure, failure.getMessageId());
    }
    ElectInstance electInstance = electInstanceOpt.get();
    electInstance.setState(ElectInstance.State.FAILED);
    lao.updateElectInstance(electInstance);
    laoRepository.updateNodes(lao.getChannel());
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) Channel(com.github.dedis.popstellar.model.objects.Channel) LAORepository(com.github.dedis.popstellar.repository.LAORepository) InvalidMessageIdException(com.github.dedis.popstellar.utility.error.InvalidMessageIdException) Lao(com.github.dedis.popstellar.model.objects.Lao)

Example 12 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LAOListAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    HomeLaoLayoutBinding binding;
    if (view == null) {
        // inflate
        LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
        binding = HomeLaoLayoutBinding.inflate(inflater, viewGroup, false);
    } else {
        binding = DataBindingUtil.getBinding(view);
    }
    if (binding == null)
        throw new IllegalStateException("Binding could not be find in the view");
    LAOItemUserActionsListener userActionsListener = lao -> {
        if (openLaoDetail) {
            homeViewModel.openLAO(lao.getId());
        } else {
            homeViewModel.openLaoWallet(lao.getId());
        }
    };
    binding.setLao(laos.get(position));
    binding.setLifecycleOwner(lifecycleOwner);
    binding.setListener(userActionsListener);
    binding.executePendingBindings();
    return binding.getRoot();
}
Also used : List(java.util.List) BaseAdapter(android.widget.BaseAdapter) LifecycleOwner(androidx.lifecycle.LifecycleOwner) Lao(com.github.dedis.popstellar.model.objects.Lao) LayoutInflater(android.view.LayoutInflater) HomeLaoLayoutBinding(com.github.dedis.popstellar.databinding.HomeLaoLayoutBinding) View(android.view.View) ViewGroup(android.view.ViewGroup) DataBindingUtil(androidx.databinding.DataBindingUtil) LayoutInflater(android.view.LayoutInflater) HomeLaoLayoutBinding(com.github.dedis.popstellar.databinding.HomeLaoLayoutBinding)

Example 13 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class ElectionHandlerTest method setup.

@Before
public void setup() throws GeneralSecurityException, IOException {
    lenient().when(keyManager.getMainKeyPair()).thenReturn(SENDER_KEY);
    lenient().when(keyManager.getMainPublicKey()).thenReturn(SENDER);
    laoRepository = new LAORepository();
    when(messageSender.subscribe(any())).then(args -> Completable.complete());
    laoRepository = new LAORepository();
    messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
    // Create one LAO
    lao = new Lao(CREATE_LAO.getName(), CREATE_LAO.getOrganizer(), CREATE_LAO.getCreation());
    lao.setLastModified(lao.getCreation());
    // Create one Roll Call and add it to the LAO
    rollCall = new RollCall(lao.getId(), Instant.now().getEpochSecond(), "roll call 1");
    lao.setRollCalls(new HashMap<String, RollCall>() {

        {
            put(rollCall.getId(), rollCall);
        }
    });
    // Create one Election and add it to the LAO
    election = new Election(lao.getId(), Instant.now().getEpochSecond(), "election 1");
    election.setStart(Instant.now().getEpochSecond());
    election.setEnd(Instant.now().getEpochSecond() + 20L);
    election.setChannel(lao.getChannel().subChannel(election.getId()));
    electionQuestion = new ElectionQuestion("question", "Plurality", false, Arrays.asList("a", "b"), election.getId());
    election.setElectionQuestions(Collections.singletonList(electionQuestion));
    lao.setElections(new HashMap<String, Election>() {

        {
            put(election.getId(), election);
        }
    });
    // Add the LAO to the LAORepository
    laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
    laoRepository.setAllLaoSubject();
    // Add the CreateLao message to the LAORepository
    MessageGeneral createLaoMessage = new MessageGeneral(SENDER_KEY, CREATE_LAO, GSON);
    laoRepository.getMessageById().put(createLaoMessage.getMessageId(), createLaoMessage);
}
Also used : LAOState(com.github.dedis.popstellar.repository.LAOState) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) LAORepository(com.github.dedis.popstellar.repository.LAORepository) ElectionQuestion(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionQuestion) RollCall(com.github.dedis.popstellar.model.objects.RollCall) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) Election(com.github.dedis.popstellar.model.objects.Election) Before(org.junit.Before)

Example 14 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class KeyManagerTest method popTokenRetrievingFailsWhenLaoHasNoRollCall.

@Test
public void popTokenRetrievingFailsWhenLaoHasNoRollCall() {
    // create LAO
    Lao lao = new Lao("lao", Base64DataUtils.generatePublicKey(), 54213424);
    KeyManager manager = new KeyManager(androidKeysetManager, wallet);
    assertThrows(NoRollCallException.class, () -> manager.getValidPoPToken(lao));
}
Also used : Lao(com.github.dedis.popstellar.model.objects.Lao) Test(org.junit.Test) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest)

Example 15 with Lao

use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.

the class LaoDetailViewModel method updateLaoName.

/**
 * Method to update the name of a Lao by sending an updateLao msg and a stateLao msg to the
 * backend
 */
public void updateLaoName() {
    Log.d(TAG, "Updating lao name to " + mLaoName.getValue());
    Lao lao = getCurrentLaoValue();
    Channel channel = lao.getChannel();
    KeyPair mainKey = keyManager.getMainKeyPair();
    long now = Instant.now().getEpochSecond();
    UpdateLao updateLao = new UpdateLao(mainKey.getPublicKey(), lao.getCreation(), mLaoName.getValue(), now, lao.getWitnesses());
    MessageGeneral msg = new MessageGeneral(mainKey, updateLao, gson);
    Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> {
        Log.d(TAG, "updated lao name");
        dispatchLaoUpdate("lao name", updateLao, lao, channel, msg);
    }, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_update_lao));
    disposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Channel(com.github.dedis.popstellar.model.objects.Channel) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)

Aggregations

Lao (com.github.dedis.popstellar.model.objects.Lao)46 Channel (com.github.dedis.popstellar.model.objects.Channel)31 LAORepository (com.github.dedis.popstellar.repository.LAORepository)24 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)18 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)16 Disposable (io.reactivex.disposables.Disposable)14 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)12 MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)11 Election (com.github.dedis.popstellar.model.objects.Election)10 RollCall (com.github.dedis.popstellar.model.objects.RollCall)10 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)9 PoPToken (com.github.dedis.popstellar.model.objects.security.PoPToken)9 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)8 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)8 KeyException (com.github.dedis.popstellar.utility.error.keys.KeyException)8 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)7 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)6 ElectInstance (com.github.dedis.popstellar.model.objects.ElectInstance)6 LAOState (com.github.dedis.popstellar.repository.LAOState)6