DNS (ticket #1998):

- Data: Cache hostname lookups in RouterAddress
- Job Queue: Make search jobs droppable
- Router: Increase JVM DNS cache time
- Util: Add negative DNS lookup cache, increase cache size
This commit is contained in:
zzz
2017-06-15 15:48:22 +00:00
parent 8216b68ee1
commit 32efa2e509
7 changed files with 90 additions and 27 deletions

View File

@@ -50,11 +50,12 @@ public class RouterAddress extends DataStructureImpl {
private String _transportStyle;
private final Properties _options;
// cached values
private byte[] _ip;
private byte[] _ip = NOT_LOOKED_UP;
private int _port;
public static final String PROP_HOST = "host";
public static final String PROP_PORT = "port";
private static final byte[] NOT_LOOKED_UP = new byte[0];
public RouterAddress() {
_options = new OrderedProperties();
@@ -213,26 +214,23 @@ public class RouterAddress extends DataStructureImpl {
/**
* Caching version of InetAddress.getByName(getOption("host")).getAddress(), which is slow.
* Caches numeric host names only.
* Will resolve but not cache resolution of DNS host names.
* Caches numeric host names AND DNS host names, and negative caches also.
*
* @return IP or null
* @since 0.9.3
*/
public byte[] getIP() {
if (_ip != null)
return _ip;
byte[] rv = null;
String host = getHost();
if (host != null) {
rv = Addresses.getIP(host);
if (rv != null &&
(InetAddressUtils.isIPv4Address(host) ||
InetAddressUtils.isIPv6Address(host))) {
_ip = rv;
}
public synchronized byte[] getIP() {
if (_ip == NOT_LOOKED_UP) {
// Only look up once, even if it fails, so we don't generate excessive DNS lookups.
// The lifetime of a RouterAddress object is a few hours at most,
// it will get republished or expired, so it's OK even for host names.
String host = getHost();
if (host != null)
_ip = Addresses.getIP(host);
else
_ip = null;
}
return rv;
return _ip;
}
/**

View File

@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.data.DataHelper;
import net.i2p.router.message.HandleGarlicMessageJob;
import net.i2p.router.networkdb.kademlia.HandleFloodfillDatabaseLookupMessageJob;
import net.i2p.router.networkdb.kademlia.IterativeSearchJob;
import net.i2p.router.RouterClock;
import net.i2p.util.Clock;
import net.i2p.util.I2PThread;
@@ -316,10 +317,13 @@ public class JobQueue {
// Garlic added in 0.9.19, floodfills were getting overloaded
// with encrypted lookups
//
// ISJ added in 0.9.31, can get backed up due to DNS
//
// Obviously we can only drop one-shot jobs, not those that requeue
//
if (cls == HandleFloodfillDatabaseLookupMessageJob.class ||
cls == HandleGarlicMessageJob.class) {
cls == HandleGarlicMessageJob.class ||
cls == IterativeSearchJob.class) {
// this tail drops based on the lag at the tail, which
// makes no sense...
//JobTiming jt = job.getTiming();

View File

@@ -117,7 +117,6 @@ public class Router implements RouterClock.ClockShiftListener {
private final static String PROP_SHUTDOWN_IN_PROGRESS = "__shutdownInProgress";
public static final String PROP_IB_RANDOM_KEY = TunnelPoolSettings.PREFIX_INBOUND_EXPLORATORY + TunnelPoolSettings.PROP_RANDOM_KEY;
public static final String PROP_OB_RANDOM_KEY = TunnelPoolSettings.PREFIX_OUTBOUND_EXPLORATORY + TunnelPoolSettings.PROP_RANDOM_KEY;
private final static String DNS_CACHE_TIME = "" + (5*60);
private static final String EVENTLOG = "eventlog.txt";
private static final String PROP_JBIGI = "jbigi.loadedResource";
public static final String UPDATE_FILE = "i2pupdate.zip";
@@ -133,10 +132,12 @@ public class Router implements RouterClock.ClockShiftListener {
if (System.getProperty("I2P_DISABLE_DNS_CACHE_OVERRIDE") == null) {
// grumble about sun's java caching DNS entries *forever* by default
// so lets just keep 'em for a short time
String DNS_CACHE_TIME = Integer.toString(2*60*60);
String DNS_NEG_CACHE_TIME = Integer.toString(30*60);
System.setProperty("sun.net.inetaddr.ttl", DNS_CACHE_TIME);
System.setProperty("sun.net.inetaddr.negative.ttl", DNS_CACHE_TIME);
System.setProperty("sun.net.inetaddr.negative.ttl", DNS_NEG_CACHE_TIME);
System.setProperty("networkaddress.cache.ttl", DNS_CACHE_TIME);
System.setProperty("networkaddress.cache.negative.ttl", DNS_CACHE_TIME);
System.setProperty("networkaddress.cache.negative.ttl", DNS_NEG_CACHE_TIME);
}
if (System.getProperty("I2P_DISABLE_HTTP_AGENT_OVERRIDE") == null) {
System.setProperty("http.agent", "I2P");

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11;
public final static long BUILD = 12;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -54,9 +54,11 @@ import net.i2p.util.VersionComparator;
* Halves search traffic for successful searches, as this doesn't do
* two sesarches in parallel like FOSJ does.
*
* Public only for JobQueue, not a public API, not for external use.
*
* @since 0.8.9
*/
class IterativeSearchJob extends FloodSearchJob {
public class IterativeSearchJob extends FloodSearchJob {
/** peers not sent to yet, sorted closest-to-the-routing-key */
private final SortedSet<Hash> _toTry;
/** query sent, no reply yet */
@@ -559,6 +561,15 @@ class IterativeSearchJob extends FloodSearchJob {
return rv == null ? -1 : rv.longValue();
}
/**
* Dropped by the job queue
* @since 0.9.31
*/
@Override
public void dropped() {
failed();
}
/**
* Total failure
*/