* 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:
@ -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
|
2008-08-13 zzz
|
||||||
* i2psnark: Fix OOM vulnerability by checking incoming message length
|
* i2psnark: Fix OOM vulnerability by checking incoming message length
|
||||||
(thanks devzero!)
|
(thanks devzero!)
|
||||||
|
@ -275,6 +275,14 @@ public class Blocklist {
|
|||||||
byte[] ip2;
|
byte[] ip2;
|
||||||
int start1 = 0;
|
int start1 = 0;
|
||||||
int end1 = buf.length();
|
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 start2 = -1;
|
||||||
int mask = -1;
|
int mask = -1;
|
||||||
String comment = null;
|
String comment = null;
|
||||||
@ -302,6 +310,8 @@ public class Blocklist {
|
|||||||
mask = index + 1;
|
mask = index + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (end1 - start1 <= 0)
|
||||||
|
return null; // blank
|
||||||
try {
|
try {
|
||||||
InetAddress pi = InetAddress.getByName(buf.substring(start1, end1));
|
InetAddress pi = InetAddress.getByName(buf.substring(start1, end1));
|
||||||
if (pi == null) return null;
|
if (pi == null) return null;
|
||||||
|
@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
|
|||||||
public class RouterVersion {
|
public class RouterVersion {
|
||||||
public final static String ID = "$Revision: 1.548 $ $Date: 2008-06-07 23:00:00 $";
|
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 String VERSION = "0.6.2";
|
||||||
public final static long BUILD = 12;
|
public final static long BUILD = 13;
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
|
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
|
||||||
System.out.println("Router ID: " + RouterVersion.ID);
|
System.out.println("Router ID: " + RouterVersion.ID);
|
||||||
|
@ -383,6 +383,14 @@ public class EventPumper implements Runnable {
|
|||||||
try {
|
try {
|
||||||
SocketChannel chan = servChan.accept();
|
SocketChannel chan = servChan.accept();
|
||||||
chan.configureBlocking(false);
|
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 (_context.blocklist().isBlocklisted(chan.socket().getInetAddress().getAddress())) {
|
||||||
if (_log.shouldLog(Log.WARN))
|
if (_log.shouldLog(Log.WARN))
|
||||||
_log.warn("Receive session request from blocklisted IP: " + chan.socket().getInetAddress());
|
_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) { }
|
try { chan.close(); } catch (IOException ioe) { }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectionKey ckey = chan.register(_selector, SelectionKey.OP_READ);
|
SelectionKey ckey = chan.register(_selector, SelectionKey.OP_READ);
|
||||||
NTCPConnection con = new NTCPConnection(_context, _transport, chan, ckey);
|
NTCPConnection con = new NTCPConnection(_context, _transport, chan, ckey);
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
@ -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)) )
|
//if ( (_myAddress != null) && (_myAddress.equals(addr)) )
|
||||||
// return null; // dont talk to yourself
|
// return null; // dont talk to yourself
|
||||||
|
|
||||||
@ -294,6 +300,19 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
return _slowBid;
|
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); }
|
void sendComplete(OutNetMessage msg) { _finisher.add(msg); }
|
||||||
/** async afterSend call, which can take some time w/ jobs, etc */
|
/** async afterSend call, which can take some time w/ jobs, etc */
|
||||||
private class SendFinisher implements SimpleTimer.TimedEvent {
|
private class SendFinisher implements SimpleTimer.TimedEvent {
|
||||||
|
Reference in New Issue
Block a user