Commit b473db0c authored by Tobias Meuser's avatar Tobias Meuser
Browse files

First working version of privacy-sensitive communication

parent 0a1cfdb4
...@@ -61,4 +61,8 @@ public class PrivacyComponent implements HostComponent { ...@@ -61,4 +61,8 @@ public class PrivacyComponent implements HostComponent {
public PrivacyLevel getPrivacyLevel() { public PrivacyLevel getPrivacyLevel() {
return _privacy; return _privacy;
} }
public void setPrivacyLevel(PrivacyLevel pPrivacy) {
_privacy = pPrivacy;
}
} }
...@@ -35,6 +35,8 @@ public class PrivacyComponentFactory implements HostComponentFactory { ...@@ -35,6 +35,8 @@ public class PrivacyComponentFactory implements HostComponentFactory {
private double _sum = 0; private double _sum = 0;
private Random _random = Randoms.getRandom(getClass()); private Random _random = Randoms.getRandom(getClass());
private double[] _ratio;
@Override @Override
public HostComponent createComponent(Host pHost) { public HostComponent createComponent(Host pHost) {
PrivacyLevel level = PrivacyLevel.NO_PRIVACY; PrivacyLevel level = PrivacyLevel.NO_PRIVACY;
...@@ -53,11 +55,19 @@ public class PrivacyComponentFactory implements HostComponentFactory { ...@@ -53,11 +55,19 @@ public class PrivacyComponentFactory implements HostComponentFactory {
return privacyComponent; return privacyComponent;
} }
public void setPrivacyFrequency(PrivacyLevelFrequency pPrivacyLevel) { public void setRatio(String pRatio) {
_levels.add(pPrivacyLevel); String[] split = pRatio.split("-");
_sum += pPrivacyLevel.getProbability(); _ratio = new double[split.length];
for (int i = 0; i < split.length; i++) {
_ratio[i] = Double.valueOf(split[i]);
_sum += _ratio[i];
}
}
public void setPrivacy(PrivacyLevel pPrivacyLevel) {
_levels.add(new PrivacyLevelFrequency(pPrivacyLevel, _ratio[_levels.size()]));
PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel.getLevel()); PrivacyLevel.PRIVACY_LEVELS.add(pPrivacyLevel);
} }
public static class PrivacyLevelFrequency { public static class PrivacyLevelFrequency {
......
...@@ -30,8 +30,8 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> { ...@@ -30,8 +30,8 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
} }
imprecisionAreaRadius = pImprecisionAreaRadius; imprecisionAreaRadius = pImprecisionAreaRadius;
String[] responsibilityLevels; String[] responsibilityLevels;
if (responsibility.contains(";")) { if (responsibility.trim().length() > 0) {
responsibilityLevels = responsibility.split(";"); responsibilityLevels = responsibility.trim().split(";");
} else { } else {
responsibilityLevels = new String[0]; responsibilityLevels = new String[0];
} }
...@@ -41,6 +41,17 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> { ...@@ -41,6 +41,17 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
} }
} }
public String getResponsibility() {
StringBuffer result = new StringBuffer();
for (int i = 0; i < responsibility.length; i++) {
if (i != 0) {
result.append(";");
}
result.append(responsibility[i]);
}
return result.toString();
}
public int getId() { public int getId() {
return id; return id;
} }
...@@ -77,6 +88,10 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> { ...@@ -77,6 +88,10 @@ public class PrivacyLevel implements Comparable<PrivacyLevel> {
@Override @Override
public int compareTo(PrivacyLevel pArg0) { public int compareTo(PrivacyLevel pArg0) {
return Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius()); int compare = Double.compare(imprecisionAreaRadius, pArg0.getImprecisionAreaRadius());
if (compare == 0) {
compare = Double.compare(id, pArg0.getId());
}
return compare;
} }
} }
...@@ -38,6 +38,15 @@ public class DeterministicExponentialLifetimeDistribution implements LifetimeDis ...@@ -38,6 +38,15 @@ public class DeterministicExponentialLifetimeDistribution implements LifetimeDis
_percentile = pPercentile; _percentile = pPercentile;
} }
@XMLConfigurableConstructor({ "duration" })
public DeterministicExponentialLifetimeDistribution(long pEventDuration) {
_averageEventDuration = pEventDuration;
_existProbability = 1 - 1 / (double) (pEventDuration / Time.SECOND);
_percentile = 0.5;
}
@Override @Override
public long getLifetime() { public long getLifetime() {
return (long) Math.ceil(Math.log(_percentile) / Math.log(_existProbability)) * Time.SECOND; return (long) Math.ceil(Math.log(_percentile) / Math.log(_existProbability)) * Time.SECOND;
......
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