mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-24 20:53:07 +02:00
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:
@@ -28,6 +28,24 @@ const (
|
|||||||
MaxMsgBody = 65533
|
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
|
// PkScript is simple type definition which represents a raw serialized public
|
||||||
// key script.
|
// key script.
|
||||||
type PkScript []byte
|
type PkScript []byte
|
||||||
@@ -54,25 +72,6 @@ const (
|
|||||||
v3OnionAddr addressType = 4
|
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
|
// WriteElement is a one-stop shop to write the big endian representation of
|
||||||
// any element which is to be serialized for the wire protocol.
|
// 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
|
var address net.Addr
|
||||||
switch aType := addressType(descriptor[0]); aType {
|
switch aType := addressType(descriptor[0]); aType {
|
||||||
case noAddr:
|
case noAddr:
|
||||||
addrBytesRead += aType.AddrLen()
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
case tcp4Addr:
|
case tcp4Addr:
|
||||||
@@ -761,7 +759,7 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
IP: net.IP(ip[:]),
|
IP: net.IP(ip[:]),
|
||||||
Port: int(binary.BigEndian.Uint16(port[:])),
|
Port: int(binary.BigEndian.Uint16(port[:])),
|
||||||
}
|
}
|
||||||
addrBytesRead += aType.AddrLen()
|
addrBytesRead += tcp4AddrLen
|
||||||
|
|
||||||
case tcp6Addr:
|
case tcp6Addr:
|
||||||
var ip [16]byte
|
var ip [16]byte
|
||||||
@@ -778,7 +776,7 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
IP: net.IP(ip[:]),
|
IP: net.IP(ip[:]),
|
||||||
Port: int(binary.BigEndian.Uint16(port[:])),
|
Port: int(binary.BigEndian.Uint16(port[:])),
|
||||||
}
|
}
|
||||||
addrBytesRead += aType.AddrLen()
|
addrBytesRead += tcp6AddrLen
|
||||||
|
|
||||||
case v2OnionAddr:
|
case v2OnionAddr:
|
||||||
var h [tor.V2DecodedLen]byte
|
var h [tor.V2DecodedLen]byte
|
||||||
@@ -799,7 +797,7 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
OnionService: onionService,
|
OnionService: onionService,
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
addrBytesRead += aType.AddrLen()
|
addrBytesRead += v2OnionAddrLen
|
||||||
|
|
||||||
case v3OnionAddr:
|
case v3OnionAddr:
|
||||||
var h [tor.V3DecodedLen]byte
|
var h [tor.V3DecodedLen]byte
|
||||||
@@ -820,7 +818,7 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
OnionService: onionService,
|
OnionService: onionService,
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
addrBytesRead += aType.AddrLen()
|
addrBytesRead += v3OnionAddrLen
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// If we don't understand this address type,
|
// If we don't understand this address type,
|
||||||
|
Reference in New Issue
Block a user