@@ -31,8 +31,36 @@ const (
31
31
// opaqueAddrs denotes an address (or a set of addresses) that LND was
32
32
// not able to parse since LND is not yet aware of the address type.
33
33
opaqueAddrs addressType = 4
34
+
35
+ // dnsAddr denotes a DNS address type.
36
+ dnsAddr addressType = 5
34
37
)
35
38
39
+ // encodeDNSAddr encodes a DNS address.
40
+ func encodeDNSAddr (w io.Writer , addr * lnwire.DNSAddress ) error {
41
+ if _ , err := w .Write ([]byte {byte (dnsAddr )}); err != nil {
42
+ return err
43
+ }
44
+
45
+ // Write the length of the hostname.
46
+ hostLen := len (addr .Hostname )
47
+ if _ , err := w .Write ([]byte {byte (hostLen )}); err != nil {
48
+ return err
49
+ }
50
+
51
+ if _ , err := w .Write ([]byte (addr .Hostname )); err != nil {
52
+ return err
53
+ }
54
+
55
+ var port [2 ]byte
56
+ byteOrder .PutUint16 (port [:], addr .Port )
57
+ if _ , err := w .Write (port [:]); err != nil {
58
+ return err
59
+ }
60
+
61
+ return nil
62
+ }
63
+
36
64
// encodeTCPAddr serializes a TCP address into its compact raw bytes
37
65
// representation.
38
66
func encodeTCPAddr (w io.Writer , addr * net.TCPAddr ) error {
@@ -230,6 +258,30 @@ func DeserializeAddr(r io.Reader) (net.Addr, error) {
230
258
Port : port ,
231
259
}
232
260
261
+ case dnsAddr :
262
+ // Read the length of the hostname.
263
+ var hostLen [1 ]byte
264
+ if _ , err := r .Read (hostLen [:]); err != nil {
265
+ return nil , err
266
+ }
267
+
268
+ // Read the hostname.
269
+ hostname := make ([]byte , hostLen [0 ])
270
+ if _ , err := r .Read (hostname ); err != nil {
271
+ return nil , err
272
+ }
273
+
274
+ // Read the port.
275
+ var port [2 ]byte
276
+ if _ , err := r .Read (port [:]); err != nil {
277
+ return nil , err
278
+ }
279
+
280
+ address = & lnwire.DNSAddress {
281
+ Hostname : string (hostname ),
282
+ Port : binary .BigEndian .Uint16 (port [:]),
283
+ }
284
+
233
285
case opaqueAddrs :
234
286
// Read the length of the payload.
235
287
var l [2 ]byte
@@ -264,6 +316,8 @@ func SerializeAddr(w io.Writer, address net.Addr) error {
264
316
return encodeOnionAddr (w , addr )
265
317
case * lnwire.OpaqueAddrs :
266
318
return encodeOpaqueAddrs (w , addr )
319
+ case * lnwire.DNSAddress :
320
+ return encodeDNSAddr (w , addr )
267
321
default :
268
322
return ErrUnknownAddressType
269
323
}
0 commit comments