Dont bid on private IP addresses in transports

This commit is contained in:
zzz
2008-05-27 13:20:56 +00:00
parent ffc67d1e5a
commit 699a62a9b9
4 changed files with 35 additions and 3 deletions

View File

@ -17,7 +17,7 @@ import net.i2p.CoreVersion;
public class RouterVersion {
public final static String ID = "$Revision: 1.548 $ $Date: 2008-02-10 15:00:00 $";
public final static String VERSION = "0.6.1.33";
public final static long BUILD = 8;
public final static long BUILD = 9;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -69,6 +69,7 @@ public class NTCPTransport extends TransportImpl {
_context.statManager().createRateStat("ntcp.closeOnBacklog", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.connectFailedIOE", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.connectFailedInvalidPort", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.bidRejectedLocalAddress", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.bidRejectedNoNTCPAddress", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.connectFailedTimeout", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
_context.statManager().createRateStat("ntcp.connectFailedTimeoutIOE", "", "ntcp", new long[] { 60*1000, 10*60*1000 });
@ -273,6 +274,15 @@ public class NTCPTransport extends TransportImpl {
_log.debug("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as they don't have a valid ntcp address");
return null;
}
if (!naddr.isPubliclyRoutable()) {
if (! _context.getProperty("i2np.ntcp.allowLocal", "false").equals("true")) {
_context.statManager().addRateData("ntcp.bidRejectedLocalAddress", 1, 0);
markUnreachable(peer);
if (_log.shouldLog(Log.DEBUG))
_log.debug("no bid when trying to send to " + toAddress.getIdentity().calculateHash().toBase64() + " as they have a private ntcp address");
return null;
}
}
//if ( (_myAddress != null) && (_myAddress.equals(addr)) )
// return null; // dont talk to yourself

View File

@ -858,8 +858,24 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
else
return _fastBid;
} else {
if (null == toAddress.getTargetAddress(STYLE))
// Validate his SSU address
RouterAddress addr = toAddress.getTargetAddress(STYLE);
if (addr == null) {
markUnreachable(to);
return null;
}
UDPAddress ua = new UDPAddress(addr);
if (ua == null) {
markUnreachable(to);
return null;
}
if (ua.getIntroducerCount() <= 0) {
InetAddress ia = ua.getHostAddress();
if (ua.getPort() <= 0 || ia == null || !isPubliclyRoutable(ia.getAddress())) {
markUnreachable(to);
return null;
}
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("bidding on a message to an unestablished peer: " + to.toBase64());