Skip to content

Commit

Permalink
cmd/devp2p: fix Route53 TXT record splitting (ethereum#20626)
Browse files Browse the repository at this point in the history
For longer records and subtree entries, the deployer created two
separate TXT records. This doesn't work as intended because the client
will receive the two records in arbitrary order. The fix is to encode
longer values as "string1""string2" instead of "string1", "string2".
This encoding creates a single record on AWS Route53.
  • Loading branch information
fjl authored Feb 5, 2020
1 parent a1313b5 commit 976a0f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
28 changes: 8 additions & 20 deletions cmd/devp2p/dns_route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (c *route53Client) computeChanges(name string, records map[string]string, e
}

prevRecords, exists := existing[path]
prevValue := combineTXT(prevRecords.values)
prevValue := strings.Join(prevRecords.values, "")
if !exists {
// Entry is unknown, push a new one
log.Info(fmt.Sprintf("Creating %s = %q", path, val))
Expand All @@ -191,8 +191,8 @@ func (c *route53Client) computeChanges(name string, records map[string]string, e
continue
}
// Stale entry, nuke it.
log.Info(fmt.Sprintf("Deleting %s = %q", path, combineTXT(set.values)))
changes = append(changes, newTXTChange("DELETE", path, set.ttl, set.values))
log.Info(fmt.Sprintf("Deleting %s = %q", path, strings.Join(set.values, "")))
changes = append(changes, newTXTChange("DELETE", path, set.ttl, set.values...))
}

sortChanges(changes)
Expand Down Expand Up @@ -263,7 +263,7 @@ func (c *route53Client) collectRecords(name string) (map[string]recordSet, error
}

// newTXTChange creates a change to a TXT record.
func newTXTChange(action, name string, ttl int64, values []string) *route53.Change {
func newTXTChange(action, name string, ttl int64, values ...string) *route53.Change {
var c route53.Change
var r route53.ResourceRecordSet
var rrs []*route53.ResourceRecord
Expand All @@ -288,28 +288,16 @@ func isSubdomain(name, domain string) bool {
return strings.HasSuffix("."+name, "."+domain)
}

// combineTXT concatenates the given quoted strings into a single unquoted string.
func combineTXT(values []string) string {
result := ""
for _, v := range values {
if v[0] == '"' {
v = v[1 : len(v)-1]
}
result += v
}
return result
}

// splitTXT splits value into a list of quoted 255-character strings.
func splitTXT(value string) []string {
var result []string
func splitTXT(value string) string {
var result strings.Builder
for len(value) > 0 {
rlen := len(value)
if rlen > 253 {
rlen = 253
}
result = append(result, strconv.Quote(value[:rlen]))
result.WriteString(strconv.Quote(value[:rlen]))
value = value[rlen:]
}
return result
return result.String()
}
6 changes: 2 additions & 4 deletions cmd/devp2p/dns_route53_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
func TestRoute53ChangeSort(t *testing.T) {
testTree0 := map[string]recordSet{
"2kfjogvxdqtxxugbh7gs7naaai.n": {ttl: 3333, values: []string{
`"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-"`,
`"vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`,
`"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-""vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`,
}},
"fdxn3sn67na5dka4j2gok7bvqi.n": {ttl: treeNodeTTL, values: []string{`"enrtree-branch:"`}},
"n": {ttl: rootTTL, values: []string{`"enrtree-root:v1 e=2KFJOGVXDQTXXUGBH7GS7NAAAI l=FDXN3SN67NA5DKA4J2GOK7BVQI seq=0 sig=v_-J_q_9ICQg5ztExFvLQhDBGMb0lZPJLhe3ts9LAcgqhOhtT3YFJsl8BWNDSwGtamUdR-9xl88_w-X42SVpjwE"`}},
Expand Down Expand Up @@ -116,8 +115,7 @@ func TestRoute53ChangeSort(t *testing.T) {
ResourceRecordSet: &route53.ResourceRecordSet{
Name: sp("2kfjogvxdqtxxugbh7gs7naaai.n"),
ResourceRecords: []*route53.ResourceRecord{
{Value: sp(`"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-"`)},
{Value: sp(`"vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`)},
{Value: sp(`"enr:-HW4QO1ml1DdXLeZLsUxewnthhUy8eROqkDyoMTyavfks9JlYQIlMFEUoM78PovJDPQrAkrb3LRJ-""vtrymDguKCOIAWAgmlkgnY0iXNlY3AyNTZrMaEDffaGfJzgGhUif1JqFruZlYmA31HzathLSWxfbq_QoQ4"`)},
},
TTL: ip(3333),
Type: sp("TXT"),
Expand Down

0 comments on commit 976a0f5

Please sign in to comment.