def messageReceived(self, message, proto, address=None):
        """
        L{DNSServerFactory.messageReceived} is called by protocols which are
        under the control of this L{DNSServerFactory} whenever they receive a
        DNS query message or an unexpected / duplicate / late DNS response
        message.

        L{DNSServerFactory.allowQuery} is called with the received message,
        protocol and origin address. If it returns L{False}, a C{dns.EREFUSED}
        response is sent back to the client.

        Otherwise the received message is dispatched to one of
        L{DNSServerFactory.handleQuery}, L{DNSServerFactory.handleInverseQuery},
        L{DNSServerFactory.handleStatus}, L{DNSServerFactory.handleNotify}, or
        L{DNSServerFactory.handleOther} depending on the I{OPCODE} of the
        received message.

        If C{DNSServerFactory.verbose} is C{>0} all received messages will be
        logged in more or less detail depending on the value of C{verbose}.

        @param message: The DNS message that was received.
        @type message: L{dns.Message}

        @param proto: The DNS protocol instance which received the message
        @type proto: L{dns.DNSDatagramProtocol} or L{dns.DNSProtocol}

        @param address: The address from which the message was received. Only
            provided for messages received by datagram protocols. The origin of
            Messages received from stream protocols can be gleaned from the
            protocol C{transport} attribute.
        @type address: L{tuple} or L{None}
        """
        message.timeReceived = time.time()

        if self.verbose:
            if self.verbose > 1:
                s = ' '.join([str(q) for q in message.queries])
            else:
                s = ' '.join([dns.QUERY_TYPES.get(q.type, 'UNKNOWN')
                              for q in message.queries])
            if not len(s):
                log.msg(
                    "Empty query from %r" % (
                        (address or proto.transport.getPeer()),))
            else:
                log.msg(
                    "%s query from %r" % (
                        s, address or proto.transport.getPeer()))

        if not self.allowQuery(message, proto, address):
            message.rCode = dns.EREFUSED
            self.sendReply(proto, message, address)
        elif message.opCode == dns.OP_QUERY:
            self.handleQuery(message, proto, address)
        elif message.opCode == dns.OP_INVERSE:
            self.handleInverseQuery(message, proto, address)
        elif message.opCode == dns.OP_STATUS:
            self.handleStatus(message, proto, address)
        elif message.opCode == dns.OP_NOTIFY:
            self.handleNotify(message, proto, address)
        else:
            self.handleOther(message, proto, address)

        L{DNSServerFactory.messageReceived} is called by protocols which are
        under the control of this L{DNSServerFactory} whenever they receive a
        DNS query message or an unexpected / duplicate / late DNS response
        message.

        L{DNSServerFactory.allowQuery} is called with the received message,
        protocol and origin address. If it returns L{False}, a C{dns.EREFUSED}
        response is sent back to the client.

        Otherwise the received message is dispatched to one of
        L{DNSServerFactory.handleQuery}, L{DNSServerFactory.handleInverseQuery},
        L{DNSServerFactory.handleStatus}, L{DNSServerFactory.handleNotify}, or
        L{DNSServerFactory.handleOther} depending on the I{OPCODE} of the
        received message.

        If C{DNSServerFactory.verbose} is C{>0} all received messages will be
        logged in more or less detail depending on the value of C{verbose}.

        @param message: The DNS message that was received.
        @type message: L{dns.Message}

        @param proto: The DNS protocol instance which received the message
        @type proto: L{dns.DNSDatagramProtocol} or L{dns.DNSProtocol}

        @param address: The address from which the message was received. Only
            provided for messages received by datagram protocols. The origin of
            Messages received from stream protocols can be gleaned from the
            protocol C{transport} attribute.
        @type address: L{tuple} or L{None}
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/names/server.py