001/*
002 * Copyright 2015-2024 the original author or authors
003 *
004 * This software is licensed under the Apache License, Version 2.0,
005 * the GNU Lesser General Public License version 2 or later ("LGPL")
006 * and the WTFPL.
007 * You may choose either license to govern your use of this software only
008 * upon the condition that you accept all of the terms of either
009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL.
010 */
011package org.minidns.dnsqueryresult;
012
013import org.minidns.dnsmessage.DnsMessage;
014import org.minidns.dnsmessage.DnsMessage.RESPONSE_CODE;
015
016public abstract class DnsQueryResult {
017
018    public enum QueryMethod {
019        udp,
020        tcp,
021        asyncUdp,
022        asyncTcp,
023        cachedDirect,
024        cachedSynthesized,
025        testWorld,
026    }
027
028    public final QueryMethod queryMethod;
029
030    public final DnsMessage query;
031
032    public final DnsMessage response;
033
034    protected DnsQueryResult(QueryMethod queryMethod, DnsMessage query, DnsMessage response) {
035        assert queryMethod != null;
036        assert query != null;
037        assert response != null;
038
039        this.queryMethod = queryMethod;
040        this.query = query;
041        this.response = response;
042    }
043
044    @Override
045    public String toString() {
046        return response.toString();
047    }
048
049    public boolean wasSuccessful() {
050        return response.responseCode == RESPONSE_CODE.NO_ERROR;
051    }
052}