* Blocklists: Handle blank lines and \r\n in blocklist.txt

* NTCP: Add connection limit, set by i2np.ntcp.maxConnections,
      default is 500 (very high for now)
This commit is contained in:
zzz
2008-08-20 14:58:45 +00:00
parent 49af13a3ca
commit 258d01f0d9
5 changed files with 44 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2008-08-20 zzz
* Blocklists: Handle blank lines and \r\n in blocklist.txt
* NTCP: Add connection limit, set by i2np.ntcp.maxConnections,
default is 500 (very high for now)
2008-08-13 zzz
* i2psnark: Fix OOM vulnerability by checking incoming message length
(thanks devzero!)

View File

@ -275,6 +275,14 @@ public class Blocklist {
byte[] ip2;
int start1 = 0;
int end1 = buf.length();
if (end1 <= 0)
return null; // blank
if (buf.charAt(end1 - 1) == '\r') { // DataHelper.readLine leaves the \r on there
buf.deleteCharAt(end1 - 1);
end1--;
}
if (end1 <= 0)
return null; // blank
int start2 = -1;
int mask = -1;
String comment = null;
@ -302,6 +310,8 @@ public class Blocklist {
mask = index + 1;
}
}
if (end1 - start1 <= 0)
return null; // blank
try {
InetAddress pi = InetAddress.getByName(buf.substring(start1, end1));
if (pi == null) return null;

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
public final static String VERSION = "0.6.2";
public final static long BUILD = 12;
public final static long BUILD = 13;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -383,6 +383,14 @@ public class EventPumper implements Runnable {
try {
SocketChannel chan = servChan.accept();
chan.configureBlocking(false);
if (!_transport.allowConnection()) {
if (_log.shouldLog(Log.WARN))
_log.warn("Receive session request but at connection limit: " + chan.socket().getInetAddress());
try { chan.close(); } catch (IOException ioe) { }
return;
}
if (_context.blocklist().isBlocklisted(chan.socket().getInetAddress().getAddress())) {
if (_log.shouldLog(Log.WARN))
_log.warn("Receive session request from blocklisted IP: " + chan.socket().getInetAddress());
@ -391,6 +399,7 @@ public class EventPumper implements Runnable {
try { chan.close(); } catch (IOException ioe) { }
return;
}
SelectionKey ckey = chan.register(_selector, SelectionKey.OP_READ);
NTCPConnection con = new NTCPConnection(_context, _transport, chan, ckey);
if (_log.shouldLog(Log.DEBUG))

View File

@ -286,6 +286,12 @@ public class NTCPTransport extends TransportImpl {
}
}
if (!allowConnection()) {
if (_log.shouldLog(Log.WARN))
_log.warn("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + ", max connection limit reached");
return null;
}
//if ( (_myAddress != null) && (_myAddress.equals(addr)) )
// return null; // dont talk to yourself
@ -294,6 +300,19 @@ public class NTCPTransport extends TransportImpl {
return _slowBid;
}
private static final int DEFAULT_MAX_CONNECTIONS = 500;
public boolean allowConnection() {
int max = DEFAULT_MAX_CONNECTIONS;
String mc = _context.getProperty("i2np.ntcp.maxConnections");
if (mc != null) {
try {
max = Integer.parseInt(mc);
} catch (NumberFormatException nfe) {}
}
return countActivePeers() < max;
}
void sendComplete(OutNetMessage msg) { _finisher.add(msg); }
/** async afterSend call, which can take some time w/ jobs, etc */
private class SendFinisher implements SimpleTimer.TimedEvent {