diff --git a/meerkat-common/src/main/proto/meerkat/voting.proto b/meerkat-common/src/main/proto/meerkat/voting.proto index 759a708..8b49ca9 100644 --- a/meerkat-common/src/main/proto/meerkat/voting.proto +++ b/meerkat-common/src/main/proto/meerkat/voting.proto @@ -28,7 +28,9 @@ message UIElement { bytes data = 2; } -// a new data structure for BallotQuestion. Need to delete the old one +// A question in the ballot +// is_mandatory determines whether the question may be skipped with no answer +// description might hold information/guidlines for the voter message BallotQuestion { bool is_mandatory = 1; UIElement question = 2; diff --git a/voting-booth/src/main/java/meerkat/voting/BallotOutputDevice.java b/voting-booth/src/main/java/meerkat/voting/BallotOutputDevice.java index 32e3208..39eed6a 100644 --- a/voting-booth/src/main/java/meerkat/voting/BallotOutputDevice.java +++ b/voting-booth/src/main/java/meerkat/voting/BallotOutputDevice.java @@ -1,5 +1,6 @@ package meerkat.voting; +import com.google.common.util.concurrent.FutureCallback; import meerkat.protobuf.Voting.*; /** @@ -7,13 +8,20 @@ import meerkat.protobuf.Voting.*; */ public interface BallotOutputDevice { - void commitToBallot(long sessionId, EncryptedBallot encryptedBallot, VotingBooth.Callback callback); + /** + * + * @param requestId + * @param encryptedBallot + * @param callback + */ + void commitToBallot(int requestId, EncryptedBallot encryptedBallot, + FutureCallback> callback); - void audit(long sessionId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets, VotingBooth.Callback callback); + void audit(int requestId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets, + FutureCallback> callback); - void castBallot(long sessionId, VotingBooth.Callback callback); + void castBallot(int requestId, FutureCallback> callback); - // probably has no difference than cast. Maybe drop this method - void cancelBallot(long sessionId, VotingBooth.Callback callback); + void cancelBallot(int requestId, FutureCallback> callback); } diff --git a/voting-booth/src/main/java/meerkat/voting/StorageManager.java b/voting-booth/src/main/java/meerkat/voting/StorageManager.java index 3edff7a..c05f383 100644 --- a/voting-booth/src/main/java/meerkat/voting/StorageManager.java +++ b/voting-booth/src/main/java/meerkat/voting/StorageManager.java @@ -1,12 +1,13 @@ package meerkat.voting; +import meerkat.protobuf.Voting; + /** * Created by hai on 23/02/16. */ public interface StorageManager { - // should these methods be synchronous or asynchronous? Can we rely on it being immediate? - public void detectAdminHardwareKey(); + boolean detectAdminHardwareKey(); - public void readElectionParams (); + Voting.ElectionParams readElectionParams (); } diff --git a/voting-booth/src/main/java/meerkat/voting/UI.java b/voting-booth/src/main/java/meerkat/voting/UI.java deleted file mode 100644 index 83739db..0000000 --- a/voting-booth/src/main/java/meerkat/voting/UI.java +++ /dev/null @@ -1,32 +0,0 @@ -package meerkat.voting; - -import meerkat.protobuf.Voting.*; - -/** - * Created by hai on 23/02/16. - */ -public interface UI { - - - // Voter scenario methods - void introductionToVoter (long sessionId); - - void chooseChannel (long sessionId, BallotQuestion question); - - void askVoterQuestion (long sessionId, int questionNumber, BallotQuestion question); - - void castOrAudit (long sessionId); - - void showWaitForFinishScreen (long sessionId); - - - // Admin scenario methods - //TODO: the admin scenario still needs some more thinking - - - - // bad thing happened scenario - void showErrorMessageAndHalt (String errorMessage); - void showErrorMessageWithCancelButton (long sessionId, String errorMessage); - -} diff --git a/voting-booth/src/main/java/meerkat/voting/VotingBooth.java b/voting-booth/src/main/java/meerkat/voting/VotingBooth.java index a7df483..9182eca 100644 --- a/voting-booth/src/main/java/meerkat/voting/VotingBooth.java +++ b/voting-booth/src/main/java/meerkat/voting/VotingBooth.java @@ -1,6 +1,5 @@ package meerkat.voting; -import meerkat.protobuf.Voting; import meerkat.protobuf.Voting.*; /** @@ -8,75 +7,21 @@ import meerkat.protobuf.Voting.*; */ public interface VotingBooth { - public enum ErrorID { - OUTPUT_DEVICE_OUT_OF_PAPER, - OUTPUT_DEVICE_OUT_OF_INK, - OUTPUT_DEVICE_NO_CONNECTION, - OUTPUT_DEVICE_HARDWARE_NOT_FOUND, + void setComponenets (BallotOutputDevice outputDevice, + VotingBoothEncryptor vbEncryptor, + VotingBoothUI vbUI, + StorageManager vbStorageManager); - UI_HARDWARE_NOT_FOUND - } + void initBoothParams (BoothParams boothParams); - - // keeps track in which state we are - // internal state will also include the number of the current question and the answers we got so far, - // later it includes the details of the PlaintextBallot and later the Encryption and the secrets - public enum State { - INITIALIZED, - - VOTER_INTRODUCTION, - VOTER_CHOOSE_CHANNEL, - VOTER_VOTING, - VOTER_ENCRYPTING, - VOTER_CAST_OR_AUDIT, - VOTER_CASTING, - VOTER_AUDITING - - } - - public interface Callback { - - // callbacks and messages from BallotOutputDevice - - public void ballotCommitResult (long sessionId, boolean result); - public void ballotCastResult (long sessionId, boolean result); - public void ballotAuditResult (long sessionId, boolean result); - public void ballotCancelResult (long sessionId, boolean result); - // other error messages, such as Printer turned-off or out-of-paper - public void outputDeviceReportProblem (ErrorID errorId); - - - // callbacks and messages from UI - - public void introductionFinished (long sessionId); - public void choiceOfChannel (long sessionId, int channelNumber); - public void skipQuestion (long sessionId, int questionNumber); - public void backwardsQuestion (long sessionId, int questionNumber); - public void cancelVotingSession (long sessionId); - public void answer (long sessionId, int questionNumber, String answer); - public void cast (long sessionId); - public void audit (long sessionId); - // other error messages, such as hardware-not-detected - public void uiReportProblem (ErrorID errorId); - - - // callbacks from encryptor - - public void returnEncryption (long sessionId, EncryptedBallot encryptedBallot, BallotSecrets secrets); - - - // callbacks from StorageManager - - public void adminHardwareKeyDetected (boolean isKeyInserted); - public void loadElectionParams (ElectionParams electionParams); - } + void initElectionParams (ElectionParams electionParams); // this function is synchronous - public void start (); + void start (); // messages from Admin Console (If there is such one) // this function is asynchronous - public void shutDown(); + void shutDown(); } diff --git a/voting-booth/src/main/java/meerkat/voting/Encryptor.java b/voting-booth/src/main/java/meerkat/voting/VotingBoothEncryptor.java similarity index 61% rename from voting-booth/src/main/java/meerkat/voting/Encryptor.java rename to voting-booth/src/main/java/meerkat/voting/VotingBoothEncryptor.java index 4cfcf57..60384e9 100644 --- a/voting-booth/src/main/java/meerkat/voting/Encryptor.java +++ b/voting-booth/src/main/java/meerkat/voting/VotingBoothEncryptor.java @@ -5,9 +5,9 @@ import meerkat.protobuf.Voting.*; /** * Created by hai on 23/02/16. */ -public interface Encryptor { +public interface VotingBoothEncryptor { - public void encrypt (long sessionId, PlaintextBallot plaintextBallot); + void encrypt (PlaintextBallot plaintextBallot); //TODO: probably needs some key generation methods as well } diff --git a/voting-booth/src/main/java/meerkat/voting/VotingBoothResult.java b/voting-booth/src/main/java/meerkat/voting/VotingBoothResult.java new file mode 100644 index 0000000..6702ce9 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/VotingBoothResult.java @@ -0,0 +1,17 @@ +package meerkat.voting; + +/** + * Created by hai on 02/03/16. + */ +public class VotingBoothResult { + private final int m_requestId; + private final T m_result; + + public int getRequestId () { return m_requestId; } + public T getResult () { return m_result; } + + public VotingBoothResult (int requestId, T result) { + m_requestId = requestId; + m_result = result; + } +} diff --git a/voting-booth/src/main/java/meerkat/voting/VotingBoothUI.java b/voting-booth/src/main/java/meerkat/voting/VotingBoothUI.java new file mode 100644 index 0000000..0726a09 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/VotingBoothUI.java @@ -0,0 +1,64 @@ +package meerkat.voting; + +import com.google.common.util.concurrent.FutureCallback; +import meerkat.protobuf.Voting.*; + +/** + * Created by hai on 23/02/16. + */ +public interface VotingBoothUI { + + enum VoterQuestionChoice { + ANSWERED, + SKIP, + BACK, + CANCEL + } + + class VoterQuestionResponse { + private final VoterQuestionChoice m_choice; + private final String m_answer; + + public VoterQuestionResponse(VoterQuestionChoice choice, String answer) { + assert ((choice == VoterQuestionChoice.ANSWERED && answer != null) || + (choice != VoterQuestionChoice.ANSWERED && answer == null)); + m_choice = choice; + m_answer = answer; + } + + public VoterQuestionChoice getChoice () { return m_choice; } + public String getAnswer () { return m_answer; } + } + + + enum FinalizeBallotChoice { + CAST, + AUDIT + } + + // Voter scenario methods + void newVoter (int requestId, FutureCallback> callback); + + void chooseChannel (int requestId, BallotQuestion question, FutureCallback> callback); + + void askVoterQuestion (int requestId, int questionNumber, BallotQuestion question, + FutureCallback> callback); + + void castOrAudit (int requestId, FutureCallback> callback); + + void showWaitForFinishScreen (int requestId, FutureCallback> callback); + + + // Admin scenario methods + //TODO: the admin scenario still needs some more thinking + + + + // bad thing happened scenario + void showErrorMessageAndHalt (int requestId, String errorMessage, + FutureCallback> callback); + + void showErrorMessageWithButtons (int requestId, String errorMessage, String[] buttonLabels, + FutureCallback> callback); + +}