lnwire: let DNSAddress implement RecordProducer

In preparation for using this type as a TLV record, we let it implement
the RecordProducer interface.
This commit is contained in:
Elle Mouton
2025-09-22 12:09:46 +02:00
parent e9a4f22dd6
commit e24dd2f9e0
3 changed files with 204 additions and 0 deletions

View File

@@ -1867,3 +1867,24 @@ func (c *Error) RandTestMessage(t *rapid.T) Message {
return msg
}
// genValidHostname generates a random valid hostname according to BOLT #7
// rules.
func genValidHostname(t *rapid.T) string {
// Valid characters: a-z, A-Z, 0-9, -, .
validChars := "abcdefghijklmnopqrstuvwxyzABCDE" +
"FGHIJKLMNOPQRSTUVWXYZ0123456789-."
// Generate hostname length between 1 and 255 characters.
length := rapid.IntRange(1, 255).Draw(t, "hostname_length")
hostname := make([]byte, length)
for i := 0; i < length; i++ {
charIndex := rapid.IntRange(0, len(validChars)-1).Draw(
t, fmt.Sprintf("char_%d", i),
)
hostname[i] = validChars[charIndex]
}
return string(hostname)
}