lnwire: modify NetAddress to implement the net.Addr interface

This commit modifies lnwire.NetAddress by adding a .Network() method.
With this added method the struct now implements the net.Addr interface
meaning that it can now be transparently passed into any context where
a net.Addr is requested.

This change paves the way to integration of btcd’s new connmgr into the
daemon to handle establishing persistent connections to all channel
counter parties.
This commit is contained in:
Olaoluwa Osuntokun 2016-11-07 18:18:04 -08:00
parent f37956e38e
commit 1855b95558
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -38,11 +38,24 @@ type NetAddress struct {
ChainNet wire.BitcoinNet
}
// A compile time assertion to ensure that NetAddress meets the net.Addr
// interface.
var _ net.Addr = (*NetAddress)(nil)
// String returns a human readable string describing the target NetAddress. The
// current string format is: <pubkey>@host.
//
// This part of the net.Addr interface.
func (n *NetAddress) String() string {
// TODO(roasbeef): use base58?
pubkey := n.IdentityKey.SerializeCompressed()
return fmt.Sprintf("%x@%v", pubkey, n.Address)
}
// Network returns the name of the network this address is binded to.
//
// This part of the net.Addr interface.
func (n *NetAddress) Network() string {
return n.Address.Network()
}