From 4d9f884c3f733f7dd97beb5d34002cf818c70e40 Mon Sep 17 00:00:00 2001 From: Mohamed Awnallah Date: Thu, 14 Aug 2025 10:26:07 +0000 Subject: [PATCH] lnwire: add `DNSAddress` type --- lnwire/dns_addr.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lnwire/dns_addr.go diff --git a/lnwire/dns_addr.go b/lnwire/dns_addr.go new file mode 100644 index 000000000..92cbc073a --- /dev/null +++ b/lnwire/dns_addr.go @@ -0,0 +1,31 @@ +package lnwire + +import ( + "net" + "strconv" +) + +// DNSAddress is used to represent a DNS address of a node. +type DNSAddress struct { + // Hostname is the DNS hostname of the address. This MUST only contain + // ASCII characters as per Bolt #7. The maximum length that this may + // be is 255 bytes. + Hostname string + + // Port is the port number of the address. + Port uint16 +} + +// A compile-time check to ensure that DNSAddress implements the net.Addr +// interface. +var _ net.Addr = (*DNSAddress)(nil) + +// Network returns the network that this address uses, which is "tcp". +func (d *DNSAddress) Network() string { + return "tcp" +} + +// String returns the address in the form "hostname:port". +func (d *DNSAddress) String() string { + return net.JoinHostPort(d.Hostname, strconv.Itoa(int(d.Port))) +}