use of com.github.dedis.popstellar.model.objects.Lao 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);
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class LaoHandler method handleUpdateLao.
/**
* Process an UpdateLao message.
*
* @param context the HandlerContext of the message
* @param updateLao the message that was received
*/
public static void handleUpdateLao(HandlerContext context, UpdateLao updateLao) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Log.d(TAG, " Receive Update Lao Broadcast msg=" + updateLao);
Lao lao = laoRepository.getLaoByChannel(channel);
if (lao.getLastModified() > updateLao.getLastModified()) {
// the current state we have is more up to date
throw new DataHandlingException(updateLao, "The current Lao is more up to date than the update lao message");
}
WitnessMessage message;
if (!updateLao.getName().equals(lao.getName())) {
message = updateLaoNameWitnessMessage(messageId, updateLao, lao);
} else if (!updateLao.getWitnesses().equals(lao.getWitnesses())) {
message = updateLaoWitnessesWitnessMessage(messageId, updateLao, lao);
} else {
Log.d(TAG, "Cannot set the witness message title to update lao");
throw new DataHandlingException(updateLao, "Cannot set the witness message title to update lao");
}
lao.updateWitnessMessage(messageId, message);
if (!lao.getWitnesses().isEmpty()) {
// We send a pending update only if there are already some witness that need to sign this
// UpdateLao
lao.getPendingUpdates().add(new PendingUpdate(updateLao.getLastModified(), messageId));
}
laoRepository.updateNodes(channel);
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class RollCallHandler method handleCloseRollCall.
/**
* Process a CloseRollCall message.
*
* @param context the HandlerContext of the message
* @param closeRollCall the message that was received
*/
public static void handleCloseRollCall(HandlerContext context, CloseRollCall closeRollCall) throws DataHandlingException {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Lao lao = laoRepository.getLaoByChannel(channel);
Log.d(TAG, "handleCloseRollCall: " + channel);
String updateId = closeRollCall.getUpdateId();
String closes = closeRollCall.getCloses();
Optional<RollCall> rollCallOptional = lao.getRollCall(closes);
if (!rollCallOptional.isPresent()) {
Log.w(TAG, "Cannot find roll call to close : " + closes);
throw new InvalidDataException(closeRollCall, "close id", closes);
}
RollCall rollCall = rollCallOptional.get();
rollCall.setEnd(closeRollCall.getClosedAt());
rollCall.setId(updateId);
rollCall.getAttendees().addAll(closeRollCall.getAttendees());
rollCall.setState(EventState.CLOSED);
lao.updateRollCall(closes, rollCall);
lao.updateWitnessMessage(messageId, closeRollCallWitnessMessage(messageId, rollCall));
// Subscribe to the social media channels
try {
PoPToken token = context.getKeyManager().getValidPoPToken(lao, rollCall);
context.getMessageSender().subscribe(channel.subChannel("social").subChannel(token.getPublicKey().getEncoded())).subscribe();
} catch (InvalidPoPTokenException e) {
Log.i(TAG, "Received a close roll-call that you did not attend");
} catch (KeyException e) {
Log.e(TAG, "Could not retrieve your PoP Token to subscribe you to your social media channel", e);
}
}
use of com.github.dedis.popstellar.model.objects.Lao in project popstellar by dedis.
the class RollCallHandler method handleCreateRollCall.
/**
* Process a CreateRollCall message.
*
* @param context the HandlerContext of the message
* @param createRollCall the message that was received
*/
public static void handleCreateRollCall(HandlerContext context, CreateRollCall createRollCall) {
LAORepository laoRepository = context.getLaoRepository();
Channel channel = context.getChannel();
MessageID messageId = context.getMessageId();
Lao lao = laoRepository.getLaoByChannel(channel);
Log.d(TAG, "handleCreateRollCall: " + channel + " name " + createRollCall.getName());
RollCall rollCall = new RollCall(createRollCall.getId());
rollCall.setCreation(createRollCall.getCreation());
rollCall.setState(EventState.CREATED);
rollCall.setStart(createRollCall.getProposedStart());
rollCall.setEnd(createRollCall.getProposedEnd());
rollCall.setName(createRollCall.getName());
rollCall.setLocation(createRollCall.getLocation());
rollCall.setLocation(createRollCall.getLocation());
rollCall.setDescription(createRollCall.getDescription().orElse(""));
lao.updateRollCall(rollCall.getId(), rollCall);
lao.updateWitnessMessage(messageId, createRollCallWitnessMessage(messageId, rollCall));
}
use of com.github.dedis.popstellar.model.objects.Lao 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));
}
Aggregations