/** The Freenet interface. */
private final FreenetInterface freenetInterface;
+ private final SoneModificationDetector soneModificationDetector;
+
/** The Sone to insert. */
private volatile Sone sone;
- /** The fingerprint of the last insert. */
- private volatile String lastInsertFingerprint;
-
/**
* Creates a new Sone inserter.
*
this.eventBus = eventBus;
this.freenetInterface = freenetInterface;
this.sone = sone;
+ this.soneModificationDetector = new SoneModificationDetector(core, sone, insertionDelay);
}
//
* @return The fingerprint of the last insert
*/
public String getLastInsertFingerprint() {
- return lastInsertFingerprint;
+ return soneModificationDetector.getOriginalFingerprint();
}
/**
* The fingerprint of the last insert
*/
public void setLastInsertFingerprint(String lastInsertFingerprint) {
- this.lastInsertFingerprint = lastInsertFingerprint;
+ soneModificationDetector.setFingerprint(lastInsertFingerprint);
}
/**
* otherwise
*/
public boolean isModified() {
- return !lastInsertFingerprint.equals(sone.getFingerprint());
+ return soneModificationDetector.isModified();
}
//
*/
@Override
protected void serviceRun() {
- SoneModificationDetector soneModificationDetector = new SoneModificationDetector(core, sone, insertionDelay);
while (!shouldStop()) {
try {
/* check every second. */
if (insertInformation.getFingerprint().equals(sone.getFingerprint())) {
logger.log(Level.FINE, String.format("Sone “%s” was not modified further, resetting counter…", sone));
soneModificationDetector.setFingerprint(insertInformation.getFingerprint());
- lastInsertFingerprint = insertInformation.getFingerprint();
core.touchConfiguration();
}
}
return insertionDelayHasPassed();
}
+ public String getOriginalFingerprint() {
+ return originalFingerprint;
+ }
+
public void setFingerprint(String fingerprint) {
originalFingerprint = fingerprint;
lastFingerprint = originalFingerprint;
return lastModificationTime.isPresent() && (NANOSECONDS.toSeconds(ticker.read() - lastModificationTime.get()) >= insertionDelay.get());
}
+ public boolean isModified() {
+ return !sone.getFingerprint().equals(originalFingerprint);
+ }
+
}
@Test
public void modifiedSoneIsEligibleAfter60Seconds() {
+ assertThat(soneModificationDetector.isModified(), is(false));
assertThat(soneModificationDetector.isEligibleForInsert(), is(false));
modifySone();
+ assertThat(soneModificationDetector.isModified(), is(true));
assertThat(soneModificationDetector.isEligibleForInsert(), is(false));
passTime(100);
+ assertThat(soneModificationDetector.isModified(), is(true));
assertThat(soneModificationDetector.isEligibleForInsert(), is(true));
}