Skip to content

Commit

Permalink
more readable Core
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin C Presley committed Feb 24, 2024
1 parent f250edb commit ed0c1d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions pkg/svs/twostate_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -219,20 +217,20 @@ 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 {
for _, sub := range c.subs {
sub <- missing
}
}
return isNewer
return lNewer
}

func (c *twoStateCore) recordVector(vector StateVector) {
Expand All @@ -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()
Expand Down

0 comments on commit ed0c1d9

Please sign in to comment.