From 277cd1e5848cc4030ef43ddf00ea6ebe59e19127 Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Thu, 29 Feb 2024 14:20:58 +0100 Subject: [PATCH] Return true or false from AddData(). Returns false and aborts the data addition if there is no change in the delta. Use this to shortcut applyUpdateFromNewState() which prevents sending out notifications for empty deltas. --- cmd/stayrtr/stayrtr.go | 7 +++++-- lib/server.go | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 2c59882..73a8bd0 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -445,10 +445,13 @@ func (s *state) applyUpdateFromNewState(vrps []rtr.VRP, brks []rtr.BgpsecKey, va for _, v := range vaps { SDs = append(SDs, v.Copy()) } - s.server.AddData(SDs) + if (s.server.AddData(SDs) == false) { + log.Info("No difference to current cache") + return nil + } serial, _ := s.server.GetCurrentSerial(sessid) - log.Infof("Updated added, new serial %v", serial) + log.Infof("Update added, new serial %v", serial) if s.sendNotifs { log.Debugf("Sending notifications to clients") s.server.NotifyClientsLatest() diff --git a/lib/server.go b/lib/server.go index 45f302f..47ceda5 100644 --- a/lib/server.go +++ b/lib/server.go @@ -361,7 +361,7 @@ func (s *Server) CountSDs() int { return len(s.sdCurrent) } -func (s *Server) AddData(new []SendableData) { +func (s *Server) AddData(new []SendableData) bool { s.sdlock.RLock() added, removed, _ := ComputeDiff(new, s.sdCurrent, false) @@ -373,7 +373,12 @@ func (s *Server) AddData(new []SendableData) { curDiff := append(added, removed...) s.sdlock.RUnlock() - s.AddSDsDiff(curDiff) + if (len(curDiff) == 0) { + return false + } else { + s.AddSDsDiff(curDiff) + return true + } } func (s *Server) addSerial(serial uint32) []uint32 {