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

lightningnetwork / lnd / 16988342641

15 Aug 2025 10:40AM UTC coverage: 66.751% (-0.01%) from 66.763%
16988342641

Pull #10159

github

web-flow
Merge c32685723 into 365f1788e
Pull Request #10159: [2/2] discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

274 of 360 new or added lines in 10 files covered. (76.11%)

96 existing lines in 19 files now uncovered.

136064 of 203838 relevant lines covered (66.75%)

21491.73 hits per line

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

64.52
/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".
32
func (d *DNSAddress) Network() string {
6✔
33
        return "tcp"
6✔
34
}
6✔
35

36
// String returns the address in the form "hostname:port".
37
func (d *DNSAddress) String() string {
50✔
38
        return net.JoinHostPort(d.Hostname, strconv.Itoa(int(d.Port)))
50✔
39
}
50✔
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 {
3✔
45
        if hostname == "" {
3✔
NEW
46
                return ErrEmptyDNSHostname
×
NEW
47
        }
×
48

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

54
        if len(hostname) > 255 {
3✔
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.
60
        for i, r := range hostname {
6✔
61
                // Check for valid hostname characters, excluding ASCII control
3✔
62
                // characters (0-31), spaces, underscores, delete character
3✔
63
                // (127), and the special characters (like /, \, @, #, $, etc.).
3✔
64
                if !((r >= 'a' && r <= 'z') ||
3✔
65
                        (r >= 'A' && r <= 'Z') ||
3✔
66
                        (r >= '0' && r <= '9') ||
3✔
67
                        r == '-' ||
3✔
68
                        r == '.') {
3✔
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

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