Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions internal/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,47 +552,53 @@ func randomFallbackServer() string {
}

func formatMessageAnswerSection(section []dns.RR) string {
ret := "[ "
var sb strings.Builder
sb.WriteByte('[')
sb.WriteByte(' ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not sb.WriteString("[ ") to save a call?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more efficient than a WriteString

for idx, rr := range section {
ret += fmt.Sprintf(
"< %s >",
strings.ReplaceAll(
strings.TrimPrefix(
rr.String(),
";",
),
"\t",
" ",
sb.WriteByte('<')
sb.WriteByte(' ')
sb.WriteString(strings.ReplaceAll(
strings.TrimPrefix(
rr.String(),
";",
),
)
"\t",
" ",
))
sb.WriteByte('>')
sb.WriteByte(' ')
if idx != len(section)-1 {
ret += `,`
sb.WriteByte(',')
}
ret += ` `
sb.WriteByte(' ')
}
ret += "]"
return ret
sb.WriteByte(']')
return sb.String()
}

func formatMessageQuestionSection(section []dns.Question) string {
ret := "[ "
var sb strings.Builder
sb.WriteByte('[')
sb.WriteByte(' ')
for idx, question := range section {
ret += fmt.Sprintf(
"< %s >",
strings.ReplaceAll(
strings.TrimPrefix(
question.String(),
";",
),
"\t",
" ",
sb.WriteByte('<')
sb.WriteByte(' ')
sb.WriteString(strings.ReplaceAll(
strings.TrimPrefix(
question.String(),
";",
),
)
"\t",
" ",
))
sb.WriteByte('>')
sb.WriteByte(' ')
if idx != len(section)-1 {
ret += `,`
sb.WriteByte(',')
}
ret += ` `
sb.WriteByte(' ')
}
ret += "]"
return ret
sb.WriteByte(']')
return sb.String()
}
11 changes: 6 additions & 5 deletions internal/handshake/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"io"
"net"
"strings"
)

const (
Expand Down Expand Up @@ -282,8 +283,8 @@ func domainRecordIPv6Decode(r *BytesReader) (net.IP, error) {
}

func domainRecordNameDecode(r *BytesReader) (string, error) {
var sb strings.Builder
// NOTE: this function is mostly ported straight from hnsd
var name string
for {
c, err := r.ReadByte()
if err != nil {
Expand Down Expand Up @@ -311,10 +312,10 @@ func domainRecordNameDecode(r *BytesReader) (string, error) {
if b == 0x2e {
b = 0xfe
}
name += string([]byte{b})
sb.WriteByte(b)
}
if len(name) > 0 {
name += "."
if sb.Len() > 0 {
sb.WriteByte('.')
}
case 0xc0:
// Lookup name from earlier in the buffer
Expand All @@ -338,5 +339,5 @@ func domainRecordNameDecode(r *BytesReader) (string, error) {
return "", errors.New("unexpected value")
}
}
return name, nil
return sb.String(), nil
}
Loading