Search in sources :

Example 21 with MessageGeneral

use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.

the class LaoDetailViewModel method dispatchLaoUpdate.

/**
 * Helper method for updateLaoWitnesses and updateLaoName to send a stateLao message
 */
private void dispatchLaoUpdate(String desc, UpdateLao updateLao, Lao lao, Channel channel, MessageGeneral msg) {
    StateLao stateLao = new StateLao(updateLao.getId(), updateLao.getName(), lao.getCreation(), updateLao.getLastModified(), lao.getOrganizer(), msg.getMessageId(), updateLao.getWitnesses(), new ArrayList<>());
    disposables.add(networkManager.getMessageSender().publish(keyManager.getMainKeyPair(), channel, stateLao).subscribe(() -> Log.d(TAG, "updated " + desc), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_state_lao)));
}
Also used : PackageManager(android.content.pm.PackageManager) HomeViewModel(com.github.dedis.popstellar.ui.home.HomeViewModel) NonNull(androidx.annotation.NonNull) ElectionEnd(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionEnd) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao) LiveDataReactiveStreams(androidx.lifecycle.LiveDataReactiveStreams) ConsensusNode(com.github.dedis.popstellar.model.objects.ConsensusNode) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) Manifest(android.Manifest) GeneralSecurityException(java.security.GeneralSecurityException) Lao(com.github.dedis.popstellar.model.objects.Lao) WitnessMessage(com.github.dedis.popstellar.model.objects.WitnessMessage) Gson(com.google.gson.Gson) Schedulers(io.reactivex.schedulers.Schedulers) Transformations(androidx.lifecycle.Transformations) ContextCompat(androidx.core.content.ContextCompat) Log(android.util.Log) CloseRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall) ConsensusElect(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElect) KeyManager(com.github.dedis.popstellar.utility.security.KeyManager) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Set(java.util.Set) ElectionVote(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionVote) KeyGenerationException(com.github.dedis.popstellar.utility.error.keys.KeyGenerationException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ElectionSetup(com.github.dedis.popstellar.model.network.method.message.data.election.ElectionSetup) HiltViewModel(dagger.hilt.android.lifecycle.HiltViewModel) Objects(java.util.Objects) ScanningAction(com.github.dedis.popstellar.ui.qrcode.ScanningAction) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Stream(java.util.stream.Stream) KeyException(com.github.dedis.popstellar.utility.error.keys.KeyException) Application(android.app.Application) RollCall(com.github.dedis.popstellar.model.objects.RollCall) Optional(java.util.Optional) SingleEvent(com.github.dedis.popstellar.SingleEvent) Wallet(com.github.dedis.popstellar.model.objects.Wallet) CameraPermissionViewModel(com.github.dedis.popstellar.ui.qrcode.CameraPermissionViewModel) MutableLiveData(androidx.lifecycle.MutableLiveData) R(com.github.dedis.popstellar.R) CreateRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall) EventType(com.github.dedis.popstellar.model.objects.event.EventType) EventState(com.github.dedis.popstellar.model.objects.event.EventState) ErrorUtils(com.github.dedis.popstellar.utility.error.ErrorUtils) Signature(com.github.dedis.popstellar.model.objects.security.Signature) ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) LAORepository(com.github.dedis.popstellar.repository.LAORepository) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PoPToken(com.github.dedis.popstellar.model.objects.security.PoPToken) UninitializedWalletException(com.github.dedis.popstellar.utility.error.keys.UninitializedWalletException) KeyPair(com.github.dedis.popstellar.model.objects.security.KeyPair) Toast(android.widget.Toast) AndroidViewModel(androidx.lifecycle.AndroidViewModel) UpdateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao) WitnessMessageSignature(com.github.dedis.popstellar.model.network.method.message.data.message.WitnessMessageSignature) LiveData(androidx.lifecycle.LiveData) Channel(com.github.dedis.popstellar.model.objects.Channel) BackpressureStrategy(io.reactivex.BackpressureStrategy) Election(com.github.dedis.popstellar.model.objects.Election) CastVote(com.github.dedis.popstellar.model.network.method.message.data.election.CastVote) OpenRollCall(com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall) ConsensusElectAccept(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept) Barcode(com.google.android.gms.vision.barcode.Barcode) QRCodeScanningViewModel(com.github.dedis.popstellar.ui.qrcode.QRCodeScanningViewModel) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) VisibleForTesting(androidx.annotation.VisibleForTesting) GlobalNetworkManager(com.github.dedis.popstellar.repository.remote.GlobalNetworkManager) StateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)

Example 22 with MessageGeneral

use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.

the class ChirpHandlerTest method testHandleAddChirp.

@Test
public void testHandleAddChirp() throws DataHandlingException {
    MessageGeneral message = new MessageGeneral(SENDER_KEY, ADD_CHIRP, GSON);
    messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message);
    Optional<Chirp> chirpOpt = LAO.getChirp(message.getMessageId());
    assertTrue(chirpOpt.isPresent());
    Chirp chirp = chirpOpt.get();
    assertEquals(message.getMessageId(), chirp.getId());
    assertEquals(CHIRP_CHANNEL, chirp.getChannel());
    assertEquals(SENDER, chirp.getSender());
    assertEquals(TEXT, chirp.getText());
    assertEquals(CREATION_TIME, chirp.getTimestamp());
    assertEquals(PARENT_ID, chirp.getParentId());
    Map<MessageID, Chirp> chirps = LAO.getAllChirps();
    assertEquals(1, chirps.size());
    assertEquals(chirp, chirps.get(chirp.getId()));
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Test(org.junit.Test)

