<commit_before>package main

import (
	"dns"
	"log"
)

func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
	if z == nil {
		panic("fks: no zone")
	}
	if *l {
		log.Printf("fks: [zone %s] incoming %s %s %d\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id)
	}
	// Referral
	// if we find something with NonAuth = true, it means
	// we need to return referral
	nss := z.Predecessor(req.Question[0].Name)
	m := new(dns.Msg)
	if nss != nil && nss.NonAuth {
		m.SetReply(req)
		m.Ns = nss.RR[dns.TypeNS]
		// lookup the a records for additional, only when
		// in baliwick
		w.Write(m)
		return
	}

	// Wildcards...?
	// If we don't have the name return NXDOMAIN
	node := z.Find(req.Question[0].Name)
	if node == nil {
		m.SetRcode(req, dns.RcodeNameError)
		w.Write(m)
		return
	}

	// We have the name it isn't a referral, but it may that
	// we still have NSs for this name. If we have nss and they
	// are NonAuth true return those.
	if nss, ok := node.RR[dns.TypeNS]; ok && node.NonAuth {
		m.SetReply(req)
		m.Ns = nss
		// lookup the a records for additional, only when
		// in baliwick
		w.Write(m)
		return
	}

	apex := z.Find(z.Origin)

	if rrs, ok := node.RR[req.Question[0].Qtype]; ok {
		m.SetReply(req)
		m.MsgHdr.Authoritative = true
		m.Answer = rrs
		m.Ns = apex.RR[dns.TypeNS]
		w.Write(m)
		return
	} else { // NoData reply or CNAME
		m.SetReply(req)
		m.Ns = apex.RR[dns.TypeSOA]
		w.Write(m)
		return
	}
	m.SetRcode(req, dns.RcodeNameError)
	w.Write(m)
}
<commit_msg>tweaks<commit_after>package main

import (
	"dns"
	"log"
)

func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
	if z == nil {
		panic("fks: no zone")
	}
	if *l {
		log.Printf("fks: [zone %s] incoming %s %s %d\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id)
	}
	// Referral
	// if we find something with NonAuth = true, it means
	// we need to return referral
	nss := z.Predecessor(req.Question[0].Name)
	m := new(dns.Msg)
	if nss != nil && nss.NonAuth {
		m.SetReply(req)
		m.Ns = nss.RR[dns.TypeNS]
		for _, n := range m.Ns {

		}

		// lookup the a records for additional, only when
		// in baliwick
		w.Write(m)
		return
	}

	// Wildcards...?
	// If we don't have the name return NXDOMAIN
	node := z.Find(req.Question[0].Name)
	if node == nil {
		m.SetRcode(req, dns.RcodeNameError)
		w.Write(m)
		return
	}

	// We have the name it isn't a referral, but it may that
	// we still have NSs for this name. If we have nss and they
	// are NonAuth true return those.
	if nss, ok := node.RR[dns.TypeNS]; ok && node.NonAuth {
		m.SetReply(req)
		m.Ns = nss
		// lookup the a records for additional, only when
		// in baliwick
		w.Write(m)
		return
	}

	apex := z.Find(z.Origin)

	if rrs, ok := node.RR[req.Question[0].Qtype]; ok {
		m.SetReply(req)
		m.MsgHdr.Authoritative = true
		m.Answer = rrs
		m.Ns = apex.RR[dns.TypeNS]
		w.Write(m)
		return
	} else { // NoData reply or CNAME
		m.SetReply(req)
		m.Ns = apex.RR[dns.TypeSOA]
		w.Write(m)
		return
	}
	m.SetRcode(req, dns.RcodeNameError)
	w.Write(m)
}

{'fraction_non_alphanumeric': 0.15444516547696302, 'fraction_numerical': 0.003244646333549643, 'mean_word_length': 2.85375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '456036', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1310, 'n_words': 338}