multi: move Route to sub-pkg routing/route
This commit is contained in:
19 files changed
+391
-366
No files matched your search
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
)
|
||||
|
||||
// ChannelGraphTimeSeries is an interface that provides time and block based
|
||||
@@ -247,7 +247,7 @@ func (c *ChanSeries) FetchChanAnns(chain chainhash.Hash,
|
||||
// We'll use this map to ensure we don't send the same node
|
||||
// announcement more than one time as one node may have many channel
|
||||
// anns we'll need to send.
|
||||
nodePubsSent := make(map[routing.Vertex]struct{})
|
||||
nodePubsSent := make(map[route.Vertex]struct{})
|
||||
|
||||
chanAnns := make([]lnwire.Message, 0, len(channels)*3)
|
||||
for _, channel := range channels {
|
||||
|
||||
+15
-14
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/multimutex"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
)
|
||||
|
||||
@@ -131,7 +132,7 @@ type Config struct {
|
||||
// that the daemon is connected to. If supplied, the exclude parameter
|
||||
// indicates that the target peer should be excluded from the
|
||||
// broadcast.
|
||||
Broadcast func(skips map[routing.Vertex]struct{},
|
||||
Broadcast func(skips map[route.Vertex]struct{},
|
||||
msg ...lnwire.Message) error
|
||||
|
||||
// NotifyWhenOnline is a function that allows the gossiper to be
|
||||
@@ -342,7 +343,7 @@ func (d *AuthenticatedGossiper) SynchronizeNode(syncPeer lnpeer.Peer) error {
|
||||
// We'll use this map to ensure we don't send the same node
|
||||
// announcement more than one time as one node may have many channel
|
||||
// anns we'll need to send.
|
||||
nodePubsSent := make(map[routing.Vertex]struct{})
|
||||
nodePubsSent := make(map[route.Vertex]struct{})
|
||||
|
||||
// As peers are expecting channel announcements before node
|
||||
// announcements, we first retrieve the initial announcement, as well as
|
||||
@@ -654,14 +655,14 @@ type msgWithSenders struct {
|
||||
msg lnwire.Message
|
||||
|
||||
// sender is the set of peers that sent us this message.
|
||||
senders map[routing.Vertex]struct{}
|
||||
senders map[route.Vertex]struct{}
|
||||
}
|
||||
|
||||
// mergeSyncerMap is used to merge the set of senders of a particular message
|
||||
// with peers that we have an active GossipSyncer with. We do this to ensure
|
||||
// that we don't broadcast messages to any peers that we have active gossip
|
||||
// syncers for.
|
||||
func (m *msgWithSenders) mergeSyncerMap(syncers map[routing.Vertex]*GossipSyncer) {
|
||||
func (m *msgWithSenders) mergeSyncerMap(syncers map[route.Vertex]*GossipSyncer) {
|
||||
for peerPub := range syncers {
|
||||
m.senders[peerPub] = struct{}{}
|
||||
}
|
||||
@@ -682,7 +683,7 @@ type deDupedAnnouncements struct {
|
||||
channelUpdates map[channelUpdateID]msgWithSenders
|
||||
|
||||
// nodeAnnouncements are identified by the Vertex field.
|
||||
nodeAnnouncements map[routing.Vertex]msgWithSenders
|
||||
nodeAnnouncements map[route.Vertex]msgWithSenders
|
||||
|
||||
sync.Mutex
|
||||
}
|
||||
@@ -704,7 +705,7 @@ func (d *deDupedAnnouncements) reset() {
|
||||
// appropriate key points to the corresponding lnwire.Message.
|
||||
d.channelAnnouncements = make(map[lnwire.ShortChannelID]msgWithSenders)
|
||||
d.channelUpdates = make(map[channelUpdateID]msgWithSenders)
|
||||
d.nodeAnnouncements = make(map[routing.Vertex]msgWithSenders)
|
||||
d.nodeAnnouncements = make(map[route.Vertex]msgWithSenders)
|
||||
}
|
||||
|
||||
// addMsg adds a new message to the current batch. If the message is already
|
||||
@@ -722,13 +723,13 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
|
||||
// Channel announcements are identified by the short channel id field.
|
||||
case *lnwire.ChannelAnnouncement:
|
||||
deDupKey := msg.ShortChannelID
|
||||
sender := routing.NewVertex(message.source)
|
||||
sender := route.NewVertex(message.source)
|
||||
|
||||
mws, ok := d.channelAnnouncements[deDupKey]
|
||||
if !ok {
|
||||
mws = msgWithSenders{
|
||||
msg: msg,
|
||||
senders: make(map[routing.Vertex]struct{}),
|
||||
senders: make(map[route.Vertex]struct{}),
|
||||
}
|
||||
mws.senders[sender] = struct{}{}
|
||||
|
||||
@@ -744,7 +745,7 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
|
||||
// Channel updates are identified by the (short channel id,
|
||||
// channelflags) tuple.
|
||||
case *lnwire.ChannelUpdate:
|
||||
sender := routing.NewVertex(message.source)
|
||||
sender := route.NewVertex(message.source)
|
||||
deDupKey := channelUpdateID{
|
||||
msg.ShortChannelID,
|
||||
msg.ChannelFlags,
|
||||
@@ -770,7 +771,7 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
|
||||
if oldTimestamp < msg.Timestamp {
|
||||
mws = msgWithSenders{
|
||||
msg: msg,
|
||||
senders: make(map[routing.Vertex]struct{}),
|
||||
senders: make(map[route.Vertex]struct{}),
|
||||
}
|
||||
|
||||
// We'll mark the sender of the message in the
|
||||
@@ -793,8 +794,8 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
|
||||
// Node announcements are identified by the Vertex field. Use the
|
||||
// NodeID to create the corresponding Vertex.
|
||||
case *lnwire.NodeAnnouncement:
|
||||
sender := routing.NewVertex(message.source)
|
||||
deDupKey := routing.Vertex(msg.NodeID)
|
||||
sender := route.NewVertex(message.source)
|
||||
deDupKey := route.Vertex(msg.NodeID)
|
||||
|
||||
// We do the same for node announcements as we did for channel
|
||||
// updates, as they also carry a timestamp.
|
||||
@@ -813,7 +814,7 @@ func (d *deDupedAnnouncements) addMsg(message networkMsg) {
|
||||
if oldTimestamp < msg.Timestamp {
|
||||
mws = msgWithSenders{
|
||||
msg: msg,
|
||||
senders: make(map[routing.Vertex]struct{}),
|
||||
senders: make(map[route.Vertex]struct{}),
|
||||
}
|
||||
|
||||
mws.senders[sender] = struct{}{}
|
||||
@@ -1137,7 +1138,7 @@ func (d *AuthenticatedGossiper) InitSyncState(syncPeer lnpeer.Peer) {
|
||||
// PruneSyncState is called by outside sub-systems once a peer that we were
|
||||
// previously connected to has been disconnected. In this case we can stop the
|
||||
// existing GossipSyncer assigned to the peer and free up resources.
|
||||
func (d *AuthenticatedGossiper) PruneSyncState(peer routing.Vertex) {
|
||||
func (d *AuthenticatedGossiper) PruneSyncState(peer route.Vertex) {
|
||||
d.syncMgr.PruneSyncState(peer)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lntest"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
)
|
||||
|
||||
@@ -272,7 +273,7 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) FetchLightningNode(
|
||||
nodePub routing.Vertex) (*channeldb.LightningNode, error) {
|
||||
nodePub route.Vertex) (*channeldb.LightningNode, error) {
|
||||
|
||||
for _, node := range r.nodes {
|
||||
if bytes.Equal(nodePub[:], node.PubKeyBytes[:]) {
|
||||
@@ -285,7 +286,7 @@ func (r *mockGraphSource) FetchLightningNode(
|
||||
|
||||
// IsStaleNode returns true if the graph source has a node announcement for the
|
||||
// target node with a more recent timestamp.
|
||||
func (r *mockGraphSource) IsStaleNode(nodePub routing.Vertex, timestamp time.Time) bool {
|
||||
func (r *mockGraphSource) IsStaleNode(nodePub route.Vertex, timestamp time.Time) bool {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
@@ -312,7 +313,7 @@ func (r *mockGraphSource) IsStaleNode(nodePub routing.Vertex, timestamp time.Tim
|
||||
|
||||
// IsPublicNode determines whether the given vertex is seen as a public node in
|
||||
// the graph from the graph's source node's point of view.
|
||||
func (r *mockGraphSource) IsPublicNode(node routing.Vertex) (bool, error) {
|
||||
func (r *mockGraphSource) IsPublicNode(node route.Vertex) (bool, error) {
|
||||
for _, info := range r.infos {
|
||||
if !bytes.Equal(node[:], info.NodeKey1Bytes[:]) &&
|
||||
!bytes.Equal(node[:], info.NodeKey2Bytes[:]) {
|
||||
@@ -721,7 +722,7 @@ func createTestCtx(startHeight uint32) (*testCtx, func(), error) {
|
||||
broadcastedMessage := make(chan msgWithSenders, 10)
|
||||
gossiper := New(Config{
|
||||
Notifier: notifier,
|
||||
Broadcast: func(senders map[routing.Vertex]struct{},
|
||||
Broadcast: func(senders map[route.Vertex]struct{},
|
||||
msgs ...lnwire.Message) error {
|
||||
|
||||
for _, msg := range msgs {
|
||||
@@ -785,7 +786,7 @@ func TestProcessAnnouncement(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
assertSenderExistence := func(sender *btcec.PublicKey, msg msgWithSenders) {
|
||||
if _, ok := msg.senders[routing.NewVertex(sender)]; !ok {
|
||||
if _, ok := msg.senders[route.NewVertex(sender)]; !ok {
|
||||
t.Fatalf("sender=%x not present in %v",
|
||||
sender.SerializeCompressed(), spew.Sdump(msg))
|
||||
}
|
||||
@@ -1987,7 +1988,7 @@ func TestDeDuplicatedAnnouncements(t *testing.T) {
|
||||
if len(announcements.nodeAnnouncements) != 2 {
|
||||
t.Fatal("node announcement not replaced in batch")
|
||||
}
|
||||
nodeID := routing.NewVertex(nodeKeyPriv2.PubKey())
|
||||
nodeID := route.NewVertex(nodeKeyPriv2.PubKey())
|
||||
stored, ok := announcements.nodeAnnouncements[nodeID]
|
||||
if !ok {
|
||||
t.Fatalf("node announcement not found in batch")
|
||||
|
||||
+15
-15
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
)
|
||||
|
||||
@@ -45,7 +45,7 @@ type newSyncer struct {
|
||||
// that a peer has disconnected and its GossipSyncer should be removed.
|
||||
type staleSyncer struct {
|
||||
// peer is the peer that has disconnected.
|
||||
peer routing.Vertex
|
||||
peer route.Vertex
|
||||
|
||||
// doneChan serves as a signal to the caller that the SyncManager's
|
||||
// internal state correctly reflects the stale active syncer. This is
|
||||
@@ -118,11 +118,11 @@ type SyncManager struct {
|
||||
// activeSyncers is the set of all syncers for which we are currently
|
||||
// receiving graph updates from. The number of possible active syncers
|
||||
// is bounded by NumActiveSyncers.
|
||||
activeSyncers map[routing.Vertex]*GossipSyncer
|
||||
activeSyncers map[route.Vertex]*GossipSyncer
|
||||
|
||||
// inactiveSyncers is the set of all syncers for which we are not
|
||||
// currently receiving new graph updates from.
|
||||
inactiveSyncers map[routing.Vertex]*GossipSyncer
|
||||
inactiveSyncers map[route.Vertex]*GossipSyncer
|
||||
|
||||
wg sync.WaitGroup
|
||||
quit chan struct{}
|
||||
@@ -135,9 +135,9 @@ func newSyncManager(cfg *SyncManagerCfg) *SyncManager {
|
||||
newSyncers: make(chan *newSyncer),
|
||||
staleSyncers: make(chan *staleSyncer),
|
||||
activeSyncers: make(
|
||||
map[routing.Vertex]*GossipSyncer, cfg.NumActiveSyncers,
|
||||
map[route.Vertex]*GossipSyncer, cfg.NumActiveSyncers,
|
||||
),
|
||||
inactiveSyncers: make(map[routing.Vertex]*GossipSyncer),
|
||||
inactiveSyncers: make(map[route.Vertex]*GossipSyncer),
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (m *SyncManager) syncerHandler() {
|
||||
|
||||
// createGossipSyncer creates the GossipSyncer for a newly connected peer.
|
||||
func (m *SyncManager) createGossipSyncer(peer lnpeer.Peer) *GossipSyncer {
|
||||
nodeID := routing.Vertex(peer.PubKey())
|
||||
nodeID := route.Vertex(peer.PubKey())
|
||||
log.Infof("Creating new GossipSyncer for peer=%x", nodeID[:])
|
||||
|
||||
encoding := lnwire.EncodingSortedPlain
|
||||
@@ -399,7 +399,7 @@ func (m *SyncManager) createGossipSyncer(peer lnpeer.Peer) *GossipSyncer {
|
||||
// removeGossipSyncer removes all internal references to the disconnected peer's
|
||||
// GossipSyncer and stops it. In the event of an active GossipSyncer being
|
||||
// disconnected, a passive GossipSyncer, if any, will take its place.
|
||||
func (m *SyncManager) removeGossipSyncer(peer routing.Vertex) {
|
||||
func (m *SyncManager) removeGossipSyncer(peer route.Vertex) {
|
||||
m.syncersMu.Lock()
|
||||
defer m.syncersMu.Unlock()
|
||||
|
||||
@@ -527,7 +527,7 @@ func (m *SyncManager) forceHistoricalSync() *GossipSyncer {
|
||||
//
|
||||
// NOTE: It's possible for a nil value to be returned if there are no eligible
|
||||
// candidate syncers.
|
||||
func chooseRandomSyncer(syncers map[routing.Vertex]*GossipSyncer,
|
||||
func chooseRandomSyncer(syncers map[route.Vertex]*GossipSyncer,
|
||||
action func(*GossipSyncer) error) *GossipSyncer {
|
||||
|
||||
for _, s := range syncers {
|
||||
@@ -583,7 +583,7 @@ func (m *SyncManager) InitSyncState(peer lnpeer.Peer) error {
|
||||
// PruneSyncState is called by outside sub-systems once a peer that we were
|
||||
// previously connected to has been disconnected. In this case we can stop the
|
||||
// existing GossipSyncer assigned to the peer and free up resources.
|
||||
func (m *SyncManager) PruneSyncState(peer routing.Vertex) {
|
||||
func (m *SyncManager) PruneSyncState(peer route.Vertex) {
|
||||
done := make(chan struct{})
|
||||
|
||||
// We avoid returning an error when the SyncManager is stopped since the
|
||||
@@ -605,7 +605,7 @@ func (m *SyncManager) PruneSyncState(peer routing.Vertex) {
|
||||
|
||||
// GossipSyncer returns the associated gossip syncer of a peer. The boolean
|
||||
// returned signals whether there exists a gossip syncer for the peer.
|
||||
func (m *SyncManager) GossipSyncer(peer routing.Vertex) (*GossipSyncer, bool) {
|
||||
func (m *SyncManager) GossipSyncer(peer route.Vertex) (*GossipSyncer, bool) {
|
||||
m.syncersMu.Lock()
|
||||
defer m.syncersMu.Unlock()
|
||||
return m.gossipSyncer(peer)
|
||||
@@ -613,7 +613,7 @@ func (m *SyncManager) GossipSyncer(peer routing.Vertex) (*GossipSyncer, bool) {
|
||||
|
||||
// gossipSyncer returns the associated gossip syncer of a peer. The boolean
|
||||
// returned signals whether there exists a gossip syncer for the peer.
|
||||
func (m *SyncManager) gossipSyncer(peer routing.Vertex) (*GossipSyncer, bool) {
|
||||
func (m *SyncManager) gossipSyncer(peer route.Vertex) (*GossipSyncer, bool) {
|
||||
syncer, ok := m.inactiveSyncers[peer]
|
||||
if ok {
|
||||
return syncer, true
|
||||
@@ -626,16 +626,16 @@ func (m *SyncManager) gossipSyncer(peer routing.Vertex) (*GossipSyncer, bool) {
|
||||
}
|
||||
|
||||
// GossipSyncers returns all of the currently initialized gossip syncers.
|
||||
func (m *SyncManager) GossipSyncers() map[routing.Vertex]*GossipSyncer {
|
||||
func (m *SyncManager) GossipSyncers() map[route.Vertex]*GossipSyncer {
|
||||
m.syncersMu.Lock()
|
||||
defer m.syncersMu.Unlock()
|
||||
return m.gossipSyncers()
|
||||
}
|
||||
|
||||
// gossipSyncers returns all of the currently initialized gossip syncers.
|
||||
func (m *SyncManager) gossipSyncers() map[routing.Vertex]*GossipSyncer {
|
||||
func (m *SyncManager) gossipSyncers() map[route.Vertex]*GossipSyncer {
|
||||
numSyncers := len(m.inactiveSyncers) + len(m.activeSyncers)
|
||||
syncers := make(map[routing.Vertex]*GossipSyncer, numSyncers)
|
||||
syncers := make(map[route.Vertex]*GossipSyncer, numSyncers)
|
||||
|
||||
for _, syncer := range m.inactiveSyncers {
|
||||
syncers[syncer.cfg.peerPub] = syncer
|
||||
|
||||
Reference in new issue
Block a user