lnwire: remove AddrLen helper

In this commit, we remove `AddrLen` as prepration step
before adding DNS address type which will have a var length.

Co-authored-by: Elle Mouton <elle.mouton@gmail.com>
This commit is contained in:
Mohamed Awnallah
2025-08-14 10:14:48 +00:00
parent 31fc556507
commit 05e4370ebd

View File

@@ -28,6 +28,24 @@ const (
MaxMsgBody = 65533
)
const (
// tcp4AddrLen is the length of an IPv4 address
// (4 bytes IP + 2 bytes port).
tcp4AddrLen = 6
// tcp6AddrLen is the length of an IPv6 address
// (16 bytes IP + 2 bytes port).
tcp6AddrLen = 18
// v2OnionAddrLen is the length of a version 2 Tor onion service
// address.
v2OnionAddrLen = 12
// v3OnionAddrLen is the length of a version 3 Tor onion service address
// (35 bytes decoded onion + 2 bytes port).
v3OnionAddrLen = 37
)
// PkScript is simple type definition which represents a raw serialized public
// key script.
type PkScript []byte
@@ -54,25 +72,6 @@ const (
v3OnionAddr addressType = 4
)
// AddrLen returns the number of bytes that it takes to encode the target
// address.
func (a addressType) AddrLen() uint16 {
switch a {
case noAddr:
return 0
case tcp4Addr:
return 6
case tcp6Addr:
return 18
case v2OnionAddr:
return 12
case v3OnionAddr:
return 37
default:
return 0
}
}
// WriteElement is a one-stop shop to write the big endian representation of
// any element which is to be serialized for the wire protocol.
//
@@ -743,7 +742,6 @@ func ReadElement(r io.Reader, element interface{}) error {
var address net.Addr
switch aType := addressType(descriptor[0]); aType {
case noAddr:
addrBytesRead += aType.AddrLen()
continue
case tcp4Addr:
@@ -761,7 +759,7 @@ func ReadElement(r io.Reader, element interface{}) error {
IP: net.IP(ip[:]),
Port: int(binary.BigEndian.Uint16(port[:])),
}
addrBytesRead += aType.AddrLen()
addrBytesRead += tcp4AddrLen
case tcp6Addr:
var ip [16]byte
@@ -778,7 +776,7 @@ func ReadElement(r io.Reader, element interface{}) error {
IP: net.IP(ip[:]),
Port: int(binary.BigEndian.Uint16(port[:])),
}
addrBytesRead += aType.AddrLen()
addrBytesRead += tcp6AddrLen
case v2OnionAddr:
var h [tor.V2DecodedLen]byte
@@ -799,7 +797,7 @@ func ReadElement(r io.Reader, element interface{}) error {
OnionService: onionService,
Port: port,
}
addrBytesRead += aType.AddrLen()
addrBytesRead += v2OnionAddrLen
case v3OnionAddr:
var h [tor.V3DecodedLen]byte
@@ -820,7 +818,7 @@ func ReadElement(r io.Reader, element interface{}) error {
OnionService: onionService,
Port: port,
}
addrBytesRead += aType.AddrLen()
addrBytesRead += v3OnionAddrLen
default:
// If we don't understand this address type,