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

Skip to content
Snippets Groups Projects
Commit 2f46efe7 authored by zzz's avatar zzz
Browse files

* Blocklist: cleanup

   * PeerProfile:
     - Replace a hot lock with concurrent RW lock
     - Rewrite ugly IP Restriction code
     - Also use transport IP in restriction code
   * Transport: Start the previously unused CleanupUnreachable
parent 3ddd5f2a
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ import net.i2p.data.Hash; ...@@ -19,6 +19,7 @@ import net.i2p.data.Hash;
import net.i2p.data.RouterAddress; import net.i2p.data.RouterAddress;
import net.i2p.data.RouterInfo; import net.i2p.data.RouterInfo;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade; import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
...@@ -55,20 +56,16 @@ public class Blocklist { ...@@ -55,20 +56,16 @@ public class Blocklist {
private int _blocklistSize; private int _blocklistSize;
private final Object _lock = new Object(); private final Object _lock = new Object();
private Entry _wrapSave; private Entry _wrapSave;
private final Set _inProcess = new HashSet(0); private final Set<Hash> _inProcess = new HashSet(0);
private Map _peerBlocklist = new HashMap(0); private Map<Hash, String> _peerBlocklist = new HashMap(0);
private final Set _singleIPBlocklist = new HashSet(0); private final Set<Integer> _singleIPBlocklist = new ConcurrentHashSet(0);
public Blocklist(RouterContext context) { public Blocklist(RouterContext context) {
_context = context; _context = context;
_log = context.logManager().getLog(Blocklist.class); _log = context.logManager().getLog(Blocklist.class);
_blocklist = null; _blocklist = null;
_blocklistSize = 0; _blocklistSize = 0;
// _lock = new Object();
_wrapSave = null; _wrapSave = null;
// _inProcess = new HashSet(0);
// _peerBlocklist = new HashMap(0);
// _singleIPBlocklist = new HashSet(0);
} }
public Blocklist() { public Blocklist() {
...@@ -446,15 +443,11 @@ public class Blocklist { ...@@ -446,15 +443,11 @@ public class Blocklist {
} }
private boolean add(int ip) { private boolean add(int ip) {
synchronized(_singleIPBlocklist) { return _singleIPBlocklist.add(Integer.valueOf(ip));
return _singleIPBlocklist.add(new Integer(ip));
}
} }
private boolean isOnSingleList(int ip) { private boolean isOnSingleList(int ip) {
synchronized(_singleIPBlocklist) { return _singleIPBlocklist.contains(Integer.valueOf(ip));
return _singleIPBlocklist.contains(new Integer(ip));
}
} }
/** /**
...@@ -586,11 +579,11 @@ public class Blocklist { ...@@ -586,11 +579,11 @@ public class Blocklist {
// methods to get and store the from/to values in the array // methods to get and store the from/to values in the array
private int getFrom(long entry) { private static int getFrom(long entry) {
return (int) ((entry >> 32) & 0xffffffff); return (int) ((entry >> 32) & 0xffffffff);
} }
private int getTo(long entry) { private static int getTo(long entry) {
return (int) (entry & 0xffffffff); return (int) (entry & 0xffffffff);
} }
...@@ -602,7 +595,7 @@ public class Blocklist { ...@@ -602,7 +595,7 @@ public class Blocklist {
* So the size is (cough) almost 2MB for the 240,000 line splist.txt. * So the size is (cough) almost 2MB for the 240,000 line splist.txt.
* *
*/ */
private long toEntry(byte ip1[], byte ip2[]) { private static long toEntry(byte ip1[], byte ip2[]) {
long entry = 0; long entry = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
entry |= ((long) (ip2[i] & 0xff)) << ((3-i)*8); entry |= ((long) (ip2[i] & 0xff)) << ((3-i)*8);
...@@ -621,14 +614,18 @@ public class Blocklist { ...@@ -621,14 +614,18 @@ public class Blocklist {
_blocklist[idx] = entry; _blocklist[idx] = entry;
} }
private int toInt(byte ip[]) { private static int toInt(byte ip[]) {
int rv = 0; int rv = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
rv |= (ip[i] & 0xff) << ((3-i)*8); rv |= (ip[i] & 0xff) << ((3-i)*8);
return rv; return rv;
} }
private String toStr(long entry) { public static String toStr(byte[] ip) {
return toStr(toInt(ip));
}
private static String toStr(long entry) {
StringBuffer buf = new StringBuffer(32); StringBuffer buf = new StringBuffer(32);
for (int i = 7; i >= 0; i--) { for (int i = 7; i >= 0; i--) {
buf.append((entry >> (8*i)) & 0xff); buf.append((entry >> (8*i)) & 0xff);
...@@ -640,7 +637,7 @@ public class Blocklist { ...@@ -640,7 +637,7 @@ public class Blocklist {
return buf.toString(); return buf.toString();
} }
private String toStr(int ip) { private static String toStr(int ip) {
StringBuffer buf = new StringBuffer(16); StringBuffer buf = new StringBuffer(16);
for (int i = 3; i >= 0; i--) { for (int i = 3; i >= 0; i--) {
buf.append((ip >> (8*i)) & 0xff); buf.append((ip >> (8*i)) & 0xff);
...@@ -756,9 +753,7 @@ public class Blocklist { ...@@ -756,9 +753,7 @@ public class Blocklist {
public void renderStatusHTML(Writer out) throws IOException { public void renderStatusHTML(Writer out) throws IOException {
out.write("<h2>IP Blocklist</h2>"); out.write("<h2>IP Blocklist</h2>");
Set singles = new TreeSet(); Set singles = new TreeSet();
synchronized(_singleIPBlocklist) { singles.addAll(_singleIPBlocklist);
singles.addAll(_singleIPBlocklist);
}
if (singles.size() > 0) { if (singles.size() > 0) {
out.write("<table><tr><td><b>Transient IPs</b></td></tr>"); out.write("<table><tr><td><b>Transient IPs</b></td></tr>");
for (Iterator iter = singles.iterator(); iter.hasNext(); ) { for (Iterator iter = singles.iterator(); iter.hasNext(); ) {
......
...@@ -58,6 +58,7 @@ public abstract class CommSystemFacade implements Service { ...@@ -58,6 +58,7 @@ public abstract class CommSystemFacade implements Service {
public boolean isBacklogged(Hash dest) { return false; } public boolean isBacklogged(Hash dest) { return false; }
public boolean wasUnreachable(Hash dest) { return false; } public boolean wasUnreachable(Hash dest) { return false; }
public boolean isEstablished(Hash dest) { return false; } public boolean isEstablished(Hash dest) { return false; }
public byte[] getIP(Hash dest) { return null; }
/** /**
* Tell other transports our address changed * Tell other transports our address changed
......
...@@ -36,6 +36,8 @@ import net.i2p.router.RouterContext; ...@@ -36,6 +36,8 @@ import net.i2p.router.RouterContext;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade; import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.ConcurrentHashSet; import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.SimpleScheduler;
import net.i2p.util.SimpleTimer;
/** /**
* Defines a way to send a message to another peer and start listening for messages * Defines a way to send a message to another peer and start listening for messages
...@@ -72,6 +74,7 @@ public abstract class TransportImpl implements Transport { ...@@ -72,6 +74,7 @@ public abstract class TransportImpl implements Transport {
_unreachableEntries = new HashMap(16); _unreachableEntries = new HashMap(16);
_wasUnreachableEntries = new ConcurrentHashSet(16); _wasUnreachableEntries = new ConcurrentHashSet(16);
_currentAddress = null; _currentAddress = null;
SimpleScheduler.getInstance().addPeriodicEvent(new CleanupUnreachable(), 2 * UNREACHABLE_PERIOD, UNREACHABLE_PERIOD / 2);
} }
/** /**
...@@ -462,13 +465,10 @@ public abstract class TransportImpl implements Transport { ...@@ -462,13 +465,10 @@ public abstract class TransportImpl implements Transport {
if (!isInbound) if (!isInbound)
markWasUnreachable(peer, false); markWasUnreachable(peer, false);
} }
private class CleanupUnreachable extends JobImpl {
public CleanupUnreachable(RouterContext ctx) { private class CleanupUnreachable implements SimpleTimer.TimedEvent {
super(ctx); public void timeReached() {
} long now = _context.clock().now();
public String getName() { return "Cleanup " + getStyle() + " unreachable list"; }
public void runJob() {
long now = getContext().clock().now();
synchronized (_unreachableEntries) { synchronized (_unreachableEntries) {
for (Iterator iter = _unreachableEntries.keySet().iterator(); iter.hasNext(); ) { for (Iterator iter = _unreachableEntries.keySet().iterator(); iter.hasNext(); ) {
Hash peer = (Hash)iter.next(); Hash peer = (Hash)iter.next();
...@@ -477,7 +477,6 @@ public abstract class TransportImpl implements Transport { ...@@ -477,7 +477,6 @@ public abstract class TransportImpl implements Transport {
iter.remove(); iter.remove();
} }
} }
requeue(60*1000);
} }
} }
......
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