server: re-work initial node ann creation to use LightnignNode.NodeAnnouncement

This commit is contained in:
Olaoluwa Osuntokun 2018-09-20 19:28:11 -07:00
parent e360005452
commit 0879a7354f
No known key found for this signature in database
GPG Key ID: CE58F7F8E20FD9A2

@ -440,14 +440,19 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
chanGraph := chanDB.ChannelGraph() chanGraph := chanDB.ChannelGraph()
// Parse node color from configuration. // We'll now reconstruct a node announcement based on our current
// configuration so we can send it out as a sort of heart beat within
// the network.
//
// We'll start by parsing the node color from configuration.
color, err := parseHexColor(cfg.Color) color, err := parseHexColor(cfg.Color)
if err != nil { if err != nil {
srvrLog.Errorf("unable to parse color: %v\n", err) srvrLog.Errorf("unable to parse color: %v\n", err)
return nil, err return nil, err
} }
// If no alias is provided, default to first 10 characters of public key // If no alias is provided, default to first 10 characters of public
// key.
alias := cfg.Alias alias := cfg.Alias
if alias == "" { if alias == "" {
alias = hex.EncodeToString(serializedPubKey[:10]) alias = hex.EncodeToString(serializedPubKey[:10])
@ -473,6 +478,9 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to gen self node ann: %v", err) return nil, fmt.Errorf("unable to gen self node ann: %v", err)
} }
// With the announcement generated, we'll sign it to properly
// authenticate the message on the network.
authSig, err := discovery.SignAnnouncement( authSig, err := discovery.SignAnnouncement(
s.nodeSigner, s.identityPriv.PubKey(), nodeAnn, s.nodeSigner, s.identityPriv.PubKey(), nodeAnn,
) )
@ -480,18 +488,21 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB, cc *chainControl,
return nil, fmt.Errorf("unable to generate signature for "+ return nil, fmt.Errorf("unable to generate signature for "+
"self node announcement: %v", err) "self node announcement: %v", err)
} }
selfNode.AuthSigBytes = authSig.Serialize() selfNode.AuthSigBytes = authSig.Serialize()
s.currentNodeAnn = nodeAnn nodeAnn.Signature, err = lnwire.NewSigFromRawSignature(
selfNode.AuthSigBytes,
if err := chanGraph.SetSourceNode(selfNode); err != nil { )
return nil, fmt.Errorf("can't set self node: %v", err)
}
nodeAnn.Signature, err = lnwire.NewSigFromRawSignature(selfNode.AuthSigBytes)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Finally, we'll update the representation on disk, and update our
// cached in-memory version as well.
if err := chanGraph.SetSourceNode(selfNode); err != nil {
return nil, fmt.Errorf("can't set self node: %v", err)
}
s.currentNodeAnn = nodeAnn
s.chanRouter, err = routing.New(routing.Config{ s.chanRouter, err = routing.New(routing.Config{
Graph: chanGraph, Graph: chanGraph,
Chain: cc.chainIO, Chain: cc.chainIO,
@ -1566,7 +1577,7 @@ func (s *server) genNodeAnnouncement(refresh bool,
} }
s.currentNodeAnn.Timestamp = newStamp s.currentNodeAnn.Timestamp = newStamp
// Now that the annoncement is fully updated, we'll generate a new // Now that the announcement is fully updated, we'll generate a new
// signature over the announcement to ensure nodes on the network // signature over the announcement to ensure nodes on the network
// accepted the new authenticated announcement. // accepted the new authenticated announcement.
sig, err := discovery.SignAnnouncement( sig, err := discovery.SignAnnouncement(