Skip to content

Commit

Permalink
Merge 69c49a8 into fe0a7b6
Browse files Browse the repository at this point in the history
  • Loading branch information
ddustin committed Sep 8, 2017
2 parents fe0a7b6 + 69c49a8 commit 2e78649
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "lnd.log"
defaultAlias = ""
defaultRPCPort = 10009
defaultRESTPort = 8080
defaultPeerPort = 9735
Expand Down Expand Up @@ -101,6 +102,7 @@ type config struct {
AdminMacPath string `long:"adminmacaroonpath" description:"Path to write the admin macaroon for lnd's RPC and REST services if it doesn't exist"`
ReadMacPath string `long:"readonlymacaroonpath" description:"Path to write the read-only macaroon for lnd's RPC and REST services if it doesn't exist"`
LogDir string `long:"logdir" description:"Directory to log output."`
Alias string `long:"alias" description:"Node's alias name (essentially a user-agent string)"`

Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 9735)"`
ExternalIPs []string `long:"externalip" description:"Add an ip to the list of local addresses we claim to listen on to peers"`
Expand Down Expand Up @@ -145,6 +147,7 @@ func loadConfig() (*config, error) {
AdminMacPath: defaultAdminMacPath,
ReadMacPath: defaultReadMacPath,
LogDir: defaultLogDir,
Alias: defaultAlias,
PeerPort: defaultPeerPort,
RPCPort: defaultRPCPort,
RESTPort: defaultRESTPort,
Expand Down
2 changes: 1 addition & 1 deletion lnd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ func testRevokedCloseRetributionPostBreachConf(
chanPoint := openChannelAndAssert(ctxt, t, net, net.Alice, carol,
chanAmt, 0)

// With the channel open, we'll create a few invoices for Caro that
// With the channel open, we'll create a few invoices for Carol that
// Alice will pay to in order to advance the state of the channel.
bobPaymentHashes := make([][]byte, numInvoices)
for i := 0; i < numInvoices; i++ {
Expand Down
1 change: 1 addition & 0 deletions networktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (l *lightningNode) genArgs() []string {
args = append(args, fmt.Sprintf("--configfile=%v", l.cfg.DataDir))
args = append(args, fmt.Sprintf("--adminmacaroonpath=%v", l.cfg.AdminMacPath))
args = append(args, fmt.Sprintf("--readonlymacaroonpath=%v", l.cfg.ReadMacPath))
args = append(args, fmt.Sprintf("--alias=%v", l.cfg.Alias))

if l.extraArgs != nil {
args = append(args, l.extraArgs...)
Expand Down
12 changes: 9 additions & 3 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2639,9 +2639,9 @@ func (r *rpcServer) DeleteAllPayments(ctx context.Context,
return &lnrpc.DeleteAllPaymentsResponse{}, nil
}

// SetAlias...
// SetAlias sets this node's alias (essentially a user-agent string), triggering an announcement to the network
func (r *rpcServer) SetAlias(ctx context.Context,
_ *lnrpc.SetAliasRequest) (*lnrpc.SetAliasResponse, error) {
req *lnrpc.SetAliasRequest) (*lnrpc.SetAliasResponse, error) {

if r.authSvc != nil {
if err := macaroons.ValidateMacaroon(ctx, "setalias",
Expand All @@ -2650,7 +2650,13 @@ func (r *rpcServer) SetAlias(ctx context.Context,
}
}

return nil, nil
rpcsLog.Debugf("[SetAlias] Setting alias to: %v", req.NewAlias)

if err := r.server.refreshNodeAnnouncement(req.NewAlias); err != nil {
return nil, err
}

return &lnrpc.SetAliasResponse{}, nil
}

// DebugLevel allows a caller to programmatically set the logging verbosity of
Expand Down
103 changes: 64 additions & 39 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type server struct {
// changed since last start.
currentNodeAnn *lnwire.NodeAnnouncement

selfAddrs []net.Addr

quit chan struct{}

wg sync.WaitGroup
Expand Down Expand Up @@ -185,7 +187,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,

// If external IP addresses have been specified, add those to the list
// of this server's addresses.
selfAddrs := make([]net.Addr, 0, len(cfg.ExternalIPs))
s.selfAddrs = make([]net.Addr, 0, len(cfg.ExternalIPs))
for _, ip := range cfg.ExternalIPs {
var addr string
_, _, err = net.SplitHostPort(ip)
Expand All @@ -200,52 +202,17 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
return nil, err
}

selfAddrs = append(selfAddrs, lnAddr)
s.selfAddrs = append(s.selfAddrs, lnAddr)
}

chanGraph := chanDB.ChannelGraph()

// TODO(roasbeef): make alias configurable
alias, err := lnwire.NewNodeAlias(hex.EncodeToString(serializedPubKey[:10]))
if err != nil {
return nil, err
}
selfNode := &channeldb.LightningNode{
HaveNodeAnnouncement: true,
LastUpdate: time.Now(),
Addresses: selfAddrs,
PubKey: privKey.PubKey(),
Alias: alias.String(),
Features: globalFeatures,
}
err = s.refreshNodeAnnouncement(cfg.Alias)

// If our information has changed since our last boot, then we'll
// re-sign our node announcement so a fresh authenticated version of it
// can be propagated throughout the network upon startup.
//
// TODO(roasbeef): don't always set timestamp above to _now.
nodeAnn := &lnwire.NodeAnnouncement{
Timestamp: uint32(selfNode.LastUpdate.Unix()),
Addresses: selfNode.Addresses,
NodeID: selfNode.PubKey,
Alias: alias,
Features: selfNode.Features,
}
selfNode.AuthSig, err = discovery.SignAnnouncement(s.nodeSigner,
s.identityPriv.PubKey(), nodeAnn,
)
if err != nil {
return nil, fmt.Errorf("unable to generate signature for "+
"self node announcement: %v", err)
}

if err := chanGraph.SetSourceNode(selfNode); err != nil {
return nil, fmt.Errorf("can't set self node: %v", err)
return nil, err
}

nodeAnn.Signature = selfNode.AuthSig
s.currentNodeAnn = nodeAnn

s.chanRouter, err = routing.New(routing.Config{
Graph: chanGraph,
Chain: cc.chainIO,
Expand Down Expand Up @@ -311,6 +278,64 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
return s, nil
}

// Announces our node using 'aliasName'. If 'aliasName' is empty then
// we use the first 10 digits of our public key instead.
//
// NOTE: This function is safe for concurrent access.
func (s *server) refreshNodeAnnouncement(aliasName string) error {

s.mu.Lock()
defer s.mu.Unlock()

if aliasName == "" {
aliasName = hex.EncodeToString(s.identityPriv.PubKey().SerializeCompressed()[:10])
}

chanGraph := s.chanDB.ChannelGraph()

alias, err := lnwire.NewNodeAlias(aliasName)
if err != nil {
return err
}
selfNode := &channeldb.LightningNode{
HaveNodeAnnouncement: true,
LastUpdate: time.Now(),
Addresses: s.selfAddrs,
PubKey: s.identityPriv.PubKey(),
Alias: alias.String(),
Features: globalFeatures,
}

// If our information has changed since our last boot, then we'll
// re-sign our node announcement so a fresh authenticated version of it
// can be propagated throughout the network upon startup.
//
// TODO(roasbeef): don't always set timestamp above to _now.
nodeAnn := &lnwire.NodeAnnouncement{
Timestamp: uint32(selfNode.LastUpdate.Unix()),
Addresses: selfNode.Addresses,
NodeID: selfNode.PubKey,
Alias: alias,
Features: selfNode.Features,
}
selfNode.AuthSig, err = discovery.SignAnnouncement(s.nodeSigner,
s.identityPriv.PubKey(), nodeAnn,
)
if err != nil {
return fmt.Errorf("unable to generate signature for "+
"self node announcement: %v", err)
}

if err := chanGraph.SetSourceNode(selfNode); err != nil {
return fmt.Errorf("can't set self node: %v", err)
}

nodeAnn.Signature = selfNode.AuthSig
s.currentNodeAnn = nodeAnn

return nil
}

// Started returns true if the server has been started, and false otherwise.
// NOTE: This function is safe for concurrent access.
func (s *server) Started() bool {
Expand Down

0 comments on commit 2e78649

Please sign in to comment.