Search in sources :

Example 1 with DNSOutgoing

use of javax.jmdns.impl.DNSOutgoing 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();
        }
    }
}
Also used : DNSOutgoing(javax.jmdns.impl.DNSOutgoing) DNSQuestion(javax.jmdns.impl.DNSQuestion) DNSRecord(javax.jmdns.impl.DNSRecord) HashSet(java.util.HashSet)

Example 2 with DNSOutgoing

use of javax.jmdns.impl.DNSOutgoing 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;
}
Also used : DNSOutgoing(javax.jmdns.impl.DNSOutgoing) DNSRecord(javax.jmdns.impl.DNSRecord)

Example 3 with DNSOutgoing

use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.

the class ServiceInfoResolver method addQuestions.

/*
     * (non-Javadoc)
     * @see javax.jmdns.impl.tasks.Resolver#addQuestions(javax.jmdns.impl.DNSOutgoing)
     */
@Override
protected DNSOutgoing addQuestions(DNSOutgoing out) throws IOException {
    DNSOutgoing newOut = out;
    if (!_info.hasData()) {
        newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_SRV, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
        newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getQualifiedName(), DNSRecordType.TYPE_TXT, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
        if (_info.getServer().length() > 0) {
            newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_A, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
            newOut = this.addQuestion(newOut, DNSQuestion.newQuestion(_info.getServer(), DNSRecordType.TYPE_AAAA, DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE));
        }
    }
    return newOut;
}
Also used : DNSOutgoing(javax.jmdns.impl.DNSOutgoing)

Example 4 with DNSOutgoing

use of javax.jmdns.impl.DNSOutgoing in project JAirPort by froks.

the class ServiceResolver 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;
    long now = System.currentTimeMillis();
    for (ServiceInfo info : this.getDns().getServices().values()) {
        newOut = this.addAnswer(newOut, new DNSRecord.Pointer(info.getType(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getQualifiedName()), now);
    // newOut = this.addAnswer(newOut, new DNSRecord.Service(info.getQualifiedName(), DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, info.getPriority(), info.getWeight(), info.getPort(),
    // this.getDns().getLocalHost().getName()), now);
    }
    return newOut;
}
Also used : ServiceInfo(javax.jmdns.ServiceInfo) DNSOutgoing(javax.jmdns.impl.DNSOutgoing)

Example 5 with DNSOutgoing

use of javax.jmdns.impl.DNSOutgoing 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;
}
Also used : DNSOutgoing(javax.jmdns.impl.DNSOutgoing) DNSRecord(javax.jmdns.impl.DNSRecord)

Aggregations

DNSOutgoing (javax.jmdns.impl.DNSOutgoing)10 DNSRecord (javax.jmdns.impl.DNSRecord)3 ServiceInfo (javax.jmdns.ServiceInfo)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DNSQuestion (javax.jmdns.impl.DNSQuestion)1 DNSStatefulObject (javax.jmdns.impl.DNSStatefulObject)1 ServiceTypeEntry (javax.jmdns.impl.JmDNSImpl.ServiceTypeEntry)1 ServiceInfoImpl (javax.jmdns.impl.ServiceInfoImpl)1