diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a8d4cda..80ed556 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] ## Changed - `Scheduler` operates entirely with `time.Duration` instead of `int64` internally. This removes many type conversions and makes it more readable. (made possible with `math/rand/v2`) +- Changed logic of `OnTimer` function within `Core` to read better. ## [v0.0.0-alpha.15] - 2024-02-23 ## Added diff --git a/pkg/svs/twostate_core.go b/pkg/svs/twostate_core.go index dc5f124..374425f 100644 --- a/pkg/svs/twostate_core.go +++ b/pkg/svs/twostate_core.go @@ -167,15 +167,13 @@ func (c *twoStateCore) onInterest(interest ndn.Interest, rawInterest enc.Wire, s } func (c *twoStateCore) onTimer() { - if atomic.LoadInt32(c.state) == steadyState { - c.sendInterest() - } else { + if atomic.LoadInt32(c.state) == suppressionState { atomic.StoreInt32(c.state, steadyState) - localNewer := c.mergeRecordToLocal() - if localNewer { - c.sendInterest() + if !c.isInterestNeeded() { + return } } + c.sendInterest() } func (c *twoStateCore) sendInterest() { @@ -206,7 +204,7 @@ func (c *twoStateCore) mergeVectorToLocal(vector StateVector) bool { var ( missing = make(SyncUpdate, 0) lVal uint64 - isNewer bool + lNewer bool ) c.localMtx.Lock() for p := vector.Entries().Back(); p != nil; p = p.Prev() { @@ -219,12 +217,12 @@ func (c *twoStateCore) mergeVectorToLocal(vector StateVector) bool { if (c.effSuppress || slices.Contains(c.selfsets, p.Kstr)) && time.Since(c.updateTimes[p.Kstr]) < c.constants.SuppressionInterval { continue } - isNewer = true + lNewer = true } } // Recently added datasets are not taken into account when checking length if vector.Len() < c.local.Len() { - isNewer = true + lNewer = true } c.localMtx.Unlock() if len(missing) != 0 { @@ -232,7 +230,7 @@ func (c *twoStateCore) mergeVectorToLocal(vector StateVector) bool { sub <- missing } } - return isNewer + return lNewer } func (c *twoStateCore) recordVector(vector StateVector) { @@ -256,7 +254,7 @@ func (c *twoStateCore) recordVector(vector StateVector) { } } -func (c *twoStateCore) mergeRecordToLocal() bool { +func (c *twoStateCore) isInterestNeeded() bool { c.localMtx.Lock() c.recordMtx.Lock() defer c.localMtx.Unlock()