From 6359f74a7b4fd5bec50051374ab8fae80ebc0349 Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Fri, 4 Mar 2016 06:02:53 -0800 Subject: [PATCH] Updated the VoterRegistry.proto file according to the new timestamp of the unsingedBulletinBoardMessage. --- .../main/proto/meerkat/VoterRegistry.proto | 9 ++------ .../java/meerkat/Registry/RegistryTags.java | 2 +- .../src/main/java/meerkat/SimpleRegistry.java | 23 +++++++++---------- .../src/main/java/meerkat/VoterRegistry.java | 2 +- .../src/test/java/SimpleRegistryTest.java | 4 ++-- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto b/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto index abfea1c..a0765d5 100644 --- a/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto +++ b/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto @@ -17,12 +17,7 @@ message GroupID{ string id = 1; } -message VoterGroup{ - VoterID voterId = 1; - GroupID groupId = 2; -} - message VoterRegistryMessage{ - bytes data = 1; - uint64 CreationMiliseconds = 2; + VoterID voterID = 1; + repeated GroupID groupID = 2; } \ No newline at end of file diff --git a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java index 8113af6..13fbadb 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java +++ b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java @@ -10,7 +10,7 @@ public abstract class RegistryTags { public final static String VOTER_ENTRY_TAG = "VoterEntry: "; public final static String VOTER_DATA_TAG = "Data: "; public final static String GROUP_ID_TAG = "GroupID: "; - public final static String ADD_TO_GROUP_TAG = "AddToGroup: "; + public final static String ADD_TO_GROUP_TAG = "AddToGroups: "; public final static String VOTE_ACTION_TAG = "VoteAction: "; } diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index da69a74..5a136f8 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -1,5 +1,6 @@ package meerkat; +import com.google.protobuf.Timestamp; import meerkat.Registry.BooleanCallBack; import meerkat.Registry.CollectionMessagesUtils; import meerkat.Registry.RegistryTags; @@ -62,39 +63,37 @@ public class SimpleRegistry implements VoterRegistry{ } public void AddVoter(VoterInfo voterInfo, RegistryCallBack callback) { - VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder(). - setData(voterInfo.toByteString()).setCreationMiliseconds(System.currentTimeMillis()); UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder(). addTag(RegistryTags.ID_TAG + voterInfo.getId().getId()) .addTag(RegistryTags.VOTER_ENTRY_TAG) .addTag(RegistryTags.VOTER_DATA_TAG + voterInfo.getInfo()) - .setData(wrapper.build().toByteString()); + .setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build()); bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } - public void AddToGroup(VoterGroup voterGroup, RegistryCallBack callback) { - VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder(). - setData(voterGroup.toByteString()).setCreationMiliseconds(System.currentTimeMillis()); + public void AddToGroups(VoterRegistryMessage voterGroup, RegistryCallBack callback) { UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder() - .addTag(RegistryTags.ID_TAG + voterGroup.getVoterId().getId()) - .addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupId().getId()) + .addTag(RegistryTags.ID_TAG + voterGroup.getVoterID().getId()) .addTag(RegistryTags.ADD_TO_GROUP_TAG) - .setData(wrapper.build().toByteString()); + .setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build()); + + for ( int i = 0 ; i < voterGroup.getGroupIDCount() ; i++) + { + basicMessage.addTag(RegistryTags.GROUP_ID_TAG + voterGroup.getGroupID(i).getId()); + } bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } public void SetVoted(VoterID voterId, RegistryCallBack callback) { - VoterRegistryMessage.Builder wrapper = VoterRegistryMessage.newBuilder(). - setData(voterId.toByteString()).setCreationMiliseconds(System.currentTimeMillis()); UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder() .addTag(RegistryTags.ID_TAG + voterId.getId()) .addTag(RegistryTags.VOTE_ACTION_TAG) - .setData(wrapper.build().toByteString()); + .setTimestamp(Timestamp.newBuilder().setNanos((int) System.nanoTime()).build()); bulletinBoardClient.postMessage(CreateBulletinBoardMessage(basicMessage.build()), new BooleanCallBack(callback)); } diff --git a/voter-registry/src/main/java/meerkat/VoterRegistry.java b/voter-registry/src/main/java/meerkat/VoterRegistry.java index f7fe31f..4247fdd 100644 --- a/voter-registry/src/main/java/meerkat/VoterRegistry.java +++ b/voter-registry/src/main/java/meerkat/VoterRegistry.java @@ -36,7 +36,7 @@ public interface VoterRegistry { * @param callBack when the adding voter done callBack.HandleResult will be called * @return true if the adding action succeeded else return false */ - void AddToGroup(VoterGroup voterGroup, RegistryCallBack callBack); + void AddToGroups(VoterRegistryMessage voterGroup, RegistryCallBack callBack); /** * Sets that the voter have voted diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index 788b55a..88389b8 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -232,7 +232,7 @@ public class SimpleRegistryTest extends TestCase { .setGroupId(GroupID.newBuilder().setId(groupId)).build(); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream); - registry.AddToGroup(voterInfo, handler); + registry.AddToGroups(voterInfo, handler); jobSemaphore.acquire(); assertEquals(1, handler.counter); @@ -267,7 +267,7 @@ public class SimpleRegistryTest extends TestCase { this.certStream = getClass().getResourceAsStream(CERT1_PEM_EXAMPLE); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient,certStream); - registry.AddToGroup(voterInfo, handler); + registry.AddToGroups(voterInfo, handler); jobSemaphore.acquire(); assertEquals(1, handler.counter );