Removed serialization from the project (we have protobufs!).

Voter-Registry
Vladimir Eliezer Tokarev 2016-03-26 03:53:53 -07:00
parent 8140dcd516
commit b8cc12dfc1
3 changed files with 9 additions and 16 deletions

View File

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

View File

@ -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<List<BulletinBoardMessa
* @throws ClassNotFoundException
*/
private List<VoterRegistry.GroupID> getVoterGroups(BulletinBoardMessage message) throws IOException, ClassNotFoundException {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(message.getMsg().getData().toByteArray()));
return (List<VoterRegistry.GroupID>)ois.readObject();
VoterRegistry.VoterRegistryMessage voterRegistryMessage =
VoterRegistry.VoterRegistryMessage.parseFrom(message.getMsg().getData());
return voterRegistryMessage.getGroupIDList();
}

View File

@ -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<GroupID> groupsIds = (List<GroupID>)ois.readObject();
VoterRegistry.VoterRegistryMessage voterRegistryMessage =
VoterRegistry.VoterRegistryMessage.parseFrom(latestMessage.getMsg().getData());
List<GroupID> groupsIds = voterRegistryMessage.getGroupIDList();
assert groupsIds.get(0).getId().equals(groupId1) : "The latest message doesn't have the voter group";
}