2016-10-27 03:41:27 +02:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
2016-10-28 04:19:16 +02:00
|
|
|
"fmt"
|
2016-10-27 03:41:27 +02:00
|
|
|
"net"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
2016-10-27 03:41:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// NetAddress represents information pertaining to the identity and network
|
|
|
|
// reachability of a peer. Information stored includes the node's identity
|
|
|
|
// public key for establishing a confidential+authenticated connection, the
|
|
|
|
// service bits it supports, and a TCP address the node is reachable at.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): merge with LinkNode in some fashion
|
|
|
|
type NetAddress struct {
|
|
|
|
// IdentityKey is the long-term static public key for a node. This node is
|
|
|
|
// used throughout the network as a node's identity key. It is used to
|
|
|
|
// authenticate any data sent to the network on behalf of the node, and
|
|
|
|
// additionally to establish a confidential+authenticated connection with
|
|
|
|
// the node.
|
|
|
|
IdentityKey *btcec.PublicKey
|
|
|
|
|
2018-04-18 04:03:27 +02:00
|
|
|
// Address is the IP address and port of the node. This is left
|
2017-10-25 21:06:26 +02:00
|
|
|
// general so that multiple implementations can be used.
|
|
|
|
Address net.Addr
|
2016-10-28 04:19:16 +02:00
|
|
|
|
|
|
|
// ChainNet is the Bitcoin network this node is associated with.
|
|
|
|
// TODO(roasbeef): make a slice in the future for multi-chain
|
|
|
|
ChainNet wire.BitcoinNet
|
|
|
|
}
|
|
|
|
|
2016-11-08 03:18:04 +01:00
|
|
|
// A compile time assertion to ensure that NetAddress meets the net.Addr
|
|
|
|
// interface.
|
|
|
|
var _ net.Addr = (*NetAddress)(nil)
|
|
|
|
|
2016-10-28 04:19:16 +02:00
|
|
|
// String returns a human readable string describing the target NetAddress. The
|
|
|
|
// current string format is: <pubkey>@host.
|
2016-11-08 03:18:04 +01:00
|
|
|
//
|
|
|
|
// This part of the net.Addr interface.
|
2016-10-28 04:19:16 +02:00
|
|
|
func (n *NetAddress) String() string {
|
|
|
|
// TODO(roasbeef): use base58?
|
|
|
|
pubkey := n.IdentityKey.SerializeCompressed()
|
|
|
|
|
|
|
|
return fmt.Sprintf("%x@%v", pubkey, n.Address)
|
2016-10-27 03:41:27 +02:00
|
|
|
}
|
2016-11-08 03:18:04 +01:00
|
|
|
|
2018-02-07 04:11:11 +01:00
|
|
|
// Network returns the name of the network this address is bound to.
|
2016-11-08 03:18:04 +01:00
|
|
|
//
|
|
|
|
// This part of the net.Addr interface.
|
|
|
|
func (n *NetAddress) Network() string {
|
|
|
|
return n.Address.Network()
|
|
|
|
}
|