diff --git a/ebc_enclave_messaging b/ebc_enclave_messaging index 9d89587c13406c3fd4a52ac1f6b3067ccc3405c8..eb462f82708dc82b5c57333b5d5d608a9bc15bc5 160000 --- a/ebc_enclave_messaging +++ b/ebc_enclave_messaging @@ -1 +1 @@ -Subproject commit 9d89587c13406c3fd4a52ac1f6b3067ccc3405c8 +Subproject commit eb462f82708dc82b5c57333b5d5d608a9bc15bc5 diff --git a/ebclibrary/src/main/java/org/mpisws/encounters/EncounterBasedCommunication.java b/ebclibrary/src/main/java/org/mpisws/encounters/EncounterBasedCommunication.java index 8b3257050a201d525a82b03ca67abc224cf1f262..92a8d10d61f8a0688261729c322ff9a6399fbf02 100644 --- a/ebclibrary/src/main/java/org/mpisws/encounters/EncounterBasedCommunication.java +++ b/ebclibrary/src/main/java/org/mpisws/encounters/EncounterBasedCommunication.java @@ -43,7 +43,7 @@ import java.util.List; * **/ public class EncounterBasedCommunication { - public static final long CHANGE_EPOCH_TIME = 15*60000; + public static final long CHANGE_EPOCH_TIME = 2*60000; public static final long SCAN_BATCH_INTERVAL = (long) (2*60000); public static final int REQUEST_ENABLE_BT = 1; public static final int REQUEST_ACCESS_FINE_LOCATION = 2; diff --git a/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java b/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java index a14bce4911a8e5e88a34fd0aaf20e71a78a3f072..522c344f139d654d52c35c06886452bcdcc8e3c9 100644 --- a/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java +++ b/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java @@ -185,7 +185,7 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge getConfirmedEntriesAfterTime(long timestamp) { - final String[] selectionArgs = new String[] { String.valueOf(timestamp), String.valueOf(timestamp) }; + final String[] selectionArgs = new String[] { String.valueOf(timestamp) }; String whereClause = "(" + PEncounterEntries.Columns.timestampEnd + " > ? OR " + PEncounterEntries.Columns.timestampEnd + " = -1)" + " AND " + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL"; diff --git a/ebcutils/src/main/java/org/mpisws/embeddedsocial/ESClient.java b/ebcutils/src/main/java/org/mpisws/embeddedsocial/ESClient.java index 52c27daa04517bff7338d7249be6182f8323ceeb..5f058ba291ea174173139483883d427b0680be2b 100644 --- a/ebcutils/src/main/java/org/mpisws/embeddedsocial/ESClient.java +++ b/ebcutils/src/main/java/org/mpisws/embeddedsocial/ESClient.java @@ -527,6 +527,7 @@ public class ESClient { // set the cursor to continue continuationCursor = r.getBody().getCursor(); for (CommentView comment : r.getBody().getData()) { + System.out.println("Comments: Got message! " + comment.getText()); msgs.add(new ESMessage(comment.getText(), "", comment.getTopicHandle(), esuser_client.isMe(comment.getUser().getUserHandle()), comment.getCommentHandle(), true, comment.getCreatedTime().getMillis())); diff --git a/ebcutils/src/main/java/org/mpisws/embeddedsocial/TestBatchClient.java b/ebcutils/src/main/java/org/mpisws/embeddedsocial/TestBatchClient.java index 3466d1e65923ec0cc5f098c0132cf6d6442cbb9f..bb1fee7dc4a8832b052f65139a090453ce202c9e 100644 --- a/ebcutils/src/main/java/org/mpisws/embeddedsocial/TestBatchClient.java +++ b/ebcutils/src/main/java/org/mpisws/embeddedsocial/TestBatchClient.java @@ -9,6 +9,7 @@ import org.mpisws.embeddedsocial.batchactions.DeleteTopicAction; import org.mpisws.embeddedsocial.batchactions.FindUniqueTopicAction; import org.mpisws.embeddedsocial.batchactions.GetBuildAction; import org.mpisws.embeddedsocial.batchactions.SubscribeTopicAction; +import org.mpisws.helpers.Coder; import org.mpisws.helpers.Identifier; import java.io.IOException; @@ -22,219 +23,30 @@ import okhttp3.Response; import static java.lang.System.exit; import static org.mpisws.embeddedsocial.ESClient.baseURL; +import static org.mpisws.helpers.Utils.hexStringToByteArray; /** * Created by tslilyai on 3/24/18. */ public class TestBatchClient { - static final String auth = "SocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNIRVUzNTA4ZVxuR29vZ2xlXG4xMTY4Njc1MTE0MDIxMzc1NzcxNTkiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQxODQ4MTQ0fQ.PTz69j2BuJB0bROiMK-b6zkpL9VOME0fhGjMPjkrkjQ"; + static final String auth = "SocialPlus TK=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIzalNjZHFzN0paYVxuR29vZ2xlXG4xMTAyMDM3NjQyMDI5ODI4NDk3NTYiLCJpc3MiOiIzcWdtZzlWUmNaeFxuMmU1YTFjYzgtNWVhYi00ZGJkLThkNmQtNmE4NGVhYjIzMzc0IiwiZXhwIjoxNTQ3Mzg1NTA0fQ.DhURO4E5-BEFz_dWMdHZHQLq-E_fZf62_si-UlqF3Ko"; + static final String topicHandle = "3gcpdys3KfY"; + static final String ss = "0E31177095EE530101D89573C8261C14F51A3877D4676F74478F5CAF"; public static void main(String[] args) { - int k = 6; - //getBuilds(k); - ESClient.getInstance().setESCredentials("user", auth); ESClient.getInstance().setESAPIKey("2e5a1cc8-5eab-4dbd-8d6d-6a84eab23374"); - List> titles = new ArrayList<>(); - for (int i = 0; i < k; i++) { - titles.add(new ImmutablePair<>(new Identifier(String.valueOf(System.currentTimeMillis()).getBytes()), - new Identifier(String.valueOf(System.currentTimeMillis()).getBytes()))); - } - for (int i = 0; i < 10; i++) { - System.out.println("Running test " + i); - Thread t = new Thread(new FindCreateSubscribeTopicsRunnable(titles)); - t.start(); - try { - t.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - exit(0); - } - - private static class FindCreateSubscribeTopicsRunnable implements Runnable { - private final List foundTopics; - private final List> toCreateTopics; - private final List> titleTextPairs; - protected List topicHandles; - public boolean doneExecuting = false; - - public FindCreateSubscribeTopicsRunnable(List> titleTextPairs) { - this.foundTopics = new ArrayList<>(titleTextPairs.size()); - this.toCreateTopics = new ArrayList<>(titleTextPairs.size()); - for (int i = 0; i < titleTextPairs.size(); i++) { - foundTopics.add(null); - toCreateTopics.add(null); - } - this.titleTextPairs = titleTextPairs; - } - - @Override - public void run() { - Response resp; - ConcurrentLinkedQueue toDeleteTopics = new ConcurrentLinkedQueue<>(); - EmbeddedSocialBatchedClientImpl batchOps; - CountDownLatch latch; - int batchSize = (int) titleTextPairs.stream().filter(s -> s != null).count(); - - /* ------------------------------------BATCH 1: FIND --------------------------------------------------------*/ - if (batchSize > 0) { - batchOps = new EmbeddedSocialBatchedClientImpl.Builder() - .batchSize(batchSize) - .baseUrl(baseURL) - .build(); - latch = new CountDownLatch(batchSize); - // find the topics - for (int i = 0; i < titleTextPairs.size(); i++) { - if (titleTextPairs.get(i) != null) { - Pair titleTextPair = titleTextPairs.get(i); - new FindUniqueTopicAction(batchOps, latch, i, auth, titleTextPair.getLeft(), titleTextPair.getRight(), - toDeleteTopics, toCreateTopics, foundTopics) - .addToBatch(); - } - } - try { - resp = batchOps.issueBatch(); - System.out.println("BATCH 1: Issued find-topics batch of size " + batchSize + " : " + resp.isSuccessful()); - latch.await(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } - } - - /* ------------------------------------BATCH 2: CREATE (and DELETE) --------------------------------------------------------*/ - batchSize = toDeleteTopics.size() + toCreateTopics.size(); - if (batchSize > 0) { - batchOps = new EmbeddedSocialBatchedClientImpl.Builder() - .batchSize(batchSize) - .baseUrl(baseURL) - .build(); - latch = new CountDownLatch(batchSize); - - // (1) delete all repeated topics - for (TopicView tv : toDeleteTopics) { - new DeleteTopicAction(batchOps, latch, auth, tv.getTopicHandle()).addToBatch(); - } - // (2) create all nonexisting topics - for (int i = 0; i < titleTextPairs.size(); i++) { - if (toCreateTopics.get(i) != null) { - new CreateTopicAction(batchOps, latch, i, auth, toCreateTopics.get(i).getLeft(), toCreateTopics.get(i).getRight(), foundTopics) - .addToBatch(); - } - } - try { - resp = batchOps.issueBatch(); - System.out.println("BATCH 2: Create/Delete " + batchSize + " : " + resp.isSuccessful()); - latch.await(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } + new Thread( () -> { + System.out.println("Starting!"); + List messages = ESClient.getInstance().getMessagesOnTopic(topicHandle); + for (ESMessage msg : messages) { + System.out.println(Coder.decrypt(msg.getMsgText(), hexStringToByteArray(ss))); } - - /* ------------------------------------BATCH 3: REFIND IF CREATED TO MAKE SURE NO RACE CONDITION----------------------------------*/ - toDeleteTopics.clear(); - batchSize = 0; - for (Pair topic : toCreateTopics) { - if (topic != null) { - batchSize++; - } - } - if (batchSize > 0) { - batchOps = new EmbeddedSocialBatchedClientImpl.Builder() - .batchSize(batchSize) - .baseUrl(baseURL) - .build(); - latch = new CountDownLatch(batchSize); - - // make sure that only we created the topics - // we shouldn't want to create again so skip that step (if the topic doesn't exist then we failed and we'll try again later) - for (int i = 0; i < titleTextPairs.size(); i++) { - if (toCreateTopics.get(i) != null) { - Pair titleTextPair = titleTextPairs.get(i); - new FindUniqueTopicAction(batchOps, latch, i, auth, titleTextPair.getLeft(), titleTextPair.getRight(), - toDeleteTopics, null, foundTopics) - .addToBatch(); - } - } - try { - resp = batchOps.issueBatch(); - System.out.println("BATCH 3: find-topics " + batchSize + " : " + resp.isSuccessful()); - latch.await(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } - } - - /* ------------------------------------BATCH 4: DELETE EXTRA TOPICS --------------------------------------------------------*/ - batchSize = toDeleteTopics.size(); - if (batchSize > 0) { - batchOps = new EmbeddedSocialBatchedClientImpl.Builder() - .batchSize(batchSize) - .baseUrl(baseURL) - .build(); - latch = new CountDownLatch(batchSize); - - // delete all repeated topics - for (TopicView tv : toDeleteTopics) { - new DeleteTopicAction(batchOps, latch, auth, tv.getTopicHandle()).addToBatch(); - } - try { - resp = batchOps.issueBatch(); - System.out.println("BATCH 4: delete topics " + batchSize + " : " + resp.isSuccessful()); - latch.await(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } - } - - /* ------------------------------------BATCH 5: SUBSCRIBE --------------------------------------------------------*/ - batchSize = 0; - for (int i = 0; i < titleTextPairs.size(); i++) { - if (foundTopics.get(i) != null) - batchSize++; - } - if (batchSize > 0) { - batchOps = new EmbeddedSocialBatchedClientImpl.Builder() - .batchSize(batchSize) - .baseUrl(baseURL) - .build(); - latch = new CountDownLatch(batchSize); - for (int i = 0; i < titleTextPairs.size(); i++) { - if (foundTopics.get(i) != null) { - new SubscribeTopicAction(batchOps, latch, i, auth, foundTopics) - .addToBatch(); - } - } - try { - resp = batchOps.issueBatch(); - System.out.println("BATCH 5: subscribe topics " + batchSize + " : " + resp.isSuccessful()); - latch.await(); - } catch (InterruptedException | IOException e) { - e.printStackTrace(); - } - } - - /* BATCH 6: POST MESSAGES ON BAD TOPIC HANDLES */ - List msgsToPost = new LinkedList<>(); - String badTopicHandle ="3%00j%00e%00E%00a%00_%002%00P%00o%00B%00B%00"; - String badData = "xlMWN0tyZ0kz1KuOlw3NpcaelNgEztsWei0ZCYHEQS+DViAAWEfbX+qPYH+yuonZ"; - for (int i = 0; i < 10; i++) - msgsToPost.add(new ESMessage(badData, badTopicHandle, null, true, null, true, -1)); - ESClient.getInstance().sendMsgs(msgsToPost); - System.out.println("BATCH 6: send bad messages"); - - topicHandles = foundTopics; - synchronized(this) { - doneExecuting = true; - notifyAll(); - } - } + }).start(); } - public static void getBuilds(int k) { org.mpisws.embeddedsocial.EmbeddedSocialBatchedClientImpl batchOps = new EmbeddedSocialBatchedClientImpl.Builder() .batchSize(k) diff --git a/testapp/src/main/java/org/mpisws/testapp/simulator/SimulationClientBT.java b/testapp/src/main/java/org/mpisws/testapp/simulator/SimulationClientBT.java index 5ebf670d06db530adcf044f32ed65af657ad47cb..edd76ceedfdd56ef3fc99a89e1e4b67ac713c2ae 100644 --- a/testapp/src/main/java/org/mpisws/testapp/simulator/SimulationClientBT.java +++ b/testapp/src/main/java/org/mpisws/testapp/simulator/SimulationClientBT.java @@ -29,7 +29,7 @@ import java.util.UUID; */ public class SimulationClientBT { Context context; - protected static final int NUM_SIMULATED_DEVICES = 30; + protected static final int NUM_SIMULATED_DEVICES = 100; protected static final int NUM_SIMULATED_EPOCHS = 10; private static final String TAG = SimulationClientBT.class.getSimpleName();