Example 23 with MessageGeneral

use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.

the class ChirpHandlerTest method testHandleDeleteChirp.

@Test
public void testHandleDeleteChirp() throws DataHandlingException {
    MessageGeneral message = new MessageGeneral(SENDER_KEY, ADD_CHIRP, GSON);
    messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message);
    final DeleteChirp DELETE_CHIRP = new DeleteChirp(message.getMessageId(), DELETION_TIME);
    MessageGeneral message2 = new MessageGeneral(SENDER_KEY, DELETE_CHIRP, GSON);
    messageHandler.handleMessage(laoRepository, messageSender, CHIRP_CHANNEL, message2);
    Optional<Chirp> chirpOpt = LAO.getChirp(message.getMessageId());
    assertTrue(chirpOpt.isPresent());
    Chirp chirp = chirpOpt.get();
    assertEquals(message.getMessageId(), chirp.getId());
    assertEquals(CHIRP_CHANNEL, chirp.getChannel());
    assertEquals(SENDER, chirp.getSender());
    assertEquals(EMPTY_STRING, chirp.getText());
    assertEquals(CREATION_TIME, chirp.getTimestamp());
    assertEquals(PARENT_ID, chirp.getParentId());
    Map<MessageID, Chirp> chirps = LAO.getAllChirps();
    assertEquals(1, chirps.size());
    assertEquals(chirp, chirps.get(chirp.getId()));
}
Also used : DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Chirp(com.github.dedis.popstellar.model.objects.Chirp) AddChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.AddChirp) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) DeleteChirp(com.github.dedis.popstellar.model.network.method.message.data.socialmedia.DeleteChirp) Base64DataUtils.generateMessageID(com.github.dedis.popstellar.testutils.Base64DataUtils.generateMessageID) MessageID(com.github.dedis.popstellar.model.objects.security.MessageID) Test(org.junit.Test)

Example 24 with MessageGeneral

use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.

the class ConsensusHandlerTest method handleConsensusLearnTest.

// handle a learn from node3 for the elect of node2
// This test need be run after the elect message was handled, else the messageId would be invalid
private void handleConsensusLearnTest() throws DataHandlingException {
    ConsensusLearn learn = new ConsensusLearn(INSTANCE_ID, messageId, CREATION_TIME, true, Collections.emptyList());
    MessageGeneral learnMsg = getMsg(NODE_3_KEY, learn);
    messageHandler.handleMessage(laoRepository, messageSender, CONSENSUS_CHANNEL, learnMsg);
    Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(electMsg.getMessageId());
    assertTrue(electInstanceOpt.isPresent());
    ElectInstance electInstance = electInstanceOpt.get();
    assertEquals(ACCEPTED, electInstance.getState());
}
Also used : ElectInstance(com.github.dedis.popstellar.model.objects.ElectInstance) MessageGeneral(com.github.dedis.popstellar.model.network.method.message.MessageGeneral) ConsensusLearn(com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusLearn)

Example 25 with MessageGeneral

use of com.github.dedis.popstellar.model.network.method.message.MessageGeneral in project popstellar by dedis.

the class ConsensusHandlerTest method setup.

@Before
public void setup() throws GeneralSecurityException, DataHandlingException, IOException {
    lenient().when(keyManager.getMainKeyPair()).thenReturn(ORGANIZER_KEY);
    lenient().when(keyManager.getMainPublicKey()).thenReturn(ORGANIZER);
    when(messageSender.subscribe(any())).then(args -> Completable.complete());
    laoRepository = new LAORepository();
    messageHandler = new MessageHandler(DataRegistryModule.provideDataRegistry(), keyManager);
    lao = new Lao(LAO_ID);
    laoRepository.getLaoById().put(LAO_ID, new LAOState(lao));
    MessageGeneral createLaoMessage = getMsg(ORGANIZER_KEY, CREATE_LAO);
    messageHandler.handleMessage(laoRepository, messageSender, lao.getChannel(), createLaoMessage);
    electMsg = getMsg(NODE_2_KEY, elect);
    messageId = electMsg.getMessageId();
}
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) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) Before(org.junit.Before)

Aggregations

MessageGeneral (com.github.dedis.popstellar.model.network.method.message.MessageGeneral)33 Test (org.junit.Test)18 Lao (com.github.dedis.popstellar.model.objects.Lao)10 Channel (com.github.dedis.popstellar.model.objects.Channel)8 LAORepository (com.github.dedis.popstellar.repository.LAORepository)8 Disposable (io.reactivex.disposables.Disposable)7 StateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.StateLao)6 UpdateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.UpdateLao)6 RollCall (com.github.dedis.popstellar.model.objects.RollCall)6 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)6 Before (org.junit.Before)6 ConsensusElectAccept (com.github.dedis.popstellar.model.network.method.message.data.consensus.ConsensusElectAccept)5 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)5 Election (com.github.dedis.popstellar.model.objects.Election)5 WitnessMessage (com.github.dedis.popstellar.model.objects.WitnessMessage)5 MessageID (com.github.dedis.popstellar.model.objects.security.MessageID)5 LAOState (com.github.dedis.popstellar.repository.LAOState)5 CloseRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CloseRollCall)4 CreateRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.CreateRollCall)4 OpenRollCall (com.github.dedis.popstellar.model.network.method.message.data.rollcall.OpenRollCall)4