How to use the zeroconf.DNSQuestion function in zeroconf

To help you get started, we’ve selected a few zeroconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wmcbrine / hmeforpython / zeroconf.py View on Github external
while (self.server is None or self.address is None or
                   self.text is None):
                if last <= now:
                    return False
                if next <= now:
                    out = DNSOutgoing(_FLAGS_QR_QUERY)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_SRV,
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name,
                        _TYPE_SRV, _CLASS_IN), now)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_TXT,
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name,
                        _TYPE_TXT, _CLASS_IN), now)
                    if self.server is not None:
                        out.addQuestion(DNSQuestion(self.server,
                            _TYPE_A, _CLASS_IN))
                        out.addAnswerAtTime(zc.cache.getByDetails(self.server,
                            _TYPE_A, _CLASS_IN), now)
                    zc.send(out)
                    next = now + delay
                    delay = delay * 2

                zc.wait(min(next, last) - now)
                now = currentTimeMillis()
            result = True
        finally:
            zc.removeListener(self)

        return result
github wmcbrine / tivoremote / zeroconf.py View on Github external
next = now + delay
        last = now + timeout
        result = False
        try:
            zc.addListener(self, DNSQuestion(self.name, _TYPE_ANY, _CLASS_IN))
            while (self.server is None or self.address is None or 
                   self.text is None):
                if last <= now:
                    return False
                if next <= now:
                    out = DNSOutgoing(_FLAGS_QR_QUERY)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_SRV, 
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name, 
                        _TYPE_SRV, _CLASS_IN), now)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_TXT, 
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name, 
                        _TYPE_TXT, _CLASS_IN), now)
                    if self.server is not None:
                        out.addQuestion(DNSQuestion(self.server, 
                            _TYPE_A, _CLASS_IN))
                        out.addAnswerAtTime(zc.cache.getByDetails(self.server, 
                            _TYPE_A, _CLASS_IN), now)
                    zc.send(out)
                    next = now + delay
                    delay = delay * 2

                zc.wait(min(next, last) - now)
                now = currentTimeMillis()
            result = True
        finally:
github wmcbrine / hmeforpython / zeroconf.py View on Github external
not record.isExpired(now) and
                    record.alias == info.name):
                    if info.name.find('.') < 0:
                        info.name = '%s.[%s:%s].%s' % (info.name,
                            info.address, info.port, info.type)

                        self.checkService(info)
                        return
                    raise NonUniqueNameException
            if now < nextTime:
                self.wait(nextTime - now)
                now = currentTimeMillis()
                continue
            out = DNSOutgoing(_FLAGS_QR_QUERY | _FLAGS_AA)
            self.debug = out
            out.addQuestion(DNSQuestion(info.type, _TYPE_PTR, _CLASS_IN))
            out.addAuthorativeAnswer(DNSPointer(info.type, _TYPE_PTR,
                                                _CLASS_IN, _DNS_TTL, info.name))
            self.send(out)
            i += 1
            nextTime += _CHECK_TIME
github wmcbrine / tivoremote / zeroconf.py View on Github external
def run(self):
        while True:
            event = None
            now = currentTimeMillis()
            if len(self.list) == 0 and self.nextTime > now:
                self.zc.wait(self.nextTime - now)
            if _GLOBAL_DONE or self.done:
                return
            now = currentTimeMillis()

            if self.nextTime <= now:
                out = DNSOutgoing(_FLAGS_QR_QUERY)
                out.addQuestion(DNSQuestion(self.type, _TYPE_PTR, _CLASS_IN))
                for record in self.services.values():
                    if not record.isExpired(now):
                        out.addAnswerAtTime(record, now)
                self.zc.send(out)
                self.nextTime = now + self.delay
                self.delay = min(20 * 1000, self.delay * 2)

            if len(self.list) > 0:
                event = self.list.pop(0)

            if event is not None:
                event(self.zc)
github wmcbrine / hmeforpython / zeroconf.py View on Github external
def readQuestions(self):
        """Reads questions section of packet"""
        for i in xrange(self.numQuestions):
            name = self.readName()
            type, clazz = self.unpack('!HH')

            question = DNSQuestion(name, type, clazz)
            self.questions.append(question)
github wmcbrine / tivoremote / zeroconf.py View on Github external
def __init__(self, zc, type, listener):
        """Creates a browser for a specific type"""
        threading.Thread.__init__(self)
        self.zc = zc
        self.type = type
        self.listener = listener
        self.services = {}
        self.nextTime = currentTimeMillis()
        self.delay = _BROWSER_TIME
        self.list = []
        
        self.done = False

        self.zc.addListener(self, DNSQuestion(self.type, _TYPE_PTR, _CLASS_IN))
        self.start()
github wmcbrine / tivoremote / zeroconf.py View on Github external
def readQuestions(self):
        """Reads questions section of packet"""
        for i in xrange(self.numQuestions):
            name = self.readName()
            type, clazz = self.unpack('!HH')

            question = DNSQuestion(name, type, clazz)
            self.questions.append(question)
github wmcbrine / tivoremote / zeroconf.py View on Github external
network, and updates this object with details discovered.
        """
        now = currentTimeMillis()
        delay = _LISTENER_TIME
        next = now + delay
        last = now + timeout
        result = False
        try:
            zc.addListener(self, DNSQuestion(self.name, _TYPE_ANY, _CLASS_IN))
            while (self.server is None or self.address is None or 
                   self.text is None):
                if last <= now:
                    return False
                if next <= now:
                    out = DNSOutgoing(_FLAGS_QR_QUERY)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_SRV, 
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name, 
                        _TYPE_SRV, _CLASS_IN), now)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_TXT, 
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name, 
                        _TYPE_TXT, _CLASS_IN), now)
                    if self.server is not None:
                        out.addQuestion(DNSQuestion(self.server, 
                            _TYPE_A, _CLASS_IN))
                        out.addAnswerAtTime(zc.cache.getByDetails(self.server, 
                            _TYPE_A, _CLASS_IN), now)
                    zc.send(out)
                    next = now + delay
                    delay = delay * 2
github wmcbrine / hmeforpython / zeroconf.py View on Github external
network, and updates this object with details discovered.
        """
        now = currentTimeMillis()
        delay = _LISTENER_TIME
        next = now + delay
        last = now + timeout
        result = False
        try:
            zc.addListener(self, DNSQuestion(self.name, _TYPE_ANY, _CLASS_IN))
            while (self.server is None or self.address is None or
                   self.text is None):
                if last <= now:
                    return False
                if next <= now:
                    out = DNSOutgoing(_FLAGS_QR_QUERY)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_SRV,
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name,
                        _TYPE_SRV, _CLASS_IN), now)
                    out.addQuestion(DNSQuestion(self.name, _TYPE_TXT,
                        _CLASS_IN))
                    out.addAnswerAtTime(zc.cache.getByDetails(self.name,
                        _TYPE_TXT, _CLASS_IN), now)
                    if self.server is not None:
                        out.addQuestion(DNSQuestion(self.server,
                            _TYPE_A, _CLASS_IN))
                        out.addAnswerAtTime(zc.cache.getByDetails(self.server,
                            _TYPE_A, _CLASS_IN), now)
                    zc.send(out)
                    next = now + delay
                    delay = delay * 2