<commit_before>/*
 * dns.js
 */
"use strict";

global.include = function(f) { var fs = require('fs'); eval(fs.readFileSync(f)+''); }

include('project_ids.js');
include('config.js');

var dns = require('native-dns');
var util = require('util');
var gcp = require('./gcp');
var server = dns.createServer();

exports.serial = new Date().getTime() / 1000 | 0; /* serial number for this runtime */
    
// DNS query types
var A = 1;
var NS = 2;
var CNAME = 5;
var SOA = 6;
var PTR = 12;
var MX = 15;
var TXT = 16;

server.on('request', function(request, response) {
  if ([A, SOA].indexOf(request.question[0].type) == -1) {
    response.send();
    return;
  }
  
  var domain = request.question[0].name;
  
  /* foramt: <instance name>.<project id or alias>.<type>.foo.dont.care */
  /* type: i = internal, * (else) = external
   */
  var _s = domain.split(".");
  console.log(_s);
  
  var hostname = _s[0];
  var project = _s[1];
  var isInternal = (3 <= _s.length && 'i' == _s[2].toLowerCase());
  
  if (SOA == request.question[0].type) {
    var name = _s.slice((isInternal) ? 3 : 2).join('.');
    response.answer.push(dns.SOA({
      'name': name,
      'type': SOA,
      'primary': config['primary_ns'],
      'admin': config['soa_admin'],
      'serial': exports.serial,
      'ttl': config["default_ttl"],
      'refresh': 900,
      'retry': 900,
      'expiration': 1800,
      'minimum': 60
    }));<commit_msg>logging all request information to console<commit_after>/*
 * dns.js
 */
"use strict";

global.include = function(f) { var fs = require('fs'); eval(fs.readFileSync(f)+''); }

include('project_ids.js');
include('config.js');

var dns = require('native-dns');
var util = require('util');
var gcp = require('./gcp');
var server = dns.createServer();

exports.serial = new Date().getTime() / 1000 | 0; /* serial number for this runtime */
    
// DNS query types
var A = 1;
var NS = 2;
var CNAME = 5;
var SOA = 6;
var PTR = 12;
var MX = 15;
var TXT = 16;

server.on('request', function(request, response) {
  console.log(util.format("[%s] %s:%s Query: %s Type: %s",Date(), request.address.address, request.address.port, request.question[0].name, request.question[0].type))

  if ([A, SOA].indexOf(request.question[0].type) == -1) {
    response.send();
    return;
  }

  var domain = request.question[0].name;
  
  /* foramt: <instance name>.<project id or alias>.<type>.foo.dont.care */
  /* type: i = internal, * (else) = external
   */
  var _s = domain.split(".");
  console.log(_s);
  
  var hostname = _s[0];
  var project = _s[1];
  var isInternal = (3 <= _s.length && 'i' == _s[2].toLowerCase());
  
  if (SOA == request.question[0].type) {
    var name = _s.slice((isInternal) ? 3 : 2).join('.');
    response.answer.push(dns.SOA({
      'name': name,
      'type': SOA,
      'primary': config['primary_ns'],
      'admin': config['soa_admin'],
      'serial': exports.serial,
      'ttl': config["default_ttl"],
      'refresh': 900,
      'retry': 900,
      'expiration': 1800,
      'minimum': 60
    }));
{'fraction_non_alphanumeric': 0.2024358130348914, 'fraction_numerical': 0.025016458196181698, 'mean_word_length': 3.168724279835391, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '990241', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1094, 'n_words': 267}