move functions closer together
This commit is contained in:
parent
2fd0e458df
commit
e6e7649112
52
zone.go
52
zone.go
|
@ -15,7 +15,8 @@ import (
|
|||
// multilpe goroutines.
|
||||
type Zone struct {
|
||||
Origin string // Origin of the zone
|
||||
olabels []string // origin cut up in labels, just to speed up the isSubDomain method
|
||||
olen int // Origin length
|
||||
olabels []string // Origin cut up in labels, just to speed up the isSubDomain method
|
||||
Wildcard int // Whenever we see a wildcard name, this is incremented
|
||||
expired bool // Slave zone is expired
|
||||
ModTime time.Time // When is the zone last modified
|
||||
|
@ -82,7 +83,7 @@ func newSignatureConfig() *SignatureConfig {
|
|||
// Minttl value is zero.
|
||||
var DefaultSignatureConfig = newSignatureConfig()
|
||||
|
||||
// NewZone creates an initialized zone with Origin set to origin.
|
||||
// NewZone creates an initialized zone with Origin set to the lower cased origin.
|
||||
func NewZone(origin string) *Zone {
|
||||
if origin == "" {
|
||||
origin = "."
|
||||
|
@ -92,6 +93,7 @@ func NewZone(origin string) *Zone {
|
|||
}
|
||||
z := new(Zone)
|
||||
z.Origin = Fqdn(strings.ToLower(origin))
|
||||
z.olen = len(z.Origin)
|
||||
z.olabels = SplitLabels(z.Origin)
|
||||
z.Names = make(map[string]*ZoneData)
|
||||
z.RWMutex = new(sync.RWMutex)
|
||||
|
@ -174,6 +176,8 @@ func (z *Zone) Insert(r RR) error {
|
|||
return &Error{Err: "out of zone data", Name: r.Header().Name}
|
||||
}
|
||||
z.ModTime = time.Now().UTC()
|
||||
// Remove the origin from the ownername of the RR
|
||||
r.Header().Name = r.Header().Name[:len(r.Header().Name)-z.olen-1]
|
||||
zd, ok := z.Names[r.Header().Name]
|
||||
if !ok {
|
||||
// Check if it's a wildcard name
|
||||
|
@ -360,6 +364,28 @@ func (z *Zone) isSubDomain(child string) bool {
|
|||
return compareLabelsSlice(z.olabels, strings.ToLower(child)) == len(z.olabels)
|
||||
}
|
||||
|
||||
// compareLabels behaves exactly as CompareLabels expect that l1 is already
|
||||
// a tokenize (in labels) version of the domain name. This saves memory and is faster.
|
||||
func compareLabelsSlice(l1 []string, s2 string) (n int) {
|
||||
l2 := SplitLabels(s2)
|
||||
|
||||
x1 := len(l1) - 1
|
||||
x2 := len(l2) - 1
|
||||
for {
|
||||
if x1 < 0 || x2 < 0 {
|
||||
break
|
||||
}
|
||||
if l1[x1] == l2[x2] {
|
||||
n++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
x1--
|
||||
x2--
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Sign (re)signs the zone z with the given keys.
|
||||
// NSECs and RRSIGs are added as needed.
|
||||
// The public keys themselves are not added to the zone.
|
||||
|
@ -611,25 +637,3 @@ func jitterDuration(d time.Duration) time.Duration {
|
|||
}
|
||||
return -time.Duration(jitter)
|
||||
}
|
||||
|
||||
// compareLabels behaves exactly as CompareLabels expect that l1 is already
|
||||
// a tokenize (in labels) version of the domain name. This saves memory and is faster.
|
||||
func compareLabelsSlice(l1 []string, s2 string) (n int) {
|
||||
l2 := SplitLabels(s2)
|
||||
|
||||
x1 := len(l1) - 1
|
||||
x2 := len(l2) - 1
|
||||
for {
|
||||
if x1 < 0 || x2 < 0 {
|
||||
break
|
||||
}
|
||||
if l1[x1] == l2[x2] {
|
||||
n++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
x1--
|
||||
x2--
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue