Changes made in the initial interfaces for further code review.

1. Especially tried to fix the callback mechanism I previously used.
2. 'long sessionID' changed to 'int requestId'
3. Introduced a generic class VotingBoothResult
4. Quite some other local changes
vbdev2
Hai Brenner 2016-03-02 19:52:17 +02:00
parent 77f47fe9e1
commit 15453a772d
8 changed files with 111 additions and 106 deletions

View File

@ -28,7 +28,9 @@ message UIElement {
bytes data = 2; 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 { message BallotQuestion {
bool is_mandatory = 1; bool is_mandatory = 1;
UIElement question = 2; UIElement question = 2;

View File

@ -1,5 +1,6 @@
package meerkat.voting; package meerkat.voting;
import com.google.common.util.concurrent.FutureCallback;
import meerkat.protobuf.Voting.*; import meerkat.protobuf.Voting.*;
/** /**
@ -7,13 +8,20 @@ import meerkat.protobuf.Voting.*;
*/ */
public interface BallotOutputDevice { 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<VotingBoothResult<Boolean>> callback);
void audit(long sessionId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets, VotingBooth.Callback callback); void audit(int requestId, EncryptedBallot encryptedBallot, BallotSecrets ballotSecrets,
FutureCallback<VotingBoothResult<Boolean>> callback);
void castBallot(long sessionId, VotingBooth.Callback callback); void castBallot(int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
// probably has no difference than cast. Maybe drop this method void cancelBallot(int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
void cancelBallot(long sessionId, VotingBooth.Callback callback);
} }

View File

@ -1,12 +1,13 @@
package meerkat.voting; package meerkat.voting;
import meerkat.protobuf.Voting;
/** /**
* Created by hai on 23/02/16. * Created by hai on 23/02/16.
*/ */
public interface StorageManager { public interface StorageManager {
// should these methods be synchronous or asynchronous? Can we rely on it being immediate? boolean detectAdminHardwareKey();
public void detectAdminHardwareKey();
public void readElectionParams (); Voting.ElectionParams readElectionParams ();
} }

View File

@ -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);
}

View File

@ -1,6 +1,5 @@
package meerkat.voting; package meerkat.voting;
import meerkat.protobuf.Voting;
import meerkat.protobuf.Voting.*; import meerkat.protobuf.Voting.*;
/** /**
@ -8,75 +7,21 @@ import meerkat.protobuf.Voting.*;
*/ */
public interface VotingBooth { public interface VotingBooth {
public enum ErrorID { void setComponenets (BallotOutputDevice outputDevice,
OUTPUT_DEVICE_OUT_OF_PAPER, VotingBoothEncryptor vbEncryptor,
OUTPUT_DEVICE_OUT_OF_INK, VotingBoothUI vbUI,
OUTPUT_DEVICE_NO_CONNECTION, StorageManager vbStorageManager);
OUTPUT_DEVICE_HARDWARE_NOT_FOUND,
UI_HARDWARE_NOT_FOUND void initBoothParams (BoothParams boothParams);
}
void initElectionParams (ElectionParams electionParams);
// 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);
}
// this function is synchronous // this function is synchronous
public void start (); void start ();
// messages from Admin Console (If there is such one) // messages from Admin Console (If there is such one)
// this function is asynchronous // this function is asynchronous
public void shutDown(); void shutDown();
} }

View File

@ -5,9 +5,9 @@ import meerkat.protobuf.Voting.*;
/** /**
* Created by hai on 23/02/16. * 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 //TODO: probably needs some key generation methods as well
} }

View File

@ -0,0 +1,17 @@
package meerkat.voting;
/**
* Created by hai on 02/03/16.
*/
public class VotingBoothResult<T> {
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;
}
}

View File

@ -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<VotingBoothResult<Boolean>> callback);
void chooseChannel (int requestId, BallotQuestion question, FutureCallback<VotingBoothResult<Integer>> callback);
void askVoterQuestion (int requestId, int questionNumber, BallotQuestion question,
FutureCallback<VotingBoothResult<VoterQuestionResponse>> callback);
void castOrAudit (int requestId, FutureCallback<VotingBoothResult<FinalizeBallotChoice>> callback);
void showWaitForFinishScreen (int requestId, FutureCallback<VotingBoothResult<Boolean>> callback);
// Admin scenario methods
//TODO: the admin scenario still needs some more thinking
// bad thing happened scenario
void showErrorMessageAndHalt (int requestId, String errorMessage,
FutureCallback<VotingBoothResult<Boolean>> callback);
void showErrorMessageWithButtons (int requestId, String errorMessage, String[] buttonLabels,
FutureCallback<VotingBoothResult<Integer>> callback);
}