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

lightningnetwork / lnd / 17832014233

18 Sep 2025 02:30PM UTC coverage: 57.196% (-9.4%) from 66.637%
17832014233

Pull #10133

github

web-flow
Merge 3e12b2767 into b34fc964b
Pull Request #10133: Add `XFindBaseLocalChanAlias` RPC

20 of 34 new or added lines in 4 files covered. (58.82%)

28528 existing lines in 459 files now uncovered.

99371 of 173739 relevant lines covered (57.2%)

1.78 hits per line

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

0.0
/lnwire/dns_addr.go
1
package lnwire
2

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

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

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

17
        // ErrHostnameTooLong is returned when a DNS hostname exceeds 255 bytes.
18
        ErrHostnameTooLong = errors.New("DNS hostname length exceeds limit " +
19
                "of 255 bytes")
20

21
        // ErrInvalidHostnameCharacter is returned when a DNS hostname contains
22
        // an invalid character.
23
        ErrInvalidHostnameCharacter = errors.New("hostname contains invalid " +
24
                "character")
25
)
26

27
// DNSAddress is used to represent a DNS address of a node.
28
type DNSAddress struct {
29
        // Hostname is the DNS hostname of the address. This MUST only contain
30
        // ASCII characters as per Bolt #7. The maximum length that this may
31
        // be is 255 bytes.
32
        Hostname string
33

34
        // Port is the port number of the address.
35
        Port uint16
36
}
37

38
// A compile-time check to ensure that DNSAddress implements the net.Addr
39
// interface.
40
var _ net.Addr = (*DNSAddress)(nil)
41

42
// Network returns the network that this address uses, which is "tcp".
43
func (d *DNSAddress) Network() string {
×
44
        return "tcp"
×
45
}
×
46

47
// String returns the address in the form "hostname:port".
UNCOV
48
func (d *DNSAddress) String() string {
×
UNCOV
49
        return net.JoinHostPort(d.Hostname, strconv.Itoa(int(d.Port)))
×
UNCOV
50
}
×
51

52
// ValidateDNSAddr validates that the DNS hostname is not empty and contains
53
// only ASCII characters and of max length 255 characters and port is non zero
54
// according to BOLT #7.
UNCOV
55
func ValidateDNSAddr(hostname string, port uint16) error {
×
UNCOV
56
        if hostname == "" {
×
UNCOV
57
                return ErrEmptyDNSHostname
×
UNCOV
58
        }
×
59

60
        // Per BOLT 7, ports must not be zero for type 5 address (DNS address).
UNCOV
61
        if port == 0 {
×
UNCOV
62
                return ErrZeroPort
×
UNCOV
63
        }
×
64

UNCOV
65
        if len(hostname) > 255 {
×
UNCOV
66
                return fmt.Errorf("%w: DNS hostname length %d",
×
UNCOV
67
                        ErrHostnameTooLong, len(hostname))
×
UNCOV
68
        }
×
69

70
        // Check if hostname contains only ASCII characters.
UNCOV
71
        for i, r := range hostname {
×
UNCOV
72
                // Check for valid hostname characters, excluding ASCII control
×
UNCOV
73
                // characters (0-31), spaces, underscores, delete character
×
UNCOV
74
                // (127), and the special characters (like /, \, @, #, $, etc.).
×
UNCOV
75
                if !((r >= 'a' && r <= 'z') ||
×
UNCOV
76
                        (r >= 'A' && r <= 'Z') ||
×
UNCOV
77
                        (r >= '0' && r <= '9') ||
×
UNCOV
78
                        r == '-' ||
×
UNCOV
79
                        r == '.') {
×
UNCOV
80

×
UNCOV
81
                        return fmt.Errorf("%w: hostname '%s' contains invalid "+
×
UNCOV
82
                                "character '%c' at position %d",
×
UNCOV
83
                                ErrInvalidHostnameCharacter, hostname, r, i)
×
UNCOV
84
                }
×
85
        }
86

UNCOV
87
        return nil
×
88
}
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