protected Cache createCache() { return new Cache(); }
@Override public void clearDNSCache() { cache.clearCache(); }
@Override public SetResponse lookupRecords(Name name, int type, int minCred) { final SetResponse setResponse = super.lookupRecords(name, type, minCred); if (count++ == 0) { assertThat(setResponse.isUnknown(), is(true)); } else { assertThat(setResponse.isUnknown(), is(false)); } return setResponse; //To change body of overridden methods use File | Settings | File Templates. }
int type = answers[i].getType(); Name name = answers[i].getName(); cred = getCred(Section.ANSWER, isAuth); if ((type == qtype || qtype == Type.ANY) && name.equals(curname)) addRRset(answers[i], cred); completed = true; if (curname == qname) { markAdditional(answers[i], additionalNames); } else if (type == Type.CNAME && name.equals(curname)) { CNAMERecord cname; addRRset(answers[i], cred); if (curname == qname) response = new SetResponse(SetResponse.CNAME, } else if (type == Type.DNAME && curname.subdomain(name)) { DNAMERecord dname; addRRset(answers[i], cred); if (curname == qname) response = new SetResponse(SetResponse.DNAME, cred = getCred(Section.AUTHORITY, isAuth); SOARecord soarec = null; if (soa != null) soarec = (SOARecord) soa.first(); addNegative(curname, cachetype, soarec, cred); if (response == null) {
/** * Adds a negative entry to the Cache. * @param name The name of the negative entry * @param type The type of the negative entry * @param soa The SOA record to add to the negative cache entry, or null. * The negative cache ttl is derived from the SOA. * @param cred The credibility of the negative entry */ public synchronized void addNegative(Name name, int type, SOARecord soa, int cred) { long ttl = 0; if (soa != null) ttl = soa.getTTL(); Element element = findElement(name, type, 0); if (ttl == 0) { if (element != null && element.compareCredibility(cred) <= 0) removeElement(name, type); } else { if (element != null && element.compareCredibility(cred) <= 0) element = null; if (element == null) addElement(name, new NegativeElement(name, type, soa, cred, maxncache)); } }
cache = new Cache(DClass.IN); cache.setMaxEntries(maxCacheSize); cache.setMaxNCache(negativeCacheTTL);
private void lookup(Name current) { SetResponse sr = cache.lookupRecords(current, type, credibility); if (verbose) { System.err.println("lookup " + current + " " + sr = cache.addMessage(response); if (sr == null) sr = cache.lookupRecords(current, type, credibility); if (verbose) { System.err.println("queried " + current + " " +
Element [] elements = allElements(types); int added = 0; for (int i = 0; i < elements.length; i++) { element = elements[i]; if (element.expired()) { removeElement(tname, element.getType()); continue; return sr; } else if (isExact) { element = oneElement(tname, types, type, minCred); if (element != null && element instanceof CacheRRset) element = oneElement(tname, types, Type.CNAME, minCred); if (element != null && element instanceof CacheRRset) element = oneElement(tname, types, Type.DNAME, minCred); if (element != null && element instanceof CacheRRset) element = oneElement(tname, types, Type.NS, minCred); if (element != null && element instanceof CacheRRset) return new SetResponse(SetResponse.DELEGATION, element = oneElement(tname, types, 0, minCred); if (element != null) return SetResponse.ofType(SetResponse.NXDOMAIN);
public DNSCacheManager() { setProperty(new CollectionProperty(SERVERS, new ArrayList<String>())); this.systemDefaultDnsResolver = new SystemDefaultDnsResolver(); this.cache = new LinkedHashMap<>(); //disabling cache lookupCache = new Cache(); lookupCache.setMaxCache(0); lookupCache.setMaxEntries(0); }
/** * Adds a record to the Cache. * @param r The record to be added * @param cred The credibility of the record * @param o The source of the record (this could be a Message, for example) * @see Record */ public synchronized void addRecord(Record r, int cred, Object o) { Name name = r.getName(); int type = r.getRRsetType(); if (!Type.isRR(type)) return; Element element = findElement(name, type, cred); if (element == null) { CacheRRset crrset = new CacheRRset(r, cred, maxcache); addRRset(crrset, cred); } else if (element.compareCredibility(cred) == 0) { if (element instanceof CacheRRset) { CacheRRset crrset = (CacheRRset) element; crrset.addRR(r); } } }
public RRset findExactMatch(Name name, int type, int dclass, boolean glue) { Zone zone = findBestZone(name); if (zone != null) return zone.findExactMatch(name, type); else { RRset [] rrsets; Cache cache = getCache(dclass); if (glue) rrsets = cache.findAnyRecords(name, type); else rrsets = cache.findRecords(name, type); if (rrsets == null) return null; else return rrsets[0]; /* not quite right */ } }
/** * Looks up Records in the Cache (a wrapper around lookupRecords). Unlike * lookupRecords, this given no indication of why failure occurred. * @param name The name to look up * @param type The type to look up * @return An array of RRsets, or null * @see Credibility */ public RRset [] findAnyRecords(Name name, int type) { return findRecords(name, type, Credibility.GLUE); }
@Override public synchronized void addRecord(final Record r, final int cred, final Object o) { super.addRecord(r, cred, o); }
/** * Returns the contents of the Cache as a string. */ public String toString() { StringBuffer sb = new StringBuffer(); synchronized (this) { Iterator it = data.values().iterator(); while (it.hasNext()) { Element [] elements = allElements(it.next()); for (int i = 0; i < elements.length; i++) { sb.append(elements[i]); sb.append("\n"); } } } return sb.toString(); }
@Override public synchronized void addRRset(final RRset rrset, final int cred) { super.addRRset(rrset, cred); }
private RRset [] findRecords(Name name, int type, int minCred) { SetResponse cr = lookupRecords(name, type, minCred); if (cr.isSuccessful()) return cr.answers(); else return null; }
int type = answers[i].getType(); Name name = answers[i].getName(); cred = getCred(Section.ANSWER, isAuth); if ((type == qtype || qtype == Type.ANY) && name.equals(curname)) addRRset(answers[i], cred); completed = true; if (curname == qname) { markAdditional(answers[i], additionalNames); } else if (type == Type.CNAME && name.equals(curname)) { CNAMERecord cname; addRRset(answers[i], cred); if (curname == qname) response = new SetResponse(SetResponse.CNAME, } else if (type == Type.DNAME && curname.subdomain(name)) { DNAMERecord dname; addRRset(answers[i], cred); if (curname == qname) response = new SetResponse(SetResponse.DNAME, cred = getCred(Section.AUTHORITY, isAuth); SOARecord soarec = null; if (soa != null) soarec = (SOARecord) soa.first(); addNegative(curname, cachetype, soarec, cred); if (response == null) {
/** * Adds a negative entry to the Cache. * @param name The name of the negative entry * @param type The type of the negative entry * @param soa The SOA record to add to the negative cache entry, or null. * The negative cache ttl is derived from the SOA. * @param cred The credibility of the negative entry */ public synchronized void addNegative(Name name, int type, SOARecord soa, int cred) { long ttl = 0; if (soa != null) ttl = soa.getTTL(); Element element = findElement(name, type, 0); if (ttl == 0) { if (element != null && element.compareCredibility(cred) <= 0) removeElement(name, type); } else { if (element != null && element.compareCredibility(cred) <= 0) element = null; if (element == null) addElement(name, new NegativeElement(name, type, soa, cred, maxncache)); } }
cache = new Cache(DClass.IN); cache.setMaxEntries(maxCacheSize); cache.setMaxNCache(negativeCacheTTL);
private void lookup(Name current) { SetResponse sr = cache.lookupRecords(current, type, credibility); if (verbose) { System.err.println("lookup " + current + " " + sr = cache.addMessage(response); if (sr == null) sr = cache.lookupRecords(current, type, credibility); if (verbose) { System.err.println("queried " + current + " " +