m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/GossipGirl.java2
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/agent/modules/Qurnik.java3
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java11
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java9
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java22
5 files changed, 37 insertions, 10 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 b6087e6..5137e0b 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
@@ -202,8 +202,6 @@ public class GossipGirl extends Module {
state.gotQuery(message);
Map<Attribute, ValueQuery> queries = new HashMap();
ValueQuery vq = message.getQuery();
- ValueTime timestamp = state.getTheirQueryTimestamp(message.getName());
- vq.setTimestamp(timestamp.getValue());
queries.put(message.getName(), vq);
UpdateQueriesMessage updateMessage = new UpdateQueriesMessage("", 0, queries);
System.out.println("INFO: GossipGirl sending UpdateQueriesMessage");
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 9a544d9..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
@@ -66,7 +66,6 @@ public class Qurnik extends Module {
}
private void executeAllQueries(ZMI zmi, List<ValueQuery> queries, PathName currentPath) throws InterruptedException {
- System.out.println("INFO: Qurnik executing all queries " + queries);
if(!zmi.getSons().isEmpty()) {
for(ZMI son : zmi.getSons()) {
Value sonName = son.getAttributes().getOrNull("name");
@@ -81,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/model/ValueQuery.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
index f049603..95f826a 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ValueQuery.java
@@ -20,6 +20,8 @@ public class ValueQuery extends Value {
private byte[] signature;
// Query signing timestamp
private long timestamp;
+ // Query installation status
+ private boolean installed;
/**
* Constructs a new <code>ValueQuery</code> object.
@@ -34,6 +36,7 @@ public class ValueQuery extends Value {
}
this.signature = null;
this.timestamp = System.currentTimeMillis();
+ this.installed = true;
}
public ValueQuery(String query, byte[] querySignature) throws Exception {
@@ -44,6 +47,7 @@ public class ValueQuery extends Value {
}
this.signature = querySignature;
this.timestamp = System.currentTimeMillis();
+ this.installed = true;
}
public ValueQuery(QueryData queryData) throws Exception {
@@ -54,6 +58,7 @@ public class ValueQuery extends Value {
}
this.signature = queryData.getSignature();
this.timestamp = System.currentTimeMillis();
+ this.installed = queryData.isInstalled();
}
public ValueQuery(String query, long timestamp) throws Exception {
@@ -64,6 +69,7 @@ public class ValueQuery extends Value {
}
this.signature = null;
this.timestamp = timestamp;
+ this.installed = true;
}
private ValueQuery() {
@@ -71,6 +77,7 @@ public class ValueQuery extends Value {
this.query = null;
this.signature = null;
this.timestamp = System.currentTimeMillis();
+ this.installed = true;
}
public String getCode() { return code; }
@@ -85,6 +92,10 @@ public class ValueQuery extends Value {
public void setTimestamp(long timestamp) { this.timestamp = timestamp; }
+ public boolean isInstalled() { return installed; }
+
+ public void setInstalled(boolean installed) { this.installed = installed; }
+
@Override
public Type getType() {
return TypePrimitive.QUERY;
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
index 7801a28..87b965c 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QueryData.java
@@ -10,10 +10,13 @@ public class QueryData implements Serializable {
// Query signing timestamp
private long timestamp;
+ private boolean installed;
+
public QueryData(String code, byte[] signature) {
this.code = code;
this.signature = signature;
- this.timestamp = System.currentTimeMillis();;
+ this.timestamp = System.currentTimeMillis();
+ this.installed = true;
}
public String getCode() {
@@ -27,4 +30,8 @@ public class QueryData implements Serializable {
public long getTimestamp() {
return timestamp;
}
+
+ public boolean isInstalled() { return installed; }
+
+ public void setInstalled(boolean installed) { this.installed = installed; }
}
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
index 3ab2931..a6233d3 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/querysigner/QuerySignerApiImplementation.java
@@ -1,7 +1,6 @@
package pl.edu.mimuw.cloudatlas.querysigner;
import pl.edu.mimuw.cloudatlas.ByteSerializer;
-import pl.edu.mimuw.cloudatlas.model.ValueQuery;
import pl.edu.mimuw.cloudatlas.querysignerapi.QuerySignerApi;
import javax.crypto.BadPaddingException;
@@ -20,7 +19,7 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
private final static String DIGEST_ALGORITHM = "SHA-256";
private PublicKey publicKey;
private PrivateKey privateKey;
- private Map<String, ValueQuery> queries;
+ private Map<String, QueryData> queries;
private Set<String> attribsSetByQueries;
public QuerySignerApiImplementation(PublicKey publicKey, PrivateKey privateKey) {
@@ -90,7 +89,10 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
byte[] serializedQuery = serializeQuery(queryName, queryCode, install);
byte[] hashedQuery = cryptographicHash(serializedQuery);
byte[] querySignature = encryptQuery(hashedQuery);
- return new QueryData(queryCode, querySignature);
+ QueryData newQuery = new QueryData(queryCode, querySignature);
+ newQuery.setInstalled(install);
+ this.queries.put(queryName, newQuery);
+ return newQuery;
} catch (Exception e) {
e.printStackTrace();
throw new RemoteException(e.getLocalizedMessage());
@@ -99,7 +101,12 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
@Override
public QueryData signInstallQuery(String queryName, String queryCode) throws RemoteException {
- return signQuery(queryName, queryCode, true);
+ QueryUtils.validateQueryName(queryName);
+ if (this.queries.containsKey(queryName) && this.queries.get(queryName).isInstalled()) {
+ throw new RemoteException("Query already installed");
+ } else {
+ return signQuery(queryName, queryCode, true);
+ }
}
public static void validateInstallQuery(String queryName, QueryData query, PublicKey publicKey) throws RemoteException,IllegalBlockSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, QuerySigner.InvalidQueryException {
@@ -120,7 +127,12 @@ public class QuerySignerApiImplementation implements QuerySignerApi {
@Override
public QueryData signUninstallQuery(String queryName) throws RemoteException {
- return signQuery(queryName, "", false);
+ QueryUtils.validateQueryName(queryName);
+ if (this.queries.containsKey(queryName) && this.queries.get(queryName).isInstalled()) {
+ return signQuery(queryName, "", false);
+ } else {
+ throw new RemoteException("Query is not installed");
+ }
}
public static void validateUninstallQuery(String queryName, QueryData query, PublicKey publicKey) throws RemoteException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, QuerySigner.InvalidQueryException, NoSuchPaddingException, InvalidKeyException {