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

lightningnetwork / lnd / 16990665124

15 Aug 2025 01:10PM UTC coverage: 66.74% (-0.03%) from 66.765%
16990665124

Pull #9455

github

web-flow
Merge 035fac41d into fb1adfc21
Pull Request #9455: [1/2] discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

116 of 188 new or added lines in 8 files covered. (61.7%)

110 existing lines in 23 files now uncovered.

136011 of 203791 relevant lines covered (66.74%)

21482.89 hits per line

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

90.32
/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.
44
func ValidateDNSAddr(hostname string, port uint16) error {
9✔
45
        if hostname == "" {
10✔
46
                return ErrEmptyDNSHostname
1✔
47
        }
1✔
48

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

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

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

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

75
        return nil
3✔
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