m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/modules')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java9
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java10
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java6
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java51
4 files changed, 54 insertions, 22 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
index 5199e82..a952274 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java
@@ -26,6 +26,7 @@ import pl.edu.mimuw.cloudatlas.model.ValueContact;
import pl.edu.mimuw.cloudatlas.model.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueTime;
import pl.edu.mimuw.cloudatlas.model.ZMI;
+import pl.edu.mimuw.cloudatlas.querysigner.QuerySignerApiImplementation;
public class GossipGirl extends Module {
private long nextGossipId = 0;
@@ -200,11 +201,9 @@ public class GossipGirl extends Module {
System.out.println("INFO: handling Query in " + Long.toString(message.getReceiverGossipId()));
state.setLastAction();
state.gotQuery(message);
- Map<Attribute, Entry<ValueQuery, ValueTime>> queries = new HashMap();
- queries.put(
- message.getName(),
- new SimpleImmutableEntry(message.getQuery(), state.getTheirQueryTimestamp(message.getName()))
- );
+ Map<Attribute, ValueQuery> queries = new HashMap();
+ ValueQuery vq = message.getQuery();
+ queries.put(message.getName(), vq);
UpdateQueriesMessage updateMessage = new UpdateQueriesMessage("", 0, queries);
System.out.println("INFO: GossipGirl sending UpdateQueriesMessage");
sendMessage(updateMessage);
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
index cfaf560..4709eb1 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirlState.java
@@ -47,7 +47,7 @@ public class GossipGirlState {
public long timeOffest;
public State state;
public ZMI hierarchy;
- public Map<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ public Map<Attribute, ValueQuery> queries;
public ValueTime hejkaSendTimestamp;
public ValueTime hejkaReceiveTimestamp;
public ValueTime noCoTamSendTimestamp;
@@ -79,7 +79,7 @@ public class GossipGirlState {
lastAction = ValueUtils.currentTime();
}
- public void setState(ZMI hierarchy, Map<Attribute, Entry<ValueQuery, ValueTime>> queries) {
+ public void setState(ZMI hierarchy, Map<Attribute, ValueQuery> queries) {
switch (state) {
case WAIT_FOR_STATE_INITIALIZER:
this.hierarchy = hierarchy;
@@ -211,8 +211,8 @@ public class GossipGirlState {
public Map<Attribute, ValueTime> getQueryTimestampsToSend() {
Map<Attribute, ValueTime> queryTimestamps= new HashMap();
- for (Entry<Attribute, Entry<ValueQuery, ValueTime>> query : queries.entrySet()) {
- queryTimestamps.put(query.getKey(), query.getValue().getValue());
+ for (Entry<Attribute, ValueQuery> query : queries.entrySet()) {
+ queryTimestamps.put(query.getKey(), new ValueTime(query.getValue().getTimestamp()));
}
return queryTimestamps;
@@ -259,7 +259,7 @@ public class GossipGirlState {
queryList.add(
new SimpleImmutableEntry(
name,
- queries.get(name).getKey()
+ queries.get(name)
)
);
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java
index 2119653..c94a87d 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java
@@ -59,8 +59,8 @@ public class Qurnik extends Module {
private void runQueriesOnState(StateMessage message) throws InterruptedException {
List<ValueQuery> queries = new LinkedList();
- for (Entry<ValueQuery, ValueTime> timestampedQuery : message.getQueries().values()) {
- queries.add(timestampedQuery.getKey());
+ for (ValueQuery timestampedQuery : message.getQueries().values()) {
+ queries.add(timestampedQuery);
}
executeAllQueries(message.getZMI(), queries, PathName.ROOT);
}
@@ -80,7 +80,7 @@ public class Qurnik extends Module {
Interpreter interpreter = new Interpreter(zmi);
AttributesMap newAttributes = new AttributesMap();
for (ValueQuery query : queries) {
- if (query != null) {
+ if (query != null && query.isInstalled()) {
try {
List<QueryResult> result = interpreter.interpretProgram(query.getQuery());
for(QueryResult r : result) {
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
index 6e7d4dc..efc5605 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Stanik.java
@@ -1,12 +1,21 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
import java.nio.file.Path;
+import java.rmi.RemoteException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
import java.util.*;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;
import pl.edu.mimuw.cloudatlas.agent.messages.*;
import pl.edu.mimuw.cloudatlas.model.*;
+import pl.edu.mimuw.cloudatlas.querysigner.*;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
public class Stanik extends Module {
private class InvalidUpdateAttributesMessage extends Exception {
@@ -16,21 +25,24 @@ public class Stanik extends Module {
}
private ZMI hierarchy;
- private HashMap<Attribute, Entry<ValueQuery, ValueTime>> queries;
+ private HashMap<Attribute, ValueQuery> queries;
private long freshnessPeriod;
private Set<ValueContact> contacts;
private ValueTime contactsTimestamp;
private PathName ourPath;
+ private PublicKey publicKey;
public Stanik(PathName ourPath, long freshnessPeriod) {
super(ModuleType.STATE);
this.ourPath = ourPath;
hierarchy = new ZMI();
- queries = new HashMap<Attribute, Entry<ValueQuery, ValueTime>>();
+ queries = new HashMap<Attribute, ValueQuery>();
hierarchy.getAttributes().add("timestamp", new ValueTime(0l));
this.freshnessPeriod = freshnessPeriod;
this.contactsTimestamp = ValueUtils.currentTime();
this.contacts = new HashSet<>();
+ String publicKeyFile = System.getProperty("public_key_file");
+ this.publicKey = KeyUtils.getPublicKey(publicKeyFile);
setDefaultQueries();
}
@@ -45,7 +57,7 @@ public class Stanik extends Module {
private void setDefaultQuery(String name, String query) {
try {
ValueQuery queryValue = new ValueQuery(query);
- queries.put(new Attribute(name), new SimpleImmutableEntry(queryValue, new ValueTime(0l)));
+ queries.put(new Attribute(name), queryValue);
} catch (Exception e) {
System.out.println("ERROR: failed to compile default query");
}
@@ -89,7 +101,7 @@ public class Stanik extends Module {
0,
message.getRequestId(),
hierarchy.clone(),
- (HashMap<Attribute, Entry<ValueQuery, ValueTime>>) queries.clone(),
+ (HashMap<Attribute, ValueQuery>) queries.clone(),
contacts
);
sendMessage(response);
@@ -210,11 +222,32 @@ public class Stanik extends Module {
}
public void handleUpdateQueries(UpdateQueriesMessage message) {
- for (Entry<Attribute, Entry<ValueQuery, ValueTime>> entry : message.getQueries().entrySet()) {
+ System.out.println("INFO: Stanik handles update queries");
+ for (Entry<Attribute, ValueQuery> entry : message.getQueries().entrySet()) {
Attribute attribute = entry.getKey();
- ValueTime timestamp = entry.getValue().getValue();
- Entry<ValueQuery, ValueTime> currentTimestampedQuery = queries.get(attribute);
- if (currentTimestampedQuery == null || ValueUtils.valueLower(currentTimestampedQuery.getValue(), timestamp)) {
+ ValueQuery query = entry.getValue();
+ try {
+ if (query.isInstalled()) {
+ QuerySignerApiImplementation.validateInstallQuery(
+ attribute.getName(),
+ QueryUtils.constructQueryData(query),
+ this.publicKey);
+
+ } else {
+ QuerySignerApiImplementation.validateUninstallQuery(
+ attribute.getName(),
+ QueryUtils.constructQueryData(query),
+ this.publicKey);
+ }
+ } catch (RemoteException | IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchAlgorithmException | NoSuchPaddingException | QuerySigner.InvalidQueryException e) {
+ System.out.println("ERROR: Query " + attribute.getName() + " was not updated in Stanik with error message " + e.getMessage());
+ e.printStackTrace();
+ continue;
+ }
+ ValueTime timestamp = new ValueTime(entry.getValue().getTimestamp());
+ ValueQuery currentTimestampedQuery = queries.get(attribute);
+ if (currentTimestampedQuery == null ||
+ ValueUtils.valueLower(new ValueTime(currentTimestampedQuery.getTimestamp()), timestamp)) {
queries.put(entry.getKey(), entry.getValue());
}
}
@@ -273,7 +306,7 @@ public class Stanik extends Module {
return hierarchy;
}
- public HashMap<Attribute, Entry<ValueQuery, ValueTime>> getQueries() {
+ public HashMap<Attribute, ValueQuery> getQueries() {
return queries;
}