Commit fa5f3f03 authored by Lily Tsai's avatar Lily Tsai

handler still not working...

parent 0cb312d6
...@@ -94,8 +94,7 @@ public class SimulationServerBT { ...@@ -94,8 +94,7 @@ public class SimulationServerBT {
}).start(); }).start();
} }
private void processData() { private void processData() {
Looper.prepare(); final Handler handler = new Handler(Looper.getMainLooper());
Handler handler = new Handler();
// Create all topics you'll ever have to create // Create all topics you'll ever have to create
List<Pair<Identifier, Identifier>> topicsToCreate = new ArrayList<>(); List<Pair<Identifier, Identifier>> topicsToCreate = new ArrayList<>();
for (int i=0; i < nonces.size(); i++) { for (int i=0; i < nonces.size(); i++) {
...@@ -109,37 +108,43 @@ public class SimulationServerBT { ...@@ -109,37 +108,43 @@ public class SimulationServerBT {
// Every "epoch" or so try to post link messages to the prior "epoch" ss for each "device" // Every "epoch" or so try to post link messages to the prior "epoch" ss for each "device"
// Let's try and post to the prior 3 epochs // Let's try and post to the prior 3 epochs
for (int loop = 1; loop <= NUM_SIMULATED_EPOCHS; loop++) { handler.postDelayed(new Runnable() {
Log.d(TAG, "Handler loop " + loop); public void run() {
handler.postDelayed(() -> { new Thread(() -> {
Log.d(TAG, "Handler loop!"); Log.d(TAG, "Runnable!");
int lowEpoch = currentEpoch > 3 ? currentEpoch - 3 : 0; int lowEpoch = currentEpoch > 3 ? currentEpoch - 3 : 0;
List<Identifier> sses = sharedSecrets.subList(lowEpoch * NUM_SIMULATED_DEVICES, currentEpoch * NUM_SIMULATED_DEVICES); List<Identifier> sses = sharedSecrets.subList(lowEpoch * NUM_SIMULATED_DEVICES, currentEpoch * NUM_SIMULATED_DEVICES);
List<String> topicHandles = ESClient.getInstance().getTopicHandles(sses); List<Identifier> eids = new ArrayList<>();
for (Identifier ss : sses) {
eids.add(Coder.convertSharedSecretToID(ss));
}
List<String> topicHandles = ESClient.getInstance().getTopicHandles(eids);
List<ESMessage> msgsToSend = new ArrayList<>(); List<ESMessage> msgsToSend = new ArrayList<>();
for (int i = 0; i < NUM_SIMULATED_DEVICES; i++) { for (int i = 0; i < NUM_SIMULATED_DEVICES; i++) {
for (int j = currentEpoch + 1; j > lowEpoch + 1; j--) { for (int j = currentEpoch + 1; j > lowEpoch + 1; j--) {
int oldIndex = (j - 1 - lowEpoch) * NUM_SIMULATED_DEVICES + i; int oldIndex = (j - 1 - lowEpoch) * NUM_SIMULATED_DEVICES + i;
int newIndex = (j - lowEpoch) * NUM_SIMULATED_DEVICES + i; int newIndex = (j - lowEpoch) * NUM_SIMULATED_DEVICES + i;
if (topicHandles.get(oldIndex) == null || topicHandles.get(oldIndex).compareTo("") == 0) { if (topicHandles.get(oldIndex) == null || topicHandles.get(oldIndex).compareTo("") == 0) {
continue; continue;
}
EpochLinkMessage epochLinkMessage = new EpochLinkMessage.EpochLinkMessageBuilder()
.addOldNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + oldIndex).toString())
.addNewNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + newIndex).toString())
.build();
msgsToSend.add(new ESMessage(epochLinkMessage.toSendMessageText(sses.get(oldIndex).getBytes()),
eids.get(oldIndex).toString(),
topicHandles.get(oldIndex),
true, null, true, -1));
} }
EpochLinkMessage epochLinkMessage = new EpochLinkMessage.EpochLinkMessageBuilder()
.addOldNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + oldIndex).toString())
.addNewNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + newIndex).toString())
.build();
msgsToSend.add(new ESMessage(epochLinkMessage.toSendMessageText(sses.get(oldIndex).getBytes()),
Coder.convertSharedSecretToID(sharedSecrets.get(i)).toString(),
topicHandles.get(oldIndex),
true, null, true, -1));
} }
} ESClient.getInstance().sendMsgs(msgsToSend);
ESClient.getInstance().sendMsgs(msgsToSend); currentEpoch++;
currentEpoch++; // heh hack
// heh hack if (currentEpoch == NUM_SIMULATED_EPOCHS) currentEpoch--;
if (currentEpoch == NUM_SIMULATED_EPOCHS) currentEpoch--; handler.postDelayed(this, CHANGE_EPOCH_TIME);
}, loop*CHANGE_EPOCH_TIME); }).start();
} }
}, CHANGE_EPOCH_TIME);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment