How to use the dns-packet.RECURSION_DESIRED function in dns-packet

To help you get started, we’ve selected a few dns-packet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github android-js / androidjs-builder / example / helloworld / node_modules / dns-socket / index.js View on Github external
const cnameresults = result.answers.filter(e => e.type === 'CNAME')
  if (cnameresults.length === 0) {
    return false
  }

  const id = this._getNextEmptyId()
  if (id === -1) {
    q.callback(new Error('Query array is full!'))
    return true
  }

  // replace current query with a new one
  q.query = {
    id: id + 1,
    flags: packet.RECURSION_DESIRED,
    questions: [{
      type: 'A',
      name: cnameresults[0].data
    }]
  }
  q.redirects++
  q.firstTry = Date.now()
  q.tries = 0
  q.buffer = packet.encode(q.query)
  this._queries[id] = q
  this.socket.send(q.buffer, 0, q.buffer.length, q.port, Array.isArray(q.host) ? q.host[Math.floor(q.host.length * Math.random())] : q.host || '127.0.0.1')
  return true
}
github ipfs / js-ipfs / src / core / ipns / routing / dns-datastore.js View on Github external
function dohBinary (key, callback) {
  const cid = new Cid(key.slice(ipns.namespaceLength))
  const buf = dnsPacket.encode({
    type: 'query',
    id: getRandomInt(1, 65534),
    flags: dnsPacket.RECURSION_DESIRED,
    questions: [{
      type: 'TXT',
      name: `${cid.toV1().toString()}.dns.ipns.dev`
    }]
  })
  // https://dns.google.com/experimental
  // https://cloudflare-dns.com/dns-query
  // https://mozilla.cloudflare-dns.com/dns-query
  ky
    .get('https://cloudflare-dns.com/dns-query', {
      searchParams: {
        dns: buf.toString('base64')
      },
      headers: {
        accept: 'application/dns-message'
      }
github mafintosh / dns-socket / index.js View on Github external
const cnameresults = result.answers.filter(e => e.type === 'CNAME')
  if (cnameresults.length === 0) {
    return false
  }

  const id = this._getNextEmptyId()
  if (id === -1) {
    q.callback(new Error('Query array is full!'))
    return true
  }

  // replace current query with a new one
  q.query = {
    id: id + 1,
    flags: packet.RECURSION_DESIRED,
    questions: [{
      type: 'A',
      name: cnameresults[0].data
    }]
  }
  q.redirects++
  q.firstTry = Date.now()
  q.tries = 0
  q.buffer = packet.encode(q.query)
  this._queries[id] = q
  this.socket.send(q.buffer, 0, q.buffer.length, q.port, Array.isArray(q.host) ? q.host[Math.floor(q.host.length * Math.random())] : q.host || '127.0.0.1')
  return true
}
github sagi / node-dns-over-tls / src / dnstls.ts View on Github external
// const tls = require('tls');
// const crypto = require('crypto');
// const dnsPacket = require('dns-packet');
import { randomBytes } from 'crypto';
import * as dnsPacket from 'dns-packet';
import { connect } from 'tls';

export const TWO_BYTES = 2;
export const DEFAULT_TYPE = 'A';
export const DEFAULT_PORT = 853;
export const DEFAULT_HOST = '1.1.1.1';
export const DEFAULT_CLASS = 'IN';
export const DEFAULT_SERVERNAME = 'cloudflare-dns.com';
export const RECURSION_DESIRED = dnsPacket.RECURSION_DESIRED;

export const randomId = () => randomBytes(TWO_BYTES).readUInt16BE(0);

interface ICheckDoneParams {
  response: Buffer;
  packetLength: number;
  socket: NodeJS.WriteStream;
  resolve: (responseObj: object) => void;
}

export const checkDone = ({
  response,
  packetLength,
  socket,
  resolve,
}: ICheckDoneParams) => {
github android-js / androidjs-builder / example / helloworld / node_modules / dns-socket / index.js View on Github external
self._ontimeoutCheck()
  }

  function onlistening () {
    self._interval = setInterval(ontimeoutCheck, self.timeoutChecks)
    self.emit('listening')
  }

  function onclose () {
    self.emit('close')
  }
}

util.inherits(DNS, events.EventEmitter)

DNS.RECURSION_DESIRED = DNS.prototype.RECURSION_DESIRED = packet.RECURSION_DESIRED
DNS.RECURSION_AVAILABLE = DNS.prototype.RECURSION_AVAILABLE = packet.RECURSION_AVAILABLE
DNS.TRUNCATED_RESPONSE = DNS.prototype.TRUNCATED_RESPONSE = packet.TRUNCATED_RESPONSE
DNS.AUTHORITATIVE_ANSWER = DNS.prototype.AUTHORITATIVE_ANSWER = packet.AUTHORITATIVE_ANSWER
DNS.AUTHENTIC_DATA = DNS.prototype.AUTHENTIC_DATA = packet.AUTHENTIC_DATA
DNS.CHECKING_DISABLED = DNS.prototype.CHECKING_DISABLED = packet.CHECKING_DISABLED

DNS.prototype.address = function () {
  return this.socket.address()
}

DNS.prototype.bind = function (...args) {
  const onlistening = args.length > 0 && args[args.length - 1]
  if (typeof onlistening === 'function') {
    this.once('listening', onlistening)
    this.socket.bind(...args.slice(0, -1))
  } else {
github mafintosh / dns-socket / index.js View on Github external
self._ontimeoutCheck()
  }

  function onlistening () {
    self._interval = setInterval(ontimeoutCheck, self.timeoutChecks)
    self.emit('listening')
  }

  function onclose () {
    self.emit('close')
  }
}

util.inherits(DNS, events.EventEmitter)

DNS.RECURSION_DESIRED = DNS.prototype.RECURSION_DESIRED = packet.RECURSION_DESIRED
DNS.RECURSION_AVAILABLE = DNS.prototype.RECURSION_AVAILABLE = packet.RECURSION_AVAILABLE
DNS.TRUNCATED_RESPONSE = DNS.prototype.TRUNCATED_RESPONSE = packet.TRUNCATED_RESPONSE
DNS.AUTHORITATIVE_ANSWER = DNS.prototype.AUTHORITATIVE_ANSWER = packet.AUTHORITATIVE_ANSWER
DNS.AUTHENTIC_DATA = DNS.prototype.AUTHENTIC_DATA = packet.AUTHENTIC_DATA
DNS.CHECKING_DISABLED = DNS.prototype.CHECKING_DISABLED = packet.CHECKING_DISABLED

DNS.prototype.address = function () {
  return this.socket.address()
}

DNS.prototype.bind = function (...args) {
  const onlistening = args.length > 0 && args[args.length - 1]
  if (typeof onlistening === 'function') {
    this.once('listening', onlistening)
    this.socket.bind(...args.slice(0, -1))
  } else {
github commonshost / bulldohzer / source / bulldohzer.js View on Github external
return new Promise((resolve, reject) => {
    const message = dnsPacket.encode({
      id: 0,
      type: 'query',
      flags: dnsPacket.RECURSION_DESIRED,
      questions: [{ name, type: rrtype }]
    })
    const headers = {}
    headers[HTTP2_HEADER_ACCEPT] = 'application/dns-message'
    headers[HTTP2_HEADER_METHOD] = HTTP2_METHOD_POST
    headers[HTTP2_HEADER_CONTENT_TYPE] = 'application/dns-message'
    headers[HTTP2_HEADER_CONTENT_LENGTH] = message.byteLength
    headers[HTTP2_HEADER_PATH] = path
    const timeout = setTimeout(() => {
      reject(new Error('Request timeout'))
    }, TIMEOUT_REQUEST)
    performance.mark('dns-before')
    let stream
    try {
      stream = session.request(headers)
    } catch (error) {