<commit_before>package dns

// A concurrent client implementation. 
// Client sends query to a channel which
// will then handle the query. Returned replys
// are return on another channel. Ready for handling --- same
// setup for server - a HANDLER function that gets run
// when the query returns.

// This completely mirrors server.go impl.
import (
	"os"
	"net"
)

type QueryHandler interface {
	QueryDNS(w RequestWriter, q *Msg)
}


// A RequestWriter interface is used by an DNS query handler to
// construct an DNS request.
type RequestWriter interface {
	RemoteAddr() string     // moet het channel zijn...!

	Write([]byte) (int, os.Error)
}

type qconn struct {
	remoteAddr net.Addr  // address of remote side (sans port)
	port       int       // port of the remote side, needed TODO(mg)
	handler    Handler   // request handler
	request    []byte    //  the request
	w          chan *Msg //
	hijacked   bool      // connection has been hijacked by hander TODO(mg)
}

type reply struct {
	conn *qconn
	req  *Msg
}

// QueryMux is an DNS request multiplexer. It matches the
// zone name of each incoming request against a list of 
// registered patterns add calls the handler for the pattern
// that most closely matches the zone name.
type QueryMux struct {
	m map[string]QueryHandler
}

// NewQueryMux allocates and returns a new QueryMux.
func NewQueryMux() *QueryMux { return &QueryMux{make(map[string]QueryHandler)} }

// DefaultQueryMux is the default QueryMux used by Query.
var DefaultQueryMux = NewQueryMux()

// The HandlerQueryFunc type is an adapter to allow the use of
// ordinary functions as DNS query handlers.  If f is a function
// with the appropriate signature, HandlerQueryFunc(f) is a
// QeuryHandler object that calls f.
type HandlerQueryFunc func(RequestWriter, *Msg)

// QueryDNS calls f(w, reg)
func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg) {
	f(w, r)
}

// Helper handlers
// Todo

// reusing zoneMatch from server.go
func (mux *QueryMux) match(zone string) QueryHandler {
	var h QueryHandler
	var n = 0
	for k, v := range mux.m {
		if !zoneMatch(k, zone) {<commit_msg>Create a DefaultQueryChan<commit_after>package dns

// A concurrent client implementation. 
// Client sends query to a channel which
// will then handle the query. Returned replys
// are return on another channel. Ready for handling --- same
// setup for server - a HANDLER function that gets run
// when the query returns.

// This completely mirrors server.go impl.
import (
	"os"
	"net"
)

type QueryHandler interface {
	QueryDNS(w RequestWriter, q *Msg)
}

// A RequestWriter interface is used by an DNS query handler to
// construct an DNS request.
type RequestWriter interface {
	RemoteAddr() string     // moet het channel zijn...!

	Write([]byte) (int, os.Error)
}

type qconn struct {
	remoteAddr net.Addr  // address of remote side (sans port)
	port       int       // port of the remote side, needed TODO(mg)
	handler    Handler   // request handler
	request    []byte    //  the request
	w          chan *Msg //
	hijacked   bool      // connection has been hijacked by hander TODO(mg)
}

type reply struct {
	conn *qconn
	req  *Msg
}

// QueryMux is an DNS request multiplexer. It matches the
// zone name of each incoming request against a list of 
// registered patterns add calls the handler for the pattern
// that most closely matches the zone name.
type QueryMux struct {
	m map[string]QueryHandler
}

// NewQueryMux allocates and returns a new QueryMux.
func NewQueryMux() *QueryMux { return &QueryMux{make(map[string]QueryHandler)} }

// DefaultQueryMux is the default QueryMux used by Query.
var DefaultQueryMux = NewQueryMux()

func newQueryChan() chan *Msg { return make(chan *Msg) }

// Default channel to use for the resolver
var DefaultQueryChan = newQueryChan()

// The HandlerQueryFunc type is an adapter to allow the use of
// ordinary functions as DNS query handlers.  If f is a function
// with the appropriate signature, HandlerQueryFunc(f) is a
// QeuryHandler object that calls f.
type HandlerQueryFunc func(RequestWriter, *Msg)

// QueryDNS calls f(w, reg)
func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg) {
	f(w, r)
}

// Helper handlers
// Todo

// reusing zoneMatch from server.go
func (mux *QueryMux) match(zone string) QueryHandler {
	var h QueryHandler
	var n = 0
	for k, v := range mux.m {
		if !zoneMatch(k, zone) {
{'fraction_non_alphanumeric': 0.0863916115796672, 'fraction_numerical': 0.00045589240939138365, 'mean_word_length': 3.3316880552813424, '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': '5720290', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1296, 'n_words': 563}