I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit b4e23664 authored by Zlatin Balevsky's avatar Zlatin Balevsky
Browse files

Merge branch 'filefilter-fix' into 'master'

Fix for FileFilterDefinitionElement.  Issue #349

See merge request i2p-hackers/i2p.i2p!50
parents 1389e89f c3abe7b3
No related branches found
No related tags found
No related merge requests found
package net.i2p.i2ptunnel.access;
import java.util.HashMap;
import java.util.Map;
import java.io.File;
......@@ -18,6 +19,7 @@ import net.i2p.data.Hash;
class FileFilterDefinitionElement extends FilterDefinitionElement {
private final File file;
private final Map<Hash, DestTracker> lastLoaded = new HashMap<>();
private volatile long lastLoading;
/**
......@@ -31,18 +33,36 @@ class FileFilterDefinitionElement extends FilterDefinitionElement {
@Override
public void update(Map<Hash, DestTracker> map) throws IOException {
if (!(file.exists() && file.isFile() && file.lastModified() > lastLoading))
if (!(file.exists() && file.isFile()))
return;
if (file.lastModified() <= lastLoading) {
synchronized (lastLoaded) {
for (Map.Entry<Hash, DestTracker> entry : lastLoaded.entrySet()) {
if (!map.containsKey(entry.getKey()))
map.put(entry.getKey(),entry.getValue());
}
}
return;
}
lastLoading = System.currentTimeMillis();
BufferedReader reader = null;
synchronized (lastLoaded) {
lastLoaded.clear();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
reader = new BufferedReader(new FileReader(file));
String b32;
while((b32 = reader.readLine()) != null) {
Hash hash = fromBase32(b32);
if (map.containsKey(hash))
continue;
map.put(hash, new DestTracker(hash, threshold));
DestTracker newTracker = new DestTracker(hash, threshold);
map.put(hash, newTracker);
synchronized (lastLoaded) {
lastLoaded.put(hash, newTracker);
}
}
} catch (InvalidDefinitionException bad32) {
throw new IOException("invalid access list entry", bad32);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment