lnd/lnwire/opaque_addrs.go
Elle Mouton fa0512f62f
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.
2022-05-04 11:06:11 +02:00

35 lines
965 B
Go

package lnwire
import (
"encoding/hex"
"net"
)
// OpaqueAddrs is used to store the address bytes for address types that are
// unknown to us.
type OpaqueAddrs struct {
Payload []byte
}
// A compile-time assertion to ensure that OpaqueAddrs meets the net.Addr
// interface.
var _ net.Addr = (*OpaqueAddrs)(nil)
// String returns a human-readable string describing the target OpaqueAddrs.
// Since this is an unknown address (and could even be multiple addresses), we
// just return the hex string of the payload.
//
// This part of the net.Addr interface.
func (o *OpaqueAddrs) String() string {
return hex.EncodeToString(o.Payload)
}
// Network returns the name of the network this address is bound to. Since this
// is an unknown address, we don't know the network and so just return a string
// indicating this.
//
// This part of the net.Addr interface.
func (o *OpaqueAddrs) Network() string {
return "unknown network for unrecognized address type"
}