use of javax.jmdns.impl.DNSRecord in project JAirPort by froks.
the class Responder method run.
@Override
public void run() {
this.getDns().respondToQuery(_in);
// We use these sets to prevent duplicate records
Set<DNSQuestion> questions = new HashSet<DNSQuestion>();
Set<DNSRecord> answers = new HashSet<DNSRecord>();
if (this.getDns().isAnnounced()) {
try {
// Answer questions
for (DNSQuestion question : _in.getQuestions()) {
if (logger.isLoggable(Level.FINER)) {
logger.finer(this.getName() + "run() JmDNS responding to: " + question);
}
// for unicast responses the question must be included
if (_unicast) {
// out.addQuestion(q);
questions.add(question);
}
question.addAnswers(this.getDns(), answers);
}
// remove known answers, if the ttl is at least half of the correct value. (See Draft Cheshire chapter 7.1.).
long now = System.currentTimeMillis();
for (DNSRecord knownAnswer : _in.getAnswers()) {
if (knownAnswer.isStale(now)) {
answers.remove(knownAnswer);
if (logger.isLoggable(Level.FINER)) {
logger.finer(this.getName() + "JmDNS Responder Known Answer Removed");
}
}
}
// respond if we have answers
if (!answers.isEmpty()) {
if (logger.isLoggable(Level.FINER)) {
logger.finer(this.getName() + "run() JmDNS responding");
}
DNSOutgoing out = new DNSOutgoing(DNSConstants.FLAGS_QR_RESPONSE | DNSConstants.FLAGS_AA, !_unicast, _in.getSenderUDPPayload());
out.setId(_in.getId());
for (DNSQuestion question : questions) {
if (question != null) {
out = this.addQuestion(out, question);
}
}
for (DNSRecord answer : answers) {
if (answer != null) {
out = this.addAnswer(out, _in, answer);
}
}
if (!out.isEmpty())
this.getDns().send(out);
}
// this.cancel();
} catch (Throwable e) {
logger.log(Level.WARNING, this.getName() + "run() exception ", e);
this.getDns().close();
}
}
}
use of javax.jmdns.impl.DNSRecord in project JAirPort by froks.
the class ServiceInfoResolver method addAnswers.
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.Resolver#addAnswers(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing addAnswers(DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
if (!_info.hasData()) {
long now = System.currentTimeMillis();
newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN), now);
newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN), now);
if (_info.getServer().length() > 0) {
newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN), now);
newOut = this.addAnswer(newOut, (DNSRecord) this.getDns().getCache().getDNSEntry(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN), now);
}
}
return newOut;
}
use of javax.jmdns.impl.DNSRecord in project JAirPort by froks.
the class Prober method buildOutgoingForDNS.
/*
* (non-Javadoc)
* @see javax.jmdns.impl.tasks.state.DNSStateTask#buildOutgoingForDNS(javax.jmdns.impl.DNSOutgoing)
*/
@Override
protected DNSOutgoing buildOutgoingForDNS(DNSOutgoing out) throws IOException {
DNSOutgoing newOut = out;
newOut.addQuestion(DNSQuestion.newQuestion(this.getDns().getLocalHost().getName(), DNSRecordType.TYPE_ANY, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
for (DNSRecord answer : this.getDns().getLocalHost().answers(DNSRecordClass.NOT_UNIQUE, this.getTTL())) {
newOut = this.addAuthoritativeAnswer(newOut, answer);
}
return newOut;
}
Aggregations