• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 16982438758

15 Aug 2025 03:47AM UTC coverage: 66.748% (-0.03%) from 66.776%
16982438758

Pull #9455

github

web-flow
Merge 9a33d5e7b into 31fc55650
Pull Request #9455: [1/2] discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

209 of 304 new or added lines in 8 files covered. (68.75%)

1268 existing lines in 30 files now uncovered.

136026 of 203789 relevant lines covered (66.75%)

21540.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.68
/lnwire/dns_addr.go
1
package lnwire
2

3
import (
4
        "errors"
5
        "fmt"
6
        "net"
7
        "strconv"
8
)
9

10
// ErrEmptyDNSHostname is returned when a DNS hostname is empty.
11
var ErrEmptyDNSHostname = errors.New("hostname cannot be empty")
12

13
// ErrZeroPort is returned when a DNS port is zero.
14
var ErrZeroPort = errors.New("port cannot be zero")
15

16
// DNSAddress is used to represent a DNS address of a node.
17
type DNSAddress struct {
18
        // Hostname is the DNS hostname of the address. This MUST only contain
19
        // ASCII characters as per Bolt #7. The maximum length that this may
20
        // be is 255 bytes.
21
        Hostname string
22

23
        // Port is the port number of the address.
24
        Port uint16
25
}
26

27
// A compile-time check to ensure that DNSAddress implements the net.Addr
28
// interface.
29
var _ net.Addr = (*DNSAddress)(nil)
30

31
// Network returns the network that this address uses, which is "tcp".
NEW
32
func (d *DNSAddress) Network() string {
×
NEW
33
        return "tcp"
×
NEW
34
}
×
35

36
// String returns the address in the form "hostname:port".
37
func (d *DNSAddress) String() string {
44✔
38
        return net.JoinHostPort(d.Hostname, strconv.Itoa(int(d.Port)))
44✔
39
}
44✔
40

41
// ValidateDNSAddr validates that the DNS hostname is not empty and contains
42
// only ASCII characters and of max length 255 characters and port is non zero
43
// according to BOLT #7.
NEW
44
func ValidateDNSAddr(hostname string, port uint16) error {
×
NEW
45
        if hostname == "" {
×
NEW
46
                return ErrEmptyDNSHostname
×
NEW
47
        }
×
48

49
        // Per BOLT 7, ports must not be zero for type 5 address (DNS address).
NEW
50
        if port == 0 {
×
NEW
51
                return ErrZeroPort
×
NEW
52
        }
×
53

NEW
54
        if len(hostname) > 255 {
×
NEW
55
                return fmt.Errorf("DNS hostname length %d, exceeds limit of "+
×
NEW
56
                        "255 bytes", len(hostname))
×
NEW
57
        }
×
58

59
        // Check if hostname contains only ASCII characters.
NEW
60
        for i, r := range hostname {
×
NEW
61
                // Check for valid hostname characters, excluding ASCII control
×
NEW
62
                // characters (0-31), spaces, underscores, delete character
×
NEW
63
                // (127), and the special characters (like /, \, @, #, $, etc.).
×
NEW
64
                if !((r >= 'a' && r <= 'z') ||
×
NEW
65
                        (r >= 'A' && r <= 'Z') ||
×
NEW
66
                        (r >= '0' && r <= '9') ||
×
NEW
67
                        r == '-' ||
×
NEW
68
                        r == '.') {
×
NEW
69

×
NEW
70
                        return fmt.Errorf("hostname '%s' contains invalid "+
×
NEW
71
                                "character '%c' at position %d", hostname, r, i)
×
NEW
72
                }
×
73
        }
74

NEW
75
        return nil
×
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc