From 1855b95558b616454541eb2ad4b1e05f6e3c9bd3 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 7 Nov 2016 18:18:04 -0800 Subject: [PATCH] lnwire: modify NetAddress to implement the net.Addr interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lnwire/netaddress.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lnwire/netaddress.go b/lnwire/netaddress.go index c22f1a1e..aad5b4d9 100644 --- a/lnwire/netaddress.go +++ b/lnwire/netaddress.go @@ -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: @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() +}