diff --git a/voter-registry/src/main/java/meerkat/AsyncRegistry.java b/voter-registry/src/main/java/meerkat/AsyncRegistry.java index 3dad76d..5af7534 100644 --- a/voter-registry/src/main/java/meerkat/AsyncRegistry.java +++ b/voter-registry/src/main/java/meerkat/AsyncRegistry.java @@ -1,7 +1,6 @@ package meerkat; import com.google.common.util.concurrent.FutureCallback; -import com.google.protobuf.ByteString; import meerkat.bulletinboard.AsyncBulletinBoardClient; import meerkat.crypto.DigitalSignature; import meerkat.protobuf.BulletinBoardAPI.UnsignedBulletinBoardMessage; @@ -15,9 +14,7 @@ import meerkat.registry.MessageCollectionUtils; import meerkat.registry.RegistryTags; import meerkat.util.BulletinBoardUtils; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.ObjectOutputStream; import java.security.SignatureException; import java.util.ArrayList; import java.util.Collection; @@ -59,15 +56,11 @@ public class AsyncRegistry implements VoterRegistry{ @Override public void setVoterGroups(VoterRegistryMessage voterRegistryMessage, FutureCallback callback) throws SignatureException, IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(voterRegistryMessage.getGroupIDList()); - UnsignedBulletinBoardMessage.Builder basicMessage = UnsignedBulletinBoardMessage.newBuilder() .addTag(RegistryTags.ID_TAG + voterRegistryMessage.getVoterID().getId()) .addTag(RegistryTags.ADD_TO_GROUP_TAG) - .setData(ByteString.copyFrom(bos.toByteArray())) + .setData(voterRegistryMessage.toByteString()) .setTimestamp(BulletinBoardUtils.getCurrentTimestampProto()); bulletinBoardClient.postMessage(signBulletinBoardMessage(basicMessage.build(), signers), callback); diff --git a/voter-registry/src/main/java/meerkat/registry/AsyncRegistryCallbacks/GetGroupsCallback.java b/voter-registry/src/main/java/meerkat/registry/AsyncRegistryCallbacks/GetGroupsCallback.java index 1547d3e..8012fb1 100644 --- a/voter-registry/src/main/java/meerkat/registry/AsyncRegistryCallbacks/GetGroupsCallback.java +++ b/voter-registry/src/main/java/meerkat/registry/AsyncRegistryCallbacks/GetGroupsCallback.java @@ -5,9 +5,7 @@ import javassist.NotFoundException; import meerkat.protobuf.BulletinBoardAPI.BulletinBoardMessage; import meerkat.protobuf.VoterRegistry; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.ObjectInputStream; import java.util.List; import static meerkat.util.BulletinBoardUtils.getLatestMessage; @@ -33,8 +31,10 @@ public class GetGroupsCallback implements FutureCallback getVoterGroups(BulletinBoardMessage message) throws IOException, ClassNotFoundException { - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(message.getMsg().getData().toByteArray())); - return (List)ois.readObject(); + VoterRegistry.VoterRegistryMessage voterRegistryMessage = + VoterRegistry.VoterRegistryMessage.parseFrom(message.getMsg().getData()); + + return voterRegistryMessage.getGroupIDList(); } diff --git a/voter-registry/src/test/java/SimpleRegistryTest.java b/voter-registry/src/test/java/SimpleRegistryTest.java index c239810..657a983 100644 --- a/voter-registry/src/test/java/SimpleRegistryTest.java +++ b/voter-registry/src/test/java/SimpleRegistryTest.java @@ -16,10 +16,8 @@ import meerkat.registry.RegistryTags; import org.junit.Before; import org.junit.Test; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; import java.math.BigInteger; import java.security.KeyStore; import java.security.SecureRandom; @@ -288,8 +286,10 @@ public class SimpleRegistryTest { assert findTagWithPrefix(latestMessage, RegistryTags.ID_TAG).equals(voterId) : "The latest message recieved is not of our voter"; - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(latestMessage.getMsg().getData().toByteArray())); - List groupsIds = (List)ois.readObject(); + VoterRegistry.VoterRegistryMessage voterRegistryMessage = + VoterRegistry.VoterRegistryMessage.parseFrom(latestMessage.getMsg().getData()); + + List groupsIds = voterRegistryMessage.getGroupIDList(); assert groupsIds.get(0).getId().equals(groupId1) : "The latest message doesn't have the voter group"; }