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.source;
012
013import java.io.IOException;
014import java.net.InetAddress;
015
016import org.minidns.MiniDnsFuture;
017import org.minidns.dnsmessage.DnsMessage;
018import org.minidns.dnsqueryresult.DnsQueryResult;
019
020public interface DnsDataSource {
021
022    DnsQueryResult query(DnsMessage message, InetAddress address, int port) throws IOException;
023
024    MiniDnsFuture<DnsQueryResult, IOException> queryAsync(DnsMessage message, InetAddress address, int port, OnResponseCallback onResponseCallback);
025
026    int getUdpPayloadSize();
027
028    /**
029     * Retrieve the current dns query timeout, in milliseconds.
030     *
031     * @return the current dns query timeout in milliseconds.
032     */
033    int getTimeout();
034
035    /**
036     * Change the dns query timeout for all future queries. The timeout
037     * must be specified in milliseconds.
038     *
039     * @param timeout new dns query timeout in milliseconds.
040     */
041    void setTimeout(int timeout);
042
043    interface OnResponseCallback {
044        void onResponse(DnsMessage request, DnsQueryResult result);
045    }
046
047}