lnd: replace 'routing' with 'discovery' package

Add usage of the 'discovery' package in the lnd, now discovery service
will be handle all lnwire announcement messages and send them to the
remote party.
This commit is contained in:
Andrey Samokhvalov 2017-03-20 00:06:10 +03:00 committed by Olaoluwa Osuntokun
parent b4ac7071ff
commit 4c52b6e6a4
4 changed files with 30 additions and 16 deletions

View file

@ -141,9 +141,9 @@ type fundingConfig struct {
// so that the channel creation process can be completed. // so that the channel creation process can be completed.
Notifier chainntnfs.ChainNotifier Notifier chainntnfs.ChainNotifier
// SendToRouter is used by the FundingManager to announce newly created // SendToDiscovery is used by the FundingManager to announce newly created
// channels to the rest of the Lightning Network. // channels to the rest of the Lightning Network.
SendToRouter func(msg lnwire.Message) SendToDiscovery func(msg lnwire.Message)
// SendToPeer allows the FundingManager to send messages to the peer // SendToPeer allows the FundingManager to send messages to the peer
// node during the multiple steps involved in the creation of the // node during the multiple steps involved in the creation of the
@ -1107,8 +1107,8 @@ func (f *fundingManager) announceChannel(idKey, remoteIDKey *btcec.PublicKey,
chanAnnouncement := newChanAnnouncement(idKey, remoteIDKey, channel, chanID, chanAnnouncement := newChanAnnouncement(idKey, remoteIDKey, channel, chanID,
localProof, remoteProof) localProof, remoteProof)
f.cfg.SendToRouter(chanAnnouncement.chanAnn) f.cfg.SendToDiscovery(chanAnnouncement.chanAnn)
f.cfg.SendToRouter(chanAnnouncement.edgeUpdate) f.cfg.SendToDiscovery(chanAnnouncement.edgeUpdate)
} }
// initFundingWorkflow sends a message to the funding manager instructing it // initFundingWorkflow sends a message to the funding manager instructing it

View file

@ -498,7 +498,7 @@ out:
*lnwire.ChannelAnnouncement, *lnwire.ChannelAnnouncement,
*lnwire.ChannelUpdateAnnouncement: *lnwire.ChannelUpdateAnnouncement:
p.server.chanRouter.ProcessRoutingMessage(msg, p.server.discoverSrv.ProcessRemoteAnnouncement(msg,
p.addr.IdentityKey) p.addr.IdentityKey)
} }

View file

@ -68,10 +68,10 @@ func createTestNode() (*channeldb.LightningNode, error) {
return &channeldb.LightningNode{ return &channeldb.LightningNode{
LastUpdate: time.Now(), LastUpdate: time.Now(),
Address: testAddr, Addresses: testAddrs,
PubKey: priv.PubKey(), PubKey: priv.PubKey(),
Alias: alias.String(), Alias: alias.String(),
Features: testFeatures, Features: testFeatures,
}, nil }, nil
} }

View file

@ -14,6 +14,7 @@ import (
"github.com/lightningnetwork/lnd/brontide" "github.com/lightningnetwork/lnd/brontide"
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/discovery"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -60,6 +61,8 @@ type server struct {
chanRouter *routing.ChannelRouter chanRouter *routing.ChannelRouter
discoverSrv *discovery.Discovery
utxoNursery *utxoNursery utxoNursery *utxoNursery
sphinx *sphinx.Router sphinx *sphinx.Router
@ -179,11 +182,9 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
} }
s.chanRouter, err = routing.New(routing.Config{ s.chanRouter, err = routing.New(routing.Config{
Graph: chanGraph, Graph: chanGraph,
Chain: bio, Chain: bio,
Notifier: notifier, Notifier: notifier,
Broadcast: s.broadcastMessage,
SendMessages: s.sendToPeer,
SendToSwitch: func(firstHop *btcec.PublicKey, SendToSwitch: func(firstHop *btcec.PublicKey,
htlcAdd *lnwire.UpdateAddHTLC) ([32]byte, error) { htlcAdd *lnwire.UpdateAddHTLC) ([32]byte, error) {
@ -200,6 +201,16 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
return nil, err return nil, err
} }
s.discoverSrv, err = discovery.New(discovery.Config{
Broadcast: s.broadcastMessage,
Notifier: s.chainNotifier,
Router: s.chanRouter,
SendMessages: s.sendToPeer,
})
if err != nil {
return nil, err
}
s.rpcServer = newRPCServer(s) s.rpcServer = newRPCServer(s)
s.breachArbiter = newBreachArbiter(wallet, chanDB, notifier, s.htlcSwitch) s.breachArbiter = newBreachArbiter(wallet, chanDB, notifier, s.htlcSwitch)
@ -207,8 +218,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
IDKey: s.identityPriv.PubKey(), IDKey: s.identityPriv.PubKey(),
Wallet: wallet, Wallet: wallet,
Notifier: s.chainNotifier, Notifier: s.chainNotifier,
SendToRouter: func(msg lnwire.Message) { SendToDiscovery: func(msg lnwire.Message) {
s.chanRouter.ProcessRoutingMessage(msg, s.discoverSrv.ProcessLocalAnnouncement(msg,
s.identityPriv.PubKey()) s.identityPriv.PubKey())
}, },
ArbiterChan: s.breachArbiter.newContracts, ArbiterChan: s.breachArbiter.newContracts,
@ -385,6 +396,9 @@ func (s *server) Start() error {
if err := s.breachArbiter.Start(); err != nil { if err := s.breachArbiter.Start(); err != nil {
return err return err
} }
if err := s.discoverSrv.Start(); err != nil {
return err
}
if err := s.chanRouter.Start(); err != nil { if err := s.chanRouter.Start(); err != nil {
return err return err
} }
@ -412,7 +426,7 @@ func (s *server) Stop() error {
s.htlcSwitch.Stop() s.htlcSwitch.Stop()
s.utxoNursery.Stop() s.utxoNursery.Stop()
s.breachArbiter.Stop() s.breachArbiter.Stop()
s.discoverSrv.Stop()
s.lnwallet.Shutdown() s.lnwallet.Shutdown()
// Signal all the lingering goroutines to quit. // Signal all the lingering goroutines to quit.
@ -643,7 +657,7 @@ func (s *server) addPeer(p *peer) {
// Once the peer has been added to our indexes, send a message to the // Once the peer has been added to our indexes, send a message to the
// channel router so we can synchronize our view of the channel graph // channel router so we can synchronize our view of the channel graph
// with this new peer. // with this new peer.
go s.chanRouter.SynchronizeNode(p.addr.IdentityKey) go s.discoverSrv.SynchronizeNode(p.addr.IdentityKey)
} }
// removePeer removes the passed peer from the server's state of all active // removePeer removes the passed peer from the server's state of all active