Commit 0cb312d6 authored by Lily Tsai's avatar Lily Tsai

create topics with eid instead of ss

parent d0647cf8
...@@ -13,6 +13,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; ...@@ -13,6 +13,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.mpisws.embeddedsocial.ESClient; import org.mpisws.embeddedsocial.ESClient;
import org.mpisws.embeddedsocial.ESMessage; import org.mpisws.embeddedsocial.ESMessage;
import org.mpisws.helpers.Coder;
import org.mpisws.helpers.Identifier; import org.mpisws.helpers.Identifier;
import org.mpisws.messaging.EpochLinkMessage; import org.mpisws.messaging.EpochLinkMessage;
...@@ -93,22 +94,25 @@ public class SimulationServerBT { ...@@ -93,22 +94,25 @@ public class SimulationServerBT {
}).start(); }).start();
} }
private void processData() { private void processData() {
Looper.prepare();
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++) {
topicsToCreate.add(new ImmutablePair<>(nonces.get(i), pubKeys.get(i))); topicsToCreate.add(new ImmutablePair<>(nonces.get(i), pubKeys.get(i)));
} }
for (Identifier ss : sharedSecrets) { for (Identifier ss : sharedSecrets) {
topicsToCreate.add(new ImmutablePair<>(ss, ss)); topicsToCreate.add(new ImmutablePair<>(Coder.convertSharedSecretToID(ss), Coder.convertSharedSecretToID(ss)));
} }
Log.d(TAG, "creating nonce and shared secret topics: " + topicsToCreate.size()); Log.d(TAG, "Creating nonce and shared secret topics: " + topicsToCreate.size());
ESClient.getInstance().createTopics(topicsToCreate); ESClient.getInstance().createTopics(topicsToCreate);
// 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
Looper.prepare();
for (int loop = 1; loop <= NUM_SIMULATED_EPOCHS; loop++) { for (int loop = 1; loop <= NUM_SIMULATED_EPOCHS; loop++) {
new Handler().postDelayed(() -> { Log.d(TAG, "Handler loop " + loop);
handler.postDelayed(() -> {
Log.d(TAG, "Handler loop!");
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<String> topicHandles = ESClient.getInstance().getTopicHandles(sses);
...@@ -126,7 +130,7 @@ public class SimulationServerBT { ...@@ -126,7 +130,7 @@ public class SimulationServerBT {
.addNewNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + newIndex).toString()) .addNewNonce(nonces.get((lowEpoch * NUM_SIMULATED_DEVICES) + newIndex).toString())
.build(); .build();
msgsToSend.add(new ESMessage(epochLinkMessage.toSendMessageText(sses.get(oldIndex).getBytes()), msgsToSend.add(new ESMessage(epochLinkMessage.toSendMessageText(sses.get(oldIndex).getBytes()),
new Identifier(SHA1(sharedSecrets.get(i).getBytes())).toString(), Coder.convertSharedSecretToID(sharedSecrets.get(i)).toString(),
topicHandles.get(oldIndex), topicHandles.get(oldIndex),
true, null, true, -1)); true, null, true, -1));
} }
......
...@@ -115,6 +115,7 @@ public class SimulatorScannerProcessor { ...@@ -115,6 +115,7 @@ public class SimulatorScannerProcessor {
*/ */
private class SDDRScanCallback extends ScanCallback { private class SDDRScanCallback extends ScanCallback {
private void simulateReceivingResults() { private void simulateReceivingResults() {
Log.d(TAG, "CURRENT EPOCH: " + CURRENT_EPOCH);
// get all "new" nonces you should've "received" // get all "new" nonces you should've "received"
for (int i = 0; i < NUM_SIMULATED_DEVICES; i++) { for (int i = 0; i < NUM_SIMULATED_DEVICES; i++) {
// for each new nonce, call processScanResult // for each new nonce, call processScanResult
...@@ -138,7 +139,7 @@ public class SimulatorScannerProcessor { ...@@ -138,7 +139,7 @@ public class SimulatorScannerProcessor {
@Override @Override
public void onScanResult(int callbackType, ScanResult result) { public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result); super.onScanResult(callbackType, result);
Log.v(TAG, "some scan result"); Log.v(TAG, "Some scan result");
SDDR_Native.c_preDiscovery(); SDDR_Native.c_preDiscovery();
simulateReceivingResults(); simulateReceivingResults();
SDDR_Native.c_postDiscovery(); SDDR_Native.c_postDiscovery();
......
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