multi: add models.Node V1 constructor
Add a version field to models.Node and a V1 constructor for it.
This commit is contained in:
1 parent
8f205e2d1c
commit
80e70096cb
18 files changed
+443
-340
No files matched your search
+87
-15
@@ -7,7 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
)
|
||||
|
||||
// Node represents an individual vertex/node within the channel graph.
|
||||
@@ -15,6 +17,9 @@ import (
|
||||
// from it. As the graph is directed, a node will also have an incoming edge
|
||||
// attached to it for each outgoing edge.
|
||||
type Node struct {
|
||||
// Version is the gossip version that this node was advertised on.
|
||||
Version lnwire.GossipVersion
|
||||
|
||||
// PubKeyBytes is the raw bytes of the public key of the target node.
|
||||
PubKeyBytes [33]byte
|
||||
pubKey *btcec.PublicKey
|
||||
@@ -27,11 +32,11 @@ type Node struct {
|
||||
Addresses []net.Addr
|
||||
|
||||
// Color is the selected color for the node.
|
||||
Color color.RGBA
|
||||
Color fn.Option[color.RGBA]
|
||||
|
||||
// Alias is a nick-name for the node. The alias can be used to confirm
|
||||
// a node's identity or to serve as a short ID for an address book.
|
||||
Alias string
|
||||
Alias fn.Option[string]
|
||||
|
||||
// AuthSigBytes is the raw signature under the advertised public key
|
||||
// which serves to authenticate the attributes announced by this node.
|
||||
@@ -49,6 +54,72 @@ type Node struct {
|
||||
ExtraOpaqueData []byte
|
||||
}
|
||||
|
||||
// NodeV1Fields houses the fields that are specific to a version 1 node
|
||||
// announcement.
|
||||
type NodeV1Fields struct {
|
||||
// Address is the TCP address this node is reachable over.
|
||||
Addresses []net.Addr
|
||||
|
||||
// AuthSigBytes is the raw signature under the advertised public key
|
||||
// which serves to authenticate the attributes announced by this node.
|
||||
AuthSigBytes []byte
|
||||
|
||||
// Features is the list of protocol features supported by this node.
|
||||
Features *lnwire.RawFeatureVector
|
||||
|
||||
// Color is the selected color for the node.
|
||||
Color color.RGBA
|
||||
|
||||
// Alias is a nick-name for the node. The alias can be used to confirm
|
||||
// a node's identity or to serve as a short ID for an address book.
|
||||
Alias string
|
||||
|
||||
// LastUpdate is the last time the vertex information for this node has
|
||||
// been updated.
|
||||
LastUpdate time.Time
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
// properly validate the set of signatures that cover these new fields,
|
||||
// and ensure we're able to make upgrades to the network in a forwards
|
||||
// compatible manner.
|
||||
ExtraOpaqueData []byte
|
||||
}
|
||||
|
||||
// NewV1Node creates a new version 1 node from the passed fields.
|
||||
func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node {
|
||||
return &Node{
|
||||
Version: lnwire.GossipVersion1,
|
||||
PubKeyBytes: pub,
|
||||
Addresses: n.Addresses,
|
||||
AuthSigBytes: n.AuthSigBytes,
|
||||
Features: lnwire.NewFeatureVector(
|
||||
n.Features, lnwire.Features,
|
||||
),
|
||||
Color: fn.Some(n.Color),
|
||||
Alias: fn.Some(n.Alias),
|
||||
LastUpdate: n.LastUpdate,
|
||||
ExtraOpaqueData: n.ExtraOpaqueData,
|
||||
}
|
||||
}
|
||||
|
||||
// NewV1ShellNode creates a new shell version 1 node.
|
||||
func NewV1ShellNode(pubKey route.Vertex) *Node {
|
||||
return NewShellNode(lnwire.GossipVersion1, pubKey)
|
||||
}
|
||||
|
||||
// NewShellNode creates a new shell node with the given gossip version and
|
||||
// public key.
|
||||
func NewShellNode(v lnwire.GossipVersion, pubKey route.Vertex) *Node {
|
||||
return &Node{
|
||||
Version: v,
|
||||
PubKeyBytes: pubKey,
|
||||
Features: lnwire.EmptyFeatureVector(),
|
||||
LastUpdate: time.Unix(0, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// HaveAnnouncement returns true if we have received a node announcement for
|
||||
// this node. We determine this by checking if we have a signature for the
|
||||
// announcement.
|
||||
@@ -85,7 +156,7 @@ func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
|
||||
return nil, fmt.Errorf("node does not have node announcement")
|
||||
}
|
||||
|
||||
alias, err := lnwire.NewNodeAlias(n.Alias)
|
||||
alias, err := lnwire.NewNodeAlias(n.Alias.UnwrapOr(""))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -93,7 +164,7 @@ func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
|
||||
nodeAnn := &lnwire.NodeAnnouncement1{
|
||||
Features: n.Features.RawFeatureVector,
|
||||
NodeID: n.PubKeyBytes,
|
||||
RGBColor: n.Color,
|
||||
RGBColor: n.Color.UnwrapOr(color.RGBA{}),
|
||||
Alias: alias,
|
||||
Addresses: n.Addresses,
|
||||
Timestamp: uint32(n.LastUpdate.Unix()),
|
||||
@@ -118,16 +189,17 @@ func (n *Node) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement1,
|
||||
// lnwire.NodeAnnouncement1 message.
|
||||
func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node {
|
||||
timestamp := time.Unix(int64(msg.Timestamp), 0)
|
||||
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features)
|
||||
|
||||
return &Node{
|
||||
LastUpdate: timestamp,
|
||||
Addresses: msg.Addresses,
|
||||
PubKeyBytes: msg.NodeID,
|
||||
Alias: msg.Alias.String(),
|
||||
AuthSigBytes: msg.Signature.ToSignatureBytes(),
|
||||
Features: features,
|
||||
Color: msg.RGBColor,
|
||||
ExtraOpaqueData: msg.ExtraOpaqueData,
|
||||
}
|
||||
return NewV1Node(
|
||||
msg.NodeID,
|
||||
&NodeV1Fields{
|
||||
LastUpdate: timestamp,
|
||||
Addresses: msg.Addresses,
|
||||
Alias: msg.Alias.String(),
|
||||
AuthSigBytes: msg.Signature.ToSignatureBytes(),
|
||||
Features: msg.Features,
|
||||
Color: msg.RGBColor,
|
||||
ExtraOpaqueData: msg.ExtraOpaqueData,
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user