Skip to content

Commit e692df1

Browse files
committed
Improve selectNewParent
1 parent 21e3b39 commit e692df1

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

router/tree.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (t *spanningTree) selectNewParent() {
120120
var bestTime time.Time
121121
var bestPort types.SwitchPortID
122122
var bestAnn *rootAnnouncementWithTime
123+
var bestSeq types.Varu64
123124
portsToCheck := map[*Peer]*rootAnnouncementWithTime{}
124125
for _, p := range t.r.activePorts() {
125126
ann := p.lastAnnouncement()
@@ -136,6 +137,7 @@ func (t *spanningTree) selectNewParent() {
136137
bestDist = hops
137138
bestPort = p.port
138139
bestTime = ann.at
140+
bestSeq = ann.Sequence
139141
bestAnn = ann
140142
}
141143
}
@@ -144,10 +146,13 @@ func (t *spanningTree) selectNewParent() {
144146
return ann.RootPublicKey.CompareTo(bestKey) > 0
145147
})
146148
checkWithCondition(func(ann *rootAnnouncementWithTime, hops int) bool {
147-
return ann.RootPublicKey.CompareTo(bestKey) > 0 && hops < bestDist
149+
return ann.RootPublicKey.CompareTo(bestKey) == 0 && ann.Sequence > bestSeq
148150
})
149151
checkWithCondition(func(ann *rootAnnouncementWithTime, hops int) bool {
150-
return ann.RootPublicKey.CompareTo(bestKey) == 0 && hops == bestDist && ann.at.Before(bestTime)
152+
return ann.RootPublicKey.CompareTo(bestKey) == 0 && ann.Sequence == bestSeq && hops < bestDist
153+
})
154+
checkWithCondition(func(ann *rootAnnouncementWithTime, hops int) bool {
155+
return ann.RootPublicKey.CompareTo(bestKey) == 0 && ann.Sequence == bestSeq && hops == bestDist && ann.at.Before(bestTime)
151156
})
152157
if bestAnn != nil {
153158
t.parent.Store(bestPort)

0 commit comments

Comments
 (0)