diff --git a/build.gradle b/build.gradle index 2791de4..9f070e3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,4 @@ - subprojects { proj -> proj.afterEvaluate { // Used to generate initial maven-dir layout diff --git a/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardClient.java b/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardClient.java index aa61726..9cf6dd4 100644 --- a/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardClient.java +++ b/bulletin-board-client/src/main/java/meerkat/bulletinboard/SimpleBulletinBoardClient.java @@ -102,7 +102,7 @@ public class SimpleBulletinBoardClient implements BulletinBoardClient { .build()) .build(); - int count = 0; + float count = 0; for (String db : meerkatDBs) { try { @@ -117,7 +117,7 @@ public class SimpleBulletinBoardClient implements BulletinBoardClient { } catch (Exception e) {} } - return count; + return count / ((float) meerkatDBs.size()); } /** diff --git a/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java b/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java new file mode 100644 index 0000000..f9699c1 --- /dev/null +++ b/bulletin-board-client/src/test/java/BulletinBoardClientIntegrationTest.java @@ -0,0 +1,109 @@ +import com.google.protobuf.ByteString; +import meerkat.bulletinboard.BulletinBoardClient; +import meerkat.bulletinboard.SimpleBulletinBoardClient; +import meerkat.comm.CommunicationException; +import meerkat.protobuf.BulletinBoardAPI.*; +import meerkat.protobuf.Crypto; + +import meerkat.util.BulletinBoardMessageComparator; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; + +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; + +/** + * Created by Arbel Deutsch Peled on 05-Dec-15. + */ +public class BulletinBoardClientIntegrationTest { + + private BulletinBoardClient bulletinBoardClient; + + private static String PROP_GETTY_URL = "gretty.httpBaseURI"; + private static String DEFAULT_BASE_URL = "http://localhost:8081"; + private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL); + + @Before + public void init(){ + + bulletinBoardClient = new SimpleBulletinBoardClient(); + + List testDB = new LinkedList(); + testDB.add(BASE_URL); + + bulletinBoardClient.init(testDB); + + } + + @Test + public void postTest(){ + + byte[] b1 = {(byte) 1, (byte) 2, (byte) 3, (byte) 4}; + byte[] b2 = {(byte) 11, (byte) 12, (byte) 13, (byte) 14}; + byte[] b3 = {(byte) 21, (byte) 22, (byte) 23, (byte) 24}; + byte[] b4 = {(byte) 4, (byte) 5, (byte) 100, (byte) -50, (byte) 0}; + + BulletinBoardMessage msg; + + MessageFilterList filterList; + List msgList; + + MessageID messageID; + + Comparator msgComparator = new BulletinBoardMessageComparator(); + + msg = BulletinBoardMessage.newBuilder() + .setMsg(UnsignedBulletinBoardMessage.newBuilder() + .addTag("Signature") + .addTag("Trustee") + .setData(ByteString.copyFrom(b1)) + .build()) + .addSig(Crypto.Signature.newBuilder() + .setType(Crypto.SignatureType.DSA) + .setData(ByteString.copyFrom(b2)) + .setSignerId(ByteString.copyFrom(b3)) + .build()) + .addSig(Crypto.Signature.newBuilder() + .setType(Crypto.SignatureType.ECDSA) + .setData(ByteString.copyFrom(b3)) + .setSignerId(ByteString.copyFrom(b2)) + .build()) + .build(); + + try { + messageID = bulletinBoardClient.postMessage(msg); + } catch (CommunicationException e) { + System.err.println("Error posting to BB Server: " + e.getMessage()); + assert false; + return; + } + + assertThat(bulletinBoardClient.getRedundancy(messageID), is((float) 1.00)); + + filterList = MessageFilterList.newBuilder() + .addFilter( + MessageFilter.newBuilder() + .setType(FilterType.TAG) + .setTag("Signature") + .build() + ) +// .addFilter( +// MessageFilter.newBuilder() +// .setType(FilterType.TAG) +// .setTag("Trustee") +// .build() +// ) + .build(); + + msgList = bulletinBoardClient.readMessages(filterList); + + assertThat(msgList.size(), is(1)); + + assertThat(msgComparator.compare(msgList.iterator().next(), msg), is(0)); + + } + +} diff --git a/bulletin-board-server/build.gradle b/bulletin-board-server/build.gradle index 790f0d3..593dfbc 100644 --- a/bulletin-board-server/build.gradle +++ b/bulletin-board-server/build.gradle @@ -2,9 +2,10 @@ plugins { id "us.kirchmeier.capsule" version "1.0.1" id 'com.google.protobuf' version '0.7.0' - id "org.akhikhl.gretty" version "1.2.4" + id 'org.akhikhl.gretty' version "1.2.4" } +apply plugin: 'org.akhikhl.gretty' apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' @@ -45,7 +46,9 @@ dependencies { // Jersey for RESTful API compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.22.+' compile 'org.xerial:sqlite-jdbc:3.7.+' - + + // Servlets + compile 'javax.servlet:javax.servlet-api:3.0.+' // Logging compile 'org.slf4j:slf4j-api:1.7.7' @@ -68,13 +71,11 @@ test { exclude '**/*IntegrationTest*' } -task debugIntegrationTest(type: Test){ - include '**/*IntegrationTest*' - debug = true -} - task integrationTest(type: Test) { include '**/*IntegrationTest*' +// debug = true + outputs.upToDateWhen { false } + } gretty { @@ -82,6 +83,7 @@ gretty { contextPath = '/' integrationTestTask = 'integrationTest' loggingLevel = 'TRACE' + debugPort = 5006 } diff --git a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java index d4aa881..bfbbc1a 100644 --- a/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java +++ b/bulletin-board-server/src/main/java/meerkat/bulletinboard/sqlserver/SQLiteBulletinBoardServer.java @@ -167,7 +167,7 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer { sqlSuffix += " LIMIT = ?"; break; case FilterType.MSG_ID_VALUE: - sql += " MsgTableMsgId = ?"; + sql += " MsgTable.MsgId = ?"; break; case FilterType.SIGNER_ID_VALUE: sql += " SignatureTable.SignerId = ?"; diff --git a/meerkat-common/src/main/java/meerkat/util/BulletinBoardMessageComparator.java b/meerkat-common/src/main/java/meerkat/util/BulletinBoardMessageComparator.java new file mode 100644 index 0000000..77a6663 --- /dev/null +++ b/meerkat-common/src/main/java/meerkat/util/BulletinBoardMessageComparator.java @@ -0,0 +1,49 @@ +package meerkat.util; + +import meerkat.protobuf.BulletinBoardAPI; +import meerkat.protobuf.BulletinBoardAPI.*; +import meerkat.protobuf.Crypto.*; + +import java.util.Comparator; +import java.util.List; + +/** + * Created by Arbel Deutsch Peled on 05-Dec-15. + * This class implements a comparison between BulletinBoardMessage instances that disregards: + * 1. The entry number (since this can be different between database instances) + * 2. The order of the signatures + */ +public class BulletinBoardMessageComparator implements Comparator { + + /** + * Compare the messages + * @param msg1 + * @param msg2 + * @return 0 if the messages are equivalent (see above) and -1 otherwise. + */ + @Override + public int compare(BulletinBoardMessage msg1, BulletinBoardMessage msg2) { + + List msg1Sigs = msg1.getSigList(); + List msg2Sigs = msg2.getSigList(); + + // Compare unsigned message + if (!msg1.getMsg().equals(msg2.getMsg())){ + return -1; + } + + // Compare signatures + + if (msg1Sigs.size() != msg2Sigs.size()){ + return -1; + } + + for (Signature sig : msg1Sigs){ + if (!msg2Sigs.contains(sig)) { + return -1; + } + } + + return 0; + } +}