A zone impl
This commit is contained in:
parent
68f08416ff
commit
38f7400e18
33
zone.go
33
zone.go
|
@ -3,33 +3,50 @@ package dns
|
||||||
// A structure for handling zone data
|
// A structure for handling zone data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/petar/GoLLRB/llrb"
|
"github.com/miekg/radix"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Zone struct {
|
type Zone struct {
|
||||||
Name string // Name of the zone
|
Name string // Name of the zone
|
||||||
*llrb.Tree // Zone data
|
*radix.Radix // Zone data
|
||||||
}
|
}
|
||||||
|
|
||||||
type ZoneData struct {
|
type ZoneData struct {
|
||||||
Name string // Domain name for this node
|
Name string // Domain name for this node
|
||||||
RR map[uint16][]RR // Map ...
|
RR map[uint16][]RR // Map of the RR type to the RR
|
||||||
Signatures map[uint16][]*RR_RRSIG // DNSSEC signatures
|
Signatures []*RR_RRSIG // DNSSEC signatures
|
||||||
Glue bool // True if the A and AAAA record are glue
|
Glue bool // True if the A and AAAA record are glue
|
||||||
}
|
}
|
||||||
|
|
||||||
func lessZone(a, b interface{}) bool { return a.(string) < b.(string) }
|
|
||||||
|
|
||||||
// New ...
|
// New ...
|
||||||
func New(name string) *Zone {
|
func New(name string) *Zone {
|
||||||
z := new(Zone)
|
z := new(Zone)
|
||||||
z.Name = name
|
z.Name = name
|
||||||
z.Tree = llrb.New(lessZone)
|
z.Radix = radix.New()
|
||||||
return z
|
return z
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zone) Insert(r RR) {
|
func (z *Zone) Insert(r RR) {
|
||||||
zd := z.Tree.Get(r.Header().Name)
|
zd := z.Radix.Find(r.Header().Name)
|
||||||
|
if zd == nil {
|
||||||
|
zd := new(ZoneData)
|
||||||
|
zd.Name = r.Header().Name
|
||||||
|
switch t := r.Header().Rrtype; t {
|
||||||
|
case TypeRRSIG:
|
||||||
|
zd.Signatures = append(zd.Signatures, r.(*RR_RRSIG))
|
||||||
|
default:
|
||||||
|
zd.RR[t] = append(zd.RR[t], r)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch t := r.Header().Rrtype; t {
|
||||||
|
case TypeRRSIG:
|
||||||
|
zd.(*ZoneData).Signatures = append(zd.(*ZoneData).Signatures, r.(*RR_RRSIG))
|
||||||
|
default:
|
||||||
|
zd.(*ZoneData).RR[t] = append(zd.(*ZoneData).RR[t], r)
|
||||||
|
}
|
||||||
|
// TODO(mg): Glue
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zone) Remove(r RR) {
|
func (z *Zone) Remove(r RR) {
|
||||||
|
|
Loading…
Reference in New Issue