netaddress.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package lnwire
  2. import (
  3. "fmt"
  4. "net"
  5. "github.com/btcsuite/btcd/btcec/v2"
  6. "github.com/btcsuite/btcd/wire"
  7. )
  8. // NetAddress represents information pertaining to the identity and network
  9. // reachability of a peer. Information stored includes the node's identity
  10. // public key for establishing a confidential+authenticated connection, the
  11. // service bits it supports, and a TCP address the node is reachable at.
  12. //
  13. // TODO(roasbeef): merge with LinkNode in some fashion
  14. type NetAddress struct {
  15. // IdentityKey is the long-term static public key for a node. This node is
  16. // used throughout the network as a node's identity key. It is used to
  17. // authenticate any data sent to the network on behalf of the node, and
  18. // additionally to establish a confidential+authenticated connection with
  19. // the node.
  20. IdentityKey *btcec.PublicKey
  21. // Address is the IP address and port of the node. This is left
  22. // general so that multiple implementations can be used.
  23. Address net.Addr
  24. // ChainNet is the Bitcoin network this node is associated with.
  25. // TODO(roasbeef): make a slice in the future for multi-chain
  26. ChainNet wire.BitcoinNet
  27. }
  28. // A compile time assertion to ensure that NetAddress meets the net.Addr
  29. // interface.
  30. var _ net.Addr = (*NetAddress)(nil)
  31. // String returns a human readable string describing the target NetAddress. The
  32. // current string format is: <pubkey>@host.
  33. //
  34. // This part of the net.Addr interface.
  35. func (n *NetAddress) String() string {
  36. // TODO(roasbeef): use base58?
  37. pubkey := n.IdentityKey.SerializeCompressed()
  38. return fmt.Sprintf("%x@%v", pubkey, n.Address)
  39. }
  40. // Network returns the name of the network this address is bound to.
  41. //
  42. // This part of the net.Addr interface.
  43. func (n *NetAddress) Network() string {
  44. return n.Address.Network()
  45. }