Code Monkey home page Code Monkey logo

dat-dns's Introduction

dat-dns

Issue DNS lookups for Dat archives using HTTPS requests to the target host. Keeps an in-memory cache of recent lookups.

API

var datDns = require('dat-dns')()

// resolve a name: pass the hostname by itself
datDns.resolveName('foo.com', function (err, key) { ... })
datDns.resolveName('foo.com').then(key => ...)

// dont use cached 'misses'
datDns.resolveName('foo.com', {ignoreCachedMiss: true})

// dont use the cache at all
datDns.resolveName('foo.com', {ignoreCache: true})

// list all entries in the cache
datDns.listCache()

// clear the cache
datDns.flushCache()

// use a persistent fallback cache
// (this is handy for persistent dns data when offline)
var datDns = require('dat-dns')({
  persistentCache: {
    read: async (name, err) => {
      // try lookup
      // if failed, you can throw the original error:
      throw err
    },
    write: async (name, key, ttl) => {
      // write to your cache
    }
  }
})

Spec

In detail.

Place a file at /.well-known/dat with the following schema:

{dat-url}
TTL={time in seconds}

TTL is optional and will default to 3600 (one hour). If set to 0, the entry is not cached.

Dat-name Resolution

Resolution of a site at dat://hostname will occur with the following process:

  • Browser checks its dat names cache. If a non-expired entry is found, return with the entry.
  • Browser issues a GET request to https://hostname/.well-known/dat.
  • If the server responds with a 404 Not Found status, store a null entry in the cache with a TTL of 3600 and return a failed lookup.
  • If the server responds with anything other than a 200 OK status, return a failed lookup.
  • If the server responds with a malformed file, return a failed lookup.
  • If the response includes no TTL, set to default 3600.
  • If the response includes a non-zero TTL, store the entry in the dat-name cache.
  • Return the entry.

dat-dns's People

Contributors

pfrazee avatar brechtcs avatar mafintosh avatar

Stargazers

 avatar

Watchers

James Cloos avatar Antoine Bluchet avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.