/** * Check if the record is expired. */ boolean isExpired(long now) { return getExpirationTime(100) <= now; }
public String toString(String other) { return toString("record", ttl + "/" + getRemainingTTL(System.currentTimeMillis()) + "," + other); } }
/** * True if this record is the same as some other record. */ public boolean equals(Object other) { return (other instanceof DNSRecord) && sameAs((DNSRecord) other); }
boolean expired = rec.isExpired(now); c.resetTTL(rec); rec = c; if (rec.getName().indexOf("._mdns._udp.") >= 0) if ((rec.getType() == DNSConstants.TYPE_A) || (rec.getType() == DNSConstants.TYPE_AAAA)) hostConflictDetected |= rec.handleResponse(this); serviceConflictDetected |= rec.handleResponse(this);
if ((answer.getType() == DNSConstants.TYPE_A) || (answer.getType() == DNSConstants.TYPE_AAAA)) hostConflictDetected |= answer.handleQuery(this, expirationTime); serviceConflictDetected |= answer.handleQuery(this, expirationTime);
void writeRecord(DNSRecord rec, long now) throws IOException { int save = off; try { writeName(rec.name); writeShort(rec.type); writeShort(rec.clazz | ((rec.unique && multicast) ? DNSConstants.CLASS_UNIQUE : 0)); writeInt((now == 0) ? rec.ttl : rec.getRemainingTTL(now)); writeShort(0); int start = off; rec.write(this); int len = off - start; data[start - 2] = (byte) (len >> 8); data[start - 1] = (byte) (len & 0xFF); } catch (IOException e) { off = save; throw e; } }
/** * Add an answer to the message. */ void addAnswer(DNSRecord rec, long now) throws IOException { if (numAuthorities > 0 || numAdditionals > 0) { throw new IllegalStateException("Questions must be added before answers"); } if (rec != null) { if ((now == 0) || !rec.isExpired(now)) { writeRecord(rec, now); numAnswers++; } } }
/** * True if this record is the same as some other record. */ boolean sameAs(DNSRecord other) { return super.equals(other) && sameValue((DNSRecord) other); }
if (c.isExpired(now))
/** * Add a listener for a question. The listener will receive updates * of answers to the question as they arrive, or from the cache if they * are already available. */ void addListener(DNSListener listener, DNSQuestion question) { long now = System.currentTimeMillis(); // add the new listener synchronized (this) { listeners.add(listener); } // report existing matched records if (question != null) { for (DNSCache.CacheNode i = cache.find(question.name); i != null; i = i.next()) { DNSRecord c = (DNSRecord) i.getValue(); if (question.answeredBy(c) && !c.isExpired(now)) { listener.updateRecord(this, now, c); } } } }
/** * Check if the record is stale, ie it has outlived * more than half of its TTL. */ boolean isStale(long now) { return getExpirationTime(50) <= now; }
/** * True if this record would be supressed by an answer. * This is the case if this record would not have a * significantly longer TTL. */ boolean suppressedBy(DNSRecord other) { if (sameAs(other) && (other.ttl > ttl / 2)) { return true; } return false; }
if ((rec != null) && !rec.isExpired(now))
/** * Get the remaining TTL for this record. */ int getRemainingTTL(long now) { return (int) Math.max(0, (getExpirationTime(100) - now) / 1000); }
if ((a.type == DNSConstants.TYPE_SRV) && !a.isExpired(now))