diff --git a/bulletin-board-server/meerkat b/bulletin-board-server/meerkat index 162a2ec..46153c6 100644 Binary files a/bulletin-board-server/meerkat and b/bulletin-board-server/meerkat differ diff --git a/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto b/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto index e3f163f..abfea1c 100644 --- a/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto +++ b/meerkat-common/src/main/proto/meerkat/VoterRegistry.proto @@ -20,4 +20,9 @@ message GroupID{ message VoterGroup{ VoterID voterId = 1; GroupID groupId = 2; +} + +message VoterRegistryMessage{ + bytes data = 1; + uint64 CreationMiliseconds = 2; } \ No newline at end of file diff --git a/voter-registry/src/main/java/meerkat/Registry/AccurateTimestamp.java b/voter-registry/src/main/java/meerkat/Registry/AccurateTimestamp.java deleted file mode 100644 index dd67a22..0000000 --- a/voter-registry/src/main/java/meerkat/Registry/AccurateTimestamp.java +++ /dev/null @@ -1,35 +0,0 @@ -package meerkat.Registry; - -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Created by Vladimir Eliezer Tokarev on 1/15/2016. - * converts time stamps to strings and the other way - */ -public abstract class AccurateTimestamp { - - private static final String DATE_FORMAT = "yyyy-MM-dd hh:mm:ss.SSS"; - - /** - * Converts current timestamp to string - * @return - */ - public static String GetCurrentTimestampString(){ - return new SimpleDateFormat(DATE_FORMAT).format(new java.util.Date()); - } - - /** - * Convets string timesta,p tp java.sql.timestamp - * @param timestamp string - * @return - * @throws ParseException - */ - public static java.sql.Timestamp GetTimestampFromString(String timestamp) throws ParseException { - Date date = new SimpleDateFormat(DATE_FORMAT).parse(timestamp); - return new Timestamp(date.getTime()); - } - -} diff --git a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java b/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java index 03d542c..c44f009 100644 --- a/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/meerkat/Registry/CollectionMessagesUtils.java @@ -1,5 +1,6 @@ package meerkat.Registry; +import com.google.protobuf.InvalidProtocolBufferException; import meerkat.VoterRegistryMessage; import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage; import meerkat.protobuf.BulletinBoardAPI.FilterType; @@ -45,7 +46,8 @@ public abstract class CollectionMessagesUtils { * @return Map{String:VoterRegistryMessage} * @throws ParseException */ - public static Map GetLatestGroupsActions(List messages) throws ParseException { + public static Map GetLatestGroupsActions(List messages) + throws ParseException, InvalidProtocolBufferException { Map groupIdToMessage = new HashMap<>(); // iterate trough all the messages and put into the map the last updated groups actions @@ -55,7 +57,7 @@ public abstract class CollectionMessagesUtils { VoterRegistryMessage temp = groupIdToMessage.get(groupId); if (temp != null && temp != message) { - if (temp.GetBasicMessageActionTimestamp().before(message.GetBasicMessageActionTimestamp())) { + if (temp.GetCreationTime() < message.GetCreationTime()) { groupIdToMessage.put(groupId, message); } } @@ -75,7 +77,7 @@ public abstract class CollectionMessagesUtils { while (entries.hasNext()) { Map.Entry tuple = (Map.Entry) entries.next(); VoterRegistryMessage message = (VoterRegistryMessage) tuple.getValue(); - String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG.toString()); + String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); groupsIds.add(groupId); } return groupsIds; @@ -88,15 +90,16 @@ public abstract class CollectionMessagesUtils { * @throws ParseException * @throws EmptyListException */ - public static VoterRegistryMessage GetLatestMessage(List messages) throws ParseException, EmptyListException { + public static VoterRegistryMessage GetLatestMessage(List messages) + throws ParseException, EmptyListException, InvalidProtocolBufferException { + System.out.print("1"); if (messages.size() == 0 ){ throw new EmptyListException("The list of messages passed to GetLatestMessage is empty."); } VoterRegistryMessage LatestMessage = messages.get(0); - for (int i = 0 ; i < messages.size() ; i++) { VoterRegistryMessage message = messages.get(i); - if (message.GetBasicMessageActionTimestamp().before(LatestMessage.GetBasicMessageActionTimestamp())) { + if (message.GetCreationTime() < LatestMessage.GetCreationTime()) { LatestMessage = message; } } diff --git a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java index 3f4d36a..8113af6 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java +++ b/voter-registry/src/main/java/meerkat/Registry/RegistryTags.java @@ -6,12 +6,12 @@ package meerkat.Registry; * Have the tags for the registry messages */ public abstract class RegistryTags { - public final static String ID_TAG = "ID:"; - public final static String VOTER_ENTRY_TAG = "VoterEntry:"; - public final static String GROUP_ID_TAG = "GroupID:"; - public final static String ADD_TO_GROUP_TAG = "AddToGroup:"; - public final static String ACTION_TIMESTAMP_TAG = "ActionTimestamp: "; - public final static String VOTE_ACTION_TAG = "VoteAction:"; + public final static String ID_TAG = "ID: "; + 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 VOTE_ACTION_TAG = "VoteAction: "; } diff --git a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java index 8339e62..9eabb1b 100644 --- a/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java +++ b/voter-registry/src/main/java/meerkat/Registry/RelevantDataCallBack.java @@ -1,5 +1,6 @@ package meerkat.Registry; +import com.google.protobuf.InvalidProtocolBufferException; import meerkat.MessageValidator; import meerkat.VoterRegistry.RegistryCallBack; import meerkat.VoterRegistryMessage; @@ -88,7 +89,8 @@ public class RelevantDataCallBack implements ClientCallback tags = base.getTagList(); - for (int i = 0 ; i < tags.size() ; i++) { - String tag = tags.get(i); - if (tag.contains(RegistryTags.ACTION_TIMESTAMP_TAG)) { - String[] tagParts = tag.split(" "); - - String timestamp = tagParts[tagParts.length - 2] + " " + tagParts[tagParts.length - 1]; - return AccurateTimestamp.GetTimestampFromString(timestamp); - } + public long GetCreationTime() throws InvalidProtocolBufferException { + try { + VoterRegistry.VoterRegistryMessage wrapper = VoterRegistry.VoterRegistryMessage.parseFrom(base.getData()); + return wrapper.getCreationMiliseconds(); + } catch (InvalidProtocolBufferException e) { + throw e; } - return null; - } } diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index 80d7500..69c3dc2 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -76,6 +76,7 @@ public class SimpleRegistryTest extends TestCase { @Override public void handleFailure(Throwable t){ + System.out.println(t); messages = null; jobSemaphore.release(); } @@ -88,7 +89,7 @@ public class SimpleRegistryTest extends TestCase { private void CommunicatorSetup() { bulletinBoardClient = new ThreadedBulletinBoardClient(); - String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:8081"; + String BULLETIN_BOARD_SERVER_ADDRESS = "http://localhost:8081/"; bulletinBoardClient.init(Voting.BulletinBoardClientParams.newBuilder() .addBulletinBoardAddress(BULLETIN_BOARD_SERVER_ADDRESS) .setMinRedundancy((float) 1.0) @@ -169,8 +170,7 @@ public class SimpleRegistryTest extends TestCase { String id = new BigInteger(130, random).toString(32); String data = new BigInteger(130, random).toString(32); - VoterInfo voterInfo = VoterInfo.newBuilder(). - setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); + VoterInfo voterInfo = VoterInfo.newBuilder().setId(VoterID.newBuilder().setId(id)).setInfo(data).build(); SimpleRegistry registry = new SimpleRegistry(signer, bulletinBoardClient, certStream); registry.AddVoter(voterInfo, handler); @@ -301,11 +301,10 @@ public class SimpleRegistryTest extends TestCase { DummyRegistryCallBackHandler personalHandler = new DummyRegistryCallBackHandler<>(); registry.GetPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler); - jobSemaphore.acquire(1); assertEquals(RegistryTags.ID_TAG + id, personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.ID_TAG)); - assertEquals(data,personalHandler.data.base.getData().toStringUtf8()); + assertTrue(personalHandler.data.GetWantedTagFromBasicMessage(RegistryTags.VOTER_DATA_TAG).contains(data)); } }