diff options
author | Florian Dold <florian.dold@gmail.com> | 2014-03-11 01:24:03 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2014-03-11 01:24:03 +0000 |
commit | e2eecb019105d48e4afebe1bf57355b3450c8219 (patch) | |
tree | 74d8aee60cc6d336a3bb0445af8e091cc2351ecd /src/main/java/org/gnunet/voting/Ballot.java | |
parent | 651cfb94264b0d12e8ed9afafab05f84d2201933 (diff) | |
download | gnunet-java-e2eecb019105d48e4afebe1bf57355b3450c8219.tar.gz gnunet-java-e2eecb019105d48e4afebe1bf57355b3450c8219.zip |
- simplify request containers
- statistics bugs
- fix missing annotation in consensus api
- work on voting
Diffstat (limited to 'src/main/java/org/gnunet/voting/Ballot.java')
-rw-r--r-- | src/main/java/org/gnunet/voting/Ballot.java | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/main/java/org/gnunet/voting/Ballot.java b/src/main/java/org/gnunet/voting/Ballot.java index 10bf25a..92ec7da 100644 --- a/src/main/java/org/gnunet/voting/Ballot.java +++ b/src/main/java/org/gnunet/voting/Ballot.java | |||
@@ -28,8 +28,14 @@ import com.google.common.collect.HashBiMap; | |||
28 | import com.google.common.collect.Maps; | 28 | import com.google.common.collect.Maps; |
29 | import com.google.common.primitives.Longs; | 29 | import com.google.common.primitives.Longs; |
30 | import org.gnunet.secretsharing.ThresholdPublicKey; | 30 | import org.gnunet.secretsharing.ThresholdPublicKey; |
31 | import org.gnunet.util.*; | 31 | import org.gnunet.util.AbsoluteTime; |
32 | import org.gnunet.util.crypto.*; | 32 | import org.gnunet.util.Configuration; |
33 | import org.gnunet.util.HashCode; | ||
34 | import org.gnunet.util.PeerIdentity; | ||
35 | import org.gnunet.util.crypto.EcdsaPrivateKey; | ||
36 | import org.gnunet.util.crypto.EcdsaPublicKey; | ||
37 | import org.gnunet.util.crypto.EcdsaSignature; | ||
38 | import org.gnunet.util.crypto.EddsaSignature; | ||
33 | import org.gnunet.voting.messages.KeyQueryResponseMessage; | 39 | import org.gnunet.voting.messages.KeyQueryResponseMessage; |
34 | 40 | ||
35 | import java.security.MessageDigest; | 41 | import java.security.MessageDigest; |
@@ -263,13 +269,13 @@ public class Ballot { | |||
263 | } | 269 | } |
264 | confirmationSigs.put(e.getKey(), sig); | 270 | confirmationSigs.put(e.getKey(), sig); |
265 | } | 271 | } |
266 | encryptedVote = EncryptedVote.parseFromConfiguration(cfg); | ||
267 | Optional<String> optVoterPub = cfg.getValueString("vote", "VOTER_PUB"); | 272 | Optional<String> optVoterPub = cfg.getValueString("vote", "VOTER_PUB"); |
268 | if (optVoterPub.isPresent()) { | 273 | if (optVoterPub.isPresent()) { |
269 | voterPub = EcdsaPublicKey.fromString(optVoterPub.get()); | 274 | voterPub = EcdsaPublicKey.fromString(optVoterPub.get()); |
270 | if (null == voterPub) { | 275 | if (null == voterPub) { |
271 | throw new InvalidBallotException("voter public key present but invalid"); | 276 | throw new InvalidBallotException("voter public key present but invalid"); |
272 | } | 277 | } |
278 | encryptedVote = EncryptedVote.parseFromConfiguration(cfg, voterPub); | ||
273 | } | 279 | } |
274 | 280 | ||
275 | startTime = getTime(cfg, "START"); | 281 | startTime = getTime(cfg, "START"); |
@@ -302,8 +308,8 @@ public class Ballot { | |||
302 | m.signedGuidKey = new KeyQueryResponseMessage.BallotPublicKey(); | 308 | m.signedGuidKey = new KeyQueryResponseMessage.BallotPublicKey(); |
303 | m.signedGuidKey.ballotGuid = getBallotGuid(); | 309 | m.signedGuidKey.ballotGuid = getBallotGuid(); |
304 | m.signedGuidKey.publicKey = ThresholdPublicKey.fromString(e.getValue()); | 310 | m.signedGuidKey.publicKey = ThresholdPublicKey.fromString(e.getValue()); |
311 | thresholdPublicKeys.put(alias, m); | ||
305 | } | 312 | } |
306 | |||
307 | } | 313 | } |
308 | 314 | ||
309 | /** | 315 | /** |
@@ -355,7 +361,7 @@ public class Ballot { | |||
355 | if (counts.containsKey(pk)) { | 361 | if (counts.containsKey(pk)) { |
356 | counts.put(pk, counts.get(pk) + 1); | 362 | counts.put(pk, counts.get(pk) + 1); |
357 | } else { | 363 | } else { |
358 | counts.put(pk, 0); | 364 | counts.put(pk, 1); |
359 | } | 365 | } |
360 | } | 366 | } |
361 | int maxCount = 0; | 367 | int maxCount = 0; |
@@ -390,11 +396,9 @@ public class Ballot { | |||
390 | i++; | 396 | i++; |
391 | } | 397 | } |
392 | voterPub = voterPrivateKey.getPublicKey(); | 398 | voterPub = voterPrivateKey.getPublicKey(); |
393 | if (choiceId < 0 || choiceId > 1) { | 399 | encryptedVote = EncryptedVote.fromChoice(choiceId, thresholdPublicKey, voterPrivateKey, voterPub); |
394 | throw new InvalidBallotException(String.format("choice '%s' not valid", choice)); | 400 | System.out.println("voter encrypted vote, ciphertext: " + encryptedVote.v.toString()); |
395 | } | 401 | System.out.println("threshold key (of voter): " + thresholdPublicKey.toString()); |
396 | |||
397 | encryptedVote = EncryptedVote.fromChoice(choiceId, thresholdPublicKey, voterPrivateKey); | ||
398 | } | 402 | } |
399 | 403 | ||
400 | /** | 404 | /** |
@@ -442,9 +446,7 @@ public class Ballot { | |||
442 | if (null != groupCert) { | 446 | if (null != groupCert) { |
443 | groupCert.writeBallotConfig(cfg); | 447 | groupCert.writeBallotConfig(cfg); |
444 | } | 448 | } |
445 | System.out.println("thresh set when writing: " + thresholdPublicKeys.size()); | ||
446 | for (Map.Entry<String,KeyQueryResponseMessage> e : thresholdPublicKeys.entrySet()) { | 449 | for (Map.Entry<String,KeyQueryResponseMessage> e : thresholdPublicKeys.entrySet()) { |
447 | System.out.println("writing tresh"); | ||
448 | cfg.setValueString("threshold-pubkeys", e.getKey(), | 450 | cfg.setValueString("threshold-pubkeys", e.getKey(), |
449 | e.getValue().signedGuidKey.publicKey.toString()); | 451 | e.getValue().signedGuidKey.publicKey.toString()); |
450 | cfg.setValueString("threshold-pubkey-sigs", e.getKey(), | 452 | cfg.setValueString("threshold-pubkey-sigs", e.getKey(), |
@@ -560,6 +562,15 @@ public class Ballot { | |||
560 | } else { | 562 | } else { |
561 | buf.append("no voter\n"); | 563 | buf.append("no voter\n"); |
562 | } | 564 | } |
565 | if (thresholdPublicKeys != null && thresholdPublicKeys.size() != 0) { | ||
566 | buf.append("Authorities with threshold public key:\n"); | ||
567 | for (String s : thresholdPublicKeys.keySet()) { | ||
568 | buf.append(s); | ||
569 | buf.append("\n"); | ||
570 | } | ||
571 | } else { | ||
572 | buf.append("no threshold public keys"); | ||
573 | } | ||
563 | return buf.toString(); | 574 | return buf.toString(); |
564 | } | 575 | } |
565 | 576 | ||