Refactor formatTxtRecords as encodeKVasRFC1464

- Move the logic of rfc1035 out of the encoding function
  - Left basic version of encodingKV as 'k=v'
This commit is contained in:
Patrick Sodré 2017-08-10 01:00:06 -04:00 committed by Frank Schroeder
parent 655c89ee10
commit d5e3b9d843
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD
1 changed files with 8 additions and 10 deletions

View File

@ -536,15 +536,9 @@ RPC:
} }
} }
// formatTxtRecords takes a kv-map and returns it as "[k=]v" for non-empty k not starting with rfc1035- // encodeKVasRFC1464 encodes a key-value pair according to RFC1464
func (d *DNSServer) formatTxtRecords(meta map[string]string) (txt []string) { func (d *DNSServer) encodeKVasRFC1464(key, value string) (txt string) {
for k, v := range meta { txt = key + "=" + value
if strings.HasPrefix(k, "rfc1035-") {
txt = append(txt, v)
} else {
txt = append(txt, k+"="+v)
}
}
return txt return txt
} }
@ -611,7 +605,11 @@ func (d *DNSServer) formatNodeRecord(node *structs.Node, addr, qName string, qTy
} }
if node != nil && (qType == dns.TypeANY || qType == dns.TypeTXT) { if node != nil && (qType == dns.TypeANY || qType == dns.TypeTXT) {
for _, txt := range d.formatTxtRecords(node.Meta) { for key, value := range node.Meta {
txt := value
if !strings.HasPrefix(strings.ToLower(key), "rfc1035-") {
txt = d.encodeKVasRFC1464(key, value)
}
records = append(records, &dns.TXT{ records = append(records, &dns.TXT{
Hdr: dns.RR_Header{ Hdr: dns.RR_Header{
Name: qName, Name: qName,