use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LaoDetailViewModel method sendConsensusElect.
/**
* Sends a ConsensusElect message.
*
* <p>Publish a GeneralMessage containing ConsensusElect data.
*
* @param creation the creation time of the consensus
* @param objId the id of the object the consensus refers to (e.g. election_id)
* @param type the type of object the consensus refers to (e.g. election)
* @param property the property the value refers to (e.g. "state")
* @param value the proposed new value for the property (e.g. "started")
*/
public void sendConsensusElect(long creation, String objId, String type, String property, Object value) {
Log.d(TAG, String.format("creating a new consensus for type: %s, property: %s, value: %s", type, property, value));
Lao lao = getCurrentLaoValue();
if (lao == null) {
Log.d(TAG, LAO_FAILURE_MESSAGE);
return;
}
Channel channel = lao.getChannel().subChannel("consensus");
ConsensusElect consensusElect = new ConsensusElect(creation, objId, type, property, value);
Log.d(TAG, PUBLISH_MESSAGE);
MessageGeneral msg = new MessageGeneral(keyManager.getMainKeyPair(), consensusElect, gson);
Disposable disposable = networkManager.getMessageSender().publish(channel, msg).subscribe(() -> Log.d(TAG, "created a consensus with message id : " + msg.getMessageId()), error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_start_election));
disposables.add(disposable);
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LAONetworkManager method catchup.
@Override
public Completable catchup(Channel channel) {
Log.d(TAG, "sending a catchup to the channel " + channel);
Catchup catchup = new Catchup(channel, requestCounter.incrementAndGet());
return request(catchup).map(ResultMessages.class::cast).map(ResultMessages::getMessages).doOnSuccess(messages -> Log.d(TAG, "Catchup on " + channel + " retrieved : " + messages)).doOnSuccess(messages -> handleMessages(messages, channel)).ignoreElement();
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class ConsensusHandler method handleLearn.
public static void handleLearn(HandlerContext context, ConsensusLearn consensusLearn) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
Lao lao = laoRepository.getLaoByChannel(channel);
Optional<ElectInstance> electInstanceOpt = lao.getElectInstance(consensusLearn.getMessageId());
if (!electInstanceOpt.isPresent()) {
Log.w(TAG, "learn for invalid messageId : " + consensusLearn.getMessageId());
throw new InvalidMessageIdException(consensusLearn, consensusLearn.getMessageId());
}
ElectInstance electInstance = electInstanceOpt.get();
if (consensusLearn.getLearnValue().isDecision()) {
electInstance.setState(ElectInstance.State.ACCEPTED);
}
lao.updateElectInstance(electInstance);
laoRepository.updateNodes(lao.getChannel());
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class ConsensusHandler method handleElect.
/**
* Process an Elect message.
*
* @param context the HandlerContext of the message
* @param consensusElect the data of the message that was received
*/
public static void handleElect(HandlerContext context, ConsensusElect consensusElect) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
PublicKey senderPk = context.getSenderPk();
Lao lao = laoRepository.getLaoByChannel(channel);
Set<PublicKey> nodes = new HashSet<>(lao.getWitnesses());
nodes.add(lao.getOrganizer());
ElectInstance electInstance = new ElectInstance(messageId, channel, senderPk, nodes, consensusElect);
lao.updateElectInstance(electInstance);
laoRepository.updateNodes(lao.getChannel());
}
use of com.github.dedis.popstellar.model.objects.Channel in project popstellar by dedis.
the class LaoHandler method handleCreateLao.
/**
* Process a CreateLao message.
*
* @param context the HandlerContext of the message
* @param createLao the message that was received
*/
public static void handleCreateLao(HandlerContext context, CreateLao createLao) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
Log.d(TAG, "handleCreateLao: channel " + channel + ", msg=" + createLao);
Lao lao = laoRepository.getLaoByChannel(channel);
lao.setName(createLao.getName());
lao.setCreation(createLao.getCreation());
lao.setLastModified(createLao.getCreation());
lao.setOrganizer(createLao.getOrganizer());
lao.setId(createLao.getId());
lao.setWitnesses(new HashSet<>(createLao.getWitnesses()));
PublicKey publicKey = context.getKeyManager().getMainPublicKey();
if (lao.getOrganizer().equals(publicKey) || lao.getWitnesses().contains(publicKey)) {
context.getMessageSender().subscribe(lao.getChannel().subChannel("consensus")).subscribe();
}
laoRepository.updateNodes(channel);
}
Aggregations