lnwire: add new type OpaqueAddrs
In this commit, a new net.Addr implementation called OpaqueAddrs is added along with a WriteOpaqueAddrs func that is called in WriteNetAddrs. It will be used to store any address bytes that we cannot parse due to us not being aware of the address type.
This commit is contained in:
3 files changed
+58
-17
No files matched your search
+7
-17
@@ -230,43 +230,33 @@ func TestChanUpdateChanFlags(t *testing.T) {
|
||||
// TestDecodeUnknownAddressType shows that an unknown address type is currently
|
||||
// incorrectly dealt with.
|
||||
func TestDecodeUnknownAddressType(t *testing.T) {
|
||||
// First, we'll encode all the addresses into an intermediate
|
||||
// buffer. We need to do this in order to compute the total
|
||||
// length of the addresses.
|
||||
addrBuf := bytes.NewBuffer(make([]byte, 0, MaxMsgBody))
|
||||
|
||||
// Add a normal, clearnet address.
|
||||
tcpAddr := &net.TCPAddr{
|
||||
IP: net.IP{127, 0, 0, 1},
|
||||
Port: 8080,
|
||||
}
|
||||
|
||||
err := WriteTCPAddr(addrBuf, tcpAddr)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add an onion address.
|
||||
onionAddr := &tor.OnionAddr{
|
||||
OnionService: "abcdefghijklmnop.onion",
|
||||
Port: 9065,
|
||||
}
|
||||
|
||||
err = WriteOnionAddr(addrBuf, onionAddr)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now add an address with an unknown type.
|
||||
var newAddrType addressType = math.MaxUint8
|
||||
data := make([]byte, 0, 16)
|
||||
data = append(data, uint8(newAddrType))
|
||||
_, err = addrBuf.Write(data)
|
||||
require.NoError(t, err)
|
||||
opaqueAddrs := &OpaqueAddrs{
|
||||
Payload: data,
|
||||
}
|
||||
|
||||
// Now that we have all the addresses, we can append the length.
|
||||
buffer := bytes.NewBuffer(make([]byte, 0, MaxMsgBody))
|
||||
err = writeDataWithLength(buffer, addrBuf.Bytes())
|
||||
err := WriteNetAddrs(
|
||||
buffer, []net.Addr{tcpAddr, onionAddr, opaqueAddrs},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now we attempt to parse the bytes and we assert that we get an
|
||||
// error.
|
||||
// Now we attempt to parse the bytes and assert that we get an error.
|
||||
var addrs []net.Addr
|
||||
err = ReadElement(buffer, &addrs)
|
||||
require.Error(t, err)
|
||||
|
||||
Reference in new issue
Block a user