net.i2p.util

## Class DNSOverHTTPS

- java.lang.Object
- - net.i2p.util.DNSOverHTTPS

- All Implemented Interfaces:
    EepGet.StatusListener

      public class DNSOverHTTPS
      extends Object
      implements EepGet.StatusListener

  Simple implemetation of DNS over HTTPS. Also sets the local clock from the received date header. Warning - not thread-safe. Create new instances as necessary. As of 0.9.49, this supports the RFC 8484 (DNS) format only. Does NOT support the JSON format (used prior to 0.9.49) or RFC 7858 (DNS over TLS). https://developers.google.com/speed/public-dns/docs/dns-over-https https://developers.cloudflare.com/1.1.1.1/dns-over-https/json-format/ https://github.com/curl/curl/wiki/DNS-over-HTTPS

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `DNSOverHTTPS.Type` DNS query type for IPv4/IPv6 preference.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `UA_CLEARNET` ESR version of Firefox, same as Tor Browser

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DNSOverHTTPS(I2PAppContext context)`
    `DNSOverHTTPS(I2PAppContext context, SSLEepGet.SSLState sslState)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)`
    `void` | `attempting(String url)`
    `void` | `bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)` Total length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls
    `static void` | `clearCaches()`
    `void` | `headerReceived(String url, int attemptNum, String key, String val)` Use the Date header as a backup time source.
    `String` | `lookup(String host)` V4_ONLY unless we have only IPv6 address, then V6_ONLY
    `String` | `lookup(String host, DNSOverHTTPS.Type type)` Lookup in cache, then query servers
    `static void` | `main(String[] args)`
    `void` | `transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)`
    `void` | `transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### UA_CLEARNET

          public static final String UA_CLEARNET

      ESR version of Firefox, same as Tor Browser
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### DNSOverHTTPS

          public DNSOverHTTPS(I2PAppContext context)

    - #### DNSOverHTTPS

          public DNSOverHTTPS(I2PAppContext context,
                              SSLEepGet.SSLState sslState)

  - ### Method Detail

    - #### attemptFailed

          public void attemptFailed(String url,
                                    long bytesTransferred,
                                    long bytesRemaining,
                                    int currentAttempt,
                                    int numRetries,
                                    Exception cause)

      Specified by:
        `attemptFailed` in interface `EepGet.StatusListener`
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`

    - #### attempting

          public void attempting(String url)

      Specified by:
        `attempting` in interface `EepGet.StatusListener`

    - #### bytesTransferred

          public void bytesTransferred(long alreadyTransferred,
                                       int currentWrite,
                                       long bytesTransferred,
                                       long bytesRemaining,
                                       String url)

      Description copied from interface: `EepGet.StatusListener`
      Total length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls
      Specified by:
        `bytesTransferred` in interface `EepGet.StatusListener`
      Parameters:
        `alreadyTransferred` - total of all attempts, not including currentWrite If nonzero on the first call, a partial file of that length was found, _and_ the server supports resume. If zero on a subsequent call after some bytes are transferred (and presumably after an attemptFailed), the server does _not_ support resume and we had to start over. To track _actual_ transfer if the output file could already exist, the listener should keep its own counter, or subtract the initial alreadyTransferred value. And watch out for alreadyTransferred resetting if a resume failed...
        `currentWrite` - since last call to the listener
        `bytesTransferred` - includes headers, retries, redirects, discarded partial downloads, ...
        `bytesRemaining` - on this attempt only, currentWrite already subtracted - or -1 if chunked encoding or server does not return a length

    - #### clearCaches

          public static void clearCaches()

    - #### headerReceived

          public void headerReceived(String url,
                                     int attemptNum,
                                     String key,
                                     String val)

      Use the Date header as a backup time source. Code from Reseeder. We set the stratum to a lower (better) value than in Reseeder, as Cloudflare and Google probably have a better idea than our reseeds.
      Specified by:
        `headerReceived` in interface `EepGet.StatusListener`

    - #### lookup

          public String lookup(String host)

      V4_ONLY unless we have only IPv6 address, then V6_ONLY
      Returns:
        null if not found

    - #### lookup

          public String lookup(String host,
                               DNSOverHTTPS.Type type)

      Lookup in cache, then query servers
      Returns:
        null if not found

    - #### main

          public static void main(String[] args)

    - #### transferComplete

          public void transferComplete(long alreadyTransferred,
                                       long bytesTransferred,
                                       long bytesRemaining,
                                       String url,
                                       String outputFile,
                                       boolean notModified)

      Specified by:
        `transferComplete` in interface `EepGet.StatusListener`
        `outputFile` - null if unknown (output stream constructor)
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`

    - #### transferFailed

          public void transferFailed(String url,
                                     long bytesTransferred,
                                     long bytesRemaining,
                                     int currentAttempt)

      Specified by:
        `transferFailed` in interface `EepGet.StatusListener`
      See Also:
        `EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)`