Use Radix tree for the mux

This commit is contained in:
Miek Gieben 2012-08-05 08:13:09 +02:00
parent 4668fcfee4
commit 77b74b02b0
2 changed files with 11 additions and 7 deletions

View File

@ -99,11 +99,12 @@ func ListenAndServeTsig(addr string, network string, handler Handler, tsig map[s
func (mux *ServeMux) match(zone string, t uint16) Handler {
// Exact match
if h := mux.m.Find(zone); h.Value != nil {
zone = toRadixName(zone)
if h := mux.m.Find(zone); h != nil && h.Value != nil {
return h.Value.(Handler)
}
// Best matching
if h := mux.m.Predecessor(zone); h.Value != nil {
if h := mux.m.Predecessor(zone); h != nil && h.Value != nil {
return h.Value.(Handler)
}
return nil
@ -114,7 +115,7 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
if pattern == "" {
panic("dns: invalid pattern " + pattern)
}
mux.m.Insert(Fqdn(pattern), handler)
mux.m.Insert(toRadixName(Fqdn(pattern)), handler)
}
// Handle adds a handler to the ServeMux for pattern.
@ -128,7 +129,7 @@ func (mux *ServeMux) HandleRemove(pattern string) {
panic("dns: invalid pattern " + pattern)
}
// if its there, its gone
mux.m.Remove(Fqdn(pattern))
mux.m.Remove(toRadixName(Fqdn(pattern)))
}
// ServeDNS dispatches the request to the handler whose

View File

@ -15,8 +15,8 @@ type Zone struct {
// ZoneData holds all the RRs having their ownername equal to Name.
type ZoneData struct {
Name string // Domain name for this node
RR map[uint16][]RR // Map of the RR type to the RR
Name string // Domain name for this node
RR map[uint16][]RR // Map of the RR type to the RR
Signatures map[uint16][]*RR_RRSIG // DNSSEC signatures for the RRs, stored under type covered
// Always false, except for NSsets that differ from z.Origin
NonAuth bool
@ -26,11 +26,14 @@ type ZoneData struct {
// we preserve the nsec ordering of the zone (this idea was stolen from NSD).
// each label is also lowercased.
func toRadixName(d string) string {
if d == "." {
return "."
}
s := ""
for _, l := range SplitLabels(d) {
s = strings.ToLower(l) + "." + s
}
return s
return "." + s
}
// NewZone creates an initialized zone with Origin set to origin.