Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- let dns = require('native-dns');
- let server = dns.createUDPServer({ dgram_type: 'udp6' });
- server.on('listening', () => console.log('server listening on', server.address()));
- server.on('close', () => console.log('server closed', server.address()));
- server.on('error', (err, buff, req, res) => console.error(err.stack));
- server.on('socketError', (err, socket) => console.error(err));
- server.serve(53, 'localhost');
- let authority = { address: '2001:4860:4860::8888', port: 53, type: 'udp' };
- function proxy(question, response, cb) {
- var request = dns.Request({
- question: question, // forwarding the question
- server: authority, // this is the DNS server we are asking
- timeout: 1000
- });
- // when we get answers, append them to the response
- request.on('message', (err, msg) => {
- msg.answer.forEach(a => {
- if (a.type != 1) {
- response.answer.push(a);
- }
- });
- });
- request.on('end', cb);
- request.send();
- }
- let async = require('async');
- function handleRequest(request, response) {
- let f = []; // array of functions
- // proxy all questions
- // since proxying is asynchronous, store all callbacks
- request.question.forEach(question => {
- f.push(cb => proxy(question, response, cb));
- });
- // do the proxying in parallel
- // when done, respond to the request by sending the response
- async.parallel(f, function() { response.send(); });
- }
- server.on('request', handleRequest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement