use of com.github.dedis.popstellar.model.objects.security.MessageID in project popstellar by dedis.
the class MessageGeneral method verify.
public boolean verify() {
if (!this.sender.verify(this.signature, this.dataBuf))
return false;
if (this.data instanceof WitnessMessageSignature) {
WitnessMessageSignature witness = (WitnessMessageSignature) this.data;
Signature witnessSignature = witness.getSignature();
MessageID messageID = witness.getMessageId();
return this.sender.verify(witnessSignature, messageID);
} else {
return true;
}
}
use of com.github.dedis.popstellar.model.objects.security.MessageID 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.security.MessageID 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.security.MessageID 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.security.MessageID 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));
}
Aggregations